summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDarren Hart <dvhart@linux.intel.com>2012-03-13 12:02:51 -0700
committerRichard Purdie <richard.purdie@linuxfoundation.org>2012-03-22 19:18:24 +0000
commitaf193ae15a2ad2e170d4a9d4bcbfff3e429784f5 (patch)
tree3a41ec6df738b0bc25cd2aa7207ccc933d75bb0d
parent77106395e14eca46e4ceef2ffce0f058004dcc72 (diff)
downloadpoky-af193ae15a2ad2e170d4a9d4bcbfff3e429784f5.tar.gz
ddimage: Add script for writing images to boot media
Fixes [YOCTO #1806] Standard practice is to use the Linux "dd" command to write images to boot media. This can be error prone and the results of sloppy usage can be disastrous. Locating the device you want to use is a clumsy process, especially on a headless build system. The ddimage script does the following: o Check the image and device exist o Check the device is writable o Compare the device to a blacklist and abort if it's listed Blacklist defaults to "/dev/sda" o Display useful identifying information about the image and device o Prompt the user before commencing the write The output looks something like this: $ sudo ~/bin/ddimage tmp/deploy/images/core-image-sato-fri2-noemgd.hddimg /dev/sdk Image details ============= image: `tmp/deploy/images/core-image-sato-fri2-noemgd.hddimg' -> `core-image-sato-fri2-noemgd-20111202214038.hddimg' size: 318568448 bytes modified: 2011-12-02 13:45:05.298897861 -0800 type: x86 boot sector, code offset 0x58, OEM-ID "SYSLINUX", sectors/cluster 16, root entries 512, Media descriptor 0xf8, sectors/FAT 152, heads 64, hidden sectors 32, sectors 622204 (volumes > 32 MB) , serial number 0x4ed946e0, label: "boot ", FAT (16 bit) Device details ============== device: /dev/sdk vendor: Kingston model: DT 101 G2 Write tmp/deploy/images/core-image-sato-fri2-noemgd.hddimg to /dev/sdk [y/N]? y Writing image... 303+1 records in 303+1 records out 318568448 bytes (319 MB) copied, 53.6766 s, 5.9 MB/s (From OE-Core rev: 87e581bb7da9f1530d190cd023fcf892c8b858f5) Signed-off-by: Darren Hart <dvhart@linux.intel.com> CC: Dexuan Cui <dexuan.cui@intel.com> CC: Joshua Lock <josh@linux.intel.com> CC: Kishore K Bodke <kishore.k.bodke@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rwxr-xr-xscripts/contrib/ddimage87
1 files changed, 87 insertions, 0 deletions
diff --git a/scripts/contrib/ddimage b/scripts/contrib/ddimage
new file mode 100755
index 0000000000..2cba9b28f1
--- /dev/null
+++ b/scripts/contrib/ddimage
@@ -0,0 +1,87 @@
1#!/bin/sh
2
3#BLACKLIST_DEVICES="/dev/sda /dev/sdb /dev/sdc /dev/sdd /dev/sde"
4BLACKLIST_DEVICES="/dev/sda"
5
6# 1MB blocksize
7BLOCKSIZE=1048576
8
9function usage() {
10 echo "Usage: $(basename $0) IMAGE DEVICE"
11}
12
13function image_details() {
14 IMG=$1
15 echo "Image details"
16 echo "============="
17 echo " image: $(stat --printf '%N\n' $IMG)"
18 echo " size: $(stat -L --printf '%s bytes\n' $IMG)"
19 echo " modified: $(stat -L --printf '%y\n' $IMG)"
20 echo " type: $(file -L -b $IMG)"
21 echo ""
22}
23
24function device_details() {
25 DEV=$1
26 BLOCK_SIZE=512
27
28 echo "Device details"
29 echo "=============="
30 echo " device: $DEVICE"
31 if [ -f "/sys/class/block/$DEV/device/vendor" ]; then
32 echo " vendor: $(cat /sys/class/block/$DEV/device/vendor)"
33 else
34 echo " vendor: UNKOWN"
35 fi
36 if [ -f "/sys/class/block/$DEV/device/model" ]; then
37 echo " model: $(cat /sys/class/block/$DEV/device/model)"
38 else
39 echo " model: UNKNOWN"
40 fi
41 if [ -f "/sys/class/block/$DEV/size" ]; then
42 echo " size: $[$(cat /sys/class/block/$DEV/size)*BLOCK_SIZE] bytes"
43 else
44 echo " size: UNKNOWN"
45 fi
46 echo ""
47}
48
49if [ $# -ne 2 ]; then
50 usage
51 exit 1
52fi
53
54IMAGE=$1
55DEVICE=$2
56
57if [ ! -e "$IMAGE" ]; then
58 echo "ERROR: Image $IMAGE does not exist"
59 usage
60 exit 1
61fi
62
63
64if [ "${BLACKLIST_DEVICES/${DEVICE}/ERROR}" != "$BLACKLIST_DEVICES" ]; then
65 echo "ERROR: Device $DEVICE is blacklisted"
66 exit 1
67fi
68
69if [ ! -w "$DEVICE" ]; then
70 echo "ERROR: Device $DEVICE does not exist or is not writable"
71 usage
72 exit 1
73fi
74
75image_details $IMAGE
76device_details $(basename $DEVICE)
77
78echo -n "Write $IMAGE to $DEVICE [y/N]? "
79read RESPONSE
80if [ "$RESPONSE" != "y" ]; then
81 echo "Write aborted"
82 exit 0
83fi
84
85echo "Writing image..."
86dd if="$IMAGE" of="$DEVICE" bs="$BLOCKSIZE"
87sync