summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Chen <philipchen@google.com>2018-09-21 15:02:32 -0700
committerchrome-bot <chrome-bot@chromium.org>2018-09-26 10:33:21 -0700
commitc297fe4ddfaf0d9308955a5c41da5074e34324e7 (patch)
tree3fae73c4768c899b37bb2e6e739e2403e50495fd
parentf55573cee45f0392806333166cd040c99825e488 (diff)
downloadvboot-c297fe4ddfaf0d9308955a5c41da5074e34324e7.tar.gz
make_dev_ssd: Support non-512B block size
BUG=b:114610466 BRANCH=none TEST=(1)Test cheza, whose storage has a block size of 4k: $ make_dev_ssd.sh --remove_rootfs_verification --partitions 2 $ make_dev_ssd.sh --partitions 2 --save_config /tmp/foo_config $ echo "console=ttyMSM0,115200n8" >> /tmp/foo_config.2 $ make_dev_ssd.sh --partitions 2 --set_config /tmp/foo_config Messages show kernel is successfully re-signed. Reboot and then see kernel log printed. Also, rootfs is modifiable. (2)Do a similar test on scarlet, whose storage has a block size of 512B. See the same result. Change-Id: Ic5d7714e4f608c477f935d244cd5ad62eb38815a Signed-off-by: Philip Chen <philipchen@google.com> Reviewed-on: https://chromium-review.googlesource.com/1240934 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: Philip Chen <philipchen@chromium.org> Reviewed-by: Hung-Te Lin <hungte@chromium.org> Reviewed-by: Evan Green <evgreen@chromium.org> Reviewed-by: Mike Frysinger <vapier@chromium.org>
-rw-r--r--scripts/image_signing/common_minimal.sh20
-rwxr-xr-xscripts/image_signing/make_dev_ssd.sh9
2 files changed, 22 insertions, 7 deletions
diff --git a/scripts/image_signing/common_minimal.sh b/scripts/image_signing/common_minimal.sh
index c57fc90d..8166d698 100644
--- a/scripts/image_signing/common_minimal.sh
+++ b/scripts/image_signing/common_minimal.sh
@@ -137,6 +137,20 @@ make_partition_dev() {
fi
}
+# Find the block size of a device in bytes
+# Args: DEVICE (e.g. /dev/sda)
+# Return: block size in bytes
+blocksize() {
+ local output=''
+ local path="$1"
+ if [ -b "${path}" ]; then
+ local dev="${path##*/}"
+ local sys="/sys/block/${dev}/queue/logical_block_size"
+ output="$(cat "${sys}" 2>/dev/null)"
+ fi
+ echo "${output:-512}"
+}
+
# Read GPT table to find the starting location of a specific partition.
# Args: DEVICE PARTNUM
# Returns: offset (in sectors) of partition PARTNUM
@@ -186,7 +200,8 @@ _mount_image_partition_retry() {
local partnum=$2
local mount_dir=$3
local ro=$4
- local offset=$(( $(partoffset "${image}" "${partnum}") * 512 ))
+ local bs="$(blocksize "${image}")"
+ local offset=$(( $(partoffset "${image}" "${partnum}") * bs ))
local out try
set -- sudo LC_ALL=C mount -o loop,offset=${offset},${ro} \
@@ -225,7 +240,8 @@ _mount_image_partition() {
local partnum=$2
local mount_dir=$3
local ro=$4
- local offset=$(( $(partoffset "${image}" "${partnum}") * 512 ))
+ local bs="$(blocksize "${image}")"
+ local offset=$(( $(partoffset "${image}" "${partnum}") * bs ))
if [ "$ro" != "ro" ]; then
# Forcibly call enable_rw_mount. It should fail on unsupported
diff --git a/scripts/image_signing/make_dev_ssd.sh b/scripts/image_signing/make_dev_ssd.sh
index b08ca48c..5871a190 100755
--- a/scripts/image_signing/make_dev_ssd.sh
+++ b/scripts/image_signing/make_dev_ssd.sh
@@ -144,13 +144,12 @@ find_valid_kernel_partitions() {
# Resigns a kernel on SSD or image.
resign_ssd_kernel() {
- # bs=512 is the fixed block size for dd and cgpt
- local bs=512
local ssd_device="$1"
+ local bs="$(blocksize "${ssd_device}")"
# reasonable size for current kernel partition
- local min_kernel_size=16000
- local max_kernel_size=65536
+ local min_kernel_size=$((8000 * 1024 / bs))
+ local max_kernel_size=$((32768 * 1024 / bs))
local resigned_kernels=0
for kernel_index in $FLAGS_partitions; do
@@ -302,7 +301,7 @@ resign_ssd_kernel() {
# (3) change kernel config to rw
if [ ${FLAGS_remove_rootfs_verification} = $FLAGS_TRUE ]; then
local root_offset_sector=$(partoffset "$ssd_device" $rootfs_index)
- local root_offset_bytes=$((root_offset_sector * 512))
+ local root_offset_bytes=$((root_offset_sector * bs))
if ! is_ext2 "$ssd_device" "$root_offset_bytes"; then
debug_msg "Non-ext2 partition: $ssd_device$rootfs_index, skip."
elif ! rw_mount_disabled "$ssd_device" "$root_offset_bytes"; then