Skip to contentSkip to conversation

dt-bindings: mtd: partitions: add TP-Link SafeLoader layout

PATCH Superseded Rafał Miłecki 2 participants 4 messages Oct 12, 2022 – Oct 15, 2022

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 dt-bindings: mtd: partitions: add TP-Link SafeLoader layout

From: Rafał Miłecki <[email protected]>

Most TP-Link home routers use the same partitioning system based on a custom ASCII table.

It doesn't seem to have any official name. GPL sources contain tool named simply "make_flash" and Makefile target "FlashMaker".

This partitions table format was first found in devices with a custom SafeLoader bootloader so it was called SafeLoader by a community. Later it was ported to other bootloaders but it seems the name sticked.

Add binding for describing flashes with SafeLoader partitions table. It allows operating systems to parse it properly and register proper flash layout.

---
V2: Fix typo in commit: s/same/name/

---
 .../tplink,safeloader-partitions.yaml         | 44 +++++++++++++++++++
 1 file changed, 44 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mtd/partitions/tplink,safeloader-partitions.yaml
Documentation/devicetree/bindings/mtd/partitions/tplink,safeloader-partitions.yaml new file +44 -0
new file mode 100644
index 000000000000..e38aaea5aa11
@@ -0,0 +1,44 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mtd/partitions/tplink,safeloader-partitions.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: TP-Link SafeLoader partitions
+
+description: |
+  TP-Link home routers store various data on flash (e.g. bootloader,
+  flash layout, firmware, product info, configuration, calibration
+  data). That requires flash partitioning.
+
+  Flash space layout of TP-Link devices is stored on flash itself using
+  a custom ASCII-based format. That format was first found in TP-Link
+  devices with a custom SafeLoader bootloader. Later it was adapted to
+  CFE and U-Boot bootloaders.
+
+  This binding describes partitioning method and defines offset of ASCII
+  based partitions table. That offset is picked at manufacturing process
+  and doesn't change.
+
+maintainers:
+  - Rafał Miłecki <[email protected]>
+
+properties:
+  compatible:
+    const: tplink,safeloader-partitions
+
+  partitions-table-offset:
+    description: Flash offset of partitions table
+    $ref: "/schemas/types.yaml#/definitions/uint32"
+
+required:
+  - partitions-table-offset
+
+additionalProperties: false
+
+examples:
+  - |
+    partitions {
+        compatible = "tplink,safeloader-partitions";
+        partitions-table-offset = <0x100000>;
+    };
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 2/2 mtd: parsers: add TP-Link SafeLoader partitions table parser

From: Rafał Miłecki <[email protected]>

This parser deals with most TP-Link home routers. It reads info about partitions and registers them in the MTD subsystem.

---
V2: Fix types (thanks kernel test robot)
Fix off-by-one when setting '\0'

---
 drivers/mtd/parsers/Kconfig             |  15 +++
 drivers/mtd/parsers/Makefile            |   1 +
 drivers/mtd/parsers/tplink_safeloader.c | 150 ++++++++++++++++++++++++
 3 files changed, 166 insertions(+)
 create mode 100644 drivers/mtd/parsers/tplink_safeloader.c
drivers/mtd/parsers/Kconfig +15 -0
index aaa06050c9bc..c258ba2a3a6f 100644
@@ -123,6 +123,21 @@ config MTD_AFS_PARTS
 	  for your particular device. It won't happen automatically. The
 	  'physmap' map driver (CONFIG_MTD_PHYSMAP) does this, for example.
 
+config MTD_PARSER_TPLINK_SAFELOADER
+	tristate "TP-Link Safeloader partitions parser"
+	depends on MTD && (ARCH_BCM_5301X || ATH79 || SOC_MT7620 || SOC_MT7621 || COMPILE_TEST)
+	help
+	  TP-Link home routers use flash partitions to store various data. Info
+	  about flash space layout is stored in a partitions table using a
+	  custom ASCII-based format.
+
+	  That format was first found in devices with SafeLoader bootloader and
+	  was named after it. Later it was adapted to CFE and U-Boot
+	  bootloaders.
+
+	  This driver reads partitions table, parses it and creates MTD
+	  partitions.
+
 config MTD_PARSER_TRX
 	tristate "Parser for TRX format partitions"
 	depends on MTD && (BCM47XX || ARCH_BCM_5301X || ARCH_MEDIATEK || RALINK || COMPILE_TEST)
drivers/mtd/parsers/Makefile +1 -0
index 23fa4de4016f..0e70b621a1d8 100644
@@ -10,6 +10,7 @@ ofpart-$(CONFIG_MTD_OF_PARTS_BCM4908)	+= ofpart_bcm4908.o
 ofpart-$(CONFIG_MTD_OF_PARTS_LINKSYS_NS)+= ofpart_linksys_ns.o
 obj-$(CONFIG_MTD_PARSER_IMAGETAG)	+= parser_imagetag.o
 obj-$(CONFIG_MTD_AFS_PARTS)		+= afs.o
+obj-$(CONFIG_MTD_PARSER_TPLINK_SAFELOADER)	+= tplink_safeloader.o
 obj-$(CONFIG_MTD_PARSER_TRX)		+= parser_trx.o
 obj-$(CONFIG_MTD_SERCOMM_PARTS)		+= scpart.o
 obj-$(CONFIG_MTD_SHARPSL_PARTS)		+= sharpslpart.o
drivers/mtd/parsers/tplink_safeloader.c new file +150 -0

150 lines not on this page · raw message

Signature · 1 line
2.34.1
maintainer
#2 lore raw
In reply to Rafał Miłecki
Quoted 52 lines · Rafał Miłecki

From: Rafał Miłecki <[email protected]>

Most TP-Link home routers use the same partitioning system based on a custom ASCII table.

It doesn't seem to have any official name. GPL sources contain tool named simply "make_flash" and Makefile target "FlashMaker".

This partitions table format was first found in devices with a custom SafeLoader bootloader so it was called SafeLoader by a community. Later it was ported to other bootloaders but it seems the name sticked.

Add binding for describing flashes with SafeLoader partitions table. It allows operating systems to parse it properly and register proper flash layout.

---
V2: Fix typo in commit: s/same/name/

---
 .../tplink,safeloader-partitions.yaml         | 44 +++++++++++++++++++
 1 file changed, 44 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mtd/partitions/tplink,safeloader-partitions.yaml
Documentation/devicetree/bindings/mtd/partitions/tplink,safeloader-partitions.yaml new file +22 -0
new file mode 100644
index 000000000000..e38aaea5aa11
@@ -0,0 +1,44 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mtd/partitions/tplink,safeloader-partitions.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: TP-Link SafeLoader partitions
+
+description: |
+  TP-Link home routers store various data on flash (e.g. bootloader,
+  flash layout, firmware, product info, configuration, calibration
+  data). That requires flash partitioning.
+
+  Flash space layout of TP-Link devices is stored on flash itself using
+  a custom ASCII-based format. That format was first found in TP-Link
+  devices with a custom SafeLoader bootloader. Later it was adapted to
+  CFE and U-Boot bootloaders.
+
+  This binding describes partitioning method and defines offset of ASCII
+  based partitions table. That offset is picked at manufacturing process
+  and doesn't change.
+

Documentation/devicetree/bindings/mtd/partitions/tplink,safeloader-partitions.yaml line 32

Quoted 10 lines
Documentation/devicetree/bindings/mtd/partitions/tplink,safeloader-partitions.yaml new file +10 -0
+maintainers:
+  - Rafał Miłecki <[email protected]>
+
+properties:
+  compatible:
+    const: tplink,safeloader-partitions
+
+  partitions-table-offset:
+    description: Flash offset of partitions table
+    $ref: "/schemas/types.yaml#/definitions/uint32"

Don't need quotes.

Documentation/devicetree/bindings/mtd/partitions/tplink,safeloader-partitions.yaml line 43

Quoted 11 lines
Documentation/devicetree/bindings/mtd/partitions/tplink,safeloader-partitions.yaml new file +11 -0
+
+required:
+  - partitions-table-offset
+
+additionalProperties: false
+
+examples:
+  - |
+    partitions {
+        compatible = "tplink,safeloader-partitions";
+        partitions-table-offset = <0x100000>;

What is in the space before this? It is part of the safeloader partitions? If the safeloader partitions are not the entire device, then perhaps we still need fixed partitions.

Rob

#3 lore raw
Quoted 66 lines · Rob Herring
Quoted 52 lines · Rafał Miłecki

From: Rafał Miłecki <[email protected]>

Most TP-Link home routers use the same partitioning system based on a custom ASCII table.

It doesn't seem to have any official name. GPL sources contain tool named simply "make_flash" and Makefile target "FlashMaker".

This partitions table format was first found in devices with a custom SafeLoader bootloader so it was called SafeLoader by a community. Later it was ported to other bootloaders but it seems the name sticked.

Add binding for describing flashes with SafeLoader partitions table. It allows operating systems to parse it properly and register proper flash layout.

---
V2: Fix typo in commit: s/same/name/

---
  .../tplink,safeloader-partitions.yaml         | 44 +++++++++++++++++++
  1 file changed, 44 insertions(+)

create mode 100644 Documentation/devicetree/bindings/mtd/partitions/tplink,safeloader-partitions.yaml

Documentation/devicetree/bindings/mtd/partitions/tplink,safeloader-partitions.yaml new file +22 -0
new file mode 100644
index 000000000000..e38aaea5aa11
@@ -0,0 +1,44 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mtd/partitions/tplink,safeloader-partitions.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: TP-Link SafeLoader partitions
+
+description: |
+  TP-Link home routers store various data on flash (e.g. bootloader,
+  flash layout, firmware, product info, configuration, calibration
+  data). That requires flash partitioning.
+
+  Flash space layout of TP-Link devices is stored on flash itself using
+  a custom ASCII-based format. That format was first found in TP-Link
+  devices with a custom SafeLoader bootloader. Later it was adapted to
+  CFE and U-Boot bootloaders.
+
+  This binding describes partitioning method and defines offset of ASCII
+  based partitions table. That offset is picked at manufacturing process
+  and doesn't change.
+

Documentation/devicetree/bindings/mtd/partitions/tplink,safeloader-partitions.yaml line 32

Quoted 10 lines
Documentation/devicetree/bindings/mtd/partitions/tplink,safeloader-partitions.yaml new file +10 -0
+maintainers:
+  - Rafał Miłecki <[email protected]>
+
+properties:
+  compatible:
+    const: tplink,safeloader-partitions
+
+  partitions-table-offset:
+    description: Flash offset of partitions table
+    $ref: "/schemas/types.yaml#/definitions/uint32"

Don't need quotes.

Quoted 15 lines

Documentation/devicetree/bindings/mtd/partitions/tplink,safeloader-partitions.yaml line 43

Quoted 11 lines
Documentation/devicetree/bindings/mtd/partitions/tplink,safeloader-partitions.yaml new file +11 -0
+
+required:
+  - partitions-table-offset
+
+additionalProperties: false
+
+examples:
+  - |
+    partitions {
+        compatible = "tplink,safeloader-partitions";
+        partitions-table-offset = <0x100000>;

What is in the space before this? It is part of the safeloader partitions? If the safeloader partitions are not the entire device, then perhaps we still need fixed partitions.

Various partitions are placed before and after partitions table.

Usually/always the whole flash space is covered by partitions defined in the partitions table.