Boot sequence suggestions


If it is possible to change now, I would like to suggest.
I’ve almost never got the sdcard OS to boot using the so called “function button”.
My suggestion would be to set sdcard as the primary boot, and if sdcard cannot boot or is not present, it boots from the emmc.
This would also be easier for trouble shooting, if the emmc flash fails then we could just pop in a flasher sdcard and reset the emmc.
and it would be generally easier to boot from sdcard rather than erasing the whole emmc.


The balbes150 images on SD card will boot by default, no Fn button needed, if is card inserted. That assumes Android is the installed OS.
The Fn button should get you to Linux if dual-boot is installed, but I usually just use the shutdown menu to reboot to Linux from Android. I realize this is not always practical.


Hi, Ric96:
Yes, you are right, and in fact, Khadas VIM will follow below boot sequence:

  • If a SD card with bootable OS inserted: will boot from SD card automate.
  • If boot with Fn button pressed: will boot from the 2nd OS on EMMC
  • If boot without Fn button pressed & without bootable SD card inserted: will boot from the 1st OS on EMMC.

Note that:

  • Should be upgrade to the latest U-Boot & Android OS (will release in a few days) to full support this boot sequence.
  • we can only confirm the official release/ROM will follow the boot sequence, 3rd party ROM not

Voices from user confused

5 posts were merged into an existing topic: Voices from user confused


There is another way to boot off SD card without having uboot support for it. It involves pin shorting the data pins on the emmc though so you have to be careful. This causes the ATF BL1, which I think is located somewhere else (?), to use SD instead for booting. I have done this on a S912 before and its been a known way to help recover older boxes as well.

I don’t know if there is a safer way to effectively do this (make the emmc temporarily disappear) on a VIM though.

Note: Gouwa’s original comment was about a modified version of uboot that can check the status of the various other states to decide what to boot afterwards. To boot directly off SD without any other support I think you need to have a modified ATF BL1 as noted above, or pin short.

I wrote the following document “[HOW TO RECOVER] So you bricked your box” on freaktab a few months ago, which was covered by a cnx-software article. It applies to the standard amlogic images, so this will probably work on VIM as well. To force the first state in the document you can pin short if its trying to boot off emmc still.

GXM:BL1:dc8b51:76f1a5;FEAT:ADFC318C:0;POC:3;RCY:0; EMMC:0;READ:0;CHK:AA;SD:0;READ:0;CHK:AA;USB:8;


Hi, Chris:
Do you mean MRegistor Mode on this Howto Boot Into Upgrade Mode Instructions.


Yes, that probably will do the same thing as pin shorting the data lines, but I haven’t tried it yet.


Hi ric96

If you talk about Linux then you can create patch for u-boot like following:

diff -b --unified -Nr u-boot-aml-2015.01-20170107-orig/board/khadas/configs/kvim.h u-boot-aml-2015.01-20170107/board/khadas/configs/kvim.h
--- u-boot-aml-2015.01-20170107-orig/board/khadas/configs/kvim.h	2017-02-02 01:25:07.000000000 +0300
+++ u-boot-aml-2015.01-20170107/board/khadas/configs/kvim.h	2017-03-25 00:02:38.716519693 +0300
@@ -86,6 +86,29 @@
     "fb_addr=0x3d800000\0" \
     "fb_width=1920\0" \
     "fb_height=1080\0" \
+    "scriptaddr=0x12ff0000\0" \
+    "load_boot_script=ext4load mmc 1:1 ${scriptaddr} /boot/boot.scr\0" \
+    "load_sd_boot_script=ext4load mmc 0:1 ${scriptaddr} /boot/\0" \
+    "bootscript=echo Running bootscript ...; autoscr ${scriptaddr}\0" \
+    "emmc_init=mmc dev 1; mmcinfo\0" \
+    "mmcboot=" \
+            "if mmcinfo; then " \
+               "echo Trying to Boot from SD Card ...;" \
+               "if run load_sd_boot_script; then " \
+                  "run bootscript;" \
+               "else " \
+                  "imgread kernel boot ${loadaddr}; bootm ${loadaddr};" \
+               "fi;" \
+            "else " \
+               "echo Trying to Boot from eMMC ...;" \
+               "run emmc_init;" \
+               "if run load_boot_script; then " \
+                  "run bootscript;" \
+               "else " \
+                  "imgread kernel boot ${loadaddr}; bootm ${loadaddr};" \
+               "fi;" \
+            "fi;" \
+    "\0" \
     "init_display=" \
             "osd open;" \
             "osd clear;" \
