From 98915b5536f3099a78bddc4be6a44bb25d412a15 Mon Sep 17 00:00:00 2001 From: Ayan Kumar Halder Date: Mon, 18 Oct 2021 19:44:49 +0100 Subject: Add an option to specify the alignment for the image "petalinux-boot --qemu" when used with a sd image, expects the image to be of size which is power of 2. Thus, one needs to provide an option to disk_image to create images aligned to the next power of two. Signed-off-by: Ayan Kumar Halder Signed-off-by: Stefano Stabellini Reviewed-by: Stefano Stabellini --- scripts/disk_image | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'scripts/disk_image') diff --git a/scripts/disk_image b/scripts/disk_image index 1d71863..56a80fc 100755 --- a/scripts/disk_image +++ b/scripts/disk_image @@ -146,6 +146,24 @@ function add_partition() _npart=$(( $_npart + 1 )) } +function align_size_power_of_two() +{ + local _cnt_bits=0 + local num=$1 + local _num=$num + while [ $_num -ne 0 ] + do + _num=$((_num >> 1)) + _cnt_bits=$((_cnt_bits + 1)) + done + _num=$((1<<(_cnt_bits - 1))) + if [ $num -gt $_num ] + then + _num=$((1<<_cnt_bits)) + fi + echo $_num +} + function write_rootfs() { local j=$1 @@ -177,7 +195,7 @@ function write_rootfs() function print_help { echo "usage:" - echo " $0 -c CONFIG_FILE -d UBOOT_DIRECTORY -t UBOOT_TYPE <-w WORK_DIRECTORY> <-s SLACK> -o IMG_FILE" + echo " $0 -c CONFIG_FILE -d UBOOT_DIRECTORY -t UBOOT_TYPE <-w WORK_DIRECTORY> <-s SLACK> <-a> -o IMG_FILE" echo " $0 -h" echo "where:" echo " -c CONFIG_FILE - configuration file" @@ -189,6 +207,7 @@ function print_help echo " < > - used for uboot load commands" echo " -w WORK_DIRECTORY - work directory used when building the image" echo " -s SLACK - free MB to add to each partition, default 128" + echo " -a specifies that the size of IMG_FILE has to be aligned to the nearest power of two" echo " -o IMG_FILE - the output img file " echo "Example:" echo " $0 -c ../config -d ./build42 -w tmp -o disk.img" @@ -201,7 +220,7 @@ then exit 1 fi -while getopts ":w:d:c:t:s:o:h" opt +while getopts ":w:d:c:t:s:o:ah" opt do case ${opt} in t ) @@ -240,6 +259,9 @@ do o ) IMG=$OPTARG ;; + a ) + ALIGN=1 + ;; h ) print_help exit 0 @@ -377,6 +399,12 @@ do done _tot_size=$(( $_tot_size + 16 )) +# NOTE: Increase the size of the image to the nearest power of two +if test "$ALIGN" +then + _tot_size=$(align_size_power_of_two $_tot_size) +fi + # NOTE: Increase vos_a to 256 to accomodate rootfs # 528 MiB (256 + 256 + 16) truncate $IMG -s "$_tot_size"M -- cgit v1.2.3