[OpenWrt-Devel] [PATCH v2 0/6] MTD parser for RouterBoot

Thibaut VARÈNE hacks at slashdirt.org
Mon Apr 20 09:13:30 EDT 2020

Following suggestion from Rafał Miłecki, this patchset introduces an OF-style
MTD parser to process MikroTik RouterBOARD "RouterBoot" partitions.

On MikroTik devices, the SPI-NOR chip contains a segment comprised of the
bootloader and some additional partitions that can be identified via magic
numbers. The content of these identifiable partitions is used by OpenWRT.

The rationale for this patchset is threefold:
 1/ Restore a preexisting behavior from ar71xx and potentially avoid breakage
 2/ Simplify bootstraping new RouterBOARD devices to OpenWRT
 3/ Lay the groundwork for single image support for RouterBOARD devices

In more details:

 1/ Existing behavior and risk of breakage:
On ar71xx, the code in routerboot.c already performs the dynamic adjustment
of the hard_config and soft_config partitions. This is especially useful on
e.g. NAND-based devices, which have only a very small SPI-NOR chip (typically
64KB) which itself contains a small bootloader and its accompanying hard_config
and soft_config data. On these devices, considering the small size of the NOR
flash, it is assumed that the partitions may be relocated on the chip to
accomodate changes in the size of the bootloader. Therefore, assuming
"fixed-partitions" in DTS (in ath79 port) is probably a bad idea.

 2/ Simplify bootstraping:
Since OpenWRT really only cares about the hard_config (to extract e.g. the
MAC address base, and the WLAN calibration data) and soft_config (to adjust
some bootloader parameters via the 'rbcfg' utility), this parser makes it
possible to boot a new device for which only the overall size of the RouterBoot
segment is known (or guestimated) by only specifying the following in DTS:

	partition0 at 0 {
		label = "RouterBoot";
		reg = <0x0000 0x100000>;
		compatible = "mikrotik,routerboot-partitions";
		#address-cells = <1>;
		#size-cells = <1>;

		hard_config {

		soft_config {

The parser will automatically assign the correct partitions on the MTD device.

 3/ Preparing groundwork for single image support
Assuming it ever becomes desirable to offer a single-image for all supported
RouterBOARD devices (a la ar71xx), this parser will greatly simplify the setup
of a common DTSI file.

The parser strictly adheres to DTS Specification Release 0.3. Since it is not
valid to have multiple child nodes with the same node-name when no unit-address
is specified, the following series proposes to use the node-name to name
the dynamic partitions. This limits the number of edits in modified DTSes.

It's also worth noting that I did not reuse any of the existing ar71xx code
(which makes invalid assumptions about endianness, among other problems). This
is a write from scratch, based on my own analysis of several dumps of flash
contents across multiple RouterBOARD platforms.

The patch series has been successfully tested on both LE and BE hardware.


Thibaut VARÈNE (6):
  generic: routerbootpart MTD parser for RouterBoot
  generic: routerboot partition build bits
  ath79/mikrotik: enable CONFIG_MTD_ROUTERBOOT_PARTS
  ath79/mikrotik: use routerbootpart partitions
  ramips/mt7621: enable CONFIG_MTD_ROUTERBOOT_PARTS
  ramips: mikrotik: use routerbootpart partitions

 ...ca9556_mikrotik_routerboard-wap-g-5hact2hnd.dts |  18 +-
 ...qca9558_mikrotik_routerboard-922uags-5hpacd.dts |  17 +-
 target/linux/ath79/mikrotik/config-default         |   1 +
 target/linux/generic/config-4.14                   |   1 +
 target/linux/generic/config-4.19                   |   1 +
 target/linux/generic/config-5.4                    |   1 +
 .../files/drivers/mtd/parsers/routerbootpart.c     | 357 +++++++++++++++++++++
 .../435-mtd-add-routerbootpart-parser-config.patch |  43 +++
 .../435-mtd-add-routerbootpart-parser-config.patch |  41 +++
 .../435-mtd-add-routerbootpart-parser-config.patch |  38 +++
 .../dts/mt7621_mikrotik_routerboard-750gr3.dts     |  12 +-
 .../dts/mt7621_mikrotik_routerboard-m11g.dts       |  12 +-
 .../dts/mt7621_mikrotik_routerboard-m33g.dts       |  12 +-
 target/linux/ramips/mt7621/config-4.14             |   1 +
 target/linux/ramips/mt7621/config-5.4              |   1 +
 15 files changed, 509 insertions(+), 47 deletions(-)
 create mode 100644 target/linux/generic/files/drivers/mtd/parsers/routerbootpart.c
 create mode 100644 target/linux/generic/pending-4.14/435-mtd-add-routerbootpart-parser-config.patch
 create mode 100644 target/linux/generic/pending-4.19/435-mtd-add-routerbootpart-parser-config.patch
 create mode 100644 target/linux/generic/pending-5.4/435-mtd-add-routerbootpart-parser-config.patch


openwrt-devel mailing list
openwrt-devel at lists.openwrt.org

More information about the openwrt-devel mailing list