[GUIDE] Re-building the kernel(3.7.8) and U-Boot (2013.01)

This forum is for Marvell Kirkwood devices such as the GoFlex Home/Net, PogoPlug v1/v2, SheevaPlug, and ZyXEL devices.

[GUIDE] Re-building the kernel(3.7.8) and U-Boot (2013.01)

Postby medve540 » Sun Feb 17, 2013 7:16 pm

This guide is about building the latest Linux kernel and U-Boot for Dreamplug. I am writing this, because GlobalScale gives outdated software for Dreamplug and currently there is no single document exists for putting all the latest stuff together.

Table of contents

  1. Requirements
  2. What will/will not be working?
  3. Linux kernel
    1. Compiling
    2. Install kernel and modules
  4. U-Boot
    1. Compiling
    2. Install to SPI flash
    3. Setup environment
  5. Enable features
    1. Bluetooth
      1. Turning the LED on/off using systemd
    2. U-Boot environment variables in linux
  6. Download compiled binaries
  7. References



1. Requirements

I am going with the cross compilation method, because compiling on the plug takes few hours and it could be problematic to re-compile after every change of the configuration. Open up a terminal and let's begin.

You will need an ARM compiler toolchain to do this. I recommend arm-linux-gnueabi-gcc[1], so search for it and install with your package manager.
Also you will need to install the so called build essentials. On debian-based systems
Code: Select all
apt-get install build-essential
and on Arch
Code: Select all
pacman -S kernel26-headers file base-devel abs
will do the trick.
For installing the latest U-Boot you will need the JTAG developer kit from GlobalScale and get OpenOCD utility installed.
It is optional, but to deploy the binaries on Dreamplug the easy way I recommend installing netcat utility.

Setting up the root file-system can be done according to the Quick start guide PDF putting your favorite distro on it.
There is one exception: the latest U-Boot can handle ext2 filesystem, so you may want to format the /boot partition to ext2.



2 What will/will not be working?

  • [WORKING] Linux kernel 3.7.8 with Flattened Device Tree (FDT) support[4]
  • [WORKING] The latest Arch Linux ARM as OS
  • [WORKING] Networking via. Gigabit Ethernet
  • [WORKING Audio playback
  • [WORKING] USB mass storage device (external HDDs)
  • [WORKING] Controlling LEDs
  • [NOT TESTED] eSATA ports
  • [NOT TESTED] SD card socket
  • [NOT WORKING] WIFI AP mode
  • [NOT WORKING] WIFI client mode



3 Linux kernel
[3][4]
Grab and unpack the source code:
Code: Select all
wget http://www.kernel.org/pub/linux/kernel/v3.0/linux-3.7.8.tar.bz2
tar xvfj linux-3.7.8.tar.bz2

Here is my .config file which is only for the Dreamplug. Wireless and audio drivers set as modules, others features will be built into the kernel image. Of course it can be or should be changed to meet your needs.
Code: Select all
wget http://pastebin.com/raw.php?i=Z0MicyJ3 -O linux-3.7.8/.config



3.1. Compiling
[3][4]
Code: Select all
cd linux-3.7.8
export ARCH=arm
export CROSS_COMPILE=arm-linux-gnueabi-
make oldconfig
make menuconfig  # Can be skipped if you don not want to change the configuration
make all
make uImage
mkdir -p modules_install
sudo make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- INSTALL_MOD_PATH=modules_install/ modules_install
sudo tar cfz modules-3.7.8-dreamplug.tar.gz -C modules_install/ .



3.2. Install kernel and modules
[4]
Terminal for your computer is represented as user@dev and Dreamplug as root@dreamplug in command lines below:
Code: Select all
user@dev$ netcat -l -p 6666 < arch/arm/boot/uImage
root@dreamplug /boot# netcat 10.42.54.158 6666 > uImage-3.7.8
root@dreamplug /boot# rm uImage
root@dreamplug /boot# ln -s uImage-3.7.8 uImage
user@dev$ netcat -l -p 6666 < arch/arm/boot/kirkwood-dreamplug.dtb
root@dreamplug /boot# netcat 10.42.54.158 6666 > kirkwood-dreamplug.dtb

user@dev$ netcat -l -p 6666 < modules-3.7.8-dreamplug.tar.gz
root@dreamplug /boot# netcat 10.42.54.158 6666 > modules-3.7.8-dreamplug.tar.gz
root@dreamplug /boot# cd /tmp/
root@dreamplug /tmp# tar xvfz /boot/modules-3.7.8-dreamplug.tar.gz .
root@dreamplug /tmp# cp -R lib/modules/3.7.8-dreamplug/ /lib/modules



4.1. Compiling

Code: Select all
cd u-boot-2013.01
export ARCH=arm
export CROSS_COMPILE=arm-linux-gnueabi-
make dreamplug_config
make all
make u-boot.kwb



4.2. Install to SPI flash
[4]
Prepare the JTAG developer kit according to the User guide.
Install and start TFTP server (tftpd) and issue
Code: Select all
cp u-boot.kwb /srv/tftp/u-boot.kwb


Terminal1:
Code: Select all
cd /path/to/u-boot_build_dir
make u-boot.elf
mv u-boot.elf uboot.elf
openocd -f /usr/share/openocd/scripts/board/sheevaplug.cfg


Terminal2:
Code: Select all
telnet localhost 4444
reset ; init ; sheevaplug_load_uboot


Terminal3:
Instead of screen, minicom can be used as well.
Code: Select all
screen /dev/ttyUSB0 115200
Marvell>> setenv ipaddr 192.168.1.2
Marvell>> setenv serverip 192.168.1.1
Marvell>> tftpboot 0x6400000 u-boot.kwb
Marvell>> sf probe 0
Marvell>> sf erase 0x0 0x100000
Marvell>> sf write 0x6400000 0x0 0x2fd74
Where "0x2fd74" is the size of u-boot.kwb image.




4.3. Setup environment
[2]
Code: Select all
Marvell>> setenv x_bootcmd_fdt ext2load usb 0 0xd000000 kirkwood-dreamplug.dtb
Marvell>> setenv x_bootcmd_kernel ext2load usb 0 0x6400000 uImage
Marvell>> setenv bootcmd '${x_bootcmd_usb}; ${x_bootcmd_kernel}; ${x_bootcmd_fdt}; setenv bootargs ${x_bootargs} ${x_bootargs_root}; bootm 0x6400000 - 0xd000000;'
Marvell>> saveenv
Marvell>> reset



5.1. Bluetooth
[4]
Installing and enabling the service:
Code: Select all
pacman -S bluez
systemctl enable bluetooth.service

Currently two drivers provides support for Marvell Bluetooth devices 8688/8787/8797 are libertas_sdio and btmrvl_sdio. For some reason or another they are in conflict with each other so libertas module should be disabled:
Code: Select all
nano /etc/modprobe.d/blacklist.conf
# add lines:
# Do not load, because it conflicts with btmrvl_sdio driver.
blacklist libertas_sdio

On the other hand it requires binary firmware from marvell. The file sd8688.bin and sd8688_helper.bin are used by btmrvl module and must be available under /lib/firmware directory. If they are missing you will see an error message in dmesg output. To solve this first install linux-firmware package, then create symlinks for them like this:
Code: Select all
cd /lib/firmware
ln -s libertas/sd8688.bin sd8688.bin
ln -s libertas/sd8688_helper.bin sd8688_helper.bin



5.1.1. Turning the LED on/off using systemd

This will turn on the blue LED of the Dreamplug when bluetooth.service is started at boot time. Put the following text into bluetooth-led.service file under /etc/systemd/system directory.
[Unit]
Description=Bluetooth LED service
Requires=bluetooth.service
After=bluetooth.service

[Service]
Type=oneshot
ExecStart=/bin/bash -c 'echo "timer" > /sys/class/leds/dreamplug\:blue\:bluetooth/trigger; echo "1300" > /sys/class/leds/dreamplug\:blue\:bluetooth/delay_off'
RemainAfterExit=yes

ExecStop=/bin/bash -c 'echo "none" > /sys/class/leds/dreamplug\:blue\:bluetooth/trigger'

[Install]
WantedBy=bluetooth.target


If you want to get the LED service started after manually starting bluetooth.service then do the following:
Code: Select all
cp /usr/lib/systemd/system/bluetooth.service /etc/systemd/system
nano /etc/systemd/system/bluetooth.service
# append the next line to the [Install] section:
# Also=bluetooth-led.service
systemctl restart bluetooth.service



5.2. U-Boot environment variables in linux

It is possible to read and write U-Boot environment variables in linux. To do this first install uboot-envtools package, then configure it like this:
Code: Select all
nano /etc/fw_env.config

# MTD device name Device offset Env. size Flash sector size
/dev/mtd1 0x0000 0x1000 0x1000




6. Download compiled binaries

If you just want to give a try without building from source code, you can download the binaries from here:
http://ubuntuone.com/33ble0BR5FRhYNWU5uTwTv


7. References

[1] http://gcc.gnu.org/
[2] http://www.spinics.net/lists/arm-kernel/msg177648.html
[3] http://wiki.gentoo.org/wiki/DreamPlug
[4] http://www.madore.org/~david/linux/dreamplug.html
medve540
 
Posts: 1
Joined: Thu Feb 14, 2013 10:15 pm

Re: [GUIDE] Re-building the kernel(3.7.8) and U-Boot (2013.0

Postby Kamikaze84 » Fri Mar 08, 2013 6:46 am

Thanks for the guide. It's been very helpful.

Just a note about 4.1 - compiling the u-boot:
The arm-linux-gnueabi toolchain wasn't working when compiling the u-boot for either version 2013.01 or 2013.01.01. I was getting the following error on the 'make all':
Code: Select all
/usr/lib/gcc/arm-linux-gnueabi/4.7.2/libgcc.a(_dvmd_lnx.o): In function `__aeabi_ldiv0':
(.text+0x8): undefined reference to `raise'
arm-linux-gnueabi-ld.bfd: error: required section '.rel.plt' not found in the linker script
arm-linux-gnueabi-ld.bfd: final link failed: Invalid operation
make: *** [u-boot] Error 1


I ended up downloading another toolchain from the AUR that worked for me:
cross-arm-none-eabi-gcc
I then needed to re-set the CROSS_COMPILE variable to the new toolchain before restarting compilation:
Code: Select all
export CROSS_COMPILE=arm-none-eabi-


This seemed to work - compilation was a success. Note that I have no idea whether the compiled u-boot actually works at this stage. I should be testing it and a compiled version of linux-3.8.2 within the next couple of days on a dreamplug v8 (0801)
Kamikaze84
 
Posts: 4
Joined: Fri Mar 08, 2013 6:00 am

Re: [GUIDE] Re-building the kernel(3.7.8) and U-Boot (2013.0

Postby Kamikaze84 » Mon Mar 11, 2013 5:30 am

Incase this helps anyone:

After a lot of hard power on/offs to try and perfectly time the openocd command to inject the new u-boot (v 2013.01.01) into memory without wiping the original u-boot stored in the SPI flash, I finally managed to get my compiled u-boot to load on the dreamplug. It seemed to work... partially. I had problems with both of the ethernet interfaces. I may have been doing something wrong but I couldn't get it to see a TFTP server on my network. It also couldn't ping anything. This was after setting a fake ethaddr as I forgot to write down the original, and after setting an ipaddr too. I will probably look at compiling 2013.01 instead and trying that to see if the network interfaces are still an issue.

I then tried to boot my own compiled kernel 3.8.2, and got a machine ID mismatch error. After fudging the machine id (using setenv machid) it got past that error, but then hung at "Uncompressing Linux... done, booting the kernel.". This is probably all because I forgot to load the kirkwood-dreamplug.dtb file first though (not knowing anything about FDT I didn't realise this was necessary). I will investigate further tonight. If that doesn't help, then I've found a page suggesting that I need to recompile the kernel with some extra config options to fix the hang which I'll look at doing: (more info on that, here: http://www.madore.org/~david/linux/dreamplug.html ). I've also seen references to needing the kernel .config option: CONFIG_SERIAL_OF_PLATFORM=y set aswell, to support serial port init when using device trees. Not sure if this is in the original .config as part of this guide - more to look at tonight.

I'll post again on here later if I get any further with this project.
Kamikaze84
 
Posts: 4
Joined: Fri Mar 08, 2013 6:00 am

Re: [GUIDE] Re-building the kernel(3.7.8) and U-Boot (2013.0

Postby Kamikaze84 » Tue Mar 12, 2013 12:42 am

Update - it all works! I'm not sure what was going on the first time I injected my 2013.01.01 u-boot into memory and the ethernet didn't work; I didn't have that issue again. The only thing I was doing differently was that I had the proper MAC addresses of each interface next time around and used them instead of a fake MAC address - perhaps it needs the correct MAC address of the ethernet adapters to use the interfaces?

The other problem I had with the kernel was indeed that I didn't load in the kirkwood-dreamplug.dtb file first. This was needed for the kernel I was attempting to load. I was able to get away with loading the old 2.6.33 globalscale provided ubuntu kernel without the dtb file if I first set the old machine ID and used the old bootstring that didn't identify a location for the FDT.

Once I confirmed the ethernet interfaces worked from the u-boot and I could boot the old kernel fine (as a fallback), I decided to flash the u-boot.kwb to the SPI and then try out the new kernel with the old ubuntu install. It worked fine, so then I made up a new microSD containing my new kernel, a copy of the files from the ArchLinuxARM-armv5te-latest.tar.gz for the rootfs, and extracted the kernel modules back to /lib/modules. Success! Finally had a "fully updated" dreamplug, and I should be able to compile mainline kernels down the track and swap them in now that I have the new u-boot!

A couple of final notes - the kernel .config provided by medve540 was missing a few things, the main one for me was that it was missing the NETFILTER module (so I couldn't use iptables). I ended up doing a full kernel recompile, this time going through the make menuconfig and adding in a few things and redeploying the uImage and modules to the dreamplug.

I have noticed one thing that no longer seems to work with the new kernel & u-boot, for some reason I can't reboot the dreamplug from within Linux anymore. It seems to hang at the point of when it should be rebooting. It doesn't really phase me though as I should never really need to do that except maybe when compiling a new kernel (AFAIK kernel 3.9 has mainlined CPU frequency stepping for kirkwood CPUs, so it can step down to a lower power state when idle, so I'll probably upgrade one more time :)).

THANKS again for the guide.
Kamikaze84
 
Posts: 4
Joined: Fri Mar 08, 2013 6:00 am


Return to Marvell Kirkwood

Who is online

Users browsing this forum: tomcheng76 and 4 guests