2010年3月1日 星期一

Update U-boot Image

Update U-boot Image on Mini2440

Startup Requirement

You need a BIOS to bootstrap the target system (the supervivi bootloader is use in this example from the Mini2440 package), set the switch to NOR BOOT and reset the board.

This update will get rid of the QTopia demo applications completely because NAND is scrub.

This also assume you have a compiled u-boot already in a directory called tftpboot and managed to configure the host computer as a tftp server.


Setup Terminal Connection

The most common way to communicate with an embedded system is to use a terminal emulation on the host to communicate through an RS232 serial port with the target system.

There are two main terminal software picocom and minicom can be used, picocom is rather superior to minicom these days, due to the fact that setting is specify easily at the command line, no weird menus and modem initialise needed, but minicom is easier to setup, once configure it's ready to run.

Configure the minicom below when the board is plugged on the main serial port.

minicom -s
  1. Move the cursor bar to 'Serial port setup' and press 'ENTER'
  2. Press 'A' to enter COM port device (eg. '/dev/ttyS0' or '/dev/ttyUSB0')
  3. Press 'E' to change the communication parameters, press 'E' and 'Q' to select '115200 bps' and '8N1' respectively
  4. Press 'F' to set Hardware Flow Control to 'No'
  5. Press 'ENTER' to accept the setting
  6. Save setup as dfl
Type minicom to test the connection, if successful the output message is display below.
Welcome to minicom 2.3

Option: I18n
Compiled at Jul 26 2009, 22:02:36.
Port /dev/ttyS0

Instead, use picocom to connect it directly.

picocom -b 115200 /dev/ttyS0 --send-cmd "sx -vv"
picocom v1.4

port is : /dev/ttyS0
flowcontrol : none
baudrate is : 115200
parity is : none
databits are : 8
escape is : C-a
noinit is : no
noreset is : no
nolock is : no
send_cmd is : sx -vv
receive_cmd is : rz -vv

Terminal ready

When the port is connected, reboot the device, the BIOS in the target system will start up the supervivi main menu program, quit from the menu will take us to the command line mode below.
##### FriendlyARM BIOS 2.0 for 2440 #####
[x] format NAND FLASH for Linux
[v] Download vivi
[k] Download linux kernel
[y] Download root_yaffs image
[a] Absolute User Application
[n] Download Nboot for WinCE
[l] Download WinCE boot-logo
[w] Download WinCE NK.bin
[d] Download & Run
[z] Download zImage into RAM
[g] Boot linux from RAM
[f] Format the nand flash
[b] Boot the system
[s] Set the boot parameters
[u] Backup NAND Flash to HOST through USB(upload)
[r] Restore NAND Flash from HOST through USB
[q] Goto shell of vivi
Enter your selection: q
Supervivi>

When in the prompt screen, proceed to download u-boot image into the ram.



Load U-boot into RAM

This will download the image into the memory via a COM port from picocom.

First check the size of the u-boot.bin file.

ls -l /var/lib/tftpboot/u-boot.bin
-rwxr-xr-x 1 root root 232316 2010-02-28 16:41 /var/lib/tftpboot/u-boot.bin
Set a longer timeout for the download connection.

Supervivi> param set xmodem_timeout 100000000

Load the image with the specify address and number of bytes to transfer, when downloading type 'Control A' and 'Control S' to prompt for a filename then enter the u-boot.bin file require.

Supervivi> load ram 0x32000000 232316 x
Ready for downloading using xmodem...
Waiting...

*** file: /var/lib/tftpboot/u-boot.bin
sx -vv /var/lib/tftpboot/u-boot.bin
Sending /var/lib/tftpboot/u-boot.bin, 1814 blocks: Give your local XMODEM receive command now.
Bytes Sent: 232320 BPS:9808

Transfer complete

*** exit status: 0


The same can be done with minicom, the USB is use to transfer the file image below.

Supervivi> load ram 0x32000000 232316 u

On the other screen, start the download with the s3c2410_boot_usb program.

Run U-boot from RAM

Once the u-boot image is downloaded, specify the address to run in the memory location.

go 0x32000000
go to 0x32000000
argument 0 = 0x00000000
argument 1 = 0x00000000
argument 2 = 0x00000000
argument 3 = 0x00000000

U-Boot 1.3.2-mini2440 (Feb 26 2010 - 17:34:45)

I2C: ready
DRAM: 64 MB
Flash: 2 MB
NAND: 128 MiB
Found Environment offset in OOB..
USB: S3C2410 USB Deviced
In: serial
Out: serial
Err: serial

