Patchwork [2/2] u-boot: added generating the env utils (fixes bug 1800)

login
register
mail settings
Submitter Frans Meulenbroeks
Date Dec. 27, 2011, 8:35 p.m.
Message ID <1325018118-30223-2-git-send-email-fransmeulenbroeks@gmail.com>
Download mbox | patch
Permalink /patch/17681/
State New
Headers show

Comments

Frans Meulenbroeks - Dec. 27, 2011, 8:35 p.m.
This adds building the u-boot tools for target.
(fw_printenv, fw_setenv).
They are put into a separate package
With these files it becomes possible to modify
the u-boot environment when linux is booted

The #ifdef's in fw_env.h were needed to avoid compilation issues
The constants have been changed to more meaningful defaults
(as 128k flash pages are much more common than 4k pages)
but can be overridden using a configuration file.

This resolves bug 1800

Signed-off-by: Frans Meulenbroeks <fransmeulenbroeks@gmail.com>

---
Note: development and testing was done under openembedded classic.
I've tested it there quite heavily (for mpc8313 if that matters).
I was requested to provide a patch for oe-core too (to resolve bug 1800)
so here it is, although at the moment I am unable to test the patch for oe-core.
I suggest that this is carefully reviewed and tested before being merged.

Frans.
---
 meta/recipes-bsp/u-boot/files/tools_fwenv.patch |   48 +++++++++++++++++++++++
 meta/recipes-bsp/u-boot/u-boot.inc              |   21 ++++++++-
 meta/recipes-bsp/u-boot/u-boot_2011.03.bb       |    3 +-
 meta/recipes-bsp/u-boot/u-boot_2011.06.bb       |    3 +-
 4 files changed, 70 insertions(+), 5 deletions(-)
 create mode 100644 meta/recipes-bsp/u-boot/files/tools_fwenv.patch
Frans Meulenbroeks - Dec. 27, 2011, 8:40 p.m.
Forgot to mention this but it could be decided to make a separate recipe
for the env utils (like there is for mkimage).

And if you are interested in the reason why HOSTCC is being used to compile
fw_printenv and friends:
read this thread:
http://old.nabble.com/-U-Boot---PATCH-1-4--tools%3A-enable-img2srec-for-%22all%22-target-td29440508.html#a29440510

