[U-Boot] [PATCH v4] pico-imx7d: Increase the CONFIG_ENV_OFFSET size

U-Boot binary has grown in such a way that it goes beyond the reserved area for the environment variables.
Running "saveenv" causes U-Boot to hang because of this overlap.
Fix this problem by increasing the CONFIG_ENV_OFFSET size.
Also, in order to prevent this same problem in the future, use CONFIG_BOARD_SIZE_LIMIT, which will detect the overlap in build-time.
CONFIG_BOARD_SIZE_LIMIT does not accept math expressions, so declare CONFIG_ENV_OFFSET with its direct value instead.
Signed-off-by: Fabio Estevam festevam@gmail.com --- Changes since v3: - Take the 69k u-boot.img offset into account when calculating CONFIG_BOARD_SIZE_LIMIT (Wolfgang)
include/configs/pico-imx7d.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/include/configs/pico-imx7d.h b/include/configs/pico-imx7d.h index 2bc42a0..06ede3f 100644 --- a/include/configs/pico-imx7d.h +++ b/include/configs/pico-imx7d.h @@ -134,7 +134,19 @@ /* FLASH and environment organization */ #define CONFIG_ENV_SIZE SZ_8K
-#define CONFIG_ENV_OFFSET (8 * SZ_64K) +/* Environment starts at 768k = 768 * 1024 = 786432 */ +#define CONFIG_ENV_OFFSET 786432 +/* + * Detect overlap between U-Boot image and environment area in build-time + * + * CONFIG_BOARD_SIZE_LIMIT = CONFIG_ENV_OFFSET - u-boot.img offset + * CONFIG_BOARD_SIZE_LIMIT = 768k - 69k = 699k = 715776 + * + * Currently CONFIG_BOARD_SIZE_LIMIT does not handle expressions, so + * write the direct value here + */ +#define CONFIG_BOARD_SIZE_LIMIT 715776 + #define CONFIG_SYS_FSL_USDHC_NUM 2
#define CONFIG_SYS_MMC_ENV_DEV 0

On Fri, Nov 30, 2018 at 12:52 PM Fabio Estevam festevam@gmail.com wrote:
U-Boot binary has grown in such a way that it goes beyond the reserved area for the environment variables.
Running "saveenv" causes U-Boot to hang because of this overlap.
Fix this problem by increasing the CONFIG_ENV_OFFSET size.
Also, in order to prevent this same problem in the future, use CONFIG_BOARD_SIZE_LIMIT, which will detect the overlap in build-time.
CONFIG_BOARD_SIZE_LIMIT does not accept math expressions, so declare CONFIG_ENV_OFFSET with its direct value instead.
Signed-off-by: Fabio Estevam festevam@gmail.com
Acked-by: Otavio Salvador otavio@ossystems.com.br

Dear Fabio,
In message 1543589533-4257-1-git-send-email-festevam@gmail.com you wrote:
U-Boot binary has grown in such a way that it goes beyond the reserved area for the environment variables.
Running "saveenv" causes U-Boot to hang because of this overlap.
Fix this problem by increasing the CONFIG_ENV_OFFSET size.
Also, in order to prevent this same problem in the future, use CONFIG_BOARD_SIZE_LIMIT, which will detect the overlap in build-time.
CONFIG_BOARD_SIZE_LIMIT does not accept math expressions, so declare CONFIG_ENV_OFFSET with its direct value instead.
This is IMHO the wrong approach. Why not fix this problem?
- CONFIG_BOARD_SIZE_LIMIT = CONFIG_ENV_OFFSET - u-boot.img offset
- CONFIG_BOARD_SIZE_LIMIT = 768k - 69k = 699k = 715776
- Currently CONFIG_BOARD_SIZE_LIMIT does not handle expressions, so
- write the direct value here
- */
+#define CONFIG_BOARD_SIZE_LIMIT 715776
This looks ugly. I mean, have a look at the Makefile - we're calling AWK anyway, so why not make this evaluating expressions (and getting rid of a few unnneeded commands)?
Can you please try somthing like this (only minimally tested):
diff --git a/arch/arm/mach-imx/Makefile b/arch/arm/mach-imx/Makefile index 53d9e5f42b..a7f02f9996 100644 --- a/arch/arm/mach-imx/Makefile +++ b/arch/arm/mach-imx/Makefile @@ -60,15 +60,13 @@ endif
ifneq ($(CONFIG_BOARD_SIZE_LIMIT),) BOARD_SIZE_CHECK = \ - @actual=`wc -c $@ | awk '{print $$1}'`; \ - limit=`printf "%d" $(CONFIG_BOARD_SIZE_LIMIT)`; \ - if test $$actual -gt $$limit; then \ - echo "$@ exceeds file size limit:" >&2 ; \ - echo " limit: $$limit bytes" >&2 ; \ - echo " actual: $$actual bytes" >&2 ; \ - echo " excess: $$((actual - limit)) bytes" >&2; \ - exit 1; \ - fi + @wc -c $@ | \ + awk '{ if ($$1 > $(CONFIG_BOARD_SIZE_LIMIT)) { \ + printf "%s exceeds file size limit:\n", $$2; \ + printf " limit: %d bytes\n", $(CONFIG_BOARD_SIZE_LIMIT); \ + printf " actual: %d bytes\n", $$1; \ + printf " excess: %d bytes\n", $$1 - $(CONFIG_BOARD_SIZE_LIMIT); \ + exit 1; } }' >&2; else BOARD_SIZE_CHECK = endif
If it works for you, then please feel free to include it in your patch v3.
Thanks!
Best regards,
Wolfgang Denk

Hi Wolfgang,
On Fri, Nov 30, 2018 at 1:33 PM Wolfgang Denk wd@denx.de wrote:
This is IMHO the wrong approach. Why not fix this problem?
That would be much better indeed, but I don't have the necessary Makefile skills to fix it.
Can you please try somthing like this (only minimally tested):
I tried it, thanks, but unfortunately It does not work for me.
Here is the complete patch I used, which consists of your proposal plus my changes: http://dark-code.bulix.org/nhg8l0-515675
Then when I build the pico-imx7d_defconfig target I get the following error:
/bin/sh: 1: printf: CONFIG_ENV_OFFSET - (69 * 1024): expected numeric value u-boot-nodtb.bin exceeds file size limit: limit: 0 bytes actual: 482952 bytes excess: 482952 bytes Makefile:1040: recipe for target 'u-boot-nodtb.bin' failed make: *** [u-boot-nodtb.bin] Error 1 make: *** Waiting for unfinished jobs.... LD spl/u-boot-spl OBJCOPY spl/u-boot-spl-nodtb.bin COPY spl/u-boot-spl.bin

Dear Fabio,
In message CAOMZO5CEeErzL2MMpktmgoV5TyXGyMZB954fNhAMBSP60scD7g@mail.gmail.com you wrote:
Can you please try somthing like this (only minimally tested):
I tried it, thanks, but unfortunately It does not work for me.
Here is the complete patch I used, which consists of your proposal plus my changes: http://dark-code.bulix.org/nhg8l0-515675
Then when I build the pico-imx7d_defconfig target I get the following error:
/bin/sh: 1: printf: CONFIG_ENV_OFFSET - (69 * 1024): expected numeric value
I see -yes, this does not work as you are referencing a CPP macro here which does not get resolved. I don't see a trivial way around this, though - for the Makefile we would need $(CONFIG_ENV_OFFSET), but CPP would barf on this...
Can you live with something like this:
#define CONFIG_ENV_OFFSET (768 * 1024) #define CONFIG_BOARD_SIZE_LIMIT ((768 * 1024) - (69 * 1024))
[or maybe even ((768 - 69) * 1024) ?]
Best regards,
Wolfgang Denk

Hi Wolfgang,
On Mon, Dec 3, 2018 at 1:52 PM Wolfgang Denk wd@denx.de wrote:
Can you live with something like this:
#define CONFIG_ENV_OFFSET (768 * 1024) #define CONFIG_BOARD_SIZE_LIMIT ((768 * 1024) - (69 * 1024))
It does not work:
/bin/sh: 1: printf: ((768 * 1024) - (69 * 1024)): expected numeric value u-boot-nodtb.bin exceeds file size limit: limit: 0 bytes actual: 482968 bytes excess: 482968 bytes
[or maybe even ((768 - 69) * 1024) ?]
/bin/sh: 1: printf: ((768 - 69) * 1024): expected numeric value u-boot-nodtb.bin exceeds file size limit: limit: 0 bytes actual: 482968 bytes excess: 482968 bytes Makefile:1040: recipe for target 'u-boot-nodtb.bin' failed
Can we please go with the solution I sent, which is ugly but at least allows the board to boot?

