common: mk-image.sh: support build different page/block size for ubi image

Signed-off-by: Weiwen Chen <cww@rock-chips.com>
Change-Id: Ic04f8780846c9480ace4c124a59a398baf69f08f
This commit is contained in:
Weiwen Chen
2021-01-07 11:50:40 +08:00
parent 198d47f525
commit bc93f2e606

View File

@ -7,6 +7,7 @@ fi
# Prefer using buildroot host tools for compatible.
HOST_DIR=$TARGET_OUTPUT_DIR/host
BUILDROOT_IMAGE_DIR=$HOST_DIR/../images/
export PATH=$HOST_DIR/usr/sbin:$HOST_DIR/usr/bin:$HOST_DIR/sbin:$HOST_DIR/bin:$PATH
fatal()
@ -30,9 +31,9 @@ SIZE=$4
if [ "$FS_TYPE" = "ubi" ]; then
UBI_VOL_NAME=${5:-test}
# default page size 2KB
UBI_PAGE_SIZE=${6:-2048}
DEFAULT_UBI_PAGE_SIZE=${6:-2048}
# default block size 128KB
UBI_BLOCK_SIZE=${7:-0x20000}
DEFAULT_UBI_BLOCK_SIZE=${7:-0x20000}
fi
TEMP=$(mktemp -u)
@ -137,8 +138,30 @@ mkimage_auto_sized()
mk_ubi_image()
{
temp_dir="`dirname $TARGET`"
temp_ubifs_image=$temp_dir/temp.ubifs
temp_ubinize_file=$temp_dir/ubinize.cfg
if [ $(( $UBI_BLOCK_SIZE )) -eq $(( 0x20000 )) ]; then
ubi_block_size_str="128KB"
elif [ $(( $UBI_BLOCK_SIZE )) -eq $(( 0x40000 )) ]; then
ubi_block_size_str="256KB"
else
echo "Error: Please add ubi block size [$UBI_BLOCK_SIZE] to $PWD/$0"
exit 1
fi
if [ $(( $UBI_PAGE_SIZE )) -eq 2048 ]; then
ubi_page_size_str="2KB"
elif [ $(( $UBI_PAGE_SIZE )) -eq 4096 ]; then
ubi_page_size_str="4KB"
else
echo "Error: Please add ubi block size [$UBI_PAGE_SIZE] to $PWD/$0"
exit 1
fi
if [ -z "$UBI_VOL_NAME" ]; then
echo "Error: Please config ubifs partition volume name"
exit 1
fi
ubifs_lebsize=$(( $UBI_BLOCK_SIZE - 2 * $UBI_PAGE_SIZE ))
ubifs_miniosize=$UBI_PAGE_SIZE
partition_size=$(( $SIZE ))
@ -147,6 +170,12 @@ mk_ubi_image()
echo "Error: ubifs partition MUST set partition size"
exit 1
fi
partition_size_str="$(( $partition_size / 1024 / 1024 ))MB"
output_image=${temp_dir}/${UBI_VOL_NAME}_${ubi_page_size_str}_${ubi_block_size_str}_${partition_size_str}.ubi
temp_ubifs_image=$BUILDROOT_IMAGE_DIR/${UBI_VOL_NAME}_${ubi_page_size_str}_${ubi_block_size_str}_${partition_size_str}.ubifs
temp_ubinize_file=$BUILDROOT_IMAGE_DIR/${UBI_VOL_NAME}_${ubi_page_size_str}_${ubi_block_size_str}_${partition_size_str}_ubinize.cfg
ubifs_maxlebcnt=$(( $partition_size / $ubifs_lebsize ))
echo "ubifs_lebsize=$UBI_BLOCK_SIZE"
@ -162,8 +191,13 @@ mk_ubi_image()
echo "vol_alignment=1" >> $temp_ubinize_file
echo "vol_flags=autoresize" >> $temp_ubinize_file
echo "image=$temp_ubifs_image" >> $temp_ubinize_file
ubinize -o $TARGET -m $ubifs_miniosize -p $UBI_BLOCK_SIZE -v $temp_ubinize_file
rm -f $temp_ubifs_image $temp_ubinize_file
ubinize -o $output_image -m $ubifs_miniosize -p $UBI_BLOCK_SIZE -v $temp_ubinize_file
# Pick a default ubi image
if [ $(( $DEFAULT_UBI_PAGE_SIZE )) -eq $(( $UBI_PAGE_SIZE )) \
-a $(( $DEFAULT_UBI_BLOCK_SIZE )) -eq $(( $UBI_BLOCK_SIZE )) ]; then
ln -rfs $output_image $TARGET
fi
}
rm -rf $TARGET
@ -179,6 +213,16 @@ case $FS_TYPE in
fi
;;
ubi)
UBI_PAGE_SIZE=2048
UBI_BLOCK_SIZE=0x20000
mk_ubi_image
UBI_PAGE_SIZE=2048
UBI_BLOCK_SIZE=0x40000
mk_ubi_image
UBI_PAGE_SIZE=4096
UBI_BLOCK_SIZE=0x40000
mk_ubi_image
;;
*)