Methods to update nand mtd kernel partition from rootfs

This forum is for users of Microchip MPUs and who are interested in using Linux OS.

Moderator: nferre

cajjed
Posts: 37
Joined: Thu Aug 25, 2016 3:12 am

Methods to update nand mtd kernel partition from rootfs

Fri Mar 15, 2019 1:26 am

My setup of my sama5d3 is the following using nand flash:

Code: Select all

mtd0: 00040000 00020000 "at91bootstrap"
mtd1: 000c0000 00020000 "uboot"
mtd2: 00080000 00020000 "uboot_env"
mtd3: 00080000 00020000 "dtb"
mtd4: 00600000 00020000 "kernel"
mtd5: 1f800000 00020000 "rootfs"

To update the kernel partitions I use an SD card and then do the following:

Code: Select all

flash_erase /dev/mtd4 0 0
nandwrite -p /dev/mtd4 zImage

Is there any method that would let you update the kernel from rootfs when running from nandflash?

I imagine I could have a second kernel partition and then tweak the uboot_env to choose the new kernel on reboot. Just curious if there was any other options?
blue_z
Location: USA
Posts: 1927
Joined: Thu Apr 19, 2007 10:15 pm

Re: Methods to update nand mtd kernel partition from rootfs

Fri Mar 15, 2019 8:58 pm

cajjed wrote: To update the kernel partitions I use an SD card and then do the following:
...
Is there any method that would let you update the kernel from rootfs when running from nandflash?
Your repeated use of the phrase "from rootfs" makes no sense.
The Linux kernel, regardless of how it is booted, has to have a rootfs.
This root filesystem can be a filesystem in a NAND partition or in a SDcard partition or in memory in a ramfs/tmpfs.
You seem to conflate a "rootfs" with NAND, which is incorrect.
The kernel doesn't care (and doesn't even know) where its image came from or what bootloader performed the loading.
The root filesystem that the Linux kernel (initially) mounts does not have to be stored in the same medium that holds the booted kernel image.
For example you could boot (AT91Bootstrap and U-Boot) from SDcard, load the Linux kernel and dtb images from NAND, and then the kernel could mount a rootfs in a partition on the SDcard!

Your other misconception seems to be the accessibility of the kernel image stored in raw NAND.
The kernel (and Device Tree blob) image(s) are simply read by the bootloader (e.g. U-Boot) during boot, and placed in main memory (for execution).
Once loaded into memory by the bootloader, the stored images in NAND (or anywhere else) are not accessed by the executing kernel, and are expendable until the next boot procedure.
IOW there are no extra restrictions on the accessibility of any kernel (and dtb) images compared to any other unmounted MTD partitions while the Linux kernel is executing.

There is no need to boot Linux from SDcard simply to "update the kernel partition".
The shell commands that you use when booting Linux from SDcard (to overwrite the kernel partition) are just as valid when you boot Linux from NAND.


cajjed wrote: I imagine I could have a second kernel partition and then tweak the uboot_env to choose the new kernel on reboot. Just curious if there was any other options?
The NAND MTD partitioning you use looks like the legacy Atmel scheme that can be improved upon.
The modern preference is to utilize the filesystem capabilities of U-Boot (e.g. ubifsmount and ubifsload), and store the kernel and dtb images as files within the Linux root filesystem (i.e. the /boot directory), which is presumably in a NAND partition/volume.
Ideally you want as much of the NAND flash to be part of the filesystem (or UBI volume) as possible (rather than as raw partitions) so that wear-leveling (and bad-block management) can be more effective.

Regards
cajjed
Posts: 37
Joined: Thu Aug 25, 2016 3:12 am

Re: Methods to update nand mtd kernel partition from rootfs

Fri Mar 15, 2019 10:29 pm

I appreciate the information, I had assumed there was some benefit to keeping the rootfs and dtb on nand in a separate partition. I reduced the partitions down:

Code: Select all

dev:    size   erasesize  name
mtd0: 00040000 00020000 "at91bootstrap"
mtd1: 000c0000 00020000 "bootloader"
mtd2: 00080000 00020000 "bootloader env"
mtd3: 1fe80000 00020000 "rootfs"
and then used my ubi settings to load them via uboot:

Code: Select all

loadImages=mtdparts default && ubi part rootfs && ubifsmount ubi0:rootfs && ubifsload 0x22000000 /boot/zImage && ubifsload 0x21000000 /boot/sama5d3.dtb && bootz 0x22000000 - 0x21000000;
If I were to dump uboot and just use at91bootstrap, where would I put these ubi settings?

Return to “LINUX”

Who is online

Users browsing this forum: No registered users and 4 guests