2010年3月3日 星期三

Build Root File System

Build Root File System on Mini2440

Startup Requirement

You need to have a compiled busybox and the kernel configure with Virtual File memory, NFS client support and the kernel level autoconfiguration function.

This build will create a new Root File System using the NFS service in the host computer to expose the contents to the target system, there is other method which is build a initrd image and booting with an initial RAM disk.

This is by no means a full system setup but a simple process to boot up a Linux system on Mini2440 as a start, alternatively there are tools that will automate the cross compiling process to generate the filesystem and software packages easily - such as Buildroot, OpenEmbedded and etc. which is another stages of learning process.



Filesystem Hierarchy Standard

In order to build a Root File System i will follow the FHS rules to define the main directories and their layout content as below.
rootfs (/)
|--bin
|--dev
|--etc
| |--init.d
|--lib
|--mnt
|--proc
|--sys
|--sbin
|--tmp
|--usr
| |--bin
| |--sbin
|--var

This RFS is mount as a root directory (/).

Note, there are two components to run a Linux system: the kernel and the RFS.

In this example, busybox is use as a base to construct the minimum set of files to support the system.



Create Root Filesystem Strcuture

First, create a new root directory for our RFS, this directory is export as a NFS shared directory.

mkdir /rootfs

Copy the busybox system files into the root directory.

cd /rootfs
cp -a /usr/src/toolchain/busybox-1.16.0/_install/* .


Create the remaining FHS directories as require.

mkdir dev
mkdir -p etc/init.d
mkdir lib
mkdir mnt
mkdir proc
mkdir sys
mkdir -m 777 tmp
mkdir var


Copy the runtime libraries from the compiler system.

cd /rootfs/lib
cp -a /usr/local/arm/4.4.1/arm-none-linux-gnueabi/libc/armv4t/lib/* .


Make a serial console device as our system standard output.

cd /rootfs/dev
mknod -m 622 console c 5 1


When the kernel is running the last initialization action is to start the init program in charge of finalizing system startup by spawning various applications and running some key software components.

The operation of the init program is define in the inittab file, busybox init has the following default behaviour.

::sysinit:/etc/init.d/rcS
::askfirst:-/bin/sh
::ctrlaltdel:/sbin/reboot
::shutdown:/bin/umount -a -r
::shutdown:/sbin/swapoff -a
::restart:/sbin/init

Add a getty on the serial console to the above inittab, depending on the environment variable set in the bootargs (eg. console=ttySAC0) the same device to be set similarly.

::respawn:/sbin/getty -L 115200 /dev/ttySAC0 vt100


Create a rcS job file in the /rootfs/etc/init.d directory to initialize the target system.

#! /bin/sh

# Setup the bin file location and export to system PATH
PATH=/sbin:/bin:/usr/sbin:/usr/bin
umask 022
export PATH

# mount the filesystem directories
mount -a
mkdir /dev/pts
mount -t devpts devpts /dev/pts -o mode=0622

# create device nodes and directories
echo /sbin/mdev>/proc/sys/kernel/hotplug
mdev -s
mkdir /var/lock

# start logging utility services
klogd
syslogd

# set system clock from RTC
hwclock -s

# set host and config loopback interface
ifconfig lo 127.0.0.1

Create a mdev.conf file in the /rootfs/etc directory for the mdev process to do an initial update of the device files dynamically.

# system all-writable devices
full 0:0 0666
null 0:0 0666
ptmx 0:0 0666
random 0:0 0666
tty 0:0 0666
zero 0:0 0666

# console devices
tty[0-9]* 0:5 0660
vc/[0-9]* 0:5 0660

# serial port devices
s3c2410_serial0 0:5 0666 =ttySAC0
s3c2410_serial1 0:5 0666 =ttySAC1
s3c2410_serial2 0:5 0666 =ttySAC2
s3c2410_serial3 0:5 0666 =ttySAC3

# loop devices
loop[0-9]* 0:0 0660 =loop/

# i2c devices
i2c-0 0:0 0666 =i2c/0
i2c-1 0:0 0666 =i2c/1

# frame buffer devices
fb[0-9] 0:0 0666

# input devices
mice 0:0 0660 =input/
mouse.* 0:0 0660 =input/
event.* 0:0 0660 =input/
ts.* 0:0 0660 =input/

# rtc devices
rtc0 0:0 0644 >rtc
rtc[1-9] 0:0 0644

# misc devices
mmcblk0p1 0:0 0600 =sdcard */bin/hotplug
sda1 0:0 0600 =udisk * /bin/hotplug