Hello Fabio,
On Mon, Dec 3, 2018 at 2:53 PM Fabio Estevam festevam@gmail.com wrote:
On Mon, Dec 3, 2018 at 1:52 PM Wolfgang Denk wd@denx.de wrote:
Can you live with something like this:
#define CONFIG_ENV_OFFSET (768 * 1024) #define CONFIG_BOARD_SIZE_LIMIT ((768 * 1024) - (69 * 1024))
It does not work:
/bin/sh: 1: printf: ((768 * 1024) - (69 * 1024)): expected numeric value u-boot-nodtb.bin exceeds file size limit: limit: 0 bytes actual: 482968 bytes excess: 482968 bytes
[or maybe even ((768 - 69) * 1024) ?]
/bin/sh: 1: printf: ((768 - 69) * 1024): expected numeric value u-boot-nodtb.bin exceeds file size limit: limit: 0 bytes actual: 482968 bytes excess: 482968 bytes Makefile:1040: recipe for target 'u-boot-nodtb.bin' failed
Can we please go with the solution I sent, which is ugly but at least allows the board to boot?
Agreed. It is better Wolfgang to send a tested solution before we change it one more time.
This fix should go in as the board is broken without it.

Dear Otavio,
In message CAP9ODKr1JVMHqsGnPyJwYK3QtHAGXQ=Cv4Y8Zx0nQtxc4C4cAw@mail.gmail.com you wrote:
Agreed. It is better Wolfgang to send a tested solution before we change it one more time.
My patch _was_ tested. I can only speculate that Fabio applied it manually, and made a mistake.
This fix should go in as the board is broken without it.
Yes, agreed. But then, we are just one step away from a better fix.
Best regards,
Wolfgang Denk

Dear Fabio,
In message CAOMZO5DBvBag4qG7tRqHi1X1Dy7=bWfaQhN5wRCB2_WM1HhiGw@mail.gmail.com you wrote:
On Mon, Dec 3, 2018 at 1:52 PM Wolfgang Denk wd@denx.de wrote:
Can you live with something like this:
#define CONFIG_ENV_OFFSET (768 * 1024) #define CONFIG_BOARD_SIZE_LIMIT ((768 * 1024) - (69 * 1024))
It does not work:
/bin/sh: 1: printf: ((768 * 1024) - (69 * 1024)): expected numeric value u-boot-nodtb.bin exceeds file size limit: limit: 0 bytes actual: 482968 bytes excess: 482968 bytes
Is there any chance you mis-applied my patch?
Apparently you still have a shell printf command in your code, most probably the old line
limit=`printf "%d" $(CONFIG_BOARD_SIZE_LIMIT)`;
But this should not be present any more with my patch applied. Here again as reference:
diff --git a/arch/arm/mach-imx/Makefile b/arch/arm/mach-imx/Makefile index 53d9e5f42b..a7f02f9996 100644 --- a/arch/arm/mach-imx/Makefile +++ b/arch/arm/mach-imx/Makefile @@ -60,15 +60,13 @@ endif
ifneq ($(CONFIG_BOARD_SIZE_LIMIT),) BOARD_SIZE_CHECK = \ - @actual=`wc -c $@ | awk '{print $$1}'`; \ - limit=`printf "%d" $(CONFIG_BOARD_SIZE_LIMIT)`; \ - if test $$actual -gt $$limit; then \ - echo "$@ exceeds file size limit:" >&2 ; \ - echo " limit: $$limit bytes" >&2 ; \ - echo " actual: $$actual bytes" >&2 ; \ - echo " excess: $$((actual - limit)) bytes" >&2; \ - exit 1; \ - fi + @wc -c $@ | \ + awk '{ if ($$1 > $(CONFIG_BOARD_SIZE_LIMIT)) { \ + printf "%s exceeds file size limit:\n", $$2; \ + printf " limit: %d bytes\n", $(CONFIG_BOARD_SIZE_LIMIT); \ + printf " actual: %d bytes\n", $$1; \ + printf " excess: %d bytes\n", $$1 - $(CONFIG_BOARD_SIZE_LIMIT); \ + exit 1; } }' >&2; else BOARD_SIZE_CHECK = endif
As you can see, with the patch there is NO printf called before the line which prints ""%s exceeds file size limit:\n", but in your output the error message comes before that.
I have tested this code, and it works for me.
Please check the code again!
Best regards,
Wolfgang Denk

Hi Wolfgang,
On Tue, Dec 4, 2018 at 7:37 AM Wolfgang Denk wd@denx.de wrote:
Is there any chance you mis-applied my patch?
Ok, so I started again.
1. Applied the following patch: http://dark-code.bulix.org/tualst-517948
2. make mproper; make make pico-pi-imx7d_defconfig; make
3. Build fails:
/bin/sh: 1: printf: ((768 - 69) * 1024): expected numeric value u-boot-nodtb.bin exceeds file size limit: limit: 0 bytes actual: 482952 bytes excess: 482952 bytes
The reason for the failure is because there is an extra CONFIG_BOARD_SIZE_LIMIT check inside the main Makefile.
Your patch only covers arch/arm/mach-imx/Makefile.
If I remove the check from the main Makefile:
--- a/Makefile +++ b/Makefile @@ -772,21 +772,6 @@ LDPPFLAGS += \ ######################################################################### #########################################################################
-ifneq ($(CONFIG_BOARD_SIZE_LIMIT),) -BOARD_SIZE_CHECK = \ - @actual=`wc -c $@ | awk '{print $$1}'`; \ - limit=`printf "%d" $(CONFIG_BOARD_SIZE_LIMIT)`; \ - if test $$actual -gt $$limit; then \ - echo "$@ exceeds file size limit:" >&2 ; \ - echo " limit: $$limit bytes" >&2 ; \ - echo " actual: $$actual bytes" >&2 ; \ - echo " excess: $$((actual - limit)) bytes" >&2; \ - exit 1; \ - fi -else -BOARD_SIZE_CHECK = -endif - # Statically apply RELA-style relocations (currently arm64 only) # This is useful for arm64 where static relocation needs to be performed on # the raw binary, but certain simulators only accept an ELF file (but don't
Then I am able to successfully build it.
It seems we need to avoid the double CONFIG_BOARD_SIZE_LIMIT check.
Ideas?
Thanks

Dear Fabio,
In message CAOMZO5DMopeGgVWZ4U23V=Br0UsfX-_Q7PXaYu7n+O8k4EEwUw@mail.gmail.com you wrote:
Ok, so I started again.
Thanks!
The reason for the failure is because there is an extra CONFIG_BOARD_SIZE_LIMIT check inside the main Makefile.
Your patch only covers arch/arm/mach-imx/Makefile.
Argh...
Then I am able to successfully build it.
Great.
It seems we need to avoid the double CONFIG_BOARD_SIZE_LIMIT check.
IMO there is nothing architecture specific about this check, so we should probably patch the top level Makefile and remove the test in arch/arm/mach-imx/Makefile ?
Best regards,
Wolfgang Denk

Hi Wolfgang,
On Tue, Dec 4, 2018 at 11:03 AM Wolfgang Denk wd@denx.de wrote:
IMO there is nothing architecture specific about this check, so we should probably patch the top level Makefile and remove the test in arch/arm/mach-imx/Makefile ?
It is not so simple, for the two following reasons:
1. The imx check has been introduced by:
commit 43e6f94cbcaf193aeedcf86e85a3ff4c79f66773 Author: Marcel Ziswiler marcel.ziswiler@toradex.com Date: Fri Nov 9 15:31:17 2018 +0100
imx: mkimage: add size check to the u-boot.imx make target
The make macro to check if the binary exceeds the board size limit is taken straight from the root Makefile.
Without this and e.g. enabled EFI Vybrid fails booting as the regular size limit check does not take the final u-boot.imx binary size into account which is bigger due to alignment as well as IMX header stuff.
Signed-off-by: Marcel Ziswiler marcel.ziswiler@toradex.com Reviewed-by: Fabio Estevam festevam@gmail.com
2. For testing purpose, I removed the imx check and patched the main Makefile, but still got error: u-boot-nodtb.bin exceeds file size limit: limit: 0 bytes actual: 482968 bytes excess: 482968 bytes
How should we proceed?

Dear Fabio,
In message CAOMZO5AC--JreCuyWA2+Kudwcp1UPaMpynkWzAKfinGhUtzhvw@mail.gmail.com you wrote:
- The imx check has been introduced by:
commit 43e6f94cbcaf193aeedcf86e85a3ff4c79f66773 Author: Marcel Ziswiler marcel.ziswiler@toradex.com Date: Fri Nov 9 15:31:17 2018 +0100
imx: mkimage: add size check to the u-boot.imx make target The make macro to check if the binary exceeds the board size limit is taken straight from the root Makefile. Without this and e.g. enabled EFI Vybrid fails booting as the regular size limit check does not take the final u-boot.imx binary size into account which is bigger due to alignment as well as IMX header stuff.
OK, so this is an additional (second) test run for a special configuration, but the code to perform the test has just been duplicated from the top level makefile (which is not a nice thing).
I think we should tun this code either into a Makefile function that is defined only once and can then be used elsewhere as well, or turn it into an external script unter scripts/
What do you think?
- For testing purpose, I removed the imx check and patched the main
Makefile, but still got error: u-boot-nodtb.bin exceeds file size limit: limit: 0 bytes actual: 482968 bytes excess: 482968 bytes
What is your exact build target / command sequence to get here?
The "limit: 0 bytes" clearly indicates that the definition of CONFIG_BOARD_SIZE_LIMIT is not known to Make at this point, or wrong.
In the meantime, having the patch applied both to the TL Makefile and to the imx one should work at least as good as the previous code.
How should we proceed?
If I know how to repeat your exact test, I can try to fix that.
Best regards,
Wolfgang Denk

Hi Wolfgang,
On Tue, Dec 4, 2018 at 11:35 AM Wolfgang Denk wd@denx.de wrote:
OK, so this is an additional (second) test run for a special configuration, but the code to perform the test has just been duplicated from the top level makefile (which is not a nice thing).
I think we should tun this code either into a Makefile function that is defined only once and can then be used elsewhere as well, or turn it into an external script unter scripts/
What do you think?
Yes, I agree that we should avoid the specific imx duplication.
If I know how to repeat your exact test, I can try to fix that.
Please follow these steps:
1. Apply the following patch: http://dark-code.bulix.org/tualst-517948
2. Build pico pi mx7d target:
make mrproper make pico-pi-imx7d_defconfig make -j4
And then you will get the error:
/bin/sh: 1: printf: ((768 - 69) * 1024): expected numeric value u-boot-nodtb.bin exceeds file size limit: limit: 0 bytes actual: 482952 bytes excess: 482952 bytes
Thanks

So far, the use of CONFIG_BOARD_SIZE_LIMIT would only work with plain numeric constants. Extend it to allow for expressions, so one can for example use
#define CONFIG_BOARD_SIZE_LIMIT (768 << 10)
in the board configuration.
Signed-off-by: Wolfgang Denk wd@denx.de
Cc: Fabio Estevam festevam@gmail.com Cc: Stefano Babic sbabic@denx.de Cc: Vanessa Maegima vanessa.maegima@nxp.com Cc: Otavio Salvador otavio@ossystems.com.br Cc: John Weber john.weber@technexion.com Cc: Stefan Roese sr@denx.de
---
Note 1: As gawk lacks an eval function, we use bash's $((...)) mechanism to evaluate the expression. This has the additional benefit that it supports expressions like "<<" which awk does not understand. OK, one could replace awk by something better... Note 2: This patch focusses on enabling this new feature. It does not addres another issue that should be solved in a lter commit: the duplication of the same code in Makefile and arch/arm/mach-imx/Makefile
Makefile | 17 ++++++++--------- arch/arm/mach-imx/Makefile | 17 ++++++++--------- 2 files changed, 16 insertions(+), 18 deletions(-)
diff --git a/Makefile b/Makefile index 0d11ff9797..d4c8f697cf 100644 --- a/Makefile +++ b/Makefile @@ -774,15 +774,14 @@ LDPPFLAGS += \
ifneq ($(CONFIG_BOARD_SIZE_LIMIT),) BOARD_SIZE_CHECK = \ - @actual=`wc -c $@ | awk '{print $$1}'`; \ - limit=`printf "%d" $(CONFIG_BOARD_SIZE_LIMIT)`; \ - if test $$actual -gt $$limit; then \ - echo "$@ exceeds file size limit:" >&2 ; \ - echo " limit: $$limit bytes" >&2 ; \ - echo " actual: $$actual bytes" >&2 ; \ - echo " excess: $$((actual - limit)) bytes" >&2; \ - exit 1; \ - fi + @(echo $$(($(CONFIG_BOARD_SIZE_LIMIT))); wc -c $@ ) | \ + awk 'BEGIN { getline limit } \ + { if ($$1 > limit) { \ + printf "%s exceeds file size limit:\n", $$2; \ + printf " limit: %d bytes\n", limit; \ + printf " actual: %d bytes\n", $$1; \ + printf " excess: %d bytes\n", $$1 - limit; \ + exit 1; } }' else BOARD_SIZE_CHECK = endif diff --git a/arch/arm/mach-imx/Makefile b/arch/arm/mach-imx/Makefile index 53d9e5f42b..230a5c73aa 100644 --- a/arch/arm/mach-imx/Makefile +++ b/arch/arm/mach-imx/Makefile @@ -60,15 +60,14 @@ endif
ifneq ($(CONFIG_BOARD_SIZE_LIMIT),) BOARD_SIZE_CHECK = \ - @actual=`wc -c $@ | awk '{print $$1}'`; \ - limit=`printf "%d" $(CONFIG_BOARD_SIZE_LIMIT)`; \ - if test $$actual -gt $$limit; then \ - echo "$@ exceeds file size limit:" >&2 ; \ - echo " limit: $$limit bytes" >&2 ; \ - echo " actual: $$actual bytes" >&2 ; \ - echo " excess: $$((actual - limit)) bytes" >&2; \ - exit 1; \ - fi + @(echo $$(($(CONFIG_BOARD_SIZE_LIMIT))); wc -c $@ ) | \ + awk 'BEGIN { getline limit } \ + { if ($$1 > limit) { \ + printf "%s exceeds file size limit:\n", $$2; \ + printf " limit: %d bytes\n", limit; \ + printf " actual: %d bytes\n", $$1; \ + printf " excess: %d bytes\n", $$1 - limit; \ + exit 1; } }' else BOARD_SIZE_CHECK = endif

On Tue, Dec 4, 2018 at 1:40 PM Wolfgang Denk wd@denx.de wrote:
So far, the use of CONFIG_BOARD_SIZE_LIMIT would only work with plain numeric constants. Extend it to allow for expressions, so one can for example use
#define CONFIG_BOARD_SIZE_LIMIT (768 << 10)
in the board configuration.
Signed-off-by: Wolfgang Denk wd@denx.de
Cc: Fabio Estevam festevam@gmail.com Cc: Stefano Babic sbabic@denx.de Cc: Vanessa Maegima vanessa.maegima@nxp.com Cc: Otavio Salvador otavio@ossystems.com.br Cc: John Weber john.weber@technexion.com Cc: Stefan Roese sr@denx.de
Reviewed-by: Otavio Salvador otavio@ossystems.com.br
Thanks for looking into this.

Hi Wolfgang,
On Tue, Dec 4, 2018 at 1:40 PM Wolfgang Denk wd@denx.de wrote:
So far, the use of CONFIG_BOARD_SIZE_LIMIT would only work with plain numeric constants. Extend it to allow for expressions, so one can for example use
#define CONFIG_BOARD_SIZE_LIMIT (768 << 10)
in the board configuration.
Signed-off-by: Wolfgang Denk wd@denx.de
Still not working for me. I do see a warning now:
LD spl/u-boot-spl /bin/sh: 1: arithmetic expression: expecting primary: ""((768 - 69) * 1024)"" COPY u-boot.bin MKIMAGE u-boot.img OBJCOPY spl/u-boot-spl-nodtb.bin COPY spl/u-boot-spl.bin CFGS spl/u-boot-spl.cfgout MKIMAGE SPL CFGCHK u-boot.cfg
It does allow the build to proceed, but it is not really detecting the overlap anymore.
For example: let's force the overlap by setting a very small CONFIG_BOARD_SIZE_LIMIT of only 1K:
#define CONFIG_ENV_OFFSET (768 * 1024) #define CONFIG_BOARD_SIZE_LIMIT (1 * 1024)
/bin/sh: 1: arithmetic expression: expecting primary: ""(1 * 1024)"" COPY u-boot.bin MKIMAGE u-boot.img LD spl/drivers/usb/gadget/built-in.o LD spl/drivers/built-in.o LD spl/u-boot-spl OBJCOPY spl/u-boot-spl-nodtb.bin COPY spl/u-boot-spl.bin CFGS spl/u-boot-spl.cfgout MKIMAGE SPL CFGCHK u-boot.cfg
It still allowed a successful build, but it should have thrown an error about the overlap.

Dear Fabio,
In message CAOMZO5Co8KPCBx+gPS8w02cYJR2Ci9cpSKVQm3zy+JRgD1mtLw@mail.gmail.com you wrote:
Still not working for me. I do see a warning now:
LD spl/u-boot-spl /bin/sh: 1: arithmetic expression: expecting primary: ""((768 - 69) * 1024)"" COPY u-boot.bin MKIMAGE u-boot.img OBJCOPY spl/u-boot-spl-nodtb.bin COPY spl/u-boot-spl.bin CFGS spl/u-boot-spl.cfgout MKIMAGE SPL CFGCHK u-boot.cfg
I'm bulding with your modification:
diff --git a/include/configs/pico-imx7d.h b/include/configs/pico-imx7d.h index 2bc42a04a0..67ca700a2f 100644 --- a/include/configs/pico-imx7d.h +++ b/include/configs/pico-imx7d.h @@ -134,7 +134,8 @@ /* FLASH and environment organization */ #define CONFIG_ENV_SIZE SZ_8K
-#define CONFIG_ENV_OFFSET (8 * SZ_64K) +#define CONFIG_ENV_OFFSET (768 * 1024) +#define CONFIG_BOARD_SIZE_LIMIT ((768 - 69) * 1024) #define CONFIG_SYS_FSL_USDHC_NUM 2
#define CONFIG_SYS_MMC_ENV_DEV 0
... LD spl/common/spl/built-in.o CC spl/lib/display_options.o LD spl/lib/built-in.o LD spl/u-boot-spl OBJCOPY spl/u-boot-spl-nodtb.bin COPY spl/u-boot-spl.bin MKIMAGE SPL OBJCOPY u-boot.srec OBJCOPY u-boot-nodtb.bin COPY u-boot.bin SYM u-boot.sym MKIMAGE u-boot.img CHK include/config.h CFG u-boot.cfg ===================== WARNING ====================== This board does not use CONFIG_DM_MMC. Please update the board to use CONFIG_DM_MMC before the v2019.04 release. Failure to update by the deadline may result in board removal. See doc/driver-model/MIGRATION.txt for more info. ==================================================== ===================== WARNING ====================== This board does not use CONFIG_DM_USB. Please update the board to use CONFIG_DM_USB before the v2019.07 release. Failure to update by the deadline may result in board removal. See doc/driver-model/MIGRATION.txt for more info. ==================================================== CFGCHK u-boot.cfg
It does allow the build to proceed, but it is not really detecting the overlap anymore.
For example: let's force the overlap by setting a very small CONFIG_BOARD_SIZE_LIMIT of only 1K:
#define CONFIG_ENV_OFFSET (768 * 1024) #define CONFIG_BOARD_SIZE_LIMIT (1 * 1024)
Please try it on the shell:
-> echo $(( ((768 - 69) * 1024) )) 715776 -> echo $(( (1 * 1024) )) 1024
/bin/sh: 1: arithmetic expression: expecting primary: ""(1 * 1024)""
I tested this with /bin/bash, /bin/sh and even /bin/dash - they all work fine here.
It still allowed a successful build, but it should have thrown an error about the overlap.
It does for me, if I set the limit low:
OBJCOPY spl/u-boot-spl-nodtb.bin COPY spl/u-boot-spl.bin CFGS spl/u-boot-spl.cfgout MKIMAGE SPL OBJCOPY u-boot.srec OBJCOPY u-boot-nodtb.bin u-boot-nodtb.bin exceeds file size limit: limit: 1024 bytes actual: 480172 bytes excess: 479148 bytes make: *** [Makefile:1071: u-boot-nodtb.bin] Error 1
Best regards,
Wolfgang Denk

Hi Wolfgang,
On Wed, Dec 5, 2018 at 7:52 AM Wolfgang Denk wd@denx.de wrote:
Please try it on the shell:
-> echo $(( ((768 - 69) * 1024) )) 715776 -> echo $(( (1 * 1024) )) 1024
This works fine.
It does for me, if I set the limit low:
OBJCOPY spl/u-boot-spl-nodtb.bin COPY spl/u-boot-spl.bin CFGS spl/u-boot-spl.cfgout MKIMAGE SPL OBJCOPY u-boot.srec OBJCOPY u-boot-nodtb.bin u-boot-nodtb.bin exceeds file size limit: limit: 1024 bytes actual: 480172 bytes excess: 479148 bytes make: *** [Makefile:1071: u-boot-nodtb.bin] Error 1
Previously I tested on a machine running Ubuntu 16.04 and today I also tested on another machine running Ubuntu 18.04.
The results are the same on both machines:
1. I get a "expecting primary" warning:
OBJCOPY u-boot-nodtb.bin /bin/sh: 1: arithmetic expression: expecting primary: ""(1 * 1024)"" SYM u-boot.sym COPY u-boot.bin MKIMAGE u-boot.img LD spl/drivers/usb/host/built-in.o LD spl/drivers/built-in.o LD spl/u-boot-spl OBJCOPY spl/u-boot-spl-nodtb.bin COPY spl/u-boot-spl.bin CFGS spl/u-boot-spl.cfgout MKIMAGE SPL
2. The overlap is not detected anymore. In the example below I forced #define CONFIG_BOARD_SIZE_LIMIT (1 * 1024)

Dear Fabio,
In message CAOMZO5Aovrx43cmykUH+Bu_O_vC0CCs2hLVXFwCxmC2JDaKOYg@mail.gmail.com you wrote:
Previously I tested on a machine running Ubuntu 16.04 and today I also tested on another machine running Ubuntu 18.04.
The results are the same on both machines:
- I get a "expecting primary" warning:
OBJCOPY u-boot-nodtb.bin /bin/sh: 1: arithmetic expression: expecting primary: ""(1 * 1024)""
This makes really no sense to me. Can you please send me (off list) a git diff of the tree that is not building for you against the nearest mainline commit?
And please also the output of /"bin/sh --version".
I have:
-> /bin/sh --version GNU bash, version 4.4.23(1)-release (x86_64-redhat-linux-gnu) Copyright (C) 2016 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This is free software; you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.
[Sorry, can't test build under Ubuntu ATM; our container gives strange errors, and I have to wait until tomorrow as I don't want to mess with the setup.]
Best regards,
Wolfgang Denk

Hi Wolfgang,
On Thu, Dec 6, 2018 at 12:23 PM Wolfgang Denk wd@denx.de wrote:
This makes really no sense to me. Can you please send me (off list) a git diff of the tree that is not building for you against the nearest mainline commit?
I am running top of tree mainline U-Boot + your patch from this thread, plus:
--- a/include/configs/pico-imx7d.h +++ b/include/configs/pico-imx7d.h @@ -134,7 +134,8 @@ /* FLASH and environment organization */ #define CONFIG_ENV_SIZE SZ_8K
-#define CONFIG_ENV_OFFSET (8 * SZ_64K) +#define CONFIG_ENV_OFFSET (768 * 1024) +#define CONFIG_BOARD_SIZE_LIMIT (1 * 1024) #define CONFIG_SYS_FSL_USDHC_NUM 2
#define CONFIG_SYS_MMC_ENV_DEV 0
It does build fine, but as I have intentionally forced a small CONFIG_BOARD_SIZE_LIMIT I wanted it to fail, but it does not fail as shown below:
OBJCOPY u-boot-nodtb.bin /bin/sh: 1: arithmetic expression: expecting primary: ""(1 * 1024)"" SYM u-boot.sym COPY u-boot.bin MKIMAGE u-boot.img ===================== WARNING ====================== This board does not use CONFIG_DM_MMC. Please update the board to use CONFIG_DM_MMC before the v2019.04 release. Failure to update by the deadline may result in board removal. See doc/driver-model/MIGRATION.txt for more info. ==================================================== ===================== WARNING ====================== This board does not use CONFIG_DM_USB. Please update the board to use CONFIG_DM_USB before the v2019.07 release. Failure to update by the deadline may result in board removal. See doc/driver-model/MIGRATION.txt for more info. ==================================================== CFGCHK u-boot.cfg
As you can see there are two issues:
1. The warnin: /bin/sh: 1: arithmetic expression: expecting primary: ""(1 * 1024)""
2. It should have not built in this case. It should have detected the overlap and signalized the error
And please also the output of /"bin/sh --version".
$ /bin/sh --version /bin/sh: 0: Illegal option --
In my system /bin/sh points to bash: $ ls -al /bin/sh lrwxrwxrwx 1 root root 4 mai 2 2018 /bin/sh -> dash
/bin/bash --version GNU bash, version 4.4.19(1)-release (x86_64-pc-linux-gnu) Copyright (C) 2016 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This is free software; you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.
I am able to reproduce this problem with a standalone script:
$ cat random.sh #!/bin/bash echo $(($RANDOM % 10)) $ ./random.sh 3
Worked fine with bash.
Now if I force it to dash:
$ cat random.sh #!/bin/dash echo $(($RANDOM % 10)) $ ./random.sh ./random.sh: 2: ./random.sh: arithmetic expression: expecting primary: " % 10"
Which is the same warning I get in U-Boot.

Fabio wrote...
$ /bin/sh --version /bin/sh: 0: Illegal option --
In my system /bin/sh points to bash: $ ls -al /bin/sh lrwxrwxrwx 1 root root 4 mai 2 2018 /bin/sh -> dash
Just to pick up on the obvious… /bin/sh is showing as linked to dash not bash!
Using (( … )) for arithmetic expansion is a bashism [1]
[1] https://wiki.ubuntu.com/DashAsBinSh
-Andy.

On Thu, Dec 6, 2018 at 12:44 PM Andy Pont andy.pont@sdcsystems.com wrote:
Fabio wrote...
$ /bin/sh --version /bin/sh: 0: Illegal option --
In my system /bin/sh points to bash: $ ls -al /bin/sh lrwxrwxrwx 1 root root 4 mai 2 2018 /bin/sh -> dash
Just to pick up on the obvious… /bin/sh is showing as linked to dash not bash!
Yes, I meant bash.
Using (( … )) for arithmetic expansion is a bashism [1]
Correct: $ cat random.sh #!/bin/sh echo $(($RANDOM % 10)) $ checkbashisms random.sh possible bashism in random.sh line 2 ($RANDOM): echo $(($RANDOM % 10))

On Thu, Dec 6, 2018 at 12:58 PM Fabio Estevam festevam@gmail.com wrote:
On Thu, Dec 6, 2018 at 12:44 PM Andy Pont andy.pont@sdcsystems.com wrote:
Fabio wrote...
$ /bin/sh --version /bin/sh: 0: Illegal option --
In my system /bin/sh points to bash: $ ls -al /bin/sh lrwxrwxrwx 1 root root 4 mai 2 2018 /bin/sh -> dash
Just to pick up on the obvious… /bin/sh is showing as linked to dash not bash!
Yes, I meant bash.
I meant 'dash' :-)

Fabio,
let me chime in (I had to do a quick ‘git grep’ on this, as I couldn’t ignore the mail traffic any longer)...
On 06.12.2018, at 15:41, Fabio Estevam festevam@gmail.com wrote:
Hi Wolfgang,
On Thu, Dec 6, 2018 at 12:23 PM Wolfgang Denk wd@denx.de wrote:
This makes really no sense to me. Can you please send me (off list) a git diff of the tree that is not building for you against the nearest mainline commit?
I am running top of tree mainline U-Boot + your patch from this thread, plus:
--- a/include/configs/pico-imx7d.h +++ b/include/configs/pico-imx7d.h @@ -134,7 +134,8 @@ /* FLASH and environment organization */ #define CONFIG_ENV_SIZE SZ_8K
-#define CONFIG_ENV_OFFSET (8 * SZ_64K) +#define CONFIG_ENV_OFFSET (768 * 1024) +#define CONFIG_BOARD_SIZE_LIMIT (1 * 1024)
If you take a look at how CONFIG_BOARD_SIZE_LIMIT is used ifneq ($(CONFIG_BOARD_SIZE_LIMIT),) BOARD_SIZE_CHECK = \ @actual=`wc -c $@ | awk '{print $$1}'`; \ limit=`printf "%d" $(CONFIG_BOARD_SIZE_LIMIT)`; \ if test $$actual -gt $$limit; then \ echo "$@ exceeds file size limit:" >&2 ; \ echo " limit: $$limit bytes" >&2 ; \ echo " actual: $$actual bytes" >&2 ; \ echo " excess: $$((actual - limit)) bytes" >&2; \ exit 1; \ fi else BOARD_SIZE_CHECK = endif you will notice that there’s no arithmetic expansion on it prior to it being passed int a 'if -gt’ compare.
'git grep’ also shows that no other board is requesting an arithmetic expansion on this (i.e. everyone else just uses a constant).
Note that the C-preprocessor will not do arithmetic for you... So you’ll either have to change the Makefile or define this as an actual constant number.
#define CONFIG_SYS_FSL_USDHC_NUM 2
#define CONFIG_SYS_MMC_ENV_DEV 0
It does build fine, but as I have intentionally forced a small CONFIG_BOARD_SIZE_LIMIT I wanted it to fail, but it does not fail as shown below:
OBJCOPY u-boot-nodtb.bin /bin/sh: 1: arithmetic expression: expecting primary: ""(1 * 1024)"" SYM u-boot.sym COPY u-boot.bin MKIMAGE u-boot.img ===================== WARNING ====================== This board does not use CONFIG_DM_MMC. Please update the board to use CONFIG_DM_MMC before the v2019.04 release. Failure to update by the deadline may result in board removal. See doc/driver-model/MIGRATION.txt for more info. ==================================================== ===================== WARNING ====================== This board does not use CONFIG_DM_USB. Please update the board to use CONFIG_DM_USB before the v2019.07 release. Failure to update by the deadline may result in board removal. See doc/driver-model/MIGRATION.txt for more info. ==================================================== CFGCHK u-boot.cfg
As you can see there are two issues:
- The warnin: /bin/sh: 1: arithmetic expression: expecting primary:
""(1 * 1024)""
- It should have not built in this case. It should have detected the
overlap and signalized the error
And please also the output of /"bin/sh --version".
$ /bin/sh --version /bin/sh: 0: Illegal option --
In my system /bin/sh points to bash: $ ls -al /bin/sh lrwxrwxrwx 1 root root 4 mai 2 2018 /bin/sh -> dash
/bin/bash --version GNU bash, version 4.4.19(1)-release (x86_64-pc-linux-gnu) Copyright (C) 2016 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This is free software; you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.
I am able to reproduce this problem with a standalone script:
$ cat random.sh #!/bin/bash echo $(($RANDOM % 10)) $ ./random.sh 3
Worked fine with bash.
Now if I force it to dash:
$ cat random.sh #!/bin/dash echo $(($RANDOM % 10)) $ ./random.sh ./random.sh: 2: ./random.sh: arithmetic expression: expecting primary: " % 10"
Which is the same warning I get in U-Boot. _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de https://lists.denx.de/listinfo/u-boot

Hi Philipp,
On Thu, Dec 6, 2018 at 12:50 PM Philipp Tomsich philipp.tomsich@theobroma-systems.com wrote:
If you take a look at how CONFIG_BOARD_SIZE_LIMIT is used ifneq ($(CONFIG_BOARD_SIZE_LIMIT),) BOARD_SIZE_CHECK = \ @actual=`wc -c $@ | awk '{print $$1}'`; \ limit=`printf "%d" $(CONFIG_BOARD_SIZE_LIMIT)`; \ if test $$actual -gt $$limit; then \ echo "$@ exceeds file size limit:" >&2 ; \ echo " limit: $$limit bytes" >&2 ; \ echo " actual: $$actual bytes" >&2 ; \ echo " excess: $$((actual - limit)) bytes" >&2; \ exit 1; \ fi else BOARD_SIZE_CHECK = endif you will notice that there’s no arithmetic expansion on it prior to it being passed int a 'if -gt’ compare.
Yes, this the current code. The patch Wolfgang submitted in this thread changed the Makefile.
'git grep’ also shows that no other board is requesting an arithmetic expansion on this (i.e. everyone else just uses a constant).
Note that the C-preprocessor will not do arithmetic for you... So you’ll either have to change the Makefile or define this as an actual constant number.
Yes, Wolfgang's patch changed the Makefile to allow arithmetic operation, but it does not work on my system.

Hi Wolfgang,
[Adding Andy]
On Thu, Dec 6, 2018 at 12:41 PM Fabio Estevam festevam@gmail.com wrote:
I am running top of tree mainline U-Boot + your patch from this thread, plus:
--- a/include/configs/pico-imx7d.h +++ b/include/configs/pico-imx7d.h @@ -134,7 +134,8 @@ /* FLASH and environment organization */ #define CONFIG_ENV_SIZE SZ_8K
-#define CONFIG_ENV_OFFSET (8 * SZ_64K) +#define CONFIG_ENV_OFFSET (768 * 1024) +#define CONFIG_BOARD_SIZE_LIMIT (1 * 1024) #define CONFIG_SYS_FSL_USDHC_NUM 2
#define CONFIG_SYS_MMC_ENV_DEV 0
It does build fine, but as I have intentionally forced a small CONFIG_BOARD_SIZE_LIMIT I wanted it to fail, but it does not fail as shown below:
OBJCOPY u-boot-nodtb.bin /bin/sh: 1: arithmetic expression: expecting primary: ""(1 * 1024)""
I read the link suggested by Andy Pont: https://wiki.ubuntu.com/DashAsBinSh
where it says:
"In Makefiles, you can set the following variable at the top:
SHELL = /bin/bash"
And by forcing the SHELL variable to bash, then your patch works fine here:
--- a/Makefile +++ b/Makefile @@ -1,5 +1,6 @@ # SPDX-License-Identifier: GPL-2.0+
+SHELL = /bin/bash VERSION = 2019 PATCHLEVEL = 01 SUBLEVEL =

Dear Fabio,
In message CAOMZO5CnnmJrc9Y_9LQpxQYWQNcGeTUw=vgPtSpdmEPwavhU6g@mail.gmail.com you wrote:
/bin/sh: 1: arithmetic expression: expecting primary: ""(1 * 1024)""
D*mn. I really thought I had tried this in a dash based environment, too. Sorry for causing such confusion.
SHELL = /bin/bash"
Yes, if this is really a bash only feature that would be an easy way to fix it.
And by forcing the SHELL variable to bash, then your patch works fine here:
Yes, this would work - but I'm not sure if everybody would appreciate such a change?
This should also work - replace the line
@(echo $$(($(CONFIG_BOARD_SIZE_LIMIT))); wc -c $@ ) | \
by
@(awk "END { print $$(echo $(CONFIG_BOARD_SIZE_LIMIT)) }" /dev/null; wc -c $@ ) | \
Can you please try this out?
Best regards,
Wolfgang Denk

Hi Wolfgang,
On Fri, Dec 7, 2018 at 1:21 PM Wolfgang Denk wd@denx.de wrote:
This should also work - replace the line
@(echo $$(($(CONFIG_BOARD_SIZE_LIMIT))); wc -c $@ ) | \
by
@(awk "END { print $$(echo $(CONFIG_BOARD_SIZE_LIMIT)) }" /dev/null; wc -c $@ ) | \
Can you please try this out?
I replaced it on the main Makefile and also in the imx one and it works as expected now.
When you send the v2, you can add:
Tested-by: Fabio Estevam festevam@gmail.com
Thanks

Dear Fabio,
In message CAOMZO5BWH8g+h4pUBGzvgsS4Ae46kuREopx_0Fisyy7+KMq4Ug@mail.gmail.com you wrote:
I replaced it on the main Makefile and also in the imx one and it works as expected now.
Thanks.
When you send the v2, you can add:
Tested-by: Fabio Estevam festevam@gmail.com
Done. Thanks for your patience.
Best regards,
Wolfgang Denk

So far, the use of CONFIG_BOARD_SIZE_LIMIT would only work with plain numeric constants. Extend it to allow for expressions, so one can for example use
#define CONFIG_BOARD_SIZE_LIMIT (768 << 10)
in the board configuration.
Signed-off-by: Wolfgang Denk wd@denx.de Tested-by: Fabio Estevam festevam@gmail.com
Cc: Fabio Estevam festevam@gmail.com Cc: Stefano Babic sbabic@denx.de Cc: Vanessa Maegima vanessa.maegima@nxp.com Cc: Otavio Salvador otavio@ossystems.com.br Cc: John Weber john.weber@technexion.com Cc: Stefan Roese sr@denx.de --- v2: replace bashism for evaluating expressions in CONFIG_BOARD_SIZE_LIMIT by another call to awk.
Note 1: As gawk lacks an eval function and we don't want to rely on bash being used as shell, we use another call to awk to evaluate the expression. This has the disadvantage that we cannot use expressions like "<<" which awk does not understand. OK, one could replace awk by something better...
Note 2: This patch focusses on enabling this new feature. It does not addres another issue that should be solved in a later commit: the duplication of the same code in Makefile and arch/arm/mach-imx/Makefile
--- Makefile | 17 ++++++++--------- arch/arm/mach-imx/Makefile | 17 ++++++++--------- 2 files changed, 16 insertions(+), 18 deletions(-)
diff --git a/Makefile b/Makefile index 0d11ff9797..87eb0fd2b1 100644 --- a/Makefile +++ b/Makefile @@ -774,15 +774,14 @@ LDPPFLAGS += \
ifneq ($(CONFIG_BOARD_SIZE_LIMIT),) BOARD_SIZE_CHECK = \ - @actual=`wc -c $@ | awk '{print $$1}'`; \ - limit=`printf "%d" $(CONFIG_BOARD_SIZE_LIMIT)`; \ - if test $$actual -gt $$limit; then \ - echo "$@ exceeds file size limit:" >&2 ; \ - echo " limit: $$limit bytes" >&2 ; \ - echo " actual: $$actual bytes" >&2 ; \ - echo " excess: $$((actual - limit)) bytes" >&2; \ - exit 1; \ - fi + @(awk "END{print $$(echo $(CONFIG_BOARD_SIZE_LIMIT))}" /dev/null; wc -c $@ ) | \ + awk 'BEGIN { getline limit } \ + { if ($$1 > limit) { \ + printf "%s exceeds file size limit:\n", $$2; \ + printf " limit: %d bytes\n", limit; \ + printf " actual: %d bytes\n", $$1; \ + printf " excess: %d bytes\n", $$1 - limit; \ + exit 1; } }' else BOARD_SIZE_CHECK = endif diff --git a/arch/arm/mach-imx/Makefile b/arch/arm/mach-imx/Makefile index 53d9e5f42b..36d1ecc732 100644 --- a/arch/arm/mach-imx/Makefile +++ b/arch/arm/mach-imx/Makefile @@ -60,15 +60,14 @@ endif
ifneq ($(CONFIG_BOARD_SIZE_LIMIT),) BOARD_SIZE_CHECK = \ - @actual=`wc -c $@ | awk '{print $$1}'`; \ - limit=`printf "%d" $(CONFIG_BOARD_SIZE_LIMIT)`; \ - if test $$actual -gt $$limit; then \ - echo "$@ exceeds file size limit:" >&2 ; \ - echo " limit: $$limit bytes" >&2 ; \ - echo " actual: $$actual bytes" >&2 ; \ - echo " excess: $$((actual - limit)) bytes" >&2; \ - exit 1; \ - fi + @(awk "END{print $$(echo $(CONFIG_BOARD_SIZE_LIMIT))}" /dev/null; wc -c $@ ) | \ + awk 'BEGIN { getline limit } \ + { if ($$1 > limit) { \ + printf "%s exceeds file size limit:\n", $$2; \ + printf " limit: %d bytes\n", limit; \ + printf " actual: %d bytes\n", $$1; \ + printf " excess: %d bytes\n", $$1 - limit; \ + exit 1; } }' else BOARD_SIZE_CHECK = endif

On Fri, Dec 07, 2018 at 08:27:51PM +0100, Wolfgang Denk wrote:
So far, the use of CONFIG_BOARD_SIZE_LIMIT would only work with plain numeric constants. Extend it to allow for expressions, so one can for example use
#define CONFIG_BOARD_SIZE_LIMIT (768 << 10)
in the board configuration.
Signed-off-by: Wolfgang Denk wd@denx.de Tested-by: Fabio Estevam festevam@gmail.com
Cc: Fabio Estevam festevam@gmail.com Cc: Stefano Babic sbabic@denx.de Cc: Vanessa Maegima vanessa.maegima@nxp.com Cc: Otavio Salvador otavio@ossystems.com.br Cc: John Weber john.weber@technexion.com Cc: Stefan Roese sr@denx.de
v2: replace bashism for evaluating expressions in CONFIG_BOARD_SIZE_LIMIT by another call to awk.
Note 1: As gawk lacks an eval function and we don't want to rely on bash being used as shell, we use another call to awk to evaluate the expression. This has the disadvantage that we cannot use expressions like "<<" which awk does not understand. OK, one could replace awk by something better...
Note 2: This patch focusses on enabling this new feature. It does not addres another issue that should be solved in a later commit: the duplication of the same code in Makefile and arch/arm/mach-imx/Makefile
Makefile | 17 ++++++++--------- arch/arm/mach-imx/Makefile | 17 ++++++++--------- 2 files changed, 16 insertions(+), 18 deletions(-)
diff --git a/Makefile b/Makefile index 0d11ff9797..87eb0fd2b1 100644 --- a/Makefile +++ b/Makefile @@ -774,15 +774,14 @@ LDPPFLAGS += \
ifneq ($(CONFIG_BOARD_SIZE_LIMIT),) BOARD_SIZE_CHECK = \
- @actual=`wc -c $@ | awk '{print $$1}'`; \
- limit=`printf "%d" $(CONFIG_BOARD_SIZE_LIMIT)`; \
- if test $$actual -gt $$limit; then \
echo "$@ exceeds file size limit:" >&2 ; \
echo " limit: $$limit bytes" >&2 ; \
echo " actual: $$actual bytes" >&2 ; \
echo " excess: $$((actual - limit)) bytes" >&2; \
exit 1; \
- fi
- @(awk "END{print $$(echo $(CONFIG_BOARD_SIZE_LIMIT))}" /dev/null; wc -c $@ ) | \
So this fails with awk being provided by mawk, not gawk: $ mawk "END{print $(echo 0xE0000)}" /dev/null; 0 $ gawk "END{print $(echo 0xE0000)}" /dev/null; 917504
And then things fail as mawk doesn't like hex.
Now, at the end of the day, I'm now not sure I agree with this patch in concept. When CONFIG_BOARD_SIZE_LIMIT is moved to Kconfig it will be taking I would assume a hex input and so we don't have to worry about << at all.

Tom,
On Fri, Dec 14, 2018 at 8:16 PM Tom Rini trini@konsulko.com wrote:
On Fri, Dec 07, 2018 at 08:27:51PM +0100, Wolfgang Denk wrote:
So far, the use of CONFIG_BOARD_SIZE_LIMIT would only work with plain numeric constants. Extend it to allow for expressions, so one can for example use
#define CONFIG_BOARD_SIZE_LIMIT (768 << 10)
in the board configuration.
Signed-off-by: Wolfgang Denk wd@denx.de Tested-by: Fabio Estevam festevam@gmail.com
Cc: Fabio Estevam festevam@gmail.com Cc: Stefano Babic sbabic@denx.de Cc: Vanessa Maegima vanessa.maegima@nxp.com Cc: Otavio Salvador otavio@ossystems.com.br Cc: John Weber john.weber@technexion.com Cc: Stefan Roese sr@denx.de
v2: replace bashism for evaluating expressions in CONFIG_BOARD_SIZE_LIMIT by another call to awk.
Note 1: As gawk lacks an eval function and we don't want to rely on bash being used as shell, we use another call to awk to evaluate the expression. This has the disadvantage that we cannot use expressions like "<<" which awk does not understand. OK, one could replace awk by something better...
Note 2: This patch focusses on enabling this new feature. It does not addres another issue that should be solved in a later commit: the duplication of the same code in Makefile and arch/arm/mach-imx/Makefile
Makefile | 17 ++++++++--------- arch/arm/mach-imx/Makefile | 17 ++++++++--------- 2 files changed, 16 insertions(+), 18 deletions(-)
diff --git a/Makefile b/Makefile index 0d11ff9797..87eb0fd2b1 100644 --- a/Makefile +++ b/Makefile @@ -774,15 +774,14 @@ LDPPFLAGS += \
ifneq ($(CONFIG_BOARD_SIZE_LIMIT),) BOARD_SIZE_CHECK = \
@actual=`wc -c $@ | awk '{print $$1}'`; \
limit=`printf "%d" $(CONFIG_BOARD_SIZE_LIMIT)`; \
if test $$actual -gt $$limit; then \
echo "$@ exceeds file size limit:" >&2 ; \
echo " limit: $$limit bytes" >&2 ; \
echo " actual: $$actual bytes" >&2 ; \
echo " excess: $$((actual - limit)) bytes" >&2; \
exit 1; \
fi
@(awk "END{print $$(echo $(CONFIG_BOARD_SIZE_LIMIT))}" /dev/null; wc -c $@ ) | \
So this fails with awk being provided by mawk, not gawk: $ mawk "END{print $(echo 0xE0000)}" /dev/null; 0 $ gawk "END{print $(echo 0xE0000)}" /dev/null; 917504
And then things fail as mawk doesn't like hex.
Now, at the end of the day, I'm now not sure I agree with this patch in concept. When CONFIG_BOARD_SIZE_LIMIT is moved to Kconfig it will be taking I would assume a hex input and so we don't have to worry about << at all.
Sorry to warm up an old thread, but I have some slightly new input on this.
I can understand you disliking the concept of this patch regarding U-Boot proper size check (if CONFIG_BOARD_SIZE_LIMIT moves to Kconfig).
However, I think for SPL this is different: SPL often starts with one single small SRAM shared for code + data. In this case, the size available for the SPL binary often can be calculated like this:
CONFIG_SPL_MAX_SIZE = SRAM_SIZE - SYS_MALLOC_F_LEN - GENERATED_GBL_DATA_SIZE - STACKSIZE;
Being like that, it cannot just be moved to Kconfig and by definition is not a hardcoded single hex number but changes depending on other options.
I see two ways out here: a) continue the way of this patch until it works for all shells/awks or b) implement SPL binary size check using 4 constants instead of 1 (see above)
I'm willing to code this through, as I am hitting this limit on socfpga, so I could need a decision ;-)
Regards, Simon

On Wed, Mar 06, 2019 at 09:54:20PM +0100, Simon Goldschmidt wrote:
Tom,
On Fri, Dec 14, 2018 at 8:16 PM Tom Rini trini@konsulko.com wrote:
On Fri, Dec 07, 2018 at 08:27:51PM +0100, Wolfgang Denk wrote:
So far, the use of CONFIG_BOARD_SIZE_LIMIT would only work with plain numeric constants. Extend it to allow for expressions, so one can for example use
#define CONFIG_BOARD_SIZE_LIMIT (768 << 10)
in the board configuration.
Signed-off-by: Wolfgang Denk wd@denx.de Tested-by: Fabio Estevam festevam@gmail.com
Cc: Fabio Estevam festevam@gmail.com Cc: Stefano Babic sbabic@denx.de Cc: Vanessa Maegima vanessa.maegima@nxp.com Cc: Otavio Salvador otavio@ossystems.com.br Cc: John Weber john.weber@technexion.com Cc: Stefan Roese sr@denx.de
v2: replace bashism for evaluating expressions in CONFIG_BOARD_SIZE_LIMIT by another call to awk.
Note 1: As gawk lacks an eval function and we don't want to rely on bash being used as shell, we use another call to awk to evaluate the expression. This has the disadvantage that we cannot use expressions like "<<" which awk does not understand. OK, one could replace awk by something better...
Note 2: This patch focusses on enabling this new feature. It does not addres another issue that should be solved in a later commit: the duplication of the same code in Makefile and arch/arm/mach-imx/Makefile
Makefile | 17 ++++++++--------- arch/arm/mach-imx/Makefile | 17 ++++++++--------- 2 files changed, 16 insertions(+), 18 deletions(-)
diff --git a/Makefile b/Makefile index 0d11ff9797..87eb0fd2b1 100644 --- a/Makefile +++ b/Makefile @@ -774,15 +774,14 @@ LDPPFLAGS += \
ifneq ($(CONFIG_BOARD_SIZE_LIMIT),) BOARD_SIZE_CHECK = \
@actual=`wc -c $@ | awk '{print $$1}'`; \
limit=`printf "%d" $(CONFIG_BOARD_SIZE_LIMIT)`; \
if test $$actual -gt $$limit; then \
echo "$@ exceeds file size limit:" >&2 ; \
echo " limit: $$limit bytes" >&2 ; \
echo " actual: $$actual bytes" >&2 ; \
echo " excess: $$((actual - limit)) bytes" >&2; \
exit 1; \
fi
@(awk "END{print $$(echo $(CONFIG_BOARD_SIZE_LIMIT))}" /dev/null; wc -c $@ ) | \
So this fails with awk being provided by mawk, not gawk: $ mawk "END{print $(echo 0xE0000)}" /dev/null; 0 $ gawk "END{print $(echo 0xE0000)}" /dev/null; 917504
And then things fail as mawk doesn't like hex.
Now, at the end of the day, I'm now not sure I agree with this patch in concept. When CONFIG_BOARD_SIZE_LIMIT is moved to Kconfig it will be taking I would assume a hex input and so we don't have to worry about << at all.
Sorry to warm up an old thread, but I have some slightly new input on this.
I can understand you disliking the concept of this patch regarding U-Boot proper size check (if CONFIG_BOARD_SIZE_LIMIT moves to Kconfig).
However, I think for SPL this is different: SPL often starts with one single small SRAM shared for code + data. In this case, the size available for the SPL binary often can be calculated like this:
CONFIG_SPL_MAX_SIZE = SRAM_SIZE - SYS_MALLOC_F_LEN - GENERATED_GBL_DATA_SIZE - STACKSIZE;
Being like that, it cannot just be moved to Kconfig and by definition is not a hardcoded single hex number but changes depending on other options.
I see two ways out here: a) continue the way of this patch until it works for all shells/awks or b) implement SPL binary size check using 4 constants instead of 1 (see above)
I'm willing to code this through, as I am hitting this limit on socfpga, so I could need a decision ;-)
OK, so a few thoughts here. - What's the portable way to do hex-based math? If we really need it? - Really, CONFIG_{SPL,TPL}_MAX_SIZE is not user configurable, it's the SoC/design imposed limit. CONFIG_BOARD_MAX_SIZE is somewhat configurable as that tends to also include "don't grow past X or we overwrite Y and break things".
Part of the problem area is that we need to take N values, which are #defined, and use that to see if our final result is too large. Prior to needing device tree stuff, OK, we can get the linker on our side to enforce this (well enough that we can fudge the rest, ie artificially lower SRAM size a little and comment on why). With DTBs and such, we need to take a look at the final result too, of each stage.
So yes, I think we need to figure out some portable way to deal with checking all constants. And we'll Kconfig what we can/should Kconfig, and #define what we need to define and (ugh) calculate and use what must be done that way. Thanks!

