Friday 17 May 2013

I.MX6 GK802 - Uboot multi-boot

I spent some re-factoring the current uboot to enable the possibility of booting a roofs located on either:

1. Internal SD
2. External SD
3. Usb drive

Here's how it works, the new boot searches for a uboot script file called "boot.scr" on each of the above devices. The boot.scr is loaded and executed from the first device it encounters containing the file. We assume the device contains an ext2/3/4 partition and the boot.scr is located in /. Within the boot.scr file the variable 'boot_normal' has to be set to contain the uboot commands to run next, the contents of this variable are then executed.

You can download multi-uboot from here and 'dd' to an sd card that will reside in the internal sd card slot. Potentially this can be a very small SD card if you have no intentions of hosting a rootfs on it.

sudo dd if=u-boot_multi_boot.imx bs=1k seek=1 of=/dev/<internal SD card device> && sync


Lets start with an example, lets say we want to execute our ubuntu image from the external SD card. I am assuming the ubuntu rootfs exists on an sd card . First we create a text file I call them 'boot.cmd' (you can give it any name) containing the uboot commands to run as shown below:

setenv console 'ttymxc3,115200'
setenv root '/dev/mmcblk1p1 rootwait'
setenv rootfstype 'ext4'
setenv kernel 'uImage'
setenv video 'mxcfb0:dev=hdmi,1280x720M@60,if=RGB24'
setenv extra ''
setenv boot_normal 'setenv bootargs console=${console} root=${root} rootfstype=${rootfstype} video=${video} ${extra};  mmc dev 1; ext2load mmc 1:1 0x10800000 /boot/uImage; bootm'

For the above :

1. 'root' is set to the external sd card (/dev/mmcblk1p1).
2. 'video' contains the video resolution we want the kernel to set. Note setting the resolution may disable sound. So you could remove the video variable from the file to let the kernel detect the resolution using EDID. There is also a kernel patch from wolfgar that fixes the sound when the resolution is set to 720p or 1080. You can download precompiled kernel and modules with the patch. Copy kernel (uImage) to /boot and untar modules_3.0.35-02708-g899792c-dirty.tar.gz and copy modules directory to /lib/modules.

3. 'boot_normal' is told to use the external sd slot by  'mmc dev 1' and then to load the kernel located at /boot/uImage.

Next the text file has to be converted to a uboot script image file using the mkimage command to create  the boot.scr file.

mkimage -A arm -O linux -T script -n "boot" -d boot.cmd boot.scr


Copy the boot.src to the root directory of your external sd card containing the rootfs.

Ensure internal sd slot has a the sd card containing the mutli-boot uboot on in it and does not contain a /boot.scr. Place the sd card containing the rootfs in the external sd card slot and boot.

Here are some example script files (remember to rename compiled file to boot.scr) :
Note the source files contain a mistake that should be fixed: 
     setenv fbmem "fbmem=28M";  
SHOULD BE  
    setenv fbmem ''; 

1. Boot from external SD (no video set)


2. Boot from from USB (assumes a single mass storage device is available).

3. Boot from internal SD (no video set)

