From e7ea0706442f80524ba0a385e9065d0c95ecbffc Mon Sep 17 00:00:00 2001 From: Hung-Te Lin Date: Tue, 28 Jun 2011 18:23:10 +0800 Subject: [PATCH] make_factory_package: allow updating HWID for image creation BUG=chromium-os:16733 TEST=./make_factory_package --release RELEASE \ --factory FACTORY --hwid HWID_UPDATER \ --diskimg IMAGE_FILE Change-Id: I1a817e1f176d22d830bf0ce8a6ccb6956086f749 Reviewed-on: http://gerrit.chromium.org/gerrit/3306 Reviewed-by: Jay Kim Tested-by: Hung-Te Lin --- lib/cros_image_common.sh | 8 ++++---- make_factory_package.sh | 13 +++++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/cros_image_common.sh b/lib/cros_image_common.sh index b9e2802c09..fce82b1bcc 100644 --- a/lib/cros_image_common.sh +++ b/lib/cros_image_common.sh @@ -129,7 +129,7 @@ image_map_partition() { local size="$(image_part_size "$file" "$part_num")" || image_die "failed to find partition #$part_num from: $file" - losetup --offset $((offset * 512)) --sizelimit=$((size * 512)) \ + sudo losetup --offset $((offset * 512)) --sizelimit=$((size * 512)) \ -f --show "$file" } @@ -137,7 +137,7 @@ image_map_partition() { image_unmap_partition() { local map_point="$1" - losetup -d "$map_point" + sudo losetup -d "$map_point" } # Mounts a specific partition inside a given image file @@ -156,7 +156,7 @@ image_mount_partition() { mount_opt=",ro" fi - mount \ + sudo mount \ -o "loop,offset=$((offset * 512)),sizelimit=$((size * 512)),$mount_opt" \ "$file" \ "$mount_point" @@ -166,7 +166,7 @@ image_mount_partition() { image_umount_partition() { local mount_point="$1" - umount -d "$mount_point" + sudo umount -d "$mount_point" } # Copy a partition from one image to another. diff --git a/make_factory_package.sh b/make_factory_package.sh index dcbf9449a2..fb9eeb2d48 100755 --- a/make_factory_package.sh +++ b/make_factory_package.sh @@ -245,6 +245,11 @@ umount_esp() { generate_img() { local outdev="$(readlink -f "$FLAGS_diskimg")" local sectors="$FLAGS_sectors" + local hwid_updater="${FLAGS_hwid_updater}" + + if [ -n "${FLAGS_hwid_updater}" ]; then + hwid_updater="$(readlink -f "$FLAGS_hwid_updater")" + fi prepare_img @@ -272,6 +277,14 @@ generate_img() { echo "EFI Partition" image_partition_copy "${FACTORY_IMAGE}" 12 "${outdev}" 12 + if [ -n "${hwid_updater}" ]; then + local state_dev="$(image_map_partition "${outdev}" 1)" + local hwid_result="0" + sudo sh "$hwid_updater" "$state_dev" || hwid_result="$?" + image_unmap_partition "$state_dev" || true + [ $hwid_result = "0" ] || die "Failed to update HWID ($hwid_result). abort." + fi + # TODO(nsanders, wad): consolidate this code into some common code # when cleaning up kernel commandlines. There is code that touches # this in postint/chromeos-setimage and build_image. However none