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

Proposed by Matt Waddel
Status: Rejected
Rejected by: Loïc Minier
Proposed branch: lp:~mwaddel/linaro-image-tools/split-deploy-v2
Merge into: lp:linaro-image-tools/11.11
Diff against target: 244 lines (+79/-36)
1 file modified
linaro-media-create (+79/-36)
To merge this branch: bzr merge lp:~mwaddel/linaro-image-tools/split-deploy-v2
Reviewer Review Type Date Requested Status
Linaro Maintainers Pending
Review via email: mp+38760@code.launchpad.net

Description of the change

Added the --no-rootfs, --no-bootfs and --no-part options.

Rearranged the code so these options could be generically added through a DEPLOY_STEPS="functions" mechanism.

These changes should not affect existing scripts or instructions. I tested on the vexpress and on a beagle qemu image deploy.

Incorporated previous code reviews.

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

r146:
- could you rename MMC1/MMC2, and get_mmcs_by_id() as well? you can do that in an additional commit on top
- "Storge" -- but that's ok, was actually fixed in r148
- you could have renamed --mmc, but I guess you didn't mean to break the external interface; ok with me

r147: good catch!

r148:
- testing for BOOTFS_STEP in create_boot_cmd() feels a bit awkard, it seems this code shouldn't be called in the first place!; I think I'd either:
  * test at the top
  * or merge this as a BOOTFS_STEP, that is, define BOOTFS_STEP="create_boot_cmd populate_boot", but I didn't actually check whether that works
  * or arrange for create_boot_cmd to be called from a bootfs step, e.g. from populate_boot
- the "parted -s ${DEVICE} mklabel msdos" bit should have been moved in a separate commit, it's unrelated and hard to read there :-/
- same for "waiting for partitioning to settle" snippet
- replace "if test -z "$MMC1"; then" with "if [ -z "$MMC1" ]; then"; why is this reached at all?
- instead of "for funcs in $DEPLOY_STEPS; do $funcs; done" it would be nicer to name your loop var singular instead of plural ($func)
- could you add a comment in the code to explain why this test is needed? echo "Do not use --no-rootfs or --no-bootfs with --image_file option"; people who ask for nothing get nothing ;-)

r149:
- "!" is a bit hard to read (inverted non-empty test); -z and -n are more common: if [ -z "${ROOTFS_STEP}" ] || [ -z "${BOOTFS_STEP}" ]; then

r150: cute!

Revision history for this message
Matt Waddel (mwaddel) wrote :

This branch has been superseded with all the corrections below integrated into:

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

On 10/18/2010 03:17 PM, Loïc Minier wrote:
> r146:
> - could you rename MMC1/MMC2, and get_mmcs_by_id() as well? you can do that in an additional commit on top

Fixed.

> - "Storge" -- but that's ok, was actually fixed in r148
> - you could have renamed --mmc, but I guess you didn't mean to break the external interface; ok with me

Yep, even though it's not exactly correct I thought it was important to not
break existing instructions.

>
> r147: good catch!
>
> r148:
> - testing for BOOTFS_STEP in create_boot_cmd() feels a bit awkard, it seems this code shouldn't be called in the first place!; I think I'd either:
> * test at the top
> * or merge this as a BOOTFS_STEP, that is, define BOOTFS_STEP="create_boot_cmd populate_boot", but I didn't actually check whether that works

+1, I liked this one the best since it retains the modularity of the script.

> * or arrange for create_boot_cmd to be called from a bootfs step, e.g. from populate_boot
> - the "parted -s ${DEVICE} mklabel msdos" bit should have been moved in a separate commit, it's unrelated and hard to read there :-/
> - same for "waiting for partitioning to settle" snippet

Got carried away in the this commit. There wasn't a nice place to
break up the commit...

> - replace "if test -z "$MMC1"; then" with "if [ -z "$MMC1" ]; then"; why is this reached at all?

I looked at this for a long time and decided this could fail if the
partitioning steps failed. It's unlikely, but possible.

> - instead of "for funcs in $DEPLOY_STEPS; do $funcs; done" it would be nicer to name your loop var singular instead of plural ($func)

Done.

> - could you add a comment in the code to explain why this test is needed? echo "Do not use --no-rootfs or --no-bootfs with --image_file option"; people who ask for nothing get nothing ;-)

Done.

>
> r149:
> - "!" is a bit hard to read (inverted non-empty test); -z and -n are more common: if [ -z "${ROOTFS_STEP}" ] || [ -z "${BOOTFS_STEP}" ]; then

Done.

>
> r150: cute!

Revision history for this message
Loïc Minier (lool) wrote :

