
Dear Timur,
in message 454BBB85.5040507@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