Chinaunix首页 | 论坛 | 博客
  • 博客访问: 913202
  • 博文数量: 132
  • 博客积分: 9976
  • 博客等级: 中将
  • 技术积分: 1781
  • 用 户 组: 普通用户
  • 注册时间: 2007-08-30 20:40
文章分类

全部博文(132)

文章存档

2013年(1)

2011年(1)

2010年(15)

2009年(77)

2008年(36)

2007年(2)

我的朋友

分类: C/C++

2009-05-19 11:54:14

Programming the Flash

=================================================================================
from: http://developer.petalogix.com/wiki/UserGuide/Bootloaders/UBoot/UsingUBoot/UBProgFlash

Programming the Flash

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 Flash Commands

U-Boot offers several commands for programming, erasing and protecting the flash memory. This section will provide guidelines on how to use these commands.

Flash information

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.

Unlock Protected Flash Sectors

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 can be a range of sectors, e.g sector 3 to 18 can be represent in 3-18

Erase Flash Sectors

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

Program the Flash

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 '' value is given in hexidecimal and is the number of units (.b for bytes etc.) to copy.

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

Restore Protection

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.



阅读(836) | 评论(0) | 转发(0) |
0

上一篇:获取crc32的程序

下一篇:我的u-boot 日志3

给主人留下些什么吧!~~