[U-Boot-Users] Why are some global vars part of the image, and some not?
Wolfgang Denk
wd at denx.de
Sat Nov 4 00:44:35 CET 2006
Dear Timur,
in message <454BBB85.5040507 at freescale.com> you wrote:
> I have the following code in one of my files:
>
> #ifdef CFG_SPD_BUS_NUM
> static volatile unsigned int i2c_bus_num = CFG_SPD_BUS_NUM;
> #else
> static volatile unsigned int i2c_bus_num = 0;
> #endif
>
> static volatile struct fsl_i2c *i2c_dev[2] = {
> (struct fsl_i2c *) (CFG_IMMR + CFG_I2C_OFFSET),
> #ifdef CFG_I2C2_OFFSET
> (struct fsl_i2c *) (CFG_IMMR + CFG_I2C2_OFFSET)
> #endif
> };
I'm not exactly sure what you mean by the "global vars" in the
Subject line. The declaration you show here says "static". This may
or may not be what you mean.
> As you can see, I defined two static volatile global vars: i2c_bus_num and
> i2c_dev.
Yes, and one of these is initialized with non-zero values (so it will
go to the data segment), while the other is not (so it will go to
bss).
> In other words, i2c_dev[] is part of the actual U-Boot image, but i2c_bus_num,
> which is defined right next to it, isn't. This means that i2c_dev[] is
> properly initialized, but i2c_bus_num is set to 0xFFFFFFFF (the value that
> erased flash has).
THis is perfectly OK. Just check the variables after U-Boot has been
relocated to RAM and BSS has been initialized.
> How is this possible? How can two adjacent global variables be located is
> completely different memory segments?
You need to understand the difference between data and bss segments,
or, between initialized and uninitialized (resp. initialized as zero)
data.
Best regards,
Wolfgang Denk
--
Software Engineering: Embedded and Realtime Systems, Embedded Linux
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
In the bathtub of history the truth is harder to hold than the soap,
and much more difficult to find ... - Terry Pratchett, _Sourcery_
More information about the U-Boot
mailing list