Deploying u-boot, Linux kernel and GPE onto Mini2440, powered by SAMSUNG S3C2440

by Forrest Sheng Bao http://fsbao.net/

An American company of my friend is selling such kit in US and Canada. Their webpage is: http://www.andahammer.com. I heavily referred this article from Kernel Lab: http://labs.kernelconcepts.de/Publications/Micro24401/





Some Terminology

One killer application of Linux is to be used as the operating system of an embedded system. ARM-based CPUs are killer partners of embedded Linux. In this article, we will discuss how to deploy the basic system (bootloader, Linux kernel, and graphic desktop system) onto an ARM development board, using SAMSUNG S3C2440X processor.

The default mini2440 comes with vivi, a bootloader provided Samsung, a long time ago. It sucks. I prefer to gear up my system all by open source stuffs. So, in this article, I am gonna tell you how to depoly u-boot (the bootload), Linux kernel (the operating system) and GPE (the graphic embedded environment) on to mini2440. This article is still under construction. Please give me comments and I will improve it.

You can jump to Step 1 directly to skip the background information below.

The bootloader: Unlike regular computer, most embedded systems don't have a firmware out-of-box like CMOS, Openfirmware or EFI, etc. Instead, you need to install the bootloader yourself or it is burned onto the board already. Generally, to a naked system, people use JTAG protocol to burn a bootloader. A bootloader can provide a interface for users to control the system as well as basic system tools, such as writing data into flash or transferring files from the host machine. In this article, the bootloader on the board by default is vivi and we are gonna replace it by u-boot. Since you have vivi on-board by default, you don't need JTAG. You can use vivi to download and write u-boot into flash memory.

The Operating System: I assume you know what an operating system is and what Linux is. The kernel version here is 2.6.31.

The Root Filesystem : Other than the Linux kernel, most embedded Linux system contain things such as a graphic environment as on most PDAs. The collection of all those files is called the Root Filesystem. It generally is stored in the flash partition called root. Attention, here "Root" is not equal to the /root directory and here "filesystem" is not a software to manager files on storage devices. The Root Filesystem is in the form of an image to be written into the flash memory.

There is no need to re-construct the Root Filesystem for writing a new file or porting an application onto the board. Once the Root Filesystem has been deployed, you can copy files from the PC to the board through Ethernet or removable media.

Just as KDE or GNOME, which are the desktop environment on PCs, Qtopia or GPE are the desktop environment for embedded Linux. They are the collections of some basic embedded applications, such as address book, email client, calendar, image viewer and media player.

Before you start

Before you start, you will need
  1. A mini2440 development board, with or without a 3.5"/7" LCD.
  2. A software called minicom on your PC
  3. The u-boot image, Linux kernel image, and GPE image, as well as the USB-downloader program to transfer files from your Linux PC to the NAND flash on mini2440 via a USB cable. All those files you need are here: http://labs.kernelconcepts.de/Projects/Micro2440/#Downloads
  4. A non-cross RS232 cable (both female heads) and a USB type-A-to-type-B cable (one head is the regular USB head as on your USB flash/thumb drive, and the other one is the little square one, like the one to connect your printer.)

Step 1: Setting up the minicom

  1. Install minicom(for example, via command "sudo apt-get install minicom")
  2. On a shell prompt, type "minicom -s"
  3. Use up and down arrow to select "Serial port setup"
  4. If you wanna setup something, press the button corresponding to that item. After you finished, press Enter to exit. Besure to configure "Bps/Par/Bits" and "Hardware Flow Control" as same as the snapshot. You can save this configuration as default so that you don't need to set it again next time.
  5. Then select "Exit" and press Enter. Don't select "Exit from Minicom", otherwise you are out of minicom.

Please note that your serial port does NOT have to be /dev/ttyUSB0, since I used a USB-to-RS2323 converter. It is only my case. In your case, it could be /dev/ttyS1 or /dev/ttyS0. But make sure set all the reset parameters as I did.

Step 2: Replacing vivi by u-boot



The mini2440 comes with two flashes, the NOR flash and the NAND flash. The NOR flash stores vivi by default. So I am NOT gonna overwrite it, in case I need it. I am gonna overwrite the NAND flash by u-boot, Linux kernel 2.6.31 and GPE.


I will boot the board from NOR flash, using vivi in it to write u-boot into NAND flash. And then, I will reboot the board from NAND flash, and use u-boot to finish all the rest.


Turn the boot selection switch to NOR flash on the board. Connect mini2440 with PC using minicom via RS232. Power on the board and you shall see this boot-up menu:

##### FriendlyARM BIOS for 2440 #####
[x] bon part 0 320k 2368k
[v] Download vivi 
[k] Download linux kernel 
[y] Download root_yaffs image 
[c] Download root_cramfs image 
[a] Absolute User Application
[n] Download Nboot 
[e] Download Eboot 
[i] Download WinCE NK.nb0 
[w] Download WinCE NK.bin 
[d] Download & Run 
[f] Format the nand flash 
[p] Partition for Linux 
[b] Boot the system 
[s] Set the boot parameters 
[t] Print the TOC struct of wince 
[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
Press q and Enter at the prompt and switch to vivi promp.


Now connect PC with mini2440's USB device port, via a USB cable. Make the compiled u-boot image handy. Tell vivi that you need 239016 Bytes space in the RAM to load something from the USB, starting at 0x31000000
Supervivi> load ram 0x31000000 239016 u
USB host is connected. Waiting a download. 
On another shell window, use following command to download u-boot into the RAM of mini2440
$ sudo ./s3c2410_boot_usb u-boot.bin 
Enter root password when prompted, and you shall see this output on the shell
csum = 0xd542
send_file: addr = 0x33f80000, len = 0x0003a5a8
Error downloading program
Please ignore the error.

Now go back to vivi. You shall see follows
Now, Downloading [ADDRESS:31000000h,TOTAL:239026]
RECEIVED FILE SIZE:  239026 (233KB/S, 1S)
Downloaded file at 0x31000000, size = 239016 bytes


Now we are ready to write u-boot from the RAM to NAND flash. Execute the code starting at RAM location 0x31000000:
Supervivi> go 0x31000000
go to 0x31000000
  argument 0 = 0x00000000
  argument 1 = 0x00000000
  argument 2 = 0x00000000
  argument 3 = 0x00000000

U-Boot 1.3.2-dirty-moko12 (Apr 16 2009 - 18:14:52)

I2C:   ready
DRAM:  64 MB
Flash:  2 MB
NAND:  Bad block table not found for chip 0
Bad block table not found for chip 0
64 MiB
Found Environment offset in OOB..
USB:   S3C2410 USB Deviced
In:    serial
Out:   serial
Err:   serial
MAC: 08:08:11:18:12:27
Hit any key to stop autoboot:  0

When seeing "Hit any key to stop autoboot," press any key on the keyboard. The prompt shall change from Supervivi> to MINI2440 #. Get the information about the NAND flash:
MINI2440 # nand info

Device 0: NAND 64MiB 3,3V 8-bit, page size 512, sector size 16 KiB

Erase everything on the NAND flash:
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/N>
Erasing at 0x3ffc000 -- 100% complete.
Bad block table not found for chip 0
Bad block table not found for chip 0
OK
Please enter a lower case y and press Enter when prompted.

Now create a new partition table
MINI2440 # nand createbbt
Create BBT and erase everything ? 
Skipping bad block at  0x03ff0000                                            
Skipping bad block at  0x03ff4000                                            
Skipping bad block at  0x03ff8000                                            
Skipping bad block at  0x03ffc000                                            

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 0x03ffc000, version 0x01
Bad block table written to 0x03ff8000, version 0x01
and partition the NAND flash using u-boot default configuration. Each partition shall be given a name.
MINI2440 # mtdparts                    

device nand0 <mini2440-nand>, # 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                0x03aa0000      0x00560000      0

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

defaults:
mtdids  : nand0=mini2440-nand
mtdparts: <NULL>

Now write u-boot to NAND flash

MINI2440 # nand write 0x31000000 u-boot

NAND write: device 0 offset 0x0, size 0x40000
 262144 bytes written: OK


Reset the on-board switch to NAND flash and reboot mini2440



Step 3: Downloading Linux Kernel



Now you shall see all u-boot informations on the minicom window. Hit any key when you see the promption "Hit any key to stop autoboot."


Now set a NAND flash offset since later you won't want to write stuffs on the area that contains u-boot.
MINI2440 # dynenv set 40000
device 0 offset 0x40000, size 0x3fc0000
45 4e 56 30 - 00 00 04 00
MINI2440 # nand erase kernel

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


Copy the Linux kernel image onto an SD card and insert the SD card to the card reader of mini2440. Now initialize the SD card.
MINI2440 # mmcinit
trying to detect SD Card...
Manufacturer:       0x02, OEM "TM"
Product name:       "SD01G", revision 2.3
Serial number:      2486075243
Manufacturing date: 1/2002
CRC:                0x72, b0 = 1
READ_BL_LEN=15, C_SIZE_MULT=7, C_SIZE=365
size = 1642070016


Suppose the Linux kernel image has the filename "uImage." Now load it to the RAM first.
MINI2440 # fatload mmc 0:1 0x31000000 uImage
reading uImage

1945804 bytes read


Write the Linux kernel from RAM to the NAND flash partition called "kernel."
MINI2440 # nand write 0x31000000 kernel

NAND write: device 0 offset 0x60000, size 0x500000
 5242880 bytes written: OK


Step 4: Downloading GPE Embedded Graphic Environment



Well, at this step, you have plenty of choices. You can try Qtopia, etc. But I prefer GPE, which is GPL'ed and small. Things like GPE are called Root Filesystems. You can follow the same steps that you did for downloading Linux kernel. Just write to NAND partition "root" instead of "kernel."


Initialize SD card
MINI2440 # nand erase root
MINI2440 # mmcinit
trying to detect SD Card...
Manufacturer:       0x02, OEM "TM"
Product name:       "SD01G", revision 2.3
Serial number:      2486075243
Manufacturing date: 1/2002
CRC:                0x72, b0 = 1
READ_BL_LEN=15, C_SIZE_MULT=7, C_SIZE=365
size = 1642070016

Load GPE image to RAM, supposing the filename is gpe-image-micro2440.jffs2.


MINI2440 # fatload mmc 0:1 0x31000000 gpe-image-micro2440.jffs2
reading gpe-image-micro2440.jffs2

39239680 bytes read

Since the GPE image is compiled in JFFS2 filesystem, you need to write it as a JFFS2 image.
MINI2440 # nand write.jffs2 0x31000000 root ${filesize}

NAND write: device 0 offset 0x560000, size 0x256c000

Writing data at 0x2acbe00 -- 100% complete.
 39239680 bytes written: OK


Finalization

Now you are pretty much done. Just do the two last things as follows
MINI2440 # setenv bootcmd nboot.e kernel \; bootm
MINI2440 # saveenv
Saving Environment to NAND...
Erasing Nand...Writing to Nand... done

Now reset your mini2440 and enjoy!


Acknowledgements

Dave Festing, from Christchurch, New Zealand gave me some comments on serial port device name, "# nand erase root before mounting the SD card to upload gpe-image-micro2440.jffs2" and a typo.

No comments: