2013年8月30日 星期五

Porting new defconfig from versatile_defconfig

First, you need to know that the bootloader pass two information to kernel:
1: register r0  <---- 0
     register r1 <---- machine ID   (it should exist in arch/arm/tools/mach-types and kernel will check it!)
2: parameters structure name ATAG

We copy the source code from versatile board:
$> cp -rf arch/arm/mach-versatile arch/arm/mach-neo
$> cp -rf arch/arm/plat-versatile arch/arm/plat-neo

We add our machine type in arch/arm/tools/mach-types:
$> vi arch/arm/tools/mach-types
----------------------------------------------------------------------------
neo                     MACH_NEO                NEO                    387
----------------------------------------------------------------------------

We modify arch/arm/Kconfig to add ARCH_NEO & PLAT_NEO and source them:
$> vi arch/arm/Kconfig
--------------------------
.................
config ARCH_NEO
        bool "NEO development board"
        select ARM_AMBA
        select ARM_VIC
        select CLKDEV_LOOKUP
        select HAVE_MACH_CLKDEV
        select ICST
        select GENERIC_CLOCKEVENTS
        select ARCH_WANT_OPTIONAL_GPIOLIB
        select PLAT_NEO
        select PLAT_VERSATILE_CLCD
        select PLAT_VERSATILE_FPGA_IRQ
        select ARM_TIMER_SP804
        help
          This enables support for NEO development board.
...................
config PLAT_NEO
        bool
..................
source "arch/arm/mach-neo/Kconfig"
source "arch/arm/plat-neo/Kconfig"
..................
--------------------------

We modify arch/arm/Makefile to refer to mach-neo & plat-neo if we used:
$> vi arch/arm/Makefile
-------------------------
...................
machine-$(CONFIG_ARCH_NEO)      := neo
...................
plat-$(CONFIG_PLAT_NEO)         := neo
..................
-------------------------

We also need to modify arch/arm/mach-neo/Kconfig:
$> vi arch/arm/mach-neo/Kconfig
-------------------------
menu "NEO development board platform type"
        depends on ARCH_NEO

config ARCH_VERSATILE_PB
        bool "Support NEO Platform Baseboard for ARM926EJ-S"
        select CPU_ARM926T
        select MIGHT_HAVE_PCI
        default y
        help
          Include support for the ARM(R) Versatile Platform Baseboard
          for the ARM926EJ-S.

config MACH_VERSATILE_AB
        bool "Support NEO Application Baseboard for ARM926EJ-S"
        select CPU_ARM926T
        help
          Include support for the ARM(R) Versatile Application Baseboard
          for the ARM926EJ-S.

config MACH_VERSATILE_DT
        bool "Support NEO platform from device tree"
        select USE_OF
        select CPU_ARM926T
        help
          Include support for the ARM(R) Versatile/PB platform,
          using the device tree for discovery

endmenu
-------------------------

Modify arch/arm/plat-neo/Kconfig too:
$> vi arch/arm/plat-neo/Kconfig
-------------------------
if PLAT_NEO

config PLAT_VERSATILE_CLCD
        bool

config PLAT_VERSATILE_FPGA_IRQ
        bool

config PLAT_VERSATILE_LEDS
        def_bool y if LEDS_CLASS
        depends on ARCH_REALVIEW || ARCH_NEO

config PLAT_VERSATILE_SCHED_CLOCK
        def_bool y

endif
-------------------------

Now, we can create new defconfig:
$> make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- versatile_defconfig
$> make ARCH=arm menuconfig
-------------------------
System Type  --->
    ARM system type (ARM Ltd. Versatile family)  --->
          (X) NEO development board
    NEO platform type  --->
          [*] Support NEO platform from device tree
          
Kernel Features  --->
     [*] Use the ARM EABI to compile the kernel                                            
     [*]   Allow old ABI binaries to run with this kernel (EXPERIMENTAL) (NEW) 
-------------------------
$> cp .config arch/arm/configs/neo_defconfig

We can make zImage by using our new defconfig:
$> make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- neo_defconfig
$> make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- zImage
$> make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- versatile-pb.dtb

