Makefile: use shell to calculate map_size
PATCH 1/1 Makefile: use shell to calculate map_size
From: "Leon M. Busch-George" <[email protected]>
The error message "bc: command not found" is easily missed since the build continues.
bc is not a part of coreutils or base-devel. POSIX sh can also do the calculation.
--- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Makefile +2 -2
@@ -1275,9 +1275,9 @@ OBJCOPYFLAGS_u-boot-nodtb.bin := -O binary \ binary_size_check: u-boot-nodtb.bin FORCE @file_size=$(shell wc -c u-boot-nodtb.bin | awk '{print $$1}') ; \ map_size=$(shell cat u-boot.map | \ - awk '/_image_copy_start/ {start = $$1} /_image_binary_end/ {end = $$1} END {if (start != "" && end != "") print "ibase=16; " toupper(end) " - " toupper(start)}' \ + awk '/_image_copy_start/ {start = $$1} /_image_binary_end/ {end = $$1} END {if (start != "" && end != "") print "echo $$((0x" toupper(end) " - 0x" toupper(start) "))"}' \ | sed 's/0X//g' \ - | bc); \ + | sh); \ if [ "" != "$$map_size" ]; then \ if test $$map_size -ne $$file_size; then \ echo "u-boot.map shows a binary size of $$map_size" >&2 ; \
Signature · 1 line
2.44.0
Hello Leon,
Quoted 8 lines · Leon M. Busch-George
From: "Leon M. Busch-George" <[email protected]>
The error message "bc: command not found" is easily missed since the build continues.
bc is not a part of coreutils or base-devel. POSIX sh can also do the calculation.Signed-off-by Leon M. Busch-George <[email protected]>
Please, see a nitpick below. Otherwise, the patch is looking good to me.
Quoted 18 lines
--- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)Makefile +0
-1@@ -1275,9 +1275,9 @@ OBJCOPYFLAGS_u-boot-nodtb.bin := -O binary \ binary_size_check: u-boot-nodtb.bin FORCE @file_size=$(shell wc -c u-boot-nodtb.bin | awk '{print $$1}') ; \ map_size=$(shell cat u-boot.map | \ - awk '/_image_copy_start/ {start = $$1} /_image_binary_end/ {end =$$1} END {if (start != "" && end != "") print "ibase=16; " toupper(end) " - " toupper(start)}' \
Makefile +1
-0+ awk '/_image_copy_start/ {start = $$1} /_image_binary_end/ {end =$$1} END {if (start != "" && end != "") print "echo $$((0x" toupper(end) " - 0x" toupper(start) "))"}' \
Makefile OBJCOPYFLAGS_u-boot-nodtb.bin := -O binary \ · line 1280
Quoted 3 lines
Makefile +1
-1| sed 's/0X//g' \ - | bc); \ + | sh); \
Maybe "sh -s" could be used instead, just for some additional strictness.
Quoted 3 lines
Makefile +0
-0if [ "" != "$$map_size" ]; then \ if test $$map_size -ne $$file_size; then \ echo "u-boot.map shows a binary size of $$map_size" >&2 ; \
A message that is not in the archive (sent off-list or not yet received): 20240304154007.67df1822@couch-potassium
Oops!
That should have went to the list as well...
Quoted 31 lines · On Mon, 4 Mar 2024 15:40:07 +0100 Leon Busch-George <[email protected]> wrote:
Hi Dragan :-)
Thanks for your reply!
Quoted 9 lines · On Sat, 02 Mar 2024 22:13:08 +0100 Dragan Simic <[email protected]> wrote:
Makefile OBJCOPYFLAGS_u-boot-nodtb.bin := -O binary \ · line 1280
Quoted 6 lines
(quoted diff) +1
-0+ awk '/_image_copy_start/ {start = $$1}/_image_binary_end/ {end = $$1} END {if (start != "" && end != "") print "echo $$((0x" toupper(end) " - 0x" toupper(start) "))"}' \
Makefile +1
-1| sed 's/0X//g' \ - | bc); \ + | sh); \Maybe "sh -s" could be used instead, just for some additional strictness.
-s is the default already but I see no reason against adding it. Allow me to offer another idea to improve strictness (I'll send a v2):
awk '.. print end " " start ..' | sh -c 'read end start; echo
$((end - start))'That gets rid off sed and the interface between awk and sh is much cleaner (only the two numbers on one line rather than shell code). Sadly, the sed 's/0X//g' was introduced without an explanation in
3ce7a4fefaand but, looking at it more, I'm farly confident it was only for bc.kind regards,
Leon
PATCH v2 1/1 Makefile: use shell to calculate map_size
In reply to Leon M. Busch-GeorgeFrom: "Leon M. Busch-George" <[email protected]>
The error message "bc: command not found" is easily missed since the build continues.
bc is not a part of coreutils or base-devel. POSIX sh can also do the calculation.
--- Makefile | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
Makefile +9 -4
@@ -1275,10 +1275,15 @@ OBJCOPYFLAGS_u-boot-nodtb.bin := -O binary \ binary_size_check: u-boot-nodtb.bin FORCE @file_size=$(shell wc -c u-boot-nodtb.bin | awk '{print $$1}') ; \ map_size=$(shell cat u-boot.map | \ - awk '/_image_copy_start/ {start = $$1} /_image_binary_end/ {end = $$1} END {if (start != "" && end != "") print "ibase=16; " toupper(end) " - " toupper(start)}' \ - | sed 's/0X//g' \ - | bc); \ - if [ "" != "$$map_size" ]; then \ + awk ' \ + /_image_copy_start/ { start = $$1 } \ + /_image_binary_end/ { end = $$1 } \ + END { \ + if (start != "" && end != "") \ + print end " " start; \ + }' \ + | sh -c 'read end start; [ -n "$$end" ] && echo $$((end - start))'); \ + if [ -n "$$map_size" ]; then \ if test $$map_size -ne $$file_size; then \ echo "u-boot.map shows a binary size of $$map_size" >&2 ; \ echo " but u-boot-nodtb.bin shows $$file_size" >&2 ; \
Signature · 1 line
2.44.0
PATCH v3 1/1 Makefile: use shell to calculate map_size
From: "Leon M. Busch-George" <[email protected]>
The error message "bc: command not found" is easily missed since the build continues.
bc is not a part of coreutils or base-devel. POSIX sh can also do the calculation.
--- Makefile | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
Makefile +9 -4
@@ -1275,10 +1275,15 @@ OBJCOPYFLAGS_u-boot-nodtb.bin := -O binary \ binary_size_check: u-boot-nodtb.bin FORCE @file_size=$(shell wc -c u-boot-nodtb.bin | awk '{print $$1}') ; \ map_size=$(shell cat u-boot.map | \ - awk '/_image_copy_start/ {start = $$1} /_image_binary_end/ {end = $$1} END {if (start != "" && end != "") print "ibase=16; " toupper(end) " - " toupper(start)}' \ - | sed 's/0X//g' \ - | bc); \ - if [ "" != "$$map_size" ]; then \ + awk ' \ + /_image_copy_start/ { start = $$1 } \ + /_image_binary_end/ { end = $$1 } \ + END { \ + if (start != "" && end != "") \ + print end " " start; \ + }' \ + | sh -c 'read end start && echo $$((end - start))'); \ + if [ -n "$$map_size" ]; then \ if test $$map_size -ne $$file_size; then \ echo "u-boot.map shows a binary size of $$map_size" >&2 ; \ echo " but u-boot-nodtb.bin shows $$file_size" >&2 ; \
Signature · 1 line
2.44.0
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 9 lines · Dragan Simic
Quoted 8 lines · Leon M. Busch-George
From: "Leon M. Busch-George" <[email protected]>
The error message "bc: command not found" is easily missed since the build continues.
bc is not a part of coreutils or base-devel. POSIX sh can also do the calculation.Signed-off-by Leon M. Busch-George <[email protected]>
Sorry, I totally missed the v3. It's still looking good to me, and my Reviewed-by tag still applies, together with the small nitpick.
Quoted 30 lines
Quoted 30 lines
--- Makefile | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)Makefile +0
-1@@ -1275,10 +1275,15 @@ OBJCOPYFLAGS_u-boot-nodtb.bin := -O binary \ binary_size_check: u-boot-nodtb.bin FORCE @file_size=$(shell wc -c u-boot-nodtb.bin | awk '{print $$1}') ; \ map_size=$(shell cat u-boot.map | \ - awk '/_image_copy_start/ {start = $$1} /_image_binary_end/ {end =$$1} END {if (start != "" && end != "") print "ibase=16; " toupper(end) " - " toupper(start)}' \
Makefile +9
-3- | sed 's/0X//g' \ - | bc); \ - if [ "" != "$$map_size" ]; then \ + awk ' \ + /_image_copy_start/ { start = $$1 } \ + /_image_binary_end/ { end = $$1 } \ + END { \ + if (start != "" && end != "") \ + print end " " start; \ + }' \ + | sh -c 'read end start && echo $$((end - start))'); \ + if [ -n "$$map_size" ]; then \ if test $$map_size -ne $$file_size; then \ echo "u-boot.map shows a binary size of $$map_size" >&2 ; \ echo " but u-boot-nodtb.bin shows $$file_size" >&2 ; \
A colleague made me aware that the '[ -n "$$end" ]' is not necessary since 'read' already returns an exit code.
v3 inc
Quoted 40 lines · On Mon, 4 Mar 2024 21:38:56 +0100 "Leon M. Busch-George" <[email protected]>…
From: "Leon M. Busch-George" <[email protected]>
The error message "bc: command not found" is easily missed since the build continues.
bc is not a part of coreutils or base-devel. POSIX sh can also do the calculation.Signed-off-by Leon M. Busch-George <[email protected]>--- Makefile | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)Makefile +9
-4@@ -1275,10 +1275,15 @@ OBJCOPYFLAGS_u-boot-nodtb.bin := -O binary \ binary_size_check: u-boot-nodtb.bin FORCE @file_size=$(shell wc -c u-boot-nodtb.bin | awk '{print $$1}') ; \ map_size=$(shell cat u-boot.map | \ - awk '/_image_copy_start/ {start = $$1} /_image_binary_end/ {end = $$1} END {if (start != "" && end != "") print "ibase=16; " toupper(end) " - " toupper(start)}' \ - | sed 's/0X//g' \ - | bc); \ - if [ "" != "$$map_size" ]; then \ + awk ' \ + /_image_copy_start/ { start = $$1 } \ + /_image_binary_end/ { end = $$1 } \ + END { \ + if (start != "" && end != "") \ + print end " " start; \ + }' \ + | sh -c 'read end start; [ -n "$$end" ] && echo $$((end - start))'); \ + if [ -n "$$map_size" ]; then \Makefile +0
-0if test $$map_size -ne $$file_size; then \ echo "u-boot.map shows a binary size of$$map_size" >&2 ; \ echo " but u-boot-nodtb.bin shows $$file_size"
Quoted 1 line
&2 ; \
A message that is not in the archive (sent off-list or not yet received): [email protected]
Dragan Simic
Reviewed-byHello Leon,
Quoted 9 lines · Dragan Simic
Quoted 8 lines · Leon M. Busch-George
From: "Leon M. Busch-George" <[email protected]>
The error message "bc: command not found" is easily missed since the build continues.
bc is not a part of coreutils or base-devel. POSIX sh can also do the calculation.Signed-off-by Leon M. Busch-George <[email protected]>
The v2 is looking good to me. I also did some testing of the awk code by hand, outside of the actual Makefile, and it worked as expected.
See also one small nitpick below, and please feel free to include:
Quoted 11 lines
Makefile OBJCOPYFLAGS_u-boot-nodtb.bin := -O binary \ · line 1276
Quoted 11 lines
--- Makefile | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)Makefile +0
-0@@ -1275,10 +1275,15 @@ OBJCOPYFLAGS_u-boot-nodtb.bin := -O binary \ binary_size_check: u-boot-nodtb.bin FORCE @file_size=$(shell wc -c u-boot-nodtb.bin | awk '{print $$1}') ; \
Perhaps a couple of spaces could be added around "print $$1" in the line above, to nicely round off the code cleanups.
Quoted 20 lines
Quoted 20 lines
Makefile +0
-1map_size=$(shell cat u-boot.map | \ - awk '/_image_copy_start/ {start = $$1} /_image_binary_end/ {end =$$1} END {if (start != "" && end != "") print "ibase=16; " toupper(end) " - " toupper(start)}' \
Makefile +8
-3- | sed 's/0X//g' \ - | bc); \ - if [ "" != "$$map_size" ]; then \ + awk ' \ + /_image_copy_start/ { start = $$1 } \ + /_image_binary_end/ { end = $$1 } \ + END { \ + if (start != "" && end != "") \ + print end " " start; \ + }' \ + | sh -c 'read end start; [ -n "$$end" ] && echo $$((end -start))'); \
Makefile +1
-0+ if [ -n "$$map_size" ]; then \ if test $$map_size -ne $$file_size; then \ echo "u-boot.map shows a binary size of $$map_size" >&2 ; \ echo " but u-boot-nodtb.bin shows $$file_size" >&2 ; \