25 comments:

  1. Hello!
    Can You paste working kernel config with sound enabled, please? Can't get sound working.
    One more thing - I tried to realize multiboot installation. Not working for me, with rootfs on external card slot. No boot signs.
    Works with rootfs on internal card.

    Best regards,
    Vertizhka

    ReplyDelete
    Replies
    1. O, sorry about multiboot. Appearantly I have used a buggy hardware.

      Delete
  2. Wouldn't it make more sense to boot in a similar way to how a typical BIOS functions? First look for a valid bootable drive on USB, if nothing there then look on the external SD, and if nothing there than finally boot from the internal SD. Then you can selectively boot new images by inserting them in the external SD card slot, but otherwise it will run your normal system off the internal one.

    ReplyDelete
    Replies
    1. The problem with USB boot is that the usb driver has to first detect all usb devices before it can boot from any. This would considerably slow down SD card booting. SD card detection is considerably faster, therefore it would be possible to change my uboot to boot from External SD card.

      Delete
  3. The link to the compiled 3rd item (3. Boot from internal SD (no video set)) is bad. I corrected what I thought it should be, downloaded, renamed and used, and it doesn't seem to work at all, although I have not been able to verify 100% that it's not something on my end, but I do know that when I back out the multi boot and switch to the normal uboot the device does in fact boot up fine.

    ReplyDelete
    Replies
    1. Thanks, I try to fix the link in the next couple of days.

      Delete
  4. This comment has been removed by the author.

    ReplyDelete
  5. Hi I'm trying start hackberry automatically with TV PAL output, but I'm having no success. I've configured the script.bin following the FEX guide, but the output that I get in that way is not the same that I get from Android settings.
    The biggest problem is that android doesn't keep the screen settings if you select them from the OS, is there a way to make them permanent?

    Sorry if I'm out-topic, but I'm going crazy with this problem :\

    ReplyDelete
  6. How goes the progress on the ubuntu image? I have been eagerly following the development!, you may soon have one of the first fully accelerated arm desktops (or at least the closest thing to that)

    ReplyDelete
    Replies
    1. We currently have X11 acceleration however this is currently limited to Xorg 11.3. Furthermore although there is OpenGL support not all the API's are supported therefore some of the desktop app aren't accelerated (eg FireFox).

      Another plus point the availability of wayland support, although I haven't tried this out.

      Delete
  7. Jas thanks i run gk802 as web server / web radio with a huge external heat sinker and work 3 days straight without temperature problems,question is a way to install Zram ?GK802 run nice only if i had more Ram things would had been way better.

    ReplyDelete
    Replies
    1. Hi, there doesn't seem to be support in our kernel for ZRAM (CONFIG_ZRAM) so it is probably not feasible unless the code can be copied from another kernel.

      It would be interesting to know what CPU part number you have on your GK802, however you would have to take off the heat sink to find out?

      Delete
  8. Hi and thanks for making this release. I was able to get the multi-boot working with sound, X11 acceleration and wifi. I'm using multi-boot to boot from an external card which is prepared pretty much as per the instructions above. But I have a weird issue. Sometimes my GK802 won't boot. In order to boot, I need to recycle the power, sometimes as many as 15-20 times. Once it eventually boots, Ubuntu runs just fine for hours. Once, however, it started Ubuntu and then froze while loading xfce (I saw the mouse pointer and partial desktop but no apps and menus). I suspected some corruption on my external SD so I made a new one. But even with a new card the behavior is the same. It looks like the more I use it, the more attempts it takes to get it to boot. But sometimes it boots fine the first time. Very strange. Has anyone experienced this problem?

    ReplyDelete
    Replies
    1. Hi, I haven't seen your problem. The best way to help solve this would be capture the serial output when the GK802 boots. This will give a good clue to what is happening when the GK802 starts.

      Delete
    2. It appears to be something after X11 starts... I discovered that by disabling the default desktop manager (by removing the full path of the display manager in /etc/X11/default-display-manager) the system boots fine to the command prompt. Later I start xfce by typing startxfce4 on the command line and everything is well. So no more freezes and now I can be pretty sure the problem is not my sd card or the hardware. I will try your suggestion with the serial output to see exactly what was causing this -- thanks. I will post the results if I find something interesting.

      Delete
    3. It could either be a slow SD card or ext4 partition gets corrupted before or while shutting down. On starup the ext4 partition is verified.

      Delete
  9. I'm having trouble. I had a card that was booting on the internal card slot that I created using the instructions here: http://www.cnx-software.com/2013/03/25/ubuntu-11-10-image-for-hi802-gk802-is-now-available-for-download/

    I created a new card using the instructions in this post, moved the old card to the external slot with a boot.scr (In /media/ubuntu/ when card is mounted on the pc?)

    I'm getting this on the console:
    ...
    Reset cause: POR
    Board: MX6Q-gk802
    DRAM: 1 GiB
    MMC: FSL_SDHC: 0, FSL_SDHC: 1
    *** Warning - bad CRC, using default environment

    In: serial
    Out: serial
    Err: serial
    Hit any key to stop autoboot: 3 2 1 0
    mmc0 is current device
    Failed to mount ext2 filesystem...
    ** Unrecognized filesystem type **
    mmc1 is current device
    438 bytes read
    ## Executing script at 10008000
    No /boot.scr found on mmc devices trying usb
    ...
    Any suggestions?

    ReplyDelete
    Replies
    1. Looks like the boot.scr is it has found on the external sd card doesn't contain the correct values. It tries to execute it but no kernel is loaded. Check 'boot_normal' refers to the correct mmc device.

      Delete
    2. Hmm...the mkimage setup on my x86 machine may not be working right. I was able to boot with your precompiled script, but couldn't get my compiled ones to work. Once I booted on your image and compiled it there it seemed to work. Thanks for your work. I used your image to test a lapdock adapter I'm working on.

      lapdock adapter

      Delete
  10. Hi Jasbir, I first wanted to thank you for all the information/builds you've provided. I understand how ridiculous ARM embedded systems are circa `13, and you helped ease the horrible for this stick.

    I wanted to ask why you're not using the armhf arch? The improvement is drastic, as you'd expect, since armhf more fully utilizes the processor. More specifically though, it would be more efficient, and would help with the excess heat/load.

    ReplyDelete
    Replies
    1. Hi, I have built an kernel/rootfs for armhf that has X11 support but no video. Although it performs faster it does not address the excessive heat under load.

      Delete
  11. Hi, I'm trying to download the scripts and root FS, but the server stende.no-ip.info seems to be down. Anyone know of a mirror.

    ReplyDelete
    Replies
    1. You can retry the links, they should be working.

      Delete
  12. I am trying to install ubuntu on external SD from android itself ( rooted ). but there is one litlle problem. There is no 'mkimage' binary. I tryed to use the one from ubuntu ( arm version that i'm trying to install ) itself and it says " #sh: mkimage: No such file or directory " ... any suggestions or alternatives to use for building boot.scr file?

    ReplyDelete
    Replies
    1. Hi, It's not possible to install from Android as the busybox shell in Android is very restrictive and does include the mkimage command. I don't know if there is an Andorid App which gives you more commands in the shell.

      Delete