scripts: ubinize-image.sh: fix on POSIX shell, allow custom images

Make sure ubinize-image.sh also works with more simple POSIX Shell and
allow creating complete custom images to be used as ARTIFACT/foo.img
and thereby allow including uImage.FIT, TF-A FIP and what ever else
is required on a specific board.

Fixes: 6c17d71973 ("scripts: ubinize-image.sh: support static volumes, make size optional")
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
This commit is contained in:
Daniel Golle 2024-02-16 05:32:51 +00:00
parent dc0cf0fc50
commit 67beab2b2b
2 changed files with 31 additions and 20 deletions

View File

@ -138,11 +138,9 @@ UBI_NAND_SIZE_LIMIT = $(IMAGE_SIZE) - ($(NAND_SIZE)*20/1024 + 4*$(BLOCKSIZE))
define Build/append-ubi define Build/append-ubi
sh $(TOPDIR)/scripts/ubinize-image.sh \ sh $(TOPDIR)/scripts/ubinize-image.sh \
$(if $(UBOOTENV_IN_UBI),--uboot-env) \ $(if $(UBOOTENV_IN_UBI),--uboot-env) \
$(foreach part,$(UBINIZE_PARTS),--part $(part)) \
$(if $(findstring fit,$(1)), \
$(if $(KERNEL_IN_UBI),--part fit=$(IMAGE_KERNEL)), \
$(if $(KERNEL_IN_UBI),--kernel $(IMAGE_KERNEL)) \ $(if $(KERNEL_IN_UBI),--kernel $(IMAGE_KERNEL)) \
--rootfs $(IMAGE_ROOTFS)) \ $(foreach part,$(UBINIZE_PARTS),--part $(part)) \
--rootfs $(IMAGE_ROOTFS) \
$@.tmp \ $@.tmp \
-p $(BLOCKSIZE:%k=%KiB) -m $(PAGESIZE) \ -p $(BLOCKSIZE:%k=%KiB) -m $(PAGESIZE) \
$(if $(SUBPAGESIZE),-s $(SUBPAGESIZE)) \ $(if $(SUBPAGESIZE),-s $(SUBPAGESIZE)) \
@ -154,6 +152,18 @@ define Build/append-ubi
$(call Build/check-size,$(UBI_NAND_SIZE_LIMIT))) $(call Build/check-size,$(UBI_NAND_SIZE_LIMIT)))
endef endef
define Build/ubinize-image
sh $(TOPDIR)/scripts/ubinize-image.sh \
$(if $(UBOOTENV_IN_UBI),--uboot-env) \
$(foreach part,$(UBINIZE_PARTS),--part $(part)) \
--part $(word 1,$(1))="$(BIN_DIR)/$(DEVICE_IMG_PREFIX)-$(word 2,$(1))" \
$@ \
-p $(BLOCKSIZE:%k=%KiB) -m $(PAGESIZE) \
$(if $(SUBPAGESIZE),-s $(SUBPAGESIZE)) \
$(if $(VID_HDR_OFFSET),-O $(VID_HDR_OFFSET)) \
$(UBINIZE_OPTS)
endef
define Build/ubinize-kernel define Build/ubinize-kernel
cp $@ $@.tmp cp $@ $@.tmp
sh $(TOPDIR)/scripts/ubinize-image.sh \ sh $(TOPDIR)/scripts/ubinize-image.sh \

View File

@ -12,10 +12,10 @@ err=""
ubinize_seq="" ubinize_seq=""
ubivol() { ubivol() {
local volid=$1 local volid="$1"
local name=$2 local name="$2"
local image=$3 local image="$3"
local autoresize=$4 local autoresize="$4"
local size="$5" local size="$5"
local voltype="${6:-dynamic}" local voltype="${6:-dynamic}"
echo "[$name]" echo "[$name]"
@ -36,16 +36,17 @@ ubivol() {
ubilayout() { ubilayout() {
local vol_id=0 local vol_id=0
local rootsize= local rootsize
local autoresize= local autoresize
local rootfs_type="$( get_fs_type "$2" )" local rootfs_type
local voltype local voltype
rootfs_type="$( get_fs_type "$2" )"
if [ "$1" = "ubootenv" ]; then if [ "$1" = "ubootenv" ]; then
ubivol $vol_id ubootenv ubivol $vol_id ubootenv
vol_id=$(( $vol_id + 1 )) vol_id=$(( vol_id + 1 ))
ubivol $vol_id ubootenv2 ubivol $vol_id ubootenv2
vol_id=$(( $vol_id + 1 )) vol_id=$(( vol_id + 1 ))
fi fi
for part in $parts; do for part in $parts; do
name="${part%%=*}" name="${part%%=*}"
@ -55,9 +56,9 @@ ubilayout() {
[ "$prev" = "$part" ] && part= [ "$prev" = "$part" ] && part=
image="${part%%=*}" image="${part%%=*}"
if [ "${image:0:1}" = ":" ]; then if [ "${image#:}" != "$image" ]; then
voltype=static voltype=static
image="${image:1}" image="${image#:}"
fi fi
prev="$part" prev="$part"
part="${part#*=}" part="${part#*=}"
@ -71,11 +72,11 @@ ubilayout() {
fi fi
ubivol $vol_id "$name" "$image" "" "${size}" "$voltype" ubivol $vol_id "$name" "$image" "" "${size}" "$voltype"
vol_id=$(( $vol_id + 1 )) vol_id=$(( vol_id + 1 ))
done done
if [ "$3" ]; then if [ "$3" ]; then
ubivol $vol_id kernel "$3" ubivol $vol_id kernel "$3"
vol_id=$(( $vol_id + 1 )) vol_id=$(( vol_id + 1 ))
fi fi
if [ "$2" ]; then if [ "$2" ]; then
@ -91,7 +92,7 @@ ubilayout() {
esac esac
ubivol $vol_id rootfs "$2" "$autoresize" "$rootsize" dynamic ubivol $vol_id rootfs "$2" "$autoresize" "$rootsize" dynamic
vol_id=$(( $vol_id + 1 )) vol_id=$(( vol_id + 1 ))
[ "$rootfs_type" = "ubifs" ] || ubivol $vol_id rootfs_data "" 1 dymamic [ "$rootfs_type" = "ubifs" ] || ubivol $vol_id rootfs_data "" 1 dymamic
fi fi
} }
@ -128,7 +129,7 @@ while [ "$1" ]; do
continue continue
;; ;;
"-"*) "-"*)
ubinize_param="$@" ubinize_param="$*"
break break
;; ;;
*) *)
@ -141,7 +142,7 @@ while [ "$1" ]; do
esac esac
done done
if [ ! -r "$rootfs" -a ! -r "$kernel" -a ! "$outfile" ]; then if [ ! -r "$rootfs" ] && [ ! -r "$kernel" ] && [ ! "$parts" ] && [ ! "$outfile" ]; then
echo "syntax: $0 [--uboot-env] [--part <name>=<file>] [--kernel kernelimage] [--rootfs rootfsimage] out [ubinize opts]" echo "syntax: $0 [--uboot-env] [--part <name>=<file>] [--kernel kernelimage] [--rootfs rootfsimage] out [ubinize opts]"
exit 1 exit 1
fi fi