[openwrt/openwrt] scripts: ubinize-image.sh: fix on POSIX shell, allow custom images
LEDE Commits
lede-commits at lists.infradead.org
Thu Feb 15 21:41:42 PST 2024
dangole pushed a commit to openwrt/openwrt.git, branch main:
https://git.openwrt.org/67beab2b2b39c4fe3e48a021aefbfac15ffa70ce
commit 67beab2b2b39c4fe3e48a021aefbfac15ffa70ce
Author: Daniel Golle <daniel at makrotopia.org>
AuthorDate: Fri Feb 16 05:32:51 2024 +0000
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 at makrotopia.org>
---
include/image-commands.mk | 18 ++++++++++++++----
scripts/ubinize-image.sh | 33 +++++++++++++++++----------------
2 files changed, 31 insertions(+), 20 deletions(-)
diff --git a/include/image-commands.mk b/include/image-commands.mk
index 9ce97b17cf..8caeb1871c 100644
--- a/include/image-commands.mk
+++ b/include/image-commands.mk
@@ -138,11 +138,9 @@ UBI_NAND_SIZE_LIMIT = $(IMAGE_SIZE) - ($(NAND_SIZE)*20/1024 + 4*$(BLOCKSIZE))
define Build/append-ubi
sh $(TOPDIR)/scripts/ubinize-image.sh \
$(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)) \
- --rootfs $(IMAGE_ROOTFS)) \
+ $(foreach part,$(UBINIZE_PARTS),--part $(part)) \
+ --rootfs $(IMAGE_ROOTFS) \
$@.tmp \
-p $(BLOCKSIZE:%k=%KiB) -m $(PAGESIZE) \
$(if $(SUBPAGESIZE),-s $(SUBPAGESIZE)) \
@@ -154,6 +152,18 @@ define Build/append-ubi
$(call Build/check-size,$(UBI_NAND_SIZE_LIMIT)))
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
cp $@ $@.tmp
sh $(TOPDIR)/scripts/ubinize-image.sh \
diff --git a/scripts/ubinize-image.sh b/scripts/ubinize-image.sh
index cd516e8afc..06a6310980 100755
--- a/scripts/ubinize-image.sh
+++ b/scripts/ubinize-image.sh
@@ -12,10 +12,10 @@ err=""
ubinize_seq=""
ubivol() {
- local volid=$1
- local name=$2
- local image=$3
- local autoresize=$4
+ local volid="$1"
+ local name="$2"
+ local image="$3"
+ local autoresize="$4"
local size="$5"
local voltype="${6:-dynamic}"
echo "[$name]"
@@ -36,16 +36,17 @@ ubivol() {
ubilayout() {
local vol_id=0
- local rootsize=
- local autoresize=
- local rootfs_type="$( get_fs_type "$2" )"
+ local rootsize
+ local autoresize
+ local rootfs_type
local voltype
+ rootfs_type="$( get_fs_type "$2" )"
if [ "$1" = "ubootenv" ]; then
ubivol $vol_id ubootenv
- vol_id=$(( $vol_id + 1 ))
+ vol_id=$(( vol_id + 1 ))
ubivol $vol_id ubootenv2
- vol_id=$(( $vol_id + 1 ))
+ vol_id=$(( vol_id + 1 ))
fi
for part in $parts; do
name="${part%%=*}"
@@ -55,9 +56,9 @@ ubilayout() {
[ "$prev" = "$part" ] && part=
image="${part%%=*}"
- if [ "${image:0:1}" = ":" ]; then
+ if [ "${image#:}" != "$image" ]; then
voltype=static
- image="${image:1}"
+ image="${image#:}"
fi
prev="$part"
part="${part#*=}"
@@ -71,11 +72,11 @@ ubilayout() {
fi
ubivol $vol_id "$name" "$image" "" "${size}" "$voltype"
- vol_id=$(( $vol_id + 1 ))
+ vol_id=$(( vol_id + 1 ))
done
if [ "$3" ]; then
ubivol $vol_id kernel "$3"
- vol_id=$(( $vol_id + 1 ))
+ vol_id=$(( vol_id + 1 ))
fi
if [ "$2" ]; then
@@ -91,7 +92,7 @@ ubilayout() {
esac
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
fi
}
@@ -128,7 +129,7 @@ while [ "$1" ]; do
continue
;;
"-"*)
- ubinize_param="$@"
+ ubinize_param="$*"
break
;;
*)
@@ -141,7 +142,7 @@ while [ "$1" ]; do
esac
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]"
exit 1
fi
More information about the lede-commits
mailing list