Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@
- Add a FAQ section to the documentation explaining the ``Filesystem has
unsupported feature(s)`` error of ``resize2fs``, caused by the ext4
``orphan_file`` feature and old e2fsprogs versions.
- Add support for UBI (Unsorted Block Images) volumes inside an MTD partition.
Raw NAND flashes have no partition table but use the UBI layer to manage
volumes within an MTD. A partition with an ``ubi`` section is formatted with
UBI, wiping all of its previous content, and the specified volumes are
created on top of it. Volumes are either dynamic, holding a UBIFS filesystem,
or static for raw data, which is how a bootloader usually accesses them.

Input files of volumes with a filesystem are copied into the mounted
filesystem or extracted into it, if they are archives. UBIFS images are
written directly to the volume. Volumes without a filesystem are written
directly and are verified by reading the volume back.

This needs the kernel's UBI and UBIFS modules to be available.

.. _release-4.0.0:

Expand Down
45 changes: 45 additions & 0 deletions doc/data/layout-ubi-nand.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
api-version: 5

supported-device-types:
- mtd

partitions:
# Barebox environment, kept intact by not erasing it.
- name: barebox-environment
size: 512kiB
offset: 512kiB
erase: false

# Barebox, written raw to the partition with flashcp.
- name: barebox
size: 1MiB
offset: 512kiB
input:
filename: barebox.bin

# The rest of the NAND is formatted with UBI.
- name: ubi
size: 300MiB
ubi:
volumes:
# Static volumes are accessed directly by the bootloader.
- name: dtb
size: 128kiB
type: static
input:
- filename: oftree

- name: kernel
size: 8MiB
type: static
input:
- filename: Image

# Dynamic volume with a UBIFS rootfs, using the rest of the UBI device.
- name: rootfs
expand: true
filesystem: ubifs
# -F makes the kernel fix up free space on first mount.
mkfs-extra-args: -F
input:
- filename: rootfs.tar
1 change: 1 addition & 0 deletions doc/data/meson.build
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
static_data = [
'layout-ab-emmc.yaml',
'layout-simple.yaml',
'layout-ubi-nand.yaml',
'partup-logo-2x.svg',
'partup-logo-2x-white.svg'
]
Expand Down
6 changes: 6 additions & 0 deletions doc/layout-config-examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@ eMMC Layout With Raw WIC Image As Input

.. literalinclude:: data/layout-raw-wic.yaml
:language: yaml

MTD Layout With UBI Volumes
---------------------------

.. literalinclude:: data/layout-ubi-nand.yaml
:language: yaml
90 changes: 90 additions & 0 deletions doc/layout-config-reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,90 @@ contained partitions of an MTD. Each entry may contain the following options:
given as a runtime argument. Note, that this checksum is independent from the
input's ``sha256sum`` option. See :ref:`checksum-verification` for details.

``ubi`` :badge-type:`mapping` :badge-since:`5.0.0`
A mapping with the UBI volumes to create on top of this partition. This
option is mutually exclusive with ``input``, as a partition either holds raw
data or UBI volumes. See :ref:`ubi-volumes`.

.. _ubi-volumes:

UBI Volumes
............

UBI (Unsorted Block Images) volume support is available since:
:ref:`release-5.0.0`

Raw NAND flash has no partition table. Instead, the UBI layer manages volumes
inside an MTD. These volumes commonly hold a UBIFS rootfs or raw files for the
bootloader. A partition with an ``ubi`` mapping is formatted with UBI and the
volumes out of its ``volumes`` sequence are created on top of it.

Formatting is always done with ``ubiformat``, which erases all previous content
of the partition and writes fresh erase counters and an empty volume table.

The ``ubi`` mapping contains the following option:

``volumes`` :badge-type:`sequence` :badge-state:`required` :badge-since:`5.0.0`
A sequence of mappings describing the UBI volumes. Each mapping may contain
the following options:

``name`` :badge-type:`string` :badge-state:`required` :badge-since:`5.0.0`
The volume name. UBI requires volume names to be unique within a UBI
device and to be at most 63 characters long.

``size`` :badge-type:`integer` :badge-type:`string` :badge-since:`5.0.0`
The size of the volume. This scalar is mandatory, unless the volume is
expanded. The same units as for the partition's ``size`` are supported,
e.g. ``12kiB`` or ``34MB``. When no unit is specified, the default is
sectors. UBI rounds the size up to whole logical eraseblocks (LEB), so a
volume may become slightly larger than specified.

``type`` :badge-type:`string` :badge-since:`5.0.0`
The volume type. Possible options are:

- ``dynamic``: Volume that can be used as a UBI character device and can
hold a UBIFS filesystem. UBI assigns the volume's data to logical
eraseblocks dynamically.
- ``static``: Volume with a fixed amount of logical eraseblocks, meant
for raw data only. This is what a bootloader usually uses to access
files directly.

