All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/1] ddimage: Add script for writing images to boot media
@ 2012-03-13 19:16 Darren Hart
  2012-03-13 19:16 ` [PATCH 1/1] " Darren Hart
  0 siblings, 1 reply; 6+ messages in thread
From: Darren Hart @ 2012-03-13 19:16 UTC (permalink / raw)
  To: Yocto Project; +Cc: Darren Hart

The following changes since commit 19d4e0c98046d434a02653864215c4fcffabc919:

  linux-yocto/meta-yocto: v3.2.9, v3.0.23 + fixes and updates (2012-03-13 16:53:47 +0000)

are available in the git repository at:
  git://git.pokylinux.org/poky-contrib dvhart/bug1806
  http://git.pokylinux.org/cgit.cgi/poky-contrib/log/?h=dvhart/bug1806

Darren Hart (1):
  ddimage: Add script for writing images to boot media

 scripts/contrib/ddimage |   87 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 87 insertions(+), 0 deletions(-)
 create mode 100755 scripts/contrib/ddimage

-- 
1.7.6.5



^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/1] ddimage: Add script for writing images to boot media
  2012-03-13 19:16 [PATCH 0/1] ddimage: Add script for writing images to boot media Darren Hart
@ 2012-03-13 19:16 ` Darren Hart
  2012-03-21 23:06   ` Darren Hart
  0 siblings, 1 reply; 6+ messages in thread
From: Darren Hart @ 2012-03-13 19:16 UTC (permalink / raw)
  To: Yocto Project

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

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>
---
 scripts/contrib/ddimage |   87 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 87 insertions(+), 0 deletions(-)
 create mode 100755 scripts/contrib/ddimage

diff --git a/scripts/contrib/ddimage b/scripts/contrib/ddimage
new file mode 100755
index 0000000..2cba9b2
--- /dev/null
+++ b/scripts/contrib/ddimage
@@ -0,0 +1,87 @@
+#!/bin/sh
+
+#BLACKLIST_DEVICES="/dev/sda /dev/sdb /dev/sdc /dev/sdd /dev/sde"
+BLACKLIST_DEVICES="/dev/sda"
+
+# 1MB blocksize
+BLOCKSIZE=1048576
+
+function usage() {
+	echo "Usage: $(basename $0) IMAGE DEVICE"
+}
+
+function image_details() {
+	IMG=$1
+	echo "Image details"
+	echo "============="
+	echo "    image: $(stat --printf '%N\n' $IMG)"
+	echo "     size: $(stat -L --printf '%s bytes\n' $IMG)"
+	echo " modified: $(stat -L --printf '%y\n' $IMG)"
+	echo "     type: $(file -L -b $IMG)"
+	echo ""
+}
+
+function device_details() {
+	DEV=$1
+	BLOCK_SIZE=512
+
+	echo "Device details"
+	echo "=============="
+	echo "  device: $DEVICE"
+	if [ -f "/sys/class/block/$DEV/device/vendor" ]; then
+		echo "  vendor: $(cat /sys/class/block/$DEV/device/vendor)"
+	else
+		echo "  vendor: UNKOWN"
+	fi
+	if [ -f "/sys/class/block/$DEV/device/model" ]; then
+		echo "   model: $(cat /sys/class/block/$DEV/device/model)"
+	else
+		echo "   model: UNKNOWN"
+	fi
+	if [ -f "/sys/class/block/$DEV/size" ]; then
+		echo "    size: $[$(cat /sys/class/block/$DEV/size)*BLOCK_SIZE] bytes"
+	else
+		echo "    size: UNKNOWN"
+	fi
+	echo ""
+}
+
+if [ $# -ne 2 ]; then
+	usage
+	exit 1
+fi
+
+IMAGE=$1
+DEVICE=$2
+
+if [ ! -e "$IMAGE" ]; then
+	echo "ERROR: Image $IMAGE does not exist"
+	usage
+	exit 1
+fi
+
+
+if [ "${BLACKLIST_DEVICES/${DEVICE}/ERROR}" != "$BLACKLIST_DEVICES" ]; then
+	echo "ERROR: Device $DEVICE is blacklisted"
+	exit 1
+fi
+
+if [ ! -w "$DEVICE" ]; then
+	echo "ERROR: Device $DEVICE does not exist or is not writable"
+	usage
+	exit 1
+fi
+
+image_details $IMAGE
+device_details $(basename $DEVICE)
+
+echo -n "Write $IMAGE to $DEVICE [y/N]? "
+read RESPONSE
+if [ "$RESPONSE" != "y" ]; then
+	echo "Write aborted"
+	exit 0
+fi
+
+echo "Writing image..."
+dd if="$IMAGE" of="$DEVICE" bs="$BLOCKSIZE"
+sync
-- 
1.7.6.5



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/1] ddimage: Add script for writing images to boot media
  2012-03-13 19:16 ` [PATCH 1/1] " Darren Hart
@ 2012-03-21 23:06   ` Darren Hart
  2012-03-22  0:26     ` Paul Eggleton
  0 siblings, 1 reply; 6+ messages in thread
From: Darren Hart @ 2012-03-21 23:06 UTC (permalink / raw)
  To: Yocto Project, Wold, Saul

Any objections to this going in?

On 03/13/2012 12:16 PM, Darren Hart wrote:
> 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
> 
> 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>
> ---
>  scripts/contrib/ddimage |   87 +++++++++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 87 insertions(+), 0 deletions(-)
>  create mode 100755 scripts/contrib/ddimage
> 
> diff --git a/scripts/contrib/ddimage b/scripts/contrib/ddimage
> new file mode 100755
> index 0000000..2cba9b2
> --- /dev/null
> +++ b/scripts/contrib/ddimage
> @@ -0,0 +1,87 @@
> +#!/bin/sh
> +
> +#BLACKLIST_DEVICES="/dev/sda /dev/sdb /dev/sdc /dev/sdd /dev/sde"
> +BLACKLIST_DEVICES="/dev/sda"
> +
> +# 1MB blocksize
> +BLOCKSIZE=1048576
> +
> +function usage() {
> +	echo "Usage: $(basename $0) IMAGE DEVICE"
> +}
> +
> +function image_details() {
> +	IMG=$1
> +	echo "Image details"
> +	echo "============="
> +	echo "    image: $(stat --printf '%N\n' $IMG)"
> +	echo "     size: $(stat -L --printf '%s bytes\n' $IMG)"
> +	echo " modified: $(stat -L --printf '%y\n' $IMG)"
> +	echo "     type: $(file -L -b $IMG)"
> +	echo ""
> +}
> +
> +function device_details() {
> +	DEV=$1
> +	BLOCK_SIZE=512
> +
> +	echo "Device details"
> +	echo "=============="
> +	echo "  device: $DEVICE"
> +	if [ -f "/sys/class/block/$DEV/device/vendor" ]; then
> +		echo "  vendor: $(cat /sys/class/block/$DEV/device/vendor)"
> +	else
> +		echo "  vendor: UNKOWN"
> +	fi
> +	if [ -f "/sys/class/block/$DEV/device/model" ]; then
> +		echo "   model: $(cat /sys/class/block/$DEV/device/model)"
> +	else
> +		echo "   model: UNKNOWN"
> +	fi
> +	if [ -f "/sys/class/block/$DEV/size" ]; then
> +		echo "    size: $[$(cat /sys/class/block/$DEV/size)*BLOCK_SIZE] bytes"
> +	else
> +		echo "    size: UNKNOWN"
> +	fi
> +	echo ""
> +}
> +
> +if [ $# -ne 2 ]; then
> +	usage
> +	exit 1
> +fi
> +
> +IMAGE=$1
> +DEVICE=$2
> +
> +if [ ! -e "$IMAGE" ]; then
> +	echo "ERROR: Image $IMAGE does not exist"
> +	usage
> +	exit 1
> +fi
> +
> +
> +if [ "${BLACKLIST_DEVICES/${DEVICE}/ERROR}" != "$BLACKLIST_DEVICES" ]; then
> +	echo "ERROR: Device $DEVICE is blacklisted"
> +	exit 1
> +fi
> +
> +if [ ! -w "$DEVICE" ]; then
> +	echo "ERROR: Device $DEVICE does not exist or is not writable"
> +	usage
> +	exit 1
> +fi
> +
> +image_details $IMAGE
> +device_details $(basename $DEVICE)
> +
> +echo -n "Write $IMAGE to $DEVICE [y/N]? "
> +read RESPONSE
> +if [ "$RESPONSE" != "y" ]; then
> +	echo "Write aborted"
> +	exit 0
> +fi
> +
> +echo "Writing image..."
> +dd if="$IMAGE" of="$DEVICE" bs="$BLOCKSIZE"
> +sync

-- 
Darren Hart
Intel Open Source Technology Center
Yocto Project - Linux Kernel


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/1] ddimage: Add script for writing images to boot media
  2012-03-21 23:06   ` Darren Hart
@ 2012-03-22  0:26     ` Paul Eggleton
  2012-03-22 15:56       ` Darren Hart
  0 siblings, 1 reply; 6+ messages in thread
From: Paul Eggleton @ 2012-03-22  0:26 UTC (permalink / raw)
  To: yocto; +Cc: Darren Hart, Wold, Saul

On Wednesday 21 March 2012 16:06:14 Darren Hart wrote:
> Any objections to this going in?

No objections, looks like a really useful tool; a couple of suggestions though 
(sorry for not looking at it earlier):

* Is it worth checking if the target device is mounted and erroring out if so?
* Not sure but it may be worth waiting a few seconds after the sync before 
exiting; I've seen some hardware that returns control to userspace before the 
hardware has actually finished writing.

Cheers,
Paul

-- 

Paul Eggleton
Intel Open Source Technology Centre


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/1] ddimage: Add script for writing images to boot media
  2012-03-22  0:26     ` Paul Eggleton
