Difference between revisions of "Linux on the Glyn Tonga2 (Toshiba TMPA900, ARM9)"

From Random Projects
Jump to: navigation, search
m
m (Linux)
Line 412: Line 412:
 
  Revision        : 0000
 
  Revision        : 0000
 
  Serial          : 0000000000000000
 
  Serial          : 0000000000000000
 +
 +
$ '''lsusb'''
 +
Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
 +
 +
$ '''mount'''
 +
rootfs on / type rootfs (rw)
 +
/dev/root on / type jffs2 (rw,relatime)
 +
devtmpfs on /dev type devtmpfs (rw,relatime,size=30500k,nr_inodes=7625,mode=755)
 +
proc on /proc type proc (rw,relatime)
 +
devpts on /dev/pts type devpts (rw,relatime,gid=5,mode=620)
 +
tmpfs on /dev/shm type tmpfs (rw,relatime,mode=777)
 +
tmpfs on /tmp type tmpfs (rw,relatime)
 +
sysfs on /sys type sysfs (rw,relatime)
 +
 +
$ '''cat /proc/fb'''
 +
0 CLCD FB
 +
 +
$ '''cat /proc/interrupts'''
 +
            CPU0
 +
  1:          0        VIC  tmpa9xx_rtc
 +
  4:      58636        VIC  TMPA9xx Timer Tick
 +
  5:          1        VIC  tmpa9xx-ts-irq
 +
  7:          0        VIC  tmpa9xx-i2c
 +
  8:          0        VIC  tmpa9xx-adc
 +
  10:      8179        VIC  uart-pl011
 +
  12:    470936        VIC  pl022
 +
  13:          0        VIC  pl022
 +
  16:          0        VIC  DMA
 +
  17:    157376        VIC  DMA
 +
  18:          0        VIC  CLCD FB
 +
  20:          0        VIC  tmpa9xx_lcdda
 +
  21:          1        VIC  tmpa9xx-udc
 +
  26:          0        VIC  gpio_r
 +
  27:          1        VIC  ohci_hcd:usb1
 +
  28:          0        VIC  gpio_n
 +
  29:          0        VIC  gpio_f
 +
  30:          0        VIC  gpio_c
 +
  31:          0        VIC  gpio_a
 +
  44:          0        gpio  eth0
 +
Err:          0
 +
 +
$ '''cat /proc/mtd'''
 +
dev:    size  erasesize  name
 +
mtd0: 00080000 00020000 "u-boot"
 +
mtd1: 00020000 00020000 "u-boot_env"
 +
mtd2: 00300000 00020000 "splash"
 +
mtd3: 00300000 00020000 "kernel"
 +
mtd4: 0f960000 00020000 "rootfs"
 +
 +
$ '''cat /proc/bus/input/devices'''
 +
I: Bus=0019 Vendor=0000 Product=0000 Version=0100
 +
N: Name="TMPA9xx touchscreen driver"
 +
P: Phys=
 +
S: Sysfs=/devices/virtual/input/input0
 +
U: Uniq=
 +
H: Handlers=mouse0 event0
 +
B: PROP=0
 +
B: EV=b
 +
B: KEY=400 0 0 0 0 0 0 0 0 0 0
 +
B: ABS=1000003
  
 
== Resources ==
 
== Resources ==

Revision as of 01:35, 16 October 2011

This is a short HOWTO for using Linux on the Glyn Tonga2 SO-DIMM CPU Module, which features a Toshiba TMPA900 (ARM9) microcontroller/CPU and additional chips for Ethernet, DDR RAM, and NAND flash.

Hardware specs

  • CPU: Toshiba TMPA900CMXBG (ARM9, 32-bit RISC with MMU, ARM926EJ-S, little endian, max. 200MHz, built-in RAM/ROM: 32/16kB)
  • DDR SDRAM: Hynix H5MS5162DFR-J3M (64Mbyte, x16, 1.8V, 166/83MHz at CL3/2)
  • NAND flash: Samsung K9F2G08U0B-PIB0 (256M x 8 Bit, 3.3V)
  • Ethernet: SMSC LAN9221I-ABZJ
  • ...