when uboot run successfully, proceed to srub the nand section.


Flashing U-boot

The supervivi bootloader is use to download the image and requires that the board is connect to the host via a USB port, set the switch to NOR BOOT and reboot the device, the main menu will show up on the serial console, press 'q' to go to the prompt shell.

Load the image with the number of bytes to transfer (232316 bytes in this example), a pending message is display waiting for the download program to begin.

Supervivi> load flash 0 232316 u

On the other screen, start up the USB download program.

s3c2410_boot_usb u-boot.bin

When download program is running, an output message is display below - just ignore the last error.
csum = 0xb97e
send_file: addr = 0x33f80000, len = 0x00038b7c
Error downloading program

When download is finish, the serial console output message is display below.
USB host is connected. Waiting a download.
Now, Downloading [ADDRESS:30000000h,TOTAL:232326]
RECEIVED FILE SIZE: 232326 (32KB/S, 7S)
Downloaded file at 0x30000000, size = 232316 bytes
Found block size = 0x00040000
Erasing... ... done
Writing... ... done
Written 232316 bytes

Set the switch to NAND BOOT and reboot the device to run the new update version.


Check Factory Bad Blocks

The NAND usually comes with some bad blocks, we can check the NAND information and verify those 'already bad' blocks.

MINI2440 # nand info
Device 0: NAND 128MiB 3,3V 8-bit, page size 2048, sector size 128 KiB

MINI2440 # nand bad
Device 0 bad blocks:                       
06b40000
07f80000
07fa0000
07fc0000
07fe0000


Scrub the NAND

When there are bad blocks in NAND, u-boot will complaints about it so it is better to clean the NAND completely to detect any new bad blocks and create an up-to-date table.

Note, do not reset the board until the u-boot is reinstalled, or you need to use supervivi to reinstall u-boot via a USB port.

MINI2440 # nand scrub
NAND scrub: device 0 whole chip              
Warning: scrub option will erase all factory set bad blocks!
There is no reliable way to recover them.
Use this command only for testing purposes if you
are sure of what you are doing!

Really scrub this NAND flash? y
Erasing at 0x6a20000 -- 83% complete.
NAND 128MiB 3,3V 8-bit: MTD Erase failure: -5
Erasing at 0x7fe0000 -- 100% complete.
Bad block table not found for chip 0
Bad block table not found for chip 0
OK

MINI2440 # nand bad
Device 0 bad blocks:                         
06b40000
07f80000
07fa0000
07fc0000
07fe0000

Format is done, there are no additional bad blocks found.

Create a bad block table, it will write a record to the last blocks of the flash so that the kernel can find it.

MINI2440 # nand createbbt
Create BBT and erase everything ?  y
Skipping bad block at 0x06b40000
Skipping bad block at 0x07f80000
Skipping bad block at 0x07fa0000
Skipping bad block at 0x07fc0000
Skipping bad block at 0x07fe0000

Creating BBT. Please wait ...Bad block table not found for chip 0
Bad block table not found for chip 0
Bad block table written to 0x07fe0000, version 0x01
Bad block table written to 0x07fc0000, version 0x01


Default U-boot Partition

By default u-boot uses a default set of variables, lets check where is the location of a u-boot partition.

MINI2440 # mtdparts
device nand0 , # parts = 4     
#: name size offset mask_flags
0: u-boot 0x00040000 0x00000000 0
1: env 0x00020000 0x00040000 0
2: kernel 0x00500000 0x00060000 0
3: root 0x07aa0000 0x00560000 0

active partition: nand0,0 - (u-boot) 0x00040000 @ 0x00000000

defaults:
mtdids : nand0=mini2440-nand
mtdparts:

The above information indicates u-boot starts at 0x0 offset address with a size of 40000 and the environment at 0x00040000 with a size of 20000 written in the NAND.

U-boot comes the above 'dynamic' environment partition located in the NAND first block after the u-boot partition, it can be arranged by specifying the address of the location, u-boot will takes care of the "bad" environment block and relocate it somewhere further the chip.

Set the default location of an environment.

MINI2440 # dynenv set 40000
device 0 offset 0x40000, size 0x7fc0000       
45 4e 56 30 - 00 00 04 00

Save the environment variables to the specify location.

MINI2440 # saveenv
Saving Environment to NAND...                 
Erasing Nand...Writing to Nand... done


Configure Network Address

The board does not have a valid MAC address in the EEPROM, it relies on the bootloader to create one and the IP address is also set as default.

