
oe-core removed the prerequisite to have sh as bash. POSIX doesn't define any options and furthermore allows 'echo -e' to be the default behavior. This means that in dash 'echo -e' will actually print '-e' and interpret backslashes by default. We use instead 'printf' builtin command with or without '\n' to simulate 'echo -e' or 'echo -n'. 'printf' needs format while 'echo' can be used without any arguments. So 'echo >' was replaced by 'printf "" >'. 'echo' without '-n' flag adds a new line by default so to keep the same behavior of two new lines while using 'echo "\n"', 'printf "\n\n"' is used. [YOCTO #3138] (From OE-Core rev: a19880ad10ccb5d7d909dcf9de5c3dc58a0ebcd3) Signed-off-by: Andrei Gherzan <andrei@gherzan.ro> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
1.7 KiB
Executable File
#!/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)
printf "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