全部博文(132)
分类: C/C++
2009-05-19 11:54:14
Flash memory is a form of non-volatile memory that can be erased and reprogrammed. Normally flash is used to store the U-Boot image, U-Boot environment variables and the kernel image. In order to update the content of flash, the designer must know how to reprogram the flash.
U-Boot offers several commands for programming, erasing and protecting the flash memory. This section will provide guidelines on how to use these commands.
Prior to accessing the Flash device, the device information such as device size, erase block size and memory mapped addresses is often required. The 'flinfo' command in U-Boot allows the user to obtain such information.
U-Boot> flinfo
Bank # 1: CFI conformant FLASH (32 x 16) Size: 8 MB in 32 Sectors
Erase timeout 16384 ms, write timeout 3 ms, buffer write timeout 3 ms, buffer size 32
Sector Start Addresses:
28000000 (RO) 28040000 (RO) 28080000 280C0000 28100000
28140000 28180000 281C0000 28200000 28240000
28280000 282C0000 28300000 28340000 28380000
283C0000 28400000 28440000 28480000 284C0000
28500000 28540000 28580000 285C0000 28600000
28640000 28680000 286C0000 28700000 28740000
28780000 287C0000
U-Boot>
The output carries quite a lot of information, e.g flash sector layout, sector start addresses. For this particular flash chip it contents 32 256KB sectors start at address 0x28000000 for a total of 8MB.
The sectors following (RO) indicate that this sector is "protected". In this example sectors, sector 0 contains U-Boot image and sector 1 is used to store the U-Boot environment variables. Any attempt to program these sectors without first unlocking them will fail.
Use U-Boot 'protect' command to unlock the protected flash sectors. Two additional parameters are required for the 'protect' command. They include the on/off option (to switch on/off the protection) and the particular bank and sector to unprotect.
protect off:
To turn off flash protection of sector 0 in bank 1.
u-boot # protect off 1:0
Un-Protect Flash Sectors 0-0 in Bank # 1
Note: The parameter
Use U-Boot 'erase' command to erase flash sectors. Similar to the 'protect' command, the 'erase' command requires the bank number and sector number information.
erase:
To erase flash sector 0 of flash bank 1.
U-Boot> erase 1:0
Erase Flash Sectors 0-0 in Bank # 1
. done
The byte version of the 'cp' command (cp.b)is used to program the flash memory. The 'cp.b' command requires three parameters, the copy-from address, copy-to address and size. The cp command will automatically detect if it is accessing Flash memory, if so it will use the appropriate Flash programming routine to program the Flash device. However, the user is required to unprotect and/or erase the Flash area before programming it.
cp.b
Note that the '
The above step will attempt to program the kernel image into the Flash device, depending on the Flash device used this step may take a while to complete. Note that the U-Boot cp command do not provide status information for the copy process.
The following example downloads a new U-Boot image file (u-boot-s.bin) into U-Boot's memory. Refer to the of the User Guide for more information.
Filename 'u-boot-s.bin'.
Load address: 0x10000000
Loading: #######################
done
Bytes transferred = 116884 (1c894 hex)
Note the "Load address and Bytes transferred" of the downloaded file. In the above example, it is 0x10000000 and 0x1c894 respectively. These values will be required when reprogramming the Flash device.
The below example will copy the image in RAM into the Flash partition.
U-Boot> cp.b 0x10000000 0x28000000 0x1c894
Copy to Flash... done
Use U-Boot 'protect' command to re-enable protection of the particular Flash sectors.
protect on:
To restore flash protection of sector 0 in bank 1.
U-Boot> protect on 1:0
Protect Flash Sectors 0-0 in Bank # 1
Reboot the system to run the newly uploaded U-Boot code.