* [Buildroot] [PATCH] board/stm32mp157: remove hardcoded device tree names from post-image.sh
@ 2023-09-30 15:59 Grzegorz Szymaszek
2023-09-30 19:16 ` Peter Korsgaard
0 siblings, 1 reply; 2+ messages in thread
From: Grzegorz Szymaszek @ 2023-09-30 15:59 UTC (permalink / raw)
To: buildroot; +Cc: Grzegorz Szymaszek
The post-image.sh script is used in several STM32MP157-based board
configs. It had hardcoded device tree file names for the supported
boards which were used for matching the expected TF-A binary name.
Replace this mechanism with a pair of grep and sed that build the TF-A
binary name from the device tree file name. For example, if
BR2_TARGET_ARM_TRUSTED_FIRMWARE_ADDITIONAL_VARIABLES contained
DTB_FILE_NAME=stm32mp157c-dk2.dtb, the appropriate TF-A file would be
named tf-a-stm32mp157c-dk2.stm32.
Since the Bash Here Strings are removed with this change, I took the
opportunity to remove the only other non-POSIX command, "local", and
then I was able to change the shebang to plain /bin/sh, with -eu for
simpler error handling.
Signed-off-by: Grzegorz Szymaszek <gszymaszek@short.pl>
---
.../common/stm32mp157/post-image.sh | 23 ++++++++-----------
1 file changed, 10 insertions(+), 13 deletions(-)
diff --git a/board/stmicroelectronics/common/stm32mp157/post-image.sh b/board/stmicroelectronics/common/stm32mp157/post-image.sh
index 363c3127cf..fe3becae86 100755
--- a/board/stmicroelectronics/common/stm32mp157/post-image.sh
+++ b/board/stmicroelectronics/common/stm32mp157/post-image.sh
@@ -1,4 +1,4 @@
-#!/usr/bin/env bash
+#!/bin/sh -eu
#
# atf_image extracts the ATF binary image from DTB_FILE_NAME that appears in
@@ -8,22 +8,19 @@
#
atf_image()
{
- local ATF_VARIABLES="$(sed -n 's/^BR2_TARGET_ARM_TRUSTED_FIRMWARE_ADDITIONAL_VARIABLES="\([\/a-zA-Z0-9_=. \-]*\)"$/\1/p' ${BR2_CONFIG})"
-
- if grep -Eq "DTB_FILE_NAME=stm32mp157c-dk2.dtb" <<< ${ATF_VARIABLES}; then
- echo "tf-a-stm32mp157c-dk2.stm32"
- elif grep -Eq "DTB_FILE_NAME=stm32mp157a-dk1.dtb" <<< ${ATF_VARIABLES}; then
- echo "tf-a-stm32mp157a-dk1.stm32"
- elif grep -Eq "DTB_FILE_NAME=stm32mp157a-avenger96.dtb" <<< ${ATF_VARIABLES}; then
- echo "tf-a-stm32mp157a-avenger96.stm32"
- fi
+ ATF_VARIABLES="$(sed -n 's/^BR2_TARGET_ARM_TRUSTED_FIRMWARE_ADDITIONAL_VARIABLES="\([\/a-zA-Z0-9_=. \-]*\)"$/\1/p' ${BR2_CONFIG})"
+ # make sure DTB_FILE_NAME is set
+ printf '%s\n' "${ATF_VARIABLES}" | grep -Eq 'DTB_FILE_NAME=[0-9A-Za-z_\-]*'
+ # extract the value
+ DTB_FILE_NAME="$(printf '%s\n' "${ATF_VARIABLES}" | sed 's/.*DTB_FILE_NAME=\([a-zA-Z0-9_\-]*\)\.dtb.*/\1/')"
+ echo "tf-a-${DTB_FILE_NAME}.stm32"
}
main()
{
- local ATFBIN="$(atf_image)"
- local GENIMAGE_CFG="$(mktemp --suffix genimage.cfg)"
- local GENIMAGE_TMP="${BUILD_DIR}/genimage.tmp"
+ ATFBIN="$(atf_image)"
+ GENIMAGE_CFG="$(mktemp --suffix genimage.cfg)"
+ GENIMAGE_TMP="${BUILD_DIR}/genimage.tmp"
sed -e "s/%ATFBIN%/${ATFBIN}/" \
board/stmicroelectronics/common/stm32mp157/genimage.cfg.template > ${GENIMAGE_CFG}
--
2.40.1
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Buildroot] [PATCH] board/stm32mp157: remove hardcoded device tree names from post-image.sh
2023-09-30 15:59 [Buildroot] [PATCH] board/stm32mp157: remove hardcoded device tree names from post-image.sh Grzegorz Szymaszek
@ 2023-09-30 19:16 ` Peter Korsgaard
0 siblings, 0 replies; 2+ messages in thread
From: Peter Korsgaard @ 2023-09-30 19:16 UTC (permalink / raw)
To: buildroot
>>>>> "Grzegorz" == Grzegorz Szymaszek <gszymaszek@short.pl> writes:
> The post-image.sh script is used in several STM32MP157-based board
> configs. It had hardcoded device tree file names for the supported
> boards which were used for matching the expected TF-A binary name.
> Replace this mechanism with a pair of grep and sed that build the TF-A
> binary name from the device tree file name. For example, if
> BR2_TARGET_ARM_TRUSTED_FIRMWARE_ADDITIONAL_VARIABLES contained
> DTB_FILE_NAME=stm32mp157c-dk2.dtb, the appropriate TF-A file would be
> named tf-a-stm32mp157c-dk2.stm32.
> Since the Bash Here Strings are removed with this change, I took the
> opportunity to remove the only other non-POSIX command, "local", and
> then I was able to change the shebang to plain /bin/sh, with -eu for
> simpler error handling.
> Signed-off-by: Grzegorz Szymaszek <gszymaszek@short.pl>
> ---
> .../common/stm32mp157/post-image.sh | 23 ++++++++-----------
> 1 file changed, 10 insertions(+), 13 deletions(-)
> diff --git a/board/stmicroelectronics/common/stm32mp157/post-image.sh b/board/stmicroelectronics/common/stm32mp157/post-image.sh
> index 363c3127cf..fe3becae86 100755
> --- a/board/stmicroelectronics/common/stm32mp157/post-image.sh
> +++ b/board/stmicroelectronics/common/stm32mp157/post-image.sh
> @@ -1,4 +1,4 @@
> -#!/usr/bin/env bash
> +#!/bin/sh -eu
> #
> # atf_image extracts the ATF binary image from DTB_FILE_NAME that appears in
> @@ -8,22 +8,19 @@
> #
> atf_image()
> {
> - local ATF_VARIABLES="$(sed -n 's/^BR2_TARGET_ARM_TRUSTED_FIRMWARE_ADDITIONAL_VARIABLES="\([\/a-zA-Z0-9_=. \-]*\)"$/\1/p' ${BR2_CONFIG})"
> -
> - if grep -Eq "DTB_FILE_NAME=stm32mp157c-dk2.dtb" <<< ${ATF_VARIABLES}; then
> - echo "tf-a-stm32mp157c-dk2.stm32"
> - elif grep -Eq "DTB_FILE_NAME=stm32mp157a-dk1.dtb" <<< ${ATF_VARIABLES}; then
> - echo "tf-a-stm32mp157a-dk1.stm32"
> - elif grep -Eq "DTB_FILE_NAME=stm32mp157a-avenger96.dtb" <<< ${ATF_VARIABLES}; then
> - echo "tf-a-stm32mp157a-avenger96.stm32"
> - fi
> + ATF_VARIABLES="$(sed -n 's/^BR2_TARGET_ARM_TRUSTED_FIRMWARE_ADDITIONAL_VARIABLES="\([\/a-zA-Z0-9_=. \-]*\)"$/\1/p' ${BR2_CONFIG})"
> + # make sure DTB_FILE_NAME is set
> + printf '%s\n' "${ATF_VARIABLES}" | grep -Eq 'DTB_FILE_NAME=[0-9A-Za-z_\-]*'
> + # extract the value
> + DTB_FILE_NAME="$(printf '%s\n' "${ATF_VARIABLES}" | sed 's/.*DTB_FILE_NAME=\([a-zA-Z0-9_\-]*\)\.dtb.*/\1/')"
> + echo "tf-a-${DTB_FILE_NAME}.stm32"
> }
> main()
> {
> - local ATFBIN="$(atf_image)"
> - local GENIMAGE_CFG="$(mktemp --suffix genimage.cfg)"
> - local GENIMAGE_TMP="${BUILD_DIR}/genimage.tmp"
> + ATFBIN="$(atf_image)"
> + GENIMAGE_CFG="$(mktemp --suffix genimage.cfg)"
> + GENIMAGE_TMP="${BUILD_DIR}/genimage.tmp"
It looks like GENIMAGE_TMP is not used anywhere. Committed with that
removed, thanks.
--
Bye, Peter Korsgaard
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-09-30 19:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-30 15:59 [Buildroot] [PATCH] board/stm32mp157: remove hardcoded device tree names from post-image.sh Grzegorz Szymaszek
2023-09-30 19:16 ` Peter Korsgaard
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox