public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [RFC/PATCH] Makefile: allow boards to check file size limits
@ 2010-10-14  2:58 Mike Frysinger
  2010-10-18 20:43 ` Wolfgang Denk
  2010-10-19 21:29 ` Wolfgang Denk
  0 siblings, 2 replies; 10+ messages in thread
From: Mike Frysinger @ 2010-10-14  2:58 UTC (permalink / raw)
  To: u-boot

Boards often have a reserved size limit on the flash where they're stored.
Sometimes during upgrades or config changes, those limits are exceeded,
but no one notices until they try to upgrade and the limit screws things
up.  Either not enough of U-Boot is written to flash (and so the reboot
fails), or too much is written (and so things after it get clobbered).

So allow boards to declare a size limit (in bytes) and have the build
system check it while building.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
 Makefile |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/Makefile b/Makefile
index de4ceb9..ca12d78 100644
--- a/Makefile
+++ b/Makefile
@@ -304,6 +304,21 @@ __LIBS := $(subst $(obj),,$(LIBS)) $(subst $(obj),,$(LIBBOARD))
 #########################################################################
 #########################################################################
 
+ifneq ($(CONFIG_BOARD_SIZE_LIMIT),)
+BOARD_SIZE_CHECK = \
+	@actual=`wc -c $@ | awk '{print $$1}'`; \
+	limit=$(CONFIG_BOARD_SIZE_LIMIT); \
+	if test $$actual -gt $$limit; then \
+		echo "$@ exceeds file size limit:"; \
+		echo "  limit:  $$limit bytes"; \
+		echo "  actual: $$actual bytes"; \
+		echo "  excess: $$((actual - limit)) bytes"; \
+		exit 1; \
+	fi
+else
+BOARD_SIZE_CHECK =
+endif
+
 # Always append ALL so that arch config.mk's can add custom ones
 ALL += $(obj)u-boot.srec $(obj)u-boot.bin $(obj)System.map $(U_BOOT_NAND) $(U_BOOT_ONENAND)
 
@@ -317,10 +332,12 @@ $(obj)u-boot.srec:	$(obj)u-boot
 
 $(obj)u-boot.bin:	$(obj)u-boot
 		$(OBJCOPY) ${OBJCFLAGS} -O binary $< $@
+		$(BOARD_SIZE_CHECK)
 
 $(obj)u-boot.ldr:	$(obj)u-boot
 		$(CREATE_LDR_ENV)
 		$(LDR) -T $(CONFIG_BFIN_CPU) -c $@ $< $(LDR_FLAGS)
+		$(BOARD_SIZE_CHECK)
 
 $(obj)u-boot.ldr.hex:	$(obj)u-boot.ldr
 		$(OBJCOPY) ${OBJCFLAGS} -O ihex $< $@ -I binary
-- 
1.7.3.1

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [U-Boot] [RFC/PATCH] Makefile: allow boards to check file size limits
  2010-10-14  2:58 [U-Boot] [RFC/PATCH] Makefile: allow boards to check file size limits Mike Frysinger
@ 2010-10-18 20:43 ` Wolfgang Denk
  2010-10-19  4:17   ` Mike Frysinger
  2010-10-19 21:29 ` Wolfgang Denk
  1 sibling, 1 reply; 10+ messages in thread
From: Wolfgang Denk @ 2010-10-18 20:43 UTC (permalink / raw)
  To: u-boot

Dear Mike Frysinger,

In message <1287025103-26681-1-git-send-email-vapier@gentoo.org> you wrote:
> Boards often have a reserved size limit on the flash where they're stored.
> Sometimes during upgrades or config changes, those limits are exceeded,
> but no one notices until they try to upgrade and the limit screws things
> up.  Either not enough of U-Boot is written to flash (and so the reboot
> fails), or too much is written (and so things after it get clobbered).
> 
> So allow boards to declare a size limit (in bytes) and have the build
> system check it while building.
> 
> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
> ---
>  Makefile |   17 +++++++++++++++++
>  1 files changed, 17 insertions(+), 0 deletions(-)
> 
> diff --git a/Makefile b/Makefile
> index de4ceb9..ca12d78 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -304,6 +304,21 @@ __LIBS := $(subst $(obj),,$(LIBS)) $(subst $(obj),,$(LIBBOARD))
>  #########################################################################
>  #########################################################################
>  
> +ifneq ($(CONFIG_BOARD_SIZE_LIMIT),)
> +BOARD_SIZE_CHECK = \
> +	@actual=`wc -c $@ | awk '{print $$1}'`; \

How about using

	stat -c '%s'

to get the file size in a single command, without need to actually
read all the data?


Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
"No matter where you go, there you are..."          - Buckaroo Banzai

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [U-Boot] [RFC/PATCH] Makefile: allow boards to check file size limits
  2010-10-18 20:43 ` Wolfgang Denk
@ 2010-10-19  4:17   ` Mike Frysinger
  2010-10-19  5:24     ` Wolfgang Denk
  0 siblings, 1 reply; 10+ messages in thread
From: Mike Frysinger @ 2010-10-19  4:17 UTC (permalink / raw)
  To: u-boot

On Monday, October 18, 2010 16:43:37 Wolfgang Denk wrote:
> Mike Frysinger wrote:
> > +ifneq ($(CONFIG_BOARD_SIZE_LIMIT),)
> > +BOARD_SIZE_CHECK = \
> > +	@actual=`wc -c $@ | awk '{print $$1}'`; \
> 
> How about using
> 
> 	stat -c '%s'
> 
> to get the file size in a single command, without need to actually
> read all the data?

because `stat` isnt portable :(.  it isnt part of the POSIX standard ... OS X 
certainly does not support this, and i imagine most *BSD's dont.

`wc -c` on the other hand should work everywhere and is part of POSIX.  
looking at the `strace` output, the GNU wc doesnt actually read() the file 
when using just the -c option.  seems to use lseek(SEEK_END).
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20101019/1ecdb70b/attachment.pgp 

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [U-Boot] [RFC/PATCH] Makefile: allow boards to check file size limits
  2010-10-19  4:17   ` Mike Frysinger
@ 2010-10-19  5:24     ` Wolfgang Denk
  2010-10-19  5:38       ` Mike Frysinger
  0 siblings, 1 reply; 10+ messages in thread
From: Wolfgang Denk @ 2010-10-19  5:24 UTC (permalink / raw)
  To: u-boot

Dear Mike Frysinger,

In message <201010190017.52346.vapier@gentoo.org> you wrote:
>
> > > +	@actual=`wc -c $@ | awk '{print $$1}'`; \
> > 
> > How about using
> > 
> > 	stat -c '%s'
> > 
> > to get the file size in a single command, without need to actually
> > read all the data?
>
> because `stat` isnt portable :(.  it isnt part of the POSIX standard ... OSX 
> certainly does not support this, and i imagine most *BSD's dont.

I see (well, at least FreeBSD 8.1 has "stat"; their man page claims it
"appeared in NetBSD 1.6 and FreeBSD 4.10).

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
"The two most common things in the universe are hydrogen  and  stupi-
dity."

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [U-Boot] [RFC/PATCH] Makefile: allow boards to check file size limits
  2010-10-19  5:24     ` Wolfgang Denk
@ 2010-10-19  5:38       ` Mike Frysinger
  0 siblings, 0 replies; 10+ messages in thread
From: Mike Frysinger @ 2010-10-19  5:38 UTC (permalink / raw)
  To: u-boot

On Tuesday, October 19, 2010 01:24:44 Wolfgang Denk wrote:
> Mike Frysinger wrote:
> > > > +	@actual=`wc -c $@ | awk '{print $$1}'`; \
> > > 
> > > How about using
> > > 
> > > 	stat -c '%s'
> > > 
> > > to get the file size in a single command, without need to actually
> > > read all the data?
> > 
> > because `stat` isnt portable :(.  it isnt part of the POSIX standard ...
> > OSX certainly does not support this, and i imagine most *BSD's dont.
> 
> I see (well, at least FreeBSD 8.1 has "stat"; their man page claims it
> "appeared in NetBSD 1.6 and FreeBSD 4.10).

yes, but what i was referring to was the command line options.  everyone has 
`stat`, but it's really only the GNU stat that supports the '-c fmt' option 
using the semantics necessary here.  `wc -c` is going to work everywhere, but 
i would need to figure out what OS i'm on and where `stat` is coming from so i 
would know how to properly invoke it.
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20101019/78d42511/attachment.pgp 

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [U-Boot] [RFC/PATCH] Makefile: allow boards to check file size limits
  2010-10-14  2:58 [U-Boot] [RFC/PATCH] Makefile: allow boards to check file size limits Mike Frysinger
  2010-10-18 20:43 ` Wolfgang Denk
@ 2010-10-19 21:29 ` Wolfgang Denk
  2010-10-20  4:38   ` Vaibhav Bedia
  1 sibling, 1 reply; 10+ messages in thread
From: Wolfgang Denk @ 2010-10-19 21:29 UTC (permalink / raw)
  To: u-boot

Dear Mike Frysinger,

In message <1287025103-26681-1-git-send-email-vapier@gentoo.org> you wrote:
> Boards often have a reserved size limit on the flash where they're stored.
> Sometimes during upgrades or config changes, those limits are exceeded,
> but no one notices until they try to upgrade and the limit screws things
> up.  Either not enough of U-Boot is written to flash (and so the reboot
> fails), or too much is written (and so things after it get clobbered).
> 
> So allow boards to declare a size limit (in bytes) and have the build
> system check it while building.
> 
> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
> ---
>  Makefile |   17 +++++++++++++++++
>  1 files changed, 17 insertions(+), 0 deletions(-)

Applied, thanks.

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
A memorandum is written not to inform the reader, but to protect  the
writer.                                               -- Dean Acheson

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [U-Boot] [RFC/PATCH] Makefile: allow boards to check file size limits
  2010-10-19 21:29 ` Wolfgang Denk
@ 2010-10-20  4:38   ` Vaibhav Bedia
  2010-10-20  5:16     ` Mike Frysinger
  0 siblings, 1 reply; 10+ messages in thread
From: Vaibhav Bedia @ 2010-10-20  4:38 UTC (permalink / raw)
  To: u-boot

Hi,

The size of other sections like the bss section also need to be accounted
for when doing a size check.

Insufficient space for bss when doing something like a MMC read which
requires large buffers causes system hangs for no apparent reason.

Regards,
Vaibhav

On Wed, Oct 20, 2010 at 2:59 AM, Wolfgang Denk <wd@denx.de> wrote:

> Dear Mike Frysinger,
>
> In message <1287025103-26681-1-git-send-email-vapier@gentoo.org> you
> wrote:
> > Boards often have a reserved size limit on the flash where they're
> stored.
> > Sometimes during upgrades or config changes, those limits are exceeded,
> > but no one notices until they try to upgrade and the limit screws things
> > up.  Either not enough of U-Boot is written to flash (and so the reboot
> > fails), or too much is written (and so things after it get clobbered).
> >
> > So allow boards to declare a size limit (in bytes) and have the build
> > system check it while building.
> >
> > Signed-off-by: Mike Frysinger <vapier@gentoo.org>
> > ---
> >  Makefile |   17 +++++++++++++++++
> >  1 files changed, 17 insertions(+), 0 deletions(-)
>
> Applied, thanks.
>
> Best regards,
>
> Wolfgang Denk
>
> --
> DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
> HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
> Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
> A memorandum is written not to inform the reader, but to protect  the
> writer.                                               -- Dean Acheson
> _______________________________________________
> U-Boot mailing list
> U-Boot at lists.denx.de
> http://lists.denx.de/mailman/listinfo/u-boot
>



-- 
Regards,
Vaibhav

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [U-Boot] [RFC/PATCH] Makefile: allow boards to check file size limits
  2010-10-20  4:38   ` Vaibhav Bedia
@ 2010-10-20  5:16     ` Mike Frysinger
  2010-10-20  6:56       ` Vaibhav Bedia
  0 siblings, 1 reply; 10+ messages in thread
From: Mike Frysinger @ 2010-10-20  5:16 UTC (permalink / raw)
  To: u-boot

On Wednesday, October 20, 2010 00:38:08 Vaibhav Bedia wrote:

please do not top post

> The size of other sections like the bss section also need to be accounted
> for when doing a size check.

that really cannot be checked at compile time.  it certainly cannot be done 
easily or with a few lines of shell code.

> Insufficient space for bss when doing something like a MMC read which
> requires large buffers causes system hangs for no apparent reason.

that doesnt make much sense.  bss is statically allocated.  either it exists, 
or it doesnt.  if bss doesnt work, your system/build is fundamentally screwed.  
either way, none of this is related to my patch.
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20101020/19afb5c9/attachment.pgp 

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [U-Boot] [RFC/PATCH] Makefile: allow boards to check file size limits
  2010-10-20  5:16     ` Mike Frysinger
@ 2010-10-20  6:56       ` Vaibhav Bedia
  2010-10-20  7:19         ` Wolfgang Denk
  0 siblings, 1 reply; 10+ messages in thread
From: Vaibhav Bedia @ 2010-10-20  6:56 UTC (permalink / raw)
  To: u-boot

On Wed, Oct 20, 2010 at 10:46 AM, Mike Frysinger <vapier@gentoo.org> wrote:

> On Wednesday, October 20, 2010 00:38:08 Vaibhav Bedia wrote:
>
> please do not top post
>
> Sorry about the top posting.


> > The size of other sections like the bss section also need to be accounted
> > for when doing a size check.
>
> that really cannot be checked at compile time.  it certainly cannot be done
> easily or with a few lines of shell code.
>
> > Insufficient space for bss when doing something like a MMC read which
> > requires large buffers causes system hangs for no apparent reason.
>
> that doesnt make much sense.  bss is statically allocated.  either it
> exists,
> or it doesnt.  if bss doesnt work, your system/build is fundamentally
> screwed.
>

Just displaying the binary size can be misleading IMHO. If the info printed
contains the complete memory requirement (stack+heap+bss) then it can
potentially save a lot of time during debugging

either way, none of this is related to my patch.
> -mike
>


-- 
Regards,
Vaibhav

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [U-Boot] [RFC/PATCH] Makefile: allow boards to check file size limits
  2010-10-20  6:56       ` Vaibhav Bedia
@ 2010-10-20  7:19         ` Wolfgang Denk
  0 siblings, 0 replies; 10+ messages in thread
From: Wolfgang Denk @ 2010-10-20  7:19 UTC (permalink / raw)
  To: u-boot

Dear Vaibhav Bedia,

In message <AANLkTinvwZsVZosDgLtGV2LiJhU0QWQoQdfD765z=1SH@mail.gmail.com> you wrote:
>
> Just displaying the binary size can be misleading IMHO. If the info printed
> contains the complete memory requirement (stack+heap+bss) then it can
> potentially save a lot of time during debugging

Just run "MAKEALL" for your board and you get exactly what you are
asking for,

> either way, none of this is related to my patch.
> > -mike
> >

You really need to get your quoting right.

Please read http://www.netmeister.org/news/learn2quote.html

> --0016e649837c8d6440049306e906
> Content-Type: text/html; charset=ISO-8859-1
> Content-Transfer-Encoding: quoted-printable

And STOP posting HTML!

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
"I used to think that the brain was the most wonderful  organ  in  my
body. Then I realized who was telling me this."        - Emo Phillips

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2010-10-20  7:19 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-14  2:58 [U-Boot] [RFC/PATCH] Makefile: allow boards to check file size limits Mike Frysinger
2010-10-18 20:43 ` Wolfgang Denk
2010-10-19  4:17   ` Mike Frysinger
2010-10-19  5:24     ` Wolfgang Denk
2010-10-19  5:38       ` Mike Frysinger
2010-10-19 21:29 ` Wolfgang Denk
2010-10-20  4:38   ` Vaibhav Bedia
2010-10-20  5:16     ` Mike Frysinger
2010-10-20  6:56       ` Vaibhav Bedia
2010-10-20  7:19         ` Wolfgang Denk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox