Search This Blog

Sunday, December 26, 2010

Deploying u-boot, Linux kernel and GPE onto Mini2440


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.
  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

  • Install minicom(for example, via command "sudo apt-get install minicom") 

  • On a shell prompt, type "minicom -s" 

  • Use up and down arrow to select "Serial port setup". 

  • 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.

  • 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
    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
    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.
    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
    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
    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


    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!

    1 comment:

    1. I want to know where exactly can we place the bootloader image file in friendly arm board