Create a fstab filesystem table in the /rootfs/etc directory to mount the system directories.
# device mount-point type options dump fsck order
proc /proc proc defaults 0 0
sysfs /sys sysfs defaults 0 0
tmpfs /dev tmpfs defaults 0 0
tmpfs /tmp tmpfs defaults 0 0
var /var tmpfs defaults 0 0

Create a group file in /rootfs/etc directory.

grep root /etc/group>group

Create a password file in /rootfs/etc directory.

grep root /etc/passwd>passwd

Create a system wide 'profile' in /rootfs/etc directory.

USER="`id -un`"                                                 
LOGNAME=$USER
PS1='[\u@\h \W]\# '
PATH=$PATH
HOSTNAME=`/bin/hostname`
export USER LOGNAME PS1 PATH HOSTNAME

Create a /rootfs/etc/issue to add a welcome prompt to the console login.

Welcome to Mini2440
Kernel \r on an \m (\l)



Finally, create a resolv.conf file in /rootfs/etc directory to configure the DNS address to access the internet with your service provider network domain and ip address.

search internet.com.tw
nameserver 192.168.55.244
nameserver 168.95.1.1



Start up the NFS Server

Edit /etc/exports to configure the RFS as a shared directory.

/rootfs *(rw,sync,no_root_squash)

Start up the server.

service nfs restart

Verify the NFS server is running.

showmount -e 192.168.114.181

Export list for 192.168.114.181:
/rootfs *

Reboot the device to run the system.

Restarting system�

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

Loading from NAND 128MiB 3,3V 8-bit, offset 0x60000
Image Name:
Created: 2010-03-02 14:51:28 UTC
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 2053096 Bytes = 2 MB
Load Address: 30008000
Entry Point: 30008000
## Booting kernel from Legacy Image at 32000000 ...
Image Name:
Created: 2010-03-02 14:51:28 UTC
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 2053096 Bytes = 2 MB
Load Address: 30008000
Entry Point: 30008000
Verifying Checksum ... OK
Loading Kernel Image ... OK
OK

Starting kernel ...

