Merge lp:~mwaddel/linaro-image-tools/split-deploy-v3 into lp:linaro-image-tools/11.11

Proposed by Matt Waddel
Status: Merged
Approved by: Loïc Minier
Approved revision: 153
Merged at revision: 153
Proposed branch: lp:~mwaddel/linaro-image-tools/split-deploy-v3
Merge into: lp:linaro-image-tools/11.11
Diff against target: 295 lines (+92/-51)
1 file modified
linaro-media-create (+92/-51)
To merge this branch: bzr merge lp:~mwaddel/linaro-image-tools/split-deploy-v3
Reviewer Review Type Date Requested Status
Loïc Minier (community) Approve
Review via email: mp+38799@code.launchpad.net

Description of the change

Added code review corrections from Loic to branch:

https://code.launchpad.net/~mwaddel/linaro-image-tools/split-deploy-v2

To post a comment you must log in.
Revision history for this message
Loïc Minier (lool) wrote :
Revision history for this message
Loïc Minier (lool) wrote :

Looks good to me, except for a typo in the comment in r153: s/devives/devices/

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'linaro-media-create'
--- linaro-media-create 2010-10-13 21:57:24 +0000
+++ linaro-media-create 2010-10-19 02:49:41 +0000
@@ -19,8 +19,8 @@
1919
20set -e20set -e
2121
22unset MMC MMC1 MMC2 MMC3 IMAGE_FILE HWPACK_FILE UBOOT_FLAVOR KERNEL_ADDR22unset DEVICE BOOTFS ROOTFS IMAGE_FILE HWPACK_FILE UBOOT_FLAVOR KERNEL_ADDR
23unset INITRD_ADDR CREATE_SWAP SWAP_SIZE23unset INITRD_ADDR CREATE_SWAP SWAP_SIZE DEPLOY_STEPS
2424
25#Defaults25#Defaults
26RFS=ext326RFS=ext3
@@ -31,6 +31,9 @@
31FAT_SIZE=3231FAT_SIZE=32
32IMAGE_SIZE=2G32IMAGE_SIZE=2G
33MMC_PART_OFFSET=033MMC_PART_OFFSET=0
34BOOTFS_STEP="create_boot_cmd populate_boot"
35ROOTFS_STEP="populate_rootfs"
36PARTITION_STEP="create_partitions"
3437
35DIR=$PWD38DIR=$PWD
36TMP_DIR=$(mktemp -d)39TMP_DIR=$(mktemp -d)
@@ -55,7 +58,7 @@
5558
56required options:59required options:
57--mmc </dev/sdX>60--mmc </dev/sdX>
58 Unformated MMC Card61 Unformatted Storage Device
59<or>62<or>
60--image_file <xxx>63--image_file <xxx>
61 specify name of image file64 specify name of image file
@@ -108,14 +111,23 @@
108111
109--binary <filename>112--binary <filename>
110 specify file used to create the bootable system. Default binary-tar.tar.gz113 specify file used to create the bootable system. Default binary-tar.tar.gz
114
115--no-rootfs
116 do not deploy the root filesystem
117
118--no-bootfs
119 do not deploy the boot filesystem
120
121--no-part
122 reuse existing partitions on the deploy media
111EOF123EOF
112 exit124 exit
113}125}
114126
115check_mmc() {127check_device() {
116 FDISK=$(sudo LC_ALL=C sfdisk -l | grep "[Disk] ${MMC}" | awk '{print $2}')128 FDISK=$(sudo LC_ALL=C sfdisk -l | grep "[Disk] ${DEVICE}" | awk '{print $2}')
117129
118 if test "-$FDISK-" = "-$MMC:-"130 if test "-$FDISK-" = "-$DEVICE:-"
119 then131 then
120 echo ""132 echo ""
121 echo "I see..."133 echo "I see..."
@@ -125,12 +137,12 @@
125 echo "mount:"137 echo "mount:"
126 LC_ALL=C mount | grep -v none | grep "/dev/" --color=never138 LC_ALL=C mount | grep -v none | grep "/dev/" --color=never
127 echo ""139 echo ""
128 read -p "Are you 100% sure, on selecting [${MMC}] (y/n)? "140 read -p "Are you 100% sure, on selecting [${DEVICE}] (y/n)? "
129 [ "$REPLY" == "y" ] || exit141 [ "$REPLY" == "y" ] || exit
130 echo ""142 echo ""
131 else143 else
132 echo ""144 echo ""
133 echo "Are you sure? I Don't see [${MMC}], here is what I do see..."145 echo "Are you sure? I Don't see [${DEVICE}], here is what I do see..."
134 echo ""146 echo ""
135 echo "sudo sfdisk -l:"147 echo "sudo sfdisk -l:"
136 sudo LC_ALL=C sfdisk -l | grep "[Disk] /dev/" --color=never148 sudo LC_ALL=C sfdisk -l | grep "[Disk] /dev/" --color=never
@@ -176,8 +188,8 @@
176 ;;188 ;;
177 --mmc)189 --mmc)
178 checkparm "$2"190 checkparm "$2"
179 MMC="$2"191 DEVICE="$2"
180 check_mmc192 check_device
181 ;;193 ;;
182 --image_file)194 --image_file)
183 checkparm "$2"195 checkparm "$2"
@@ -224,10 +236,21 @@
224 checkparm "$2"236 checkparm "$2"
225 BINARY_TARBALL="$2"237 BINARY_TARBALL="$2"
226 ;;238 ;;
239 --no-rootfs)
240 ROOTFS_STEP=""
241 ;;
242 --no-bootfs)
243 BOOTFS_STEP=""
244 ;;
245 --no-part)
246 PARTITION_STEP=""
247 ;;
227 esac248 esac
228 shift249 shift
229done250done
230251
252DEPLOY_STEPS="$PARTITION_STEP prepare_partitions $BOOTFS_STEP $ROOTFS_STEP"
253
231ensure_command mkimage uboot-mkimage254ensure_command mkimage uboot-mkimage
232ensure_command uuidgen uuid-runtime255ensure_command uuidgen uuid-runtime
233ensure_command parted parted256ensure_command parted parted
@@ -254,13 +277,13 @@
254277
255RFS_UUID=`uuidgen -r`278RFS_UUID=`uuidgen -r`
256279
257get_mmcs_by_id() {280get_device_by_id() {
258 if [ ! "${IMAGE_FILE}" ]; then281 if [ ! "${IMAGE_FILE}" ]; then
259 for device in /dev/disk/by-id/*; do282 for device in /dev/disk/by-id/*; do
260 if [ `realpath $device` = $MMC ]; then283 if [ `realpath $device` = $DEVICE ]; then
261 case "$device" in284 case "$device" in
262 *-part[0-9]*)285 *-part[0-9]*)
263 echo "device $MMC must not be a partition part ($device)" >&2286 echo "device $DEVICE must not be a partition part ($device)" >&2
264 exit 1287 exit 1
265 ;;288 ;;
266 esac289 esac
@@ -270,11 +293,9 @@
270 # echo "part $part_no found: $part_id" 1>&2293 # echo "part $part_no found: $part_id" 1>&2
271 # if there is a non-fs-data part (e.g. mx51evk), MMC_PART_OFFSET=1294 # if there is a non-fs-data part (e.g. mx51evk), MMC_PART_OFFSET=1
272 if test "$part_no" = $((1 + $MMC_PART_OFFSET)); then295 if test "$part_no" = $((1 + $MMC_PART_OFFSET)); then
273 MMC1=$part296 BOOTFS=$part
274 elif test "$part_no" = $((2 + $MMC_PART_OFFSET)) ; then297 elif test "$part_no" = $((2 + $MMC_PART_OFFSET)) ; then
275 MMC2=$part298 ROOTFS=$part
276 elif test "$part_no" = $((3 + $MMC_PART_OFFSET)); then
277 MMC3=$part
278 fi299 fi
279 done300 done
280 break301 break
@@ -367,22 +388,23 @@
367 echo "Umounting Partitions"388 echo "Umounting Partitions"
368 echo ""389 echo ""
369390
370 if test -n "$MMC1"; then391 if test -n "$BOOTFS"; then
371 sudo umount ${MMC1} &> /dev/null || true392 sudo umount ${BOOTFS} &> /dev/null || true
372 fi393 fi
373 if test -n "$MMC2"; then394 if test -n "$ROOTFS"; then
374 sudo umount ${MMC2} &> /dev/null || true395 sudo umount ${ROOTFS} &> /dev/null || true
375 fi
376 if [ "${MMC}" ]; then
377 sudo parted -s ${MMC} mklabel msdos
378 fi396 fi
379}397}
380398
381create_partitions() {399create_partitions() {
400 if [ "${DEVICE}" ]; then
401 sudo parted -s ${DEVICE} mklabel msdos
402 fi
403
382 if [ "${IMAGE_FILE}" ]; then404 if [ "${IMAGE_FILE}" ]; then
383 partdev=${IMAGE_FILE}405 partdev=${IMAGE_FILE}
384 else406 else
385 partdev=${MMC}407 partdev=${DEVICE}
386 fi408 fi
387409
388 if [ "$FAT_SIZE" = "32" ]; then410 if [ "$FAT_SIZE" = "32" ]; then
@@ -419,23 +441,43 @@
419 ROOTSIZE2=$(($(LC_ALL=C fdisk -l -u "$IMAGE_FILE" | grep Linux | awk '{print $3}')))441 ROOTSIZE2=$(($(LC_ALL=C fdisk -l -u "$IMAGE_FILE" | grep Linux | awk '{print $3}')))
420 ROOTSIZE1=$(($(LC_ALL=C fdisk -l -u "$IMAGE_FILE" | grep Linux | awk '{print $2}')))442 ROOTSIZE1=$(($(LC_ALL=C fdisk -l -u "$IMAGE_FILE" | grep Linux | awk '{print $2}')))
421 ROOTSIZE=$((((ROOTSIZE2+1-ROOTSIZE1)/2)*1024))443 ROOTSIZE=$((((ROOTSIZE2+1-ROOTSIZE1)/2)*1024))
422 MMC1=$(sudo losetup -f --show "$IMAGE_FILE" --offset $VFATOFFSET --sizelimit $VFATSIZE)444 BOOTFS=$(sudo losetup -f --show "$IMAGE_FILE" --offset $VFATOFFSET --sizelimit $VFATSIZE)
423 MMC2=$(sudo losetup -f --show "$IMAGE_FILE" --offset $ROOTOFFSET --sizelimit $ROOTSIZE)445 ROOTFS=$(sudo losetup -f --show "$IMAGE_FILE" --offset $ROOTOFFSET --sizelimit $ROOTSIZE)
424 fi446 fi
425}447}
426448
427449
428prepare_partitions() {450prepare_partitions() {
451
452echo -n "waiting for partitioning to settle ..."
453sync
454sleep 3
455echo "done."
456get_device_by_id
457
458if [ "$BOOTFS_STEP" ]; then
429 echo ""459 echo ""
430 echo "Formating Boot Partition"460 echo "Formating Boot Partition"
431 echo ""461 echo ""
432462 if [ -z "$BOOTFS" ]; then
433 sudo mkfs.vfat -F ${FAT_SIZE} ${MMC1} -n ${BOOT_LABEL}463 echo "Partition $BOOTFS does not exist"
434464 exit 2
465 else
466 sudo mkfs.vfat -F ${FAT_SIZE} ${BOOTFS} -n ${BOOT_LABEL}
467 fi
468fi
469
470if [ "$ROOTFS_STEP" ]; then
435 echo ""471 echo ""
436 echo "Formating ${RFS} Partition"472 echo "Formating ${RFS} Partition"
437 echo ""473 echo ""
438 sudo mkfs.${RFS} -U "$RFS_UUID" ${MMC2} -L ${RFS_LABEL}474 if [ -z "$ROOTFS" ]; then
475 echo "Partition $ROOTFS does not exist"
476 exit 2
477 else
478 sudo mkfs.${RFS} -U "$RFS_UUID" ${ROOTFS} -L ${RFS_LABEL}
479 fi
480fi
439}481}
440482
441populate_boot() {483populate_boot() {
@@ -454,7 +496,7 @@
454 fi496 fi
455 497
456 mkdir -p "${BOOT_DISK}"498 mkdir -p "${BOOT_DISK}"
457 sudo mount ${MMC1} "${BOOT_DISK}"499 sudo mount ${BOOTFS} "${BOOT_DISK}"
458500
459 if [ -n "$UBOOT_FLAVOR" ]; then501 if [ -n "$UBOOT_FLAVOR" ]; then
460 sudo cp -v "binary/usr/lib/u-boot/${UBOOT_FLAVOR}/u-boot.bin" \502 sudo cp -v "binary/usr/lib/u-boot/${UBOOT_FLAVOR}/u-boot.bin" \
@@ -526,7 +568,7 @@
526 echo "Be patient, this may take a few minutes"568 echo "Be patient, this may take a few minutes"
527 echo ""569 echo ""
528 mkdir -p "${ROOT_DISK}"570 mkdir -p "${ROOT_DISK}"
529 sudo mount ${MMC2} "${ROOT_DISK}"571 sudo mount ${ROOTFS} "${ROOT_DISK}"
530572
531 sudo mv ${DIR}/binary/* "$ROOT_DISK"573 sudo mv ${DIR}/binary/* "$ROOT_DISK"
532574
@@ -539,7 +581,7 @@
539 echo "Creating SWAP File"581 echo "Creating SWAP File"
540 echo ""582 echo ""
541583
542 SPACE_LEFT=$(LC_ALL=C df "${ROOT_DISK}" | grep ${MMC2} | awk '{print $4}')584 SPACE_LEFT=$(LC_ALL=C df "${ROOT_DISK}" | grep ${ROOTFS} | awk '{print $4}')
543585
544 let SIZE=$SWAP_SIZE*1024586 let SIZE=$SWAP_SIZE*1024
545587
@@ -675,31 +717,30 @@
675TARGET_BOOT_DEV=/dev/mmcblk0p$(( 1 + $MMC_PART_OFFSET ))717TARGET_BOOT_DEV=/dev/mmcblk0p$(( 1 + $MMC_PART_OFFSET ))
676TARGET_ROOT_DEV=/dev/mmcblk0p$(( 2 + $MMC_PART_OFFSET ))718TARGET_ROOT_DEV=/dev/mmcblk0p$(( 2 + $MMC_PART_OFFSET ))
677719
678if [ ! "${MMC}" -a ! "${IMAGE_FILE}" ]; then720if [ ! "${DEVICE}" -a ! "${IMAGE_FILE}" ]; then
679 usage721 usage
680fi722fi
681723
724# The bootfs and rootfs deploy options are only available with physical
725# devives. These options are intended for deploying to different devices like
726# a USB drive and an MMC device. The options do not apply to qemu image_files.
727if [ "${IMAGE_FILE}" ]; then
728 if [ -z "${ROOTFS_STEP}" ] || [ -z "${BOOTFS_STEP}" ]; then
729 echo "Do not use --no-rootfs or --no-bootfs with the --image_file option"
730 exit
731 fi
732fi
733
682unpack_binary_tarball734unpack_binary_tarball
683if [ "$HWPACK_FILE" ]; then735if [ "$HWPACK_FILE" ]; then
684 install_hwpack736 install_hwpack
685else737else
686 echo "Warning, --hwpack <filename> was not specified, the result is unlikely to be functional without manual effort to setup uImage, MLO, u-boot.bin and so as as appropriate for your hardware."738 echo "Warning, --hwpack <filename> was not specified, the result is unlikely to be functional without manual effort to setup uImage, MLO, u-boot.bin and so as as appropriate for your hardware."
687fi739fi
688create_boot_cmd740get_device_by_id
689get_mmcs_by_id
690cleanup_sd741cleanup_sd
691create_partitions742for func in $DEPLOY_STEPS; do
692echo -n "waiting for partitioning to settle ..."743 $func
693sync744done
694sleep 3
695echo "done."
696get_mmcs_by_id
697if test -z "$MMC1" -o -z "$MMC2"; then
698 echo "MMC1: $MMC1 nor MMC2: $MMC2 must be empty"
699 exit 2
700fi
701prepare_partitions
702populate_boot
703populate_rootfs
704remove_binary_dir745remove_binary_dir
705746

Subscribers

People subscribed via source and target branches