From b344800aa68f923c979522612e08419bc10dc3e7 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Mon, 24 Sep 2012 17:15:21 -0400 Subject: [PATCH] build_image: clean up emit_gpt_scripts a bit Looks like the func was copy & pasted, so delete the first one (which doesn't get used). Then expand on the existing func to also generate a mount and an umount script. BUG=None TEST=ran build_image, then tested the mount/umount and unpack/pack scripts Change-Id: I34a372c7b4858b8e9057a29b2eb58c38d547eadd Reviewed-on: https://gerrit.chromium.org/gerrit/33929 Reviewed-by: Liam McLoughlin Tested-by: Liam McLoughlin Commit-Ready: Mike Frysinger Tested-by: Mike Frysinger --- build_library/disk_layout_util.sh | 93 +++++++++++++------------------ 1 file changed, 38 insertions(+), 55 deletions(-) diff --git a/build_library/disk_layout_util.sh b/build_library/disk_layout_util.sh index 719a4093b7..4c3c140b09 100644 --- a/build_library/disk_layout_util.sh +++ b/build_library/disk_layout_util.sh @@ -16,45 +16,6 @@ get_disk_layout_path() { done } -emit_gpt_scripts() { - local image="$1" - local dir="$2" - - local pack="${dir}/pack_partitions.sh" - local unpack="${dir}/unpack_partitions.sh" - - cat >"$unpack" <
> "$unpack" - - cat >>"${unpack}" <
&2 - exit 1 -fi -set -x -HEADER - - $GPT show "${image}" | sed -e 's/^/# /' >>"${unpack}" - cp "${unpack}" "${pack}" - - $GPT show -q "${image}" | - while read start size part x; do - local file="part_${part}" - local target="\"\${TARGET}\"" - local dd_args="bs=512 count=${size}" - echo "dd if=${target} of=${file} ${dd_args} skip=${start}" >>"${unpack}" - echo "dd if=${file} of=${target} ${dd_args} seek=${start} conv=notrunc" \ - >>"${pack}" - done - - chmod +x "${unpack}" "${pack}" -} - write_partition_script() { local image_type=$1 local partition_script_path=$2 @@ -139,32 +100,54 @@ emit_gpt_scripts() { local pack="${dir}/pack_partitions.sh" local unpack="${dir}/unpack_partitions.sh" + local mount="${dir}/mount_image.sh" + local umount="${dir}/umount_image.sh" - cat >"${unpack}" <
"${unpack}" <&2 +if [[ -z \${TARGET} ]]; then + echo "Usage: \$0 " 1>&2 + echo "Example: \$0 chromiumos_image.bin" 1>&2 exit 1 fi set -x -HEADER +$(${GPT} show "${image}" | sed -e 's/^/# /') +EOF - $GPT show "${image}" | sed -e 's/^/# /' >>"${unpack}" - cp "${unpack}" "${pack}" + for x in "${pack}" "${mount}" "${umount}"; do + cp "${unpack}" "${x}" + done - $GPT show -q "${image}" | - while read start size part x; do - local file="part_${part}" - local target="\"\$TARGET\"" - local dd_args="bs=512 count=${size}" - echo "dd if=${target} of=${file} ${dd_args} skip=${start}" >>"${unpack}" - echo "dd if=${file} of=${target} ${dd_args} seek=${start} conv=notrunc" \ - >>"${pack}" - done + while read start size part x; do + local file="part_${part}" + local dir="dir_${part}" + local target='"${TARGET}"' + local dd_args="bs=512 count=${size}" + local start_b=$(( start * 512 )) + local size_b=$(( size * 512 )) + echo "dd if=${target} of=${file} ${dd_args} skip=${start}" >>"${unpack}" + echo "dd if=${file} of=${target} ${dd_args} seek=${start} conv=notrunc" \ + >>"${pack}" + if [[ ${size} -gt 1 ]]; then + cat <<-EOF >>"${mount}" +mkdir -p ${dir} +sudo mount -o loop,offset=${start_b},sizelimit=${size_b} ${target} ${dir} || \ + rmdir ${dir} +EOF + cat <<-EOF >>"${umount}" +if [[ -d ${dir} ]]; then + sudo umount ${dir} || : + rmdir ${dir} +fi +EOF + fi + done < <(${GPT} show -q "${image}") - chmod +x "${unpack}" "${pack}" + chmod +x "${unpack}" "${pack}" "${mount}" "${umount}" } build_gpt() {