[Request] U-Boot with ext4 capabilities

Hi Gouwa,

this would be really nice if you could provide a ubuntu flavoured u-boot image for sd/emmc which has built-in ext4/ext2 support. I assume the ubuntu flavour uses a different storage scheme which allows modifications to the u-boot environment via fw_printenv/fw_setenv. If yes I’d be happy to know the right environment offset and size.


Check this Link for the loader bin, which is compile from the latest commit of ubuntu branch on the Github.

Hi Gouwa,

this one works like a charm, thank you very much. What is the difference between these two branches?
This firmware still knows about the Android partitions:

Partition table get from SPL is :
        name                        offset              size              flag
   0: bootloader                         0            400000                  0
   1: reserved                     2400000           4000000                  0
   2: cache                        6c00000                 0                  0
   3: env                          7400000            800000                  0
   4: logo                         8400000           2000000                  1
   5: ramdisk                      ac00000           2000000                  1
   6: rootfs                       d400000         396a00000                  4

so the first effective partition shouldn’t start before sector 0x6A000 (=0xd400000 / 0x200).


Currently, we keep Vim branch same with Amlogic official code style for android.

What do you mean here? do you mean the cache partitions for Android?

OK, and the ubuntu branch? How does it differ w.t.r. to the Vim branch?

The Android partitions occupy the first 212 MB of the storage device, which cannot be used elsewhere. The only purpose is to store the 64kB u-boot environment. Other u-boot versions use the space below sector 2048 to store the u-boot environment, which doesn’t conflict with the standard Linux partitioning scheme (but doesn’t work to boot Android).

Basically, we create a new ubuntu branch is for Linux Distro, and as you can seen, ubuntu branch comes with more simple and brief U-Boot ENV for Linux Distro.

More difference can run this for details:

gouwa@Server:~/project/khadas/ubuntu/u-boot$ git diff Vim..ubuntu  --stat
 arch/arm/include/asm/arch-gxl/reboot.h           |   2 ++
 board/khadas/configs/kvim.h                      | 197 +++++++++++++++++++-------------------------------------------------------------------------------------------
 board/khadas/kvim/firmware/scp_task/dvfs_board.c |   2 +-
 board/khadas/kvim/firmware/scp_task/pwr_ctrl.c   |   6 +---
 board/khadas/kvim/kvim.c                         | 155 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------
 common/cmd_reboot.c                              |  14 ++++++++
 scripts/Makefile.autoconf                        |   9 +++--
 7 files changed, 163 insertions(+), 222 deletions(-)

The first five[0-4] partitions except cache partition is needed for every OS included both Android and Linux Distro on Amlogic platform, note that the U-Boot can load and display the LOGO if logo partition got the specified picture format stored on it.

Hm, HK has two different u-boot flavours for the C2 using different disk layouts.

Hi all,

We can reduce the partitions size and remove cache partition by following two patches:


diff -b --unified -Nr u-boot-aml-2015.01-20170107-orig/common/cmd_aml_mmc.c u-boot-aml-2015.01-20170107/common/cmd_aml_mmc.c
--- u-boot-aml-2015.01-20170107-orig/common/cmd_aml_mmc.c	2017-01-29 16:34:06.000000000 +0300
+++ u-boot-aml-2015.01-20170107/common/cmd_aml_mmc.c	2017-03-07 02:01:54.757376978 +0300
@@ -217,7 +217,6 @@
                                 int dev;
                                 u32 n=0;
                                 bool is_part = false;//is argv[2] partition name
-                                bool protect_cache = false;
                                 bool non_loader = false;
                                 int blk_shift;
                                 u64 cnt=0, blk =0,start_blk =0;