The default value is ``dynamic``. A static volume cannot be expanded and
cannot have a filesystem.

``filesystem`` :badge-type:`string` :badge-since:`5.0.0`
The filesystem type of the volume. The only supported filesystem is
``ubifs``, which is also the default value of dynamic volumes. Use
``null`` to write raw data into the volume. Static volumes have no
filesystem by default.

The filesystem is created with ``mkfs.ubifs`` before any input file is
written, replacing any filesystem that was on the volume before.

``mkfs-extra-args`` :badge-type:`string` :badge-since:`5.0.0`
Extra arguments to be passed to ``mkfs.ubifs``. See ``man mkfs.ubifs``
for allowed arguments.

``expand`` :badge-type:`boolean` :badge-since:`5.0.0`
Expand the volume to the rest of the UBI device. Only the last volume can
be expanded. The default is ``false`` for all volumes.

``input`` :badge-type:`sequence` :badge-since:`5.0.0`
A sequence of input mappings. See :ref:`input-files`.

Volumes with a filesystem get their input files copied into the mounted
filesystem, or extracted if they are archives. UBIFS images are written
directly to the volume and are then mounted once, so that UBIFS can
resize the filesystem to the whole volume. Volumes without a filesystem
are written directly with ``ubiupdatevol``. Such a volume takes only one
input file, because writing replaces the whole volume's content.

Raw volume writes are always being verified by reading the volume back and
checking it against the input's SHA1 sum. The checksum is not being
verified when ``--skip-checksums`` is given as a runtime argument. Note,
that this checksum is independent from the input's ``sha256sum`` option.
See :ref:`checksum-verification` for details.

.. _input-files:

Input Files
Expand Down Expand Up @@ -356,3 +440,9 @@ types, they are treated as following.
any existing filesystem, so it should be specified as ``filesystem: null`` or
not be specified at all. Additionally ext filesystems are resized to utilize
the whole partition.

``ubifs``
Raw filesystem images are written directly to the UBI volume. This overrides
any existing filesystem. Additionally, the UBIFS filesystem is mounted after
writing, so that it resizes itself to utilize the whole volume. Only works on
:ref:`ubi-volumes`.
20 changes: 13 additions & 7 deletions doc/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,17 @@ translation layer. This includes:
- SSD
- SD cards
- eMMC devices and their eMMC boot partitions
- Memory Technology Devices (MTD) (since :ref:`release-3.0.0`), including raw
NAND flash with UBI volumes (since :ref:`release-5.0.0`)

The device must be named ``mmcblk*`` or ``sd*``, e.g. the following device names
are valid::
The device must be named ``mmcblk*``, ``sd*``, or ``mtd*``, e.g. the following
device names are valid::

/dev/mmcblk0
/dev/mmcblk9
/dev/sda
/dev/sdf
/dev/mtd0

.. warning::

Expand All @@ -87,9 +90,10 @@ are valid::

.. note::

Devices with raw access to memory, not incorporating a flash translation
layer, like those accessible through the `Linux MTD interface
<http://www.linux-mtd.infradead.org/>`_, are currently not supported.
MTDs must be specified as their master device, like ``/dev/mtd0``. partup
creates the MTD's partitions itself. For that, the kernel must be configured
with ``CONFIG_MTD_PARTITIONED_MASTER``, so that the master device is exposed
even if the MTD is already partitioned.

.. _example-usage:

Expand Down Expand Up @@ -199,10 +203,12 @@ the raw device, namely:
- the ``raw`` section of MMC and HD devices (since :ref:`release-2.1.0`),
- eMMC boot partition ``binaries`` -- verified on both boot partitions
(``boot0`` and ``boot1``) (since :ref:`release-3.0.0`), and
- MTD ``partitions`` (since :ref:`release-3.0.0`).
- MTD ``partitions`` (since :ref:`release-3.0.0`), and
- UBI ``volumes`` without a filesystem (since :ref:`release-5.0.0`).

Read-back verification is *not* performed for data that is written through a
mounted filesystem, i.e. files copied into a partition, archives extracted into
a partition, or raw ext[234] filesystem images written to a partition.
a partition, or raw ext[234] or UBIFS filesystem images written to a partition
or volume.

The output verification is skipped when ``--skip-checksums`` is given.
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ src = [
'src/pu-mount.c',
'src/pu-mtd.c',
'src/pu-package.c',
'src/pu-ubi.c',
'src/pu-unit.c',
'src/pu-utils.c'
]
Expand Down
5 changes: 5 additions & 0 deletions src/pu-error.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ typedef enum {
/* MTD errors */
PU_ERROR_MTD_PARSE,

/* UBI errors */
PU_ERROR_UBI_PARSE,
PU_ERROR_UBI_FORMAT,
PU_ERROR_UBI_VERIFY,

/* Config parsing errors */
PU_ERROR_CONFIG_INIT_FAILED,
PU_ERROR_CONFIG_INVALID_ROOT,
Expand Down
Loading