Using the SDcard for storing kernels

AmigaOne X5000 platform specific issues related to Linux only.
Post Reply
marcus
Posts: 56
Joined: Wed Nov 07, 2012 8:07 pm

Using the SDcard for storing kernels

Post 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").
User avatar
xeno74
Posts: 9319
Joined: Fri Mar 23, 2012 7:58 am

Re: Using the SDcard for storing kernels

Post by xeno74 »

@marcus

Fantastic idea! Well done! Interesting!
http://www.amigalinux.org
http://www.supertuxkart-amiga.de

Running Linux on AmigaONEs can require some tinkering.
aperezbios
Posts: 35
Joined: Mon Jan 13, 2014 7:02 pm

Re: Using the SDcard for storing kernels

Post 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").
marcus
Posts: 56
Joined: Wed Nov 07, 2012 8:07 pm

Re: Using the SDcard for storing kernels

Post 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.
Roland
Posts: 824
Joined: Tue May 02, 2017 7:23 am

Re: Using the SDcard for storing kernels

Post 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?
- Roland -
User avatar
Skateman
Posts: 858
Joined: Thu Aug 10, 2017 8:36 pm
Location: The Netherlands

Re: Using the SDcard for storing kernels

Post 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
AmigaOne X5000 -> 2GHz / 16GB RAM / Radeon RX 570 / Radeon X1950 / M-Audio 5.1 -> AmigaOS / Linux
Amiga 1200 -> Recapped / 68ec020 ACA 1221ec / CF HDD / RetroNET connected to the world
Vampire 4SA - RPi4 Running AmiKitXE Full
Roland
Posts: 824
Joined: Tue May 02, 2017 7:23 am

Re: Using the SDcard for storing kernels

Post 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?
- Roland -
Roland
Posts: 824
Joined: Tue May 02, 2017 7:23 am

Re: Using the SDcard for storing kernels

Post 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 :-).
- Roland -
Post Reply