Optionally, set the MAC address if you got one.

MINI2440 # set ethaddr 08:00:2f:00:00:02


Define the device network address.

MINI2440 # set ipaddr 192.168.114.190
MINI2440 # set serverip 192.168.114.181
MINI2440 # set gateway 192.168.114.1



Set the boot command as an argument pass to the kernel system.

MINI2440 # setenv bootargs console=ttySAC0 noinitrd init=/sbin/init mini2440=0tb root=/dev/nfs nfsroot=$(serverip):/rootfs ip=$(ipaddr)::$(gateway):$(netmask):mini2440:eth0:off
MINI2440 # saveenv


Note, the above nfsroot variable will boot up the kernel image with a root filesystem over the NFS.


Print out the variables to check all settings are correct.

MINI2440 # printenv
bootargs=root=/dev/mtdblock3 rootfstype=jffs2 console=ttySAC0,115200
bootcmd=
bootdelay=3
baudrate=115200
netmask=255.255.255.0
usbtty=cdc_acm
mtdparts=mtdparts=mini2440-nand:256k@0(u-boot),128k(env),5m(kernel),-(root)
mini2440=mini2440=0tb
bootargs_base=console=ttySAC0,115200 noinitrd
bootargs_init=init=/sbin/init
root_nand=root=/dev/mtdblock3 rootfstype=jffs2
root_mmc=root=/dev/mmcblk0p2 rootdelay=2
root_nfs=/mnt/nfs
set_root_nfs=setenv root_nfs root=/dev/nfs rw nfsroot=${serverip}:${root_nfs}
ifconfig_static=run setenv ifconfig ip=${ipaddr}:${serverip}::${netmask}:mini240
ifconfig_dhcp=run setenv ifconfig ip=dhcp
ifconfig=ip=dhcp
set_bootargs_mmc=setenv bootargs ${bootargs_base} ${bootargs_init} ${mini2440} }
set_bootargs_nand=setenv bootargs ${bootargs_base} ${bootargs_init} ${mini2440}}
set_bootargs_nfs=run set_root_nfs; setenv bootargs ${bootargs_base} ${bootargs_}
mtdids=nand0=mini2440-nand
partition=nand0,0
mtddevnum=0
mtddevname=u-boot
ethaddr=08:00:2f:00:00:02
ipaddr=192.168.114.190
serverip=192.168.114.181
gateway=192.168.114.1

Environment size: 1115/131068 bytes

Note: if you flashing a new bootloader do not reboot, continue to complete the following step.


Update U-boot Partition

After flashing the first u-boot, it can be used to upgrade to a new version by overriding the existing one, tftp is use to download the image into the memory map location and then write to the NAND.

First, start up the tftp server and make sure the setup IP address of the device is correct.

/etc/rc.d/init.d/xinetd start

Verify the tftp server is running.

netstat -anu

Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
udp 0 0 0.0.0.0:69 0.0.0.0:*

Download image into the specify location.

MINI2440 # tftp 32000000 u-boot.bin
dm9000 i/o: 0x20000300, id: 0x90000a46           
DM9000: running in 16 bit mode
MAC: 08:00:2f:00:00:02
TFTP from server 192.168.114.181; our IP address is 192.168.114.190
Filename 'u-boot.bin'.
Load address: 0x32000000
Loading: T T T ################
done
Bytes transferred = 232316 (38b7c hex)

Clean up the u-boot partition.

MINI2440 # nand erase 0 40000

NAND erase: device 0 offset 0x0, size 0x40000    
Erasing at 0x20000 -- 100% complete.
OK

Write image to the u-boot partition

MINI2440 # nand write.e 32000000 0 ${filesize}
NAND write: device 0 offset 0x0, size 0x38b7c    

Writing data at 0x38800 -- 100% complete.
232316 bytes written: OK

At last, set the environment offset and save all the settings

MINI2440 # dynenv set env
MINI2440 # saveenv


Reboot the device to run the new update version.

MINI2440 # reset
U-Boot 1.3.2-mini2440 (Feb 26 2010 - 17:34:45)   

I2C: ready
DRAM: 64 MB
Flash: 2 MB
NAND: 128 MiB
Found Environment offset in OOB..
USB: S3C2410 USB Deviced
In: serial
Out: serial
Err: serial
MAC: 08:00:2f:00:00:02
Hit any key to stop autoboot: 0
MINI2440 #

1 則留言:

  1. hi ... thank you very much ... for this.. doc..
    my name is shravan india,AP

    回覆刪除