@@ -104,7 +127,7 @@
     "run init_display;" \
     "run upgrade_key;"
-#define CONFIG_BOOTCOMMAND "imgread kernel boot ${loadaddr}; bootm ${loadaddr}"
+#define CONFIG_BOOTCOMMAND "run mmcboot"
 #define CONFIG_ENV_SIZE   (64*1024)

So, If mmcinfo is true then we have SD card in the card reader and we can try to boot; If mmcinfo is false then we have to switch to mmc dev 1 (this is eMMC) and try to boot again.

Andrey K.


awesome! i’ll give it a shot


Bootscripts (, boot.scr) created in this code


Was this ever implemented in u-boot (khadas or mainline)? Is the patch from Andrey still needed to first boot from mSD and then eMMC?


Hi, vrabac.

I don’t think that this patch will be implemented soon into Amlogic u-boot because Amlogic is focused on Android. I think this patch can be implemeted on Khadas u-boot is present on the ubuntu branch. But before this implementation we need to make decision about some standartization. For example? I usualy use boot.scr scripts in the /boot directory and also I never use MS-DOS partitions because one ext4 partition is enough for normal Linux system.

Any case this is a domain of Khadas owners. I think Gouwa can make some design and suggest his solution for community.

If you agree with my way, you can use my code. Moreover it is very simple to do such patches before building the u-boot.

Best Regards,
Andrey K.


Hi Andrey,
Thank you for the clarification regarding mainlining these changes, I hope Khadas Support can push this, as there were with Amlogic meeting if I remember it. Never saw any end statement what they decided.

Currently I am trying to boot Archlinuxarm armv8/generic rootfs and there is need to re-generate the uImage after every kernel update and the dtbs have to be updated after each kernel update.
In this setup I do use sdb1 as vfat /boot partition and sdb2 as /root but just because I don’t know any other way to do it. I will check what does boot.scr scripts do.


To run from external media you can use the command “booti”, it starts immediately not Packed kernel file, initrd and dtb (each element independently). Packaging using mkimage is needed only for writing (start) of the kernel from the internal memory (eMMC), because u-boot can’t load into memory other options of the kernel from the internal memory. When compiling the kernel, specify the format for the kernel “Image”.


Instead of patching u-boot, I’ve written a bunch of u-boot macros making the boot procedure a little bit more flexible. You can store them inside of the permanent u-.boot environment.


Hi vrabac,

vfat partition is not realy needed because u-boot can read ext4 partitions and you only need to read the kernel with dts. boot.scr scripts are very simple and both of them generated by this Makefile.

Also because kernel sources doesn’t have procedure for creating uImage you can do it by simple command:

$ mkimage \
   -A $(ARCH) -O linux -T kernel -C gzip -a $(load_address) -e $(entry_point) \
   -n $(kernel_version) -d $(linux_zImage) uImage


load_address = entry_point = 0x01080000

Andrey K.


Just tried it without vfat partition but i can’t load anymore uImage over u-boot. Does khadas u-boot (one which came with Android) support ext4 boot?

If i understand this info below correctly my mSD is in Port B which is 0 and as this mSD have only one partition the correct part should be “mmc 0:1” ?

U-Boot 2015.01-g35f4e9d (Apr 19 2017 - 19:03:15)
aarch64-linux-gnu-gcc (Ubuntu/Linaro 4.8.4-2ubuntu1~14.04.1) 4.8.4
GNU ld (GNU Binutils for Ubuntu) 2.24
card in
init_part() 278: PART_TYPE_DOS
[mmc_init] mmc init success
Device: SDIO Port B
Manufacturer ID: 60
OEM: 4853
Name: 2GU2M
Tran Speed: 50000000
Rd Block Len: 512
SD version 2.0
High Capacity: No
Capacity: 1.9 GiB
mmc clock: 40000000
Bus Width: 4-bit
kvim#mmc list
SDIO Port B: 0
SDIO Port C: 1
kvim#mmc part
Unknown command 'mmc' - try 'help'
kvim#mmc part
Partition Map for MMC device 0  --   Partition Type: DOS
Part    Start Sector    Num Sectors     UUID            Type
  1     2048            3919872         2aa8835a-01     83
