You can customize the partition table of a Digi embedded module using a series of U-Boot commands.

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 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.

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.

Single-MTD system partitioning

The single-MTD system partitioning strategy uses one MTD partition called UBI and multiple UBI volumes.

The UBI partition occupies most of the available space on the NAND so it’s unlikely that you want to change the MTD partition layout. Instead, you may want to change the number and size of the UBI volumes inside the UBI partition.

Change the system UBI volumes (run-time)

The layout of UBI volumes is defined on variable ubivolscript. You can edit this variable using env edit command in U-Boot.

Although it is possible, it’s not recommended to change the layout of UBI volumes at run-time. Variable ubivolscript is a long script with conditionals, difficult to edit on a terminal using env edit command.

Change the system UBI volumes (build-time)

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

  • Open your platform’s common header file in U-Boot source code at include/configs/ccmp15-dvk.h.

  • Locate the UBI volumes layout definition for your module’s NAND capacity (constants such as UBIVOLSx_xxxMB, or UBIVOLSx_DUALBOOT_xxxMB if using Dual boot):

    #define UBIVOLS1_256MB			"ubi create " LINUX_PARTITION " 900000;" \
    					"ubi create " RECOVERY_PARTITION ";"
    #define UBIVOLS2_256MB			"ubi create " ROOTFS_PARTITION " 7000000;" \
    					"ubi create " UPDATE_PARTITION " 6000000;" \
    					"ubi create " DATA_PARTITION ";"
    
    #define UBIVOLS1_512MB			"ubi create " LINUX_PARTITION " 1000000;" \
    					"ubi create " RECOVERY_PARTITION ";"
    #define UBIVOLS2_512MB			"ubi create " ROOTFS_PARTITION " 10000000;" \
    					"ubi create " UPDATE_PARTITION " b800000;" \
    					"ubi create " DATA_PARTITION ";"
    
    #define UBIVOLS1_DUALBOOT_256MB		"ubi create " LINUX_A_PARTITION " b00000;" \
    					"ubi create " LINUX_B_PARTITION ";"
    #define UBIVOLS2_DUALBOOT_256MB		"ubi create " ROOTFS_A_PARTITION " 6800000;" \
    					"ubi create " ROOTFS_B_PARTITION " 6800000;" \
    					"ubi create " DATA_PARTITION ";"
    
    #define UBIVOLS1_DUALBOOT_512MB		"ubi create " LINUX_A_PARTITION " 1000000;" \
    					"ubi create " LINUX_B_PARTITION ";"
    #define UBIVOLS2_DUALBOOT_512MB		"ubi create " ROOTFS_A_PARTITION " dc00000;" \
    					"ubi create " ROOTFS_B_PARTITION " dc00000;" \
    					"ubi create " DATA_PARTITION ";"
  • Edit the appropriate constant to create the volumes you want. For system updates to work, preserve the original names of the default UBI volumes (you can modify the sizes, though).

  • Save your changes and recompile U-Boot.

  • Update the bootloader of your device and reboot it.

  • Reset the whole environment to default values:

    => env default -a
  • Run the following script to generate the new UBI volumes layout:

    => run ubivolscript
  • Save the environment with saveenv.