summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJamin Lin <jamin_lin@aspeedtech.com>2025-06-17 16:10:51 +0800
committerRichard Purdie <richard.purdie@linuxfoundation.org>2025-06-19 21:54:43 +0100
commit6d3b93af2e955a462f3f0a68693a07f5f1d775ff (patch)
treec70f8a827fce2d7566dbbe88189b191804309966
parentd8cd58cc7ad5d8b7c92ef6eb6f0b973f0276422d (diff)
downloadpoky-6d3b93af2e955a462f3f0a68693a07f5f1d775ff.tar.gz
uboot-sign.bbclass: Refactor condition checks to use && and || instead of -a and -o
This commit cleans up and modernizes the shell condition expressions in `uboot-sign.bbclass` to follow best practices for portable and reliable shell usage. Key changes: - Replace legacy `[ -a ]` and `[ -o ]` with explicit `[ ] && [ ]` and `[ ] || [ ]`. Modern POSIX and busybox sh recommend using `&&` and `||` instead of `-a` and `-o` because `-a` and `-o` are less robust and can cause parsing ambiguities in some shells. - Simplify `concat_dtb()` by moving the DTB existence check to the top and using early `return` to avoid deep nesting. - Remove redundant fallback `else` blocks; use clearer control flow with direct checks. This improves maintainability, reduces shell syntax pitfalls, and aligns with current shell scripting best practices. References: - POSIX recommends avoiding `-a` and `-o` in `[ ]` and using explicit `&&` and `||`: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html (From OE-Core rev: d2740e39800a044d557b620e38ca0ac1b8c6d030) Signed-off-by: Jamin Lin <jamin_lin@aspeedtech.com> Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/classes-recipe/uboot-sign.bbclass26
1 files changed, 14 insertions, 12 deletions
diff --git a/meta/classes-recipe/uboot-sign.bbclass b/meta/classes-recipe/uboot-sign.bbclass
index 01c53c7448..0f387a3a3e 100644
--- a/meta/classes-recipe/uboot-sign.bbclass
+++ b/meta/classes-recipe/uboot-sign.bbclass
@@ -198,21 +198,23 @@ concat_dtb() {
198 # If we're not using a signed u-boot fit, concatenate SPL w/o DTB & U-Boot DTB 198 # If we're not using a signed u-boot fit, concatenate SPL w/o DTB & U-Boot DTB
199 # with public key (otherwise U-Boot will be packaged by uboot_fitimage_assemble) 199 # with public key (otherwise U-Boot will be packaged by uboot_fitimage_assemble)
200 if [ "${SPL_SIGN_ENABLE}" != "1" ] ; then 200 if [ "${SPL_SIGN_ENABLE}" != "1" ] ; then
201 if [ "x${UBOOT_SUFFIX}" = "ximg" -o "x${UBOOT_SUFFIX}" = "xrom" ] && \ 201 if [ ! -e "${UBOOT_DTB_BINARY}" ]; then
202 [ -e "${UBOOT_DTB_BINARY}" ]; then 202 bbwarn "Failure while adding public key to u-boot binary. Verified boot won't be available."
203 return
204 fi
205
206 if [ "x${UBOOT_SUFFIX}" = "ximg" ] || [ "x${UBOOT_SUFFIX}" = "xrom" ]; then
203 oe_runmake EXT_DTB="${UBOOT_DTB_SIGNED}" ${UBOOT_MAKE_TARGET} 207 oe_runmake EXT_DTB="${UBOOT_DTB_SIGNED}" ${UBOOT_MAKE_TARGET}
204 if [ -n "${binary}" ]; then 208 if [ -n "${binary}" ]; then
205 cp ${binary} ${UBOOT_BINARYNAME}-${type}.${UBOOT_SUFFIX} 209 cp ${binary} ${UBOOT_BINARYNAME}-${type}.${UBOOT_SUFFIX}
206 fi 210 fi
207 elif [ -e "${UBOOT_NODTB_BINARY}" -a -e "${UBOOT_DTB_BINARY}" ]; then 211 elif [ -e "${UBOOT_NODTB_BINARY}" ]; then
208 if [ -n "${binary}" ]; then 212 if [ -n "${binary}" ]; then
209 cat ${UBOOT_NODTB_BINARY} ${UBOOT_DTB_SIGNED} | tee ${binary} > \ 213 cat ${UBOOT_NODTB_BINARY} ${UBOOT_DTB_SIGNED} | tee ${binary} > \
210 ${UBOOT_BINARYNAME}-${type}.${UBOOT_SUFFIX} 214 ${UBOOT_BINARYNAME}-${type}.${UBOOT_SUFFIX}
211 else 215 else
212 cat ${UBOOT_NODTB_BINARY} ${UBOOT_DTB_SIGNED} > ${UBOOT_BINARY} 216 cat ${UBOOT_NODTB_BINARY} ${UBOOT_DTB_SIGNED} > ${UBOOT_BINARY}
213 fi 217 fi
214 else
215 bbwarn "Failure while adding public key to u-boot binary. Verified boot won't be available."
216 fi 218 fi
217 fi 219 fi
218} 220}
@@ -244,7 +246,7 @@ deploy_dtb() {
244} 246}
245 247
246concat_spl_dtb() { 248concat_spl_dtb() {
247 if [ -e "${SPL_DIR}/${SPL_NODTB_BINARY}" -a -e "${SPL_DIR}/${SPL_DTB_BINARY}" ] ; then 249 if [ -e "${SPL_DIR}/${SPL_NODTB_BINARY}" ] && [ -e "${SPL_DIR}/${SPL_DTB_BINARY}" ] ; then
248 cat ${SPL_DIR}/${SPL_NODTB_BINARY} ${SPL_DIR}/${SPL_DTB_SIGNED} > "${SPL_BINARY}" 250 cat ${SPL_DIR}/${SPL_NODTB_BINARY} ${SPL_DIR}/${SPL_DTB_SIGNED} > "${SPL_BINARY}"
249 else 251 else
250 bbwarn "Failure while adding public key to spl binary. Verified U-Boot boot won't be available." 252 bbwarn "Failure while adding public key to spl binary. Verified U-Boot boot won't be available."
@@ -500,7 +502,7 @@ uboot_assemble_fitimage_helper() {
500 type="$1" 502 type="$1"
501 binary="$2" 503 binary="$2"
502 504
503 if [ "${UBOOT_SIGN_ENABLE}" = "1" -a -n "${UBOOT_DTB_BINARY}" ] ; then 505 if [ "${UBOOT_SIGN_ENABLE}" = "1" ] && [ -n "${UBOOT_DTB_BINARY}" ] ; then
504 concat_dtb "$type" "$binary" 506 concat_dtb "$type" "$binary"
505 fi 507 fi
506 508
@@ -508,7 +510,7 @@ uboot_assemble_fitimage_helper() {
508 uboot_fitimage_assemble 510 uboot_fitimage_assemble
509 fi 511 fi
510 512
511 if [ "${SPL_SIGN_ENABLE}" = "1" -a -n "${SPL_DTB_BINARY}" ] ; then 513 if [ "${SPL_SIGN_ENABLE}" = "1" ] && [ -n "${SPL_DTB_BINARY}" ] ; then
512 concat_spl_dtb 514 concat_spl_dtb
513 fi 515 fi
514} 516}
@@ -547,7 +549,7 @@ addtask uboot_assemble_fitimage before do_install do_deploy after do_compile
547deploy_helper() { 549deploy_helper() {
548 type="$1" 550 type="$1"
549 551
550 if [ "${UBOOT_SIGN_ENABLE}" = "1" -a -n "${UBOOT_DTB_SIGNED}" ] ; then 552 if [ "${UBOOT_SIGN_ENABLE}" = "1" ] && [ -n "${UBOOT_DTB_SIGNED}" ] ; then
551 deploy_dtb $type 553 deploy_dtb $type
552 fi 554 fi
553 555
@@ -569,7 +571,7 @@ deploy_helper() {
569 fi 571 fi
570 fi 572 fi
571 573
572 if [ "${SPL_SIGN_ENABLE}" = "1" -a -n "${SPL_DTB_BINARY}" ] ; then 574 if [ "${SPL_SIGN_ENABLE}" = "1" ] && [ -n "${SPL_DTB_BINARY}" ] ; then
573 deploy_spl_dtb $type 575 deploy_spl_dtb $type
574 fi 576 fi
575} 577}
@@ -594,7 +596,7 @@ do_deploy:prepend() {
594 deploy_helper "" 596 deploy_helper ""
595 fi 597 fi
596 598
597 if [ "${UBOOT_SIGN_ENABLE}" = "1" -a -n "${UBOOT_DTB_BINARY}" ] ; then 599 if [ "${UBOOT_SIGN_ENABLE}" = "1" ] && [ -n "${UBOOT_DTB_BINARY}" ] ; then
598 ln -sf ${UBOOT_DTB_IMAGE} ${DEPLOYDIR}/${UBOOT_DTB_BINARY} 600 ln -sf ${UBOOT_DTB_IMAGE} ${DEPLOYDIR}/${UBOOT_DTB_BINARY}
599 ln -sf ${UBOOT_DTB_IMAGE} ${DEPLOYDIR}/${UBOOT_DTB_SYMLINK} 601 ln -sf ${UBOOT_DTB_IMAGE} ${DEPLOYDIR}/${UBOOT_DTB_SYMLINK}
600 ln -sf ${UBOOT_NODTB_IMAGE} ${DEPLOYDIR}/${UBOOT_NODTB_SYMLINK} 602 ln -sf ${UBOOT_NODTB_IMAGE} ${DEPLOYDIR}/${UBOOT_NODTB_SYMLINK}
@@ -608,7 +610,7 @@ do_deploy:prepend() {
608 ln -sf ${UBOOT_FITIMAGE_IMAGE} ${DEPLOYDIR}/${UBOOT_FITIMAGE_SYMLINK} 610 ln -sf ${UBOOT_FITIMAGE_IMAGE} ${DEPLOYDIR}/${UBOOT_FITIMAGE_SYMLINK}
609 fi 611 fi
610 612
611 if [ "${SPL_SIGN_ENABLE}" = "1" -a -n "${SPL_DTB_BINARY}" ] ; then 613 if [ "${SPL_SIGN_ENABLE}" = "1" ] && [ -n "${SPL_DTB_BINARY}" ] ; then
612 ln -sf ${SPL_DTB_IMAGE} ${DEPLOYDIR}/${SPL_DTB_SYMLINK} 614 ln -sf ${SPL_DTB_IMAGE} ${DEPLOYDIR}/${SPL_DTB_SYMLINK}
613 ln -sf ${SPL_DTB_IMAGE} ${DEPLOYDIR}/${SPL_DTB_BINARY} 615 ln -sf ${SPL_DTB_IMAGE} ${DEPLOYDIR}/${SPL_DTB_BINARY}
614 ln -sf ${SPL_NODTB_IMAGE} ${DEPLOYDIR}/${SPL_NODTB_SYMLINK} 616 ln -sf ${SPL_NODTB_IMAGE} ${DEPLOYDIR}/${SPL_NODTB_SYMLINK}