[OpenWrt-Devel] [PATCH v2 00/14] RouterBOARD sysfs driver for RouterBoot data

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

Following a conversation on IRC, this patchset introduces a sysfs interface to
access routerboot "hard_config" data (as stored in the flash segment of the
same name) in a consistent, platform-independent manner.
It makes use of that interface to properly setup WLAN caldata and MAC addresses
on devices.

The rationale for this patchset is threefold:
 1/ Make "hard_config" data accessible in a platform-agnostic way
 2/ Reduce the amount of processing for wlan calibration data
 3/ Lay the groundwork for single image support on RouterBOARD devices

In more details:
 1/ "hard_config" data platform-agnostic accessors
The MikroTik RouterBOARD "hard_config" flash segment contains encoded data such
as the board code, name, serial number, memory size, mac address base, booter
version, hardware features, product name, WLAN calibration data and more. This
driver presents all known datapoints via sysfs in a machine and human friendly
way. This makes it possible for userspace to process that information, in
particular for the two cases further detailed below.
Furthermore, it has been evidenced that no assumption should be made on the
disposition of data within this partition: the content must be programmatically
processed to identify which is which.

 2/ Simplify the processing of wlan calibration data
On ar71xx, ath9k calibration data was directly fed to the driver in the code
while ath10k was typically exposed in binary form in sysfs, to be then loaded
by the corresponding driver.
On ath79 and other DTS-based devices, the sysfs file is not available (as the
original code that exposed it was apparently deemed unsuitable for inclusion or
upstreaming), so these devices resort to a userspace utility ("rbextract") that
fetches the data from the flash and uncompresses/decodes it. The result is then
copied back to the flash upon first boot, wasting space there.
This driver makes it possible to entirely get rid of rbextract (which has a
number of issues of its own, as it ported into userspace the code issues of the
original ar71xx kernel driver), and use the common "caldata_from_file()"
routine to extract the relevant calibration data.
As an extra bonus, this patchset includes a patch that enables loading caldata
directly via the kernel sysfs loader helper, therefore freeing some space on
the flash (and potentially reducing wear across upgrades).

 3/ Groundwork for single image support
Assuming it ever becomes desirable to offer a single-image for all supported
RouterBOARD devices (per arch, of course), a la ar71xx, this driver will
simplify this task as it will be possible to update e.g. the actual product
name or perform further device setup based on the information exposed in sysfs.

This patchset also affects ar71xx, demonstrating that the driver works
correctly there too. This is done so in case a backport becomes desirable
(for instance to address PR#2729).

The driver currently lives in drivers/platform for lack of a better idea, it
can certainly be moved elsewhere if necessary. Likewise for the sysfs basedir

The driver does not reuse any code from the ar71xx bits, it is a write from
scratch based on my analysis of several flash dumps across multiple RouterBOARD
devices. It can coexist with the ar71xx code (tested sucessfully in this

The code for handling the new-style "LZOR" WLAN calibration compression scheme
has been left as a separate patch for two main reasons:
 - I couldn't test it on hardware that would exert that code path
 - The required binary blob LZO prefix might pose licensing issues
Should this latter point materialize, an alternative option would be to expose
the raw, compressed/encoded data in sysfs and rewrite "rbextract" so that its
only job becomes decoding. This moves the questionable bits from kernel to user
space, if that makes a difference. The blob is nevertheless necessary to
decompress the data.

Finally, should this driver be accepted, I intend to also expose the so-called
"soft_config" data in an incremental patch, making it possible to drastically
simplify if not remove entirely the "rbcfg" utility (whose job could then be
implemented directly in a luci app for instance).

This patchset is orthogonal to my previous series ("MTD parser for RouterBoot
partitions") and can be tested independently.

This patch series has been successfully tested on BE (ath79, ar71xx) and LE
(ipq40xx, ramips) hardware.

I guess that sums it up, I hope this helps!

Thibaut VARÈNE (14):
  generic: routerboot sysfs platform driver
  generic: mikrotik platform build bits
  ath79/mikrotik: enable mikrotik platform driver
  ar71xx/mikrotik: enable mikrotik platform driver
  ramips/mt7621: enable mikrotik platform driver
  generic: platform/mikrotik: support LZOR encoding
  ath79/mikrotik: don't use mtd-mac-address in DTS
  ath79/mikrotik: use standard caldata functions
  package/utils: remove rbextract
  ar71xx/mikrotik: ath10k: use new sysfs driver
  package/base-files: caldata: allow setting target file
  package/base-files: add caldata_sysfsload_from_file()
  ath79/mikrotik: load caldata via sysfs loader
  ramips/mt7621: mikrotik: don't use mtd-mac-address in DTS

 package/base-files/Makefile                        |   2 +-
 package/base-files/files/lib/functions/caldata.sh  |  44 +-
 package/utils/rbextract/Makefile                   |  38 --
 package/utils/rbextract/src/CMakeLists.txt         |  14 -
 package/utils/rbextract/src/rbextract.c            | 497 --------------
 package/utils/rbextract/src/rle.c                  |  80 ---
 package/utils/rbextract/src/rle.h                  |   8 -
 package/utils/rbextract/src/routerboot.h           | 258 -------
 .../etc/hotplug.d/firmware/11-ath10k-caldata       |   4 +-
 target/linux/ar71xx/mikrotik/config-default        |   2 +
 ...ca9556_mikrotik_routerboard-wap-g-5hact2hnd.dts |   3 -
 ...qca9558_mikrotik_routerboard-922uags-5hpacd.dts |   2 -
 target/linux/ath79/image/common-mikrotik.mk        |   2 +-
 .../mikrotik/base-files/etc/board.d/02_network     |   7 +
 .../etc/hotplug.d/firmware/10-ath9k-eeprom         |  10 +-
 .../etc/hotplug.d/firmware/11-ath10k-caldata       |   7 +-
 .../base-files/lib/functions/mikrotik-caldata.sh   |  26 -
 target/linux/ath79/mikrotik/config-default         |   2 +
 target/linux/generic/config-4.14                   |   1 +
 target/linux/generic/config-4.19                   |   1 +
 target/linux/generic/config-5.4                    |   1 +
 .../files/drivers/platform/mikrotik/Kconfig        |  18 +
 .../files/drivers/platform/mikrotik/Makefile       |   4 +
 .../drivers/platform/mikrotik/rb_hardconfig.c      | 741 +++++++++++++++++++++
 .../files/drivers/platform/mikrotik/routerboot.c   | 185 +++++
 .../files/drivers/platform/mikrotik/routerboot.h   |  31 +
 .../270-platform-mikrotik-build-bits.patch         |  38 ++
 .../270-platform-mikrotik-build-bits.patch         |  38 ++
 .../270-platform-mikrotik-build-bits.patch         |  31 +
 .../dts/mt7621_mikrotik_routerboard-750gr3.dts     |   7 -
 .../dts/mt7621_mikrotik_routerboard-m11g.dts       |   5 -
 .../dts/mt7621_mikrotik_routerboard-m33g.dts       |   7 -
 .../mt7621/base-files/etc/board.d/02_network       |   4 +-
 target/linux/ramips/mt7621/config-4.14             |   2 +
 target/linux/ramips/mt7621/config-5.4              |   2 +
 35 files changed, 1158 insertions(+), 964 deletions(-)
 delete mode 100644 package/utils/rbextract/Makefile
 delete mode 100644 package/utils/rbextract/src/CMakeLists.txt
 delete mode 100644 package/utils/rbextract/src/rbextract.c
 delete mode 100644 package/utils/rbextract/src/rle.c
 delete mode 100644 package/utils/rbextract/src/rle.h
 delete mode 100644 package/utils/rbextract/src/routerboot.h
 delete mode 100644 target/linux/ath79/mikrotik/base-files/lib/functions/mikrotik-caldata.sh
 create mode 100644 target/linux/generic/files/drivers/platform/mikrotik/Kconfig
 create mode 100644 target/linux/generic/files/drivers/platform/mikrotik/Makefile
 create mode 100644 target/linux/generic/files/drivers/platform/mikrotik/rb_hardconfig.c
 create mode 100644 target/linux/generic/files/drivers/platform/mikrotik/routerboot.c
 create mode 100644 target/linux/generic/files/drivers/platform/mikrotik/routerboot.h
 create mode 100644 target/linux/generic/pending-4.14/270-platform-mikrotik-build-bits.patch
 create mode 100644 target/linux/generic/pending-4.19/270-platform-mikrotik-build-bits.patch
 create mode 100644 target/linux/generic/pending-5.4/270-platform-mikrotik-build-bits.patch


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

More information about the openwrt-devel mailing list