PM9G45-U-BOOT-LINUX-YOCTO

From Ronetix's Wiki
Revision as of 19:48, 16 August 2020 by Ilko (talk | contribs) (Initial import)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
File:Pm9g45 top.png

PM9G45 User's Manual and Schematics

The User's Manual and the schematics of PM9G45 can be found here:

Before you start

The instructions in this document are meant to be done under GNU/Linux environment.


Connecting to the board

A serial terminal connection through RS-232 null modem cable is needed to control U-Boot and GNU/Linux.

To set up U-Boot run time a serial terminal connection must be used, this is the only way you can get access to the U-Boot command line. The Linux boot messages are transmitted to the same serial connection.

The Serial Debug interface is set to 115200 bps with 8 data bits, one stop bit and no parity. Use the screen command like this

"screen /dev/ttyS0 115200 cs8,-cstopb,-parenb"

or

minicom

Networking

As tftp or ftp servers are needed call your system/network administrator to give you the settings. The IP address can be obtained using DHCP service or set static IP.

After the IP address is set and know, a link to the board running GNU/Linux can be made with telnet.

Toolchain

Description

The GNU Toolchain, is a combination of multiple projects:

GCC
GCC stands for "GNU Compiler Collection". GCC is an integrated distribution of compilers for several major programming languages. These languages currently include C, C++, Objective-C, Objective-C++, Java, Fortran, and Ada.
Binutils
GNU Binutils are a collection of binary tools. The main ones are: the GNU linker (ld) and the GNU assembler (as).
Debugger
GNU debugger, allows you to see what is going on `inside’ another program while it executes -- or what another program was doing at the moment it rashed.

Ronetix provides several GNU toolchains

The recommded one is "KaeilOS v2010.1 SDK".

  • KaeilOS v2010.1 SDK at kaeilos-2010.1/
  • ronetix-arm-elf-4.4.1.tar.bz2 - gcc 4.4.1, newlib, ARM, Cortex
  • ronetix-arm-linux-4.3.3.tar.bz2 - gcc 4.3.3, glibc
  • ronetix-arm-linux-uclibc-4.1.2.tar.bz2 - gcc 4.1.2, uclibc
  • ronetix-gnutools-arm-elf-4.1.1-linux.tar.bz2 - gcc 4.1.1, newlib
  • ronetix-toolset-arm-elf-4.1.1-windows.exe - gcc 4.1.1, newlib, for Windows
  • openzaurus-arm-linux-glibc-3.4.4.tar.bz2 - gcc 3.4.4, glibc
  • ronetix-gnutools-arm-elf-3.2.1-linux.tar.bz2 - gcc 3.2.1, newlib

GNU toolchain notes

The pre-built GNU toolchains can be found http://download.ronetix.at/toolchains/arm/

Linux
The Linux kernel reqires a minimal GCC version in order to compile. To check that minimal version take a look at the README file in the Linux source directory.
U-Boot
U-Boot can not be compiled with some toolchains because of (E)ABI conformation. The USE_PRIVATE_LIBGCC parameter allows the usage of different run-time support library(libgcc.a). More on using this parameter see README in U-Boot source


Download and install the GNU toolchain

Installation of "KaeilOS v2010.1 SDK"

This is SDK produced by OpenEmbedded recipes. It includes and package management system opkg. It includes development sources form the packages in KaeilOS. Download the two files and extract them in the "/" directory. They could be extracted in any directory, and then the file "<work directory>/usr/local/kaeilos/arm/environment-setup" have to be edited and prefix the "SDK_PATH" value with the "work directory". And also remove the line which sets the CPATH environment.

Before compiling execute:

$ . <work directory>/usr/local/kaeilos/arm/environment-setup

The toolchain prefix is "arm-oe-linux-gnueabi-".

$ wget http://download.ronetix.at/toolchains/arm/kaeilos-2010.1/kaeilos-2010.1-20110221-i686-linux-armv5te-linux-gnueabi-toolchain-extras.tar.bz2
$ wget http://download.ronetix.at/toolchains/arm/kaeilos-2010.1/kaeilos-2010.1-20110221-i686-linux-armv5te-linux-gnueabi-toolchain.tar.bz2
$ su -
$ tar -C / -xjf kaeilos-2010.1-20110221-i686-linux-armv5te-linux-gnueabi-toolchain-extras.tar.bz2 
$ tar -C / -xjf kaeilos-2010.1-20110221-i686-linux-armv5te-linux-gnueabi-toolchain.tar.bz2
$ exit
$ . /usr/local/kaeilos/arm/environment-setup
$ echo '#include <stdio.h>
int main(int argc, char** argv) {
   printf("Hello World!\n");
   return 0;
  }
 ' > hello.c
$ arm-oe-linux-gnueabi-gcc hello.c -o hello

The rest of the toolchains

The toolchains will be installed in the /usr/cross directory.

$ wget http://download.ronetix.at/toolchains/arm/ronetix-arm-linux-4.3.3.tar.bz2
$ su -
$ cd /
$ tar xvfj ronetix-arm-linux-4.3.3.tar.bz2
$ exit

Setup the path:

$ export PATH=/usr/cross/arm-linux-4.3.3/bin:$PATH

AT91BootStrap

Download AT91BootStrap image file

$ wget http://download.ronetix.info/boards/linux/bootstrap/nandflashboot/pm9g45-nandflashboot-2.13.bin

Installing and building AT91BootStrap 2.13

$ wget http://download.ronetix.info/boards/linux/bootstrap/nandflashboot/at91bootstrap-2.13-src-pm9g45-svn-r370.tar.bz2
$ tar xjvf at91bootstrap-2.13-src-pm9g45-svn-r370.tar.bz2
$ cd at91bootstrap-2.13-pm9g45-svn-r370
$ export ARCH=arm
$ export CROSS_ARCH=arm-elf- # or put your ARM toolchain prefix
$ make clean
$ make pm9g45_defconfig
$ make

The file is binaries/pm9g45-nandflashboot-2.13.bin

Installing and building AT91BootStrap 3.8.12

$ git clone git://github.com/linux4sam/at91bootstrap.git
$ cd at91bootstrap
$ wget http://download.ronetix.info/boards/linux/bootstrap/nandflashboot/AT91Bootstrap-3.8.12/patches/*
$ git checkout -b v3.8.12 v3.8.12
$ git am 0001-at91sam9m10g45eknf_uboot_defconfig-Modify-load-addre.patch
$ git am 0001-Makefile-generate-build-date-always-in-english.patch
$ git am 0003-main.c-add-target-memory-test.patch
$ git am 0004-Do-not-configure-CPU-clock-if-it-is-already-done-by-.patch
$ make at91sam9m10g45eknf_uboot_defconfig
$ make

The file is binaries/at91sam9m10g45ek-nandflashboot--3.8.12.bin

Programming AT91BootStrap

Since the U-boot can not fit in the first NAND block, PM9G45 uses AT91BootStrap for initial startup. The file nandflash_pm9g45.bin must be programmed at address 0x0.

Using PEEDI

peedi> flash select 1
peedi> flash program pm9g45-nandflashboot-2.13.bin BIN 0x0 erase

Using U-Boot

u-boot> tftp 0x70000000 pm9g45-nandflashboot-2.13.bin
u-boot> nand erase 0x0 0x4000
u-boot> nand write 0x70000000 0x0 0x4000


U-BOOT

Short introduction

U-BOOT is used for basic initialization of the boards and for loading and starting an Operating system or an user application. The loading can be done via the various FLASH devices or the Ethernet.

U-BOOT supports the following devices on the board:

  • NOR Flash
  • Dataflash
  • NAND flash
  • Ethernet
  • LCD
  • USB

Download and install the U-BOOT

PM9G45 is supported by the mainline U-BOOT.

Alternatively, u-boot-2010.09 + patches can be used.

Get U-Boot as tar.bz2

$ wget http://download.ronetix.at/boards/linux/bootloader/u-boot-2010.09/u-boot-2010.09.tar.bz2
$ tar xjf u-boot-2010.09.tar.bz2
$ mv u-boot-2010.09 u-boot
$ cd u-boot
$ git init
$ git add *
$ git add .gitignore
$ git commit -m "U-Boot v2010.09"
$ git checkout -b v2010.09-pm9g45
$ cd ..

Get U-Boot with git clone

For easy code management(trace and history of changes, patch submit and so) it is good to use revision control(in this case GIT). To get U-Boot using git, if you prefer tar.bz2 skip getting U-Boot using git.

$ git clone git://git.denx.de/u-boot.git u-boot
$ cd u-boot
$ git checkout -b v2010.09-pm9g45 v2010.09
$ cd ..


Apply the provided patches

$ wget http://download.ronetix.info/boards/linux/bootloader/u-boot-2010.09/patches/u-boot-2010.09-patches-ronetix-13012012.tar.bz2
$ tar xjvf u-boot-2010.09-patches-ronetix-13012012.tar.bz2
$ cd u-boot
$ for N in ../u-boot-2010.09-ronetix-13012012/*.patch ;do git am $N ; done

Configuration

The U-Boot configuration files named as the respective Ronetix CPU modules are:

  • include/configs/pm9g45.h
  • include/configs/pm9263.h
  • include/configs/pm9261.h

The definitions in these header files are explained in the README file in the U-Boot source.

If needed set the lines for the network interface as show. In the config files only the ETHADDR is set, the rest parameters can be obtained runtime in the U-Boot prompt by invoking the command "dhcp".

#define CONFIG_ETHADDR		02:00:00:FE:ED:01
#define CONFIG_IPADDR		192.168.3.222
#define CONFIG_NETMASK		255.255.255.0
#define CONFIG_GATEWAYIP	192.168.3.1
#define CONFIG_SERVERIP	192.168.3.1
#define CONFIG_OVERWRITE_ETHADDR_ONCE /* Read Using it! */

These parameters can be modified later and set to a environment variables, except "ethaddr".

If you do not want LCD support, comment as shown:

/* No need of LCD
* #define	CONFIG_LCD			1
*/

You may leave the configs as they are, test and then change as needed.

Configure and build

$ make pm9g45_config

The common part for all boards:

$ export USE_PRIVATE_LIBGCC=yes
$ export CROSS_COMPILE=arm-oe-linux-gnueabi-
$ export ARCH=arm
$ make

The binary file for programming is u-boot.bin, and the u-boot is the elf file.

When building U-Boot, the mkimage is also build. This utility is needed to wrap zImage(Linux kernel) for booting by U-Boot, so put it in a place mentioned by PATH environment.


Programming U-Boot for PM9G45

The file u-boot.bin must be programmed in the NAND FLASH at address 0x20000.

Using PEEDI

peedi> flash set 1
peedi> fflash program pm9g45_bb9g45_u-boot.bin BIN 0x20000 erase

Using U-Boot

u-boot> tftp 0x70000000 pm9g45_bb9g45_u-boot.bin
u-boot> nand erase 0x20000 $filesize
u-boot> nand write 0x70000000 0x20000 0x40000


Linux kernel

Getting and unpacking the Linux kernel for PM9G45

$ wget http://download.ronetix.info/boards/linux/kernel/2.6.30/linux-2.6.30.tar.bz2
$ wget http://download.ronetix.info/boards/linux/kernel/2.6.30/patches/2.6.30-at91.patch.gz
$ wget http://download.ronetix.info/boards/linux/kernel/2.6.30/patches/2.6.30-at91-exp.5.tar.gz
$ wget http://download.ronetix.info/boards/linux/kernel/2.6.30/patches/2.6.30-at91-exp.5-patches-pm9g45-09122011.tar.bz2
$ tar xjf linux-2.6.30.tar.bz2
$ gunzip 2.6.30-at91.patch.gz
$ tar xzf 2.6.30-at91-exp.5.tar.gz
$ tar xjf 2.6.30-at91-exp.5-patches-pm9g45-09122011.tar.bz2
$ cd linux-2.6.30
$ git init
$ git add *
$ git add .gitignore .mailmap
$ git commit -m "Initial commit after linux-2.6.30.tar.bz2 extraction"
$ git checkout -b 2.6.30-at91.patch
$ patch -p1 < ../2.6.30-at91.patch
$ git add -u
$ git add *
$ git commit -m "patching with 2.6.30-at91.patch"
$ git checkout -b 2.6.30-at91-exp.5
$ for N in ../2.6.30-at91-exp.5/*.patch; do git am $N ; done
$ git checkout -b pm9g45
$ for P in ../2.6.30-at91-exp.5-patches-pm9g45-09122011/*.patch ;do git am $P ; done

Kernel config

$ make pm9263_defconfig

To carry into effect the default kernel configuration you have to do the following.

Common for all boards:

$ export ARCH=arm
$ make pm9g45_v1.3-bb9g45_v1.1_defconfig


Kernel build

uImage is the Linux kernel packed(U-Boot wrapped zImage) in format for loading by U-Boot. The "mkimage" utility which is part of U-Boot is required to be in the executable search path(environment variable PATH).

The "mkimage" can be taken from http://download.ronetix.at/boards/tools/linux/mkimage or obtained after building U-Boot for an ARM board.

$ echo Make sure "mkimage" is in the executable search path!
$ export CROSS_COMPILE=arm-oe-linux-gnueabi-
$ make uImage

The binary file for programming is arch/arm/boot/uImage.


Programming of the Kernel for PM9G45

Using PEEDI

peedi> flash select 2
peedi> flash program uImage bin 0x200000 erase

Using U-BOOT

u-boot> tftp 0x70000000 uImage
u-boot> nand erase clean 0x200000 0x200000
u-boot> nand write.jffs2 0x70000000 0x200000 0x200000


OpenEmbedded

The OpenEmbedded has been undergoing reorganizations since 2011. All the recipes were on one place, which has caused maintenance issues and fragility. Several clone of OE, like Poky and Yocto Project, were started to fix this. And now, to consolidate forces Yocto and OE are merging in the new OpenEmbedded with layers. The OE before changes is named OpenEmbedded-classic. It is still alive. Its recipes are transferring to the layer structure. The layer structure is still on intensive development process. This readme covers the OpenEmbedded-classic.

Preparation

First you need to prepare your host Linux distribution in order to be able to get and build KaeilOS. A list of required packages for variety of host distributions is described in:

Lets prepare directory structure. Login on your host as ordinary user not as root(root privileges are not needed and a good practice is to avoid being root if not needed). You can login as a user you like. Starting point is being in the home directory. You may choose working directory at your decision, but be aware of the paths.

Make directory for doing things and go to it:

$ cd
$ mkdir -p usr/src/oe
$ cd usr/src/oe

Now it is time to get bitbake - the building tool. All thing here are done with bitbake version 1.10.2. And don't install bitbake globally, install it as a sibling directory of openembedded/ and build/.

$ git clone git://git.openembedded.org/bitbake.git
$ cd bitbake
$ git pull
$ git checkout -b _tag_1.10.2 1.10.2


Getting openembedded - meta data, packages, relations and more

Get it, go to directory openembedded/ and update.

$ git clone git://git.openembedded.org/openembedded
$ cd openembedded

Since KaelOS distribution will be used, check out a tested OE metadata.

$ git checkout -b kaeilos-2011 origin/mckoan/kaeilos-2011

As the OE is developing continuously sometimes the OE can not be build successfully so you can keep updating OE until it builds or use a build verified state(commit). The latest stable states can be found at http://www.kaeilos.com/latest-changes.


Warning: even the tested OpenEmbedded/Bitbake metadata state after "some" time the build process can not produce the desired images and fail, due to URL sources are not available, most probably a new version of that resource, and the old one have been removed. Also there is recipes referring to a source in a svn, git or other repositories, which at the build time could be in broken state.


Get KaeilOS settings and configuration files

$ wget ftp://ftp.koansoftware.com/public/kaeilos/kaeilos-4.11-config-files.tgz
$ tar xzvf kaeilos-4.11-config-files.tgz

Get custom-extra-image.bb recipe file and save it in $OEBASE/openembedded/recipes/images:

$ wget http://download.ronetix.at/boards/linux/rootfs/custom-extra-image.bb -O openembedded/recipes/images/custom-extra-image.bb

Edit the files listed below so that they contains the correct paths. Use the absolute path:

  • in file setup-kaeilos.sh adjust the paths
  • in build/kaeilos/conf/auto.conf you can select the machine to

build KaeilOS for. The default machine is "ronetix-pm9263", to build for pm9g45 change the name "ronetix-pm9263" to "ronetix-pm9g45", and if the case is pm9261 use "ronetix-pm9261"

  • in build/kaeilos/conf/local.conf remove "ext2" parameter in

IMAGE_FSTYPES. Change the SCREEN_TERMCMD to 'xterm -e'.

  • in build/kaeilos/conf/site.conf adjust the paths, select

a Debian mirror near you for higher download speed and in the Debian mirror remove the "pub/" part, also.


Initial building of the system

You should be in $OEBASE directory. Running this command for the first time will take a some hours to finish:

$ source setup-kaeilos.sh /home/ivan/usr/src/oe/build/kaeilos
$ bitbake custom-extra-image

Warning: custom-extra-image.bb is recipe example, it is useful to to demonstrate how to add stuff you like/want. It is build-able with the OpenEmbedded/Bitbake latest metadata state mentioned at "2. Getting openembedded - meta data, packages, relations and more". Doe to continuous change/improvement of OE there could be a time when some packages included in the custom-extra-image.bb are not build-able, and the items in the custom-extra-image.bb have to be adopted. The "x11-image", "console-image" and "console-base-image" are general for OE.

Warning: even the tested OpenEmbedded/Bitbake metadata state after "some" time can not produce the desired images, due to URL sources are not available, most probably a new version, and the old one is removed. Example of this is missing live.2010.10.15.tar.gz from recipe live555_20101015.bb. Also there is recipes referring to a source in a svn, git or other repositories, which at the build time could be with broken sources like mplayer.

This initial system building is to let the OpenEmbedded build the system as it is by default, and later you can customize it.

Note that toolchains installation is not required as the OE makes it. There is an option to tell OE to use external toolchains.

AT91Bootstrap

AT91Bootstrap for PM9G45 is configured and build automatically. The image to program is in the deploy directory.

~/usr/src/oe/build/kaeilos/tmp/deploy/eglibc/images/ronetix-pm9g45/at91bootstrap.bin

For more details refer to AT91Bootstrap README.


U-Boot

U-Boot for PM9G45 is configured and build automatically. The image to program is in the deploy directory.

~/usr/src/oe/build/kaeilos/tmp/deploy/eglibc/images/ronetix-pm9g45/u-boot-ronetix-pm9g45.bin

For more details refer to U-Boot README.

Kernel configuring

Go to $OEBASE/build/kaeilos to configure and build your linux kernel:

$ cd $OEBASE/build/kaeilos
$ bitbake virtual/kernel -c menuconfig


Kernel building

Next comes to compile, populate stage directory, install the kernel. Executing these task will compile kernel and modules, make head files to be in the stage directory and finally copy kernel and modules to $DEPLOY directory.

$ bitbake virtual/kernel -c compile -f
$ bitbake virtual/kernel


RootFS building

To create RootFS go to $OEBASE/build/kaeilos:

$ cd $OEBASE/build/kaeilos
$ bitbake custom-extra-image

The RootFS image is in the $DEPLOY directory. This is the image you should program into the NAND Flash of PM9G45:

KaeilOS-custom-extra-image-glibc-ipk-2010.1-20110223-ronetix-pm9g45.rootfs.jffs2


Export SDK

Creating a toolchain(SDK) is the same as creating a rootfs image. From the $OEBASE directory:

$ source setup-kaeilos.sh /home/ivan/usr/src/oe/build/kaeilos
$ bitbake meta-toolchain

and the resulted SDK is in $DEPLOY directory.

For reference:

ROOTFS programming into the NAND flash for PM9G45

Using PEEDI

peedi> flash set 3
peedi> flash erase
peedi> flash program rootfs.jffs2 bin 0x500000

Using U-BOOT

Caution: the RootFS image larger than 126MiB can't be programmed by U-BOOT, because it doesn't fit in the SDRAM.

u-boot> tftp 0x70000000 rootfs.jffs2
u-boot> nand erase clean 0x500000 $filesize
u-boot> nand write.jffs2 0x70000000 0x500000 $filesize

Note: Here the variable $filesize can be used because the jffs2 image file is padded to the page size of the NAND, but the sizes of uImage, U-Boot and AT91Bootstrap are not write-page padded(but can be made to be write-page padded).

Tips and tricks

In /etc/defaul/psplash add "--angle 90" in psplash arguments variable, so that splash screen is rotated properly.

Enable/Disable mouse pointer in X

In /etc/matchbox/session find the line starting with "exec matchbox-window-manager" and change to "-use_cursor no" or to "-use_cursor yes" to hide or show mouse pointer.

To rotate X display properly you can execute this from the command line

Take a look at /etc/X11/xorg.conf in Section "Device", and add or change the Option "Roatate", like this:

Option          "Rotate" "CCW"

Adjusting touchscreen axes, in 'Section "InputDevice"' modify or add:

Option          "SwapAxes" "True"
Option          "InvertX" "True"
Option          "InvertY" "True"

Getting eth0 gateway parameter from dhcp

In /etc/network/interface add "iface eth0 inet dhcp" before "iface eth0 inet static" line.

Form the command line call "udhcpc" or "dhclient eth0" to set network through DHCP server.

Calibrating the touchscren

  • From a terminal using keyboard on USB port, run "ts_calibrate"
  • In GPE from Settings/Screen Setting press the "start" button in the calibration section.

A text from "http://comments.gmane.org/gmane.comp.handhelds.openembedded/32629" with title "[oe] Handling different touchscreen calibration systems"

Develop

Compiling a simple GNU/Linux application

Create a text file example.c with contents:

--- example.c ---
#include <stdio.h>
int main(int argc, char** argv){
  printf("Hello world\n");
  return 0;
}
--- example.c ---

Compiling: Substitute "arm-oe-linux-gnueabi-gcc" with the toolchain used to build kernel and root file system utilities.

$ arm-oe-linux-gnueabi-gcc -o example example.c

The result is the ELF file called "example".


Transferring the executable file from the PC to the target

Using USB stick

The simples way is to use a USB stick - just copy the file example to a USB stick inserted into your PC. Unmount the stick and put it into the target board. After few seconds the USB stick will be discovered(most probably). You should have support of the file system on the USB stick, most probably it will be VFAT(FAT32). Take a look at the kernel messages to see the device node of your USB stick.

Depending auto-mounter is enabled and installed on the rootfs, the USB stick could be automatically mounted. To see if it is automatically mounted:

On target machine mount /dev/sda1 on /media/sda1

In case it is not mounted automatically:

On target machine:

$ mkdir /mnt/sda1
$ mount /dev/sda1 /mnt/sda1 -t vfat
$ cp /mnt/sda1/main .
$ chmod +x main
$./main
Hello world

Tftp over network

A tftp server should work on a host(or any development) computer.

On host:

$ cp hello tftp_boot_dir/

On target machine:

$ udhcpc
$ tftp -g -r tftp_boot_dir/hello -l hello 192.168.3.1
$ chmod u+x hello
$ ./hello
Hello world

Alternatively to the "udhcpc" you can use "dhclient eth0".


Kernel debugging

The board should be programmed with the u-boot and the binary version of the kernel.

Start gdb/insight:

$ arm-oe-linux-gnueabi-gdb vmlinux

In the console window:

(gdb) target remote peedi_ip:2000
(gdb) set $pc = 0x10000040	; the u-boot is flashed at 0x10000000 (after remap)
(gdb) c

The board is running: first starts the u-boot, then the Linux kernel. If you have a serial console you can see that the Linux is working. Now you can halt the kernel and set breakpoints where you want.

If you want to have a breakpoint before the kernel is running you have to do the following:

(gdb) target remote peedi_ip:2000
(gdb) set $pc = 0x10000040	; assuming the u-boot is flashed at 0x10000000
(gdb) hbreak start_kernel	; hardware breakpoint is used because the MMU is still not active
(gdb) c

The board is running (u-boot, then the kernel) and will stop at the start_kernel function.

(gdb) delete	; delete the hardware breakpoint.

Now you can use the software breakpoints.


pre-built images

U-Boot
http://download.ronetix.info/boards/linux/bootloader/u-boot-2010.09/pm9263_u-boot.bin
Linux Kernel
http://download.ronetix.info/boards/linux/kernel/2.6.28/uImage-2.6.28-r12-ronetix-pm9263.bin
RootFS
http://download.ronetix.info/boards/linux/rootfs/2.6.28-pm9263/KaeilOS-console-image-glibc-ipk-2009.1-test-20090909-ronetix-pm9263.rootfs.jffs2