Photos

TODO

Building an arm-linux toolchain and root filesystem using buildroot

First install some requirements, in case you don't have them already:

$ apt-get install build-essential bison flex gettext libncurses-dev git-core subversion

Then get the buildroot source code from the git repo:

$ cd $HOME
$ git clone git://git.buildroot.net/buildroot buildroot-git
$ cd buildroot-git

Configure buildroot, select the target architecture, toolchain, and packages you want to build:

$ make menuconfig

I used the following settings (some are required, others are optional, depends a lot on your needs):

  • Target arch: arm
  • Target arch variant: arm926t
  • Target ABI: EABI (this is the default anyway)
  • Toolchain:
    • Toolchain type: Buildroot toolchain (this is the default anyway)
    • Kernel Headers: Linux 2.6.38.x kernel headers (the version here must match the kernel version you'll use on the board, otherwise stuff could break, e.g. tslib)
    • GCC compiler Version: gcc 4.6.x (default is gcc 4.3.x, but the newer 4.6.x version works fine too)
    • Purge unwanted locales (leave only "C en_US" selected, this saves a lot of space)
    • Enable large file (files > 2 GB) support (needed for some packages)
    • Enable IPv6 support (needed for some packages)
    • Enable WCHAR support (needed for some packages)
    • Enable C++ support
  • Package selection:
    • BusyBox (already selected, this is the bare minimum you need)
    • Graphic libraries and applications (graphic/text) / Libraries:
      • directfb, SDL, Qt, cairo, gdk-pixbuf, gtk2, others (if you want to write graphical programs for the board)
    • Hardware handling:
      • mtd/jffs2 utilities (useful for NAND utilities in the Linux system later)
      • u-boot tools (for fw_printenv)
    • Networking applications:
      • lrzsz (I'm using the zx tool from this package to transfer files to the target via serial console + minicom; you can also use other means though, e.g. USB, SD card, ethernet/TFTP/scp/whatever)
  • Filesystem images:
    • jffs2 root filesystem
      • Flash Type: NAND flash with 2kB Page and 128 kB erasesize (the default is incorrect for this board)
      • Pad output (otherwise the respective nand write command in U-Boot will fail later on)
      • Produce a summarized JFFS2 image (apparently this speeds up boot time a bit, if your kernel supports "summarized" JFFS2 images, which it will).
    • You can un-select tar the root filesystem, it's not needed if you just write JFFS2 images to NAND flash, like I do.
    • ubifs root filesystem is another option you might want to look into, it's the successor to JFFS2 and has some advantages; I haven't tested it yet, though.
  • Do not select anything in "Bootloaders" or "Kernel", we'll build those independently later.

Save the settings and exit menuconfig, then build all the stuff:

$ make

The resulting rootfs.jffs2 file is what you can write to NAND flash later; it's located in the output/images directory.

The arm-linux toolchain which was built, is located in output/host/usr/bin etc.

Random hints and notes

  • If you get build errors for "microperl", this fix should help (wasn't needed in the latest git version of buildroot anymore, though).
  • If you get a strange build error in ftl_format (part of mtd-utils), this is likely a binutils/ld bug (PR ld/13195), which was fixed in current Debian unstable as of binutils 2.21.90.20111004-1. For easier googling, here's the error message:

/usr/bin/ld: /home/uwe/buildroot-2011.08/output/build/host-mtd-1.4.6/ftl_format: local symbol `_dl_argv@@GLIBC_PRIVATE' in /lib/i386-linux-gnu/ld-linux.so.2 is referenced by DSO
/usr/bin/ld: final link failed: Bad value
collect2: ld returned 1 exit status
make[1]: *** [/home/uwe/buildroot-2011.08/output/build/host-mtd-1.4.6/ftl_format] Error 1

Building U-Boot

Add the bin directory (where the toolchain you built above resides) to your $PATH:

$ export PATH=$PATH:~/buildroot-git/output/host/usr/bin

Get the U-Boot source code (a patched version for tmpa9xx) via git:

$ git clone git://git.labs.kernelconcepts.de/u-boot-tmpa9xx.git
$ cd u-boot-tmpa9xx

Configure and build U-Boot:

$ make tonga2_config
$ make CROSS_COMPILE=arm-linux-
[...]
arm-linux-objcopy -O srec u-boot u-boot.srec
arm-linux-objcopy --gap-fill=0xff -O binary u-boot u-boot.bin
Generating Tonga2 board NAND Flash image
all done

Building the Linux kernel

Add the bin directory (where the toolchain you built above resides) to your $PATH (if you haven't done so already):

$ export PATH=$PATH:~/buildroot-git/output/host/usr/bin

Install some more required packages:

$ apt-get install lzop u-boot-tools

Grab the Linux source code from the respective repository:

$ git clone git://git.labs.kernelconcepts.de/topas.git
$ cd topas

Configure and build the kernel (you'll build a uImage for use with U-Boot):

$ make tonga_defconfig ARCH=arm
$ make menuconfig ARCH=arm
$ make uImage ARCH=arm CROSS_COMPILE=arm-linux-
[...]
  LD      arch/arm/boot/compressed/vmlinux
  OBJCOPY arch/arm/boot/zImage
  Kernel: arch/arm/boot/zImage is ready
  UIMAGE  arch/arm/boot/uImage
Image Name:   Linux-2.6.38+
Created:      Thu Oct  6 11:13:21 2011
Image Type:   ARM Linux Kernel Image (uncompressed)
Data Size:    2444056 Bytes = 2386.77 kB = 2.33 MB
Load Address: 40008000
Entry Point:  40008000

At the "menuconfig" stage you can configure the kernel to your needs as you see fit.

The resulting arch/arm/boot/uImage file will be written to NAND flash later on.

Use the arm-linux toolchain for writing/cross-compiling programs

Add the bin directory (where the toolchain you built above resides) to your $PATH (if you haven't done so already):

$ export PATH=$PATH:~/buildroot-git/output/host/usr/bin

If you want to cross-compile other programs you need to tell the respective build system to use the arm-linux-* cross-toolchain, not the standard host gcc/g++/ld.

For example, you can build/cross-compile simple C programs by hand like this:

$ arm-linux-gcc helloworld.c

Most Makefile based C programs can probably be built like this:

$ make CC=arm-linux-gcc

Most autoconf/automake/libtool based programs can be built like this:

$ ./configure --host=arm-linux CC=arm-linux-gcc && make

Using U-Boot via serial/TFTP to flash a kernel/uImage to NAND

In order to transfer files into the board's (DDR) RAM via U-Boot, and using TFTP (i.e., via the Ethernet connector), you'll need to setup a TFTP server on your host first:

$ apt-get install tftpd
$ mkdir /src/tftp

Every file located in /src/tftp will be accessible via TFTP. For now, copy the uImage file you built above into that directory.

Assuming you already have a U-Boot bootloader installed on the target board, you can attach a null-modem cable to the serial port and use a terminal program (e.g. minicom) on the host to connect to U-Boot. The terminal settings are 115200 8n1 per default. The minicom config file can look something like this:

$ cat /etc/minicom/minirc.tonga2
pu port             /dev/ttyS0
pu baudrate         115200
pu rtscts           No

Start minicom via:

$ minicom -o tonga2

Reset the board and then press a key in the serial terminal to prevent U-Boot from booting a kernel; instead you'll be shown the U-Boot prompt.

On the target, we'll first setup the board's IP address (192.168.0.34 here) and the IP address of your TFTP server (192.168.0.32 here), and save those settings:

U-Boot> setenv ipaddr 192.168.0.34
U-Boot> setenv serverip 192.168.0.32
U-Boot> saveenv
Saving Environment to NAND...
Erasing Nand...
Erasing at 0x60000 -- 100% complete.
Writing to Nand... done

Then, get the Linux kernel (uImage) via TFTP:

U-Boot> tftp uImage
smc911x: detected LAN9221 controller
smc911x: phy initialized
smc911x: MAC 00:11:22:44:55:66
Using smc911x-0 device
TFTP from server 192.168.0.32; our IP address is 192.168.0.34
Filename 'uImage'.
Load address: 0x40600000
Loading: #################################################################
         #################################################################
         [...]
         #######################
Bytes transferred = 2061008 (1f72d0 hex)

Then erase the "kernel" partition in the NAND flash:

U-Boot> nand erase.part kernel
NAND erase.part: device 0 offset 0x3a0000, size 0x300000
Erasing at 0x680000 -- 100% complete.
OK

Finally, write the uImage from RAM into the "kernel" partition in the NAND flash:

U-Boot> nand write ${fileaddr} kernel
NAND write: device 0 offset 0x3a0000, size 0x300000
 3145728 bytes written: OK

Note: Do not replace "${fileaddr}" with a number here, that's a U-Boot environment variable which gets automatically set to the correct value after the TFTP file transfer.

Using U-Boot via serial/TFTP to flash a root filesystem to NAND

We're assuming that you already setup a TFTP server and configured the server/client IP addresses in U-Boot (and saved them via saveenv), see above.

Now, get the root filesystem via TFTP:

U-Boot> tftp rootfs.jffs2
smc911x: detected LAN9221 controller
smc911x: phy initialized
smc911x: MAC 00:11:22:44:55:66
Using smc911x-0 device
TFTP from server 192.168.0.32; our IP address is 192.168.0.34
Filename 'rootfs.jffs2'.
Load address: 0x40600000
Loading: T #################################################################
         #################################################################
         [...]
         #################################
done
Bytes transferred = 32112640 (1ea0000 hex)

Erase the "rootfs" partition in the NAND flash:

U-Boot> nand erase.part rootfs
NAND erase.part: device 0 offset 0x6a0000, size 0xf960000
Skipping bad block at  0x05280000                                          
Skipping bad block at  0x09040000                                          
Skipping bad block at  0x0ad40000                                          
Skipping bad block at  0x0b080000                                          
Skipping bad block at  0x0caa0000                                          
Skipping bad block at  0x0ff80000                                          
Skipping bad block at  0x0ffa0000                                          
Skipping bad block at  0x0ffc0000                                          
Skipping bad block at  0x0ffe0000                                          
OK

Finally, write the rootfs.jffs2 file from RAM into the "rootfs" partition in the NAND flash:

U-Boot> nand write ${fileaddr} rootfs ${filesize}
NAND write: device 0 offset 0x6a0000, size 0x1ea0000
 32112640 bytes written: OK

Note: Do not replace "${fileaddr}" or "${filesize}" with a number here, those are U-Boot environment variables which get automatically set to the correct value after the TFTP file transfer.

Note: The root filesystem file must be smaller than roughly 60 MB (DDR RAM size is 64MB, and some of it is used by U-Boot itself).

Using U-Boot via serial/TFTP to flash an updated U-Boot to NAND

Assuming you already have a U-Boot bootloader installed on the target board, you can upgrade to another version of U-Boot like this:

First, on the host, make the U-Boot image (u-boot_nand_tonga2.bin) accessible via TFTP:

$ cp u-boot_nand_tonga2.bin /srv/tftp

Then, on the target, get the U-Boot image via TFTP:

U-Boot> tftp u-boot_nand_tonga2.bin
smc911x: detected LAN9221 controller
smc911x: phy initialized
smc911x: MAC 00:11:22:44:55:66
Using smc911x-0 device
TFTP from server 192.168.0.32; our IP address is 192.168.0.34
Filename 'u-boot_nand_tonga2.bin'.
Load address: 0x40600000
Loading: T #################################################################
         ##########
done
Bytes transferred = 379012 (5c884 hex)

Erase the "u-boot" partition in the NAND flash:

U-Boot> nand erase.part u-boot
NAND erase.part: device 0 offset 0x0, size 0x80000
Erasing at 0x60000 -- 100% complete.
OK

Finally, write the new U-Boot image from RAM into the "u-boot" partition in the NAND flash:

U-Boot> nand write ${fileaddr} u-boot
NAND write: device 0 offset 0x0, size 0x80000
 524288 bytes written: OK

Note: Do not replace "${fileaddr}" with a number here, that's a U-Boot environment variable which gets automatically set to the correct value after the TFTP file transfer.

You can now reset the board and the new U-Boot will be started from NAND flash (press a key to get into the U-Boot console):

U-Boot 2011.03 (Oct 15 2011 - 23:41:04)

DRAM:  64 MiB
NAND:  256 MiB
No dynamic environment marker in OOB block 0
Bad block table found at page 131008, version 0x01
Bad block table found at page 130944, version 0x01
nand_read_bbt: Bad block at 0x000005280000
nand_read_bbt: Bad block at 0x000009040000
nand_read_bbt: Bad block at 0x00000ad40000
nand_read_bbt: Bad block at 0x00000b080000
nand_read_bbt: Bad block at 0x00000caa0000
Net:   smc911x-0
Hit any key to stop autoboot:  0 
U-Boot>

Resetting the U-Boot environment

U-Boot stores its configuration in the u-boot_env part of the NAND flash. In order to erase that (which will revert to the built-in defaults) run this command:

U-Boot> nand erase.part u-boot_env
NAND erase.part: device 0 offset 0x80000, size 0x20000
Erasing at 0x80000 -- 100% complete.
OK

Board info

U-Boot

U-Boot> version
U-Boot 2011.03 (Oct 15 2011 - 23:41:04)
arm-linux-gcc (Buildroot 2011.11-git-00241-gbde4564) 4.6.1
GNU ld (GNU Binutils) 2.21.1
U-Boot> printenv
baudrate=115200
bootargs=console=ttyS0,115200n8 consoleblank=0 root=/dev/mtdblock4 rootfstype=jffs2 mtdparts=tmpa9xx-nand:0x00080000(u-boot),0x00020000(u-boot_env),0x00300000(splash),0x00300000(kernel),0x0f960000(rootfs) video=tmpa9xxfb:19211e4c:10040cef:013f380d:00010828 ethaddr=00:11:22:44:55:66
bootargs_base=setenv bootargs console=ttyS0,115200n8 consoleblank=0 ${rootfs} ${mtdparts} ${videoparams} ethaddr=${ethaddr}
bootcmd=run rootfs_base;run bootargs_base; nboot kernel; bootm
bootdelay=1
ethact=smc911x-0
ethaddr=00:11:22:44:55:66
ipaddr=192.168.0.34
mtddevname=u-boot
mtddevnum=0
mtdids=nand0=tmpa9xx-nand
mtdparts=mtdparts=tmpa9xx-nand:0x00080000(u-boot),0x00020000(u-boot_env),0x00300000(splash),0x00300000(kernel),0x0f960000(rootfs)
partition=nand0,0
rootfs=root=/dev/mtdblock4 rootfstype=jffs2
rootfs_base=setenv rootfs ${rootfs_jffs2}
rootfs_jffs2=root=/dev/mtdblock4 rootfstype=jffs2
rootfs_ubifs=ubi.mtd=4 root=ubi0:rootfs rootfstype=ubifs
serverip=192.168.0.32 
stderr=serial
stdin=serial
stdout=serial
update_kernel_dhcp=dhcp uImage-tonga2; nand erase.part kernel; nand write ${fileaddr} kernel
update_kernel_tftp=tftp uImage-tonga2; nand erase.part kernel; nand write ${fileaddr} kernel
update_rootfs_dhcp=dhcp rootfs       ; nand erase.part rootfs; nand write ${fileaddr} rootfs ${filesize}
update_rootfs_tftp=tftp rootfs       ; nand erase.part rootfs; nand write ${fileaddr} rootfs ${filesize}
verify=n
videoparams=video=tmpa9xxfb:4b3580c4:210a09df:031f2802

Environment size: 1603/131068 bytes
U-Boot> mtdparts
device nand0 <tmpa9xx-nand>, # parts = 5                                        
 #: name                size            offset          mask_flags              
 0: u-boot              0x00080000      0x00000000      0                       
 1: u-boot_env          0x00020000      0x00080000      0                       
 2: splash              0x00300000      0x000a0000      0                       
 3: kernel              0x00300000      0x003a0000      0                       
 4: rootfs              0x0f960000      0x006a0000      0                       
                                                                                
active partition: nand0,0 - (u-boot) 0x00080000 @ 0x00000000                    
                                                                                
defaults:                                                                       
mtdids  : nand0=tmpa9xx-nand                                                    
mtdparts: none

Bootlog

See here for a bootlog, including U-Boot and Linux kernel output.

Linux

$ uname -a
Linux buildroot 2.6.38+ #2 PREEMPT Sun Oct 16 01:00:02 CEST 2011 armv5tejl GNU/Linux
$ cat /proc/cpuinfo
Processor       : ARM926EJ-S rev 5 (v5l)
BogoMIPS        : 95.84
Features        : swp half thumb fastmult edsp java
CPU implementer : 0x41
CPU architecture: 5TEJ
CPU variant     : 0x0
CPU part        : 0x926
CPU revision    : 5

Hardware        : Tonga 2
Revision        : 0000
Serial          : 0000000000000000
$ lsusb
Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
$ mount
rootfs on / type rootfs (rw)
/dev/root on / type jffs2 (rw,relatime)
devtmpfs on /dev type devtmpfs (rw,relatime,size=30500k,nr_inodes=7625,mode=755)
proc on /proc type proc (rw,relatime)
devpts on /dev/pts type devpts (rw,relatime,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,relatime,mode=777)
tmpfs on /tmp type tmpfs (rw,relatime)
sysfs on /sys type sysfs (rw,relatime)
$ cat /proc/fb
0 CLCD FB
$ cat /proc/interrupts
           CPU0
  1:          0         VIC  tmpa9xx_rtc
  4:      58636         VIC  TMPA9xx Timer Tick
  5:          1         VIC  tmpa9xx-ts-irq
  7:          0         VIC  tmpa9xx-i2c
  8:          0         VIC  tmpa9xx-adc
 10:       8179         VIC  uart-pl011
 12:     470936         VIC  pl022
 13:          0         VIC  pl022
 16:          0         VIC  DMA
 17:     157376         VIC  DMA
 18:          0         VIC  CLCD FB
 20:          0         VIC  tmpa9xx_lcdda
 21:          1         VIC  tmpa9xx-udc
 26:          0         VIC  gpio_r
 27:          1         VIC  ohci_hcd:usb1
 28:          0         VIC  gpio_n
 29:          0         VIC  gpio_f
 30:          0         VIC  gpio_c
 31:          0         VIC  gpio_a
 44:          0        gpio  eth0
Err:          0
$ cat /proc/mtd
dev:    size   erasesize  name
mtd0: 00080000 00020000 "u-boot"
mtd1: 00020000 00020000 "u-boot_env"
mtd2: 00300000 00020000 "splash"
mtd3: 00300000 00020000 "kernel"
mtd4: 0f960000 00020000 "rootfs"
$ cat /proc/bus/input/devices
I: Bus=0019 Vendor=0000 Product=0000 Version=0100
N: Name="TMPA9xx touchscreen driver"
P: Phys=
S: Sysfs=/devices/virtual/input/input0
U: Uniq=
H: Handlers=mouse0 event0 
B: PROP=0
B: EV=b
B: KEY=400 0 0 0 0 0 0 0 0 0 0
B: ABS=1000003

Resources