@@ -230,7 +229,6 @@
                                         }else if(!strcmp(argv[2], "non_cache")){
                                                 name = "logo";
                                                 dev = find_dev_num_by_partition_name (name);
-                                                protect_cache = true;
                                         else if(!strcmp(argv[2], "non_loader")){
                                                 dev = 1;
@@ -318,12 +316,6 @@
                                                 if (n == 0) { // not error
                                                         // (2) erase all the area after reserve-partition
-                                                        if (protect_cache) {
-                                                                part_info = find_mmc_partition_by_name(MMC_CACHE_NAME);
-                                                                if (part_info == NULL) {
-                                                                        return 1;
-                                                                }
-                                                        }
                                                         start_blk = (part_info->offset + part_info->size + PARTITION_RESERVED) >> blk_shift;
                                                         u64 erase_cnt = (mmc->capacity >> blk_shift) - 1 - start_blk;
                                                         n = mmc->block_dev.block_erase(dev, start_blk, erase_cnt);
diff -b --unified -Nr u-boot-aml-2015.01-20170107-orig/drivers/mmc/emmc_partitions.c u-boot-aml-2015.01-20170107/drivers/mmc/emmc_partitions.c
--- u-boot-aml-2015.01-20170107-orig/drivers/mmc/emmc_partitions.c	2016-11-24 09:48:28.000000000 +0300
+++ u-boot-aml-2015.01-20170107/drivers/mmc/emmc_partitions.c	2017-03-07 02:01:54.757376978 +0300
@@ -89,7 +89,7 @@
     /* prior partitions, same partition name with dts*/
     /* partition size will be overide by dts*/
diff -b --unified -Nr u-boot-aml-2015.01-20170107-orig/include/emmc_partitions.h u-boot-aml-2015.01-20170107/include/emmc_partitions.h
--- u-boot-aml-2015.01-20170107-orig/include/emmc_partitions.h	2016-11-24 09:48:38.000000000 +0300
+++ u-boot-aml-2015.01-20170107/include/emmc_partitions.h	2017-03-07 02:01:54.756376932 +0300
@@ -27,22 +27,22 @@
 #define     MAX_MMC_PART_NAME_LEN           16
-#define     PARTITION_RESERVED              (8*SZ_1M)  // 8MB
-#define     MMC_BOOT_PARTITION_RESERVED     (32*SZ_1M) // 32MB
+#define     PARTITION_RESERVED              (0)         /* default 8MB: size reserver after each partition */
+#define     MMC_BOOT_PARTITION_RESERVED     (0x2*SZ_1M) /* default 32MB: size reserved after 'bootloader' partition */
 #define     MMC_BOOT_NAME                   "bootloader"
-#define     MMC_BOOT_DEVICE_SIZE            (0x4*SZ_1M)
+#define     MMC_BOOT_DEVICE_SIZE            (0x2*SZ_1M) /* currently U-Boot size is approximately 920K */
 #define     MMC_RESERVED_NAME               "reserved"
 #define     MMC_RESERVED_SIZE               (64*SZ_1M)
 #define		MMC_BOTTOM_RSV_SIZE				(0)
-#define     MMC_CACHE_NAME                  "cache"
+// #define     MMC_CACHE_NAME                  "cache"
 // #define     MMC_CACHE_SIZE                  (512*SZ_1M) // this is not used and should be get from spl
 #define     MMC_ENV_NAME                    "env"
-#define     MMC_ENV_SIZE                    (8*SZ_1M)
+#define     MMC_ENV_SIZE                    (0x4*SZ_1M)
 // #define     MMC_KEY_NAME                    "key"
 #define     MMC_KEY_SIZE                    (256*1024)


diff -b --unified -Nr linux-aml-3.14.29-20170119-orig/include/linux/mmc/emmc_partitions.h linux-aml-3.14.29-20170119/include/linux/mmc/emmc_partitions.h
--- linux-aml-3.14.29-20170119-orig/include/linux/mmc/emmc_partitions.h	2016-11-24 09:47:47.000000000 +0300
+++ linux-aml-3.14.29-20170119/include/linux/mmc/emmc_partitions.h	2017-03-07 02:00:29.391523283 +0300
@@ -25,10 +25,10 @@
 #define     SZ_1M                           0x00100000
 /* the size of bootloader partition */
-#define     MMC_BOOT_PARTITION_SIZE         (4*SZ_1M)
+#define     MMC_BOOT_PARTITION_SIZE         (2*SZ_1M)
 /* the size of reserve space behind bootloader partition */
-#define     MMC_BOOT_PARTITION_RESERVED     (32*SZ_1M)
+#define     MMC_BOOT_PARTITION_RESERVED     (2*SZ_1M)
 #define     RESULT_OK                       0
 #define     RESULT_FAIL                     1

Reserved partition is strongly needed for DTB and u-boot partition table structures. I don’t known can we reduce the size of reserved partitions.

I didn’t made pull request because it is specific changed and only Gouwa can make decision about implementation of this into ubuntu branches of Linux and u-boot repositories.

Andrey K.

Hi, Andrey:
I agree that cache partition is not quite needed for Linux Distro, so can you make a pull request and I will take some test then merge into ubuntu branch.


Hi all,

instead of patching the BSP/Android flavoured u-boot source tree, wouldn’t it be better to put some effort to achieve mainline u-boot support. Some recent work related to the Odroid C2 can be found here and here.


1 Like

Hi Gouwa,

The pull request will take a lot of time because I have to create some organization on GitHub for it. Because I have to make some decision about CM policy. You known that on GitHub you cannot create subdirectories and for splitting projects we have to create organizations and teams. Currently I have to careate three: first for Khadas VIM, second for mainline kernel and third for Amlogic (from their FTP placed tarball).

If you strongly need the pull request I will create mirror on github from a fake temporary account. But these patches very small and I want to warmly ask you to do it by yourself.

Also we need to investigate which is a minimal size of reserved partition.to create final patch.

Best Regards,
Andrey K.

OK, I will do it. (I just wanna keep you name on the commit :slight_smile: )

Oh!!! No problem with NAME!!! Please sign this commit with your name.

- Нет, ребята, я не гордый.
Не заглядывая вдаль,
Так скажу: зачем мне орден?
Я согласен на медаль.

I tried to compile your own version of u-boot. All set, works properly. But I don’t see response to changes the variable CONFIG_EXTRA_ENV_SETTINGS. In the body of the file u-boot I do not see the presence of env variables. Perhaps this when you run the command reset variables to default value (env default -a) I don’t get the desired result. You have made special changes to the source code, what would be the variables not included in the composition or is the result of my not build correctly (configuration) ?

Hi Balbes150,

After partitioning of the eMMC and flashing eMMC u-boot you have to do following command

kvim# defenv
## defenv_reserve

kvim# saveenv
Saving Environment to aml-storage...
mmc env offset: 0x4400000
Writing to MMC(1)... done


It is needed to store ENV to the partition on the eMMC. Then all functions defined in the kvim.h by CONFIG_EXTRA_ENV_SETTINGS will works.

1 Like

As Andrey comment above, you might need to:

  • upgrade new u-boot binary
  • run defenv to restore the new ENV of new u-boot
  • run saveenv to save the new ENV

I follow the patch Andrey provided, works fine here:

U-Boot 2015.01-g475417e (Mar 10 2017 - 17:29:34)


Partition table get from SPL is : 
        name                        offset              size              flag
   0: bootloader                         0            400000                  0
   1: reserved                     2400000           4000000                  0
   2: env                          6c00000            800000                  0
   3: logo                         7c00000           2000000                  1
   4: ramdisk                      a400000           2000000                  1
   5: rootfs                       cc00000         1c5400000                  4
mmc read lba=0x12000, blocks=0x2
mmc read lba=0x12002, blocks=0x2


## Booting Android Image at 0x01080000 ...
load dtb from 0x1000000 ......
   Loading Kernel Image(COMP_NONE) ... OK
   kernel loaded at 0x01080000, end = 0x01f83900
   Loading Ramdisk to 73a9f000, end 73ebd530 ... OK
   Loading Device Tree to 000000001fff3000, end 000000001ffff0c4 ... OK

Starting kernel ...

uboot time: 1580098 us
domain-0 init dvfs: 4
[    0.000000@0] Initializing cgroup subsys cpuset
[    0.000000@0] Initializing cgroup subsys cpu
[    0.000000@0] Initializing cgroup subsys cpuacct
[    0.000000@0] Linux version 3.14.29-kvim-g809f69d (gouwa@Wesion) (gcc version 5.4.0 20160609 (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.4) ) #4 SMP PREEMPT Fri Mar 10 16:19:20 CST 2017

It is advisable to add description of reset commands ENV in the default state to the page with the description of the update for the boot loader.


These commands are different from the previous cases that are used in the documentation for the official Amlogic buildroot. By the way, I checked the updated boot loader (built-in function multi-boot) on the branches of Vim and ubuntu. Everything works. If these changes to include in the regular version of u-boot images, users do not have to activate, it will work immediately after turning on VIM. It’s up to you, if you want, I can put a request for inclusion in main branch.

Test options ready binary files, you can get here.

Yes, I think it’s a good thought to add it, please make the PR. :slight_smile: