From 8d5f0e60de4f0d77afdf1fc542d87aeceeca1841 Mon Sep 17 00:00:00 2001 From: Hung-Te Lin Date: Wed, 13 Jul 2011 19:08:01 +0800 Subject: [PATCH] make_universal_factory_shim: support "-m" to assign master (base) image Some images (especially RMA) need to use stateful or other lagacy stuff from other image files. This CL adds "-m" to make_universal_factory_shim so that we can change the master image (the one for all legacy / stateful partition). BUG=chrome-os-partner:4108 TEST=./make_universal_factory_shim.sh -m factory_test.bin \ factory_install.bin factory_test.bin release_image.bin Change-Id: I6c8e096fd7ae921a4fb157c035f575a7c3b33834 Reviewed-on: http://gerrit.chromium.org/gerrit/4020 Reviewed-by: Nick Sanders Tested-by: Hung-Te Lin --- make_universal_factory_shim.sh | 78 ++++++++++++++++++++++++++-------- 1 file changed, 60 insertions(+), 18 deletions(-) diff --git a/make_universal_factory_shim.sh b/make_universal_factory_shim.sh index e8903db2a7..0791f70515 100755 --- a/make_universal_factory_shim.sh +++ b/make_universal_factory_shim.sh @@ -52,6 +52,7 @@ image_copy_partition() { local from_part="$2" local to_image="$3" local to_part="$4" + local bs="$CGPT_BS" local from_offset="$(image_get_partition_offset "$from_image" "$from_part")" local from_size="$(image_get_partition_size "$from_image" "$from_part")" @@ -62,9 +63,29 @@ image_copy_partition() { die "Failed to copy partition: $from_image#$from_part -> $to_image#$to_part" fi - # TODO(hungte) Speed up by increasing bs - dd if="$from_image" of="$to_image" bs="$CGPT_BS" conv=notrunc \ - count=$from_size skip="$from_offset" seek="$to_offset" + # Seed up by increasing block size + # TODO(hungte) improve obs calculation or change offsets + while [ "$((from_size > 0 && + from_size % 2 == 0 && + from_offset % 2 == 0 && + to_offset % 2 == 0))" = "1" ]; do + bs=$((bs * 2)) + from_size=$((from_size / 2)) + from_offset=$((from_offset / 2)) + to_offset=$((to_offset / 2)) + done + + # Display progress if the partition is larger than 32M. + if [ "$((from_size * bs > 32 * 1048576))" = "1" ] && type pv >/dev/null 2>&1 + then + dd if="$from_image" bs="$bs" count=$from_size skip="$from_offset" | + pv -B "$bs" -s "$((bs * from_size))" | + dd of="$to_image" bs="$bs" count="$from_size" seek="$to_offset" \ + conv=notrunc iflag=fullblock + else + dd if="$from_image" of="$to_image" bs="$bs" conv=notrunc \ + count=$from_size skip="$from_offset" seek="$to_offset" + fi } images_get_total_size() { @@ -72,13 +93,16 @@ images_get_total_size() { local total="0" local index + # reference, slot_a, slot_b, slot_c. + [ "$#" = 4 ] || die "incorrect call to images_get_total_size" + # copy most partitions from first image total="$((total + CGPT_START_SIZE + CGPT_END_SIZE))" for index in $STATE_PARTITION $LEGACY_PARTITIONS; do total="$((total + $(image_get_partition_size "$1" $index) ))" done - for image in "$1" "$2" "$3"; do + for image in "$2" "$3" "$4"; do if [ -z "$image" ]; then total="$((total + $(image_get_partition_size "$1" $RESERVED_PARTITION)))" total="$((total + $(image_get_partition_size "$1" $RESERVED_PARTITION)))" @@ -115,35 +139,53 @@ image_append_partition() { main() { local force="" - if [ "$1" = "-f" ]; then - shift - force="True" - fi + local image="" + local output="" + local main_source="" + local index="" + local slots="0" + + while [ "$#" -gt 1 ]; do + case "$1" in + "-f" ) + force="True" + shift + ;; + "-m" ) + main_source="$2" + shift + shift + ;; + * ) + break + esac + done + if [ "$#" -lt 2 -o "$#" -gt 4 ]; then - echo "Usage: $SCRIPT [-f] output shim_image_1 [shim_2 [shim_3]]" + echo "Usage: $SCRIPT [-m master] [-f] output shim_image_1 [shim_2 [shim_3]]" exit 1 fi - local image="" - local output="$1" - local main_source="$2" - local index="" - local slots="0" + if [ -z "$main_source" ]; then + main_source="$2" + fi + output="$1" shift if [ -f "$output" -a -z "$force" ]; then die "Output file $output already exists. To overwrite the file, add -f." fi - for image in "$@"; do + for image in "$main_source" "$@"; do if [ ! -f "$image" ]; then die "Cannot find input file $image." fi done # build output - local total_size="$(images_get_total_size "$@")" + local total_size="$(images_get_total_size "$main_source" "$@")" # echo "Total size from [$@]: $total_size" - truncate "$output" -s "$((total_size * CGPT_BS))" + truncate -s "0" "$output" # starting with a new file is much faster. + truncate -s "$((total_size * CGPT_BS))" "$output" cgpt create "$output" cgpt boot -p "$output" @@ -153,7 +195,7 @@ main() { local rootfs_part=3 for image in "$1" "$2" "$3"; do if [ -z "$image" ]; then - image="$1" + image="$main_source" kpart="$RESERVED_PARTITION" rootfs_part="$RESERVED_PARTITION" fi