
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 };
As you can see, I defined two static volatile global vars: i2c_bus_num and i2c_dev.
My U-Boot image is 0x294E0 bytes in size, and it's located at address 0xFE000000. When I run U-Boot, the address of i2c_bus_num is 0xfe02a114, and the address of i2c_dev[] is 0xfe028124.
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).
How is this possible? How can two adjacent global variables be located is completely different memory segments?