[U-Boot-Users] How to support multiple flash sizes ?

Laurent Pinchart laurent.pinchart at tbox.biz
Tue May 9 12:50:45 CEST 2006


> > I'm trying to find a way for U-Boot to automatically detect the flash
> > base address.
>
> That's trivial - it's a constant: CFG_FLASH_BASE
>
> > Our custom board can be mounted with different flash options, from 16MB
> > to 128MB. I would like to avoid programming the board with a different
> > boot loader for each flash size, so I was trying a way to create a
> > "one-fits-them-all" U-Boot version.
>
> Yes, that's the standard approach which is used on all sane ports  of
> U-Boot. U-Boot auto-detects the size of flash and maps it as needed.

The only place where U-Boot handles flash memory mapping is in cpu_init_f (in 
cpu/mpc8260/cpu_init.c). The flash is mapped using CFG_OR0_PRELIM and 
CFG_BR0_PRELIM which are compile-time constants. I can't find any flash 
remapping code.

> > I thought defining CFG_FLASH_BASE to 0xF8000000 would be enough, as the
> > flash would repeat over the 128MB memory range. This indeed works fine
> > for reading,
>
> What do mean with "repeat"? U-Boot will map only  the  correct  size,
> and nothing will "repeat".

Where does it remap the flash after detecting its size ?

> > but U-Boot is clever enough to detect the flash size, which leads to
> > problems when erasing sectors. The environment, for instance, is stored
> > at TEXT_BASE + 256kB (0xFFF40000). Saving the environment fails, as
> > U-Boot is unable to erase sector 0xFFF40000 which is outside the 16MB
> > flash memory range (0xF8000000 - 0xF8FFFFFF).
>
> Why do you define a TEXT_BASE+256kB location for your environment then?

That was copied from another board's configuration file. I'd like to put the 
environment in the sector right after the monitor like it's done for many 
other boards. The monitor must be located at 0xFFF00000 and is thus at a 
known constant offset from the *end* of the flash. As I don't know the flash 
size at compile time, I can't define the environment address as an offset 
from the beginning of the flash.

> > CFG_FLASH_BASE is used throughout the U-Boot code, so it would not be an
> > easy task to replacing it by a variable. Does someone know of a way to
> > either detect the flash base address, or read it from a fixed location in
> > flash (let's say in the first sector for instance, after the hard reset
> > configuration word) ? A possible approach would be to use the hardcoded
> > CFG_FLASH_BASE value at startup, and remap the flash at 0xFFFFFFFF -
> > flash_size later when the flash size is known. CFG_FLASH_BASE would have
> > to be replaced by a variable in several places.
>
> I don't understand  a  single  word.  Why  would  you  want  to  make
> CFG_FLASH_BASE  a variable? Just define a memory map for your system,
> and use it. Put CFG_FLASH_BASE low enough to allow for  all  possible
> configurations, and that's it.

Let's assume I'm using a 16MB flash chip, with options up to 128MB.

To accommodate space for the largest possible flash, I must define 
CFG_FLASH_BASE to 0xF8000000 with a 128MB size. TEXT_BASE *must* be defined 
to 0xFFF00000, as the processor's interrupt vectors are located at that 
address. The flash is mapped from 0xF8000000 to 0xFFFFFFFF, but physically 
covers 0xF8000000 to 0xF8FFFFFF. This means the flash is repeated 8 times 
over its mapping.

At bootup, the processor starts running at 0xFFF00100. This is inside the 8th 
flash copy in its mapping, and the monitor is stored in flash at the correct 
offset, so everything works correctly.

When U-Boot wants to write the environment, it will try to erase sector 
0xFFF40000. This leads to an error, as U-Boot knows the flash is only 16MB 
large, and 0xFFF40000 is thus outside the flash.

Is this clearer, or is there still something you don't understand ?

Regards,

Laurent Pinchart




More information about the U-Boot mailing list