mbox series

[OpenWrt-Devel,00/11,RFC] MTD parser for RouterBoot partitions

Message ID 20200328142032.37734-1-hacks@slashdirt.org
Headers show
Series MTD parser for RouterBoot partitions | expand

Message

Thibaut March 28, 2020, 2:20 p.m. UTC
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@0 {
		label = "RouterBoot";
		reg = <0x0000 0x100000>;
		read-only;
		compatible = "mikrotik,routerboot-partitions";
		#address-cells = <1>;
		#size-cells = <1>;

		hard_config {
			read-only;
		};

		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.

Bootnotes:
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 two different approaches to naming
the dynamic partitions: for the ath79 series I used "partitionN" for all MTD
partitions, with N incremented for each partition; whereas for the ramips
series I left the static partitions untouched and used the node-name to name
the dynamic partitions. I have no religion on this matter: I'm willing to use
whatever option is preferred in the final patch.

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.

Finally, I kept the kernel config edit grouped for easier merging as master
moves, but of course a little bit of cleanup is in order should this series be
accepted.

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

HTH, looking forward to comments :)
Thibaut

Thibaut VARÈNE (11):
  generic: routerbootpart MTD parser for RouterBoot
  generic: routerboot partition build bits (4.19)
  generic: CONFIG_MTD_ROUTERBOOT_PARTS is not set
  ath79: mikrotik: enable CONFIG_MTD_ROUTERBOOT_PARTS
  ath79: MikroTik WAP G-5HacT2HnD routerboot partitions
  ath79: MikroTik RB 922UAGS-5HPacD routerboot partitions
  generic: routerboot partition build bits (4.14)
  ramips: mt7621: enable CONFIG_MTD_ROUTERBOOT_PARTS
  ramips: MikroTik RB750GR3 routerboot partitions
  ramips: MikroTik RBM11G routerboot partitions
  ramips: MikroTik RBM33G routerboot partitions

 ...ca9556_mikrotik_routerboard-wap-g-5hact2hnd.dts |  20 +-
 ...qca9558_mikrotik_routerboard-922uags-5hpacd.dts |  16 +-
 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     | 355 +++++++++++++++++++++
 .../435-mtd-add-routerbootpart-parser-config.patch |  41 +++
 .../435-mtd-add-routerbootpart-parser-config.patch |  25 ++
 .../linux/ramips/dts/mt7621_mikrotik_rb750gr3.dts  |  12 +-
 target/linux/ramips/dts/mt7621_mikrotik_rbm11g.dts |  12 +-
 target/linux/ramips/dts/mt7621_mikrotik_rbm33g.dts |  12 +-
 target/linux/ramips/mt7621/config-4.14             |   1 +
 13 files changed, 453 insertions(+), 45 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