Emulator:
$> qemu-system-arm -M versatilepb -dtb ./versatile-pb.dtb -kernel zImage -initrd rootfs.img -serial stdio -append "root=/dev/ram rdinit=/sbin/init  console=ttyAMA0"


PS:
1 You can install QEMU in UBUNTU by:
$> sudo apt-get install qemu qmeu-kvm-extras
2 "CROSS_COMPILE=arm-none-linux-gnueabi-" depends on your toolchain.
3 rootfs.img.gz can be found in my old post named "Build Rootfs by Busybox for ARM on QEMU"
4 You can see versatile-pb.dts in path arch/arm/boot/dts
5 Because we use "-M versatilepb" to emulate, the machine type in  arch/arm/tools/mach-types should be 387.

Emulate Vexpress-a15 board on QEMU .............. (using Device Tree)

Download Linux Kernel 3.45 first:
$> wget https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.4.45.tar.bz2
$> tar xvf linux-3.4.45.tar.bz2

Configure:
$> make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- vexpress_defconfig
$> make ARCH=arm menuconfig
------------------------------------------------------------------------------------------------------------
System Type  --->
     Versatile Express platform type  --->
          [*] Device Tree support for Versatile Express platforms
------------------------------------------------------------------------------------------------------------
Now we can build zImage:
$> make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- zImage
Build dtb:
$> make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- vexpress-v2p-ca15-tc1.dtb
Emulate:
$> qemu-system-arm -M vexpress-a15 -serial stdio -dtb ./vexpress-v2p-ca15-tc1.dtb -kernel zImage -initrd rootfs.img -append "root=/dev/ram rdinit=/sbin/init  console=ttyAMA0"



PS:
1 You can install QEMU in UBUNTU by:
$> sudo apt-get install qemu qmeu-kvm-extras
2 "CROSS_COMPILE=arm-none-linux-gnueabi-" depends on your toolchain.
3 rootfs.img.gz can be found in my old post named "Build Rootfs by Busybox for ARM on QEMU"
4 You can see vexpress-v2p-ca15-tc1.dts in path arch/arm/boot/dts

Emulate VersatilePB board on QEMU

Download Linux Kernel 3.45 first:
$> wget https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.4.45.tar.bz2
$> tar xvf linux-3.4.45.tar.bz2

Configure:
$> make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- versatile_defconfig
$> make ARCH=arm menuconfig
------------------------------------------------------------------------------------------------------------

Kernel Features  --->
     [*] Use the ARM EABI to compile the kernel                                          
     [*]   Allow old ABI binaries to run with this kernel (EXPERIMENTAL) (NEW)

------------------------------------------------------------------------------------------------------------
Now we can build zImage:
$> make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- zImage
Emulate:
$> qemu-system-arm -M versatilepb -m 128M -kernel arch/arm/boot/zImage -initrd ../rootfs.img.gz -append "root=/dev/ram rdinit=/sbin/init"



PS:
1 You can install QEMU in UBUNTU by:
$> sudo apt-get install qemu qmeu-kvm-extras
2 "CROSS_COMPILE=arm-none-linux-gnueabi-" depends on your toolchain.
3 rootfs.img.gz can be found in my old post named "Build Rootfs by Busybox for ARM on QEMU"

Build Rootfs by Busybox for ARM on QEMU

Download busybox first:
$> wget http://busybox.net/downloads/busybox-1.21.1.tar.bz2
$> tar xvf busybox-1.21.1.tar.bz2

Configure:
$> make menuconfig
------------------------------------------------------------------------------------------------------------
Busybox settings --> Build option
                                     "Build busybox as a static binary"
                           --> cross compiler prefix
                                      "arm-none-linux-gnueabi-"                       <----Depends on your cross_compiler
------------------------------------------------------------------------------------------------------------
$> make
$> make install
Now we can build rootfs.img:
$> cd _install
$> mkdir proc sys dev etc etc/init.d
$> cat << EOF > etc/init.d/rcS
#!/bin/sh
mount -t proc none /proc
mount -t sysfs none /sys
/sbin/mdev -s
EOF
$> chmod +x etc/init.d/rcS
$> find . | cpio -o --format=newc > ../rootfs.img
Create rootfs.img.gz:
$> cd ..
$> gzip -c rootfs.img > rootfs.img.gz