Change the partition table

You can customize the partition table of a Digi embedded module using a series of U-Boot commands. The partition table is handled differently depending on the media used to store the system: MMC media or NAND flash.

MMC media (eMMC/microSD card)

GPT partition table

eMMC and microSD are partitioned using a GPT. The partition table (partition names, sizes, and UUIDs) is described in a U-Boot environment variable.

The syntax for describing a GPT as a string is defined at doc/README.gpt file in the U-Boot source code:

   Format of partitions layout:
     "partitions=uuid_disk=...;name=u-boot,size=60MiB,uuid=...;
    name=kernel,size=60MiB,uuid=...;"
     or
     "partitions=uuid_disk=${uuid_gpt_disk};name=${uboot_name},
    size=${uboot_size},uuid=${uboot_uuid};"
 
   The fields 'name' and 'size' are mandatory for every partition.
   The field 'start' is optional.
 
   The fields 'uuid' and 'uuid_disk' are optional if CONFIG_RANDOM_UUID is
   enabled. A random uuid will be used if omitted or they point to an empty/
   non-existent environment variable. The environment variable will be set to
   the generated UUID.

Note A size of "-" (without the MiB suffix) indicates that the partition will use the remaining available space on the media, so the dash is usually used for the last partition in the table.

Once the partition table is defined as a string, you can write the partition table to the media using U-Boot's gpt command.

Digi provides the following predefined variables:

Change the MMC partition table (run-time)

=> env edit parts_linux
=> run partition_mmc_linux

Change the default MMC partition table (build-time)

You may want to change the default partition table so that all devices ship with the same partition layout. To do that:

=> env default parts_linux

You can also reset the whole environment to default values:

=> env default -a
=> run partition_mmc_linux

The mmcpart, mmcroot, and recoverycmd U-Boot variables are used by the dboot and update commands as well as by the installation, recovery, and boot scripts generated by Digi Embedded Yocto.

  • The values of these variables must reflect any changes made to the partition table, and vice versa.
  • Make sure the variable syntax is correct; incorrect syntax may lead to unexpected results.

NAND flash

On a NAND flash, the partition table is simply a string that gets passed to the kernel during the boot process. The NAND flash itself is not written with any partition table data.

The syntax for describing a NAND partition table is defined at common/cmd_mtdparts.c file in the U-Boot source code:

 * mtdparts=mtdparts=<mtd-def>[;<mtd-def>...]
 *
 * <mtd-def>  := <mtd-id>:<part-def>[,<part-def>...]
 * <mtd-id>   := unique device tag used by linux kernel to find mtd device (mtd->name)
 * <part-def> := <size>[@<offset>][<name>][<ro-flag>]
 * <size>     := standard linux memsize OR '-' to denote all remaining space
 * <offset>   := partition start offset within the device
 * <name>     := '(' NAME ')'
 * <ro-flag>  := when set to 'ro' makes partition read-only (not used, passed to kernel)
 * <enc-flag> := when set to 'enc' makes partition encrypted (not used, passed to kernel)

In U-Boot, the NAND partition table is stored in variable mtdparts.

Note File systems have some overhead, so the total partition size won't be available for use when the file system is mounted. This overhead is significant in UBIFS and NAND flashes since in addition to the metadata of the file system itself, a certain amount of blocks must be reserved to account for potential bad blocks.

Change the NAND partition table (run-time)

=> env edit mtdparts
=> nand erase.part <partition>

Change the default NAND partition table (build-time)

You may want to change the default partition table so that all devices ship with the same partition layout. To do that:

=> env default mtdparts

You can also reset the whole environment to default values:

=> env default -a
=> nand erase.part <partition>

The recoverycmd and mtdparts U-Boot variables are used by the dboot and update commands as well as by the installation, recovery, and boot scripts generated by Digi Embedded Yocto.

  • The values of these variables must reflect any changes made to the partition table, and vice versa.
  • Make sure the variable syntax is correct; incorrect syntax may lead to unexpected results.

Adjust Digi Embedded Yocto for partition table changes

After changing the NAND partition table in U-Boot, you must review the MKUBIFS_BOOT_ARGS and MKUBIFS_ARGS variables used in Digi Embedded Yocto. These variables establish the NAND partition parameters to use when building UBIFS images for your system:

The default parameters in Digi Embedded Yocto:

# mkfs.ubifs parameters for boot partition (the one holding kernel and device tree files)
MKUBIFS_BOOT_ARGS ?= "-m 2048 -e 126976 -c 127"
 
# mkfs.ubifs parameters for rootfs partition
MKUBIFS_ARGS ?= "-m 2048 -e 126976 -c 8191"

where:

The -m and -e parameters depend on the NAND geometry, so they do not need to be modified. The -c parameter may need to be adjusted depending on the size of your partitions, to better adjust the overhead of the UBIFS image to the real size of the partition.