On Tue, Oct 19, 2010, Matt Waddel wrote:
> > - replace "if test -z "$MMC1"; then" with "if [ -z "$MMC1" ]; then"; why is this reached at all?
>
> I looked at this for a long time and decided this could fail if the
> partitioning steps failed. It's unlikely, but possible.

 The partitioning step should cause the script to fail in this case
 though? (script is set -e)

 Checked your new branch; looks good!

--
Loïc Minier

Revision history for this message
Loïc Minier (lool) wrote :

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'linaro-media-create'
2--- linaro-media-create 2010-10-13 21:57:24 +0000
3+++ linaro-media-create 2010-10-18 19:21:26 +0000
4@@ -19,8 +19,8 @@
5
6 set -e
7
8-unset MMC MMC1 MMC2 MMC3 IMAGE_FILE HWPACK_FILE UBOOT_FLAVOR KERNEL_ADDR
9-unset INITRD_ADDR CREATE_SWAP SWAP_SIZE
10+unset DEVICE MMC1 MMC2 IMAGE_FILE HWPACK_FILE UBOOT_FLAVOR KERNEL_ADDR
11+unset INITRD_ADDR CREATE_SWAP SWAP_SIZE DEPLOY_STEPS
12
13 #Defaults
14 RFS=ext3
15@@ -31,6 +31,9 @@
16 FAT_SIZE=32
17 IMAGE_SIZE=2G
18 MMC_PART_OFFSET=0
19+BOOTFS_STEP="populate_boot"
20+ROOTFS_STEP="populate_rootfs"
21+PARTITION_STEP="create_partitions"
22
23 DIR=$PWD
24 TMP_DIR=$(mktemp -d)
25@@ -55,7 +58,7 @@
26
27 required options:
28 --mmc </dev/sdX>
29- Unformated MMC Card
30+ Unformatted Storage Device
31 <or>
32 --image_file <xxx>
33 specify name of image file
34@@ -108,14 +111,23 @@
35
36 --binary <filename>
37 specify file used to create the bootable system. Default binary-tar.tar.gz
38+
39+--no-rootfs
40+ do not deploy the root filesystem
41+
42+--no-bootfs
43+ do not deploy the boot filesystem
44+
45+--no-part
46+ reuse existing partitions on the deploy media
47 EOF
48 exit
49 }
50
51-check_mmc() {
52- FDISK=$(sudo LC_ALL=C sfdisk -l | grep "[Disk] ${MMC}" | awk '{print $2}')
53+check_device() {
54+ FDISK=$(sudo LC_ALL=C sfdisk -l | grep "[Disk] ${DEVICE}" | awk '{print $2}')
55
56- if test "-$FDISK-" = "-$MMC:-"
57+ if test "-$FDISK-" = "-$DEVICE:-"
58 then
59 echo ""
60 echo "I see..."
61@@ -125,12 +137,12 @@
62 echo "mount:"
63 LC_ALL=C mount | grep -v none | grep "/dev/" --color=never
64 echo ""
65- read -p "Are you 100% sure, on selecting [${MMC}] (y/n)? "
66+ read -p "Are you 100% sure, on selecting [${DEVICE}] (y/n)? "
67 [ "$REPLY" == "y" ] || exit
68 echo ""
69 else
70 echo ""
71- echo "Are you sure? I Don't see [${MMC}], here is what I do see..."
72+ echo "Are you sure? I Don't see [${DEVICE}], here is what I do see..."
73 echo ""
74 echo "sudo sfdisk -l:"
75 sudo LC_ALL=C sfdisk -l | grep "[Disk] /dev/" --color=never
76@@ -176,8 +188,8 @@
77 ;;
78 --mmc)
79 checkparm "$2"
80- MMC="$2"
81- check_mmc
82+ DEVICE="$2"
83+ check_device
84 ;;
85 --image_file)
86 checkparm "$2"
87@@ -224,10 +236,21 @@
88 checkparm "$2"
89 BINARY_TARBALL="$2"
90 ;;
91+ --no-rootfs)
92+ ROOTFS_STEP=""
93+ ;;
94+ --no-bootfs)
95+ BOOTFS_STEP=""
96+ ;;
97+ --no-part)
98+ PARTITION_STEP=""
99+ ;;
100 esac
101 shift
102 done
103
104+DEPLOY_STEPS="$PARTITION_STEP prepare_partitions $BOOTFS_STEP $ROOTFS_STEP"
105+
106 ensure_command mkimage uboot-mkimage
107 ensure_command uuidgen uuid-runtime
108 ensure_command parted parted
109@@ -257,10 +280,10 @@
110 get_mmcs_by_id() {
111 if [ ! "${IMAGE_FILE}" ]; then
112 for device in /dev/disk/by-id/*; do
113- if [ `realpath $device` = $MMC ]; then
114+ if [ `realpath $device` = $DEVICE ]; then
115 case "$device" in
116 *-part[0-9]*)
117- echo "device $MMC must not be a partition part ($device)" >&2
118+ echo "device $DEVICE must not be a partition part ($device)" >&2
119 exit 1
120 ;;
121 esac
122@@ -273,8 +296,6 @@
123 MMC1=$part
124 elif test "$part_no" = $((2 + $MMC_PART_OFFSET)) ; then
125 MMC2=$part
126- elif test "$part_no" = $((3 + $MMC_PART_OFFSET)); then
127- MMC3=$part
128 fi
129 done
130 break
131@@ -335,6 +356,10 @@
132 }
133
134 create_boot_cmd() {
135+ if [ ! "$BOOTFS_STEP" ]; then
136+ return
137+ fi
138+
139 if [ "$IS_LIVE" ]; then
140 boot_snippet='boot=casper'
141 [ "$IS_LOWMEM" ] && lowmem_opt=only-ubiquity
142@@ -373,16 +398,17 @@
143 if test -n "$MMC2"; then
144 sudo umount ${MMC2} &> /dev/null || true
145 fi
146- if [ "${MMC}" ]; then
147- sudo parted -s ${MMC} mklabel msdos
148- fi
149 }
150
151 create_partitions() {
152+ if [ "${DEVICE}" ]; then
153+ sudo parted -s ${DEVICE} mklabel msdos
154+ fi
155+
156 if [ "${IMAGE_FILE}" ]; then
157 partdev=${IMAGE_FILE}
158 else
159- partdev=${MMC}
160+ partdev=${DEVICE}
161 fi
162
163 if [ "$FAT_SIZE" = "32" ]; then
164@@ -426,16 +452,36 @@
165
166
167 prepare_partitions() {
168+
169+echo -n "waiting for partitioning to settle ..."
170+sync
171+sleep 3
172+echo "done."
173+get_mmcs_by_id
174+
175+if [ "$BOOTFS_STEP" ]; then
176 echo ""
177 echo "Formating Boot Partition"
178 echo ""
179-
180- sudo mkfs.vfat -F ${FAT_SIZE} ${MMC1} -n ${BOOT_LABEL}
181-
182+ if test -z "$MMC1"; then
183+ echo "Partition $MMC1 does not exist"
184+ exit 2
185+ else
186+ sudo mkfs.vfat -F ${FAT_SIZE} ${MMC1} -n ${BOOT_LABEL}
187+ fi
188+fi
189+
190+if [ "$ROOTFS_STEP" ]; then
191 echo ""
192 echo "Formating ${RFS} Partition"
193 echo ""
194- sudo mkfs.${RFS} -U "$RFS_UUID" ${MMC2} -L ${RFS_LABEL}
195+ if test -z "$MMC2"; then
196+ echo "Partition $MMC2 does not exist"
197+ exit 2
198+ else
199+ sudo mkfs.${RFS} -U "$RFS_UUID" ${MMC2} -L ${RFS_LABEL}
200+ fi
201+fi
202 }
203
204 populate_boot() {
205@@ -675,10 +721,17 @@
206 TARGET_BOOT_DEV=/dev/mmcblk0p$(( 1 + $MMC_PART_OFFSET ))
207 TARGET_ROOT_DEV=/dev/mmcblk0p$(( 2 + $MMC_PART_OFFSET ))
208
209-if [ ! "${MMC}" -a ! "${IMAGE_FILE}" ]; then
210+if [ ! "${DEVICE}" -a ! "${IMAGE_FILE}" ]; then
211 usage
212 fi
213
214+if [ "${IMAGE_FILE}" ]; then
215+ if [ ! "${ROOTFS_STEP}" ] || [ ! "${BOOTFS_STEP}" ]; then
216+ echo "Do not use --no-rootfs or --no-bootfs with --image_file option"
217+ exit
218+ fi
219+fi
220+
221 unpack_binary_tarball
222 if [ "$HWPACK_FILE" ]; then
223 install_hwpack
224@@ -688,18 +741,8 @@
225 create_boot_cmd
226 get_mmcs_by_id
227 cleanup_sd
228-create_partitions
229-echo -n "waiting for partitioning to settle ..."
230-sync
231-sleep 3
232-echo "done."
233-get_mmcs_by_id
234-if test -z "$MMC1" -o -z "$MMC2"; then
235- echo "MMC1: $MMC1 nor MMC2: $MMC2 must be empty"
236- exit 2
237-fi
238-prepare_partitions
239-populate_boot
240-populate_rootfs
241+for funcs in $DEPLOY_STEPS; do
242+ $funcs
243+done
244 remove_binary_dir
245

Subscribers

People subscribed via source and target branches