Uncompressing Linux.............................................................
Linux version 2.6.32.7 (root@gmax.localdomain) (gcc version 4.4.1 (Sourcery G++0
CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=c0007177
CPU: VIVT data cache, VIVT instruction cache
Machine: MINI2440
Memory policy: ECC disabled, Data cache writeback
CPU S3C2440A (id 0x32440001)
S3C24XX Clocks, (c) 2004 Simtec Electronics
S3C244X: core 405.000 MHz, memory 101.250 MHz, peripheral 50.625 MHz
CLOCK: Slow mode (1.500 MHz), fast, MPLL on, UPLL on
Built 1 zonelists in Zone order, mobility grouping on. Total pages: 16256
Kernel command line: console=ttySAC0 noinitrd init=/sbin/init mini2440=0tb rootf
PID hash table entries: 256 (order: -2, 1024 bytes)
Dentry cache hash table entries: 8192 (order: 3, 32768 bytes)
Inode-cache hash table entries: 4096 (order: 2, 16384 bytes)
Memory: 64MB = 64MB total
Memory: 60664KB available (3572K code, 388K data, 128K init, 0K highmem)
SLUB: Genslabs=11, HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
Hierarchical RCU implementation.
NR_IRQS:85
irq: clearing subpending status 00000002
Console: colour dummy device 80x30
console [ttySAC0] enabled
Calibrating delay loop... 201.93 BogoMIPS (lpj=504832)
Mount-cache hash table entries: 512
CPU: Testing write buffer coherency: ok
NET: Registered protocol family 16
MINI2440: Option string mini2440=0tb
MINI2440: LCD [0:240x320] 1:800x480 2:1024x768 3:240x320 4:640x480
S3C2440: Initialising architecture
S3C2440: IRQ Support
S3C24XX DMA Driver, (c) 2003-2004,2006 Simtec Electronics
DMA channel 0 at c4808000, irq 33
DMA channel 1 at c4808040, irq 34
DMA channel 2 at c4808080, irq 35
DMA channel 3 at c48080c0, irq 36
S3C244X: Clock Support, DVS off
S3C24XX CPU Frequency driver, s3c244x cpu support
bio: create slab at 0
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver hub
usbcore: registered new device driver usb
s3c-i2c s3c2440-i2c: slave address 0x10
s3c-i2c s3c2440-i2c: bus frequency set to 98 KHz
s3c-i2c s3c2440-i2c: i2c-0: S3C I2C adapter
NET: Registered protocol family 2
IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
TCP established hash table entries: 2048 (order: 2, 16384 bytes)
TCP bind hash table entries: 2048 (order: 1, 8192 bytes)
TCP: Hash tables configured (established 2048 bind 2048)
TCP reno registered
NET: Registered protocol family 1
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp NFSv4.1 backchannel transport module.
squashfs: version 4.0 (2009/01/31) Phillip Lougher
JFFS2 version 2.2. (NAND) �© 2001-2006 Red Hat, Inc.
msgmni has been set to 118
alg: No test for stdrng (krng)
io scheduler noop registered
io scheduler anticipatory registered (default)
io scheduler deadline registered
io scheduler cfq registered
Console: switching to colour frame buffer device 60x53
fb0: s3c2410fb frame buffer device
s3c2440-uart.0: ttySAC0 at MMIO 0x50000000 (irq = 70) is a S3C2440
s3c2440-uart.1: ttySAC1 at MMIO 0x50004000 (irq = 73) is a S3C2440
s3c2440-uart.2: ttySAC2 at MMIO 0x50008000 (irq = 76) is a S3C2440
brd: module loaded
at24 0-0050: 1024 byte 24c08 EEPROM (writable)
S3C24XX NAND Driver, (c) 2004 Simtec Electronics
s3c24xx-nand s3c2440-nand: Tacls=1, 9ns Twrph0=3 29ns, Twrph1=2 19ns
s3c24xx-nand s3c2440-nand: NAND soft ECC
NAND device: Manufacturer ID: 0xec, Chip ID: 0xf1 (Samsung NAND 128MiB 3,3V 8-b)
Creating 4 MTD partitions on "NAND 128MiB 3,3V 8-bit":
0x000000000000-0x000000040000 : "u-boot"
0x000000040000-0x000000060000 : "u-boot-env"
0x000000060000-0x000000560000 : "kernel"
0x000000560000-0x000008000000 : "root"
dm9000 Ethernet Driver, V1.31
eth0: dm9000e at c4860300,c4864304 IRQ 51 MAC: 08:00:2f:00:00:02 (chip)
ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
s3c2410-ohci s3c2410-ohci: S3C24XX OHCI
s3c2410-ohci s3c2410-ohci: new USB bus registered, assigned bus number 1
s3c2410-ohci s3c2410-ohci: irq 42, io mem 0x49000000
usb usb1: configuration #1 chosen from 1 choice
hub 1-0:1.0: USB hub found
hub 1-0:1.0: 2 ports detected
usbcore: registered new interface driver libusual
mice: PS/2 mouse device common for all mice
input: gpio-keys as /devices/platform/gpio-keys/input/input0
s3c2440-ts s3c2440-ts: Starting
Created group ts filter len 12 depth 2 close 10 thresh 6
Created Median ts filter len 20 depth 2 dec 24
Created Mean ts filter len 4 depth 2 thresh 65535
Created Linear ts filter depth 2
s3c2440-ts s3c2440-ts: 4 filter(s) initialized
s3c2440-ts s3c2440-ts: successfully loaded
input: s3c2410 TouchScreen as /devices/virtual/input/input1
S3C24XX RTC, (c) 2004,2006 Simtec Electronics
s3c2410-rtc s3c2410-rtc: rtc disabled, re-enabling
s3c2410-rtc s3c2410-rtc: rtc core: registered s3c as rtc0
i2c /dev entries driver
S3C2410 Watchdog Timer, (c) 2004 Simtec Electronics
s3c2410-wdt s3c2410-wdt: watchdog inactive, reset disabled, irq enabled
cpuidle: using governor ladder
sdhci: Secure Digital Host Controller Interface driver
sdhci: Copyright(c) Pierre Ossman
s3c-sdi s3c2440-sdi: powered down.
s3c-sdi s3c2440-sdi: mmc0 - using pio, sw SDIO IRQ
Registered led device: led1
Registered led device: led2
Registered led device: led3
Registered led device: led4
Registered led device: backlight
usbcore: registered new interface driver hiddev
usbcore: registered new interface driver usbhid
usbhid: v2.6:USB HID core driver
Advanced Linux Sound Architecture Driver Version 1.0.21.
No device for DAI UDA134X
No device for DAI s3c24xx-i2s
S3C24XX_UDA134X SoC Audio driver
UDA134X SoC Audio Codec
asoc: UDA134X <-> s3c24xx-i2s mapping ok
ALSA device list:
#0: S3C24XX_UDA134X (UDA134X)
TCP cubic registered
NET: Registered protocol family 17
s3c2410-rtc s3c2410-rtc: setting system clock to 2008-12-27 10:22:30 UTC (12303)
eth0: link up, 100Mbps, full-duplex, lpa 0x45E1
IP-Config: Complete:
device=eth0, addr=192.168.114.190, mask=255.255.255.0, gw=192.168.114.1,
host=mini2440, domain=, nis-domain=(none),
bootserver=255.255.255.255, rootserver=192.168.114.181, rootpath=
Looking up port of RPC 100003/2 on 192.168.114.181
Looking up port of RPC 100005/1 on 192.168.114.181
VFS: Mounted root (nfs filesystem) on device 0:13.
Freeing init memory: 128K

Please press Enter to activate this console.
[root@mini2440 /]#


2010年3月2日 星期二

Update Kernel Image

Update Kenel Image on Mini2440

Startup Requirement

You need to have a working installed bootloader in the target system, set the switch to NAND BOOT and reset the board into the command prompt.

This update will override the old kernel image.

This also assume that you have a compiled kernel in a directory called tftpboot and managed to configure the host computer as a tftp server.


Refresh Kernel

First check the size of the uImage file.

ls -l /var/lib/tftpboot/uImage
-rw-r--r-- 1 root root 2053160 2010-03-02 22:51 uImage

Verify the table information, we need the size and offset of the kernel 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 output shows that kernel is at the third block and start at 0x00060000 offset address with size of 500000.

Clean up the kernel partition.

MINI2440 # nand erase 60000 500000

NAND erase: device 0 offset 0x60000, size 0x500000                   
Erasing at 0x540000 -- 100% complete.
OK

Download image into the specify location, make sure you have start up the tftp server.

MINI2440 # tftp 32000000 uImage

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 'uImage'.
Load address: 0x3200000
Loading: T T #################################################################
#################################################################
##########
done
Bytes transferred = 2053160 (1f5428 hex)
Write image to the kernel partition, if there is a write problem you may have to refresh the NAND from scratch.

MINI2440 # nand write.e 32000000 60000 ${filesize}

NAND write: device 0 offset 0x60000, size 0x1f5428                   

Writing data at 0x255000 -- 100% complete.
2053160 bytes written: OK

Verify the number of bytes written is correct (2053160 in this example).

At last, set the boot command to load from the kernel block and save all the settings.

MINI2440 # setenv bootcmd 'nboot.e kernel;bootm'
MINI2440 # saveenv


Reboot the device to run the new update version.

MINI2440 # reset

You will see the bootloader starting up the kernel image and it will stop running at the system initialization stage because we have not yet build a root filesystem.

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

Loading from NAND 128MiB 3,3V 8-bit, offset 0x60000
Image Name:
Created: 2010-03-02 14:51:28 UTC
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 2053096 Bytes = 2 MB
Load Address: 30008000
Entry Point: 30008000
## Booting kernel from Legacy Image at 32000000 ...
Image Name:
Created: 2010-03-02 14:51:28 UTC
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 2053096 Bytes = 2 MB
Load Address: 30008000
Entry Point: 30008000
Verifying Checksum ... OK
Loading Kernel Image ... OK
OK

Starting kernel ...

Uncompressing Linux.............................................................
Linux version 2.6.32.7 (root@gmax.localdomain) (gcc version 4.4.1 (Sourcery G++0
CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=c0007177
CPU: VIVT data cache, VIVT instruction cache
Machine: MINI2440

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 #

Porting MINI2440

Mini2440 FriendlyARM for Embedded Developer

Startup Introduction

Mini2440 is an ARM9 architecture device providing embedded RISC Microprocessor solution empower from the Samsung S3C2440 CPU, the device has a 64M RAM and 128M Flash memory, equip with 3.5 inch TFT LCD, Ethernet interface, SD card, USB host and slave, a serial COM port and other ranges of hardware features.

This board comes with a BIOS (when switch to NOR BOOT) which can be used to format the NAND Flash, download image file into the memory, to boot up the system and etc, it is also preinstalled with a supervivi bootloader that will start up the Linux system (when switch to NAND BOOT) and showcase a front-end GUI Qt/Embedded applications.


Source Package

Open source code is provided with the bootloaders from vboot, vivi and u-boot-1.1.6, a copy of linux-2.6.29 source kernel, busybox-1.13.3 toolchains, Qtopia-2.2.0 development toolkit and the arm-linux-gcc-4.3.2 cross-compiler.

In addition, there are backup image of supervivi bootloader, kernel zImage and a copy of the root filesystem which contains all the Qtopia demo applications, it can be used to restore the original system in case of system crash.


System Setup

The host machine is install with a Fedora package and the Mini2440 is connect to the host system with a serial COM Port.

An Ethernet hub is also use to configure a client server network where by the NFS service is use to export the shared directory to the target system.



Doing the Work

The source kernel, compiler and toolkit provided is quite some times ago which i will upgrade the software to the current release.

Besides, the supervivi bootloader is a proprietary software base on vivi, but i prefer to use u-boot which is an open source program with proper documentations and lots of tutorial on the internet.

All the compiled programs will be installed in the NFS shared directory, when boot up from the target system the shared directory will be mounted to run the programs.


1. Install Cross Compiler

Download a copy of Sourcery G++ from codesourcery into the /usr/local/arm directory and decompress the zip file.

bzip2 -dc arm-2009q3.tar.bz2 |tar xvf -

Check what is the compiler version number.

/usr/local/arm/arm-2009q3/bin/arm-none-linux-gnueabi-gcc --version
arm-none-linux-gnueabi-gcc (Sourcery G++ Lite 2009q3-67) 4.4.1
Copyright (C) 2009 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.>

Optionally, make a reference link to the compiler directory.

ln -s arm-2009q3 4.4.1

Create soft link for all the bin files below.

cd 4.4.1/bin
ln -s arm-none-linux-gnueabi-addr2line arm-linux-addr2line
ln -s arm-none-linux-gnueabi-ar arm-linux-ar
ln -s arm-none-linux-gnueabi-as arm-linux-as
ln -s arm-none-linux-gnueabi-c++ arm-linux-c++
ln -s arm-none-linux-gnueabi-c++filt arm-linux-c++filt
ln -s arm-none-linux-gnueabi-cpp arm-linux-cpp
ln -s arm-none-linux-gnueabi-gcov arm-linux-gcov
ln -s arm-none-linux-gnueabi-gdb arm-linux-gdb
ln -s arm-none-linux-gnueabi-gdbtui arm-linux-gdbtui
ln -s arm-none-linux-gnueabi-gprof arm-linux-gprof
ln -s arm-none-linux-gnueabi-ld arm-linux-ld
ln -s arm-none-linux-gnueabi-nm arm-linux-nm
ln -s arm-none-linux-gnueabi-objcopy arm-linux-objcopy
ln -s arm-none-linux-gnueabi-objdump arm-linux-objdump
ln -s arm-none-linux-gnueabi-ranlib arm-linux-ranlib
ln -s arm-none-linux-gnueabi-readelf arm-linux-readelf
ln -s arm-none-linux-gnueabi-size arm-linux-size
ln -s arm-none-linux-gnueabi-sprite arm-linux-sprite
ln -s arm-none-linux-gnueabi-strings arm-linux-strings
ln -s arm-none-linux-gnueabi-strip arm-linux-strip

Create shell script for the bin files below with a 'armv4t' machine option.

echo arm-none-linux-gnueabi-g++ -march=armv4t $@ > arm-linux-g++
echo arm-none-linux-gnueabi-gcc -march=armv4t $@ > arm-linux-gcc
echo arm-none-linux-gnueabi-gcc-4.4.1 -march=armv4t $@ > arm-linux-gcc-4.4.1


Change the shell scripts attribute to executable mode.

chmod +x arm-linux-g++
chmod +x arm-linux-gcc
chmod +x arm-linux-gcc-4.4.1


Export the bin directory to the environment PATH variable.

Note, this line is necessary whenever logon to a new terminal, you may add it into your user profile to run this cmd automatically.

export PATH=/usr/local/arm/4.4.1/bin:$PATH

Test the shell script if it's working.

arm-linux-gcc -v

When successful the output result is display below.
Using built-in specs.
Target: arm-none-linux-gnueabi
Configured with: /scratch/julian/2009q3-respin-linux-lite/src/gcc-4.4/configure --build=i686-pc-linux-gnu --host=i686-pc-linux-gnu --target=arm-none-linux-gnueabi --enable-threads --disable-libmudflap --disable-libssp --disable-libstdcxx-pch --enable-extra-sgxxlite-multilibs --with-arch=armv5te --with-gnu-as --with-gnu-ld --with-specs='%{funwind-tables|fno-unwind-tables|mabi=*|ffreestanding|nostdlib:;:-funwind-tables} %{O2:%{!fno-remove-local-statics: -fremove-local-statics}} %{O*:%{O|O0|O1|O2|Os:;:%{!fno-remove-local-statics: -fremove-local-statics}}}' --enable-languages=c,c++ --enable-shared --disable-lto --enable-symvers=gnu --enable-__cxa_atexit --with-pkgversion='Sourcery G++ Lite 2009q3-67' --with-bugurl=https://support.codesourcery.com/GNUToolchain/ --disable-nls --prefix=/opt/codesourcery --with-sysroot=/opt/codesourcery/arm-none-linux-gnueabi/libc --with-build-sysroot=/scratch/julian/2009q3-respin-linux-lite/install/arm-none-linux-gnueabi/libc --with-gmp=/scratch/julian/2009q3-respin-linux-lite/obj/host-libs-2009q3-67-arm-none-linux-gnueabi-i686-pc-linux-gnu/usr --with-mpfr=/scratch/julian/2009q3-respin-linux-lite/obj/host-libs-2009q3-67-arm-none-linux-gnueabi-i686-pc-linux-gnu/usr --with-ppl=/scratch/julian/2009q3-respin-linux-lite/obj/host-libs-2009q3-67-arm-none-linux-gnueabi-i686-pc-linux-gnu/usr --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' --with-cloog=/scratch/julian/2009q3-respin-linux-lite/obj/host-libs-2009q3-67-arm-none-linux-gnueabi-i686-pc-linux-gnu/usr --disable-libgomp --enable-poison-system-directories --with-build-time-tools=/scratch/julian/2009q3-respin-linux-lite/install/arm-none-linux-gnueabi/bin --with-build-time-tools=/scratch/julian/2009q3-respin-linux-lite/install/arm-none-linux-gnueabi/bin
Thread model: posix
gcc version 4.4.1 (Sourcery G++ Lite 2009q3-67)

2. Build Boot-loader Image

Download a source copy from the mini2440 u-boot project into the /usr/src/bootloader directory and decompress the zip file.

gzip -cd dev-mini2440-stable.tar.gz |tar xvf -

A new directory 'mini2440' is created.

Optionally, change the directory name and make a reference link to the bootloader directory.

mv mini2440 mini2440-1.3.2
ln -s mini2440-1.3.2 u-boot


Create a u-boot configuration file for the target system.

cd u-boot
make clean
ARCH=arm make mini2440_config


Build the bootloader image

ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- make
cp -rf u-boot.bin /var/lib/tftpboot


When finish without errors, the u-boot.bin file will be used to flash the u-boot image.


3. Build Kernel Image

Download a source copy from mini2440 kernel project into the /usr/src/kernels directory and decompress the zip file.

gzip -cd mini2440-stable.tar.gz |tar xvf -

A new directory 'mini2440' is created.

Optionally, change the directory name and create a reference link to the kernel directory.

mv mini2440 mini2440-2.6.32.7
ln -s mini2440-2.6.32.7 arm-linux


Create a kernel configuration file base on the old config_mini2440_n35 file from an earlier version eg. linux-2.6.29 from the Mini2440 package.

cd arm-linux
make clean
cp /usr/src/kernels/linux-2.6.29/config_mini2440_n35 ./.config
ARCH=arm make oldconfig


Press enter to select all the default settings, when finish a new .config file is generated while the old one is save in the .config.old.

Optionally, create a default configuration file if you don't have an existing .config file, this will produce the largest general-purpose configuration.

ARCH=arm make mini2440_defconfig

Change the kernel configuration setting below.

ARCH=arm make menuconfig

Go to 'File Systems' --> 'Network File Systems' --> Select 'NFS client support for NFS' and 'Root file system on NFS'

--- Network File Systems
<*> NFS client support
[*] NFS client support for NFS version 3
[*] NFS client support for the NFSv3 ACL protocol extension
[*] NFS client support for NFS version 4 (EXPERIMENTAL)
[ ] NFS client support for NFSv4.1 (DEVELOPER ONLY)
[*] Root file system on NFS
< > NFS server support


Go to 'Networking Support' --> 'Networking Options' --> Select the 'IP: kernel level autoconfiguration

[*] IP: kernel level autoconfiguration
[*] IP: DHCP support
[*] IP: BOOTP support
[*] IP: RARP support


Go to 'File System' --> 'Pseudo filesystems' --> Select 'Virtual memory file system support'

[*] /proc file system support
[*] Sysctl support (/proc/sys)
[*] Enable /proc page monitoring
[*] sysfs file system support
[*] Virtual memory file system support (former shm fs)
[*] Tmpfs POSIX Access Control Lists


Build the kernel image.

ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- make zImage
cp -rf arch/arm/boot/zImage /var/lib/tftpboot


Build the kernel modules, if there are modules setup in the configuration file.

ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- make modules
ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- make modules_install


Finally, compressed the kernel image to include checksum and header records require for use with u-boot.

mkimage -A arm -O linux -T kernel -C none -a 0x30008000 -e 0x30008000 -d ./zImage ./uImage

Image Name:
Created: Tue Mar 2 22:51:28 2010
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 2053096 Bytes = 2004.98 kB = 1.96 MB
Load Address: 30008000
Entry Point: 30008000

When finish without errors, the uImage file will be used to flash the kernel image.


4. Build System Tools and Utilities

Download a source copy from busybox into the /usr/src/toolchain directory and decompress the zip file.

cd /usr/src/toolchain bzip2 -dc busybox-1.16.0.tar.bz2 |tar xvf -

A new directory 'busybox-1.16.0' is created.

Make a reference link to the busybox directory.

ln -s busybox-1.16.0 busybox

Create a busybox configuration file base on the old fa.config file from an earlier version eg. busybox-1.13.3 from the Mini2440 package.

cd busybox
make clean
copy /usr/src/toolchain/busybox-1.13.3/fa.config ./.config
ARCH=arm CC=arm-linux-gcc-4.4.1 make oldconfig


Press enter to select all the default settings, when finish a new .config file is generated while the old one is save in the .config.old.

Optionally, create a default configuration file if you don't have an existing fa.config file, this will produce the largest general-purpose configuration.

ARCH=arm CC=arm-linux-gcc-4.4.1 make oldconfig

Change the configuration setting below.

make menuconfig

Go to 'Busybox Settings' --> 'Installation Options' --> Change the busybox installation prefix to './_install'

[ ] Don't use /usr
Applets links (as soft-links) --->
(./_install) BusyBox installation prefix


Go to 'Busybox Settings' --> 'Build Options' --> Change the cross compiler prefix to 'arm-linux'

[ ] Build BusyBox as a static binary (no shared libs)
[ ] Build BusyBox as a position independent executable
[ ] Force NOMMU build [ ] Build shared libbusybox
[*] Build with Large File Support (for accessing files > 2 GB)
(arm-linux-) Cross Compiler prefix
() Additional CFLAGS


Build the busybox system.

ARCH=arm CC=arm-linux-gcc-4.4.1 make
ARCH=arm CC=arm-linux-gcc-4.4.1 make install


When finish without errors, the _install system folder will be used to build the root filesystem.



More Information

Furthre Reading