全部博文(584)
分类: LINUX
2010-11-03 16:44:19
In section 1.2., we introduced how to download firmware to NAND flash using "NOR boot" when u-boot in NAND is gone. In this section, we will detail how to download or upgrade firmware in NAND using u-boot via Ethernet tftp download. Since our platform is positioned at "application ready", that means users usually only need to focus on their own market-oriented application. If developers don't build your own u-boot and kernel, you could skip this section unless you need to update new firmware. Developers could also choose serial console port to download firmware. Since it takes time, we will only focus on tftp download only. If users are interested in serial download, please refer the DENX u-boot manual.
If you have u-boot or Linux running on your system, then you can use Linux or u-boot to install a u-boot image to the appropriate address in flash memory. This section shows you how to download u-boot when Linux is running.
[root@M190]# cat /proc/mtd
dev: size erasesize name
mtd0: 00020000 00004000 "BIOS_BIN"
mtd1: 00010000 00004000 "BIOS_DAT"
mtd2: 001c0000 00004000 "KERNEL"
mtd3: 00200000 00004000 "SYSCFG"
mtd4: 01c00000 00004000 "INITRD"
[root@M190]# dd if=/tmp/uboot.bin of=/dev/mtdblock/0 bs=128k conv=sync
1+1 records in
2+0 records out
You could use the same way to download Linux image to appropriate flash memory.
You could also use u-boot tftp command to download u-boot, Linux kernel and rescue root file system. Below we will detail how to do this under Windows and Linux PC environment.
First, open up "DNW" program and set up the serial port. (Please refer to section 1.2.1.1. for serial port setting of DNW program.) Connect the Ethernet cable. If you connect directly from device to PC, use the cross Ethernet cable.
Users need to install tftp server on Windows. You can download the freeware and install to your Windows PC in the tftpboot directory. Copy the uboot.bin, zImage and nand.img into this directory. Close your anti-virus software like PC-cillin. (Or close port 69)
You can set and add the environment parameter of device using "setenv", "saveenv" command as below.
[root@M190]#setenv ipaddr XXX.XXX.XXX.XXX [root@M190]#setenv serverip XXX.XXX.XXX.XXX [root@M190]#saveenv |
Example:
ipaddr 192.168.1.2
serverip 192.168.1.121
Note:
Make sure that the ipaddr for device and serverip for Windows PC are in the same network domain.
After setting up the IP address and wire everything right, you could start the tftp download.
After setting up the tftp server and IP address of devices, users can start transfer and write images using u-boot tftp and nandw command. It is necessary to download to SDRAM first before writing to NAND. The following command shows how to transfer u-boot.bin images to SDRAM.
[root@M190]#tftp 30000000 u-boot.bin |
[root@M190]#nandw 0x0 0x1c000 30000000 |
Next example shows how to transfer and write Linux kernel. The file name is "zImage". Again, we tftp to SDRAM first by the following command.
[root@M190]#tftp 30000000 zImage |
Temporary address is base address of SDRAM, i.e. 0x30000000. And you will see the following screen:
Figure 10. U-Boot TFTP Transfer to SDRAM
Write the zImage image to the NAND by using nandw command.
[root@M190]#nandw 0xc 0x190000 30000000 |
Figure 11. Using U-Boot Write NAND Flash
Temporary address is base address of SDRAM, i.e. 0x30000000. Start block number of kernel is 0xc, 1.8M (12~79 blocks) of NAND flash is environment space. In this case, we have written the kernel image size as 10c000, it varies depending on the menuconfig options and module selection.
After writing u-boot and kernel images to NAND flash, the last step is to write rescue root file system nand.img image. Repeat the same steps, first, we tftp the "nand.img" image to SDRAM.
[root@M190]#tftp 30000000 nand.img |
Temporary address is base address of SDRAM, i.e. 0x30000000. Write the nand.img image to the NAND by using following nandw command.
[root@M190]#nandw 0x100 0xce4000 30000000 |
Temporary address is base address of SDRAM, i.e. 0x30000000. Start block number of nand.img is 0x100, 13M (256~1084 blocks) of NAND flash is environment space. In this case, we have written the nand.img image size as cf0000.
After done, reset device and the kernel will be booting as following figure 12.
Figure 12. Booting Kernel
In this section, we will detail how to transfer and write firmware under Linux PC. First, we need to set up minicom so that we could see the message from the console.
Before transferring images using tftp, you should know how to use Minicom so that you could see the messages from console. In this section will explain how to setup Minicom.
Desktop Linux has Minicom program for serial communication. It is used for command prompt of u-boot.bin or shell prompt of embedded Linux.
Set up the values before using Minicom program. To execute minicom on setting mode:
[root@localhost root]#minicom -s |
Figure 13. Minicom Setup
Please select 'Serial port setup'. Push 'A' key for setting 'Serial Device', then write serial port which is connected to device via console cable. (If you are using COM1, write /dev/ttyS0, if COM2, write /dev/ttyS1.)
Figure 14. Serial Port Setup I
Push 'E' key for setting up 'Bps/Par/Bits'. Push 'I' to set up 'bps' to 115200. Push 'V' to set up 'Data bits' to 8. Push 'W' to set up 'Stop bits' to '1', and 'V' to set up 'parity to 'NONE'.
Figure 15. Serial Port Setup II
Push 'F' key for setting up 'Hardware Flow Control to 'NO'. Push 'G' key for setting up 'Software Flow Control' to 'NO. The default value is 'NO'.
Figure 16. Hardware/Software Flow Control Setup
Once setting is over, please press 'Enter' key. And select 'Save setup as dfl item, then press 'Enter' for saving the values.
Figure 17. Saving Minicom Setup
Push 'Exit key, to exit from the setting mode. Currently, the set points are stored to the file '/etc/minirc.dfl'
Figure 18. Exiting Minicom Setup
To quit from Minicom, please press 'Ctrl + A' and then 'Z', at last push 'Q key. Then selecting 'Yes', Minicom is quitted.
Figure 18. Resetting from Minicom
This section will explain how to setup TFTP server under Linux. To use tftp server program you have to setup your computer by executing the following command.
[root@localhost root]#setup |
You can see the "Text Mode Setup Utility" as shown below.
Figure 19. Text Mode Setup Utilities
Please select "System services". As shown below.
Figure 20. System Service List
Please select "tftp" service as shown in above figure and finally click on "ok".
Finally "quit" setup utility and execute the following command.
[root@localhost root]#xinetd -restart |
Now you can download compiled images to the device by using tftp. Before downloading the images, connect host PC and device by Ethernet cable. (If you direct link PC and device, please use Ethernet cross cable.)
To download binary image files to device, run tftp server service on your computer and put images in /tftpboot directory.
Copy kernel zImage image to /tftpboot directory. In Linux PC, type
[root@localhost root]#cp zImage /tftpboot/ |
Setting up an IP address helps in downloading the compiled images to device.
Connect host PC and device by Ethernet cable.
Note: If you are connecting PC LAN port to the device directly, you need to use an Ethernet cross cable.
Setting Up IP Address for Host PC
In your Linux host PC, run the terminal and execute following commands to set up an IP address.
[root@localhost tftpboot]# ifconfig eth0 down [root@localhost tftpboot]# ifconfig eth0 192.168.1.10 netmask 255.255.255.0 up [root@localhost tftpboot]# ifconfig |
Figure 21. Setting IP Address for Host PC
Setting Up IP Address for Device
Run the Minicom first in host PC and Power ON device. Please press any key at auto-count to get the '[root@m190]#' command prompt.
Execute the command "printenv" as shown below.
Figure 22. Environment Parameter for Device
You can set and add the environment parameter of device using "setenv", "saveenv" command as below.
[root@M190]#setenv ipaddr XXX.XXX.XXX.XXX [root@M190]#setenv serverip XXX.XXX.XXX.XXX [root@M190]#saveenv |
Example:
ipaddr 192.168.1.2
serverip 192.168.1.121
Note:
Make sure that the ipaddr is for device and serverip is for Linux PC are in the same network domain.
After setting up the IP address and wire everything right, you could start the tftp download.
Figure 23. Setting Up and Saving Parameters
After you configure the network for Host PC and device, the LED of the Ethernet jack will be on. It shows that the network connection has been successfully done.
After setting up the tftp server and IP address of devices, users can start transfer images to SDRAM by tftp and write to NAND by nandw command. It is necessary to download to SDRAM first before writing to NAND. The following command shows how to transfer u-boot.bin images to SDRAM.
[root@M190]#tftp 30000000 u-boot.bin |
[root@M190]#nandw 0 20000 30000000 |
Figure 24. Transfer and Write U-Boot to NAND
Next example shows how to transfer and write Linux kernel. The file name is "zImage". Again, we tftp to SDRAM first by the following command.
[root@M190]#tftp 30000000 zImage |
Temporary address is base address of SDRAM, i.e. 0x30000000.
Write the zImage image to the NAND by using nandw command.
[root@M190]#nandw 0xc 0x190000 30000000 |
Figure 25. Transfer and Write Kernel Image to NAND
Temporary address is base address of SDRAM, i.e. 0x30000000. Start block number of kernel is 0xc, 1.8M (12~79 blocks) of NAND flash is environment space. In this case, we have written the kernel image size as 10c000, it varies depending on the menuconfig options and module selection.
After writing u-boot and kernel images to NAND flash, the last step is to write rescue root file system nand.img image. Repeat the same steps, first, we tftp the nand.img image to SDRAM.
[root@M190]#tftp 30000000 nand.img |
Temporary address is base address of SDRAM, i.e. 0x30000000. Write the nand.img image to the NAND by using following nandw command.
[root@M190]#nandw 0x100 0xcf0000 30000000 |
Temporary address is base address of SDRAM, i.e. 0x30000000. Start block number of nand.img is 0x100, 13M (256~1084 blocks) of NAND flash is environment space. In this case, we have written the nand.img image size as cf0000.
After done, reset device and the kernel will be booting as following figure 26.
Figure 26. Booting Kernel