@ 2012-03-22 15:56       ` Darren Hart
  2012-03-22 17:45         ` Paul Eggleton
  0 siblings, 1 reply; 6+ messages in thread
From: Darren Hart @ 2012-03-22 15:56 UTC (permalink / raw)
  To: Paul Eggleton; +Cc: yocto, Wold, Saul



On 03/21/2012 05:26 PM, Paul Eggleton wrote:
> On Wednesday 21 March 2012 16:06:14 Darren Hart wrote:
>> Any objections to this going in?
> 
> No objections, looks like a really useful tool; a couple of suggestions though 
> (sorry for not looking at it earlier):
> 
> * Is it worth checking if the target device is mounted and erroring out if so?

That's a good suggestion. Alright with you if that is a follow-on patch?

> * Not sure but it may be worth waiting a few seconds after the sync before 
> exiting; I've seen some hardware that returns control to userspace before the 
> hardware has actually finished writing.

That may be, but anything we assume will be wrong for some hardware. The
sticks I have flash an LED for a few seconds afterwards, indicating writing.

-- 
Darren Hart
Intel Open Source Technology Center
Yocto Project - Linux Kernel


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/1] ddimage: Add script for writing images to boot media
  2012-03-22 15:56       ` Darren Hart
@ 2012-03-22 17:45         ` Paul Eggleton
  0 siblings, 0 replies; 6+ messages in thread
From: Paul Eggleton @ 2012-03-22 17:45 UTC (permalink / raw)
  To: yocto; +Cc: Darren Hart, Wold, Saul

On Thursday 22 March 2012 08:56:08 Darren Hart wrote:
> On 03/21/2012 05:26 PM, Paul Eggleton wrote:
> > On Wednesday 21 March 2012 16:06:14 Darren Hart wrote:
> >> Any objections to this going in?
> > 
> > No objections, looks like a really useful tool; a couple of suggestions
> > though (sorry for not looking at it earlier):
> > 
> > * Is it worth checking if the target device is mounted and erroring out if
> > so?
> That's a good suggestion. Alright with you if that is a follow-on patch?

Sure, sounds fine to me.
 
> > * Not sure but it may be worth waiting a few seconds after the sync before
> > exiting; I've seen some hardware that returns control to userspace before
> > the hardware has actually finished writing.
> 
> That may be, but anything we assume will be wrong for some hardware. The
> sticks I have flash an LED for a few seconds afterwards, indicating writing.

Many do, yes. I guess it was just a simple idea to avoid potential issues 
particularly for those that don't have an LED.

Cheers,
Paul

-- 

Paul Eggleton
Intel Open Source Technology Centre


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-03-22 17:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-13 19:16 [PATCH 0/1] ddimage: Add script for writing images to boot media Darren Hart
2012-03-13 19:16 ` [PATCH 1/1] " Darren Hart
2012-03-21 23:06   ` Darren Hart
2012-03-22  0:26     ` Paul Eggleton
2012-03-22 15:56       ` Darren Hart
2012-03-22 17:45         ` Paul Eggleton

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.