kvim#setenv bootargs "console=ttyAML0,115200 root=/dev/mmcblk0p1 rootwait=1 rootdelay=2 init=/usr/bin/init"
kvim#fatload mmc 0:1 ${loadaddr} uImage
** Unrecognized filesystem type **


Partition Type is 83. This is standard Linux partition.
I don’t think that this partition contains vfat filesystem

For loading from ext4 fs you have to use ext4load command lile follow:

kvim# ext4load mmc 0:1 ${loadaddr} /boot/uImage

But before please make sure that this partition has ext4 fs:

kvim# ext4ls mmc 0:1


Andrey that is correct, as i wrote i am trying without vfat partition. Thanks to you I found that i need ext4load and not fatload (it is logical but i never used u-boot before).
Now i can boot Archlinuxarm by using official archlinuxarm rootfs.


I put Khadas Ubuntu image on eMMC and its u-boot does not see mSD partition like in android u-boot (posted few posts above). However device boot fine the mSD.

U-Boot 2015.01-g52d10ef (May 15 2017 - 03:27:25)
aarch64-linux-gnu-gcc (Ubuntu/Linaro 4.8.4-2ubuntu1~14.04.1) 4.8.4
GNU ld (GNU Binutils for Ubuntu) 2.24
card in
[mmc_init] mmc init success
Device: SDIO Port B
Manufacturer ID: 60
OEM: 4853
Name: 2GU2M
Tran Speed: 50000000
Rd Block Len: 512
SD version 2.0
High Capacity: No
Capacity: 1.9 GiB
mmc clock: 40000000
Bus Width: 4-bit

> kvim#mmc part
**> kvim#**ext4ls mmc 0:1

<DIR>       4096 .
<DIR>       4096 ..
<DIR>      16384 lost+found
<SYM>          7 bin
<DIR>       4096 boot
<DIR>       4096 dev
<DIR>       4096 etc
<DIR>       4096 home
<SYM>          7 lib
<DIR>       4096 mnt
<DIR>       4096 opt
<DIR>       4096 proc
<DIR>       4096 root
<DIR>       4096 run
<SYM>          7 sbin
<DIR>       4096 srv
<DIR>       4096 sys
<DIR>       4096 tmp
<DIR>       4096 usr
<DIR>       4096 var
kvim#setenv bootargs "console=ttyAML0,115200 root=/dev/mmcblk0p1 rw rootwait=1 rootdelay=2 init=/usr/bin/init"
kvim#ext4load mmc 0:1 ${loadaddr} /boot/uImage
21561920 bytes read in 1511 ms (13.6 MiB/s)
kvim#ext4load mmc 0:1 $dtb_mem_addr /boot/dtbs/amlogic/meson-gxl-s905x-khadas-vim.dtb
19699 bytes read in 32 ms (600.6 KiB/s)
kvim#bootm ${loadaddr} - $dtb_mem_addr
ee_gate_off ...
## Booting kernel from Legacy Image at 01080000 ...
   Image Name:   Arch Linux kernel
   Image Type:   AArch64 Linux Kernel Image (uncompressed)
   Data Size:    21561856 Bytes = 20.6 MiB
   Load Address: 01080000
   Entry Point:  01080000
   Verifying Checksum ... OK
load dtb from 0x1000000 ......
## Flattened Device Tree blob at 01000000
   Booting using the fdt blob at 0x1000000
   Loading Kernel Image(COMP_NONE) ... OK
   kernel loaded at 0x01080000, end = 0x02510200
libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND
[rsvmem] bl31 reserved memory set addr error.
   Loading Device Tree to 000000001fff8000, end 000000001ffffcf2 ... OK
Starting kernel ...
uboot time: 95016087 us
[    0.000000] Booting Linux on physical CPU 0x0
[    0.000000] Linux version 4.12.0-rc2-1-ARCH (builduser@leming) (gcc version 6.3.1 20170306 (GCC) ) #1 SMP Sun May 21 22:11:21 MDT 2017
[    0.000000] Boot CPU: AArch64 Processor [410fd034]
[    0.000000] Machine model: Khadas VIM

how to store these four command above to u-boot, not to enter them over serial on every boot?