On Fri, Mar 08, 2019 at 12:17:09PM -0500, Tom Rini wrote:
OK, so a few thoughts here.
- What's the portable way to do hex-based math? If we really need it?
Use printf(3) to convert to/from hex, and standard shell arithmetic with $(( )).
Looks horrible, but something like:
v=$(( $( printf "%d\n" 0xa0 ) + $( printf "%d\n" 0x10 ) )) printf "v = %d (%x)\n" $v $v
... maybe arranged into some sh helper functions.
Martin

On 08.03.2019, at 18:28, Martin Husemann martin@NetBSD.org wrote:
On Fri, Mar 08, 2019 at 12:17:09PM -0500, Tom Rini wrote:
OK, so a few thoughts here.
- What's the portable way to do hex-based math? If we really need it?
Use printf(3) to convert to/from hex, and standard shell arithmetic with $(( )).
Looks horrible, but something like:
v=$(( $( printf "%d\n" 0xa0 ) + $( printf "%d\n" 0x10 ) )) printf "v = %d (%x)\n" $v $v
Can we just assume that awk is available? After all, AWK is defined in the top-level Makefile...
... maybe arranged into some sh helper functions.
Martin _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de https://lists.denx.de/listinfo/u-boot

Philipp Tomsich philipp.tomsich@theobroma-systems.com schrieb am Fr., 8. März 2019, 18:53:
On 08.03.2019, at 18:28, Martin Husemann martin@NetBSD.org wrote:
On Fri, Mar 08, 2019 at 12:17:09PM -0500, Tom Rini wrote:
OK, so a few thoughts here.
- What's the portable way to do hex-based math? If we really need it?
Use printf(3) to convert to/from hex, and standard shell arithmetic with $(( )).
Looks horrible, but something like:
v=$(( $( printf "%d\n" 0xa0 ) + $( printf "%d\n" 0x10 ) )) printf "v = %d (%x)\n" $v $v
Can we just assume that awk is available? After all, AWK is defined in the top-level Makefile...
I guess we can, but see Toms mail from mid of December: not all awk flavours seem to supper hey numbers. So I guess the next round on this patch should try to test different shells as well as different awk's...
Regards, Simon

On Fri, Mar 08, 2019 at 06:53:28PM +0100, Philipp Tomsich wrote:
On 08.03.2019, at 18:28, Martin Husemann martin@NetBSD.org wrote:
On Fri, Mar 08, 2019 at 12:17:09PM -0500, Tom Rini wrote:
OK, so a few thoughts here.
- What's the portable way to do hex-based math? If we really need it?
Use printf(3) to convert to/from hex, and standard shell arithmetic with $(( )).
Looks horrible, but something like:
v=$(( $( printf "%d\n" 0xa0 ) + $( printf "%d\n" 0x10 ) )) printf "v = %d (%x)\n" $v $v
Can we just assume that awk is available? After all, AWK is defined in the top-level Makefile...
No, we can't exactly. In sum, gawk and mawk behave differently and mawk doesn't do hex and yes, we run into that in the wild. Whatever we do here needs to be POSIX shell happy (or something more strict than that?) as it needs to work on macOS and Free/Net/OpenBSD and anything else that we can otherwise be building on.

On 08/Mar/2019 18:28, Martin Husemann wrote:
On Fri, Mar 08, 2019 at 12:17:09PM -0500, Tom Rini wrote:
OK, so a few thoughts here.
- What's the portable way to do hex-based math? If we really need it?
Use printf(3) to convert to/from hex, and standard shell arithmetic with $(( )).
Looks horrible, but something like:
v=$(( $( printf "%d\n" 0xa0 ) + $( printf "%d\n" 0x10 ) )) printf "v = %d (%x)\n" $v $v
... maybe arranged into some sh helper functions.
dash, bash, mksh, zsh, all ksh-compatible shells in fact, support hex numbers on arithmetic expressions, no need for conversion.

Hi Stefano,
On Fri, Nov 30, 2018 at 12:52 PM Fabio Estevam festevam@gmail.com wrote:
U-Boot binary has grown in such a way that it goes beyond the reserved area for the environment variables.
Running "saveenv" causes U-Boot to hang because of this overlap.
Fix this problem by increasing the CONFIG_ENV_OFFSET size.
Also, in order to prevent this same problem in the future, use CONFIG_BOARD_SIZE_LIMIT, which will detect the overlap in build-time.
CONFIG_BOARD_SIZE_LIMIT does not accept math expressions, so declare CONFIG_ENV_OFFSET with its direct value instead.
Signed-off-by: Fabio Estevam festevam@gmail.com
Changes since v3:
- Take the 69k u-boot.img offset into account when calculating
CONFIG_BOARD_SIZE_LIMIT (Wolfgang)
Could you please consider applying this version?
Wolfgang's patch causes breakage on some systems as reported by Tom and I would prefer we fix the critical problem soon independently of Wolgang's fix.
Thanks

On 17/12/18 15:13, Fabio Estevam wrote:
Hi Stefano,
On Fri, Nov 30, 2018 at 12:52 PM Fabio Estevam festevam@gmail.com wrote:
U-Boot binary has grown in such a way that it goes beyond the reserved area for the environment variables.
Running "saveenv" causes U-Boot to hang because of this overlap.
Fix this problem by increasing the CONFIG_ENV_OFFSET size.
Also, in order to prevent this same problem in the future, use CONFIG_BOARD_SIZE_LIMIT, which will detect the overlap in build-time.
CONFIG_BOARD_SIZE_LIMIT does not accept math expressions, so declare CONFIG_ENV_OFFSET with its direct value instead.
Signed-off-by: Fabio Estevam festevam@gmail.com
Changes since v3:
- Take the 69k u-boot.img offset into account when calculating
CONFIG_BOARD_SIZE_LIMIT (Wolfgang)
Could you please consider applying this version?
Wolfgang's patch causes breakage on some systems as reported by Tom and I would prefer we fix the critical problem soon independently of Wolgang's fix.
Yes, I agree with you - we could have a follow up patch when Wolfgang's patch will be merged.
Best regards, Stefano

Hi Stefano,
On Mon, Dec 17, 2018 at 12:47 PM Stefano Babic sbabic@denx.de wrote:
Yes, I agree with you - we could have a follow up patch when Wolfgang's patch will be merged.
Yes, I will send a follow up patch after Wolfgang's patch is accepted.
Thanks
participants (10)
-
Andy Pont
-
Fabio Estevam
-
Ismael Luceno Cortes
-
Martin Husemann
-
Otavio Salvador
-
Philipp Tomsich
-
Simon Goldschmidt
-
Stefano Babic
-
Tom Rini
-
Wolfgang Denk