Enjoy!
Frans
Saul Wold - Dec. 27, 2011, 10 p.m.
On 12/27/2011 12:35 PM, Frans Meulenbroeks wrote:
> This adds building the u-boot tools for target.
> (fw_printenv, fw_setenv).
> They are put into a separate package
> With these files it becomes possible to modify
> the u-boot environment when linux is booted
>
> The #ifdef's in fw_env.h were needed to avoid compilation issues
> The constants have been changed to more meaningful defaults
> (as 128k flash pages are much more common than 4k pages)
> but can be overridden using a configuration file.
>
> This resolves bug 1800
>
Thanks for the fix, in the future please mark this as [YOCTO #1800]

Reviewing and someone will test also.

Thanks	
	Sau!
> Signed-off-by: Frans Meulenbroeks<fransmeulenbroeks@gmail.com>
>
> ---
> Note: development and testing was done under openembedded classic.
> I've tested it there quite heavily (for mpc8313 if that matters).
> I was requested to provide a patch for oe-core too (to resolve bug 1800)
> so here it is, although at the moment I am unable to test the patch for oe-core.
> I suggest that this is carefully reviewed and tested before being merged.
>
> Frans.
> ---
>   meta/recipes-bsp/u-boot/files/tools_fwenv.patch |   48 +++++++++++++++++++++++
>   meta/recipes-bsp/u-boot/u-boot.inc              |   21 ++++++++-
>   meta/recipes-bsp/u-boot/u-boot_2011.03.bb       |    3 +-
>   meta/recipes-bsp/u-boot/u-boot_2011.06.bb       |    3 +-
>   4 files changed, 70 insertions(+), 5 deletions(-)
>   create mode 100644 meta/recipes-bsp/u-boot/files/tools_fwenv.patch
>
> diff --git a/meta/recipes-bsp/u-boot/files/tools_fwenv.patch b/meta/recipes-bsp/u-boot/files/tools_fwenv.patch
> new file mode 100644
> index 0000000..8e87800
> --- /dev/null
> +++ b/meta/recipes-bsp/u-boot/files/tools_fwenv.patch
> @@ -0,0 +1,48 @@
> +Index: u-boot-2011.03/tools/env/fw_env.h
> +===================================================================
> +--- u-boot-2011.03.orig/tools/env/fw_env.h	2011-03-31 23:45:36.000000000 +0200
> ++++ u-boot-2011.03/tools/env/fw_env.h	2011-12-02 13:55:24.667278362 +0100
> +@@ -27,25 +27,35 @@
> +  * See included "fw_env.config" sample file (TRAB board)
> +  * for notes on configuration.
> +  */
> +-#define CONFIG_FILE     "/etc/fw_env.config"
> ++//#define CONFIG_FILE     "/etc/fw_env.config"
> ++
> ++#include "config.h"
> +
> + #define HAVE_REDUND /* For systems with 2 env sectors */
> +-#define DEVICE1_NAME      "/dev/mtd1"
> +-#define DEVICE2_NAME      "/dev/mtd2"
> ++#define DEVICE1_NAME      "/dev/mtd0"
> ++#define DEVICE2_NAME      "/dev/mtd0"
> + #define DEVICE1_OFFSET    0x0000
> +-#define ENV1_SIZE         0x4000
> +-#define DEVICE1_ESIZE     0x4000
> +-#define DEVICE2_OFFSET    0x0000
> +-#define ENV2_SIZE         0x4000
> +-#define DEVICE2_ESIZE     0x4000
> ++#define ENV1_SIZE         0x2000
> ++#define DEVICE1_ESIZE     0x20000
> ++#define DEVICE1_ENVSECTORS     1
> ++#define DEVICE2_OFFSET    0x20000
> ++#define ENV2_SIZE         0x2000
> ++#define DEVICE2_ESIZE     0x20000
> ++#define DEVICE2_ENVSECTORS     1
> +
> ++#ifndef CONFIG_BAUDRATE
> + #define CONFIG_BAUDRATE		115200
> ++#endif
> ++#ifndef CONFIG_BOOTDELAY
> + #define CONFIG_BOOTDELAY	5	/* autoboot after 5 seconds	*/
> ++#endif
> ++#ifndef CONFIG_BOOTCOMMAND
> + #define CONFIG_BOOTCOMMAND							\
> + 	"bootp; "								\
> + 	"setenv bootargs root=/dev/nfs nfsroot=${serverip}:${rootpath} "	\
> + 	"ip=${ipaddr}:${serverip}:${gatewayip}:${netmask}:${hostname}::off; "	\
> + 	"bootm"
> ++#endif
> +
> + extern int   fw_printenv(int argc, char *argv[]);
> + extern char *fw_getenv  (char *name);
> diff --git a/meta/recipes-bsp/u-boot/u-boot.inc b/meta/recipes-bsp/u-boot/u-boot.inc
> index a3f50bc..bbfc6d6 100644
> --- a/meta/recipes-bsp/u-boot/u-boot.inc
> +++ b/meta/recipes-bsp/u-boot/u-boot.inc
> @@ -32,16 +32,31 @@ do_compile () {
>   	unset CPPFLAGS
>   	oe_runmake ${UBOOT_MACHINE}
>   	oe_runmake ${UBOOT_MAKE_TARGET}
> +	oe_runmake tools env HOSTCC="${CC}"
>   }
>
>   do_install () {
> -    install -d ${D}/boot
> -    install ${S}/${UBOOT_BINARY} ${D}/boot/${UBOOT_IMAGE}
> -    ln -sf ${UBOOT_IMAGE} ${D}/boot/${UBOOT_BINARY}
> +	install -d ${D}/boot
> +	install ${S}/${UBOOT_BINARY} ${D}/boot/${UBOOT_IMAGE}
> +	ln -sf ${UBOOT_IMAGE} ${D}/boot/${UBOOT_BINARY}
> +
> +	if [ -e ${WORKDIR}/fw_env.config ] ; then
> +		install -d ${D}${base_sbindir}
> +		install -d ${D}${sysconfdir}
> +		install -m 644 ${WORKDIR}/fw_env.config ${D}${sysconfdir}/fw_env.config
> +		install -m 755 ${S}/tools/env/fw_printenv ${D}${base_sbindir}/fw_printenv
> +		install -m 755 ${S}/tools/env/fw_printenv ${D}${base_sbindir}/fw_setenv
> +	fi
> +
>   }
>
>   FILES_${PN} = "/boot"
>
> +PACKAGES += "${PN}-fw-utils"
> +FILES_${PN}-fw-utils = "${sysconfdir} ${base_sbindir}"
> +# u-boot doesn't use LDFLAGS for fw files, needs to get fixed, but until then:
> +INSANE_SKIP_${PN}-fw-utils = True
> +
>   do_deploy () {
>   	install ${S}/u-boot.bin ${DEPLOYDIR}/${UBOOT_IMAGE}
>
> diff --git a/meta/recipes-bsp/u-boot/u-boot_2011.03.bb b/meta/recipes-bsp/u-boot/u-boot_2011.03.bb
> index 1ebdbea..fe10f58 100644
> --- a/meta/recipes-bsp/u-boot/u-boot_2011.03.bb
> +++ b/meta/recipes-bsp/u-boot/u-boot_2011.03.bb
> @@ -19,7 +19,8 @@ SRCREV = "19b54a701811220221fc4d5089a2bb18892018ca"
>   PV = "v2011.03+git${SRCPV}"
>   PR = "r5"
>
> -SRC_URI = "git://git.denx.de/u-boot.git;branch=master;protocol=git"
> +SRC_URI = "git://git.denx.de/u-boot.git;branch=master;protocol=git \
> +           file://tools_fwenv.patch"
>
>   S = "${WORKDIR}/git"
>
> diff --git a/meta/recipes-bsp/u-boot/u-boot_2011.06.bb b/meta/recipes-bsp/u-boot/u-boot_2011.06.bb
> index 8ebdbff..bfe5db7 100644
> --- a/meta/recipes-bsp/u-boot/u-boot_2011.06.bb
> +++ b/meta/recipes-bsp/u-boot/u-boot_2011.06.bb
> @@ -19,7 +19,8 @@ SRCREV = "b1af6f532e0d348b153d5c148369229d24af361a"
>   PV = "v2011.06+git${SRCPV}"
>   PR = "r0"
>
> -SRC_URI = "git://git.denx.de/u-boot.git;branch=master;protocol=git"
> +SRC_URI = "git://git.denx.de/u-boot.git;branch=master;protocol=git \
> +           file://tools_fwenv.patch"
>
>   S = "${WORKDIR}/git"
>
Koen Kooi - Dec. 27, 2011, 10:10 p.m.
Op 27 dec. 2011, om 23:00 heeft Saul Wold het volgende geschreven:

> On 12/27/2011 12:35 PM, Frans Meulenbroeks wrote:
>> This adds building the u-boot tools for target.
>> (fw_printenv, fw_setenv).
>> They are put into a separate package
>> With these files it becomes possible to modify
>> the u-boot environment when linux is booted
>> 
>> The #ifdef's in fw_env.h were needed to avoid compilation issues
>> The constants have been changed to more meaningful defaults
>> (as 128k flash pages are much more common than 4k pages)
>> but can be overridden using a configuration file.
>> 
>> This resolves bug 1800
>> 
> Thanks for the fix, in the future please mark this as [YOCTO #1800]
> 
> Reviewing and someone will test also.

This seems to be copying http://cgit.openembedded.org/openembedded/commit/?id=fde321de556abd8ce66e494ab21bc4a2d4e28699 without credit
Anders Darander - Dec. 28, 2011, 12:16 p.m.
On 27 dec 2011, at 21:35, "Frans Meulenbroeks" <fransmeulenbroeks@gmail.com> wrote:

> This adds building the u-boot tools for target.
> (fw_printenv, fw_setenv).
> They are put into a separate package
> With these files it becomes possible to modify
> the u-boot environment when linux is booted
> 
> The #ifdef's in fw_env.h were needed to avoid compilation issues
> The constants have been changed to more meaningful defaults
> (as 128k flash pages are much more common than 4k pages)
> but can be overridden using a configuration file.
> 
> This resolves bug 1800
> 
> Signed-off-by: Frans Meulenbroeks <fransmeulenbroeks@gmail.com>
> 
> ---
> Note: development and testing was done under openembedded classic.
> I've tested it there quite heavily (for mpc8313 if that matters).
> I was requested to provide a patch for oe-core too (to resolve bug 1800)
> so here it is, although at the moment I am unable to test the patch for oe-core.
> I suggest that this is carefully reviewed and tested before being merged.


> create mode 100644 meta/recipes-bsp/u-boot/files/tools_fwenv.patch
> 
> diff --git a/meta/recipes-bsp/u-boot/files/tools_fwenv.patch b/meta/recipes-bsp/u-boot/files/tools_fwenv.patch
> new file mode 100644
> index 0000000..8e87800
> --- /dev/null
> +++ b/meta/recipes-bsp/u-boot/files/tools_fwenv.patch
> @@ -0,0 +1,48 @@
> +Index: u-boot-2011.03/tools/env/fw_env.h
> +===================================================================
> +--- u-boot-2011.03.orig/tools/env/fw_env.h    2011-03-31 23:45:36.000000000 +0200++++ u-boot-2011.03/tools/env/fw_env.h    2011-12-02 13:55:24.667278362 +0100
> +@@ -27,25 +27,35 @@
> +  * See included "fw_env.config" sample file (TRAB board)
> +  * for notes on configuration.
> +  */
> +-#define CONFIG_FILE     "/etc/fw_env.config"
> ++//#define CONFIG_FILE     "/etc/fw_env.config"

Why do you remove the default for CONFIG_FILE?
I haven't the u-boot code here, but isn't there a check for the configuration file in the code? Thus, you would still get compiled in defaults if no config file is found?

> ++
> ++#include "config.h"
> + 
> + #define HAVE_REDUND /* For systems with 2 env sectors */
> +-#define DEVICE1_NAME      "/dev/mtd1"
> +-#define DEVICE2_NAME      "/dev/mtd2"
> ++#define DEVICE1_NAME      "/dev/mtd0"
> ++#define DEVICE2_NAME      "/dev/mtd0"

Would this really be a more comman case than he original defines? (Personally, I'm usually using the config file, so this doesn't really matter. But I'd still question changing these to mtd0...)

> + #define DEVICE1_OFFSET    0x0000
> +-#define ENV1_SIZE         0x4000
> +-#define DEVICE1_ESIZE     0x4000
> +-#define DEVICE2_OFFSET    0x0000
> +-#define ENV2_SIZE         0x4000
> +-#define DEVICE2_ESIZE     0x4000
> ++#define ENV1_SIZE         0x2000
> ++#define DEVICE1_ESIZE     0x20000
> ++#define DEVICE1_ENVSECTORS     1
> ++#define DEVICE2_OFFSET    0x20000
> ++#define ENV2_SIZE         0x2000
> ++#define DEVICE2_ESIZE     0x20000
> ++#define DEVICE2_ENVSECTORS     1

Ok, I can agree with you that 128k pages are more common, thus that could be a sensible default.

I can also see a few reasons for changing the size of the environments, ENV1_SIZE and ENV2_SIZE, but there is no reason given in the commit log.

Cheers,
Anders
Frans Meulenbroeks - Dec. 28, 2011, 1:36 p.m.
2011/12/28 Anders Darander <anders@chargestorm.se>

>
> On 27 dec 2011, at 21:35, "Frans Meulenbroeks" <
> fransmeulenbroeks@gmail.com> wrote:
>
> > This adds building the u-boot tools for target.
> > (fw_printenv, fw_setenv).
> > They are put into a separate package
> > With these files it becomes possible to modify
> > the u-boot environment when linux is booted
> >
> > The #ifdef's in fw_env.h were needed to avoid compilation issues
> > The constants have been changed to more meaningful defaults
> > (as 128k flash pages are much more common than 4k pages)
> > but can be overridden using a configuration file.
> >
> > This resolves bug 1800
> >
> > Signed-off-by: Frans Meulenbroeks <fransmeulenbroeks@gmail.com>
> >
> > ---
> > Note: development and testing was done under openembedded classic.
> > I've tested it there quite heavily (for mpc8313 if that matters).
> > I was requested to provide a patch for oe-core too (to resolve bug 1800)
> > so here it is, although at the moment I am unable to test the patch for
> oe-core.
> > I suggest that this is carefully reviewed and tested before being merged.
>
>
> > create mode 100644 meta/recipes-bsp/u-boot/files/tools_fwenv.patch
> >
> > diff --git a/meta/recipes-bsp/u-boot/files/tools_fwenv.patch
> b/meta/recipes-bsp/u-boot/files/tools_fwenv.patch
> > new file mode 100644
> > index 0000000..8e87800
> > --- /dev/null
> > +++ b/meta/recipes-bsp/u-boot/files/tools_fwenv.patch
> > @@ -0,0 +1,48 @@
> > +Index: u-boot-2011.03/tools/env/fw_env.h
> > +===================================================================
> > +--- u-boot-2011.03.orig/tools/env/fw_env.h    2011-03-31
> 23:45:36.000000000 +0200++++ u-boot-2011.03/tools/env/fw_env.h
>  2011-12-02 13:55:24.667278362 +0100
> > +@@ -27,25 +27,35 @@
> > +  * See included "fw_env.config" sample file (TRAB board)
> > +  * for notes on configuration.
> > +  */
> > +-#define CONFIG_FILE     "/etc/fw_env.config"
> > ++//#define CONFIG_FILE     "/etc/fw_env.config"
>
> Why do you remove the default for CONFIG_FILE?
> I haven't the u-boot code here, but isn't there a check for the
> configuration file in the code? Thus, you would still get compiled in
> defaults if no config file is found?
>

Good catch.
This was based on work I did for a project a while ago.
Didn't have time to submit a patch then and decided the Xmas holiday was a
good point in time to upstream this, but apparently I overlooked this local
change.

I peeked into the code (tools/env/fw_env.c). If config file is used it does
uses the values in it, otherwise it fails. It does not use the built-in
values in that case (which imho would be preferable)
Anyway, for this specific project it was decided to use hardcoded values,
and that crept in.
I'll see if I can come up with a patch to use the default values if the
config file cannot be opened.


>
> > ++
> > ++#include "config.h"
> > +
> > + #define HAVE_REDUND /* For systems with 2 env sectors */
> > +-#define DEVICE1_NAME      "/dev/mtd1"
> > +-#define DEVICE2_NAME      "/dev/mtd2"
> > ++#define DEVICE1_NAME      "/dev/mtd0"
> > ++#define DEVICE2_NAME      "/dev/mtd0"
>
> Would this really be a more comman case than he original defines?
> (Personally, I'm usually using the config file, so this doesn't really
> matter. But I'd still question changing these to mtd0...)
>
I can live with either value. This was what was used in our project.
Personally I'm somewhat inclined to keep the # of partitions small, so I am
less inclined to make two partitions for the env.

>
> > + #define DEVICE1_OFFSET    0x0000
> > +-#define ENV1_SIZE         0x4000
> > +-#define DEVICE1_ESIZE     0x4000
> > +-#define DEVICE2_OFFSET    0x0000
> > +-#define ENV2_SIZE         0x4000
> > +-#define DEVICE2_ESIZE     0x4000
> > ++#define ENV1_SIZE         0x2000
> > ++#define DEVICE1_ESIZE     0x20000
> > ++#define DEVICE1_ENVSECTORS     1
> > ++#define DEVICE2_OFFSET    0x20000
> > ++#define ENV2_SIZE         0x2000
> > ++#define DEVICE2_ESIZE     0x20000
> > ++#define DEVICE2_ENVSECTORS     1
>
> Ok, I can agree with you that 128k pages are more common, thus that could
> be a sensible default.
>
> I can also see a few reasons for changing the size of the environments,
> ENV1_SIZE and ENV2_SIZE, but there is no reason given in the commit log.
>
> Again probably a personal preference that crept in.
I did a quick grep: in u-boot/include/configs 146 boards have a size of
0x2000, and 78 have a size of 0x4000, so it seems 0x2000 is more used.
THen again perhaps the code should be modified to make use of whatever
config/include says.

I'll see if I can come up with an update.
But actually the most important part of this patch is to add the code in
.inc and .bb to compile the tools.

Best regards, Frans

PS: it could also be decided to make a separate u-boot-env recipe.
PPS: if interested in why fw_prntenv is compiled with HOSTCC: see this
thread:
http://old.nabble.com/-U-Boot---PATCH-1-4--tools%3A-enable-img2srec-for-%22all%22-target-td29440508.html#a29440510
discussion starts somewhere halfway the thread.
Anders Darander - Dec. 28, 2011, 6:17 p.m.
On 28 dec 2011, at 14:36, "Frans Meulenbroeks" <fransmeulenbroeks@gmail.com<mailto:fransmeulenbroeks@gmail.com>> wrote:

2011/12/28 Anders Darander <anders@chargestorm.se<mailto:anders@chargestorm.se>>

On 27 dec 2011, at 21:35, "Frans Meulenbroeks" <fransmeulenbroeks@gmail.com<mailto:fransmeulenbroeks@gmail.com>> wrote:

> This adds building the u-boot tools for target.

> (fw_printenv, fw_setenv).

> They are put into a separate package

> With these files it becomes possible to modify

> the u-boot environment when linux is booted

>

> The #ifdef's in fw_env.h were needed to avoid compilation issues

> The constants have been changed to more meaningful defaults

> (as 128k flash pages are much more common than 4k pages)

> but can be overridden using a configuration file.

>

> This resolves bug 1800

>

> Signed-off-by: Frans Meulenbroeks <fransmeulenbroeks@gmail.com<mailto:fransmeulenbroeks@gmail.com>>

>

> ---

> Note: development and testing was done under openembedded classic.

> I've tested it there quite heavily (for mpc8313 if that matters).

> I was requested to provide a patch for oe-core too (to resolve bug 1800)

> so here it is, although at the moment I am unable to test the patch for oe-core.

> I suggest that this is carefully reviewed and tested before being merged.



> create mode 100644 meta/recipes-bsp/u-boot/files/tools_fwenv.patch

>

> diff --git a/meta/recipes-bsp/u-boot/files/tools_fwenv.patch b/meta/recipes-bsp/u-boot/files/tools_fwenv.patch

> new file mode 100644

> index 0000000..8e87800

> --- /dev/null

> +++ b/meta/recipes-bsp/u-boot/files/tools_fwenv.patch.


> ++

> ++#include "config.h"

> +

> + #define HAVE_REDUND /* For systems with 2 env sectors */

> +-#define DEVICE1_NAME      "/dev/mtd1"

> +-#define DEVICE2_NAME      "/dev/mtd2"

> ++#define DEVICE1_NAME      "/dev/mtd0"

> ++#define DEVICE2_NAME      "/dev/mtd0"


Would this really be a more comman case than he original defines? (Personally, I'm usually using the config file, so this doesn't really matter. But I'd still question changing these to mtd0...)
I can live with either value. This was what was used in our project.
Personally I'm somewhat inclined to keep the # of partitions small, so I am less inclined to make two partitions for the env.

I'm personally fine with either, as I'm often using config-files, or otherwise there's likely more customization anyway.

Though, I'd probably argue that if we are to change the defaults in this case compared to upstream, it should be due to a either that most/a lage number of boards are using that scheme, or that the new seem is at least used by reference boards for OE-Core and yocto (although, I don't know which reference boards uses nandflash, and how they are configured).


> + #define DEVICE1_OFFSET    0x0000

> +-#define ENV1_SIZE         0x4000

> +-#define DEVICE1_ESIZE     0x4000

> +-#define DEVICE2_OFFSET    0x0000

> +-#define ENV2_SIZE         0x4000

> +-#define DEVICE2_ESIZE     0x4000

> ++#define ENV1_SIZE         0x2000

> ++#define DEVICE1_ESIZE     0x20000

> ++#define DEVICE1_ENVSECTORS     1

> ++#define DEVICE2_OFFSET    0x20000

> ++#define ENV2_SIZE         0x2000

> ++#define DEVICE2_ESIZE     0x20000

> ++#define DEVICE2_ENVSECTORS     1


Ok, I can agree with you that 128k pages are more common, thus that could be a sensible default.

I can also see a few reasons for changing the size of the environments, ENV1_SIZE and ENV2_SIZE, but there is no reason given in the commit log.

Again probably a personal preference that crept in.
I did a quick grep: in u-boot/include/configs 146 boards have a size of 0x2000, and 78 have a size of 0x4000, so it seems 0x2000 is more used.
THen again perhaps the code should be modified to make use of whatever config/include says.

If the numbers quoted above are the same/similar if you only look at boards with 128k pages, then we should keep your patch.

I'll see if I can come up with an update.
But actually the most important part of this patch is to add the code in .inc and .bb to compile the tools.

Yes, I agree that that's the most important part of the patch. And a welcomed patch. (I've a local patch doing something similar, that I've never got around to submit).

Cheers,
Anders

Best regards, Frans

PS: it could also be decided to make a separate u-boot-env recipe.
PPS: if interested in why fw_prntenv is compiled with HOSTCC: see this thread: http://old.nabble.com/-U-Boot---PATCH-1-4--tools%3A-enable-img2srec-for-%22all%22-target-td29440508.html#a29440510
discussion starts somewhere halfway the thread.
Frans Meulenbroeks - Jan. 2, 2012, 12:46 p.m.
Triggered by the remarks of Anders I've been digging into this a little bit
more.
I suggest to ignore tools_fwenv.patch, and only add the changes to the .inc
file.

For fw_env.h a better solution exists, namely using the value from the
config file.
I'll try to submit a patch to upstream to fix that.

Best regards (and a prosperous 2012!)
Frans

Patch

diff --git a/meta/recipes-bsp/u-boot/files/tools_fwenv.patch b/meta/recipes-bsp/u-boot/files/tools_fwenv.patch
new file mode 100644
index 0000000..8e87800
--- /dev/null
+++ b/meta/recipes-bsp/u-boot/files/tools_fwenv.patch
@@ -0,0 +1,48 @@ 
+Index: u-boot-2011.03/tools/env/fw_env.h
+===================================================================
+--- u-boot-2011.03.orig/tools/env/fw_env.h	2011-03-31 23:45:36.000000000 +0200
++++ u-boot-2011.03/tools/env/fw_env.h	2011-12-02 13:55:24.667278362 +0100
+@@ -27,25 +27,35 @@
+  * See included "fw_env.config" sample file (TRAB board)
+  * for notes on configuration.
+  */
+-#define CONFIG_FILE     "/etc/fw_env.config"
++//#define CONFIG_FILE     "/etc/fw_env.config"
++
++#include "config.h"
+ 
+ #define HAVE_REDUND /* For systems with 2 env sectors */
+-#define DEVICE1_NAME      "/dev/mtd1"
+-#define DEVICE2_NAME      "/dev/mtd2"
++#define DEVICE1_NAME      "/dev/mtd0"
++#define DEVICE2_NAME      "/dev/mtd0"
+ #define DEVICE1_OFFSET    0x0000
+-#define ENV1_SIZE         0x4000
+-#define DEVICE1_ESIZE     0x4000
+-#define DEVICE2_OFFSET    0x0000
+-#define ENV2_SIZE         0x4000
+-#define DEVICE2_ESIZE     0x4000
++#define ENV1_SIZE         0x2000
++#define DEVICE1_ESIZE     0x20000
++#define DEVICE1_ENVSECTORS     1
++#define DEVICE2_OFFSET    0x20000
++#define ENV2_SIZE         0x2000
++#define DEVICE2_ESIZE     0x20000
++#define DEVICE2_ENVSECTORS     1
+ 
++#ifndef CONFIG_BAUDRATE
+ #define CONFIG_BAUDRATE		115200
++#endif
++#ifndef CONFIG_BOOTDELAY
+ #define CONFIG_BOOTDELAY	5	/* autoboot after 5 seconds	*/
++#endif
++#ifndef CONFIG_BOOTCOMMAND
+ #define CONFIG_BOOTCOMMAND							\
+ 	"bootp; "								\
+ 	"setenv bootargs root=/dev/nfs nfsroot=${serverip}:${rootpath} "	\
+ 	"ip=${ipaddr}:${serverip}:${gatewayip}:${netmask}:${hostname}::off; "	\
+ 	"bootm"
++#endif
+ 
+ extern int   fw_printenv(int argc, char *argv[]);
+ extern char *fw_getenv  (char *name);
diff --git a/meta/recipes-bsp/u-boot/u-boot.inc b/meta/recipes-bsp/u-boot/u-boot.inc
index a3f50bc..bbfc6d6 100644
--- a/meta/recipes-bsp/u-boot/u-boot.inc
+++ b/meta/recipes-bsp/u-boot/u-boot.inc
@@ -32,16 +32,31 @@  do_compile () {
 	unset CPPFLAGS
 	oe_runmake ${UBOOT_MACHINE}
 	oe_runmake ${UBOOT_MAKE_TARGET}
+	oe_runmake tools env HOSTCC="${CC}"
 }
 
 do_install () {
-    install -d ${D}/boot
-    install ${S}/${UBOOT_BINARY} ${D}/boot/${UBOOT_IMAGE}
-    ln -sf ${UBOOT_IMAGE} ${D}/boot/${UBOOT_BINARY}
+	install -d ${D}/boot
+	install ${S}/${UBOOT_BINARY} ${D}/boot/${UBOOT_IMAGE}
+	ln -sf ${UBOOT_IMAGE} ${D}/boot/${UBOOT_BINARY}
+
+	if [ -e ${WORKDIR}/fw_env.config ] ; then
+		install -d ${D}${base_sbindir}
+		install -d ${D}${sysconfdir}
+		install -m 644 ${WORKDIR}/fw_env.config ${D}${sysconfdir}/fw_env.config
+		install -m 755 ${S}/tools/env/fw_printenv ${D}${base_sbindir}/fw_printenv
+		install -m 755 ${S}/tools/env/fw_printenv ${D}${base_sbindir}/fw_setenv
+	fi
+
 }
 
 FILES_${PN} = "/boot"
 
+PACKAGES += "${PN}-fw-utils"
+FILES_${PN}-fw-utils = "${sysconfdir} ${base_sbindir}"
+# u-boot doesn't use LDFLAGS for fw files, needs to get fixed, but until then:
+INSANE_SKIP_${PN}-fw-utils = True
+
 do_deploy () {
 	install ${S}/u-boot.bin ${DEPLOYDIR}/${UBOOT_IMAGE}
 
diff --git a/meta/recipes-bsp/u-boot/u-boot_2011.03.bb b/meta/recipes-bsp/u-boot/u-boot_2011.03.bb
index 1ebdbea..fe10f58 100644
--- a/meta/recipes-bsp/u-boot/u-boot_2011.03.bb
+++ b/meta/recipes-bsp/u-boot/u-boot_2011.03.bb
@@ -19,7 +19,8 @@  SRCREV = "19b54a701811220221fc4d5089a2bb18892018ca"
 PV = "v2011.03+git${SRCPV}"
 PR = "r5"
 
-SRC_URI = "git://git.denx.de/u-boot.git;branch=master;protocol=git"
+SRC_URI = "git://git.denx.de/u-boot.git;branch=master;protocol=git \
+           file://tools_fwenv.patch"
 
 S = "${WORKDIR}/git"
 
diff --git a/meta/recipes-bsp/u-boot/u-boot_2011.06.bb b/meta/recipes-bsp/u-boot/u-boot_2011.06.bb
index 8ebdbff..bfe5db7 100644
--- a/meta/recipes-bsp/u-boot/u-boot_2011.06.bb
+++ b/meta/recipes-bsp/u-boot/u-boot_2011.06.bb
@@ -19,7 +19,8 @@  SRCREV = "b1af6f532e0d348b153d5c148369229d24af361a"
 PV = "v2011.06+git${SRCPV}"
 PR = "r0"
 
-SRC_URI = "git://git.denx.de/u-boot.git;branch=master;protocol=git"
+SRC_URI = "git://git.denx.de/u-boot.git;branch=master;protocol=git \
+           file://tools_fwenv.patch"
 
 S = "${WORKDIR}/git"