Page 1 of 1

Using the SDcard for storing kernels

Posted: Thu Apr 13, 2017 5:39 pm
by marcus
Hi all.

As mentioned in another thread, U-boot can not access Linux kernels stored on a hard drive that is partitioned using an AmigaOS partition table.

This is just like it was with CFE on the X1000. So on that system you would typically store the kernels on the CompactFlash card, which was FAT formatted.

So I was thinking to myself "Well, the X5000 does not have a CompactFlash card, but it does have an SDcard which is used for storing the bootloader, so why not use that to store the kernels on?".

It turns out that the SDcard does not have a partition table at all, but fortunately the first 4K are not used, so there is plently of room to add an msdos partition table. Upon inspecting the contents of the SDcard in my X5000, I found the following:

Code: Select all

--------------------------------------------------------------
| offset              | size   | contents                    |
--------------------------------------------------------------
| 00000000 - 00000fff | 4K     | zeroes                      |
| 00001000 - 04bfffff | 76M    | uboot                       |
| 04c00000 - ee7fffff | 3740M  | junk (repeating 1K pattern) |
| ee800000 - eeafffff | 3M     | zeroes                      |
--------------------------------------------------------------
So there is a big chunk of junk to cut out a partition from.

Here is how to do it:
  • Boot into Linux (using USB)
  • Backup U-Boot:

    Code: Select all

    sudo dd if=/dev/mmcblk0 bs=1M count=128 of=/tmp/uboot.bin
  • Start gparted
  • select /dev/mmcblk0
  • Pick Device / Create Partition Table...
  • select "msdos" and click Apply
  • Pick Partition / New
  • Set the settings as follows:
    • Free space preceding (MiB): 512
    • New size (MiB): Decrease until "Free space following (MiB):" is also 512
    • Align to: MiB
    • Create as: Primary Partition
    • File Systen: ext4
    • Label: SDCARD
  • Click Add.
  • Right click on the new partition, and pick Format to / ext4.
  • Then pick Edit / Apply all operations.
  • Acknowledge the warning, and wait for the operation to finish.
  • Quit gparted.
  • Restore U-Boot, while keeping the partition table:

    Code: Select all

    sudo dd if=/tmp/uboot.bin of=/dev/mmcblk0 bs=4096 skip=1 seek=1
Et voila, you now have a partition on the SDcard which can be mounted read/write from Linux, and which can be read from U-Boot (try "ext4ls mmc 0:1").

Re: Using the SDcard for storing kernels

Posted: Thu Apr 13, 2017 9:05 pm
by xeno74
@marcus

Fantastic idea! Well done! Interesting!

Re: Using the SDcard for storing kernels

Posted: Fri Apr 14, 2017 4:21 pm
by aperezbios
marcus wrote:Hi all.

As mentioned in another thread, U-boot can not access Linux kernels stored on a hard drive that is partitioned using an AmigaOS partition table.

This is just like it was with CFE on the X1000. So on that system you would typically store the kernels on the CompactFlash card, which was FAT formatted.

So I was thinking to myself "Well, the X5000 does not have a CompactFlash card, but it does have an SDcard which is used for storing the bootloader, so why not use that to store the kernels on?".
:) I've been doing this for 2+ years. Honestly, this is where kickstart modules should be loaded from.
marcus wrote: It turns out that the SDcard does not have a partition table at all, but fortunately the first 4K are not used, so there is plently of room to add an msdos partition table.
It's almost as if they designed it to work this way (they did)
marcus wrote: Upon inspecting the contents of the SDcard in my X5000, I found the following:

Code: Select all

--------------------------------------------------------------
| offset              | size   | contents                    |
--------------------------------------------------------------
| 00000000 - 00000fff | 4K     | zeroes                      |
| 00001000 - 04bfffff | 76M    | uboot                       |
| 04c00000 - ee7fffff | 3740M  | junk (repeating 1K pattern) |
| ee800000 - eeafffff | 3M     | zeroes                      |
--------------------------------------------------------------
So there is a big chunk of junk to cut out a partition from.

Here is how to do it:
  • Boot into Linux (using USB)
  • Backup U-Boot:

    Code: Select all

    sudo dd if=/dev/mmcblk0 bs=1M count=128 of=/tmp/uboot.bin
  • Start gparted
  • select /dev/mmcblk0
  • Pick Device / Create Partition Table...
  • select "msdos" and click Apply
  • Pick Partition / New
  • Set the settings as follows:
    • Free space preceding (MiB): 512
    • New size (MiB): Decrease until "Free space following (MiB):" is also 512
    • Align to: MiB
    • Create as: Primary Partition
    • File Systen: ext4
    • Label: SDCARD
  • Click Add.
  • Right click on the new partition, and pick Format to / ext4.
  • Then pick Edit / Apply all operations.
  • Acknowledge the warning, and wait for the operation to finish.
  • Quit gparted.
  • Restore U-Boot, while keeping the partition table:

    Code: Select all

    sudo dd if=/tmp/uboot.bin of=/dev/mmcblk0 bs=4096 skip=1 seek=1
Et voila, you now have a partition on the SDcard which can be mounted read/write from Linux, and which can be read from U-Boot (try "ext4ls mmc 0:1").

Re: Using the SDcard for storing kernels

Posted: Sat Apr 15, 2017 9:55 am
by marcus
aperezbios wrote:It's almost as if they designed it to work this way (they did)
Yes, it seems pretty common. Cavium ThunderX does the same thing.

Re: Using the SDcard for storing kernels

Posted: Fri Mar 26, 2021 9:39 am
by Roland
Are the instructions given in the first message of this thread still valid - no changes in placement/size in the latest U-Boot version? Is it possible to make the FAT partition larger, and how much in that case? Or even several partitions at the end of the disk space?

Re: Using the SDcard for storing kernels

Posted: Sat Mar 27, 2021 8:55 pm
by Skateman
I think they are... i have been using this method since 2017. I always have my kernels on the SDcard of the X5K

Re: Using the SDcard for storing kernels

Posted: Mon Mar 29, 2021 2:57 pm
by Roland
Skateman wrote: Sat Mar 27, 2021 8:55 pm I think they are... i have been using this method since 2017. I always have my kernels on the SDcard of the X5K
Ok, thanks! I will try it. BTW, have you ever succeeded to corrupt your BootSD partition, or a kernel file on it? (Has happened for me a few times with an USB disk).

Do I understand right that in order to access that BootSD partition, the "fatload usb 0:1 ..." has to be replaced with "fatload ext4ls mmc 0:1..." in U-Boot scripts? No need to run 'usb reset' or some similar command first?

Re: Using the SDcard for storing kernels

Posted: Tue Mar 30, 2021 5:35 pm
by Roland
Got it working... Instead of ext4 I made a FAT32 partition, and sized it to 1 GB. I also installed a SD extension cable, so that it will be easier to swap the SD card.

BTW, the red SD icon Linux uses for MMC partitions is quite fancy :-).