[PATCH] ath79: mikrotik: erase firmware on SPI NOR devices before install

2020-08-17 Thread Thibaut VARÈNE
On Mikrotik SPI NOR devices, the firmware partition must be erased when flashing
from stock firmware, otherwise leftover bits (in particular a kernel signature)
can trigger a boot loop.

When booted from initramfs (the only way to install OpenWRT on these devices),
this patch unconditionally erases the firmware partition in the do_upgrade()
stage for all supported SPI NOR devices.

This is forward-ported from ed49d0876 and 20452a8db

Signed-off-by: Thibaut VARÈNE 
---
 target/linux/ath79/mikrotik/base-files/lib/upgrade/platform.sh | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/target/linux/ath79/mikrotik/base-files/lib/upgrade/platform.sh 
b/target/linux/ath79/mikrotik/base-files/lib/upgrade/platform.sh
index d79bd03af5..d7fac35708 100644
--- a/target/linux/ath79/mikrotik/base-files/lib/upgrade/platform.sh
+++ b/target/linux/ath79/mikrotik/base-files/lib/upgrade/platform.sh
@@ -38,6 +38,8 @@ platform_do_upgrade() {
platform_do_upgrade_mikrotik_nand "$1"
;;
*)
+   # NOR devices: erase firmware if booted from initramfs
+   [ -z "$(rootfs_type)" ] && mtd erase firmware
default_do_upgrade "$1"
;;
esac
-- 
2.21.1 (Apple Git-122.3)


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[PATCH] generic: platform/mikrotik: fix incorrect test

2020-08-18 Thread Thibaut VARÈNE
Signed-off-by: Thibaut VARÈNE 
---
 .../generic/files/drivers/platform/mikrotik/rb_hardconfig.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git 
a/target/linux/generic/files/drivers/platform/mikrotik/rb_hardconfig.c 
b/target/linux/generic/files/drivers/platform/mikrotik/rb_hardconfig.c
index 4559418de7..8861814be4 100644
--- a/target/linux/generic/files/drivers/platform/mikrotik/rb_hardconfig.c
+++ b/target/linux/generic/files/drivers/platform/mikrotik/rb_hardconfig.c
@@ -480,7 +480,7 @@ static int hc_wlan_data_unpack_lzor(const u8 *inbuf, size_t 
inlen,
/* Temporary buffer same size as the outbuf */
templen = *outlen;
tempbuf = kmalloc(templen, GFP_KERNEL);
-   if (!outbuf)
+   if (!tempbuf)
return -ENOMEM;
 
/* Concatenate into the outbuf */
-- 
2.24.3 (Apple Git-128)


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[PATCH v2] generic: platform/mikrotik: fix incorrect test

2020-08-18 Thread Thibaut VARÈNE
The test is meant to check the result of the preceding kmalloc()

Signed-off-by: Thibaut VARÈNE 
---
 .../generic/files/drivers/platform/mikrotik/rb_hardconfig.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git 
a/target/linux/generic/files/drivers/platform/mikrotik/rb_hardconfig.c 
b/target/linux/generic/files/drivers/platform/mikrotik/rb_hardconfig.c
index 4559418de7..8861814be4 100644
--- a/target/linux/generic/files/drivers/platform/mikrotik/rb_hardconfig.c
+++ b/target/linux/generic/files/drivers/platform/mikrotik/rb_hardconfig.c
@@ -480,7 +480,7 @@ static int hc_wlan_data_unpack_lzor(const u8 *inbuf, size_t 
inlen,
/* Temporary buffer same size as the outbuf */
templen = *outlen;
tempbuf = kmalloc(templen, GFP_KERNEL);
-   if (!outbuf)
+   if (!tempbuf)
return -ENOMEM;
 
/* Concatenate into the outbuf */
-- 
2.24.3 (Apple Git-128)


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[PATCH] generic: platform/mikrotik: implement multi caldata

2020-08-24 Thread Thibaut VARÈNE
MikroTik recently changed again the way they store wlan calibration data
on devices. Prior to this change, ERD calibration data for all available
radios was stored within a single identifier node ("tag" in RouterBoot
parlance).

Recent devices have been seen with calibration (and BDF) data stored in
separate identifiers within LZOR packing for each radio: this patch
addresses this by:
1) ensuring that both variants are properly supported,
2) preserving backward compatibility with existing data consumers,
3) allowing for more than 2 calibration blobs to be exposed via sysfs.

Specifically, before this patch, the driver would provide a single sysfs
file named /sys/firmware/mikrotik/hard_config/wlan_data that contained
whatever calibration data found on the device's flash. After this patch,
when executed on a device that uses the old style storage, this behavior
is unchanged, but when executed on a device that uses new style storage
(for either traditional "ERD" packing or "LZOR" packing), the driver
replaces that single file with a folder containing one or more files
each containing the data encoded within individual identifiers.

As far as OpenWRT is concerned, this means that for devices which are
known to exist with both styles of data storage, a suitable hotplug stub
could look like this for e.g. the second radio:

wdata="/sys/firmware/mikrotik/hard_config/wlan_data"
( [ -f "$wdata" ] && caldata_sysfsload_from_file "$wdata" 0x8000 0x2f20 ) || \
( [ -d "$wdata" ] && caldata_sysfsload_from_file "$wdata/data_2" 0x0 0x2f20 )

This patch has been tested with LZOR old and new style packing on ipq4019,
and with old style on ath79.

Tested-by: John Thomson 
Tested-by: Шебанов Алексей 
Tested-by: Alen Opačić 
Signed-off-by: Thibaut VARÈNE 
---
 .../drivers/platform/mikrotik/rb_hardconfig.c | 139 +-
 1 file changed, 106 insertions(+), 33 deletions(-)

diff --git 
a/target/linux/generic/files/drivers/platform/mikrotik/rb_hardconfig.c 
b/target/linux/generic/files/drivers/platform/mikrotik/rb_hardconfig.c
index 8861814be4..41dea98b5e 100644
--- a/target/linux/generic/files/drivers/platform/mikrotik/rb_hardconfig.c
+++ b/target/linux/generic/files/drivers/platform/mikrotik/rb_hardconfig.c
@@ -39,7 +39,7 @@
 
 #include "routerboot.h"
 
-#define RB_HARDCONFIG_VER  "0.05"
+#define RB_HARDCONFIG_VER  "0.06"
 #define RB_HC_PR_PFX   "[rb_hardconfig] "
 
 /* ID values for hardware settings */
@@ -76,6 +76,17 @@
 #define RB_HW_OPT_HAS_TS_FOR_ADC   BIT(22)
 #define RB_HW_OPT_HAS_PLC  BIT(29)
 
+/*
+ * Tag ID values for ERD data.
+ * Mikrotik used to pack all calibration data under a single tag id 0x1, but
+ * recently switched to a new scheme where each radio calibration gets a
+ * separate tag. The new scheme has tag id bit 15 always set and seems to be
+ * mutually exclusive with the old scheme.
+ */
+#define RB_WLAN_ERD_ID_SOLO0x0001
+#define RB_WLAN_ERD_ID_MULTI_8001  0x8001
+#define RB_WLAN_ERD_ID_MULTI_8201  0x8201
+
 static struct kobject *hc_kobj;
 static u8 *hc_buf; // ro buffer after init(): no locking required
 static size_t hc_buflen;
@@ -351,10 +362,22 @@ static ssize_t hc_wlan_data_bin_read(struct file *filp, 
struct kobject *kobj,
 loff_t off, size_t count);
 
 static struct hc_wlan_attr {
+   const u16 erd_tag_id;
struct bin_attribute battr;
u16 pld_ofs;
u16 pld_len;
-} hc_wlandata_battr = {
+} hc_wd_multi_battrs[] = {
+   {
+   .erd_tag_id = RB_WLAN_ERD_ID_MULTI_8001,
+   .battr = __BIN_ATTR(data_0, S_IRUSR, hc_wlan_data_bin_read, 
NULL, 0),
+   }, {
+   .erd_tag_id = RB_WLAN_ERD_ID_MULTI_8201,
+   .battr = __BIN_ATTR(data_2, S_IRUSR, hc_wlan_data_bin_read, 
NULL, 0),
+   }
+};
+
+static struct hc_wlan_attr hc_wd_solo_battr = {
+   .erd_tag_id = RB_WLAN_ERD_ID_SOLO,
.battr = __BIN_ATTR(wlan_data, S_IRUSR, hc_wlan_data_bin_read, NULL, 0),
 };
 
@@ -426,19 +449,19 @@ static struct hc_attr {
 /*
  * If the RB_ID_WLAN_DATA payload starts with RB_MAGIC_ERD, then past
  * that magic number the payload itself contains a routerboot tag node
- * locating the LZO-compressed calibration data at id 0x1.
+ * locating the LZO-compressed calibration data. So far this scheme is only
+ * known to use a single tag at id 0x1.
  */
-static int hc_wlan_data_unpack_erd(const u8 *inbuf, size_t inlen,
+static int hc_wlan_data_unpack_erd(const u16 tag_id, const u8 *inbuf, size_t 
inlen,
   void *outbuf, size_t *outlen)
 {
u16 lzo_ofs, lzo_len;
int ret;
 
/* Find embedded tag */
-   ret = routerboot_tag_find(inbuf, inlen, 0x1,// always id 1
- &lzo_ofs, &lzo_

[OpenWrt-Devel] [PATCH v2 1/4] ramips: fix RBM33G name

2018-07-29 Thread Thibaut VARÈNE
The device name is corrected to match the hardware-stored (in hard config
flash space) device name.

Tested-by: Tobias Schramm 
Signed-off-by: Thibaut VARÈNE 
---
 target/linux/ramips/dts/RBM33G.dts | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/target/linux/ramips/dts/RBM33G.dts 
b/target/linux/ramips/dts/RBM33G.dts
index cc6da267a2..612dc106ed 100644
--- a/target/linux/ramips/dts/RBM33G.dts
+++ b/target/linux/ramips/dts/RBM33G.dts
@@ -7,7 +7,7 @@
 
 / {
compatible = "mikrotik,rbm33g", "mediatek,mt7621-soc";
-   model = "MikroTik RBM33G";
+   model = "MikroTik RouterBOARD M33G";
 
aliases {
led-status = &led_usr;
-- 
2.13.6 (Apple Git-96)


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH v2 4/4] ramips: improve RBM11G partitioning

2018-07-29 Thread Thibaut VARÈNE
This patch improves faf64056ddd46992a75b1e277d94541c7251035c by updating
the partition scheme for the "RouterBoot" section of the flash.

This section is subdivided in several segments, as they are on ar71xx
RB devices, albeit with different offsets and sizes. The naming convention
from ar71xx has been preserved. The preferred 'fixed-partitions' DTS
node syntax is used, with nesting support as introduced in 2a598bbaa3.

Leave a note in DTS to explain how the original author selected the SPI speed.

Tested-by: Tobias Schramm 
Signed-off-by: Thibaut VARÈNE 
---
 target/linux/ramips/dts/RBM11G.dts | 59 +++---
 1 file changed, 43 insertions(+), 16 deletions(-)

diff --git a/target/linux/ramips/dts/RBM11G.dts 
b/target/linux/ramips/dts/RBM11G.dts
index c26c68350f..715d9dda48 100644
--- a/target/linux/ramips/dts/RBM11G.dts
+++ b/target/linux/ramips/dts/RBM11G.dts
@@ -90,29 +90,56 @@
#size-cells = <1>;
compatible = "jedec,spi-nor";
reg = <0>;
+   // XXX empiric value to obtain actual 10MHz SCK at the chip
spi-max-frequency = <3125000>;
 
-   partition@0 {
-   label = "routerboot";
-   reg = <0x00 0x00F000>;
-   read-only;
-   };
-
-   factory: partition@f000 {
-   label = "factory";
-   reg = <0x00F000 0x031000>;
-   read-only;
-   };
-
-   partition@4 {
-   label = "firmware";
-   reg = <0x04 0xFC>;
+   partitions {
+   compatible = "fixed-partitions";
+   #address-cells = <1>;
+   #size-cells = <1>;
+
+   partition@0 {
+   label = "RouterBoot";
+   reg = <0x0 0x4>;
+   read-only;
+   compatible = "fixed-partitions";
+   #address-cells = <1>;
+   #size-cells = <1>;
+
+   routerboot@0 {
+   reg = <0x0 0xf000>;
+   read-only;
+   };
+
+   hard_config: hard_config@f000 {
+   reg = <0xf000 0x1000>;
+   read-only;
+   };
+
+   routerboot2@1 {
+   reg = <0x1 0xf000>;
+   read-only;
+   };
+
+   soft_config@2 {
+   reg = <0x2 0x1000>;
+   };
+
+   bios@3 {
+   reg = <0x3 0x1000>;
+   read-only;
+   };
+   };
+
+   firmware@4 {
+   reg = <0x04 0xFC>;
+   };
};
};
 };
 
 ðernet {
-   mtd-mac-address = <&factory 0x0010>;
+   mtd-mac-address = <&hard_config 0x0010>;
mtd-mac-address-increment = <1>;
 };
 
-- 
2.13.6 (Apple Git-96)


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH v2 2/4] ramips: fix RBM33G partitioning

2018-07-29 Thread Thibaut VARÈNE
This patch improves 5684d087418d176cfdef4e045e1950ca7ba3b09f by correcting
the partition scheme for the "RouterBoot" section of the flash.

This section is subdivided in several segments, as they are on ar71xx
RB devices, albeit with different offsets and sizes. The naming convention
from ar71xx has been preserved. The preferred 'fixed-partitions' DTS
node syntax is used, with nesting support as introduced in 2a598bbaa3.

The OEM source code also define a "RouterBootFake" partition at the
beginning of the secondary flash chip: to avoid trouble if OEM ever makes
use of that space, it is also defined here.

The resulting partition scheme looks like this:
[   10.114241] m25p80 spi0.0: w25x40 (512 Kbytes)
[   10.118708] 1 fixed-partitions partitions found on MTD device spi0.0
[   10.125049] Creating 1 MTD partitions on "spi0.0":
[   10.129824] 0x-0x0004 : "RouterBoot"
[   10.136215] 5 fixed-partitions partitions found on MTD device RouterBoot
[   10.142894] Creating 5 MTD partitions on "RouterBoot":
[   10.148032] 0x-0xf000 : "routerboot"
[   10.154336] 0xf000-0x0001 : "hard_config"
[   10.160665] 0x0001-0x0001f000 : "routerboot2"
[   10.167046] 0x0002-0x00021000 : "soft_config"
[   10.173461] 0x0003-0x00031000 : "bios"
[   10.190191] m25p80 spi0.1: w25q128 (16384 Kbytes)
[   10.194950] 2 fixed-partitions partitions found on MTD device spi0.1
[   10.201271] Creating 2 MTD partitions on "spi0.1":
[   10.206071] 0x-0x0004 : "RouterBootFake"
[   10.212746] 0x0004-0x0100 : "firmware"
[   10.307216] 2 minor-fw partitions found on MTD device firmware
[   10.313044] 0x0004-0x0022 : "kernel"
[   10.319002] 0x0022-0x0100 : "rootfs"
[   10.324906] mtd: device 9 (rootfs) set to be root filesystem
[   10.330678] 1 squashfs-split partitions found on MTD device rootfs
[   10.336886] 0x00b4-0x0100 : "rootfs_data"

Leave a note in DTS to explain how the original author selected the SPI speed.

Tested-by: Tobias Schramm 
Signed-off-by: Thibaut VARÈNE 
---
 target/linux/ramips/dts/RBM33G.dts | 69 +-
 1 file changed, 54 insertions(+), 15 deletions(-)

diff --git a/target/linux/ramips/dts/RBM33G.dts 
b/target/linux/ramips/dts/RBM33G.dts
index 612dc106ed..a02d03818f 100644
--- a/target/linux/ramips/dts/RBM33G.dts
+++ b/target/linux/ramips/dts/RBM33G.dts
@@ -104,18 +104,44 @@
reg = <0>;
spi-max-frequency = <3125000>;
 
-   partition@0 {
-   label = "routerboot";
-   reg = <0x0 0xf000>;
-   read-only;
+   partitions {
+   compatible = "fixed-partitions";
+   #address-cells = <1>;
+   #size-cells = <1>;
+
+   partition@0 {
+   label = "RouterBoot";
+   reg = <0x0 0x4>;
+   read-only;
+   compatible = "fixed-partitions";
+   #address-cells = <1>;
+   #size-cells = <1>;
+
+   routerboot@0 {
+   reg = <0x0 0xf000>;
+   read-only;
+   };
+
+   hard_config: hard_config@f000 {
+   reg = <0xf000 0x1000>;
+   read-only;
+   };
+
+   routerboot2@1 {
+   reg = <0x1 0xf000>;
+   read-only;
+   };
+
+   soft_config@2 {
+   reg = <0x2 0x1000>;
+   };
+
+   bios@3 {
+   reg = <0x3 0x1000>;
+   read-only;
+   };
+   };
};
-
-   factory: partition@f000 {
-   label = "factory";
-   reg = <0xf000 0x71000>;
-   read-only;
-   };
-
};
 
w25q128@0 {
@@ -123,17 +149,30 @@
#size-cells = <1>;
compatible = "jedec,spi-nor";
reg = <1>;
+   

[OpenWrt-Devel] [PATCH v2 3/4] ramips: fix RBM11G name

2018-07-29 Thread Thibaut VARÈNE
The device name is corrected to match the hardware-stored (in hard config
flash space) device name.

Tested-by: Tobias Schramm 
Signed-off-by: Thibaut VARÈNE 
---
 target/linux/ramips/dts/RBM11G.dts | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/target/linux/ramips/dts/RBM11G.dts 
b/target/linux/ramips/dts/RBM11G.dts
index f312093a22..c26c68350f 100644
--- a/target/linux/ramips/dts/RBM11G.dts
+++ b/target/linux/ramips/dts/RBM11G.dts
@@ -7,7 +7,7 @@
 
 / {
compatible = "mikrotik,rbm11g", "mediatek,mt7621-soc";
-   model = "MikroTik RBM11G";
+   model = "MikroTik RouterBOARD M11G";
 
aliases {
led-status = &led_usr;
-- 
2.13.6 (Apple Git-96)


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [RFT] [PATCH] ramips: add RB750Gr3 native support

2018-07-29 Thread Thibaut VARÈNE
This patch attempts to support the MikroTik RouterBOARD 750Gr3 "natively",
i.e. without reflashing the bootloader.

Installation through RouterBoot probably follows the usual MikroTik method
(force tftp booting via long press on the reset button, boot openwrt
initramfs, and sysupgrade from there).

I don't own the hardware, this code is untested.

Signed-off-by: Thibaut VARÈNE 
---
 .../linux/ramips/base-files/etc/board.d/02_network |   2 +-
 target/linux/ramips/base-files/lib/ramips.sh   |   3 -
 .../ramips/base-files/lib/upgrade/platform.sh  |   3 +-
 target/linux/ramips/dts/RB750Gr3.dts   | 105 ++---
 target/linux/ramips/image/mt7621.mk|  15 ++-
 5 files changed, 79 insertions(+), 49 deletions(-)

diff --git a/target/linux/ramips/base-files/etc/board.d/02_network 
b/target/linux/ramips/base-files/etc/board.d/02_network
index 818a919f41..e47c3cd5c9 100755
--- a/target/linux/ramips/base-files/etc/board.d/02_network
+++ b/target/linux/ramips/base-files/etc/board.d/02_network
@@ -201,9 +201,9 @@ ramips_setup_interfaces()
jhr-n805r|\
jhr-n825r|\
jhr-n926r|\
+   mikrotik,rb750gr3|\
mikrotik,rbm33g|\
mzk-wdpr|\
-   rb750gr3|\
rt-n14u|\
tplink,c20-v4|\
tplink,c50-v3|\
diff --git a/target/linux/ramips/base-files/lib/ramips.sh 
b/target/linux/ramips/base-files/lib/ramips.sh
index 5741cbd2ee..2dd0388426 100755
--- a/target/linux/ramips/base-files/lib/ramips.sh
+++ b/target/linux/ramips/base-files/lib/ramips.sh
@@ -418,9 +418,6 @@ ramips_board_detect() {
*"R6220")
name="r6220"
;;
-   *"RB750Gr3")
-   name="rb750gr3"
-   ;;
*"RE350 v1")
name="re350-v1"
;;
diff --git a/target/linux/ramips/base-files/lib/upgrade/platform.sh 
b/target/linux/ramips/base-files/lib/upgrade/platform.sh
index a7f9c1722e..818d854464 100755
--- a/target/linux/ramips/base-files/lib/upgrade/platform.sh
+++ b/target/linux/ramips/base-files/lib/upgrade/platform.sh
@@ -131,7 +131,6 @@ platform_check_image() {
psr-680w|\
px-4885-4M|\
px-4885-8M|\
-   rb750gr3|\
re6500|\
rp-n53|\
rt5350f-olinuxino|\
@@ -301,6 +300,7 @@ platform_check_image() {
nand_do_platform_check "$board" "$1"
return $?;
;;
+   mikrotik,rb750gr3|\
mikrotik,rbm11g|\
mikrotik,rbm33g|\
re350-v1)
@@ -328,6 +328,7 @@ platform_pre_upgrade() {
local board=$(board_name)
 
case "$board" in
+   mikrotik,rb750gr3|\
mikrotik,rbm11g|\
mikrotik,rbm33g)
[ -z "$(rootfs_type)" ] && mtd erase firmware
diff --git a/target/linux/ramips/dts/RB750Gr3.dts 
b/target/linux/ramips/dts/RB750Gr3.dts
index 563a537268..6a163734ad 100644
--- a/target/linux/ramips/dts/RB750Gr3.dts
+++ b/target/linux/ramips/dts/RB750Gr3.dts
@@ -7,10 +7,10 @@
 
 / {
compatible = "mikrotik,rb750gr3", "mediatek,mt7621-soc";
-   model = "MikroTik RB750Gr3";
+   model = "MikroTik RouterBOARD 750Gr3";
 
aliases {
-   led-status = &led_pwr;
+   led-status = &led_usr;
};
 
memory@0 {
@@ -19,18 +19,19 @@
};
 
chosen {
-   bootargs = "console=ttyS0,57600";
+   bootargs = "console=ttyS0,115200";
};
 
gpio-leds {
compatible = "gpio-leds";
 
-   led_pwr: pwr {
+   pwr {
label = "rb750gr3:blue:pwr";
gpios = <&gpio0 16 GPIO_ACTIVE_HIGH>;
+   default-state = "on";
};
 
-   usr {
+   led_usr: usr {
label = "rb750gr3:green:usr";
gpios = <&gpio0 0 GPIO_ACTIVE_HIGH>;
};
@@ -45,7 +46,7 @@
mode {
label = "mode";
gpios = <&gpio0 13 GPIO_ACTIVE_LOW>;
-   linux,code = ;
+   linux,code = ;
};
 
res {
@@ -66,9 +67,21 @@
};
 
usb {
-   gpio-export,name = "usb";
+   gpio-export,name = "usb_power_off";
gpio-export,output = <1>;
-   gpios = <&gpio0 12 GPIO_ACTIVE_HIGH>;
+   gpios = <&gpio0 12 GPIO_ACTIVE_LOW>;
+   };
+
+   // Used to enable power-over-ethernet passthrough to eth4 
(according to OEM source).
+   poe

[OpenWrt-Devel] [PATCH 0/5] several fixes for mach-rbspi.c / correct support for wAP R

2018-07-29 Thread Thibaut VARÈNE
Repost of PR#1181

Thibaut VARÈNE (5):
  ar71xx: rbspi: clarify USB power gpios action
  ar71xx: rbspi: fix RB wAP AC gpio conflict and LED
  ar71xx: rbspi: mark rb911L user led as active low
  ar71xx: add missing diag LED support for RB wAP 2nD
  ar71xx: improve MikroTik wAP R support

 target/linux/ar71xx/base-files/etc/board.d/01_leds |   3 +
 target/linux/ar71xx/base-files/etc/diag.sh |   7 +-
 .../ar71xx/files/arch/mips/ath79/mach-rbspi.c  | 104 -
 3 files changed, 90 insertions(+), 24 deletions(-)

-- 
2.13.6 (Apple Git-96)


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH 4/5] ar71xx: add missing diag LED support for RB wAP 2nD

2018-07-29 Thread Thibaut VARÈNE
3b15eb06c366cf3805590a61f22e966a95bf8101 did not include diag.sh
edit

Signed-off-by: Thibaut VARÈNE 
---
 target/linux/ar71xx/base-files/etc/diag.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/target/linux/ar71xx/base-files/etc/diag.sh 
b/target/linux/ar71xx/base-files/etc/diag.sh
index 280b83b413..efb1305aec 100644
--- a/target/linux/ar71xx/base-files/etc/diag.sh
+++ b/target/linux/ar71xx/base-files/etc/diag.sh
@@ -375,7 +375,8 @@ get_status_led() {
rb-962uigs-5hact2hnt|\
rb-lhg-5nd|\
rb-map-2nd|\
-   rb-mapl-2nd)
+   rb-mapl-2nd|\
+   rb-wap-2nd)
status_led="rb:green:user"
;;
rb-951ui-2hnd)
-- 
2.13.6 (Apple Git-96)


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH 3/5] ar71xx: rbspi: mark rb911L user led as active low

2018-07-29 Thread Thibaut VARÈNE
The active_low flag was missing for the user LED. This LED is open drain
(confirmed in OEM source) and open drain only makes sense for active low
GPIOs.

The two wireless LEDs mentioned in the comments are also #defined for
future reference.

Signed-off-by: Thibaut VARÈNE 
Tested-by: Ryan Mounce 
---
 target/linux/ar71xx/files/arch/mips/ath79/mach-rbspi.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/target/linux/ar71xx/files/arch/mips/ath79/mach-rbspi.c 
b/target/linux/ar71xx/files/arch/mips/ath79/mach-rbspi.c
index ad67c6e869..4aff7df55b 100644
--- a/target/linux/ar71xx/files/arch/mips/ath79/mach-rbspi.c
+++ b/target/linux/ar71xx/files/arch/mips/ath79/mach-rbspi.c
@@ -255,6 +255,8 @@ static struct gpio_led rb952_leds[] __initdata = {
 
 
 /* RB 962UiGS-5HacT2HnT gpios */
+#define RB962_WIFI_LED_1   1
+#define RB962_WIFI_LED_2   2
 #define RB962_GPIO_POE_STATUS  2
 #define RB962_GPIO_POE_POWER   3
 #define RB962_GPIO_LED_USER12
@@ -520,7 +522,7 @@ static struct platform_device rbwapgsc_phy_device = {
 #define RB911L_GPIO_LED_ETH20
 #define RB911L_GPIO_LED_POWER  11
 #define RB911L_GPIO_LED_USER   3
-#define RB911L_GPIO_PIN_HOLE   14 /* for reference */
+#define RB911L_GPIO_PIN_HOLE   14 /* for reference, active low */
 
 static struct gpio_led rb911l_leds[] __initdata = {
{
@@ -551,6 +553,7 @@ static struct gpio_led rb911l_leds[] __initdata = {
.name = "rb:green:power",
.gpio = RB911L_GPIO_LED_POWER,
.default_state = LEDS_GPIO_DEFSTATE_ON,
+   .active_low = 1,
.open_drain = 1,
}, {
.name = "rb:green:user",
-- 
2.13.6 (Apple Git-96)


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH 2/5] ar71xx: rbspi: fix RB wAP AC gpio conflict and LED

2018-07-29 Thread Thibaut VARÈNE
e15c63a37574bd15ce3a6636c2f04741ab76f7b9 introduced code that was trying
to register GPIO 1 as both an LED and a button. The OEM source makes it
clear that LED1 is not wired to the SoC GPIOs. GPIO 1 is the reset button.

Furthermore the (green) power led default state should also be defined,
(matching OEM source), and it should be used by diag.sh since it's
currently the only software-controllable LED.

This patch fixes these issues and renames the corresponding #defines for
clarity

Signed-off-by: Thibaut VARÈNE 
---
 target/linux/ar71xx/base-files/etc/diag.sh |  3 ++-
 target/linux/ar71xx/files/arch/mips/ath79/mach-rbspi.c | 17 +++--
 2 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/target/linux/ar71xx/base-files/etc/diag.sh 
b/target/linux/ar71xx/base-files/etc/diag.sh
index d3cdc81b39..280b83b413 100644
--- a/target/linux/ar71xx/base-files/etc/diag.sh
+++ b/target/linux/ar71xx/base-files/etc/diag.sh
@@ -384,7 +384,8 @@ get_status_led() {
rb-912uag-2hpnd|\
rb-912uag-5hpnd|\
rb-sxt2n|\
-   rb-sxt5n)
+   rb-sxt5n|\
+   rb-wapg-5hact2hnd)
status_led="rb:green:power"
;;
re355|\
diff --git a/target/linux/ar71xx/files/arch/mips/ath79/mach-rbspi.c 
b/target/linux/ar71xx/files/arch/mips/ath79/mach-rbspi.c
index f14b078b2c..ad67c6e869 100644
--- a/target/linux/ar71xx/files/arch/mips/ath79/mach-rbspi.c
+++ b/target/linux/ar71xx/files/arch/mips/ath79/mach-rbspi.c
@@ -478,10 +478,10 @@ static struct gpio_led rblhg_leds[] __initdata = {
 };
 
 /* RB w APG-5HacT2HnD (wAP AC) gpios*/
-#define RBWAPGSC_LED1  1
-#define RBWAPGSC_LED2  8
-#define RBWAPGSC_LED3  9
-#define RBWAPGSC_POWERLED  16
+#define RBWAPGSC_WIFI_LED_11
+#define RBWAPGSC_WIFI_LED_28
+#define RBWAPGSC_WIFI_LED_39
+#define RBWAPGSC_GPIO_LED_POWER16
 #define RBWAPGSC_GPIO_BTN_RESET1
 #define RBWAPGSC_GPIO_MDIO_MDC 12
 #define RBWAPGSC_GPIO_MDIO_DATA11
@@ -489,13 +489,10 @@ static struct gpio_led rblhg_leds[] __initdata = {
 
 static struct gpio_led rbwapgsc_leds[] __initdata = {
{
-   .name = "rb:green:led1",
-   .gpio = RBWAPGSC_LED1,
-   .active_low = 1,
-   },{
-   .name = "rb:blue:power",
-   .gpio = RBWAPGSC_POWERLED,
+   .name = "rb:green:power",
+   .gpio = RBWAPGSC_GPIO_LED_POWER,
.active_low = 1,
+   .default_state = LEDS_GPIO_DEFSTATE_ON,
},
 };
 
-- 
2.13.6 (Apple Git-96)


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH 1/5] ar71xx: rbspi: clarify USB power gpios action

2018-07-29 Thread Thibaut VARÈNE
The gpios that control power toggle for USB on the RouterBOARD devices
are active low _off_ switches.

When they are active (low), power is off. When they are inactive
(high), power is on.

Rename GPIO defines, set gpios to GPIOF_ACTIVE_LOW for consistency and
reflect their true action in the display name. This brings openwrt code
in line with OEM.

Signed-off-by: Thibaut VARÈNE 
Tested-by: Ryan Mounce 
---
 .../linux/ar71xx/files/arch/mips/ath79/mach-rbspi.c   | 19 +--
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/target/linux/ar71xx/files/arch/mips/ath79/mach-rbspi.c 
b/target/linux/ar71xx/files/arch/mips/ath79/mach-rbspi.c
index 2997018aa3..f14b078b2c 100644
--- a/target/linux/ar71xx/files/arch/mips/ath79/mach-rbspi.c
+++ b/target/linux/ar71xx/files/arch/mips/ath79/mach-rbspi.c
@@ -213,7 +213,7 @@ static struct gpio_led rbhapl_leds[] __initdata = {
 #define RB952_GPIO_POE_POWER   14
 #define RB952_GPIO_POE_STATUS  12
 #define RB952_GPIO_BTN_RESET   16
-#define RB952_GPIO_USB_POWER   RBSPI_SSR_GPIO(RB952_SSR_BIT_USB_POWER)
+#define RB952_GPIO_USB_PWROFF  RBSPI_SSR_GPIO(RB952_SSR_BIT_USB_POWER)
 #define RB952_GPIO_LED_LAN1RBSPI_SSR_GPIO(RB952_SSR_BIT_LED_LAN1)
 #define RB952_GPIO_LED_LAN2RBSPI_SSR_GPIO(RB952_SSR_BIT_LED_LAN2)
 #define RB952_GPIO_LED_LAN3RBSPI_SSR_GPIO(RB952_SSR_BIT_LED_LAN3)
@@ -258,7 +258,7 @@ static struct gpio_led rb952_leds[] __initdata = {
 #define RB962_GPIO_POE_STATUS  2
 #define RB962_GPIO_POE_POWER   3
 #define RB962_GPIO_LED_USER12
-#define RB962_GPIO_USB_POWER   13
+#define RB962_GPIO_USB_PWROFF  13
 #define RB962_GPIO_BTN_RESET   20
 
 static struct gpio_led rb962_leds_gpio[] __initdata = {
@@ -388,7 +388,7 @@ static struct gpio_led rbcap_leds[] __initdata = {
 #define RBMAP_GPIO_LED_POWER   4
 #define RBMAP_GPIO_POE_POWER   14
 #define RBMAP_GPIO_POE_STATUS  12
-#define RBMAP_GPIO_USB_POWER   RBSPI_SSR_GPIO(RBMAP_SSR_BIT_USB_POWER)
+#define RBMAP_GPIO_USB_PWROFF  RBSPI_SSR_GPIO(RBMAP_SSR_BIT_USB_POWER)
 #define RBMAP_GPIO_LED_LAN1RBSPI_SSR_GPIO(RBMAP_SSR_BIT_LED_LAN1)
 #define RBMAP_GPIO_LED_LAN2RBSPI_SSR_GPIO(RBMAP_SSR_BIT_LED_LAN2)
 #define RBMAP_GPIO_LED_POEORBSPI_SSR_GPIO(RBMAP_SSR_BIT_LED_POEO)
@@ -828,9 +828,9 @@ static void __init rbspi_952_750r2_setup(u32 flags)
rbspi_network_setup(flags, 1, 5, 6);
 
if (flags & RBSPI_HAS_USB)
-   gpio_request_one(RB952_GPIO_USB_POWER,
+   gpio_request_one(RB952_GPIO_USB_PWROFF, GPIOF_ACTIVE_LOW |
GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
-   "USB power");
+   "USB power off");
 
if (flags & RBSPI_HAS_POE)
gpio_request_one(RB952_GPIO_POE_POWER,
@@ -938,9 +938,9 @@ static void __init rb962_setup(void)
rbspi_wlan_init(1, 7);
 
if (flags & RBSPI_HAS_USB)
-   gpio_request_one(RB962_GPIO_USB_POWER,
+   gpio_request_one(RB962_GPIO_USB_PWROFF, GPIOF_ACTIVE_LOW |
GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
-   "USB power");
+   "USB power off");
 
/* PoE output GPIO is inverted, set GPIOF_ACTIVE_LOW for consistency */
if (flags & RBSPI_HAS_POE)
@@ -1047,12 +1047,11 @@ static void __init rbmap_setup(void)
GPIOF_OUT_INIT_LOW | GPIOF_EXPORT_DIR_FIXED,
"POE power");
 
-   /* USB power GPIO is inverted, set GPIOF_ACTIVE_LOW for consistency */
if (flags & RBSPI_HAS_USB)
-   gpio_request_one(RBMAP_GPIO_USB_POWER,
+   gpio_request_one(RBMAP_GPIO_USB_PWROFF,
GPIOF_OUT_INIT_HIGH | GPIOF_ACTIVE_LOW |
GPIOF_EXPORT_DIR_FIXED,
-   "USB power");
+   "USB power off");
 
ath79_register_leds_gpio(-1, ARRAY_SIZE(rbmap_leds), rbmap_leds);
 
-- 
2.13.6 (Apple Git-96)


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH 5/5] ar71xx: improve MikroTik wAP R support

2018-07-29 Thread Thibaut VARÈNE
81d446b045176e3e25bb0ef74e3d060b51a0a353 introduced incomplete
support for this device.

This patch attempts to correct the situation based on OEM source
code.

LED1-3 are GSM mode on OFW (2G/3G/4G) hence unassigned here.

Signed-off-by: Thibaut VARÈNE 
Tested-by: David Ehrmann 
---
 target/linux/ar71xx/base-files/etc/board.d/01_leds |  3 ++
 target/linux/ar71xx/base-files/etc/diag.sh |  3 +-
 .../ar71xx/files/arch/mips/ath79/mach-rbspi.c  | 63 +-
 3 files changed, 67 insertions(+), 2 deletions(-)

diff --git a/target/linux/ar71xx/base-files/etc/board.d/01_leds 
b/target/linux/ar71xx/base-files/etc/board.d/01_leds
index 11299dcb92..b0f4975e5c 100755
--- a/target/linux/ar71xx/base-files/etc/board.d/01_leds
+++ b/target/linux/ar71xx/base-files/etc/board.d/01_leds
@@ -680,6 +680,9 @@ rb-wap-2nd)
ucidef_set_led_timer "user" "USER" "rb:green:user" "1000" "1000"
ucidef_set_led_wlan "wlan" "WLAN" "rb:green:wlan" "phy0tpt"
;;
+rb-wapr-2nd)
+   ucidef_set_led_wlan "wlan" "WLAN" "rb:green:user" "phy0tpt"
+   ;;
 re355|\
 re450)
ucidef_set_led_netdev "lan_data" "LAN Data" "$board:green:lan_data" 
"eth0" "tx rx"
diff --git a/target/linux/ar71xx/base-files/etc/diag.sh 
b/target/linux/ar71xx/base-files/etc/diag.sh
index efb1305aec..129df16097 100644
--- a/target/linux/ar71xx/base-files/etc/diag.sh
+++ b/target/linux/ar71xx/base-files/etc/diag.sh
@@ -376,7 +376,8 @@ get_status_led() {
rb-lhg-5nd|\
rb-map-2nd|\
rb-mapl-2nd|\
-   rb-wap-2nd)
+   rb-wap-2nd|\
+   rb-wapr-2nd)
status_led="rb:green:user"
;;
rb-951ui-2hnd)
diff --git a/target/linux/ar71xx/files/arch/mips/ath79/mach-rbspi.c 
b/target/linux/ar71xx/files/arch/mips/ath79/mach-rbspi.c
index 4aff7df55b..cff69092c4 100644
--- a/target/linux/ar71xx/files/arch/mips/ath79/mach-rbspi.c
+++ b/target/linux/ar71xx/files/arch/mips/ath79/mach-rbspi.c
@@ -594,6 +594,36 @@ static struct gpio_led rb931_leds[] __initdata = {
},
 };
 
+/* RB wAP R-2nD (wAP R) gpios*/
+#define RBWAPR_GPIO_LED_USER   14
+#define RBWAPR_GPIO_LED1   12
+#define RBWAPR_GPIO_LED2   13
+#define RBWAPR_GPIO_LED3   3
+#define RBWAPR_GPIO_PCIE_PWROFF15
+#define RBWAPR_GPIO_CONTROL10
+#define RBWAPR_GPIO_BTN_RESET  16
+
+static struct gpio_led rbwapr_leds[] __initdata = {
+   {
+   .name = "rb:green:user",
+   .gpio = RBWAPR_GPIO_LED_USER,
+   .active_low = 0,
+   },{
+   .name = "rb:green:led1",
+   .gpio = RBWAPR_GPIO_LED1,
+   .active_low = 1,
+   },{
+   .name = "rb:green:led2",
+   .gpio = RBWAPR_GPIO_LED2,
+   .active_low = 1,
+   },{
+   .name = "rb:green:led3",
+   .gpio = RBWAPR_GPIO_LED3,
+   .active_low = 0,
+   },
+};
+
+
 static struct gen_74x164_chip_platform_data rbspi_ssr_data = {
.base = RBSPI_SSR_GPIO_BASE,
.num_registers = 1,
@@ -1170,6 +1200,37 @@ static void __init rb931_setup(void)
rb931_gpio_keys);
 }
 
+/*
+ * Init the wAP R hardware.
+ * The wAP R-2nD has a single ethernet port and a mini PCIe slot.
+ * The OEM source shows it has usb (used over PCIe for LTE devices),
+ * and the 'control' GPIO is assumed to be an output pin not tied to an LED.
+ */
+static void __init rbwapr_setup(void)
+{
+   u32 flags = RBSPI_HAS_WLAN0 | RBSPI_HAS_USB | RBSPI_HAS_PCI;
+
+   if (!rbspi_platform_setup())
+   return;
+
+   rbspi_peripherals_setup(flags);
+
+   /* GMAC1 is HW MAC, WLAN0 MAC is HW MAC + 1 */
+   rbspi_network_setup(flags, 0, 1, 0);
+
+   ath79_register_leds_gpio(-1, ARRAY_SIZE(rbwapr_leds), rbwapr_leds);
+
+   gpio_request_one(RBWAPR_GPIO_PCIE_PWROFF, GPIOF_OUT_INIT_HIGH |
+   GPIOF_ACTIVE_LOW | GPIOF_EXPORT_DIR_FIXED,
+   "PCIE power off");
+
+   gpio_request_one(RBWAPR_GPIO_CONTROL, GPIOF_OUT_INIT_LOW |
+   GPIOF_ACTIVE_LOW | GPIOF_EXPORT_DIR_FIXED,
+   "control");
+
+   rbspi_register_reset_button(RBWAPR_GPIO_BTN_RESET);
+}
+
 MIPS_MACHINE_NONAME(ATH79_MACH_RB_MAPL, "map-hb", rbmapl_setup);
 MIPS_MACHINE_NONAME(ATH79_MACH_RB_941, "H951L", rbhapl_setup);
 MIPS_MACHINE_NONAME(ATH79_MACH_RB_911L, "911L", rb911l_setup);
@@ -1178,7 +1239,7 @@ MIPS_MACHINE_NONAME(ATH79_MACH_RB_962, "962", 
rb962_setup);
 MIPS_MACHINE_NONAME(ATH79_MACH_RB_750UPR2, "750-hb", rb750upr2_setup);
 MIPS_MACHINE_NONAME(ATH79_MACH_RB_LHG5, "lhg", rblhg_setup);
 MI

[OpenWrt-Devel] [PATCH] [18.06] ar71xx: define switch for rb-952ui-5ac2nd

2018-07-30 Thread Thibaut VARÈNE
QCA9533 built-in switch can be configured

Tested-by: Thibaut VARÈNE 
Signed-off-by: Thibaut VARÈNE 
---
 target/linux/ar71xx/base-files/etc/board.d/02_network | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/target/linux/ar71xx/base-files/etc/board.d/02_network 
b/target/linux/ar71xx/base-files/etc/board.d/02_network
index b0076366bc..f650b4cd04 100755
--- a/target/linux/ar71xx/base-files/etc/board.d/02_network
+++ b/target/linux/ar71xx/base-files/etc/board.d/02_network
@@ -169,7 +169,6 @@ ar71xx_setup_interfaces()
pb42|\
pb44|\
rb-951ui-2hnd|\
-   rb-952ui-5ac2nd|\
routerstation|\
tl-wr710n|\
tl-wr720n-v3|\
@@ -182,7 +181,8 @@ ar71xx_setup_interfaces()
rb-750-r2|\
rb-750p-pbr2|\
rb-750up-r2|\
-   rb-951ui-2nd)
+   rb-951ui-2nd|\
+   rb-952ui-5ac2nd)
ucidef_set_interfaces_lan_wan "eth1.1" "eth0"
ucidef_add_switch "switch0" \
"0@eth1" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1"
-- 
2.13.6 (Apple Git-96)


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH] base-files: make wifi report unknown command

2018-08-03 Thread Thibaut VARÈNE
Avoid having /sbin/wifi silently ignore unknown keywords and execute
"enable"; instead display the help message and exit with an error.

Signed-off-by: Thibaut VARÈNE 
---
 package/base-files/files/sbin/wifi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/package/base-files/files/sbin/wifi 
b/package/base-files/files/sbin/wifi
index 83befc0d6f..09e483ec55 100755
--- a/package/base-files/files/sbin/wifi
+++ b/package/base-files/files/sbin/wifi
@@ -241,5 +241,5 @@ case "$1" in
reload) wifi_reload "$2";;
reload_legacy) wifi_reload_legacy "$2";;
--help|help) usage;;
-   *) ubus call network reload; wifi_updown "enable" "$2";;
+   *) usage; exit 1;;
 esac
-- 
2.13.6 (Apple Git-96)


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH v3 0/2] ramips: fix RBMxxG partitioning

2018-08-04 Thread Thibaut VARÈNE
[Patchset repost after master rebasing]

The current DTS partitioning is wrong.
The RouterBoot partition table is static on device, and a splitter is not
feasible (bootloader{1,2} and bios are raw binaries without a signature).
This patchset relies on Rafał's nested "fixed-partitions" as introduced in
2a598bbaa3.
This patchset follows node name policy set by 6dd94c2781.

Thibaut VARÈNE (2):
  ramips: fix RBM33G partitioning
  ramips: fix RBM11G partitioning

 target/linux/ramips/dts/RBM11G.dts | 43 +++-
 target/linux/ramips/dts/RBM33G.dts | 50 +-
 2 files changed, 71 insertions(+), 22 deletions(-)

-- 
2.13.6 (Apple Git-96)


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH v3 2/2] ramips: fix RBM11G partitioning

2018-08-04 Thread Thibaut VARÈNE
This patch improves faf64056ddd46992a75b1e277d94541c7251035c by correcting
the partition scheme for the "RouterBoot" section of the flash.

The partition scheme initially submitted is incorrect and does not reflect
the actual flash structure.

The "RouterBoot" section (name matching OEM) is subdivided in several
static segments, as they are on ar71xx RB devices albeit with different
offsets and sizes.
The naming convention from ar71xx has been preserved, except for the
bootloaders which are named "bootloader1" and "bootloader2" to avoid
confusion with the master "RouterBoot" partition.
The preferred 'fixed-partitions' DTS node syntax is used, with nesting
support as introduced in 2a598bbaa3.
"partition" is used for node names, with associated "label" to match
policy set by 6dd94c2781.

Leave a note in DTS to explain how the original author selected the SPI speed.

Tested-by: Tobias Schramm 
Signed-off-by: Thibaut VARÈNE 
---
 target/linux/ramips/dts/RBM11G.dts | 45 ++
 1 file changed, 36 insertions(+), 9 deletions(-)

diff --git a/target/linux/ramips/dts/RBM11G.dts 
b/target/linux/ramips/dts/RBM11G.dts
index 800f230d95..41dabdd1a3 100644
--- a/target/linux/ramips/dts/RBM11G.dts
+++ b/target/linux/ramips/dts/RBM11G.dts
@@ -86,6 +86,7 @@
w25q128@0 {
compatible = "jedec,spi-nor";
reg = <0>;
+   // XXX empiric value to obtain actual 10MHz SCK at the chip
spi-max-frequency = <3125000>;
 
partitions {
@@ -94,15 +95,41 @@
#size-cells = <1>;
 
partition@0 {
-   label = "routerboot";
-   reg = <0x00 0x00F000>;
-   read-only;
-   };
-
-   factory: partition@f000 {
-   label = "factory";
-   reg = <0x00F000 0x031000>;
+   label = "RouterBoot";
+   reg = <0x0 0x4>;
read-only;
+   compatible = "fixed-partitions";
+   #address-cells = <1>;
+   #size-cells = <1>;
+
+   partition@0 {
+   label = "bootloader1";
+   reg = <0x0 0xf000>;
+   read-only;
+   };
+
+   hard_config: partition@f000 {
+   label = "hard_config";
+   reg = <0xf000 0x1000>;
+   read-only;
+   };
+
+   partition@1 {
+   label = "bootloader2";
+   reg = <0x1 0xf000>;
+   read-only;
+   };
+
+   partition@2 {
+   label = "soft_config";
+   reg = <0x2 0x1000>;
+   };
+
+   partition@3 {
+   label = "bios";
+   reg = <0x3 0x1000>;
+   read-only;
+   };
};
 
partition@4 {
@@ -114,7 +141,7 @@
 };
 
 ðernet {
-   mtd-mac-address = <&factory 0x0010>;
+   mtd-mac-address = <&hard_config 0x0010>;
mtd-mac-address-increment = <1>;
 };
 
-- 
2.13.6 (Apple Git-96)


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH v3 1/2] ramips: fix RBM33G partitioning

2018-08-04 Thread Thibaut VARÈNE
This patch improves 5684d087418d176cfdef4e045e1950ca7ba3b09f by correcting
the partition scheme for the "RouterBoot" section of the flash.

The partition scheme initially submitted is incorrect and does not reflect
the actual flash structure.

The "RouterBoot" section (name matching OEM) is subdivided in several
static segments, as they are on ar71xx RB devices albeit with different
offsets and sizes.
The naming convention from ar71xx has been preserved, except for the
bootloaders which are named "bootloader1" and "bootloader2" to avoid
confusion with the master "RouterBoot" partition.
The preferred 'fixed-partitions' DTS node syntax is used, with nesting
support as introduced in 2a598bbaa3.
"partition" is used for node names, with associated "label" to match
policy set by 6dd94c2781.

The OEM source code also define a "RouterBootFake" partition at the
beginning of the secondary flash chip: to avoid trouble if OEM ever makes
use of that space, it is also defined here.

The resulting partition scheme looks like this:
[   10.114241] m25p80 spi0.0: w25x40 (512 Kbytes)
[   10.118708] 1 fixed-partitions partitions found on MTD device spi0.0
[   10.125049] Creating 1 MTD partitions on "spi0.0":
[   10.129824] 0x-0x0004 : "RouterBoot"
[   10.136215] 5 fixed-partitions partitions found on MTD device RouterBoot
[   10.142894] Creating 5 MTD partitions on "RouterBoot":
[   10.148032] 0x-0xf000 : "bootloader1"
[   10.154336] 0xf000-0x0001 : "hard_config"
[   10.160665] 0x0001-0x0001f000 : "bootloader2"
[   10.167046] 0x0002-0x00021000 : "soft_config"
[   10.173461] 0x0003-0x00031000 : "bios"
[   10.190191] m25p80 spi0.1: w25q128 (16384 Kbytes)
[   10.194950] 2 fixed-partitions partitions found on MTD device spi0.1
[   10.201271] Creating 2 MTD partitions on "spi0.1":
[   10.206071] 0x-0x0004 : "RouterBootFake"
[   10.212746] 0x0004-0x0100 : "firmware"
[   10.307216] 2 minor-fw partitions found on MTD device firmware
[   10.313044] 0x0004-0x0022 : "kernel"
[   10.319002] 0x0022-0x0100 : "rootfs"
[   10.324906] mtd: device 9 (rootfs) set to be root filesystem
[   10.330678] 1 squashfs-split partitions found on MTD device rootfs
[   10.336886] 0x00b4-0x0100 : "rootfs_data"

Leave a note in DTS to explain how the original author selected the SPI speed.

Tested-by: Tobias Schramm 
Signed-off-by: Thibaut VARÈNE 
---
 target/linux/ramips/dts/RBM33G.dts | 52 +++---
 1 file changed, 43 insertions(+), 9 deletions(-)

diff --git a/target/linux/ramips/dts/RBM33G.dts 
b/target/linux/ramips/dts/RBM33G.dts
index 65560ab821..db4d1599d7 100644
--- a/target/linux/ramips/dts/RBM33G.dts
+++ b/target/linux/ramips/dts/RBM33G.dts
@@ -106,15 +106,41 @@
#size-cells = <1>;
 
partition@0 {
-   label = "routerboot";
-   reg = <0x0 0xf000>;
-   read-only;
-   };
-
-   factory: partition@f000 {
-   label = "factory";
-   reg = <0xf000 0x71000>;
+   label = "RouterBoot";
+   reg = <0x0 0x4>;
read-only;
+   compatible = "fixed-partitions";
+   #address-cells = <1>;
+   #size-cells = <1>;
+
+   partition@0 {
+   label = "bootloader1";
+   reg = <0x0 0xf000>;
+   read-only;
+   };
+
+   hard_config: partition@f000 {
+   label = "hard_config";
+   reg = <0xf000 0x1000>;
+   read-only;
+   };
+
+   partition@1 {
+   label = "bootloader2";
+   reg = <0x1 0xf000>;
+   read-only;
+   };
+
+   partition@2 {
+   label = "soft_config";
+   reg = <0x2 0x1000>;
+

[OpenWrt-Devel] [RTF] [PATCH v2] ramips: add RB750Gr3 native support

2018-08-04 Thread Thibaut VARÈNE
[Repost after rebasing on current master]

This patch attempts to support the MikroTik RouterBOARD 750Gr3 "natively",
i.e. without reflashing the bootloader.

Installation through RouterBoot probably follows the usual MikroTik method
(force tftp booting via long press on the reset button, boot openwrt
initramfs, and sysupgrade from there).

I don't own the hardware, this code is untested.

Signed-off-by: Thibaut VARÈNE 
---
 .../linux/ramips/base-files/etc/board.d/02_network |  2 +-
 target/linux/ramips/base-files/lib/ramips.sh   |  3 -
 .../ramips/base-files/lib/upgrade/platform.sh  |  3 +-
 target/linux/ramips/dts/RB750Gr3.dts   | 92 +++---
 target/linux/ramips/image/mt7621.mk| 15 ++--
 5 files changed, 73 insertions(+), 42 deletions(-)

diff --git a/target/linux/ramips/base-files/etc/board.d/02_network 
b/target/linux/ramips/base-files/etc/board.d/02_network
index 7d5f09c35c..3ec2259e01 100755
--- a/target/linux/ramips/base-files/etc/board.d/02_network
+++ b/target/linux/ramips/base-files/etc/board.d/02_network
@@ -201,9 +201,9 @@ ramips_setup_interfaces()
jhr-n805r|\
jhr-n825r|\
jhr-n926r|\
+   mikrotik,rb750gr3|\
mikrotik,rbm33g|\
mzk-wdpr|\
-   rb750gr3|\
rt-n14u|\
tplink,c20-v4|\
tplink,c50-v3|\
diff --git a/target/linux/ramips/base-files/lib/ramips.sh 
b/target/linux/ramips/base-files/lib/ramips.sh
index 5741cbd2ee..2dd0388426 100755
--- a/target/linux/ramips/base-files/lib/ramips.sh
+++ b/target/linux/ramips/base-files/lib/ramips.sh
@@ -418,9 +418,6 @@ ramips_board_detect() {
*"R6220")
name="r6220"
;;
-   *"RB750Gr3")
-   name="rb750gr3"
-   ;;
*"RE350 v1")
name="re350-v1"
;;
diff --git a/target/linux/ramips/base-files/lib/upgrade/platform.sh 
b/target/linux/ramips/base-files/lib/upgrade/platform.sh
index e3f8e606c2..1221500c79 100755
--- a/target/linux/ramips/base-files/lib/upgrade/platform.sh
+++ b/target/linux/ramips/base-files/lib/upgrade/platform.sh
@@ -132,7 +132,6 @@ platform_check_image() {
psr-680w|\
px-4885-4M|\
px-4885-8M|\
-   rb750gr3|\
re6500|\
rp-n53|\
rt5350f-olinuxino|\
@@ -302,6 +301,7 @@ platform_check_image() {
nand_do_platform_check "$board" "$1"
return $?;
;;
+   mikrotik,rb750gr3|\
mikrotik,rbm11g|\
mikrotik,rbm33g|\
re350-v1)
@@ -329,6 +329,7 @@ platform_pre_upgrade() {
local board=$(board_name)
 
case "$board" in
+   mikrotik,rb750gr3|\
mikrotik,rbm11g|\
mikrotik,rbm33g)
[ -z "$(rootfs_type)" ] && mtd erase firmware
diff --git a/target/linux/ramips/dts/RB750Gr3.dts 
b/target/linux/ramips/dts/RB750Gr3.dts
index 20198eb9ca..89863b68e0 100644
--- a/target/linux/ramips/dts/RB750Gr3.dts
+++ b/target/linux/ramips/dts/RB750Gr3.dts
@@ -7,10 +7,10 @@
 
 / {
compatible = "mikrotik,rb750gr3", "mediatek,mt7621-soc";
-   model = "MikroTik RB750Gr3";
+   model = "MikroTik RouterBOARD 750Gr3";
 
aliases {
-   led-status = &led_pwr;
+   led-status = &led_usr;
};
 
memory@0 {
@@ -19,18 +19,19 @@
};
 
chosen {
-   bootargs = "console=ttyS0,57600";
+   bootargs = "console=ttyS0,115200";
};
 
gpio-leds {
compatible = "gpio-leds";
 
-   led_pwr: pwr {
+   pwr {
label = "rb750gr3:blue:pwr";
gpios = <&gpio0 16 GPIO_ACTIVE_HIGH>;
+   default-state = "on";
};
 
-   usr {
+   led_usr: usr {
label = "rb750gr3:green:usr";
gpios = <&gpio0 0 GPIO_ACTIVE_HIGH>;
};
@@ -43,7 +44,7 @@
mode {
label = "mode";
gpios = <&gpio0 13 GPIO_ACTIVE_LOW>;
-   linux,code = ;
+   linux,code = ;
};
 
res {
@@ -64,9 +65,21 @@
};
 
usb {
-   gpio-export,name = "usb";
+   gpio-export,name = "usb_power_off";
gpio-export,output = <1>;
-   gpios = <&gpio0 12 GPIO_ACTIVE_HIGH>;
+   gpios = <&gpio0 12 GPIO_ACTIVE_LOW>;
+   };
+
+   // Used to enable power-over-ethernet passthrough to eth4 

[OpenWrt-Devel] [PATCH] base-files: make wifi report unknown command

2018-08-06 Thread Thibaut VARÈNE
Avoid having /sbin/wifi silently ignore unknown keywords and execute
"enable"; instead display the help message and exit with an error.

Also preserve the implicit assumption that runing /sbin/wifi without
argument performs network reload and "enable".

Signed-off-by: Thibaut VARÈNE 
---
 package/base-files/files/sbin/wifi | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/package/base-files/files/sbin/wifi 
b/package/base-files/files/sbin/wifi
index 83befc0d6f..13c91c2919 100755
--- a/package/base-files/files/sbin/wifi
+++ b/package/base-files/files/sbin/wifi
@@ -241,5 +241,6 @@ case "$1" in
reload) wifi_reload "$2";;
reload_legacy) wifi_reload_legacy "$2";;
--help|help) usage;;
-   *) ubus call network reload; wifi_updown "enable" "$2";;
+   '') ubus call network reload; wifi_updown "enable";;
+   *) usage; exit 1;;
 esac
-- 
2.13.6 (Apple Git-96)


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH v3] base-files: make wifi report unknown command

2018-08-09 Thread Thibaut VARÈNE
Avoid having /sbin/wifi silently ignore unknown keywords and execute
"enable"; instead display the help message and exit with an error.

Spell out the 'enable' keyword and preserve the implicit assumption
that runing /sbin/wifi without argument performs "enable".

Signed-off-by: Thibaut VARÈNE 
---
 package/base-files/files/sbin/wifi | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/package/base-files/files/sbin/wifi 
b/package/base-files/files/sbin/wifi
index 83befc0d6f..68536ed25f 100755
--- a/package/base-files/files/sbin/wifi
+++ b/package/base-files/files/sbin/wifi
@@ -241,5 +241,6 @@ case "$1" in
reload) wifi_reload "$2";;
reload_legacy) wifi_reload_legacy "$2";;
--help|help) usage;;
-   *) ubus call network reload; wifi_updown "enable" "$2";;
+   ''|enable) ubus call network reload; wifi_updown "enable" "$2";;
+   *) usage; exit 1;;
 esac
-- 
2.14.3 (Apple Git-98)


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH v4] base-files: make wifi report unknown command

2018-08-09 Thread Thibaut VARÈNE
Avoid having /sbin/wifi silently ignore unknown keywords and execute
"up"; instead display the help message and exit with an error.

Spell out the "up" keyword (which has users), add it to usage output,
and preserve the implicit assumption that runing /sbin/wifi without
argument performs "up".

Signed-off-by: Thibaut VARÈNE 
---
 package/base-files/files/sbin/wifi | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/package/base-files/files/sbin/wifi 
b/package/base-files/files/sbin/wifi
index 83befc0d6f..f7a10de215 100755
--- a/package/base-files/files/sbin/wifi
+++ b/package/base-files/files/sbin/wifi
@@ -6,7 +6,7 @@
 
 usage() {
cat <https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[PATCH][19.07] ar71xx: wix MikroTik wAP detection

2021-10-05 Thread Thibaut VARÈNE
MikroTik released a 3rd revision of that board, virtually identical
to the previous one as far as software is concerned.

Signed-off-by: Thibaut VARÈNE 
---
In case anyone still cares about ar71xx on 19.07, this one-liner keeps
it working with MikroTik's latest minor revision of an otherwise
already supported device.
---
 target/linux/ar71xx/base-files/lib/ar71xx.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/target/linux/ar71xx/base-files/lib/ar71xx.sh 
b/target/linux/ar71xx/base-files/lib/ar71xx.sh
index 044ef4eae5..14b661cfd7 100755
--- a/target/linux/ar71xx/base-files/lib/ar71xx.sh
+++ b/target/linux/ar71xx/base-files/lib/ar71xx.sh
@@ -542,7 +542,8 @@ mikrotik_board_detect() {
*"SXT Lite5")
name="rb-sxt5n"
;;
-   *"wAP 2nD r2")
+   *"wAP 2nD r2"|\
+   *"wAP 2nD r3")
name="rb-wap-2nd"
;;
*"wAP R-2nD"|\
-- 
2.24.3 (Apple Git-128)


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[PATCH 21.02] ath79: add support for MikroTik RouterBOARD mAP lite

2022-03-10 Thread Thibaut VARÈNE
The MikroTik RouterBOARD mAPL-2nd (sold as mAP Lite) is a small
2.4 GHz 802.11b/g/n PoE-capable AP.

See https://mikrotik.com/product/RBmAPL-2nD for more info.

Specifications:
 - SoC: Qualcomm Atheros QCA9533
 - RAM: 64 MB
 - Storage: 16 MB NOR
 - Wireless: Atheros AR9531 (SoC) 802.11b/g/n 2x2:2, 1.5 dBi antenna
 - Ethernet: Atheros AR8229 (SoC), 1x 10/100 port, 802.3af/at PoE in
 - 4 user-controllable LEDs:
   · 1x power (green)
   · 1x user (green)
   · 1x lan (green)
   · 1x wlan (green)

Flashing:
 TFTP boot initramfs image and then perform sysupgrade. Follow common
 MikroTik procedure as in https://openwrt.org/toh/mikrotik/common.

Note: following 781d4bfb397cdd12ee0151eb66c577f470e3377d
 The network setup avoids using the integrated switch and connects the
 single Ethernet port directly. This way, link speed (10/100 Mbps) is
 properly reported by eth0.

Signed-off-by: Thibaut VARÈNE 
(cherry picked from commit eb38af788180d624e5b37aa5db1fe3766b138dc8)
---
 .../qca9533_mikrotik_routerboard-mapl-2nd.dts | 68 +++
 target/linux/ath79/image/mikrotik.mk  |  8 +++
 .../mikrotik/base-files/etc/board.d/01_leds   |  3 +-
 .../base-files/etc/board.d/02_network |  2 +
 .../etc/hotplug.d/firmware/10-ath9k-eeprom|  1 +
 5 files changed, 81 insertions(+), 1 deletion(-)
 create mode 100644 
target/linux/ath79/dts/qca9533_mikrotik_routerboard-mapl-2nd.dts

diff --git a/target/linux/ath79/dts/qca9533_mikrotik_routerboard-mapl-2nd.dts 
b/target/linux/ath79/dts/qca9533_mikrotik_routerboard-mapl-2nd.dts
new file mode 100644
index 00..e2442f0095
--- /dev/null
+++ b/target/linux/ath79/dts/qca9533_mikrotik_routerboard-mapl-2nd.dts
@@ -0,0 +1,68 @@
+// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
+
+#include "qca9533_mikrotik_routerboard-16m.dtsi"
+
+/ {
+   compatible = "mikrotik,routerboard-mapl-2nd", "qca,qca9533";
+   model = "MikroTik RouterBOARD mAPL-2nD (mAP lite)";
+
+   aliases {
+   led-boot = &led_user;
+   led-failsafe = &led_user;
+   led-running = &led_user;
+   led-upgrade = &led_user;
+   };
+
+   leds {
+   compatible = "gpio-leds";
+   pinctrl-names = "default";
+   pinctrl-0 = <&led_power_pin &led_lan_pin>;
+
+   power {
+   label = "green:power";
+   gpios = <&gpio 17 GPIO_ACTIVE_HIGH>;
+   default-state = "on";
+   };
+
+   lan {
+   label = "green:lan";
+   gpios = <&gpio 4 GPIO_ACTIVE_HIGH>;
+   };
+
+   wlan {
+   label = "green:wlan";
+   gpios = <&gpio 11 GPIO_ACTIVE_HIGH>;
+   linux,default-trigger = "phy0tpt";
+   };
+
+   led_user: user {
+   label = "green:user";
+   gpios = <&gpio 14 GPIO_ACTIVE_HIGH>;
+   };
+   };
+};
+
+ð0 {
+   status = "okay";
+
+   phy-handle = <&swphy0>;
+
+   gmac-config {
+   device = <&gmac>;
+   switch-phy-swap = <1>;
+   };
+};
+
+ð1 {
+   compatible = "syscon", "simple-mfd";
+};
+
+&pinmux {
+   led_lan_pin: pinmux_led_lan_pin {
+   pinctrl-single,bits = <0x4 0x0 0xff>;
+   };
+
+   led_power_pin: pinmux_led_power_pin {
+   pinctrl-single,bits = <0x10 0x0 0xff00>;
+   };
+};
diff --git a/target/linux/ath79/image/mikrotik.mk 
b/target/linux/ath79/image/mikrotik.mk
index 4256f77379..b2c7000419 100644
--- a/target/linux/ath79/image/mikrotik.mk
+++ b/target/linux/ath79/image/mikrotik.mk
@@ -45,6 +45,14 @@ define Device/mikrotik_routerboard-lhg-2nd
 endef
 TARGET_DEVICES += mikrotik_routerboard-lhg-2nd
 
+define Device/mikrotik_routerboard-mapl-2nd
+  $(Device/mikrotik_nor)
+  SOC := qca9533
+  DEVICE_MODEL := RouterBOARD mAPL-2nD (mAP lite)
+  IMAGE_SIZE := 16256k
+endef
+TARGET_DEVICES += mikrotik_routerboard-mapl-2nd
+
 define Device/mikrotik_routerboard-sxt-5nd-r2
   $(Device/mikrotik_nand)
   SOC := ar9344
diff --git a/target/linux/ath79/mikrotik/base-files/etc/board.d/01_leds 
b/target/linux/ath79/mikrotik/base-files/etc/board.d/01_leds
index 0d3209c2e3..e95c5830e2 100755
--- a/target/linux/ath79/mikrotik/base-files/etc/board.d/01_leds
+++ b/target/linux/ath79/mikrotik/base-files/etc/board.d/01_leds
@@ -7,7 +7,8 @@ board_config_update
 board=$(board_name)
 
 case "$board" in
-mikrotik,routerboard-lhg-2nd)
+mikrotik,routerboard-lhg-2nd|\
+mikrotik,routerboard-mapl-2nd)
ucidef_set_led_netdev "lan" "lan" "green:lan" "eth0"

[OpenWrt-Devel] [PATCH] ramips: define common MikroTik RouterBOARD image recipe

2018-07-19 Thread Thibaut VARÈNE
All these devices share the exact same image format.

Signed-off-by: Thibaut VARÈNE 
---
 target/linux/ramips/image/mt7621.mk | 20 +---
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/target/linux/ramips/image/mt7621.mk 
b/target/linux/ramips/image/mt7621.mk
index fa87e40520..8ac78ad7de 100644
--- a/target/linux/ramips/image/mt7621.mk
+++ b/target/linux/ramips/image/mt7621.mk
@@ -260,11 +260,9 @@ define Device/rb750gr3
 endef
 TARGET_DEVICES += rb750gr3
 
-define Device/mikrotik_rbm33g
-  DTS := RBM33G
+define Device/MikroTik
   BLOCKSIZE := 64k
   IMAGE_SIZE := 16128k
-  DEVICE_TITLE := MikroTik RBM33G
   DEVICE_PACKAGES := kmod-usb3
   LOADER_TYPE := elf
   PLATFORM := mt7621
@@ -272,18 +270,18 @@ define Device/mikrotik_rbm33g
   IMAGE/sysupgrade.bin := append-kernel | kernel2minor -s 1024 | pad-to 
(BLOCKSIZE) | \
append-rootfs | pad-rootfs | append-metadata | check-size 
(IMAGE_SIZE)
 endef
+
+define Device/mikrotik_rbm33g
+  $(Device/MikroTik)
+  DTS := RBM33G
+  DEVICE_TITLE := MikroTik RouterBOARD M33G
+endef
 TARGET_DEVICES += mikrotik_rbm33g
 
 define Device/mikrotik_rbm11g
+  $(Device/MikroTik)
   DTS := RBM11G
-  BLOCKSIZE := 64k
-  IMAGE_SIZE := 16128k
-  DEVICE_TITLE := MikroTik RBM11G
-  LOADER_TYPE := elf
-  PLATFORM := mt7621
-  KERNEL := kernel-bin | patch-dtb | lzma | loader-kernel
-  IMAGE/sysupgrade.bin := append-kernel | kernel2minor -s 1024 | pad-to 
(BLOCKSIZE) | \
-   append-rootfs | pad-rootfs | append-metadata | check-size 
(IMAGE_SIZE)
+  DEVICE_TITLE := MikroTik RouterBOARD M11G
 endef
 TARGET_DEVICES += mikrotik_rbm11g
 
-- 
2.14.3 (Apple Git-98)


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH 2/2] ramips: fix RBM11G name and partitioning

2018-07-19 Thread Thibaut VARÈNE
This patch improves faf64056ddd46992a75b1e277d94541c7251035c by setting
the correct partition scheme for the RouterBoot section of the flash.

This section is subdivided in several segments, as they are on ar71xx
RB devices, albeit with different offsets and sizes. The naming convention
from ar71xx has been preserved, with an overlapping "RouterBoot" top level
partition added for clarity due to the many holes.

The resulting partition scheme looks like this:
[2.477826] Creating 7 MTD partitions on "spi0.0":
[2.482604] 0x-0x0004 : "RouterBoot"
[2.488948] 0x-0xf000 : "routerboot"
[2.495289] 0xf000-0x0001 : "hard_config"
[2.501596] 0x0001-0x0001f000 : "routerboot2"
[2.507966] 0x0002-0x00021000 : "soft_config"
[2.514307] 0x0003-0x00031000 : "bios"
[2.520108] 0x0004-0x0100 : "firmware"

The device name is corrected to match the hardware-stored (in hard_config)
device name.

Leave a note in DTS to mention this device supports hardware crypto.
Leave a note in DTS to explain how the original author selected the SPI speed.

Note: more work is required to get rbcfg working on this device due to
endianness.

Tested-by: Tobias Schramm 
Signed-off-by: Thibaut VARÈNE 
---
 target/linux/ramips/dts/RBM11G.dts | 62 +++---
 1 file changed, 45 insertions(+), 17 deletions(-)

diff --git a/target/linux/ramips/dts/RBM11G.dts 
b/target/linux/ramips/dts/RBM11G.dts
index f312093a22..079b4fc146 100644
--- a/target/linux/ramips/dts/RBM11G.dts
+++ b/target/linux/ramips/dts/RBM11G.dts
@@ -7,7 +7,7 @@
 
 / {
compatible = "mikrotik,rbm11g", "mediatek,mt7621-soc";
-   model = "MikroTik RBM11G";
+   model = "MikroTik RouterBOARD M11G";
 
aliases {
led-status = &led_usr;
@@ -90,29 +90,54 @@
#size-cells = <1>;
compatible = "jedec,spi-nor";
reg = <0>;
+   // XXX empiric value to obtain actual 10MHz SCK at the chip
spi-max-frequency = <3125000>;
 
-   partition@0 {
-   label = "routerboot";
-   reg = <0x00 0x00F000>;
-   read-only;
-   };
-
-   factory: partition@f000 {
-   label = "factory";
-   reg = <0x00F000 0x031000>;
-   read-only;
-   };
-
-   partition@4 {
-   label = "firmware";
-   reg = <0x04 0xFC>;
+   partitions {
+   compatible = "fixed-partitions";
+   #address-cells = <1>;
+   #size-cells = <1>;
+
+   partition@0 {
+   label = "RouterBoot";
+   reg = <0x0 0x4>;
+   read-only;
+   };
+
+   routerboot@0 {
+   reg = <0x0 0xf000>;
+   read-only;
+   };
+
+   hard_config: hard_config@f000 {
+   reg = <0xf000 0x1000>;
+   read-only;
+   };
+
+   routerboot2@1 {
+   reg = <0x1 0xf000>;
+   read-only;
+   };
+
+   soft_config@2 {
+   reg = <0x2 0x1000>;
+   };
+
+   // valid data only extends up to 0x4f but make it 
0x1000 to match ar71xx
+   bios@3 {
+   reg = <0x3 0x1000>;
+   read-only;
+   };
+
+   firmware@4 {
+   reg = <0x04 0xFC>;
+   };
};
};
 };
 
 ðernet {
-   mtd-mac-address = <&factory 0x0010>;
+   mtd-mac-address = <&hard_config 0x0010>;
mtd-mac-address-increment = <1>;
 };
 
@@ -133,3 +158,6 @@
 &pcie {
status = "okay";
 };
+
+// XXX this device has hardware crypto
+//&crypto {};
-- 
2.14.3 (Apple Git-98)


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH 0/2] ramips: fix RBMxxG name and partitionning

2018-07-19 Thread Thibaut VARÈNE
This series fix the DTS files of the MikroTik RouterBOARD M11G and M33G. The
changes are similar in both patches:

 - The model name string is updated to match the hardware-stored (in flash)
   string that we cannot (yet?) extract at runtime.
 - The partition scheme is updated to reflect areas reserved by OEM (as defined
   in their GPL source code) and the reverse-engineered sections contained
   herein.

The proposed partition scheme defines a "top-level" overlapping "RouterBoot"
partition that matches the identically named, OEM-defined segment (in their GPL
code), and then defines extrapolated sub-segments.

The rationale for this is as follows:
 - OEM only defines the 0x0 0x4 segment in their source: the whole segment
   should thus be considered "reserved by OEM", despite having empty holes.
 - The subsegments are reverse-engineered (initially by Gabor Juhos in
   target/linux/ar71xx/files/arch/mips/ath79/routerboot.c) and may vary from
   hardware to hardware (they are already different in size and offsets between
   ar71xx and ramips).
 - We have no certitude that the empty holes will remain empty: it is desirable
   to make it perfectly clear that they should never be reclaimed as user
   storage space (preferably without having to define a clutter of empty
   partitions).
 - OEM tools might be usable with this top level partition present and named
   identically with OEM.
 - The top level partition is a convenient way to ask for a user dump ("please
   send the content of the RouterBoot partition") and build a database of such
   dumps whose use will become apparent below.
 - I expect it might eventually be possible to split that top level partition
   at runtime with a splitter.

This last point is of particular significance: currently the proposed partition
scheme "emulates" what the purported splitter would produce at runtime. In an
ideal world the DTS would only define the top-level RouterBoot area and the
splitter would produce the exact same partition as is currently defined, in a
fashion very similar to what is done with e.g. the 'firmware' partition.
Regardless, in this situation the partition scheme for these devices would thus
not change.

I cannot immediately provide such a runtime splitter, notably because I would
need to collect several dumps to extract a statistically meaningful working set
to test the splitter code against; and also because of DTS-specific challenges
associated with this proposal (the MAC address and ART data are contained in a
specific sub-partition currently directly referred in DTS).

These subpartitions are nevertheless necessary in their own right: besides the
primary and secondary bootloader (apparently common to all RB devices, across
all platforms) defined as 'routerboot' and 'routerboot2', the 'hard_config'
segment contains the device MAC address, its model name string, its serial
number or its WLAN calibration data for instance.
The 'soft_config' partition contains user-modifiable settings such as boot
delay, boot order, selected bootloader, cpu frequency scaling or uart speed.
These settings can be accessed and modified in OpenWRT via the 'rbcfg' utility,
which relies on the presence of the 'soft_config' partition to operate. This
explains the naming choice for these subpartitions: it's been carried over from
ar71xx for consistency.

Thibaut VARÈNE (2):
  ramips: fix RBM33G name and partitioning
  ramips: fix RBM11G name and partitioning

 target/linux/ramips/dts/RBM11G.dts | 62 ++--
 target/linux/ramips/dts/RBM33G.dts | 64 +-
 2 files changed, 95 insertions(+), 31 deletions(-)

-- 
2.14.3 (Apple Git-98)


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH 1/2] ramips: fix RBM33G name and partitioning

2018-07-19 Thread Thibaut VARÈNE
This patch improves 5684d087418d176cfdef4e045e1950ca7ba3b09f by setting
the correct partition scheme for the RouterBoot section of the flash.

This section is subdivided in several segments, as they are on ar71xx
RB devices, albeit with different offsets and sizes. The naming convention
from ar71xx has been preserved, with an overlapping "RouterBoot" top level
partition added for clarity due to the many holes.

The OEM source code also define a "fake" partition at the beginning of
the secondary flash chip: to avoid trouble if OEM ever make use of that
space, we define it here.

The resulting partition scheme looks like this:
[2.355095] Creating 6 MTD partitions on "spi0.0":
[2.359872] 0x-0x0004 : "RouterBoot"
[2.366197] 0x-0xf000 : "routerboot"
[2.372437] 0xf000-0x0001 : "hard_config"
[2.378818] 0x0001-0x0001f000 : "routerboot2"
[2.385200] 0x0002-0x00021000 : "soft_config"
[2.391503] 0x0003-0x00031000 : "bios"
[2.419283] Creating 2 MTD partitions on "spi0.1":
[2.424062] 0x-0x0004 : "RouterBootFake"
[2.430717] 0x0004-0x0100 : "firmware"

The device name is corrected to match the hardware-stored (in hard_config)
device name.

Leave a note in DTS to mention this device supports hardware crypto.
Leave a note in DTS to explain how the original author selected the SPI speed.

Note: more work is required to get rbcfg working on this device due to
endianness.

Tested-by: Tobias Schramm 
Signed-off-by: Thibaut VARÈNE 
---
 target/linux/ramips/dts/RBM33G.dts | 64 +-
 1 file changed, 50 insertions(+), 14 deletions(-)

diff --git a/target/linux/ramips/dts/RBM33G.dts 
b/target/linux/ramips/dts/RBM33G.dts
index cc6da267a2..e1de3c8c11 100644
--- a/target/linux/ramips/dts/RBM33G.dts
+++ b/target/linux/ramips/dts/RBM33G.dts
@@ -7,7 +7,7 @@
 
 / {
compatible = "mikrotik,rbm33g", "mediatek,mt7621-soc";
-   model = "MikroTik RBM33G";
+   model = "MikroTik RouterBOARD M33G";
 
aliases {
led-status = &led_usr;
@@ -39,7 +39,7 @@
poll-interval = <20>;
 
res {
-   label = "res";
+   label = "reset";
gpios = <&gpio0 18 GPIO_ACTIVE_LOW>;
linux,code = ;
};
@@ -69,6 +69,7 @@
regulator-always-on;
};
 
+   // not defined in OEM source, this controls the M.2 slot
pcie2_vcc_reg {
compatible = "regulator-fixed";
regulator-name = "pcie2_vcc";
@@ -104,18 +105,42 @@
reg = <0>;
spi-max-frequency = <3125000>;
 
-   partition@0 {
-   label = "routerboot";
-   reg = <0x0 0xf000>;
-   read-only;
-   };
-
-   factory: partition@f000 {
-   label = "factory";
-   reg = <0xf000 0x71000>;
-   read-only;
+   partitions {
+   compatible = "fixed-partitions";
+   #address-cells = <1>;
+   #size-cells = <1>;
+
+   partition@0 {
+   label = "RouterBoot";
+   reg = <0x0 0x4>;
+   read-only;
+   };
+
+   routerboot@0 {
+   reg = <0x0 0xf000>;
+   read-only;
+   };
+
+   hard_config: hard_config@f000 {
+   reg = <0xf000 0x1000>;
+   read-only;
+   };
+
+   routerboot2@1 {
+   reg = <0x1 0xf000>;
+   read-only;
+   };
+
+   soft_config@2 {
+   reg = <0x2 0x1000>;
+   };
+
+   // valid data only extends up to 0x4f but make it 
0x1000 to match ar71xx
+   bios@3 {
+   reg = <0x3 0x1000>;
+   read-only;
+   };
};
-
};
 
w25q128@0 {
@@ -123,8 +148,16 @@
#size-cells = <1>;
compatible = "jedec,spi-nor";
reg = <1>;

[OpenWrt-Devel] [PATCH 0/1] [18.06] ramips: remove RB750GR3 support

2018-07-19 Thread Thibaut VARÈNE
[resending properly formatted]

Detailed rationale:
• This code should never have been accepted: it should certainly not be part of
  a release and if it accidentally was part of one that should not be reason to
  continue what is IMO a mistake.
• This code does not support the stock hardware.
• This code is a maintenance burden (it's a custom hack, in essence).
• This code will induce confusion with end user when the correct code is
  introduced
• There will be no upgrade path between this code and the correct support.

Assuming there’s more than a single user for this code (which I doubt
considering the wiki suggests using an SPI flash programmer to install), the
supplementary rationale from my point of view is thus precisely to break the
support chain and make it perfectly clear that current “support" stops in 18.06
without what could be taken as a sign of a transition ("oh, image has changed
name but it should still be the right one"): old code in 17, nothing in 18,
support in 19: clean break.

No replacement is proposed since no such a thing can exist: stock hw uses a
different bootloader (routerboot) which expects a different image format, and
uses an incompatible mtd flash partitioning. "New" support code will be exactly
that: new.

Thibaut VARÈNE (1):
  ramips: remove RB750GR3 support

 .../linux/ramips/base-files/etc/board.d/02_network |   1 -
 target/linux/ramips/base-files/lib/ramips.sh   |   3 -
 .../ramips/base-files/lib/upgrade/platform.sh  |   1 -
 target/linux/ramips/dts/RB750Gr3.dts   | 125 -
 target/linux/ramips/image/mt7621.mk|   8 --
 5 files changed, 138 deletions(-)
 delete mode 100644 target/linux/ramips/dts/RB750Gr3.dts

-- 
2.14.3 (Apple Git-98)


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH 1/1] ramips: remove RB750GR3 support

2018-07-19 Thread Thibaut VARÈNE
faf94d926e2810f895f2a98d4a49ee2fe8f673e8 added "support" for a hacked
device where the original boot loader (routerboot) has been replaced
by u-boot.

Support for this device with stock bootloader is possible (as evidenced
by support for the RBM33G), and conflicts with this code.

Remove code before release.

Signed-off-by: Thibaut VARÈNE 
---
 .../linux/ramips/base-files/etc/board.d/02_network |   1 -
 target/linux/ramips/base-files/lib/ramips.sh   |   3 -
 .../ramips/base-files/lib/upgrade/platform.sh  |   1 -
 target/linux/ramips/dts/RB750Gr3.dts   | 125 -
 target/linux/ramips/image/mt7621.mk|   8 --
 5 files changed, 138 deletions(-)
 delete mode 100644 target/linux/ramips/dts/RB750Gr3.dts

diff --git a/target/linux/ramips/base-files/etc/board.d/02_network 
b/target/linux/ramips/base-files/etc/board.d/02_network
index 76b6fe9f50..981e001f64 100755
--- a/target/linux/ramips/base-files/etc/board.d/02_network
+++ b/target/linux/ramips/base-files/etc/board.d/02_network
@@ -200,7 +200,6 @@ ramips_setup_interfaces()
jhr-n926r|\
mikrotik,rbm33g|\
mzk-wdpr|\
-   rb750gr3|\
rt-n14u|\
tplink,c20-v4|\
tplink,c50-v3|\
diff --git a/target/linux/ramips/base-files/lib/ramips.sh 
b/target/linux/ramips/base-files/lib/ramips.sh
index 5741cbd2ee..2dd0388426 100755
--- a/target/linux/ramips/base-files/lib/ramips.sh
+++ b/target/linux/ramips/base-files/lib/ramips.sh
@@ -418,9 +418,6 @@ ramips_board_detect() {
*"R6220")
name="r6220"
;;
-   *"RB750Gr3")
-   name="rb750gr3"
-   ;;
*"RE350 v1")
name="re350-v1"
;;
diff --git a/target/linux/ramips/base-files/lib/upgrade/platform.sh 
b/target/linux/ramips/base-files/lib/upgrade/platform.sh
index ffdc5e73e0..59aca60ad0 100755
--- a/target/linux/ramips/base-files/lib/upgrade/platform.sh
+++ b/target/linux/ramips/base-files/lib/upgrade/platform.sh
@@ -129,7 +129,6 @@ platform_check_image() {
psr-680w|\
px-4885-4M|\
px-4885-8M|\
-   rb750gr3|\
re6500|\
rp-n53|\
rt5350f-olinuxino|\
diff --git a/target/linux/ramips/dts/RB750Gr3.dts 
b/target/linux/ramips/dts/RB750Gr3.dts
deleted file mode 100644
index dc359b10bb..00
--- a/target/linux/ramips/dts/RB750Gr3.dts
+++ /dev/null
@@ -1,125 +0,0 @@
-/dts-v1/;
-
-#include "mt7621.dtsi"
-
-#include 
-#include 
-
-/ {
-   compatible = "mikrotik,rb750gr3", "mediatek,mt7621-soc";
-   model = "MikroTik RB750Gr3";
-
-   memory@0 {
-   device_type = "memory";
-   reg = <0x0 0x1000>;
-   };
-
-   chosen {
-   bootargs = "console=ttyS0,57600";
-   };
-
-   gpio-leds {
-   compatible = "gpio-leds";
-
-   pwr {
-   label = "rb750gr3:blue:pwr";
-   gpios = <&gpio0 16 GPIO_ACTIVE_HIGH>;
-   };
-
-   usr {
-   label = "rb750gr3:green:usr";
-   gpios = <&gpio0 0 GPIO_ACTIVE_HIGH>;
-   };
-   };
-
-   gpio-keys-polled {
-   compatible = "gpio-keys-polled";
-   #address-cells = <1>;
-   #size-cells = <0>;
-   poll-interval = <20>;
-
-   mode {
-   label = "mode";
-   gpios = <&gpio0 13 GPIO_ACTIVE_LOW>;
-   linux,code = ;
-   };
-
-   res {
-   label = "res";
-   gpios = <&gpio0 18 GPIO_ACTIVE_LOW>;
-   linux,code = ;
-   };
-   };
-
-   gpio_export {
-   compatible = "gpio-export";
-   #size-cells = <0>;
-
-   buzzer {
-   gpio-export,name = "buzzer";
-   gpio-export,output = <0>;
-   gpios = <&gpio0 15 GPIO_ACTIVE_HIGH>;
-   };
-
-   usb {
-   gpio-export,name = "usb";
-   gpio-export,output = <1>;
-   gpios = <&gpio0 12 GPIO_ACTIVE_HIGH>;
-   };
-   };
-};
-
-&spi0 {
-   status = "okay";
-
-   m25p80@0 {
-   #address-cells = <1>;
-   #size-cells = <1>;
-   compatible = "jedec,spi-nor";
-   reg = <0>;
-   spi-max-frequency = <1000>;
-   m25p,chunked-io = <32>;
-
-   partit

[OpenWrt-Devel] [PATCH] ar71xx: add support for RB SXTsq 2nD

2020-03-14 Thread Thibaut VARÈNE
This patch adds support for the MikroTik RouterBOARD SXTsq Lite2
https://mikrotik.com/product/sxtsq_lite2

Specifications:
- SoC: Qualcomm QCA9533 (650MHz)
- RAM: 64MB
- Storage: 16MB SPI NOR flash
- Wireless: QCA9533 built-in, dual-chain 802.11b/g/n
- Ethernet: 1x100M

Note: the reset button shares its GPIO with the last RSSI LED:
this is not supported, the last LED is thus disabled (reset works).
That aside, the device is fully supported.

Installation:

1. Setup a DHCP/BOOTP Server with the following parameters:
   * DHCP-Option 66 (TFTP server name): pointing to a local TFTP
 server within the same subnet of the DHCP range
   * DHCP-Option 67 (Bootfile-Name): matching the initramfs filename
 of the to be booted image. The usable intramfs files are:
   - openwrt-ar71xx-mikrotik-vmlinux-initramfs.elf
   - openwrt-ar71xx-mikrotik-vmlinux-initramfs-lzma.elf
   - openwrt-ar71xx-mikrotik-rb-nor-flash-16M-initramfs-kernel.bin

2. Press the reset button on the board and keep that pressed.

3. Connect the board to your local network via its Internet port.

4. Release the button after the LEDs on the board are turned off.
   Now the board should load and start the initramfs image from
   the TFTP server.

5. Now connect the board via either of its LAN ports (2 or 3).

6. Upload the sysupgrade image to the board with scp:
 $ scp openwrt-ar71xx-mikrotik-rb-nor-flash-16M-squashfs-sysupgrade.bin 
root@192.168.1.1:/tmp/fw.bin

7. Log in to the running system listening on 192.168.1.1 via ssh
   as root (without password):
 $ ssh root@192.168.1.1

8. Flash the uploaded firmware file from the ssh session via the
   sysupgrade command:
 root@OpenWrt:~# sysupgrade /tmp/fw.bin

Signed-off-by: Thibaut VARÈNE 
---
 target/linux/ar71xx/base-files/etc/board.d/01_leds |  3 +-
 .../linux/ar71xx/base-files/etc/board.d/02_network |  1 +
 target/linux/ar71xx/base-files/etc/diag.sh |  1 +
 target/linux/ar71xx/base-files/lib/ar71xx.sh   |  3 +
 .../ar71xx/base-files/lib/upgrade/platform.sh  |  2 +
 .../ar71xx/files/arch/mips/ath79/Kconfig.openwrt   |  1 +
 .../ar71xx/files/arch/mips/ath79/mach-rbspi.c  | 78 +-
 .../linux/ar71xx/files/arch/mips/ath79/machtypes.h |  1 +
 target/linux/ar71xx/image/mikrotik.mk  |  2 +-
 9 files changed, 89 insertions(+), 3 deletions(-)

diff --git a/target/linux/ar71xx/base-files/etc/board.d/01_leds 
b/target/linux/ar71xx/base-files/etc/board.d/01_leds
index 54727a6e52..4d50f489d5 100755
--- a/target/linux/ar71xx/base-files/etc/board.d/01_leds
+++ b/target/linux/ar71xx/base-files/etc/board.d/01_leds
@@ -683,7 +683,8 @@ rb-2011uias-2hnd-r2)
ucidef_set_led_switch "eth9" "ETH9" "rb:green:eth9" "switch1" "0x04"
ucidef_set_led_switch "eth10" "ETH10" "rb:green:eth10" "switch1" "0x02"
;;
-rb-lhg-5nd)
+rb-lhg-5nd|\
+rb-sxtsq-2nd)
ucidef_set_led_netdev "lan" "LAN" "rb:green:eth" "eth0"
ucidef_set_rssimon "wlan0" "20" "1"
ucidef_set_led_rssi "rssilow" "RSSILOW" "rb:green:rssi0" "wlan0" "1" 
"100" "0" "13"
diff --git a/target/linux/ar71xx/base-files/etc/board.d/02_network 
b/target/linux/ar71xx/base-files/etc/board.d/02_network
index 1487ff58de..1334e48e7a 100755
--- a/target/linux/ar71xx/base-files/etc/board.d/02_network
+++ b/target/linux/ar71xx/base-files/etc/board.d/02_network
@@ -116,6 +116,7 @@ ar71xx_setup_interfaces()
rb-sxt2n|\
rb-sxt-2nd-r3|\
rb-sxt5n|\
+   rb-sxtsq-2nd|\
rb-wap-2nd|\
rb-wapr-2nd|\
rb-wapg-5hact2hnd|\
diff --git a/target/linux/ar71xx/base-files/etc/diag.sh 
b/target/linux/ar71xx/base-files/etc/diag.sh
index c5fe5bdcc1..b0e56fda8a 100644
--- a/target/linux/ar71xx/base-files/etc/diag.sh
+++ b/target/linux/ar71xx/base-files/etc/diag.sh
@@ -381,6 +381,7 @@ get_status_led() {
rb-map-2nd|\
rb-mapl-2nd|\
rb-sxt-2nd-r3|\
+   rb-sxtsq-2nd|\
rb-wap-2nd|\
rb-wapr-2nd)
status_led="rb:green:user"
diff --git a/target/linux/ar71xx/base-files/lib/ar71xx.sh 
b/target/linux/ar71xx/base-files/lib/ar71xx.sh
index 044ef4eae5..cf792783c4 100755
--- a/target/linux/ar71xx/base-files/lib/ar71xx.sh
+++ b/target/linux/ar71xx/base-files/lib/ar71xx.sh
@@ -542,6 +542,9 @@ mikrotik_board_detect() {
*"SXT Lite5")
name="rb-sxt5n"
;;
+   *"SXTsq 2nD")
+   name="rb-sxtsq-2nd"
+   ;;
*"wAP 2nD r2")
name="rb-wap-2nd"
;;
diff --git a/target/linux/ar71xx/base-files/lib/upgrade/platform.sh 
b/target/linux/ar71xx/base-files/lib/upgrade/platform.sh
index a76

[OpenWrt-Devel] [PATCH v2] ar71xx: add support for RB SXTsq 2nD

2020-03-15 Thread Thibaut VARÈNE
[no change, commit msg update: fixed installation instructions]

This patch adds support for the MikroTik RouterBOARD SXTsq Lite2
https://mikrotik.com/product/sxtsq_lite2

Specifications:
- SoC: Qualcomm QCA9533 (650MHz)
- RAM: 64MB
- Storage: 16MB SPI NOR flash
- Wireless: QCA9533 built-in, dual-chain 802.11b/g/n
- Ethernet: 1x100M

Note: the reset button shares its GPIO with the last RSSI LED:
this is not supported, the last LED is thus disabled (reset works).
That aside, the device is fully supported.

Installation:
(Standard Mikrotik TFTP)

1. Setup a DHCP/BOOTP Server with the following parameters:
   * DHCP-Option 66 (TFTP server name): pointing to a local TFTP
 server within the same subnet of the DHCP range
   * DHCP-Option 67 (Bootfile-Name): matching the initramfs filename
 of the to be booted image. The usable intramfs files are:
   - openwrt-ar71xx-mikrotik-vmlinux-initramfs.elf
   - openwrt-ar71xx-mikrotik-vmlinux-initramfs-lzma.elf
   - openwrt-ar71xx-mikrotik-rb-nor-flash-16M-initramfs-kernel.bin

2. Press the reset button on the board and keep that pressed.

3. Connect the board to your local network via its ethernet port.

4. Release the button after the LEDs on the board are turned off.
   Now the board should load and start the initramfs image from
   the TFTP server.

5. Upload the sysupgrade image to the board with scp:
 $ scp openwrt-ar71xx-mikrotik-rb-nor-flash-16M-squashfs-sysupgrade.bin 
root@192.168.1.1:/tmp/fw.bin

6. Log in to the running system listening on 192.168.1.1 via ssh
   as root (without password):
 $ ssh root@192.168.1.1

7. Flash the uploaded firmware file from the ssh session via the
   sysupgrade command:
 root@OpenWrt:~# sysupgrade /tmp/fw.bin

Signed-off-by: Thibaut VARÈNE 
---
 target/linux/ar71xx/base-files/etc/board.d/01_leds |  3 +-
 .../linux/ar71xx/base-files/etc/board.d/02_network |  1 +
 target/linux/ar71xx/base-files/etc/diag.sh |  1 +
 target/linux/ar71xx/base-files/lib/ar71xx.sh   |  3 +
 .../ar71xx/base-files/lib/upgrade/platform.sh  |  2 +
 .../ar71xx/files/arch/mips/ath79/Kconfig.openwrt   |  1 +
 .../ar71xx/files/arch/mips/ath79/mach-rbspi.c  | 78 +-
 .../linux/ar71xx/files/arch/mips/ath79/machtypes.h |  1 +
 target/linux/ar71xx/image/mikrotik.mk  |  2 +-
 9 files changed, 89 insertions(+), 3 deletions(-)

diff --git a/target/linux/ar71xx/base-files/etc/board.d/01_leds 
b/target/linux/ar71xx/base-files/etc/board.d/01_leds
index 54727a6e52..4d50f489d5 100755
--- a/target/linux/ar71xx/base-files/etc/board.d/01_leds
+++ b/target/linux/ar71xx/base-files/etc/board.d/01_leds
@@ -683,7 +683,8 @@ rb-2011uias-2hnd-r2)
ucidef_set_led_switch "eth9" "ETH9" "rb:green:eth9" "switch1" "0x04"
ucidef_set_led_switch "eth10" "ETH10" "rb:green:eth10" "switch1" "0x02"
;;
-rb-lhg-5nd)
+rb-lhg-5nd|\
+rb-sxtsq-2nd)
ucidef_set_led_netdev "lan" "LAN" "rb:green:eth" "eth0"
ucidef_set_rssimon "wlan0" "20" "1"
ucidef_set_led_rssi "rssilow" "RSSILOW" "rb:green:rssi0" "wlan0" "1" 
"100" "0" "13"
diff --git a/target/linux/ar71xx/base-files/etc/board.d/02_network 
b/target/linux/ar71xx/base-files/etc/board.d/02_network
index 1487ff58de..1334e48e7a 100755
--- a/target/linux/ar71xx/base-files/etc/board.d/02_network
+++ b/target/linux/ar71xx/base-files/etc/board.d/02_network
@@ -116,6 +116,7 @@ ar71xx_setup_interfaces()
rb-sxt2n|\
rb-sxt-2nd-r3|\
rb-sxt5n|\
+   rb-sxtsq-2nd|\
rb-wap-2nd|\
rb-wapr-2nd|\
rb-wapg-5hact2hnd|\
diff --git a/target/linux/ar71xx/base-files/etc/diag.sh 
b/target/linux/ar71xx/base-files/etc/diag.sh
index c5fe5bdcc1..b0e56fda8a 100644
--- a/target/linux/ar71xx/base-files/etc/diag.sh
+++ b/target/linux/ar71xx/base-files/etc/diag.sh
@@ -381,6 +381,7 @@ get_status_led() {
rb-map-2nd|\
rb-mapl-2nd|\
rb-sxt-2nd-r3|\
+   rb-sxtsq-2nd|\
rb-wap-2nd|\
rb-wapr-2nd)
status_led="rb:green:user"
diff --git a/target/linux/ar71xx/base-files/lib/ar71xx.sh 
b/target/linux/ar71xx/base-files/lib/ar71xx.sh
index 044ef4eae5..cf792783c4 100755
--- a/target/linux/ar71xx/base-files/lib/ar71xx.sh
+++ b/target/linux/ar71xx/base-files/lib/ar71xx.sh
@@ -542,6 +542,9 @@ mikrotik_board_detect() {
*"SXT Lite5")
name="rb-sxt5n"
;;
+   *"SXTsq 2nD")
+   name="rb-sxtsq-2nd"
+   ;;
*"wAP 2nD r2")
name="rb-wap-2nd"
;;
diff --git a/target/linux/ar71xx/base-files/lib/upgrade/platform.sh 
b/target/linux/ar71xx/base-files/lib/upgrade/pla

[OpenWrt-Devel] [PATCH 1/2] ath79: fix mikrotik WAP G-5HacT2HnD mtd partitions

2020-03-16 Thread Thibaut VARÈNE
In RouterBOARD parlance there never was an "art" partition.
This partition has always been named 'hard_config' on ar71xx.

This partition contains more than just ART (Atheros Radio Test) data. It
includes the hardware description (product code, serial, board
identifier, name, hardware options, MAC address), as well as other bits
affecting the operation of RouterBoot.
To avoid confusion with regular ART data, this partition is renamed in
line with historical ar71xx and ramips nomenclature as 'hard_config'.

This commit fixes the previous support files and implements the nested
RouterBoot partition scheme as already used by ramips-based SPI-NOR
RouterBOARD DTSes, as previously reviewed and implemented in bbe2cf657c.

Tested-by: Roger Pueyo Centelles 
Signed-off-by: Thibaut VARÈNE 
---
 ...ca9556_mikrotik_routerboard-wap-g-5hact2hnd.dts | 61 +-
 .../etc/hotplug.d/firmware/10-ath9k-eeprom |  4 +-
 .../etc/hotplug.d/firmware/11-ath10k-caldata   |  2 +-
 3 files changed, 38 insertions(+), 29 deletions(-)

diff --git 
a/target/linux/ath79/dts/qca9556_mikrotik_routerboard-wap-g-5hact2hnd.dts 
b/target/linux/ath79/dts/qca9556_mikrotik_routerboard-wap-g-5hact2hnd.dts
index 015bd2efe5..5fd4623726 100644
--- a/target/linux/ath79/dts/qca9556_mikrotik_routerboard-wap-g-5hact2hnd.dts
+++ b/target/linux/ath79/dts/qca9556_mikrotik_routerboard-wap-g-5hact2hnd.dts
@@ -53,7 +53,7 @@
 ð1 {
status = "okay";
 
-   mtd-mac-address = <&art 0x10>;
+   mtd-mac-address = <&hard_config 0x10>;
 
pll-data = <0x03000101 0x8101 0x80001313>;
phy-handle = <&phy0>;
@@ -81,32 +81,41 @@
#size-cells = <1>;
 
partition@0 {
-   label = "routerboot";
-   reg = <0x00 0x00e000>;
+   label = "RouterBoot";
+   reg = <0x0 0x2>;
read-only;
-   };
-
-   art: partition@e000 {
-   label = "art";
-   reg = <0x000e000 0x001000>;
-   read-only;
-   };
-
-   partition@f000 {
-   label = "bios";
-   reg = <0x000f000 0x001000>;
-   read-only;
-   };
-
-   partition@1 {
-   label = "routerboot2";
-   reg = <0x01 0x00f000>;
-   read-only;
-   };
-
-   partition@1f000 {
-   label = "soft_config";
-   reg = <0x001f000 0x001000>;
+   compatible = "fixed-partitions";
+   #address-cells = <1>;
+   #size-cells = <1>;
+
+   partition@0 {
+   label = "bootloader1";
+   reg = <0x0 0xe000>;
+   read-only;
+   };
+
+   hard_config: partition@e000 {
+   label = "hard_config";
+   reg = <0xe000 0x1000>;
+   read-only;
+   };
+
+   partition@f000 {
+   label = "bios";
+   reg = <0xf000 0x1000>;
+   read-only;
+   };
+
+   partition@1 {
+   label = "bootloader2";
+   reg = <0x1 0xf000>;
+   read-only;
+   };
+
+   partition@1f000 {
+   label = "soft_config";
+   reg = <0x1f000 0x1000>;
+   };
};
 
partition@2 {
diff --git 
a/target/linux/ath79/generic/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom 
b/target/linux/ath79/generic/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom
index b06a481c94..66bc3cb880 100644
--- 
a/target/linux/ath79/generic/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom
+++ 
b/target/linux/ath79/generic/base

[OpenWrt-Devel] [PATCH 2/2] ath79: rename mikrotik RB 922UAGS-5HPacD mtd partition

2020-03-16 Thread Thibaut VARÈNE
In RouterBOARD parlance there never was an "art" partition.
This partition has always been named 'hard_config' on ar71xx.

This partition contains more than just ART (Atheros Radio Test) data. It
includes the hardware description (product code, serial, board
identifier, name, hardware options, MAC address), as well as other bits
affecting the operation of RouterBoot.
To avoid confusion with regular ART data, this partition is renamed in
line with historical ar71xx and ramips nomenclature as 'hard_config'.

This commit fixes the previous support files.

Signed-off-by: Thibaut VARÈNE 
---
 .../linux/ath79/dts/qca9558_mikrotik_routerboard-922uags-5hpacd.dts | 6 +++---
 .../ath79/nand/base-files/etc/hotplug.d/firmware/11-ath10k-caldata  | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git 
a/target/linux/ath79/dts/qca9558_mikrotik_routerboard-922uags-5hpacd.dts 
b/target/linux/ath79/dts/qca9558_mikrotik_routerboard-922uags-5hpacd.dts
index 26a18ad6a7..3f2a1a51a6 100644
--- a/target/linux/ath79/dts/qca9558_mikrotik_routerboard-922uags-5hpacd.dts
+++ b/target/linux/ath79/dts/qca9558_mikrotik_routerboard-922uags-5hpacd.dts
@@ -80,7 +80,7 @@
 ð0 {
status = "okay";
 
-   mtd-mac-address = <&art 0x10>;
+   mtd-mac-address = <&hard_config 0x10>;
phy-handle = <&phy4>;
pll-data = <0x8f00 0xa101 0xa0001313>;
 
@@ -109,8 +109,8 @@
read-only;
};
 
-   art: partition@c000 {
-   label = "art";
+   hard_config: partition@c000 {
+   label = "hard_config";
reg = <0x000c000 0x0001000>;
read-only;
};
diff --git 
a/target/linux/ath79/nand/base-files/etc/hotplug.d/firmware/11-ath10k-caldata 
b/target/linux/ath79/nand/base-files/etc/hotplug.d/firmware/11-ath10k-caldata
index 8a1bed58c1..31a1db5aeb 100644
--- 
a/target/linux/ath79/nand/base-files/etc/hotplug.d/firmware/11-ath10k-caldata
+++ 
b/target/linux/ath79/nand/base-files/etc/hotplug.d/firmware/11-ath10k-caldata
@@ -28,7 +28,7 @@ case "$FIRMWARE" in
 "ath10k/cal-pci-:01:00.0.bin")
case $board in
mikrotik,routerboard-922uags-5hpacd)
-   mikrotik_caldata_extract "art" 0x5000 0x844
+   mikrotik_caldata_extract "hard_config" 0x5000 0x844
;;
esac
;;
-- 
2.11.0


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH 2/2] ath79: rename mikrotik RB 922UAGS-5HPacD mtd partition

2020-03-17 Thread Thibaut VARÈNE
In RouterBOARD parlance there never was an "art" partition.
This partition has always been named 'hard_config' on ar71xx.

This partition contains more than just ART (Atheros Radio Test) data. It
includes the hardware description (product code, serial, board
identifier, name, hardware options, MAC address), as well as other bits
affecting the operation of RouterBoot.
To avoid confusion with regular ART data, this partition is renamed in
line with historical ar71xx and ramips nomenclature as 'hard_config'.

This commit fixes the previous support files.

Signed-off-by: Thibaut VARÈNE 
---
Resend after rebase on new mikrotik subtarget
---
 .../linux/ath79/dts/qca9558_mikrotik_routerboard-922uags-5hpacd.dts | 6 +++---
 .../mikrotik/base-files/etc/hotplug.d/firmware/11-ath10k-caldata| 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git 
a/target/linux/ath79/dts/qca9558_mikrotik_routerboard-922uags-5hpacd.dts 
b/target/linux/ath79/dts/qca9558_mikrotik_routerboard-922uags-5hpacd.dts
index 26a18ad6a7..3f2a1a51a6 100644
--- a/target/linux/ath79/dts/qca9558_mikrotik_routerboard-922uags-5hpacd.dts
+++ b/target/linux/ath79/dts/qca9558_mikrotik_routerboard-922uags-5hpacd.dts
@@ -80,7 +80,7 @@
 ð0 {
status = "okay";
 
-   mtd-mac-address = <&art 0x10>;
+   mtd-mac-address = <&hard_config 0x10>;
phy-handle = <&phy4>;
pll-data = <0x8f00 0xa101 0xa0001313>;
 
@@ -109,8 +109,8 @@
read-only;
};
 
-   art: partition@c000 {
-   label = "art";
+   hard_config: partition@c000 {
+   label = "hard_config";
reg = <0x000c000 0x0001000>;
read-only;
};
diff --git 
a/target/linux/ath79/mikrotik/base-files/etc/hotplug.d/firmware/11-ath10k-caldata
 
b/target/linux/ath79/mikrotik/base-files/etc/hotplug.d/firmware/11-ath10k-caldata
index 7773eb1e3a..2521f0ad96 100644
--- 
a/target/linux/ath79/mikrotik/base-files/etc/hotplug.d/firmware/11-ath10k-caldata
+++ 
b/target/linux/ath79/mikrotik/base-files/etc/hotplug.d/firmware/11-ath10k-caldata
@@ -18,7 +18,7 @@ case "$FIRMWARE" in
 "ath10k/cal-pci-:01:00.0.bin")
case $board in
mikrotik,routerboard-922uags-5hpacd)
-   mikrotik_caldata_extract "art" 0x5000 0x844
+   mikrotik_caldata_extract "hard_config" 0x5000 0x844
;;
esac
;;
-- 
2.11.0


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH 1/2] ath79: fix mikrotik WAP G-5HacT2HnD mtd partitions

2020-03-17 Thread Thibaut VARÈNE
In RouterBOARD parlance there never was an "art" partition.
This partition has always been named 'hard_config' on ar71xx.

This partition contains more than just ART (Atheros Radio Test) data. It
includes the hardware description (product code, serial, board
identifier, name, hardware options, MAC address), as well as other bits
affecting the operation of RouterBoot.
To avoid confusion with regular ART data, this partition is renamed in
line with historical ar71xx and ramips nomenclature as 'hard_config'.

This commit fixes the previous support files and implements the nested
RouterBoot partition scheme as already used by ramips-based SPI-NOR
RouterBOARD DTSes, as previously reviewed and implemented in bbe2cf657c.

Tested-by: Roger Pueyo Centelles 
Signed-off-by: Thibaut VARÈNE 
---
Resend after rebase on new mikrotik subtarget
---
 ...ca9556_mikrotik_routerboard-wap-g-5hact2hnd.dts | 61 +-
 .../etc/hotplug.d/firmware/10-ath9k-eeprom |  4 +-
 .../etc/hotplug.d/firmware/11-ath10k-caldata   |  2 +-
 3 files changed, 38 insertions(+), 29 deletions(-)

diff --git 
a/target/linux/ath79/dts/qca9556_mikrotik_routerboard-wap-g-5hact2hnd.dts 
b/target/linux/ath79/dts/qca9556_mikrotik_routerboard-wap-g-5hact2hnd.dts
index 015bd2efe5..5fd4623726 100644
--- a/target/linux/ath79/dts/qca9556_mikrotik_routerboard-wap-g-5hact2hnd.dts
+++ b/target/linux/ath79/dts/qca9556_mikrotik_routerboard-wap-g-5hact2hnd.dts
@@ -53,7 +53,7 @@
 ð1 {
status = "okay";
 
-   mtd-mac-address = <&art 0x10>;
+   mtd-mac-address = <&hard_config 0x10>;
 
pll-data = <0x03000101 0x8101 0x80001313>;
phy-handle = <&phy0>;
@@ -81,32 +81,41 @@
#size-cells = <1>;
 
partition@0 {
-   label = "routerboot";
-   reg = <0x00 0x00e000>;
+   label = "RouterBoot";
+   reg = <0x0 0x2>;
read-only;
-   };
-
-   art: partition@e000 {
-   label = "art";
-   reg = <0x000e000 0x001000>;
-   read-only;
-   };
-
-   partition@f000 {
-   label = "bios";
-   reg = <0x000f000 0x001000>;
-   read-only;
-   };
-
-   partition@1 {
-   label = "routerboot2";
-   reg = <0x01 0x00f000>;
-   read-only;
-   };
-
-   partition@1f000 {
-   label = "soft_config";
-   reg = <0x001f000 0x001000>;
+   compatible = "fixed-partitions";
+   #address-cells = <1>;
+   #size-cells = <1>;
+
+   partition@0 {
+   label = "bootloader1";
+   reg = <0x0 0xe000>;
+   read-only;
+   };
+
+   hard_config: partition@e000 {
+   label = "hard_config";
+   reg = <0xe000 0x1000>;
+   read-only;
+   };
+
+   partition@f000 {
+   label = "bios";
+   reg = <0xf000 0x1000>;
+   read-only;
+   };
+
+   partition@1 {
+   label = "bootloader2";
+   reg = <0x1 0xf000>;
+   read-only;
+   };
+
+   partition@1f000 {
+   label = "soft_config";
+   reg = <0x1f000 0x1000>;
+   };
};
 
partition@2 {
diff --git 
a/target/linux/ath79/mikrotik/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom 
b/target/linux/ath79/mikrotik/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom
index f5f88484b5..86995de890 100644
--- 
a/target/linux/ath79/mikrotik/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom
+++ 
b/tar

[OpenWrt-Devel] [PATCH] ath79: improve mikrotik-caldata.sh

2020-03-18 Thread Thibaut VARÈNE
Reduce unnecessary flash wear and be tidy:
- Run the extraction only if necessary
- Extract temporary file to /tmp
- cleanup after execution

Tested-by: Roger Pueyo Centelles 
Signed-off-by: Thibaut VARÈNE 
---
 .../ath79/mikrotik/base-files/lib/functions/mikrotik-caldata.sh  | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git 
a/target/linux/ath79/mikrotik/base-files/lib/functions/mikrotik-caldata.sh 
b/target/linux/ath79/mikrotik/base-files/lib/functions/mikrotik-caldata.sh
index 9c4016ee5d..71a1bf02f3 100644
--- a/target/linux/ath79/mikrotik/base-files/lib/functions/mikrotik-caldata.sh
+++ b/target/linux/ath79/mikrotik/base-files/lib/functions/mikrotik-caldata.sh
@@ -9,13 +9,18 @@ mikrotik_caldata_extract() {
local offset=$(($2))
local count=$(($3))
local mtd
-   local erdfile="/lib/firmware/erd.bin"
+   local erdfile="/tmp/erd.bin"
+   local fwfile="/lib/firmware/${FIRMWARE}"
+
+   [ -e $fwfile ] && exit 0
 
mtd=$(find_mtd_chardev $part)
[ -n "$mtd" ] || caldata_die "no mtd device found for partition $part"
 
rbextract -e $mtd $erdfile
 
-   dd if=$erdfile of=/lib/firmware/$FIRMWARE iflag=skip_bytes bs=$count 
skip=$offset count=1 2>/dev/null || \
+   dd if=$erdfile of=$fwfile iflag=skip_bytes bs=$count skip=$offset 
count=1 2>/dev/null || \
caldata_die "failed to extract calibration data from $mtd"
+
+   rm -f $erdfile
 }
-- 
2.11.0


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


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

2020-03-28 Thread Thibaut VARÈNE
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 = <0x 0x10>;
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_r

[OpenWrt-Devel] [PATCH 03/11] generic: CONFIG_MTD_ROUTERBOOT_PARTS is not set

2020-03-28 Thread Thibaut VARÈNE
Signed-off-by: Thibaut VARÈNE 
---
 target/linux/generic/config-4.14 | 1 +
 target/linux/generic/config-4.19 | 1 +
 target/linux/generic/config-5.4  | 1 +
 3 files changed, 3 insertions(+)

diff --git a/target/linux/generic/config-4.14 b/target/linux/generic/config-4.14
index e42139744a..8f4e424ce6 100644
--- a/target/linux/generic/config-4.14
+++ b/target/linux/generic/config-4.14
@@ -2887,6 +2887,7 @@ CONFIG_MTD_REDBOOT_DIRECTORY_BLOCK=-1
 # CONFIG_MTD_REDBOOT_PARTS_UNALLOCATED is not set
 # CONFIG_MTD_ROM is not set
 CONFIG_MTD_ROOTFS_ROOT_DEV=y
+# CONFIG_MTD_ROUTERBOOT_PARTS is not set
 # CONFIG_MTD_SLRAM is not set
 # CONFIG_MTD_SM_COMMON is not set
 # CONFIG_MTD_SPINAND_MT29F is not set
diff --git a/target/linux/generic/config-4.19 b/target/linux/generic/config-4.19
index 418b85a738..54b4a4a1b1 100644
--- a/target/linux/generic/config-4.19
+++ b/target/linux/generic/config-4.19
@@ -3043,6 +3043,7 @@ CONFIG_MTD_REDBOOT_DIRECTORY_BLOCK=-1
 # CONFIG_MTD_REDBOOT_PARTS_UNALLOCATED is not set
 # CONFIG_MTD_ROM is not set
 CONFIG_MTD_ROOTFS_ROOT_DEV=y
+# CONFIG_MTD_ROUTERBOOT_PARTS is not set
 # CONFIG_MTD_SLRAM is not set
 # CONFIG_MTD_SM_COMMON is not set
 # CONFIG_MTD_SPINAND_MT29F is not set
diff --git a/target/linux/generic/config-5.4 b/target/linux/generic/config-5.4
index 2bdb0f5f75..e39541c79f 100644
--- a/target/linux/generic/config-5.4
+++ b/target/linux/generic/config-5.4
@@ -3239,6 +3239,7 @@ CONFIG_MTD_REDBOOT_DIRECTORY_BLOCK=-1
 # CONFIG_MTD_REDBOOT_PARTS_UNALLOCATED is not set
 # CONFIG_MTD_ROM is not set
 CONFIG_MTD_ROOTFS_ROOT_DEV=y
+# CONFIG_MTD_ROUTERBOOT_PARTS is not set
 # CONFIG_MTD_SLRAM is not set
 # CONFIG_MTD_SM_COMMON is not set
 # CONFIG_MTD_SPINAND_MT29F is not set
-- 
2.11.0


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH 01/11] generic: routerbootpart MTD parser for RouterBoot

2020-03-28 Thread Thibaut VARÈNE
This driver provides an OF MTD parser to properly assign the RouterBoot
partitions on the flash. This parser builds from the "fixed-partitions"
one (see ofpart.c), but it can handle dynamic partitions as found on
routerboot devices.

The parent node must contain the following:
compatible = "mikrotik,routerboot-partitions";
#address-cells = <1>;
#size-cells = <1>;

Children routerbootpart DTS nodes are defined as follows:
For fixed partitions
node-name@unit-address {
reg = ;
label = ;
read-only;
lock;
};

All properties but reg are optional.

For dynamic partitions:
node-name {
size = ;
label = ;
read-only;
lock;
};

size property is mandatory unless the next partition is a fixed one or
a "well-known" one (matched from the strings defined below) in which case
it can be omitted or set to 0; other properties are optional.

By default dynamic partitions are appended after the preceding one, except
for "well-known" ones which are automatically located on flash.

Well-known partitions (matched via label or node-name):
 - "hard_config"
 - "soft_config"
 - "dtb_config"

This parser requires the DTS to list partitions in ascending order as
expected on the MTD device.

This parser has been successfully tested on BE (ath79) and LE (ipq40xx)
hardware.

Tested-by: Baptiste Jonglez 
Tested-by: Roger Pueyo Centelles 
Signed-off-by: Thibaut VARÈNE 
---
 .../files/drivers/mtd/parsers/routerbootpart.c | 355 +
 1 file changed, 355 insertions(+)
 create mode 100644 
target/linux/generic/files/drivers/mtd/parsers/routerbootpart.c

diff --git a/target/linux/generic/files/drivers/mtd/parsers/routerbootpart.c 
b/target/linux/generic/files/drivers/mtd/parsers/routerbootpart.c
new file mode 100644
index 00..1ca7135d80
--- /dev/null
+++ b/target/linux/generic/files/drivers/mtd/parsers/routerbootpart.c
@@ -0,0 +1,355 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Parser for MikroTik RouterBoot partitions.
+ *
+ * Copyright (C) 2020 Thibaut VARÈNE 
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation.
+ *
+ * This parser builds from the "fixed-partitions" one (see ofpart.c), but it 
can
+ * handle dynamic partitions as found on routerboot devices.
+ *
+ * DTS nodes are defined as follows:
+ * For fixed partitions:
+ * node-name@unit-address {
+ * reg = ;
+ * label = ;
+ * read-only;
+ * lock;
+ * };
+ *
+ * reg property is mandatory; other properties are optional.
+ * reg format is . length can be 0 if the next partition is
+ * another fixed partition or a "well-known" partition as defined below: in 
that
+ * case the partition will extend up to the next one.
+ *
+ * For dynamic partitions:
+ * node-name {
+ * size = ;
+ * label = ;
+ * read-only;
+ * lock;
+ * };
+ *
+ * size property is mandatory unless the next partition is a fixed one or
+ * a "well-known" one (matched from the strings defined below) in which case it
+ * can be omitted or set to 0; other properties are optional.
+ * size format is .
+ * By default dynamic partitions are appended after the preceding one, except
+ * for "well-known" ones which are automatically located on flash.
+ *
+ * Well-known partitions (matched via label or node-name):
+ * - "hard_config"
+ * - "soft_config"
+ * - "dtb_config"
+ *
+ * Note: this parser will happily register 0-sized partitions if misused.
+ *
+ * This parser requires the DTS to list partitions in ascending order as
+ * expected on the MTD device.
+ *
+ * Since only the "hard_config" and "soft_config" partitions are used in 
OpenWRT,
+ * a minimal working DTS could define only these two partitions dynamically (in
+ * the right order, usually hard_config then soft_config).
+ */
+
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define RB_MAGIC_HARD  (('H') | ('a' << 8) | ('r' << 16) | ('d' << 24))
+#define RB_MAGIC_SOFT  (('S') | ('o' << 8) | ('f' << 16) | ('t' << 24))
+#define RB_BLOCK_SIZE  0x1000
+
+struct routerboot_dynpart {
+   const char * const name;
+   const u32 magic;
+   int (* const size_fixup)(struct mtd_info *, struct routerboot_dynpart 
*);
+   size_t offset;
+   size_t size;
+   bool found;
+};
+
+static int routerboot_dtbsfixup(struct mtd_info *, struct routerboot_dynpart 
*);
+
+static struct rou

[OpenWrt-Devel] [PATCH 02/11] generic: routerboot partition build bits (4.19)

2020-03-28 Thread Thibaut VARÈNE
Signed-off-by: Thibaut VARÈNE 
---
 .../435-mtd-add-routerbootpart-parser-config.patch | 25 ++
 1 file changed, 25 insertions(+)
 create mode 100644 
target/linux/generic/pending-4.19/435-mtd-add-routerbootpart-parser-config.patch

diff --git 
a/target/linux/generic/pending-4.19/435-mtd-add-routerbootpart-parser-config.patch
 
b/target/linux/generic/pending-4.19/435-mtd-add-routerbootpart-parser-config.patch
new file mode 100644
index 00..2cc91179b1
--- /dev/null
+++ 
b/target/linux/generic/pending-4.19/435-mtd-add-routerbootpart-parser-config.patch
@@ -0,0 +1,25 @@
+diff --git a/drivers/mtd/parsers/Kconfig b/drivers/mtd/parsers/Kconfig
+index de6f5f8..0afa89c 100644
+--- a/drivers/mtd/parsers/Kconfig
 b/drivers/mtd/parsers/Kconfig
+@@ -22,3 +22,12 @@ config MTD_SHARPSL_PARTS
+ This provides the read-only FTL logic necessary to read the partition
+ table from the NAND flash of Sharp SL Series (Zaurus) and the MTD
+ partition parser using this code.
++
++config MTD_ROUTERBOOT_PARTS
++  tristate "RouterBoot flash partition parser"
++  depends on MTD && OF
++  help
++MikroTik RouterBoot is implemented as a multi segment system on the
++flash, some of which are fixed and some of which are located at
++variable offsets. This parser handles both cases via properly
++formatted DTS.
+diff --git a/drivers/mtd/parsers/Makefile b/drivers/mtd/parsers/Makefile
+index 44ff342..0543362 100644
+--- a/drivers/mtd/parsers/Makefile
 b/drivers/mtd/parsers/Makefile
+@@ -1,2 +1,3 @@
+ obj-$(CONFIG_MTD_PARSER_TRX)  += parser_trx.o
+ obj-$(CONFIG_MTD_SHARPSL_PARTS)   += sharpslpart.o
++obj-$(CONFIG_MTD_ROUTERBOOT_PARTS)+= routerbootpart.o
-- 
2.11.0


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH 07/11] generic: routerboot partition build bits (4.14)

2020-03-28 Thread Thibaut VARÈNE
Signed-off-by: Thibaut VARÈNE 
---
 .../435-mtd-add-routerbootpart-parser-config.patch | 41 ++
 1 file changed, 41 insertions(+)
 create mode 100644 
target/linux/generic/pending-4.14/435-mtd-add-routerbootpart-parser-config.patch

diff --git 
a/target/linux/generic/pending-4.14/435-mtd-add-routerbootpart-parser-config.patch
 
b/target/linux/generic/pending-4.14/435-mtd-add-routerbootpart-parser-config.patch
new file mode 100644
index 00..79aa89dcb3
--- /dev/null
+++ 
b/target/linux/generic/pending-4.14/435-mtd-add-routerbootpart-parser-config.patch
@@ -0,0 +1,41 @@
+From 4437e01fb6bca63fccdba5d6c44888b0935885c2 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Thibaut=20VAR=C3=88NE?= 
+Date: Tue, 24 Mar 2020 11:45:07 +0100
+Subject: [PATCH] generic: routerboot partition build bits (4.14)
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+Signed-off-by: Thibaut VARÈNE 
+---
+ drivers/mtd/parsers/Kconfig  | 9 +
+ drivers/mtd/parsers/Makefile | 1 +
+ 2 files changed, 10 insertions(+)
+
+diff --git a/drivers/mtd/parsers/Kconfig b/drivers/mtd/parsers/Kconfig
+index d206b3c..58cbdd6 100644
+--- a/drivers/mtd/parsers/Kconfig
 b/drivers/mtd/parsers/Kconfig
+@@ -6,3 +6,12 @@ config MTD_PARSER_TRX
+ may contain up to 3/4 partitions (depending on the version).
+ This driver will parse TRX header and report at least two partitions:
+ kernel and rootfs.
++
++config MTD_ROUTERBOOT_PARTS
++  tristate "RouterBoot flash partition parser"
++  depends on MTD && OF
++  help
++MikroTik RouterBoot is implemented as a multi segment system on the
++flash, some of which are fixed and some of which are located at
++variable offsets. This parser handles both cases via properly
++formatted DTS.
+diff --git a/drivers/mtd/parsers/Makefile b/drivers/mtd/parsers/Makefile
+index 4d9024e..41d363a 100644
+--- a/drivers/mtd/parsers/Makefile
 b/drivers/mtd/parsers/Makefile
+@@ -1 +1,2 @@
+ obj-$(CONFIG_MTD_PARSER_TRX)  += parser_trx.o
++obj-$(CONFIG_MTD_ROUTERBOOT_PARTS)+= routerbootpart.o
+-- 
+2.11.0
+
-- 
2.11.0


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH 06/11] ath79: MikroTik RB 922UAGS-5HPacD routerboot partitions

2020-03-28 Thread Thibaut VARÈNE
Signed-off-by: Thibaut VARÈNE 
---
 .../dts/qca9558_mikrotik_routerboard-922uags-5hpacd.dts  | 16 ++--
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git 
a/target/linux/ath79/dts/qca9558_mikrotik_routerboard-922uags-5hpacd.dts 
b/target/linux/ath79/dts/qca9558_mikrotik_routerboard-922uags-5hpacd.dts
index 3f2a1a51a6..9a1bd52948 100644
--- a/target/linux/ath79/dts/qca9558_mikrotik_routerboard-922uags-5hpacd.dts
+++ b/target/linux/ath79/dts/qca9558_mikrotik_routerboard-922uags-5hpacd.dts
@@ -99,32 +99,28 @@
spi-max-frequency = <2500>;
 
partitions {
-   compatible = "fixed-partitions";
+   compatible = "mikrotik,routerboot-partitions";
#address-cells = <1>;
#size-cells = <1>;
 
-   partition@0 {
+   partition1@0 {
label = "routerboot";
-   reg = <0x000 0x000c000>;
+   reg = <0x0 0x0>;
read-only;
};
 
-   hard_config: partition@c000 {
+   hard_config: partition2 {
label = "hard_config";
-   reg = <0x000c000 0x0001000>;
read-only;
};
 
-   partition@d000 {
+   partition3 {
label = "bios";
-   reg = <0x000d000 0x0001000>;
read-only;
};
 
-   partition@e000 {
+   partition4 {
label = "soft_config";
-   reg = <0x000e000 0x0001000>;
-   read-only;
};
};
};
-- 
2.11.0


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH 04/11] ath79: mikrotik: enable CONFIG_MTD_ROUTERBOOT_PARTS

2020-03-28 Thread Thibaut VARÈNE
Signed-off-by: Thibaut VARÈNE 
---
 target/linux/ath79/mikrotik/config-default | 1 +
 1 file changed, 1 insertion(+)

diff --git a/target/linux/ath79/mikrotik/config-default 
b/target/linux/ath79/mikrotik/config-default
index a95d13406a..cea3d3cc57 100644
--- a/target/linux/ath79/mikrotik/config-default
+++ b/target/linux/ath79/mikrotik/config-default
@@ -17,6 +17,7 @@ CONFIG_MTD_UBI=y
 CONFIG_MTD_UBI_BLOCK=y
 CONFIG_MTD_UBI_WL_THRESHOLD=4096
 CONFIG_MTD_UBI_BEB_LIMIT=20
+CONFIG_MTD_ROUTERBOOT_PARTS=y
 # CONFIG_MTD_UBI_FASTMAP is not set
 # CONFIG_MTD_UBI_GLUEBI is not set
 CONFIG_NET_SWITCHDEV=y
-- 
2.11.0


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH 05/11] ath79: MikroTik WAP G-5HacT2HnD routerboot partitions

2020-03-28 Thread Thibaut VARÈNE
Tested-by: Roger Pueyo Centelles 
Signed-off-by: Thibaut VARÈNE 
---
 .../qca9556_mikrotik_routerboard-wap-g-5hact2hnd.dts | 20 +---
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git 
a/target/linux/ath79/dts/qca9556_mikrotik_routerboard-wap-g-5hact2hnd.dts 
b/target/linux/ath79/dts/qca9556_mikrotik_routerboard-wap-g-5hact2hnd.dts
index 5fd4623726..ebb2465e15 100644
--- a/target/linux/ath79/dts/qca9556_mikrotik_routerboard-wap-g-5hact2hnd.dts
+++ b/target/linux/ath79/dts/qca9556_mikrotik_routerboard-wap-g-5hact2hnd.dts
@@ -84,37 +84,35 @@
label = "RouterBoot";
reg = <0x0 0x2>;
read-only;
-   compatible = "fixed-partitions";
+   compatible = "mikrotik,routerboot-partitions";
#address-cells = <1>;
#size-cells = <1>;
 
-   partition@0 {
+   partition1@0 {
label = "bootloader1";
-   reg = <0x0 0xe000>;
+   reg = <0x0 0x0>;
read-only;
};
 
-   hard_config: partition@e000 {
+   hard_config: partition2 {
label = "hard_config";
-   reg = <0xe000 0x1000>;
read-only;
};
 
-   partition@f000 {
+   partition3 {
label = "bios";
-   reg = <0xf000 0x1000>;
+   size = <0x1000>;
read-only;
};
 
-   partition@1 {
+   partition4@1 {
label = "bootloader2";
-   reg = <0x1 0xf000>;
+   reg = <0x1 0x0>;
read-only;
};
 
-   partition@1f000 {
+   partition5 {
label = "soft_config";
-   reg = <0x1f000 0x1000>;
};
};
 
-- 
2.11.0


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH 09/11] ramips: MikroTik RB750GR3 routerboot partitions

2020-03-28 Thread Thibaut VARÈNE
Signed-off-by: Thibaut VARÈNE 
---
 target/linux/ramips/dts/mt7621_mikrotik_rb750gr3.dts | 12 
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/target/linux/ramips/dts/mt7621_mikrotik_rb750gr3.dts 
b/target/linux/ramips/dts/mt7621_mikrotik_rb750gr3.dts
index da2b571dd4..b8f56afb52 100644
--- a/target/linux/ramips/dts/mt7621_mikrotik_rb750gr3.dts
+++ b/target/linux/ramips/dts/mt7621_mikrotik_rb750gr3.dts
@@ -86,19 +86,17 @@
label = "RouterBoot";
reg = <0x0 0x4>;
read-only;
-   compatible = "fixed-partitions";
+   compatible = "mikrotik,routerboot-partitions";
#address-cells = <1>;
#size-cells = <1>;
 
partition@0 {
label = "bootloader1";
-   reg = <0x0 0xf000>;
+   reg = <0x0 0x0>;
read-only;
};
 
-   hard_config: partition@f000 {
-   label = "hard_config";
-   reg = <0xf000 0x1000>;
+   hard_config: hard_config {
read-only;
};
 
@@ -108,9 +106,7 @@
read-only;
};
 
-   partition@2 {
-   label = "soft_config";
-   reg = <0x2 0x1000>;
+   soft_config {
};
 
partition@3 {
-- 
2.11.0


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH 10/11] ramips: MikroTik RBM11G routerboot partitions

2020-03-28 Thread Thibaut VARÈNE
Signed-off-by: Thibaut VARÈNE 
---
 target/linux/ramips/dts/mt7621_mikrotik_rbm11g.dts | 12 
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/target/linux/ramips/dts/mt7621_mikrotik_rbm11g.dts 
b/target/linux/ramips/dts/mt7621_mikrotik_rbm11g.dts
index 60b6395c17..4e5f5915e3 100644
--- a/target/linux/ramips/dts/mt7621_mikrotik_rbm11g.dts
+++ b/target/linux/ramips/dts/mt7621_mikrotik_rbm11g.dts
@@ -95,19 +95,17 @@
label = "RouterBoot";
reg = <0x0 0x4>;
read-only;
-   compatible = "fixed-partitions";
+   compatible = "mikrotik,routerboot-partitions";
#address-cells = <1>;
#size-cells = <1>;
 
partition@0 {
label = "bootloader1";
-   reg = <0x0 0xf000>;
+   reg = <0x0 0x0>;
read-only;
};
 
-   hard_config: partition@f000 {
-   label = "hard_config";
-   reg = <0xf000 0x1000>;
+   hard_config: hard_config {
read-only;
};
 
@@ -117,9 +115,7 @@
read-only;
};
 
-   partition@2 {
-   label = "soft_config";
-   reg = <0x2 0x1000>;
+   soft_config {
};
 
partition@3 {
-- 
2.11.0


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH 08/11] ramips: mt7621: enable CONFIG_MTD_ROUTERBOOT_PARTS

2020-03-28 Thread Thibaut VARÈNE
Signed-off-by: Thibaut VARÈNE 
---
 target/linux/ramips/mt7621/config-4.14 | 1 +
 1 file changed, 1 insertion(+)

diff --git a/target/linux/ramips/mt7621/config-4.14 
b/target/linux/ramips/mt7621/config-4.14
index 2ae6afb97f..d8c8c95d30 100644
--- a/target/linux/ramips/mt7621/config-4.14
+++ b/target/linux/ramips/mt7621/config-4.14
@@ -188,6 +188,7 @@ CONFIG_MTD_M25P80=y
 CONFIG_MTD_NAND=y
 CONFIG_MTD_NAND_ECC=y
 CONFIG_MTD_PHYSMAP=y
+CONFIG_MTD_ROUTERBOOT_PARTS=y
 CONFIG_MTD_SPI_NOR=y
 CONFIG_MTD_SPLIT_MINOR_FW=y
 CONFIG_MTD_SPLIT_SEAMA_FW=y
-- 
2.11.0


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH 11/11] ramips: MikroTik RBM33G routerboot partitions

2020-03-28 Thread Thibaut VARÈNE
Signed-off-by: Thibaut VARÈNE 
---
 target/linux/ramips/dts/mt7621_mikrotik_rbm33g.dts | 12 
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/target/linux/ramips/dts/mt7621_mikrotik_rbm33g.dts 
b/target/linux/ramips/dts/mt7621_mikrotik_rbm33g.dts
index 2500ae29da..9895bb70d5 100644
--- a/target/linux/ramips/dts/mt7621_mikrotik_rbm33g.dts
+++ b/target/linux/ramips/dts/mt7621_mikrotik_rbm33g.dts
@@ -104,19 +104,17 @@
label = "RouterBoot";
reg = <0x0 0x4>;
read-only;
-   compatible = "fixed-partitions";
+   compatible = "mikrotik,routerboot-partitions";
#address-cells = <1>;
#size-cells = <1>;
 
partition@0 {
label = "bootloader1";
-   reg = <0x0 0xf000>;
+   reg = <0x0 0x0>;
read-only;
};
 
-   hard_config: partition@f000 {
-   label = "hard_config";
-   reg = <0xf000 0x1000>;
+   hard_config: hard_config {
read-only;
};
 
@@ -126,9 +124,7 @@
read-only;
};
 
-   partition@2 {
-   label = "soft_config";
-   reg = <0x2 0x1000>;
+   soft_config {
};
 
partition@3 {
-- 
2.11.0


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH 1/8] generic: routerboot sysfs platform driver

2020-04-03 Thread Thibaut VARÈNE
This driver exposes the data encoded in the "hard_config" flash segment
of MikroTik RouterBOARDs devices. It presents the data in a sysfs folder
named "hard_config". The WLAN calibration data is available on demand via
the 'wlan_data' sysfs file in that folder.

This driver permanently allocates a chunk of RAM as large as the
"hard_config" MTD partition (typically 4KB), although it is technically
possible to operate entirely from the MTD device without using a local
buffer (except when requesting WLAN calibration data), at the cost of a
performance penalty.

This driver does not reuse any of the existing code previously found in
routerboot.c.

This driver has been successfully tested on BE (ath79) and LE (ipq40xx)
hardware.

Tested-by: Roger Pueyo Centelles 
Tested-by: Baptiste Jonglez 
Signed-off-by: Thibaut VARÈNE 
---
 .../files/drivers/platform/mikrotik/Kconfig|  17 +
 .../files/drivers/platform/mikrotik/Makefile   |   4 +
 .../drivers/platform/mikrotik/rb_hardconfig.c  | 483 +
 .../files/drivers/platform/mikrotik/routerboot.c   | 185 
 .../files/drivers/platform/mikrotik/routerboot.h   |  32 ++
 5 files changed, 721 insertions(+)
 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

diff --git a/target/linux/generic/files/drivers/platform/mikrotik/Kconfig 
b/target/linux/generic/files/drivers/platform/mikrotik/Kconfig
new file mode 100644
index 00..98cc44d068
--- /dev/null
+++ b/target/linux/generic/files/drivers/platform/mikrotik/Kconfig
@@ -0,0 +1,17 @@
+menuconfig MIKROTIK
+bool "Platform support for MikroTik RouterBoard virtual devices"
+depends on MTD
+   select LZO_DECOMPRESS
+help
+  Say Y here to get to see options for the MikroTik RouterBoard 
platform.
+  This option alone does not add any kernel code.
+
+
+if MIKROTIK
+
+config ROUTERBOOT_SYSFS_CFG
+tristate "RouterBoot sysfs support"
+help
+ This driver exposes RouterBoot configuration in sysfs.
+
+endif # MIKROTIK
diff --git a/target/linux/generic/files/drivers/platform/mikrotik/Makefile 
b/target/linux/generic/files/drivers/platform/mikrotik/Makefile
new file mode 100644
index 00..32d0a4395e
--- /dev/null
+++ b/target/linux/generic/files/drivers/platform/mikrotik/Makefile
@@ -0,0 +1,4 @@
+#
+# Makefile for MikroTik RouterBoard platform specific drivers
+#
+obj-$(CONFIG_ROUTERBOOT_SYSFS_CFG) += routerboot.o rb_hardconfig.o
diff --git 
a/target/linux/generic/files/drivers/platform/mikrotik/rb_hardconfig.c 
b/target/linux/generic/files/drivers/platform/mikrotik/rb_hardconfig.c
new file mode 100644
index 00..567db76e35
--- /dev/null
+++ b/target/linux/generic/files/drivers/platform/mikrotik/rb_hardconfig.c
@@ -0,0 +1,483 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Driver for MikroTik RouterBoot hard config.
+ *
+ * Copyright (C) 2020 Thibaut VARÈNE 
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation.
+ *
+ * This driver exposes the data encoded in the "hard_config" flash segment of
+ * MikroTik RouterBOARDs devices. It presents the data in a sysfs folder
+ * named "hard_config". The WLAN calibration data is available on demand via
+ * the 'wlan_data' sysfs file in that folder.
+ *
+ * This driver permanently allocates a chunk of RAM as large as the hard_config
+ * MTD partition, although it is technically possible to operate entirely from
+ * the MTD device without using a local buffer (except when requesting WLAN
+ * calibration data), at the cost of a performance penalty.
+ *
+ * Some constant defines extracted from routerboot.{c,h} by Gabor Juhos
+ * 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "routerboot.h"
+
+#define RB_HARDCONFIG_VER  "0.01"
+#define PR_PREFIX  "[rb_hardconfig] "
+
+/* ID values for hardware settings */
+#define RB_ID_FLASH_INFO   0x03
+#define RB_ID_MAC_ADDRESS_PACK 0x04
+#define RB_ID_BOARD_PRODUCT_CODE   0x05
+#define RB_ID_BIOS_VERSION 0x06
+#define RB_ID_SDRAM_TIMINGS0x08
+#define RB_ID_DEVICE_TIMINGS   0x09
+#define RB_ID_SOFTWARE_ID  0x0A
+#define RB_ID_SERIAL_NUMBER0x0B
+#define RB_ID_MEMORY_SIZE  0x0D
+#

[OpenWrt-Devel] [PATCH 2/8] generic: mikrotik platform build bits (4.14)

2020-04-03 Thread Thibaut VARÈNE
Signed-off-by: Thibaut VARÈNE 
---
 .../270-platform-mikrotik-build-bits.patch | 36 ++
 1 file changed, 36 insertions(+)
 create mode 100644 
target/linux/generic/pending-4.14/270-platform-mikrotik-build-bits.patch

diff --git 
a/target/linux/generic/pending-4.14/270-platform-mikrotik-build-bits.patch 
b/target/linux/generic/pending-4.14/270-platform-mikrotik-build-bits.patch
new file mode 100644
index 00..026476c15e
--- /dev/null
+++ b/target/linux/generic/pending-4.14/270-platform-mikrotik-build-bits.patch
@@ -0,0 +1,36 @@
+From c2deb5ef01a0ef09088832744cbace9e239a6ee0 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Thibaut=20VAR=C3=88NE?= 
+Date: Tue, 24 Mar 2020 22:11:50 +0100
+Subject: [PATCH] generic: platform/mikrotik build bits (4.14)
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+Signed-off-by: Thibaut VARÈNE 
+---
+ drivers/platform/Kconfig  | 2 ++
+ drivers/platform/Makefile | 1 +
+ 2 files changed, 3 insertions(+)
+
+diff --git a/drivers/platform/Kconfig b/drivers/platform/Kconfig
+index c11db8b..0283f0b 100644
+--- a/drivers/platform/Kconfig
 b/drivers/platform/Kconfig
+@@ -8,3 +8,5 @@ endif
+ source "drivers/platform/goldfish/Kconfig"
+ 
+ source "drivers/platform/chrome/Kconfig"
++
++source "drivers/platform/mikrotik/Kconfig"
+diff --git a/drivers/platform/Makefile b/drivers/platform/Makefile
+index d3a6630..ad290c3 100644
+--- a/drivers/platform/Makefile
 b/drivers/platform/Makefile
+@@ -8,3 +8,4 @@ obj-$(CONFIG_MIPS) += mips/
+ obj-$(CONFIG_OLPC)+= olpc/
+ obj-$(CONFIG_GOLDFISH)+= goldfish/
+ obj-$(CONFIG_CHROME_PLATFORMS)+= chrome/
++obj-$(CONFIG_MIKROTIK)+= mikrotik/
+-- 
+2.11.0
+
-- 
2.11.0


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH 3/8] generic: mikrotik platform build bits (4.19)

2020-04-03 Thread Thibaut VARÈNE
UNTESTED

Signed-off-by: Thibaut VARÈNE 
---
 .../270-platform-mikrotik-build-bits.patch | 36 ++
 1 file changed, 36 insertions(+)
 create mode 100644 
target/linux/generic/pending-4.19/270-platform-mikrotik-build-bits.patch

diff --git 
a/target/linux/generic/pending-4.19/270-platform-mikrotik-build-bits.patch 
b/target/linux/generic/pending-4.19/270-platform-mikrotik-build-bits.patch
new file mode 100644
index 00..4c5e92e0e3
--- /dev/null
+++ b/target/linux/generic/pending-4.19/270-platform-mikrotik-build-bits.patch
@@ -0,0 +1,36 @@
+From c2deb5ef01a0ef09088832744cbace9e239a6ee0 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Thibaut=20VAR=C3=88NE?= 
+Date: Sat, 28 Mar 2020 12:11:50 +0100
+Subject: [PATCH] generic: platform/mikrotik build bits (4.14)
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+Signed-off-by: Thibaut VARÈNE 
+---
+ drivers/platform/Kconfig  | 2 ++
+ drivers/platform/Makefile | 1 +
+ 2 files changed, 3 insertions(+)
+
+diff --git a/drivers/platform/Kconfig b/drivers/platform/Kconfig
+index c11db8b..0283f0b 100644
+--- a/drivers/platform/Kconfig
 b/drivers/platform/Kconfig
+@@ -10,3 +10,5 @@
+ source "drivers/platform/chrome/Kconfig"
+
+ source "drivers/platform/mellanox/Kconfig"
++
++source "drivers/platform/mikrotik/Kconfig"
+diff --git a/drivers/platform/Makefile b/drivers/platform/Makefile
+index d3a6630..ad290c3 100644
+--- a/drivers/platform/Makefile
 b/drivers/platform/Makefile
+@@ -9,3 +9,4 @@
+ obj-$(CONFIG_OLPC)+= olpc/
+ obj-$(CONFIG_GOLDFISH)+= goldfish/
+ obj-$(CONFIG_CHROME_PLATFORMS)+= chrome/
++obj-$(CONFIG_MIKROTIK)+= mikrotik/
+-- 
+2.11.0
+
-- 
2.11.0


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH 4/8] generic: CONFIG_MIKROTIK is not set

2020-04-03 Thread Thibaut VARÈNE
Signed-off-by: Thibaut VARÈNE 
---
 target/linux/generic/config-4.14 | 1 +
 target/linux/generic/config-4.19 | 1 +
 target/linux/generic/config-5.4  | 1 +
 3 files changed, 3 insertions(+)

diff --git a/target/linux/generic/config-4.14 b/target/linux/generic/config-4.14
index e42139744a..9e9b0e1d7c 100644
--- a/target/linux/generic/config-4.14
+++ b/target/linux/generic/config-4.14
@@ -2661,6 +2661,7 @@ CONFIG_MESSAGE_LOGLEVEL_DEFAULT=4
 # CONFIG_MIGRATION is not set
 CONFIG_MII=y
 # CONFIG_MIKROTIK_RB532 is not set
+# CONFIG_MIKROTIK is not set
 # CONFIG_MINIX_FS is not set
 # CONFIG_MINIX_FS_NATIVE_ENDIAN is not set
 # CONFIG_MINIX_SUBPARTITION is not set
diff --git a/target/linux/generic/config-4.19 b/target/linux/generic/config-4.19
index 32209674ba..ee7f3f1352 100644
--- a/target/linux/generic/config-4.19
+++ b/target/linux/generic/config-4.19
@@ -2810,6 +2810,7 @@ CONFIG_MESSAGE_LOGLEVEL_DEFAULT=4
 # CONFIG_MIGRATION is not set
 CONFIG_MII=y
 # CONFIG_MIKROTIK_RB532 is not set
+# CONFIG_MIKROTIK is not set
 # CONFIG_MINIX_FS is not set
 # CONFIG_MINIX_FS_NATIVE_ENDIAN is not set
 # CONFIG_MINIX_SUBPARTITION is not set
diff --git a/target/linux/generic/config-5.4 b/target/linux/generic/config-5.4
index b5deef31de..19825e494c 100644
--- a/target/linux/generic/config-5.4
+++ b/target/linux/generic/config-5.4
@@ -2989,6 +2989,7 @@ CONFIG_MESSAGE_LOGLEVEL_DEFAULT=4
 # CONFIG_MIGRATION is not set
 CONFIG_MII=y
 # CONFIG_MIKROTIK_RB532 is not set
+# CONFIG_MIKROTIK is not set
 # CONFIG_MINIX_FS is not set
 # CONFIG_MINIX_FS_NATIVE_ENDIAN is not set
 # CONFIG_MINIX_SUBPARTITION is not set
-- 
2.11.0


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH 7/8] ramips: enable mikrotik platform driver

2020-04-03 Thread Thibaut VARÈNE
Signed-off-by: Thibaut VARÈNE 
---
 target/linux/ramips/mt7621/config-4.14 | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/target/linux/ramips/mt7621/config-4.14 
b/target/linux/ramips/mt7621/config-4.14
index 2ae6afb97f..a90f8ad6cd 100644
--- a/target/linux/ramips/mt7621/config-4.14
+++ b/target/linux/ramips/mt7621/config-4.14
@@ -182,6 +182,8 @@ CONFIG_MIPS_SPRAM=y
 # CONFIG_MIPS_VPE_LOADER is not set
 CONFIG_MODULES_USE_ELF_REL=y
 CONFIG_MT7621_WDT=y
+CONFIG_MIKROTIK=y
+CONFIG_ROUTERBOOT_SYSFS_CFG=y
 # CONFIG_MTD_CFI_INTELEXT is not set
 CONFIG_MTD_CMDLINE_PARTS=y
 CONFIG_MTD_M25P80=y
-- 
2.11.0


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH 6/8] ar71xx: enable mikrotik platform driver

2020-04-03 Thread Thibaut VARÈNE
Signed-off-by: Thibaut VARÈNE 
---
 target/linux/ar71xx/mikrotik/config-default | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/target/linux/ar71xx/mikrotik/config-default 
b/target/linux/ar71xx/mikrotik/config-default
index e324e4c252..984e5aa908 100644
--- a/target/linux/ar71xx/mikrotik/config-default
+++ b/target/linux/ar71xx/mikrotik/config-default
@@ -26,6 +26,8 @@ CONFIG_HW_HAS_PCI=y
 CONFIG_LEDS_RB750=y
 CONFIG_LZO_DECOMPRESS=y
 # CONFIG_MARVELL_PHY is not set
+CONFIG_MIKROTIK=y
+CONFIG_ROUTERBOOT_SYSFS_CFG=y
 # CONFIG_MTD_CFI is not set
 CONFIG_MTD_CFI_I2=y
 # CONFIG_MTD_CMDLINE_PARTS is not set
-- 
2.11.0


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH 5/8] ath79: enable mikrotik platform driver

2020-04-03 Thread Thibaut VARÈNE
Signed-off-by: Thibaut VARÈNE 
---
 target/linux/ath79/mikrotik/config-default | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/target/linux/ath79/mikrotik/config-default 
b/target/linux/ath79/mikrotik/config-default
index a95d13406a..11b3a8c4bf 100644
--- a/target/linux/ath79/mikrotik/config-default
+++ b/target/linux/ath79/mikrotik/config-default
@@ -6,6 +6,8 @@ CONFIG_GPIO_WATCHDOG=y
 CONFIG_GPIO_WATCHDOG_ARCH_INITCALL=y
 CONFIG_LEDS_RESET=y
 CONFIG_LZO_DECOMPRESS=y
+CONFIG_MIKROTIK=y
+CONFIG_ROUTERBOOT_SYSFS_CFG=y
 CONFIG_MTD_NAND=y
 CONFIG_MTD_NAND_AR934X=y
 CONFIG_MTD_NAND_CORE=y
-- 
2.11.0


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH 0/8, RFC] RouterBOARD sysfs driver for RouterBoot data

2020-04-03 Thread Thibaut VARÈNE
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.

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.

 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.
It doesn't (yet) remove the need to use flash space to store that extracted
data, however should this driver be accepted, it would be technically be 
possible
to implement direct DTS-based accessors (I have been pointed at nvmem).

 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.

 Bootnotes:
This driver doesn't (yet) offer OF capabilities, it seemed unnecessary at this
stage, this also makes it possible to use the driver on ar71xx (it's been tested
successfully there too), in case a backport is desirable (for instance to
address PR#2729). Adding OF support is nevertheless possible if required.

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
"/sys/firmware/mikrotik".

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
context).

The code currently allocates a buffer the size of the hard_config flash
partition, but it's been written in a way that makes it possible to switch to
reading directly from the flash without ever allocating permanent RAM
(obviously at a performance cost).

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).

I once again grouped the kernel config edits for simplicity. This patchset is
orthogonal to my previous series ("MTD parser for RouterBoot partitions") and
can be tested independently. There are a few "XXX" comments in the code which
are pending feedback from this submission and will be cleaned up in the final
patch.

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

I guess that sums it up, I hope this helps; looking forward to comments :)
Thibaut

T

[OpenWrt-Devel] [PATCH 8/8] generic: platform/mikrotik: support LZOR encoding

2020-04-03 Thread Thibaut VARÈNE
Some newer MikroTik RouterBOARD devices use a new encoding scheme
for their WLAN calibration data. This patch provides support for
decoding this new scheme.

Signed-off-by: Thibaut VARÈNE 
---
 .../drivers/platform/mikrotik/rb_hardconfig.c  | 261 -
 1 file changed, 260 insertions(+), 1 deletion(-)

diff --git 
a/target/linux/generic/files/drivers/platform/mikrotik/rb_hardconfig.c 
b/target/linux/generic/files/drivers/platform/mikrotik/rb_hardconfig.c
index 567db76e35..97f1e95763 100644
--- a/target/linux/generic/files/drivers/platform/mikrotik/rb_hardconfig.c
+++ b/target/linux/generic/files/drivers/platform/mikrotik/rb_hardconfig.c
@@ -37,7 +37,7 @@
 
 #include "routerboot.h"
 
-#define RB_HARDCONFIG_VER  "0.01"
+#define RB_HARDCONFIG_VER  "0.02"
 #define PR_PREFIX  "[rb_hardconfig] "
 
 /* ID values for hardware settings */
@@ -76,6 +76,190 @@ static struct kobject *hc_kobj;
 static u8 *hc_buf; // ro buffer after init(): no locking required
 static size_t hc_buflen;
 
+/*
+ * For LZOR style WLAN data unpacking.
+ * This binary blob is prepended to the data encoded on some devices as
+ * RB_ID_WLAN_DATA, the result is then first decompressed with LZO, and then
+ * finally RLE-decoded.
+ * This binary blob has been extracted from RouterOS by
+ * https://forum.openwrt.org/u/ius
+ */
+static const u8 hc_lzor_prefix[] = {
+   0x00, 0x05, 0x4c, 0x4c, 0x44, 0x00, 0x34, 0xfe,
+   0xfe, 0x34, 0x11, 0x3c, 0x1e, 0x3c, 0x2e, 0x3c,
+   0x4c, 0x34, 0x00, 0x52, 0x62, 0x92, 0xa2, 0xb2,
+   0xc3, 0x2a, 0x14, 0x00, 0x00, 0x05, 0xfe, 0x6a,
+   0x3c, 0x16, 0x32, 0x16, 0x11, 0x1e, 0x12, 0x46,
+   0x32, 0x46, 0x11, 0x4e, 0x12, 0x36, 0x32, 0x36,
+   0x11, 0x3e, 0x12, 0x5a, 0x9a, 0x64, 0x00, 0x04,
+   0xfe, 0x10, 0x3c, 0x00, 0x01, 0x00, 0x00, 0x28,
+   0x0c, 0x00, 0x0f, 0xfe, 0x14, 0x00, 0x24, 0x24,
+   0x23, 0x24, 0x24, 0x23, 0x25, 0x22, 0x21, 0x21,
+   0x23, 0x22, 0x21, 0x22, 0x21, 0x2d, 0x38, 0x00,
+   0x0c, 0x25, 0x25, 0x24, 0x25, 0x25, 0x24, 0x23,
+   0x22, 0x21, 0x20, 0x23, 0x21, 0x21, 0x22, 0x21,
+   0x2d, 0x38, 0x00, 0x28, 0xb0, 0x00, 0x00, 0x22,
+   0x00, 0x00, 0xc0, 0xfe, 0x03, 0x00, 0xc0, 0x00,
+   0x62, 0xff, 0x62, 0xff, 0xfe, 0x06, 0x00, 0xbb,
+   0xff, 0xba, 0xff, 0xfe, 0x08, 0x00, 0x9e, 0xff,
+   0xfe, 0x0a, 0x00, 0x53, 0xff, 0xfe, 0x02, 0x00,
+   0x20, 0xff, 0xb1, 0xfe, 0xfe, 0xb2, 0xfe, 0xfe,
+   0xed, 0xfe, 0xfe, 0xfe, 0x04, 0x00, 0x3a, 0xff,
+   0x3a, 0xff, 0xde, 0xfd, 0x5f, 0x04, 0x33, 0xff,
+   0x4c, 0x74, 0x03, 0x05, 0x05, 0xff, 0x6d, 0xfe,
+   0xfe, 0x6d, 0xfe, 0xfe, 0xaf, 0x08, 0x63, 0xff,
+   0x64, 0x6f, 0x08, 0xac, 0xff, 0xbf, 0x6d, 0x08,
+   0x7a, 0x6d, 0x08, 0x96, 0x74, 0x04, 0x00, 0x08,
+   0x79, 0xff, 0xda, 0xfe, 0xfe, 0xdb, 0xfe, 0xfe,
+   0x56, 0xff, 0xfe, 0x04, 0x00, 0x5e, 0xff, 0x5e,
+   0xff, 0x6c, 0xfe, 0xfe, 0xfe, 0x06, 0x00, 0x41,
+   0xff, 0x7f, 0x74, 0x03, 0x00, 0x11, 0x44, 0xff,
+   0xa9, 0xfe, 0xfe, 0xa9, 0xfe, 0xfe, 0xa5, 0x8f,
+   0x01, 0x00, 0x08, 0x01, 0x01, 0x02, 0x04, 0x08,
+   0x02, 0x04, 0x08, 0x08, 0x01, 0x01, 0xfe, 0x22,
+   0x00, 0x4c, 0x60, 0x64, 0x8c, 0x90, 0xd0, 0xd4,
+   0xd8, 0x5c, 0x10, 0x09, 0xd8, 0xff, 0xb0, 0xff,
+   0x00, 0x00, 0xba, 0xff, 0x14, 0x00, 0xba, 0xff,
+   0x64, 0x00, 0x00, 0x08, 0xfe, 0x06, 0x00, 0x74,
+   0xff, 0x42, 0xff, 0xce, 0xff, 0x60, 0xff, 0x0a,
+   0x00, 0xb4, 0x00, 0xa0, 0x00, 0xa0, 0xfe, 0x07,
+   0x00, 0x0a, 0x00, 0xb0, 0xff, 0x96, 0x4d, 0x00,
+   0x56, 0x57, 0x18, 0xa6, 0xff, 0x92, 0x70, 0x11,
+   0x00, 0x12, 0x90, 0x90, 0x76, 0x5a, 0x54, 0x54,
+   0x4c, 0x46, 0x38, 0x00, 0x10, 0x10, 0x08, 0xfe,
+   0x05, 0x00, 0x38, 0x29, 0x25, 0x23, 0x22, 0x22,
+   0x1f, 0x00, 0x00, 0x00, 0xf6, 0xe1, 0xdd, 0xf8,
+   0xfe, 0x00, 0xfe, 0x15, 0x00, 0x00, 0xd0, 0x02,
+   0x74, 0x02, 0x08, 0xf8, 0xe5, 0xde, 0x02, 0x04,
+   0x04, 0xfd, 0x00, 0x00, 0x00, 0x07, 0x50, 0x2d,
+   0x01, 0x90, 0x90, 0x76, 0x60, 0xb0, 0x07, 0x07,
+   0x0c, 0x0c, 0x04, 0xfe, 0x05, 0x00, 0x66, 0x66,
+   0x5a, 0x56, 0xbc, 0x01, 0x06, 0xfc, 0xfc, 0xf1,
+   0xfe, 0x07, 0x00, 0x24, 0x95, 0x70, 0x64, 0x18,
+   0x06, 0x2c, 0xff, 0xb5, 0xfe, 0xfe, 0xb5, 0xfe,
+   0xfe, 0xe2, 0x8c, 0x24, 0x02, 0x2f, 0xff, 0x2f,
+   0xff, 0xb4, 0x78, 0x02, 0x05, 0x73, 0xff, 0xed,
+   0xfe, 0xfe, 0x4f, 0xff, 0x36, 0x74, 0x1e, 0x09,
+   0x4f, 0xff, 0x50, 0xff, 0xfe, 0x16, 0x00, 0x70,
+   0xac, 0x70, 0x8e, 0xac, 0x40, 0x0e, 0x01, 0x70,
+   0x7f, 0x8e, 0xac, 0x6c, 0x00, 0x0b, 0xfe, 0x02,
+   0x00, 0xfe, 0x0a, 0x2c, 0x2a, 0x2a, 0x28, 0x26,
+   0x1e, 0x1e, 0xfe, 0x02, 0x20, 0x65, 0x20, 0x00,
+   0x00, 0x05, 0x12, 0x00, 0x11, 0x1e, 0x11, 0x11,
+   0x41, 0x1e, 0x41, 0x11, 0x31, 0x1e, 0x31, 0x11,
+   0x70, 0x75, 0x7a, 0x7f, 0x84, 0x89, 0x8e, 0x93,
+   

[OpenWrt-Devel] [PATCH v2 1/6] generic: routerbootpart MTD parser for RouterBoot

2020-04-20 Thread Thibaut VARÈNE
This driver provides an OF MTD parser to properly assign the RouterBoot
partitions on the flash. This parser builds from the "fixed-partitions"
one (see ofpart.c), but it can handle dynamic partitions as found on
routerboot devices.

The parent node must contain the following:
compatible = "mikrotik,routerboot-partitions";
#address-cells = <1>;
#size-cells = <1>;

Children routerbootpart DTS nodes are defined as follows:
For fixed partitions
node-name@unit-address {
reg = ;
label = ;
read-only;
lock;
};

All properties but reg are optional.

For dynamic partitions:
node-name {
size = ;
label = ;
read-only;
lock;
};

size property is mandatory unless the next partition is a fixed one or
a "well-known" one (matched from the strings defined below) in which case
it can be omitted or set to 0; other properties are optional.

By default dynamic partitions are appended after the preceding one, except
for "well-known" ones which are automatically located on flash.

Well-known partitions (matched via label or node-name):
 - "hard_config"
 - "soft_config"
 - "dtb_config"

This parser requires the DTS to list partitions in ascending order as
expected on the MTD device.

This parser has been successfully tested on BE (ath79) and LE (ipq40xx
and ramips) hardware.

Tested-by: Baptiste Jonglez 
Tested-by: Roger Pueyo Centelles 
Tested-by: Tobias Schramm 
Tested-by: Christopher Hill 
Signed-off-by: Thibaut VARÈNE 
---
 .../files/drivers/mtd/parsers/routerbootpart.c | 357 +
 1 file changed, 357 insertions(+)
 create mode 100644 
target/linux/generic/files/drivers/mtd/parsers/routerbootpart.c

diff --git a/target/linux/generic/files/drivers/mtd/parsers/routerbootpart.c 
b/target/linux/generic/files/drivers/mtd/parsers/routerbootpart.c
new file mode 100644
index 00..8b0784388f
--- /dev/null
+++ b/target/linux/generic/files/drivers/mtd/parsers/routerbootpart.c
@@ -0,0 +1,357 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Parser for MikroTik RouterBoot partitions.
+ *
+ * Copyright (C) 2020 Thibaut VARÈNE 
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation.
+ *
+ * This parser builds from the "fixed-partitions" one (see ofpart.c), but it 
can
+ * handle dynamic partitions as found on routerboot devices.
+ *
+ * DTS nodes are defined as follows:
+ * For fixed partitions:
+ * node-name@unit-address {
+ * reg = ;
+ * label = ;
+ * read-only;
+ * lock;
+ * };
+ *
+ * reg property is mandatory; other properties are optional.
+ * reg format is . length can be 0 if the next partition is
+ * another fixed partition or a "well-known" partition as defined below: in 
that
+ * case the partition will extend up to the next one.
+ *
+ * For dynamic partitions:
+ * node-name {
+ * size = ;
+ * label = ;
+ * read-only;
+ * lock;
+ * };
+ *
+ * size property is mandatory unless the next partition is a fixed one or
+ * a "well-known" one (matched from the strings defined below) in which case it
+ * can be omitted or set to 0; other properties are optional.
+ * size format is .
+ * By default dynamic partitions are appended after the preceding one, except
+ * for "well-known" ones which are automatically located on flash.
+ *
+ * Well-known partitions (matched via label or node-name):
+ * - "hard_config"
+ * - "soft_config"
+ * - "dtb_config"
+ *
+ * Note: this parser will happily register 0-sized partitions if misused.
+ *
+ * This parser requires the DTS to list partitions in ascending order as
+ * expected on the MTD device.
+ *
+ * Since only the "hard_config" and "soft_config" partitions are used in 
OpenWRT,
+ * a minimal working DTS could define only these two partitions dynamically (in
+ * the right order, usually hard_config then soft_config).
+ *
+ * Note: some mips RB devices encode the hard_config offset and length in two
+ * consecutive u32 located at offset 0x14 (for ramips) or 0x24 (for ath79) on
+ * the SPI NOR flash. Unfortunately this seems inconsistent across machines and
+ * does not apply to e.g. ipq-based ones, so we ignore that information.
+ */
+
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define RB_MAGIC_HARD  (('H') | ('a' << 8) | ('r' << 16) | ('d' << 24))
+#define RB_MAGIC_SOFT  (('S') | ('o' << 8) | ('f' << 16) | ('t' << 2

[OpenWrt-Devel] [PATCH v2 2/6] generic: routerboot partition build bits

2020-04-20 Thread Thibaut VARÈNE
Signed-off-by: Thibaut VARÈNE 
---
 target/linux/generic/config-4.14   |  1 +
 target/linux/generic/config-4.19   |  1 +
 target/linux/generic/config-5.4|  1 +
 .../435-mtd-add-routerbootpart-parser-config.patch | 43 ++
 .../435-mtd-add-routerbootpart-parser-config.patch | 41 +
 .../435-mtd-add-routerbootpart-parser-config.patch | 38 +++
 6 files changed, 125 insertions(+)
 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

diff --git a/target/linux/generic/config-4.14 b/target/linux/generic/config-4.14
index cd087227ae..c8b3c602dd 100644
--- a/target/linux/generic/config-4.14
+++ b/target/linux/generic/config-4.14
@@ -2877,6 +2877,7 @@ CONFIG_MTD_REDBOOT_DIRECTORY_BLOCK=-1
 # CONFIG_MTD_REDBOOT_PARTS_UNALLOCATED is not set
 # CONFIG_MTD_ROM is not set
 CONFIG_MTD_ROOTFS_ROOT_DEV=y
+# CONFIG_MTD_ROUTERBOOT_PARTS is not set
 # CONFIG_MTD_SLRAM is not set
 # CONFIG_MTD_SM_COMMON is not set
 # CONFIG_MTD_SPINAND_MT29F is not set
diff --git a/target/linux/generic/config-4.19 b/target/linux/generic/config-4.19
index 4ce3de57ad..9e3e35f793 100644
--- a/target/linux/generic/config-4.19
+++ b/target/linux/generic/config-4.19
@@ -3024,6 +3024,7 @@ CONFIG_MTD_REDBOOT_DIRECTORY_BLOCK=-1
 # CONFIG_MTD_REDBOOT_PARTS_UNALLOCATED is not set
 # CONFIG_MTD_ROM is not set
 CONFIG_MTD_ROOTFS_ROOT_DEV=y
+# CONFIG_MTD_ROUTERBOOT_PARTS is not set
 # CONFIG_MTD_SLRAM is not set
 # CONFIG_MTD_SM_COMMON is not set
 # CONFIG_MTD_SPINAND_MT29F is not set
diff --git a/target/linux/generic/config-5.4 b/target/linux/generic/config-5.4
index 21dd447cdf..7a7f27c1fc 100644
--- a/target/linux/generic/config-5.4
+++ b/target/linux/generic/config-5.4
@@ -3220,6 +3220,7 @@ CONFIG_MTD_REDBOOT_DIRECTORY_BLOCK=-1
 # CONFIG_MTD_REDBOOT_PARTS_UNALLOCATED is not set
 # CONFIG_MTD_ROM is not set
 CONFIG_MTD_ROOTFS_ROOT_DEV=y
+# CONFIG_MTD_ROUTERBOOT_PARTS is not set
 # CONFIG_MTD_SLRAM is not set
 # CONFIG_MTD_SM_COMMON is not set
 # CONFIG_MTD_SPINAND_MT29F is not set
diff --git 
a/target/linux/generic/pending-4.14/435-mtd-add-routerbootpart-parser-config.patch
 
b/target/linux/generic/pending-4.14/435-mtd-add-routerbootpart-parser-config.patch
new file mode 100644
index 00..192886b102
--- /dev/null
+++ 
b/target/linux/generic/pending-4.14/435-mtd-add-routerbootpart-parser-config.patch
@@ -0,0 +1,43 @@
+From 4437e01fb6bca63fccdba5d6c44888b0935885c2 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Thibaut=20VAR=C3=88NE?= 
+Date: Tue, 24 Mar 2020 11:45:07 +0100
+Subject: [PATCH] generic: routerboot partition build bits (4.14)
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+This patch adds routerbootpart kernel build bits
+
+Signed-off-by: Thibaut VARÈNE 
+---
+ drivers/mtd/parsers/Kconfig  | 9 +
+ drivers/mtd/parsers/Makefile | 1 +
+ 2 files changed, 10 insertions(+)
+
+diff --git a/drivers/mtd/parsers/Kconfig b/drivers/mtd/parsers/Kconfig
+index d206b3c..58cbdd6 100644
+--- a/drivers/mtd/parsers/Kconfig
 b/drivers/mtd/parsers/Kconfig
+@@ -6,3 +6,12 @@ config MTD_PARSER_TRX
+ may contain up to 3/4 partitions (depending on the version).
+ This driver will parse TRX header and report at least two partitions:
+ kernel and rootfs.
++
++config MTD_ROUTERBOOT_PARTS
++  tristate "RouterBoot flash partition parser"
++  depends on MTD && OF
++  help
++MikroTik RouterBoot is implemented as a multi segment system on the
++flash, some of which are fixed and some of which are located at
++variable offsets. This parser handles both cases via properly
++formatted DTS.
+diff --git a/drivers/mtd/parsers/Makefile b/drivers/mtd/parsers/Makefile
+index 4d9024e..41d363a 100644
+--- a/drivers/mtd/parsers/Makefile
 b/drivers/mtd/parsers/Makefile
+@@ -1 +1,2 @@
+ obj-$(CONFIG_MTD_PARSER_TRX)  += parser_trx.o
++obj-$(CONFIG_MTD_ROUTERBOOT_PARTS)+= routerbootpart.o
+-- 
+2.11.0
+
diff --git 
a/target/linux/generic/pending-4.19/435-mtd-add-routerbootpart-parser-config.patch
 
b/target/linux/generic/pending-4.19/435-mtd-add-routerbootpart-parser-config.patch
new file mode 100644
index 00..678eaed4ce
--- /dev/null
+++ 
b/target/linux/generic/pending-4.19/435-mtd-add-routerbootpart-parser-config.patch
@@ -0,0 +1,41 @@
+From 4437e01fb6bca63fccdba5d6c44888b0935885c2 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Thibaut=20VAR=C3=88NE?= 
+Date: Tue, 24 Mar 2020 11:45:07 +0100
+Subject: [PATCH] generic: routerboot partition build bits (4.19)
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+This patch adds routerboo

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

2020-04-20 Thread Thibaut VARÈNE
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 = <0x 0x10>;
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 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.

HTH,
Thibaut

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

-- 
2.11.0


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH v2 5/6] ramips/mt7621: enable CONFIG_MTD_ROUTERBOOT_PARTS

2020-04-20 Thread Thibaut VARÈNE
Signed-off-by: Thibaut VARÈNE 
---
 target/linux/ramips/mt7621/config-4.14 | 1 +
 target/linux/ramips/mt7621/config-5.4  | 1 +
 2 files changed, 2 insertions(+)

diff --git a/target/linux/ramips/mt7621/config-4.14 
b/target/linux/ramips/mt7621/config-4.14
index 2ae6afb97f..d8c8c95d30 100644
--- a/target/linux/ramips/mt7621/config-4.14
+++ b/target/linux/ramips/mt7621/config-4.14
@@ -188,6 +188,7 @@ CONFIG_MTD_M25P80=y
 CONFIG_MTD_NAND=y
 CONFIG_MTD_NAND_ECC=y
 CONFIG_MTD_PHYSMAP=y
+CONFIG_MTD_ROUTERBOOT_PARTS=y
 CONFIG_MTD_SPI_NOR=y
 CONFIG_MTD_SPLIT_MINOR_FW=y
 CONFIG_MTD_SPLIT_SEAMA_FW=y
diff --git a/target/linux/ramips/mt7621/config-5.4 
b/target/linux/ramips/mt7621/config-5.4
index e91003d8d2..65b10b80e4 100644
--- a/target/linux/ramips/mt7621/config-5.4
+++ b/target/linux/ramips/mt7621/config-5.4
@@ -205,6 +205,7 @@ CONFIG_MTD_NAND_ECC_SW_HAMMING=y
 CONFIG_MTD_NAND_MT7621=y
 CONFIG_MTD_PHYSMAP=y
 CONFIG_MTD_RAW_NAND=y
+CONFIG_MTD_ROUTERBOOT_PARTS=y
 CONFIG_MTD_SPI_NOR=y
 CONFIG_MTD_SPLIT_MINOR_FW=y
 CONFIG_MTD_SPLIT_SEAMA_FW=y
-- 
2.11.0


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH v2 4/6] ath79/mikrotik: use routerbootpart partitions

2020-04-20 Thread Thibaut VARÈNE
Enable routerbootpart partitions on MikroTik devices.

Tested-by: Roger Pueyo Centelles 
Signed-off-by: Thibaut VARÈNE 
---
 .../qca9556_mikrotik_routerboard-wap-g-5hact2hnd.dts   | 18 +++---
 .../qca9558_mikrotik_routerboard-922uags-5hpacd.dts| 17 +
 2 files changed, 12 insertions(+), 23 deletions(-)

diff --git 
a/target/linux/ath79/dts/qca9556_mikrotik_routerboard-wap-g-5hact2hnd.dts 
b/target/linux/ath79/dts/qca9556_mikrotik_routerboard-wap-g-5hact2hnd.dts
index 529ac1cf3b..18b58990b9 100644
--- a/target/linux/ath79/dts/qca9556_mikrotik_routerboard-wap-g-5hact2hnd.dts
+++ b/target/linux/ath79/dts/qca9556_mikrotik_routerboard-wap-g-5hact2hnd.dts
@@ -84,37 +84,33 @@
label = "RouterBoot";
reg = <0x0 0x2>;
read-only;
-   compatible = "fixed-partitions";
+   compatible = "mikrotik,routerboot-partitions";
#address-cells = <1>;
#size-cells = <1>;
 
partition@0 {
label = "bootloader1";
-   reg = <0x0 0xe000>;
+   reg = <0x0 0x0>;
read-only;
};
 
-   hard_config: partition@e000 {
-   label = "hard_config";
-   reg = <0xe000 0x1000>;
+   hard_config: hard_config {
read-only;
};
 
-   partition@f000 {
-   label = "bios";
-   reg = <0xf000 0x1000>;
+   bios {
+   size = <0x1000>;
read-only;
};
 
partition@1 {
label = "bootloader2";
-   reg = <0x1 0xf000>;
+   reg = <0x1 0x0>;
read-only;
};
 
-   partition@1f000 {
+   soft_config {
label = "soft_config";
-   reg = <0x1f000 0x1000>;
};
};
 
diff --git 
a/target/linux/ath79/dts/qca9558_mikrotik_routerboard-922uags-5hpacd.dts 
b/target/linux/ath79/dts/qca9558_mikrotik_routerboard-922uags-5hpacd.dts
index 3f2a1a51a6..e40909678b 100644
--- a/target/linux/ath79/dts/qca9558_mikrotik_routerboard-922uags-5hpacd.dts
+++ b/target/linux/ath79/dts/qca9558_mikrotik_routerboard-922uags-5hpacd.dts
@@ -99,32 +99,25 @@
spi-max-frequency = <2500>;
 
partitions {
-   compatible = "fixed-partitions";
+   compatible = "mikrotik,routerboot-partitions";
#address-cells = <1>;
#size-cells = <1>;
 
partition@0 {
label = "routerboot";
-   reg = <0x000 0x000c000>;
+   reg = <0x0 0x0>;
read-only;
};
 
-   hard_config: partition@c000 {
-   label = "hard_config";
-   reg = <0x000c000 0x0001000>;
+   hard_config: hard_config {
read-only;
};
 
-   partition@d000 {
-   label = "bios";
-   reg = <0x000d000 0x0001000>;
+   bios {
read-only;
};
 
-   partition@e000 {
-   label = "soft_config";
-   reg = <0x000e000 0x0001000>;
-   read-only;
+   soft_config {
};
};
};
-- 
2.11.0


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH v2 3/6] ath79/mikrotik: enable CONFIG_MTD_ROUTERBOOT_PARTS

2020-04-20 Thread Thibaut VARÈNE
Signed-off-by: Thibaut VARÈNE 
---
 target/linux/ath79/mikrotik/config-default | 1 +
 1 file changed, 1 insertion(+)

diff --git a/target/linux/ath79/mikrotik/config-default 
b/target/linux/ath79/mikrotik/config-default
index c0c61985bc..e1e30dbe8f 100644
--- a/target/linux/ath79/mikrotik/config-default
+++ b/target/linux/ath79/mikrotik/config-default
@@ -11,6 +11,7 @@ CONFIG_MTD_NAND_AR934X=y
 CONFIG_MTD_NAND_CORE=y
 CONFIG_MTD_NAND_ECC=y
 CONFIG_MTD_RAW_NAND=y
+CONFIG_MTD_ROUTERBOOT_PARTS=y
 CONFIG_MTD_SPI_NAND=y
 CONFIG_MTD_SPI_NOR_USE_4K_SECTORS=y
 CONFIG_MTD_SPLIT_MINOR_FW=y
-- 
2.11.0


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH v2 6/6] ramips: mikrotik: use routerbootpart partitions

2020-04-20 Thread Thibaut VARÈNE
Enable routerbootpart partitions on MikroTik devices.

Tested-by: Tobias Schramm 
Signed-off-by: Thibaut VARÈNE 
---
 .../linux/ramips/dts/mt7621_mikrotik_routerboard-750gr3.dts  | 12 
 target/linux/ramips/dts/mt7621_mikrotik_routerboard-m11g.dts | 12 
 target/linux/ramips/dts/mt7621_mikrotik_routerboard-m33g.dts | 12 
 3 files changed, 12 insertions(+), 24 deletions(-)

diff --git a/target/linux/ramips/dts/mt7621_mikrotik_routerboard-750gr3.dts 
b/target/linux/ramips/dts/mt7621_mikrotik_routerboard-750gr3.dts
index 3f37155f24..d7f97ef1d6 100644
--- a/target/linux/ramips/dts/mt7621_mikrotik_routerboard-750gr3.dts
+++ b/target/linux/ramips/dts/mt7621_mikrotik_routerboard-750gr3.dts
@@ -86,19 +86,17 @@
label = "RouterBoot";
reg = <0x0 0x4>;
read-only;
-   compatible = "fixed-partitions";
+   compatible = "mikrotik,routerboot-partitions";
#address-cells = <1>;
#size-cells = <1>;
 
partition@0 {
label = "bootloader1";
-   reg = <0x0 0xf000>;
+   reg = <0x0 0x0>;
read-only;
};
 
-   hard_config: partition@f000 {
-   label = "hard_config";
-   reg = <0xf000 0x1000>;
+   hard_config: hard_config {
read-only;
};
 
@@ -108,9 +106,7 @@
read-only;
};
 
-   partition@2 {
-   label = "soft_config";
-   reg = <0x2 0x1000>;
+   soft_config {
};
 
partition@3 {
diff --git a/target/linux/ramips/dts/mt7621_mikrotik_routerboard-m11g.dts 
b/target/linux/ramips/dts/mt7621_mikrotik_routerboard-m11g.dts
index bd58aea951..128b8a2816 100644
--- a/target/linux/ramips/dts/mt7621_mikrotik_routerboard-m11g.dts
+++ b/target/linux/ramips/dts/mt7621_mikrotik_routerboard-m11g.dts
@@ -95,19 +95,17 @@
label = "RouterBoot";
reg = <0x0 0x4>;
read-only;
-   compatible = "fixed-partitions";
+   compatible = "mikrotik,routerboot-partitions";
#address-cells = <1>;
#size-cells = <1>;
 
partition@0 {
label = "bootloader1";
-   reg = <0x0 0xf000>;
+   reg = <0x0 0x0>;
read-only;
};
 
-   hard_config: partition@f000 {
-   label = "hard_config";
-   reg = <0xf000 0x1000>;
+   hard_config: hard_config {
read-only;
};
 
@@ -117,9 +115,7 @@
read-only;
};
 
-   partition@2 {
-   label = "soft_config";
-   reg = <0x2 0x1000>;
+   soft_config {
};
 
partition@3 {
diff --git a/target/linux/ramips/dts/mt7621_mikrotik_routerboard-m33g.dts 
b/target/linux/ramips/dts/mt7621_mikrotik_routerboard-m33g.dts
index 19e1a71e99..aff2d0e64f 100644
--- a/target/linux/ramips/dts/mt7621_mikrotik_routerboard-m33g.dts
+++ b/target/linux/ramips/dts/mt7621_mikrotik_routerboard-m33g.dts
@@ -104,19 +104,17 @@
label = "RouterBoot";
reg = <0x0 0x4>;
read-only;
-   compatible = "fixed-partitions";
+   compatible = "mikrotik,routerboot-partitions";
#address-cells = <1>;
  

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

2020-04-20 Thread Thibaut VARÈNE
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.

 Bootnotes:
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
"/sys/firmware/mikrotik".

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
context).

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


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

[OpenWrt-Devel] [PATCH v2 01/14] generic: routerboot sysfs platform driver

2020-04-20 Thread Thibaut VARÈNE
This driver exposes the data encoded in the "hard_config" flash segment
of MikroTik RouterBOARDs devices. It presents the data in a sysfs folder
named "hard_config". The WLAN calibration data is available on demand via
the 'wlan_data' sysfs file in that folder.

This driver permanently allocates a chunk of RAM as large as the
"hard_config" MTD partition (typically 4KB), although it is technically
possible to operate entirely from the MTD device without using a local
buffer (except when requesting WLAN calibration data), at the cost of a
performance penalty.

This driver does not reuse any of the existing code previously found in
routerboot.c.

This driver has been successfully tested on BE (ath79) and LE (ipq40xx
and ramips) hardware.

Tested-by: Roger Pueyo Centelles 
Tested-by: Baptiste Jonglez 
Tested-by: Tobias Schramm 
Tested-by: Christopher Hill 
Signed-off-by: Thibaut VARÈNE 
---
 .../files/drivers/platform/mikrotik/Kconfig|  18 +
 .../files/drivers/platform/mikrotik/Makefile   |   4 +
 .../drivers/platform/mikrotik/rb_hardconfig.c  | 481 +
 .../files/drivers/platform/mikrotik/routerboot.c   | 185 
 .../files/drivers/platform/mikrotik/routerboot.h   |  31 ++
 5 files changed, 719 insertions(+)
 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

diff --git a/target/linux/generic/files/drivers/platform/mikrotik/Kconfig 
b/target/linux/generic/files/drivers/platform/mikrotik/Kconfig
new file mode 100644
index 00..195a1e8fd3
--- /dev/null
+++ b/target/linux/generic/files/drivers/platform/mikrotik/Kconfig
@@ -0,0 +1,18 @@
+menuconfig MIKROTIK
+   bool "Platform support for MikroTik RouterBoard virtual devices"
+   default n
+   depends on MTD
+   select LZO_DECOMPRESS
+   help
+ Say Y here to get to see options for the MikroTik RouterBoard 
platform.
+ This option alone does not add any kernel code.
+
+
+if MIKROTIK
+
+config MIKROTIK_RB_SYSFS
+   tristate "RouterBoot sysfs support"
+   help
+ This driver exposes RouterBoot configuration in sysfs.
+
+endif # MIKROTIK
diff --git a/target/linux/generic/files/drivers/platform/mikrotik/Makefile 
b/target/linux/generic/files/drivers/platform/mikrotik/Makefile
new file mode 100644
index 00..4d50ede9ff
--- /dev/null
+++ b/target/linux/generic/files/drivers/platform/mikrotik/Makefile
@@ -0,0 +1,4 @@
+#
+# Makefile for MikroTik RouterBoard platform specific drivers
+#
+obj-$(CONFIG_MIKROTIK_RB_SYSFS) += routerboot.o rb_hardconfig.o
diff --git 
a/target/linux/generic/files/drivers/platform/mikrotik/rb_hardconfig.c 
b/target/linux/generic/files/drivers/platform/mikrotik/rb_hardconfig.c
new file mode 100644
index 00..0653d7f9f6
--- /dev/null
+++ b/target/linux/generic/files/drivers/platform/mikrotik/rb_hardconfig.c
@@ -0,0 +1,481 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Driver for MikroTik RouterBoot hard config.
+ *
+ * Copyright (C) 2020 Thibaut VARÈNE 
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation.
+ *
+ * This driver exposes the data encoded in the "hard_config" flash segment of
+ * MikroTik RouterBOARDs devices. It presents the data in a sysfs folder
+ * named "hard_config". The WLAN calibration data is available on demand via
+ * the 'wlan_data' sysfs file in that folder.
+ *
+ * This driver permanently allocates a chunk of RAM as large as the hard_config
+ * MTD partition, although it is technically possible to operate entirely from
+ * the MTD device without using a local buffer (except when requesting WLAN
+ * calibration data), at the cost of a performance penalty.
+ *
+ * Some constant defines extracted from routerboot.{c,h} by Gabor Juhos
+ * 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "routerboot.h"
+
+#define RB_HARDCONFIG_VER  "0.01"
+#define PR_PREFIX  "[rb_hardconfig] "
+
+/* ID values for hardware settings */
+#define RB_ID_FLASH_INFO   0x03
+#define RB_ID_MAC_ADDRESS_PACK 0x04
+#define RB_ID_BOARD_PRODUCT_CODE   0x05
+#define RB_ID_BIOS_VERSION 0x06
+#define RB_ID_SDRAM_TIMINGS0x08
+#define RB_ID_DEVICE_TIMINGS   0x09
+#define RB_ID_SOFTWARE_ID  0x0A
+#define RB_ID_SERIAL_NUMBER   

[OpenWrt-Devel] [PATCH v2 02/14] generic: mikrotik platform build bits

2020-04-20 Thread Thibaut VARÈNE
Signed-off-by: Thibaut VARÈNE 
---
 target/linux/generic/config-4.14   |  1 +
 target/linux/generic/config-4.19   |  1 +
 target/linux/generic/config-5.4|  1 +
 .../270-platform-mikrotik-build-bits.patch | 38 ++
 .../270-platform-mikrotik-build-bits.patch | 38 ++
 .../270-platform-mikrotik-build-bits.patch | 31 ++
 6 files changed, 110 insertions(+)
 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

diff --git a/target/linux/generic/config-4.14 b/target/linux/generic/config-4.14
index cd087227ae..4b97a9c640 100644
--- a/target/linux/generic/config-4.14
+++ b/target/linux/generic/config-4.14
@@ -2651,6 +2651,7 @@ CONFIG_MESSAGE_LOGLEVEL_DEFAULT=4
 # CONFIG_MIGRATION is not set
 CONFIG_MII=y
 # CONFIG_MIKROTIK_RB532 is not set
+# CONFIG_MIKROTIK is not set
 # CONFIG_MINIX_FS is not set
 # CONFIG_MINIX_FS_NATIVE_ENDIAN is not set
 # CONFIG_MINIX_SUBPARTITION is not set
diff --git a/target/linux/generic/config-4.19 b/target/linux/generic/config-4.19
index 4ce3de57ad..bc137d2c8b 100644
--- a/target/linux/generic/config-4.19
+++ b/target/linux/generic/config-4.19
@@ -2791,6 +2791,7 @@ CONFIG_MESSAGE_LOGLEVEL_DEFAULT=4
 # CONFIG_MIGRATION is not set
 CONFIG_MII=y
 # CONFIG_MIKROTIK_RB532 is not set
+# CONFIG_MIKROTIK is not set
 # CONFIG_MINIX_FS is not set
 # CONFIG_MINIX_FS_NATIVE_ENDIAN is not set
 # CONFIG_MINIX_SUBPARTITION is not set
diff --git a/target/linux/generic/config-5.4 b/target/linux/generic/config-5.4
index 21dd447cdf..43767df5ed 100644
--- a/target/linux/generic/config-5.4
+++ b/target/linux/generic/config-5.4
@@ -2970,6 +2970,7 @@ CONFIG_MESSAGE_LOGLEVEL_DEFAULT=4
 # CONFIG_MIGRATION is not set
 CONFIG_MII=y
 # CONFIG_MIKROTIK_RB532 is not set
+# CONFIG_MIKROTIK is not set
 # CONFIG_MINIX_FS is not set
 # CONFIG_MINIX_FS_NATIVE_ENDIAN is not set
 # CONFIG_MINIX_SUBPARTITION is not set
diff --git 
a/target/linux/generic/pending-4.14/270-platform-mikrotik-build-bits.patch 
b/target/linux/generic/pending-4.14/270-platform-mikrotik-build-bits.patch
new file mode 100644
index 00..5f1009bf31
--- /dev/null
+++ b/target/linux/generic/pending-4.14/270-platform-mikrotik-build-bits.patch
@@ -0,0 +1,38 @@
+From c2deb5ef01a0ef09088832744cbace9e239a6ee0 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Thibaut=20VAR=C3=88NE?= 
+Date: Tue, 24 Mar 2020 22:11:50 +0100
+Subject: [PATCH] generic: platform/mikrotik build bits (4.14)
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+This patch adds platform/mikrotik kernel build bits
+
+Signed-off-by: Thibaut VARÈNE 
+---
+ drivers/platform/Kconfig  | 2 ++
+ drivers/platform/Makefile | 1 +
+ 2 files changed, 3 insertions(+)
+
+diff --git a/drivers/platform/Kconfig b/drivers/platform/Kconfig
+index c11db8b..0283f0b 100644
+--- a/drivers/platform/Kconfig
 b/drivers/platform/Kconfig
+@@ -8,3 +8,5 @@ endif
+ source "drivers/platform/goldfish/Kconfig"
+ 
+ source "drivers/platform/chrome/Kconfig"
++
++source "drivers/platform/mikrotik/Kconfig"
+diff --git a/drivers/platform/Makefile b/drivers/platform/Makefile
+index d3a6630..ad290c3 100644
+--- a/drivers/platform/Makefile
 b/drivers/platform/Makefile
+@@ -8,3 +8,4 @@ obj-$(CONFIG_MIPS) += mips/
+ obj-$(CONFIG_OLPC)+= olpc/
+ obj-$(CONFIG_GOLDFISH)+= goldfish/
+ obj-$(CONFIG_CHROME_PLATFORMS)+= chrome/
++obj-$(CONFIG_MIKROTIK)+= mikrotik/
+-- 
+2.11.0
+
diff --git 
a/target/linux/generic/pending-4.19/270-platform-mikrotik-build-bits.patch 
b/target/linux/generic/pending-4.19/270-platform-mikrotik-build-bits.patch
new file mode 100644
index 00..e2e8fbfcff
--- /dev/null
+++ b/target/linux/generic/pending-4.19/270-platform-mikrotik-build-bits.patch
@@ -0,0 +1,38 @@
+From c2deb5ef01a0ef09088832744cbace9e239a6ee0 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Thibaut=20VAR=C3=88NE?= 
+Date: Sat, 28 Mar 2020 12:11:50 +0100
+Subject: [PATCH] generic: platform/mikrotik build bits (4.19)
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+This patch adds platform/mikrotik kernel build bits
+
+Signed-off-by: Thibaut VARÈNE 
+---
+ drivers/platform/Kconfig  | 2 ++
+ drivers/platform/Makefile | 1 +
+ 2 files changed, 3 insertions(+)
+
+diff --git a/drivers/platform/Kconfig b/drivers/platform/Kconfig
+index c11db8b..0283f0b 100644
+--- a/drivers/platform/Kconfig
 b/drivers/platform/Kconfig
+@@ -10,3 +10,5 @@
+ source "drivers/platform/chrome/Kconfig"
+
+ source "drivers/platform/mellanox/Kconfig"
++
++source "drivers/platform/mikrotik/Kconfig"
+diff -

[OpenWrt-Devel] [PATCH v2 03/14] ath79/mikrotik: enable mikrotik platform driver

2020-04-20 Thread Thibaut VARÈNE
Signed-off-by: Thibaut VARÈNE 
---
 target/linux/ath79/mikrotik/config-default | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/target/linux/ath79/mikrotik/config-default 
b/target/linux/ath79/mikrotik/config-default
index c0c61985bc..43a339db41 100644
--- a/target/linux/ath79/mikrotik/config-default
+++ b/target/linux/ath79/mikrotik/config-default
@@ -6,6 +6,8 @@ CONFIG_GPIO_WATCHDOG=y
 CONFIG_GPIO_WATCHDOG_ARCH_INITCALL=y
 CONFIG_LEDS_RESET=y
 CONFIG_LZO_DECOMPRESS=y
+CONFIG_MIKROTIK=y
+CONFIG_MIKROTIK_RB_SYSFS=y
 CONFIG_MTD_NAND=y
 CONFIG_MTD_NAND_AR934X=y
 CONFIG_MTD_NAND_CORE=y
-- 
2.11.0


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH v2 07/14] ath79/mikrotik: don't use mtd-mac-address in DTS

2020-04-20 Thread Thibaut VARÈNE
As evidenced here[1] the device MAC address can be stored at a random
offset in the hard_config partition. Rely on sysfs to update the MAC
address correctly.

Note: this will trigger a harmless kernel message during boot:
ag71xx 1900.eth: invalid MAC address, using random address

There is no clean workaround to prevent this message from being emitted.

[1] https://github.com/openwrt/openwrt/pull/2850#issuecomment-610809021

Signed-off-by: Thibaut VARÈNE 
---
 .../ath79/dts/qca9556_mikrotik_routerboard-wap-g-5hact2hnd.dts | 3 ---
 .../ath79/dts/qca9558_mikrotik_routerboard-922uags-5hpacd.dts  | 2 --
 target/linux/ath79/mikrotik/base-files/etc/board.d/02_network  | 7 +++
 3 files changed, 7 insertions(+), 5 deletions(-)

diff --git 
a/target/linux/ath79/dts/qca9556_mikrotik_routerboard-wap-g-5hact2hnd.dts 
b/target/linux/ath79/dts/qca9556_mikrotik_routerboard-wap-g-5hact2hnd.dts
index 529ac1cf3b..3c0dc84a37 100644
--- a/target/linux/ath79/dts/qca9556_mikrotik_routerboard-wap-g-5hact2hnd.dts
+++ b/target/linux/ath79/dts/qca9556_mikrotik_routerboard-wap-g-5hact2hnd.dts
@@ -11,7 +11,6 @@
model = "MikroTik RouterBOARD wAP G-5HacT2HnD";
 
aliases {
-   label-mac-device = ð1;
mdio-gpio1 = &mdio2;
serial0 = &uart;
};
@@ -53,8 +52,6 @@
 ð1 {
status = "okay";
 
-   mtd-mac-address = <&hard_config 0x10>;
-
pll-data = <0x03000101 0x8101 0x80001313>;
phy-handle = <&phy0>;
 
diff --git 
a/target/linux/ath79/dts/qca9558_mikrotik_routerboard-922uags-5hpacd.dts 
b/target/linux/ath79/dts/qca9558_mikrotik_routerboard-922uags-5hpacd.dts
index 3f2a1a51a6..ff806ff88d 100644
--- a/target/linux/ath79/dts/qca9558_mikrotik_routerboard-922uags-5hpacd.dts
+++ b/target/linux/ath79/dts/qca9558_mikrotik_routerboard-922uags-5hpacd.dts
@@ -11,7 +11,6 @@
model = "MikroTik RouterBOARD 922UAGS-5HPacD";
 
aliases {
-   label-mac-device = ð0;
led-boot = &led_user;
led-failsafe = &led_user;
led-upgrade = &led_user;
@@ -80,7 +79,6 @@
 ð0 {
status = "okay";
 
-   mtd-mac-address = <&hard_config 0x10>;
phy-handle = <&phy4>;
pll-data = <0x8f00 0xa101 0xa0001313>;
 
diff --git a/target/linux/ath79/mikrotik/base-files/etc/board.d/02_network 
b/target/linux/ath79/mikrotik/base-files/etc/board.d/02_network
index ee795c7496..20c670f702 100755
--- a/target/linux/ath79/mikrotik/base-files/etc/board.d/02_network
+++ b/target/linux/ath79/mikrotik/base-files/etc/board.d/02_network
@@ -21,8 +21,15 @@ ath79_setup_interfaces()
 ath79_setup_macs()
 {
local board="$1"
+   local lan_mac=""
+   local wan_mac=""
+   local mac_base="/sys/firmware/mikrotik/hard_config/mac_base"
 
case "$board" in
+   *)
+   lan_mac="$(cat $mac_base)"
+   wan_mac="$(cat $mac_base)"
+   ;;
esac
 
[ -n "$lan_mac" ] && ucidef_set_interface_macaddr "lan" $lan_mac
-- 
2.11.0


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH v2 05/14] ramips/mt7621: enable mikrotik platform driver

2020-04-20 Thread Thibaut VARÈNE
Signed-off-by: Thibaut VARÈNE 
---
 target/linux/ramips/mt7621/config-4.14 | 2 ++
 target/linux/ramips/mt7621/config-5.4  | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/target/linux/ramips/mt7621/config-4.14 
b/target/linux/ramips/mt7621/config-4.14
index 2ae6afb97f..6da3a994a8 100644
--- a/target/linux/ramips/mt7621/config-4.14
+++ b/target/linux/ramips/mt7621/config-4.14
@@ -153,6 +153,8 @@ CONFIG_LZO_DECOMPRESS=y
 CONFIG_MDIO_BUS=y
 CONFIG_MDIO_DEVICE=y
 CONFIG_MIGRATION=y
+CONFIG_MIKROTIK=y
+CONFIG_MIKROTIK_RB_SYSFS=y
 CONFIG_MIPS=y
 CONFIG_MIPS_ASID_BITS=8
 CONFIG_MIPS_ASID_SHIFT=0
diff --git a/target/linux/ramips/mt7621/config-5.4 
b/target/linux/ramips/mt7621/config-5.4
index e91003d8d2..4a93ab702a 100644
--- a/target/linux/ramips/mt7621/config-5.4
+++ b/target/linux/ramips/mt7621/config-5.4
@@ -172,6 +172,8 @@ CONFIG_MDIO_DEVICE=y
 CONFIG_MEMFD_CREATE=y
 CONFIG_MFD_SYSCON=y
 CONFIG_MIGRATION=y
+CONFIG_MIKROTIK=y
+CONFIG_MIKROTIK_RB_SYSFS=y
 CONFIG_MIPS=y
 CONFIG_MIPS_ASID_BITS=8
 CONFIG_MIPS_ASID_SHIFT=0
-- 
2.11.0


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH v2 04/14] ar71xx/mikrotik: enable mikrotik platform driver

2020-04-20 Thread Thibaut VARÈNE
Signed-off-by: Thibaut VARÈNE 
---
 target/linux/ar71xx/mikrotik/config-default | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/target/linux/ar71xx/mikrotik/config-default 
b/target/linux/ar71xx/mikrotik/config-default
index e324e4c252..eb2f362034 100644
--- a/target/linux/ar71xx/mikrotik/config-default
+++ b/target/linux/ar71xx/mikrotik/config-default
@@ -26,6 +26,8 @@ CONFIG_HW_HAS_PCI=y
 CONFIG_LEDS_RB750=y
 CONFIG_LZO_DECOMPRESS=y
 # CONFIG_MARVELL_PHY is not set
+CONFIG_MIKROTIK=y
+CONFIG_MIKROTIK_RB_SYSFS=y
 # CONFIG_MTD_CFI is not set
 CONFIG_MTD_CFI_I2=y
 # CONFIG_MTD_CMDLINE_PARTS is not set
-- 
2.11.0


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH v2 06/14] generic: platform/mikrotik: support LZOR encoding

2020-04-20 Thread Thibaut VARÈNE
Some newer MikroTik RouterBOARD devices use a new encoding scheme
for their WLAN calibration data. This patch provides support for
decoding this new scheme.

Signed-off-by: Thibaut VARÈNE 
---
 .../drivers/platform/mikrotik/rb_hardconfig.c  | 262 -
 1 file changed, 261 insertions(+), 1 deletion(-)

diff --git 
a/target/linux/generic/files/drivers/platform/mikrotik/rb_hardconfig.c 
b/target/linux/generic/files/drivers/platform/mikrotik/rb_hardconfig.c
index 0653d7f9f6..a7d5db123c 100644
--- a/target/linux/generic/files/drivers/platform/mikrotik/rb_hardconfig.c
+++ b/target/linux/generic/files/drivers/platform/mikrotik/rb_hardconfig.c
@@ -37,7 +37,7 @@
 
 #include "routerboot.h"
 
-#define RB_HARDCONFIG_VER  "0.01"
+#define RB_HARDCONFIG_VER  "0.02"
 #define PR_PREFIX  "[rb_hardconfig] "
 
 /* ID values for hardware settings */
@@ -76,6 +76,190 @@ static struct kobject *hc_kobj;
 static u8 *hc_buf; // ro buffer after init(): no locking required
 static size_t hc_buflen;
 
+/*
+ * For LZOR style WLAN data unpacking.
+ * This binary blob is prepended to the data encoded on some devices as
+ * RB_ID_WLAN_DATA, the result is then first decompressed with LZO, and then
+ * finally RLE-decoded.
+ * This binary blob has been extracted from RouterOS by
+ * https://forum.openwrt.org/u/ius
+ */
+static const u8 hc_lzor_prefix[] = {
+   0x00, 0x05, 0x4c, 0x4c, 0x44, 0x00, 0x34, 0xfe,
+   0xfe, 0x34, 0x11, 0x3c, 0x1e, 0x3c, 0x2e, 0x3c,
+   0x4c, 0x34, 0x00, 0x52, 0x62, 0x92, 0xa2, 0xb2,
+   0xc3, 0x2a, 0x14, 0x00, 0x00, 0x05, 0xfe, 0x6a,
+   0x3c, 0x16, 0x32, 0x16, 0x11, 0x1e, 0x12, 0x46,
+   0x32, 0x46, 0x11, 0x4e, 0x12, 0x36, 0x32, 0x36,
+   0x11, 0x3e, 0x12, 0x5a, 0x9a, 0x64, 0x00, 0x04,
+   0xfe, 0x10, 0x3c, 0x00, 0x01, 0x00, 0x00, 0x28,
+   0x0c, 0x00, 0x0f, 0xfe, 0x14, 0x00, 0x24, 0x24,
+   0x23, 0x24, 0x24, 0x23, 0x25, 0x22, 0x21, 0x21,
+   0x23, 0x22, 0x21, 0x22, 0x21, 0x2d, 0x38, 0x00,
+   0x0c, 0x25, 0x25, 0x24, 0x25, 0x25, 0x24, 0x23,
+   0x22, 0x21, 0x20, 0x23, 0x21, 0x21, 0x22, 0x21,
+   0x2d, 0x38, 0x00, 0x28, 0xb0, 0x00, 0x00, 0x22,
+   0x00, 0x00, 0xc0, 0xfe, 0x03, 0x00, 0xc0, 0x00,
+   0x62, 0xff, 0x62, 0xff, 0xfe, 0x06, 0x00, 0xbb,
+   0xff, 0xba, 0xff, 0xfe, 0x08, 0x00, 0x9e, 0xff,
+   0xfe, 0x0a, 0x00, 0x53, 0xff, 0xfe, 0x02, 0x00,
+   0x20, 0xff, 0xb1, 0xfe, 0xfe, 0xb2, 0xfe, 0xfe,
+   0xed, 0xfe, 0xfe, 0xfe, 0x04, 0x00, 0x3a, 0xff,
+   0x3a, 0xff, 0xde, 0xfd, 0x5f, 0x04, 0x33, 0xff,
+   0x4c, 0x74, 0x03, 0x05, 0x05, 0xff, 0x6d, 0xfe,
+   0xfe, 0x6d, 0xfe, 0xfe, 0xaf, 0x08, 0x63, 0xff,
+   0x64, 0x6f, 0x08, 0xac, 0xff, 0xbf, 0x6d, 0x08,
+   0x7a, 0x6d, 0x08, 0x96, 0x74, 0x04, 0x00, 0x08,
+   0x79, 0xff, 0xda, 0xfe, 0xfe, 0xdb, 0xfe, 0xfe,
+   0x56, 0xff, 0xfe, 0x04, 0x00, 0x5e, 0xff, 0x5e,
+   0xff, 0x6c, 0xfe, 0xfe, 0xfe, 0x06, 0x00, 0x41,
+   0xff, 0x7f, 0x74, 0x03, 0x00, 0x11, 0x44, 0xff,
+   0xa9, 0xfe, 0xfe, 0xa9, 0xfe, 0xfe, 0xa5, 0x8f,
+   0x01, 0x00, 0x08, 0x01, 0x01, 0x02, 0x04, 0x08,
+   0x02, 0x04, 0x08, 0x08, 0x01, 0x01, 0xfe, 0x22,
+   0x00, 0x4c, 0x60, 0x64, 0x8c, 0x90, 0xd0, 0xd4,
+   0xd8, 0x5c, 0x10, 0x09, 0xd8, 0xff, 0xb0, 0xff,
+   0x00, 0x00, 0xba, 0xff, 0x14, 0x00, 0xba, 0xff,
+   0x64, 0x00, 0x00, 0x08, 0xfe, 0x06, 0x00, 0x74,
+   0xff, 0x42, 0xff, 0xce, 0xff, 0x60, 0xff, 0x0a,
+   0x00, 0xb4, 0x00, 0xa0, 0x00, 0xa0, 0xfe, 0x07,
+   0x00, 0x0a, 0x00, 0xb0, 0xff, 0x96, 0x4d, 0x00,
+   0x56, 0x57, 0x18, 0xa6, 0xff, 0x92, 0x70, 0x11,
+   0x00, 0x12, 0x90, 0x90, 0x76, 0x5a, 0x54, 0x54,
+   0x4c, 0x46, 0x38, 0x00, 0x10, 0x10, 0x08, 0xfe,
+   0x05, 0x00, 0x38, 0x29, 0x25, 0x23, 0x22, 0x22,
+   0x1f, 0x00, 0x00, 0x00, 0xf6, 0xe1, 0xdd, 0xf8,
+   0xfe, 0x00, 0xfe, 0x15, 0x00, 0x00, 0xd0, 0x02,
+   0x74, 0x02, 0x08, 0xf8, 0xe5, 0xde, 0x02, 0x04,
+   0x04, 0xfd, 0x00, 0x00, 0x00, 0x07, 0x50, 0x2d,
+   0x01, 0x90, 0x90, 0x76, 0x60, 0xb0, 0x07, 0x07,
+   0x0c, 0x0c, 0x04, 0xfe, 0x05, 0x00, 0x66, 0x66,
+   0x5a, 0x56, 0xbc, 0x01, 0x06, 0xfc, 0xfc, 0xf1,
+   0xfe, 0x07, 0x00, 0x24, 0x95, 0x70, 0x64, 0x18,
+   0x06, 0x2c, 0xff, 0xb5, 0xfe, 0xfe, 0xb5, 0xfe,
+   0xfe, 0xe2, 0x8c, 0x24, 0x02, 0x2f, 0xff, 0x2f,
+   0xff, 0xb4, 0x78, 0x02, 0x05, 0x73, 0xff, 0xed,
+   0xfe, 0xfe, 0x4f, 0xff, 0x36, 0x74, 0x1e, 0x09,
+   0x4f, 0xff, 0x50, 0xff, 0xfe, 0x16, 0x00, 0x70,
+   0xac, 0x70, 0x8e, 0xac, 0x40, 0x0e, 0x01, 0x70,
+   0x7f, 0x8e, 0xac, 0x6c, 0x00, 0x0b, 0xfe, 0x02,
+   0x00, 0xfe, 0x0a, 0x2c, 0x2a, 0x2a, 0x28, 0x26,
+   0x1e, 0x1e, 0xfe, 0x02, 0x20, 0x65, 0x20, 0x00,
+   0x00, 0x05, 0x12, 0x00, 0x11, 0x1e, 0x11, 0x11,
+   0x41, 0x1e, 0x41, 0x11, 0x31, 0x1e, 0x31, 0x11,
+   0x70, 0x75, 0x7a, 0x7f, 0x84, 0x89, 0x8e, 0x93,
+   

[OpenWrt-Devel] [PATCH v2 11/14] package/base-files: caldata: allow setting target file

2020-04-20 Thread Thibaut VARÈNE
This will enable platforms to extract caldata to an arbitrary file,
or patch mac in an abitrary file.

Signed-off-by: Thibaut VARÈNE 
---
 package/base-files/Makefile   |  2 +-
 package/base-files/files/lib/functions/caldata.sh | 29 ---
 2 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/package/base-files/Makefile b/package/base-files/Makefile
index 156e7bc8b9..f1f0f17a60 100644
--- a/package/base-files/Makefile
+++ b/package/base-files/Makefile
@@ -12,7 +12,7 @@ include $(INCLUDE_DIR)/version.mk
 include $(INCLUDE_DIR)/feeds.mk
 
 PKG_NAME:=base-files
-PKG_RELEASE:=218
+PKG_RELEASE:=219
 PKG_FLAGS:=nonshared
 
 PKG_FILE_DEPENDS:=$(PLATFORM_DIR)/ $(GENERIC_PLATFORM_DIR)/base-files/
diff --git a/package/base-files/files/lib/functions/caldata.sh 
b/package/base-files/files/lib/functions/caldata.sh
index 3bdb1e4dd5..e9349c7eee 100644
--- a/package/base-files/files/lib/functions/caldata.sh
+++ b/package/base-files/files/lib/functions/caldata.sh
@@ -60,15 +60,21 @@ caldata_from_file() {
local source=$1
local offset=$(($2))
local count=$(($3))
+   local target=$4
 
-   dd if=$source of=/lib/firmware/$FIRMWARE iflag=skip_bytes bs=$count 
skip=$offset count=1 2>/dev/null || \
+   [ -z "$target" ] && target=/lib/firmware/$FIRMWARE
+
+   dd if=$source of=$target iflag=skip_bytes bs=$count skip=$offset 
count=1 2>/dev/null || \
caldata_die "failed to extract calibration data from $source"
 }
 
 caldata_valid() {
local expected="$1"
+   local target=$2
+
+   [ -z "$target" ] && target=/lib/firmware/$FIRMWARE
 
-   magic=$(hexdump -v -n 2 -e '1/1 "%02x"' /lib/firmware/$FIRMWARE)
+   magic=$(hexdump -v -n 2 -e '1/1 "%02x"' $target)
[ "$magic" = "$expected" ]
return $?
 }
@@ -77,6 +83,7 @@ caldata_patch_chksum() {
local mac=$1
local mac_offset=$(($2))
local chksum_offset=$(($3))
+   local target=$4
local xor_mac
local xor_fw_mac
local xor_fw_chksum
@@ -91,38 +98,44 @@ caldata_patch_chksum() {
xor_fw_chksum=$(xor $xor_fw_chksum $xor_fw_mac $xor_mac)
 
printf "%b" "\x${xor_fw_chksum:0:2}\x${xor_fw_chksum:2:2}" | \
-   dd of=/lib/firmware/$FIRMWARE conv=notrunc bs=1 
seek=$chksum_offset count=2
+   dd of=$target conv=notrunc bs=1 seek=$chksum_offset count=2
 }
 
 caldata_patch_mac() {
local mac=$1
local mac_offset=$(($2))
local chksum_offset=$3
+   local target=$4
 
[ -z "$mac" -o -z "$mac_offset" ] && return
 
-   [ -n "$chksum_offset" ] && caldata_patch_chksum "$mac" "$mac_offset" 
"$chksum_offset"
+   [ -z "$target" ] && target=/lib/firmware/$FIRMWARE
+
+   [ -n "$chksum_offset" ] && caldata_patch_chksum "$mac" "$mac_offset" 
"$chksum_offset" "$target"
 
-   macaddr_2bin $mac | dd of=/lib/firmware/$FIRMWARE conv=notrunc 
oflag=seek_bytes bs=6 seek=$mac_offset count=1 || \
+   macaddr_2bin $mac | dd of=$target conv=notrunc oflag=seek_bytes bs=6 
seek=$mac_offset count=1 || \
caldata_die "failed to write MAC address to eeprom file"
 }
 
 ath9k_patch_mac() {
local mac=$1
+   local target=$2
 
-   caldata_patch_mac "$mac" 0x2
+   caldata_patch_mac "$mac" 0x2 "" "$target"
 }
 
 ath9k_patch_mac_crc() {
local mac=$1
local mac_offset=$2
local chksum_offset=$((mac_offset - 10))
+   local target=$4
 
-   caldata_patch_mac "$mac" "$mac_offset" "$chksum_offset"
+   caldata_patch_mac "$mac" "$mac_offset" "$chksum_offset" "$target"
 }
 
 ath10k_patch_mac() {
local mac=$1
+   local target=$2
 
-   caldata_patch_mac "$mac" 0x6 0x2
+   caldata_patch_mac "$mac" 0x6 0x2 "$target"
 }
-- 
2.11.0


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH v2 08/14] ath79/mikrotik: use standard caldata functions

2020-04-20 Thread Thibaut VARÈNE
With the implementation of a sysfs interface to access WLAN data, this
target no longer needs a special wrapper to extract caldata.

Signed-off-by: Thibaut VARÈNE 
---
 target/linux/ath79/image/common-mikrotik.mk|  2 +-
 .../etc/hotplug.d/firmware/10-ath9k-eeprom |  8 ---
 .../etc/hotplug.d/firmware/11-ath10k-caldata   |  7 +++---
 .../base-files/lib/functions/mikrotik-caldata.sh   | 26 --
 4 files changed, 10 insertions(+), 33 deletions(-)
 delete mode 100644 
target/linux/ath79/mikrotik/base-files/lib/functions/mikrotik-caldata.sh

diff --git a/target/linux/ath79/image/common-mikrotik.mk 
b/target/linux/ath79/image/common-mikrotik.mk
index 292237c76a..4cf0aa1cac 100644
--- a/target/linux/ath79/image/common-mikrotik.mk
+++ b/target/linux/ath79/image/common-mikrotik.mk
@@ -1,6 +1,6 @@
 define Device/mikrotik
DEVICE_VENDOR := MikroTik
-   DEVICE_PACKAGES := rbextract rbcfg
+   DEVICE_PACKAGES := rbcfg
LOADER_TYPE := elf
KERNEL := kernel-bin | append-dtb | lzma | loader-kernel
KERNEL_INITRAMFS := kernel-bin | append-dtb | lzma | loader-kernel
diff --git 
a/target/linux/ath79/mikrotik/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom 
b/target/linux/ath79/mikrotik/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom
index 86995de890..be2f6aec69 100644
--- 
a/target/linux/ath79/mikrotik/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom
+++ 
b/target/linux/ath79/mikrotik/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom
@@ -3,7 +3,9 @@
 [ -e /lib/firmware/$FIRMWARE ] && exit 0
 
 . /lib/functions/caldata.sh
-. /lib/functions/mikrotik-caldata.sh
+
+wlan_data="/sys/firmware/mikrotik/hard_config/wlan_data"
+mac_base="/sys/firmware/mikrotik/hard_config/mac_base"
 
 board=$(board_name)
 
@@ -11,8 +13,8 @@ case "$FIRMWARE" in
 "ath9k-eeprom-ahb-1810.wmac.bin")
case $board in
mikrotik,routerboard-wap-g-5hact2hnd)
-   mikrotik_caldata_extract "hard_config" 0x1000 0x440
-   ath9k_patch_mac $(macaddr_add $(mtd_get_mac_binary hard_config 
0x10) +2)
+   caldata_from_file $wlan_data 0x1000 0x440
+   ath9k_patch_mac $(macaddr_add $(cat $mac_base) +2)
;;
*)
caldata_die "board $board is not supported yet"
diff --git 
a/target/linux/ath79/mikrotik/base-files/etc/hotplug.d/firmware/11-ath10k-caldata
 
b/target/linux/ath79/mikrotik/base-files/etc/hotplug.d/firmware/11-ath10k-caldata
index 2521f0ad96..b486a5720d 100644
--- 
a/target/linux/ath79/mikrotik/base-files/etc/hotplug.d/firmware/11-ath10k-caldata
+++ 
b/target/linux/ath79/mikrotik/base-files/etc/hotplug.d/firmware/11-ath10k-caldata
@@ -3,7 +3,8 @@
 [ -e /lib/firmware/$FIRMWARE ] && exit 0
 
 . /lib/functions/caldata.sh
-. /lib/functions/mikrotik-caldata.sh
+
+wlan_data="/sys/firmware/mikrotik/hard_config/wlan_data"
 
 board=$(board_name)
 
@@ -11,14 +12,14 @@ case "$FIRMWARE" in
 "ath10k/cal-pci-:00:00.0.bin")
case $board in
mikrotik,routerboard-wap-g-5hact2hnd)
-   mikrotik_caldata_extract "hard_config" 0x5000 0x844
+   caldata_from_file $wlan_data 0x5000 0x844
;;
esac
;;
 "ath10k/cal-pci-:01:00.0.bin")
case $board in
mikrotik,routerboard-922uags-5hpacd)
-   mikrotik_caldata_extract "hard_config" 0x5000 0x844
+   caldata_from_file $wlan_data 0x5000 0x844
;;
esac
;;
diff --git 
a/target/linux/ath79/mikrotik/base-files/lib/functions/mikrotik-caldata.sh 
b/target/linux/ath79/mikrotik/base-files/lib/functions/mikrotik-caldata.sh
deleted file mode 100644
index 71a1bf02f3..00
--- a/target/linux/ath79/mikrotik/base-files/lib/functions/mikrotik-caldata.sh
+++ /dev/null
@@ -1,26 +0,0 @@
-# Copyright (C) 2019 Robert Marko 
-# Copyright (C) 2019 Roger Pueyo Centelles 
-#
-# Helper function to extract MAC addresses and calibration data for MikroTik
-#
-
-mikrotik_caldata_extract() {
-   local part=$1
-   local offset=$(($2))
-   local count=$(($3))
-   local mtd
-   local erdfile="/tmp/erd.bin"
-   local fwfile="/lib/firmware/${FIRMWARE}"
-
-   [ -e $fwfile ] && exit 0
-
-   mtd=$(find_mtd_chardev $part)
-   [ -n "$mtd" ] || caldata_die "no mtd device found for partition $part"
-
-   rbextract -e $mtd $erdfile
-
-   dd if=$erdfile of=$fwfile iflag=skip_bytes bs=$count skip=$offset 
count=1 2>/dev/null || \
-   caldata_die "failed to extract calibration data from $mtd"
-
-   rm -f $erdfile
-}
-- 
2.11.0


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH v2 09/14] package/utils: remove rbextract

2020-04-20 Thread Thibaut VARÈNE
Rationale:
1/ This tool is no longer necessary following the implementation of a
   sysfs driver
2/ The upstream author, Robert Marko, stated[1] that this tool had been
   taken from his tree in an unfinished state not suitable for merging

[1] https://github.com/openwrt/openwrt/pull/2850#issuecomment-610277863

Signed-off-by: Thibaut VARÈNE 
---
 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 ---
 6 files changed, 895 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

diff --git a/package/utils/rbextract/Makefile b/package/utils/rbextract/Makefile
deleted file mode 100644
index f50bbea120..00
--- a/package/utils/rbextract/Makefile
+++ /dev/null
@@ -1,38 +0,0 @@
-#
-# Copyright (C) 2010 Gabor Juhos 
-# Copyright (C) 2018 Chris Schimp 
-# Copyright (C) 2019 Robert Marko 
-# Copyright (C) 2019 Roger Pueyo Centelles 
-#
-# This is free software, licensed under the GNU General Public License v2.
-# See /LICENSE for more information.
-#
-
-include $(TOPDIR)/rules.mk
-
-PKG_NAME:=rbextract
-PKG_RELEASE:=3
-CMAKE_INSTALL:=1
-
-include $(INCLUDE_DIR)/package.mk
-include $(INCLUDE_DIR)/cmake.mk
-
-define Package/rbextract
-  SECTION:=utils
-  CATEGORY:=Utilities
-  SUBMENU:=Boot Loaders
-  TITLE:=RouterBOOT ART Extractor
-  DEPENDS:=@TARGET_ath79 +liblzo
-endef
-
-define Package/rbextract/description
- This utility is for extracting the WLAN radio calibration data from Mikrotik
- Routerboards.
-endef
-
-define Package/rbextract/install
-   $(INSTALL_DIR) $(1)/usr/sbin
-   $(INSTALL_BIN) $(PKG_BUILD_DIR)/rbextract $(1)/usr/sbin/
-endef
-
-$(eval $(call BuildPackage,rbextract))
diff --git a/package/utils/rbextract/src/CMakeLists.txt 
b/package/utils/rbextract/src/CMakeLists.txt
deleted file mode 100644
index 0ed5168fb0..00
--- a/package/utils/rbextract/src/CMakeLists.txt
+++ /dev/null
@@ -1,14 +0,0 @@
-cmake_minimum_required(VERSION 2.6)
-
-PROJECT(rbextract C)
-ADD_DEFINITIONS(-Wall --std=gnu99 -Wmissing-declarations)
-
-SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
-
-FIND_PATH(lzo_include_dir lzo/lzo1x.h)
-INCLUDE_DIRECTORIES(${lzo_include_dir})
-
-ADD_EXECUTABLE(rbextract rbextract.c rle.c)
-TARGET_LINK_LIBRARIES(rbextract lzo2)
-
-INSTALL(TARGETS rbextract RUNTIME DESTINATION sbin)
diff --git a/package/utils/rbextract/src/rbextract.c 
b/package/utils/rbextract/src/rbextract.c
deleted file mode 100644
index e75d74957a..00
--- a/package/utils/rbextract/src/rbextract.c
+++ /dev/null
@@ -1,497 +0,0 @@
-/*
- *  RouterBoot helper routines
- *
- *  Copyright (C) 2012 Gabor Juhos 
- *  Copyright (C) 2018 Chris Schimp 
- *  Copyright (C) 2019 Robert Marko 
- *  
- *  This program is free software; you can redistribute it and/or modify it
- *  under the terms of the GNU General Public License version 2 as published
- *  by the Free Software Foundation.
- */
-
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#include 
-
-#include "rle.h"
-#include "routerboot.h"
-
-inline uint32_t
-get_u32(const void *buf)
-{
-#if __BYTE_ORDER == __LITTLE_ENDIAN
-   return *(uint32_t *)buf;
-#elif __BYTE_ORDER == __BIG_ENDIAN
-   const uint8_t *p = buf;
-   return ((uint32_t) p[3] + ((uint32_t) p[2] << 8) +
-  ((uint32_t) p[1] << 16) + ((uint32_t) p[0] << 24));
-#else
-#error "Unknown byte order!"
-#endif
-}
-
-int
-routerboot_find_tag(uint8_t *buf, unsigned int buflen, uint16_t tag_id,
-   uint8_t **tag_data, uint16_t *tag_len)
-{
-   uint16_t id;
-   uint16_t len;
-   uint32_t magic;
-   bool align = false;
-   int ret;
-
-   if (buflen < 4)
-   return 1;
-
-   magic = get_u32(buf);
-
-   switch (magic) {
-   case RB_MAGIC_LZOR:
-   buf += 4;
-   buflen -= 4;
-   break;
-   case RB_MAGIC_ERD:
-   align = true;
-   /* fall trough */
-   case RB_MAGIC_HARD:
-   /* skip magic value */
-   buf += 4;
-   buflen -= 4;
-   break;
-
-   case RB_MAGIC_SOFT:
-   if (buflen < 8)
-   return 1;
-
-   /* skip magic and CRC value */
-   buf += 8;
-   buflen -= 8;
-
-   break;
-
-   default:
-   

[OpenWrt-Devel] [PATCH v2 10/14] ar71xx/mikrotik: ath10k: use new sysfs driver

2020-04-20 Thread Thibaut VARÈNE
Fetch ath10k calibration data from new mikrotik sysfs driver

Signed-off-by: Thibaut VARÈNE 
---
 .../linux/ar71xx/base-files/etc/hotplug.d/firmware/11-ath10k-caldata  | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git 
a/target/linux/ar71xx/base-files/etc/hotplug.d/firmware/11-ath10k-caldata 
b/target/linux/ar71xx/base-files/etc/hotplug.d/firmware/11-ath10k-caldata
index 03eeb2ef9c..c0e8f17d94 100644
--- a/target/linux/ar71xx/base-files/etc/hotplug.d/firmware/11-ath10k-caldata
+++ b/target/linux/ar71xx/base-files/etc/hotplug.d/firmware/11-ath10k-caldata
@@ -121,7 +121,7 @@ case "$FIRMWARE" in
;;
rb-952ui-5ac2nd|\
rb-wapg-5hact2hnd)
-   ath10kcal_from_file "/sys/firmware/routerboot/ext_wlan_data" 
0x5000 0x844
+   ath10kcal_from_file 
"/sys/firmware/mikrotik/hard_config/wlan_data" 0x5000 0x844
;;
re355|\
re450|\
@@ -158,7 +158,7 @@ case "$FIRMWARE" in
rb-921gs-5hpacd-r2|\
rb-922uags-5hpacd|\
rb-962uigs-5hact2hnt)
-   ath10kcal_from_file "/sys/firmware/routerboot/ext_wlan_data" 
0x5000 0x844
+   ath10kcal_from_file 
"/sys/firmware/mikrotik/hard_config/wlan_data" 0x5000 0x844
;;
wlr8100)
ath10kcal_extract "art" 0x5000 0x844
-- 
2.11.0


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH v2 12/14] package/base-files: add caldata_sysfsload_from_file()

2020-04-20 Thread Thibaut VARÈNE
This routine enables loading caldata binary via the kernel sysfs loader

Signed-off-by: Thibaut VARÈNE 
---
 package/base-files/Makefile   |  2 +-
 package/base-files/files/lib/functions/caldata.sh | 15 +++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/package/base-files/Makefile b/package/base-files/Makefile
index f1f0f17a60..d8e7c31878 100644
--- a/package/base-files/Makefile
+++ b/package/base-files/Makefile
@@ -12,7 +12,7 @@ include $(INCLUDE_DIR)/version.mk
 include $(INCLUDE_DIR)/feeds.mk
 
 PKG_NAME:=base-files
-PKG_RELEASE:=219
+PKG_RELEASE:=220
 PKG_FLAGS:=nonshared
 
 PKG_FILE_DEPENDS:=$(PLATFORM_DIR)/ $(GENERIC_PLATFORM_DIR)/base-files/
diff --git a/package/base-files/files/lib/functions/caldata.sh 
b/package/base-files/files/lib/functions/caldata.sh
index e9349c7eee..a64f07778d 100644
--- a/package/base-files/files/lib/functions/caldata.sh
+++ b/package/base-files/files/lib/functions/caldata.sh
@@ -68,6 +68,21 @@ caldata_from_file() {
caldata_die "failed to extract calibration data from $source"
 }
 
+caldata_sysfsload_from_file() {
+   local source=$1
+   local offset=$(($2))
+   local count=$(($3))
+
+   # test extract to /dev/null first
+   dd if=$source of=/dev/null iflag=skip_bytes bs=$count skip=$offset 
count=1 2>/dev/null || \
+   caldata_die "failed to extract calibration data from $source"
+
+   # can't fail now
+   echo 1 > /sys/$DEVPATH/loading
+   dd if=$source of=/sys/$DEVPATH/data iflag=skip_bytes bs=$count 
skip=$offset count=1 2>/dev/null
+   echo 0 > /sys/$DEVPATH/loading
+}
+
 caldata_valid() {
local expected="$1"
local target=$2
-- 
2.11.0


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH v2 14/14] ramips/mt7621: mikrotik: don't use mtd-mac-address in DTS

2020-04-20 Thread Thibaut VARÈNE
As evidenced here[1] the device MAC address can be stored at a random
offset in the hard_config partition. Rely on sysfs to update the MAC
address correctly.

[1] https://github.com/openwrt/openwrt/pull/2850#issuecomment-610809021

Signed-off-by: Thibaut VARÈNE 
---
 target/linux/ramips/dts/mt7621_mikrotik_routerboard-750gr3.dts | 7 ---
 target/linux/ramips/dts/mt7621_mikrotik_routerboard-m11g.dts   | 5 -
 target/linux/ramips/dts/mt7621_mikrotik_routerboard-m33g.dts   | 7 ---
 target/linux/ramips/mt7621/base-files/etc/board.d/02_network   | 4 +++-
 4 files changed, 3 insertions(+), 20 deletions(-)

diff --git a/target/linux/ramips/dts/mt7621_mikrotik_routerboard-750gr3.dts 
b/target/linux/ramips/dts/mt7621_mikrotik_routerboard-750gr3.dts
index 3f37155f24..755c5ec932 100644
--- a/target/linux/ramips/dts/mt7621_mikrotik_routerboard-750gr3.dts
+++ b/target/linux/ramips/dts/mt7621_mikrotik_routerboard-750gr3.dts
@@ -129,18 +129,11 @@
};
 };
 
-&gmac0 {
-   mtd-mac-address = <&hard_config 0x0010>;
-   mtd-mac-address-increment = <1>;
-};
-
 &switch0 {
ports {
port@0 {
status = "okay";
label = "wan";
-   mtd-mac-address = <&hard_config 0x0010>;
-   mtd-mac-address-increment = <2>;
};
 
port@1 {
diff --git a/target/linux/ramips/dts/mt7621_mikrotik_routerboard-m11g.dts 
b/target/linux/ramips/dts/mt7621_mikrotik_routerboard-m11g.dts
index bd58aea951..37a1312f52 100644
--- a/target/linux/ramips/dts/mt7621_mikrotik_routerboard-m11g.dts
+++ b/target/linux/ramips/dts/mt7621_mikrotik_routerboard-m11g.dts
@@ -138,11 +138,6 @@
};
 };
 
-&gmac0 {
-   mtd-mac-address = <&hard_config 0x0010>;
-   mtd-mac-address-increment = <1>;
-};
-
 &switch0 {
ports {
port@0 {
diff --git a/target/linux/ramips/dts/mt7621_mikrotik_routerboard-m33g.dts 
b/target/linux/ramips/dts/mt7621_mikrotik_routerboard-m33g.dts
index 19e1a71e99..03bc489380 100644
--- a/target/linux/ramips/dts/mt7621_mikrotik_routerboard-m33g.dts
+++ b/target/linux/ramips/dts/mt7621_mikrotik_routerboard-m33g.dts
@@ -162,18 +162,11 @@
};
 };
 
-&gmac0 {
-   mtd-mac-address = <&hard_config 0x0010>;
-   mtd-mac-address-increment = <1>;
-};
-
 &switch0 {
ports {
port@0 {
status = "okay";
label = "wan";
-   mtd-mac-address = <&hard_config 0x0010>;
-   mtd-mac-address-increment = <2>;
};
 
port@1 {
diff --git a/target/linux/ramips/mt7621/base-files/etc/board.d/02_network 
b/target/linux/ramips/mt7621/base-files/etc/board.d/02_network
index 252f9f1dda..91ced8ede7 100755
--- a/target/linux/ramips/mt7621/base-files/etc/board.d/02_network
+++ b/target/linux/ramips/mt7621/base-files/etc/board.d/02_network
@@ -92,7 +92,9 @@ ramips_setup_macs()
mikrotik,routerboard-750gr3|\
mikrotik,routerboard-m11g|\
mikrotik,routerboard-m33g)
-   label_mac=$(mtd_get_mac_binary hard_config 0x10)
+   label_mac=$(cat "/sys/firmware/mikrotik/hard_config/mac_base")
+   lan_mac=$(macaddr_add $label_mac 1)
+   wan_mac=$(macaddr_add $label_mac 2)
;;
zbtlink,zbt-we1326|\
zbtlink,zbt-wg3526-16m|\
-- 
2.11.0


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH v2 13/14] ath79/mikrotik: load caldata via sysfs loader

2020-04-20 Thread Thibaut VARÈNE
This commit takes advantages of base-files 220 which introduces routines
to perform caldata loading directly via the kernel sysfs loader helper.
This has the benefits of not wasting flash space to store caldata.

Memory footprint is reduced to the bare minimum: for devices that don't
need MAC patching, the caldata is loaded directly, for devices that do
need MAC patching, the caldata is extracted to /tmp, patched and then
loaded.

Signed-off-by: Thibaut VARÈNE 
---
 .../mikrotik/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom  | 6 --
 .../mikrotik/base-files/etc/hotplug.d/firmware/11-ath10k-caldata| 4 ++--
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git 
a/target/linux/ath79/mikrotik/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom 
b/target/linux/ath79/mikrotik/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom
index be2f6aec69..c63856327c 100644
--- 
a/target/linux/ath79/mikrotik/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom
+++ 
b/target/linux/ath79/mikrotik/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom
@@ -13,8 +13,10 @@ case "$FIRMWARE" in
 "ath9k-eeprom-ahb-1810.wmac.bin")
case $board in
mikrotik,routerboard-wap-g-5hact2hnd)
-   caldata_from_file $wlan_data 0x1000 0x440
-   ath9k_patch_mac $(macaddr_add $(cat $mac_base) +2)
+   caldata_from_file $wlan_data 0x1000 0x440 /tmp/$FIRMWARE
+   ath9k_patch_mac $(macaddr_add $(cat $mac_base) +2) 
/tmp/$FIRMWARE
+   caldata_sysfsload_from_file /tmp/$FIRMWARE 0x0 0x440
+   rm -f /tmp/$FIRMWARE
;;
*)
caldata_die "board $board is not supported yet"
diff --git 
a/target/linux/ath79/mikrotik/base-files/etc/hotplug.d/firmware/11-ath10k-caldata
 
b/target/linux/ath79/mikrotik/base-files/etc/hotplug.d/firmware/11-ath10k-caldata
index b486a5720d..531c21678f 100644
--- 
a/target/linux/ath79/mikrotik/base-files/etc/hotplug.d/firmware/11-ath10k-caldata
+++ 
b/target/linux/ath79/mikrotik/base-files/etc/hotplug.d/firmware/11-ath10k-caldata
@@ -12,14 +12,14 @@ case "$FIRMWARE" in
 "ath10k/cal-pci-:00:00.0.bin")
case $board in
mikrotik,routerboard-wap-g-5hact2hnd)
-   caldata_from_file $wlan_data 0x5000 0x844
+   caldata_sysfsload_from_file $wlan_data 0x5000 0x844
;;
esac
;;
 "ath10k/cal-pci-:01:00.0.bin")
case $board in
mikrotik,routerboard-922uags-5hpacd)
-   caldata_from_file $wlan_data 0x5000 0x844
+   caldata_sysfsload_from_file $wlan_data 0x5000 0x844
;;
esac
;;
-- 
2.11.0


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH] generic: platform/mikrotik: fix LZOR support

2020-05-16 Thread Thibaut VARÈNE
31e99fe3da which introduced this code was unfortunately untested.
This commit fixes a number of issues and works around the fact that in
this particular scheme, the LZO payload may be padded at the end which
will trigger a harmless lzo decompression error.
This commit also disambiguates the debug printks.

Tested-by: Robert Marko 
Signed-off-by: Thibaut VARÈNE 
---
 .../drivers/platform/mikrotik/rb_hardconfig.c  | 59 ++
 1 file changed, 37 insertions(+), 22 deletions(-)

diff --git 
a/target/linux/generic/files/drivers/platform/mikrotik/rb_hardconfig.c 
b/target/linux/generic/files/drivers/platform/mikrotik/rb_hardconfig.c
index 26218d6a7d..7402320428 100644
--- a/target/linux/generic/files/drivers/platform/mikrotik/rb_hardconfig.c
+++ b/target/linux/generic/files/drivers/platform/mikrotik/rb_hardconfig.c
@@ -36,7 +36,7 @@
 
 #include "routerboot.h"
 
-#define RB_HARDCONFIG_VER  "0.02"
+#define RB_HARDCONFIG_VER  "0.03"
 #define RB_HC_PR_PFX   "[rb_hardconfig] "
 
 /* ID values for hardware settings */
@@ -484,16 +484,18 @@ static int hc_wlan_data_unpack_lzor(const u8 *inbuf, 
size_t inlen,
void *outbuf, size_t *outlen)
 {
u16 rle_ofs, rle_len;
-   size_t templen;
-   u8 *tempbuf;
+   const u32 *needle;
+   u8 *tempbuf, *ptr;
+   size_t templen, lzo_len;
int ret;
 
-   templen = inlen + sizeof(hc_lzor_prefix);
-   if (templen > *outlen)
+   lzo_len = inlen + sizeof(hc_lzor_prefix);
+   if (lzo_len > *outlen)
return -EFBIG;
 
/* Temporary buffer same size as the outbuf */
-   tempbuf = kmalloc(*outlen, GFP_KERNEL);
+   templen = *outlen;
+   tempbuf = kmalloc(templen, GFP_KERNEL);
if (!outbuf)
return -ENOMEM;
 
@@ -501,41 +503,54 @@ static int hc_wlan_data_unpack_lzor(const u8 *inbuf, 
size_t inlen,
memcpy(outbuf, hc_lzor_prefix, sizeof(hc_lzor_prefix));
memcpy(outbuf + sizeof(hc_lzor_prefix), inbuf, inlen);
 
-   /* LZO-decompress templen bytes of outbuf into the tempbuf */
-   ret = lzo1x_decompress_safe(outbuf, templen, tempbuf, outlen);
+   /* LZO-decompress lzo_len bytes of outbuf into the tempbuf */
+   ret = lzo1x_decompress_safe(outbuf, lzo_len, tempbuf, &templen);
if (ret) {
-   pr_debug(RB_HC_PR_PFX "LZO decompression error (%d)\n", ret);
-   goto fail;
+   if (LZO_E_INPUT_NOT_CONSUMED == ret) {
+   /*
+* It is assumed that because the LZO payload is 
embedded
+* in a "root" RB_ID_WLAN_DATA tag, the tag length is 
aligned
+* and the payload is padded at the end, which triggers 
a
+* spurious error which we ignore here.
+*/
+   pr_debug(RB_HC_PR_PFX "LZOR: LZO EOF before buffer end 
- this may be harmless\n");
+   } else {
+   pr_debug(RB_HC_PR_PFX "LZOR: LZO decompression error 
(%d)\n", ret);
+   goto fail;
+   }
}
-   templen = *outlen;
 
/*
 * Post decompression we have a blob (possibly byproduct of the lzo
 * dictionary). We need to find RB_MAGIC_ERD. The magic number seems to
 * be 32bit-aligned in the decompression output.
 */
-
-   while (RB_MAGIC_ERD != *(u32 *)tempbuf) {
-   tempbuf += 4;
-   templen -= 4;
-   }
+   needle = (const u32 *)tempbuf;
+   while (RB_MAGIC_ERD != *needle++) {
+   if ((u8 *)needle >= tempbuf+templen) {
+   pr_debug(RB_HC_PR_PFX "LZOR: ERD magic not found\n");
+   goto fail;
+   }
+   };
+   templen -= (u8 *)needle - tempbuf;
 
/* Past magic. Look for tag node */
-   ret = routerboot_tag_find(tempbuf, templen, 0x1, &rle_ofs, &rle_len);
+   ret = routerboot_tag_find((u8 *)needle, templen, 0x1, &rle_ofs, 
&rle_len);
if (ret) {
-   pr_debug(RB_HC_PR_PFX "RLE data not found\n");
+   pr_debug(RB_HC_PR_PFX "LZOR: RLE data not found\n");
goto fail;
}
 
if (rle_len > templen) {
-   pr_debug(RB_HC_PR_PFX "Invalid RLE data length\n");
+   pr_debug(RB_HC_PR_PFX "LZOR: Invalid RLE data length\n");
+   ret = -EINVAL;
goto fail;
}
 
-   /* RLE-decode tempbuf back into the outbuf */
-   ret = routerboot_rle_decode(tempbuf+rle_ofs, rle_len, outbuf, outlen);
+   /* RLE-decode tempbuf from needle back into the outbuf */
+   ret = routerboot_rle_decode((u8 *)needle+rle_ofs, rle_len, outbuf, 
outlen);

[OpenWrt-Devel] [PATCH v2] generic: platform/mikrotik: fix LZOR support

2020-05-16 Thread Thibaut VARÈNE
31e99fe3da which introduced this code was unfortunately untested.
This commit fixes a number of issues and works around the fact that in
this particular scheme, the LZO payload may be padded at the end which
will trigger a harmless lzo decompression error.
This commit also disambiguates the debug printks.

Tested-by: Robert Marko 
Signed-off-by: Thibaut VARÈNE 

Fixes: 31e99fe3da ("generic: platform/mikrotik: support LZOR encoding")
---
 .../drivers/platform/mikrotik/rb_hardconfig.c  | 57 ++
 1 file changed, 36 insertions(+), 21 deletions(-)

diff --git 
a/target/linux/generic/files/drivers/platform/mikrotik/rb_hardconfig.c 
b/target/linux/generic/files/drivers/platform/mikrotik/rb_hardconfig.c
index 26218d6a7d..93c731a5f0 100644
--- a/target/linux/generic/files/drivers/platform/mikrotik/rb_hardconfig.c
+++ b/target/linux/generic/files/drivers/platform/mikrotik/rb_hardconfig.c
@@ -36,7 +36,7 @@
 
 #include "routerboot.h"
 
-#define RB_HARDCONFIG_VER  "0.02"
+#define RB_HARDCONFIG_VER  "0.03"
 #define RB_HC_PR_PFX   "[rb_hardconfig] "
 
 /* ID values for hardware settings */
@@ -484,16 +484,18 @@ static int hc_wlan_data_unpack_lzor(const u8 *inbuf, 
size_t inlen,
void *outbuf, size_t *outlen)
 {
u16 rle_ofs, rle_len;
-   size_t templen;
+   const u32 *needle;
u8 *tempbuf;
+   size_t templen, lzo_len;
int ret;
 
-   templen = inlen + sizeof(hc_lzor_prefix);
-   if (templen > *outlen)
+   lzo_len = inlen + sizeof(hc_lzor_prefix);
+   if (lzo_len > *outlen)
return -EFBIG;
 
/* Temporary buffer same size as the outbuf */
-   tempbuf = kmalloc(*outlen, GFP_KERNEL);
+   templen = *outlen;
+   tempbuf = kmalloc(templen, GFP_KERNEL);
if (!outbuf)
return -ENOMEM;
 
@@ -501,41 +503,54 @@ static int hc_wlan_data_unpack_lzor(const u8 *inbuf, 
size_t inlen,
memcpy(outbuf, hc_lzor_prefix, sizeof(hc_lzor_prefix));
memcpy(outbuf + sizeof(hc_lzor_prefix), inbuf, inlen);
 
-   /* LZO-decompress templen bytes of outbuf into the tempbuf */
-   ret = lzo1x_decompress_safe(outbuf, templen, tempbuf, outlen);
+   /* LZO-decompress lzo_len bytes of outbuf into the tempbuf */
+   ret = lzo1x_decompress_safe(outbuf, lzo_len, tempbuf, &templen);
if (ret) {
-   pr_debug(RB_HC_PR_PFX "LZO decompression error (%d)\n", ret);
-   goto fail;
+   if (LZO_E_INPUT_NOT_CONSUMED == ret) {
+   /*
+* It is assumed that because the LZO payload is 
embedded
+* in a "root" RB_ID_WLAN_DATA tag, the tag length is 
aligned
+* and the payload is padded at the end, which triggers 
a
+* spurious error which we ignore here.
+*/
+   pr_debug(RB_HC_PR_PFX "LZOR: LZO EOF before buffer end 
- this may be harmless\n");
+   } else {
+   pr_debug(RB_HC_PR_PFX "LZOR: LZO decompression error 
(%d)\n", ret);
+   goto fail;
+   }
}
-   templen = *outlen;
 
/*
 * Post decompression we have a blob (possibly byproduct of the lzo
 * dictionary). We need to find RB_MAGIC_ERD. The magic number seems to
 * be 32bit-aligned in the decompression output.
 */
-
-   while (RB_MAGIC_ERD != *(u32 *)tempbuf) {
-   tempbuf += 4;
-   templen -= 4;
-   }
+   needle = (const u32 *)tempbuf;
+   while (RB_MAGIC_ERD != *needle++) {
+   if ((u8 *)needle >= tempbuf+templen) {
+   pr_debug(RB_HC_PR_PFX "LZOR: ERD magic not found\n");
+   goto fail;
+   }
+   };
+   templen -= (u8 *)needle - tempbuf;
 
/* Past magic. Look for tag node */
-   ret = routerboot_tag_find(tempbuf, templen, 0x1, &rle_ofs, &rle_len);
+   ret = routerboot_tag_find((u8 *)needle, templen, 0x1, &rle_ofs, 
&rle_len);
if (ret) {
-   pr_debug(RB_HC_PR_PFX "RLE data not found\n");
+   pr_debug(RB_HC_PR_PFX "LZOR: RLE data not found\n");
goto fail;
}
 
if (rle_len > templen) {
-   pr_debug(RB_HC_PR_PFX "Invalid RLE data length\n");
+   pr_debug(RB_HC_PR_PFX "LZOR: Invalid RLE data length\n");
+   ret = -EINVAL;
goto fail;
}
 
-   /* RLE-decode tempbuf back into the outbuf */
-   ret = routerboot_rle_decode(tempbuf+rle_ofs, rle_len, outbuf, outlen);
+   /* RLE-decode tempbuf from needle back into the outbuf */
+   ret = routerboot_rl

[OpenWrt-Devel] [PATCH] package/base-files: caldata: work around dd's limitation

2020-05-17 Thread Thibaut VARÈNE
tl;dr: dd will silently truncate the output if reading from special
files (e.g. sysfs attributes) with a too large bs parameter.

This problem was exposed on some RouterBOARD ipq40xx devices which use a
caldata payload which is larger than PAGE_SIZE, contrary to all other
currently supported RouterBOARD devices: the caldata would fail to
properly load with the current scripts.

Background: dd doesn't seem to correctly handle read() results that
return less than requested data. sysfs attributes have a kernel exchange
buffer which is at most PAGE_SIZE big, so only 1 page can be read() at a
time. In this case, if bs is larger than PAGE_SIZE, dd will silently
truncate blocks to PAGE_SIZE. With the current scripts using bs=
count=1, the data is truncated to PAGE_SIZE as soon as the requested
 exceeds this value.

This commit works around this problem by using `cat` in the caldata
routines that can read from a file (routines that read from mtd devices
are untouched). cat correctly handles partial read requests. The output
is then piped to dd with the same parameters as before, to ensure that
the resulting file remains exactly the same.

This is a simple workaround, the downside is that it uses a pipe and one
more executable, and therefore has a larger memory footprint and is
slower. This is deemed acceptable considering these routines are only
used at boot time.

Tested-by: Robert Marko 
Signed-off-by: Thibaut VARÈNE 
---
 package/base-files/Makefile   | 2 +-
 package/base-files/files/lib/functions/caldata.sh | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/package/base-files/Makefile b/package/base-files/Makefile
index d8e7c31878..5fb275533d 100644
--- a/package/base-files/Makefile
+++ b/package/base-files/Makefile
@@ -12,7 +12,7 @@ include $(INCLUDE_DIR)/version.mk
 include $(INCLUDE_DIR)/feeds.mk
 
 PKG_NAME:=base-files
-PKG_RELEASE:=220
+PKG_RELEASE:=221
 PKG_FLAGS:=nonshared
 
 PKG_FILE_DEPENDS:=$(PLATFORM_DIR)/ $(GENERIC_PLATFORM_DIR)/base-files/
diff --git a/package/base-files/files/lib/functions/caldata.sh 
b/package/base-files/files/lib/functions/caldata.sh
index 6862da7164..8b031e29cd 100644
--- a/package/base-files/files/lib/functions/caldata.sh
+++ b/package/base-files/files/lib/functions/caldata.sh
@@ -64,7 +64,7 @@ caldata_from_file() {
 
[ -n "$target" ] || target=/lib/firmware/$FIRMWARE
 
-   dd if=$source of=$target iflag=skip_bytes bs=$count skip=$offset 
count=1 2>/dev/null || \
+   cat $source | dd of=$target iflag=skip_bytes bs=$count skip=$offset 
count=1 2>/dev/null || \
caldata_die "failed to extract calibration data from $source"
 }
 
@@ -74,12 +74,12 @@ caldata_sysfsload_from_file() {
local count=$(($3))
 
# test extract to /dev/null first
-   dd if=$source of=/dev/null iflag=skip_bytes bs=$count skip=$offset 
count=1 2>/dev/null || \
+   cat $source | dd of=/dev/null iflag=skip_bytes bs=$count skip=$offset 
count=1 2>/dev/null || \
caldata_die "failed to extract calibration data from $source"
 
# can't fail now
echo 1 > /sys/$DEVPATH/loading
-   dd if=$source of=/sys/$DEVPATH/data iflag=skip_bytes bs=$count 
skip=$offset count=1 2>/dev/null
+   cat $source | dd of=/sys/$DEVPATH/data iflag=skip_bytes bs=$count 
skip=$offset count=1 2>/dev/null
echo 0 > /sys/$DEVPATH/loading
 }
 
-- 
2.11.0


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH v2] package/base-files: caldata: work around dd's limitation

2020-05-17 Thread Thibaut VARÈNE
tl;dr: dd will silently truncate the output if reading from special
files (e.g. sysfs attributes) with a too large bs parameter.

This problem was exposed on some RouterBOARD ipq40xx devices which use a
caldata payload which is larger than PAGE_SIZE, contrary to all other
currently supported RouterBOARD devices: the caldata would fail to
properly load with the current scripts.

Background: dd doesn't seem to correctly handle read() results that
return less than requested data. sysfs attributes have a kernel exchange
buffer which is at most PAGE_SIZE big, so only 1 page can be read() at a
time. In this case, if bs is larger than PAGE_SIZE, dd will silently
truncate blocks to PAGE_SIZE. With the current scripts using bs=
count=1, the data is truncated to PAGE_SIZE as soon as the requested
 exceeds this value.

This commit works around this problem by using `cat` in the caldata
routines that can read from a file (routines that read from mtd devices
are untouched). cat correctly handles partial read requests. The output
is then piped to dd with the same parameters as before, to ensure that
the resulting file remains exactly the same.

This is a simple workaround, the downside is that it uses a pipe and one
more executable, and therefore has a larger memory footprint and is
slower. This is deemed acceptable considering these routines are only
used at boot time.

Tested-by: Robert Marko 
Signed-off-by: Thibaut VARÈNE 
---
v2: leave a comment in scripts
---
 package/base-files/Makefile   | 2 +-
 package/base-files/files/lib/functions/caldata.sh | 8 +---
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/package/base-files/Makefile b/package/base-files/Makefile
index d8e7c31878..5fb275533d 100644
--- a/package/base-files/Makefile
+++ b/package/base-files/Makefile
@@ -12,7 +12,7 @@ include $(INCLUDE_DIR)/version.mk
 include $(INCLUDE_DIR)/feeds.mk
 
 PKG_NAME:=base-files
-PKG_RELEASE:=220
+PKG_RELEASE:=221
 PKG_FLAGS:=nonshared
 
 PKG_FILE_DEPENDS:=$(PLATFORM_DIR)/ $(GENERIC_PLATFORM_DIR)/base-files/
diff --git a/package/base-files/files/lib/functions/caldata.sh 
b/package/base-files/files/lib/functions/caldata.sh
index 6862da7164..e22c7d27e6 100644
--- a/package/base-files/files/lib/functions/caldata.sh
+++ b/package/base-files/files/lib/functions/caldata.sh
@@ -64,7 +64,8 @@ caldata_from_file() {
 
[ -n "$target" ] || target=/lib/firmware/$FIRMWARE
 
-   dd if=$source of=$target iflag=skip_bytes bs=$count skip=$offset 
count=1 2>/dev/null || \
+   # dd doesn't handle partial reads from special files: use cat
+   cat $source | dd of=$target iflag=skip_bytes bs=$count skip=$offset 
count=1 2>/dev/null || \
caldata_die "failed to extract calibration data from $source"
 }
 
@@ -73,13 +74,14 @@ caldata_sysfsload_from_file() {
local offset=$(($2))
local count=$(($3))
 
+   # dd doesn't handle partial reads from special files: use cat
# test extract to /dev/null first
-   dd if=$source of=/dev/null iflag=skip_bytes bs=$count skip=$offset 
count=1 2>/dev/null || \
+   cat $source | dd of=/dev/null iflag=skip_bytes bs=$count skip=$offset 
count=1 2>/dev/null || \
caldata_die "failed to extract calibration data from $source"
 
# can't fail now
echo 1 > /sys/$DEVPATH/loading
-   dd if=$source of=/sys/$DEVPATH/data iflag=skip_bytes bs=$count 
skip=$offset count=1 2>/dev/null
+   cat $source | dd of=/sys/$DEVPATH/data iflag=skip_bytes bs=$count 
skip=$offset count=1 2>/dev/null
echo 0 > /sys/$DEVPATH/loading
 }
 
-- 
2.11.0


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH 2/2] generic: platform/mikrotik: disambiguate SPDX-License-Identifier

2020-05-18 Thread Thibaut VARÈNE
I meant it to be GPL-2.0-only, as evidenced by the boilerplate.

Signed-off-by: Thibaut VARÈNE 
---
 target/linux/generic/files/drivers/platform/mikrotik/rb_hardconfig.c | 2 +-
 target/linux/generic/files/drivers/platform/mikrotik/routerboot.c| 2 +-
 target/linux/generic/files/drivers/platform/mikrotik/routerboot.h| 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git 
a/target/linux/generic/files/drivers/platform/mikrotik/rb_hardconfig.c 
b/target/linux/generic/files/drivers/platform/mikrotik/rb_hardconfig.c
index 93c731a5f0..2a059a4d25 100644
--- a/target/linux/generic/files/drivers/platform/mikrotik/rb_hardconfig.c
+++ b/target/linux/generic/files/drivers/platform/mikrotik/rb_hardconfig.c
@@ -1,4 +1,4 @@
-// SPDX-License-Identifier: GPL-2.0
+// SPDX-License-Identifier: GPL-2.0-only
 /*
  * Driver for MikroTik RouterBoot hard config.
  *
diff --git a/target/linux/generic/files/drivers/platform/mikrotik/routerboot.c 
b/target/linux/generic/files/drivers/platform/mikrotik/routerboot.c
index 172db02533..36ca90c1ad 100644
--- a/target/linux/generic/files/drivers/platform/mikrotik/routerboot.c
+++ b/target/linux/generic/files/drivers/platform/mikrotik/routerboot.c
@@ -1,4 +1,4 @@
-// SPDX-License-Identifier: GPL-2.0
+// SPDX-License-Identifier: GPL-2.0-only
 /*
  * Driver for MikroTik RouterBoot flash data. Common routines.
  *
diff --git a/target/linux/generic/files/drivers/platform/mikrotik/routerboot.h 
b/target/linux/generic/files/drivers/platform/mikrotik/routerboot.h
index d2ca41fb1b..c75f61ebbf 100644
--- a/target/linux/generic/files/drivers/platform/mikrotik/routerboot.h
+++ b/target/linux/generic/files/drivers/platform/mikrotik/routerboot.h
@@ -1,4 +1,4 @@
-// SPDX-License-Identifier: GPL-2.0
+// SPDX-License-Identifier: GPL-2.0-only
 /*
  * Common definitions for MikroTik RouterBoot data.
  *
-- 
2.11.0


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH 1/2] generic: routerbootpart.c: disambiguate SPDX-License-Identifier

2020-05-18 Thread Thibaut VARÈNE
I meant it to be GPL-2.0-only, as evidenced by the boilerplate.

Signed-off-by: Thibaut VARÈNE 
---
 target/linux/generic/files/drivers/mtd/parsers/routerbootpart.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/target/linux/generic/files/drivers/mtd/parsers/routerbootpart.c 
b/target/linux/generic/files/drivers/mtd/parsers/routerbootpart.c
index e019094058..f9bba0f3ba 100644
--- a/target/linux/generic/files/drivers/mtd/parsers/routerbootpart.c
+++ b/target/linux/generic/files/drivers/mtd/parsers/routerbootpart.c
@@ -1,4 +1,4 @@
-// SPDX-License-Identifier: GPL-2.0
+// SPDX-License-Identifier: GPL-2.0-only
 /*
  * Parser for MikroTik RouterBoot partitions.
  *
-- 
2.11.0


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH] packages/utils: fbtest fix Makefile

2020-05-21 Thread Thibaut VARÈNE
The clean target tries to remove what looks like a bogus 'rbcfg',
probably carried over copy-pasta. Remove the name of the generated
executable ('fbtest') instead.

Signed-off-by: Thibaut VARÈNE 
---
 package/utils/fbtest/src/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/package/utils/fbtest/src/Makefile 
b/package/utils/fbtest/src/Makefile
index 075bc0ecbf..f7c9f86a87 100644
--- a/package/utils/fbtest/src/Makefile
+++ b/package/utils/fbtest/src/Makefile
@@ -11,4 +11,4 @@ fbtest: $(OBJS)
$(CC) -o $@ $(OBJS)
 
 clean:
-   rm -f rbcfg *.o
+   rm -f fbtest *.o
-- 
2.11.0


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH v2] packages/utils: fbtest fix Makefile

2020-05-21 Thread Thibaut VARÈNE
The clean target tries to remove what looks like a bogus 'rbcfg',
probably carried over copy-pasta. Remove the name of the generated
executable ('fbtest') instead.

Signed-off-by: Thibaut VARÈNE 
Fixes: 8099f4e0d3af ("fbtest utility ")
---
 package/utils/fbtest/src/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/package/utils/fbtest/src/Makefile 
b/package/utils/fbtest/src/Makefile
index 075bc0ecbf..f7c9f86a87 100644
--- a/package/utils/fbtest/src/Makefile
+++ b/package/utils/fbtest/src/Makefile
@@ -11,4 +11,4 @@ fbtest: $(OBJS)
$(CC) -o $@ $(OBJS)
 
 clean:
-   rm -f rbcfg *.o
+   rm -f fbtest *.o
-- 
2.11.0


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[PATCH] kernel: backport mt7530 dsa bridge-vlan fixes

2022-08-09 Thread Thibaut VARÈNE
Backport patches:
0b69c54c74bc ("net: dsa: mt7530: enable assisted learning on CPU port")
6087175b7991 ("net: dsa: mt7530: use independent VLAN learning on VLAN-unaware 
bridges)

These patches fix outstanding issues with bridge-vlan setups. In
particular, prior to this change setups involving a bridge-vlan with
untagged ethernet ports would see wireless clients roaming to the AP
experience connection drops lasting 2-5mn as the stale FDB entries
persist.

See the discussion here:
http://lists.openwrt.org/pipermail/openwrt-devel/2022-August/039175.html

Signed-off-by: Thibaut VARÈNE 
---
CCing DENG Qingfang  as the upstream author: I had to
massage the patch a little bit to apply to older 5.10 code base.

Note: this cherry-picks with no conflict into openwrt-22.03, and I have
also successfully tested this backport there: I would thus recommend this
be cherry-picked into 22.03.
---
 ...enable-assisted-learning-on-CPU-port.patch |  83 ++
 ...LAN-learning-on-VLAN-unaware-bridges.patch | 272 ++
 2 files changed, 355 insertions(+)
 create mode 100644 
target/linux/generic/backport-5.10/797-v5.15-0001-net-dsa-mt7530-enable-assisted-learning-on-CPU-port.patch
 create mode 100644 
target/linux/generic/backport-5.10/797-v5.15-0002-net-dsa-mt7530-use-independent-VLAN-learning-on-VLAN-unaware-bridges.patch

diff --git 
a/target/linux/generic/backport-5.10/797-v5.15-0001-net-dsa-mt7530-enable-assisted-learning-on-CPU-port.patch
 
b/target/linux/generic/backport-5.10/797-v5.15-0001-net-dsa-mt7530-enable-assisted-learning-on-CPU-port.patch
new file mode 100644
index 00..a474527ca9
--- /dev/null
+++ 
b/target/linux/generic/backport-5.10/797-v5.15-0001-net-dsa-mt7530-enable-assisted-learning-on-CPU-port.patch
@@ -0,0 +1,83 @@
+From 0b69c54c74bcb60e834013ccaf596caf05156a8e Mon Sep 17 00:00:00 2001
+From: DENG Qingfang 
+Date: Wed, 4 Aug 2021 00:04:01 +0800
+Subject: [PATCH] net: dsa: mt7530: enable assisted learning on CPU port
+
+Consider the following bridge configuration, where bond0 is not
+offloaded:
+
+ +-- br0 --+
+/ /   | \
+   / /|  \
+  /  || bond0
+ /   || /   \
+   swp0 swp1 swp2 swp3 swp4
+ ..   .
+ ..   .
+ AB   C
+
+Address learning is enabled on offloaded ports (swp0~2) and the CPU
+port, so when client A sends a packet to C, the following will happen:
+
+1. The switch learns that client A can be reached at swp0.
+2. The switch probably already knows that client C can be reached at the
+   CPU port, so it forwards the packet to the CPU.
+3. The bridge core knows client C can be reached at bond0, so it
+   forwards the packet back to the switch.
+4. The switch learns that client A can be reached at the CPU port.
+5. The switch forwards the packet to either swp3 or swp4, according to
+   the packet's tag.
+
+That makes client A's MAC address flap between swp0 and the CPU port. If
+client B sends a packet to A, it is possible that the packet is
+forwarded to the CPU. With offload_fwd_mark = 1, the bridge core won't
+forward it back to the switch, resulting in packet loss.
+
+As we have the assisted_learning_on_cpu_port in DSA core now, enable
+that and disable hardware learning on the CPU port.
+
+Signed-off-by: DENG Qingfang 
+Reviewed-by: Vladimir Oltean 
+Signed-off-by: David S. Miller 
+---
+ drivers/net/dsa/mt7530.c | 14 --
+ 1 file changed, 8 insertions(+), 6 deletions(-)
+
+--- a/drivers/net/dsa/mt7530.c
 b/drivers/net/dsa/mt7530.c
+@@ -2026,6 +2026,7 @@ mt7530_setup(struct dsa_switch *ds)
+*/
+   dn = dsa_to_port(ds, MT7530_CPU_PORT)->master->dev.of_node->parent;
+   ds->configure_vlan_while_not_filtering = true;
++  ds->assisted_learning_on_cpu_port = true;
+   ds->mtu_enforcement_ingress = true;
+ 
+   if (priv->id == ID_MT7530) {
+@@ -2096,6 +2097,9 @@ mt7530_setup(struct dsa_switch *ds)
+   mt7530_rmw(priv, MT7530_PCR_P(i), PCR_MATRIX_MASK,
+  PCR_MATRIX_CLR);
+ 
++  /* Disable learning by default on all ports */
++  mt7530_set(priv, MT7530_PSC_P(i), SA_DIS);
++
+   if (dsa_is_cpu_port(ds, i)) {
+   ret = mt753x_cpu_port_enable(ds, i);
+   if (ret)
+@@ -2257,6 +2261,9 @@ mt7531_setup(struct dsa_switch *ds)
+   mt7530_rmw(priv, MT7530_PCR_P(i), PCR_MATRIX_MASK,
+  PCR_MATRIX_CLR);
+ 
++  /* Disable learning by default on all ports */
++  mt7530_set(priv, MT7530_PSC_P(i), SA_DIS);
++
+   mt7530_set(priv, MT7531_DBG_CNT(i), MT7531_DIS_CLR);
+ 
+   if (dsa_is_cpu_port(ds, i)) {
+@@ -2272,6 +2279,7 @@ mt7531_setup(struct dsa_switch *ds)
+   }
+ 
+   ds->configure_vlan_while_not_filtering = true;
++  ds->assisted_learning_on_cpu_port = true;
+   ds->mtu_enforceme

[PATCH 21.02] ath79: add support for MikroTik RouterBOARD wAP-2nD (wAP)

2022-10-22 Thread Thibaut VARÈNE
From: David Musil <0x4...@protonmail.com>

The MikroTik RouterBOARD wAP-2nd (sold as wAP) is a small
2.4 GHz 802.11b/g/n PoE-capable AP.

Specifications:
 - SoC: Qualcomm Atheros QCA9533
 - Flash: 16 MB (SPI)
 - RAM: 64 MB
 - Ethernet: 1x 10/100 Mbps (PoE in)
 - WiFi: AR9531 2T2R 2.4 GHz (SoC)
 - 3x green LEDs (1x lan, 1x wlan, 1x user)

 See https://mikrotik.com/product/RBwAP2nD for more info.

Flashing:
 TFTP boot initramfs image and then perform sysupgrade. Follow common
 MikroTik procedure as in https://openwrt.org/toh/mikrotik/common.

Note: following 781d4bfb397cdd12ee0151eb66c577f470e3377d
 The network setup avoids using the integrated switch and connects the
 single Ethernet port directly. This way, link speed (10/100 Mbps) is
 properly reported by eth0.

Signed-off-by: David Musil <0x4...@protonmail.com>
(cherry picked from commit e20de224427008e0f26161f924bc347d974fd15a)
Signed-off-by: Thibaut VARÈNE 
---
Successfully tested with 21.02.5 - backporting will ease transition from 19.07
---
 .../qca9533_mikrotik_routerboard-wap-2nd.dts  | 58 +++
 target/linux/ath79/image/mikrotik.mk  |  8 +++
 .../mikrotik/base-files/etc/board.d/01_leds   |  3 +-
 .../base-files/etc/board.d/02_network |  2 +
 .../etc/hotplug.d/firmware/10-ath9k-eeprom|  1 +
 5 files changed, 71 insertions(+), 1 deletion(-)
 create mode 100644 
target/linux/ath79/dts/qca9533_mikrotik_routerboard-wap-2nd.dts

diff --git a/target/linux/ath79/dts/qca9533_mikrotik_routerboard-wap-2nd.dts 
b/target/linux/ath79/dts/qca9533_mikrotik_routerboard-wap-2nd.dts
new file mode 100644
index 00..807941c608
--- /dev/null
+++ b/target/linux/ath79/dts/qca9533_mikrotik_routerboard-wap-2nd.dts
@@ -0,0 +1,58 @@
+// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
+
+#include "qca9533_mikrotik_routerboard-16m.dtsi"
+
+/ {
+   compatible = "mikrotik,routerboard-wap-2nd", "qca,qca9533";
+   model = "MikroTik RouterBOARD wAP-2nD (wAP)";
+
+   aliases {
+   led-boot = &led_user;
+   led-failsafe = &led_user;
+   led-running = &led_user;
+   led-upgrade = &led_user;
+   };
+
+   leds {
+   compatible = "gpio-leds";
+   pinctrl-names = "default";
+   pinctrl-0 = <&led_lan_pin>;
+
+   lan {
+   label = "green:lan";
+   gpios = <&gpio 4 GPIO_ACTIVE_LOW>;
+   };
+
+   wlan {
+   label = "green:wlan";
+   gpios = <&gpio 11 GPIO_ACTIVE_LOW>;
+   linux,default-trigger = "phy0tpt";
+   };
+
+   led_user: user {
+   label = "green:user";
+   gpios = <&gpio 14 GPIO_ACTIVE_LOW>;
+   };
+   };
+};
+
+ð0 {
+   status = "okay";
+
+   phy-handle = <&swphy0>;
+
+   gmac-config {
+   device = <&gmac>;
+   switch-phy-swap = <1>;
+   };
+};
+
+ð1 {
+   compatible = "syscon", "simple-mfd";
+};
+
+&pinmux {
+   led_lan_pin: pinmux_led_lan_pin {
+   pinctrl-single,bits = <0x4 0x0 0xff>;
+   };
+};
diff --git a/target/linux/ath79/image/mikrotik.mk 
b/target/linux/ath79/image/mikrotik.mk
index 08759f98ad..69d3097847 100644
--- a/target/linux/ath79/image/mikrotik.mk
+++ b/target/linux/ath79/image/mikrotik.mk
@@ -99,3 +99,11 @@ define Device/mikrotik_routerboard-wapr-2nd
   IMAGE_SIZE := 16256k
 endef
 TARGET_DEVICES += mikrotik_routerboard-wapr-2nd
+
+define Device/mikrotik_routerboard-wap-2nd
+  $(Device/mikrotik_nor)
+  SOC := qca9533
+  DEVICE_MODEL := RouterBOARD wAP-2nD (wAP)
+  IMAGE_SIZE := 16256k
+endef
+TARGET_DEVICES += mikrotik_routerboard-wap-2nd
diff --git a/target/linux/ath79/mikrotik/base-files/etc/board.d/01_leds 
b/target/linux/ath79/mikrotik/base-files/etc/board.d/01_leds
index 9f42a09a2e..448efe15b4 100755
--- a/target/linux/ath79/mikrotik/base-files/etc/board.d/01_leds
+++ b/target/linux/ath79/mikrotik/base-files/etc/board.d/01_leds
@@ -15,7 +15,8 @@ mikrotik,routerboard-952ui-5ac2nd)
ucidef_set_led_switch "port5" "port5" "green:port5" "switch0" "0x02"
;;
 mikrotik,routerboard-lhg-2nd|\
-mikrotik,routerboard-mapl-2nd)
+mikrotik,routerboard-mapl-2nd|\
+mikrotik,routerboard-wap-2nd)
ucidef_set_led_netdev "lan" "lan" "green:lan" "eth0"
;;
 mikrotik,routerboard-map-2nd)
diff --git a/target/linux/ath79/mikrotik/base-files/etc/board.d/02_network 
b/target/linux/ath79/mikrotik/base-files/etc/board.d/02_network
index e14db83ed1..0906ac42b7 100755
--- a/target/linux/ath79/mikrotik/base-files/etc/board.d/02

[PATCH 22.03] ath79: mikrotik: use OpenWrt loader for initram image

2022-11-19 Thread Thibaut VARÈNE
From: John Thomson 

Return to using the OpenWrt kernel loader to decompress and load kernel
initram image.

Continue to use the vmlinuz kernel for squashfs.

Mikrotik's bootloader RouterBOOT on some ath79 devices is
failing to boot the current initram, due to the size of the initram image.

On the ath79 wAP-ac:
a 5.7MiB initram image would fail to boot
After this change:
a 6.6MiB initram image successfully loads

This partially reverts commit e91344776b9ba7c864be88d915c9c0df0eb790dd.

An alternative of using RouterBOOT's capability of loading an initrd ELF
section was investigated, but the OpenWrt kernel loader allows larger image.

Signed-off-by: John Thomson 
(cherry picked from commit 62b72eafe49d2eecd3692691152ed86a0327fcb0)
Signed-off-by: Thibaut VARÈNE 
Fixes: #9954
---
This should be backported as it fixes non-bootable install media for 22.03
It has seen a couple months of use in master with no report of issues.
---
 target/linux/ath79/image/common-mikrotik.mk | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/target/linux/ath79/image/common-mikrotik.mk 
b/target/linux/ath79/image/common-mikrotik.mk
index 5f5fa7899a..fb3dc78226 100644
--- a/target/linux/ath79/image/common-mikrotik.mk
+++ b/target/linux/ath79/image/common-mikrotik.mk
@@ -1,8 +1,10 @@
 define Device/mikrotik
DEVICE_VENDOR := MikroTik
+   LOADER_TYPE := elf
KERNEL_NAME := vmlinuz
KERNEL := kernel-bin | append-dtb-elf
-   KERNEL_INITRAMFS := kernel-bin | append-dtb-elf
+   KERNEL_INITRAMFS_NAME := vmlinux-initramfs
+   KERNEL_INITRAMFS := kernel-bin | append-dtb | lzma | loader-kernel
 endef
 
 define Device/mikrotik_nor
-- 
2.24.3 (Apple Git-128)


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


Re: [PATCH v2 6/7] coreutils: Import from packages feed

2023-01-07 Thread Thibaut VARÈNE


> Le 7 janv. 2023 à 15:06, Christian Marangi  a écrit :
> 
> On Fri, Jan 06, 2023 at 11:49:44PM -0800, Brian Norris wrote:
>> I need to express a per-target dependency on the 'base64' utility, and
>> that's seemingly impossible to do for busybox. Pull in coreutils to make
>> that easier.
>> 
>> Signed-off-by: Brian Norris 
> 
> We still need to think of a correct solution for this... coreutils is an
> option but wonder if a better one is openssl... Actually we have a small
> tool to handle specific decryption of some stuff... Wonder if that can
> be expanded for this task and just use wolfssl or openssl api to decode
> base64 stuff?

Using one or the other would impose (i.e. (en)force) that SSL library on this 
particular target. Do we want this, especially considering the ongoing 
conversation about mbedTLS?

Also pulling an entire SSL implementation just to decode base64 seems a tad 
overkill too.

HTH
___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[PATCH] ath79: mikrotik: bump compat version for yafut images

2023-05-05 Thread Thibaut VARÈNE
Following 5264296, Mirotik NAND devices now use yafut to flash the
kernel on devices. This method is incompatible with the old-style
"kernel2minor" flash mechanism.

Even though NAND images were disabled in default build since 21.02, a
user flashing a new-style image onto an old-style image would result in
in a soft-brick[1]. In order to prevent such accidental mishap,
especially as these device images will be reenabled in the upcoming
release, bump the compat version.

After the new image is flashed, the compat version can be updated:

uci set system.@system[0].compat_version='1.1'
uci commit

[1] https://github.com/openwrt/openwrt/pull/12225#issuecomment-1517529262

Cc: Michał Kępień 
Signed-off-by: Thibaut VARÈNE 
---
 target/linux/ath79/image/common-mikrotik.mk | 4 
 1 file changed, 4 insertions(+)

diff --git a/target/linux/ath79/image/common-mikrotik.mk 
b/target/linux/ath79/image/common-mikrotik.mk
index ce349b60b1..b37c8b7197 100644
--- a/target/linux/ath79/image/common-mikrotik.mk
+++ b/target/linux/ath79/image/common-mikrotik.mk
@@ -18,4 +18,8 @@ endef
 define Device/mikrotik_nand
   $(Device/mikrotik)
   IMAGE/sysupgrade.bin = append-kernel | sysupgrade-tar | append-metadata
+  DEVICE_COMPAT_MESSAGE := \
+   NAND images switched to yafut. If running older image, reinstall from 
initramfs.
+  DEVICE_COMPAT_VERSION := 1.1
+
 endef
-- 
2.37.1 (Apple Git-137.1)


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[PATCH] Revert "feeds: use git-src-full to allow Git versioning"

2023-05-27 Thread Thibaut VARÈNE
From: Petr Štetiar 

This partially reverts commit 7fae1e5677e9bb4979c8d4ac99be4de6955b13d0
as it should be no longer necessary to do a full clone since commit
48ed07bc0b94 ("treewide: replace AUTORELEASE with real PKG_RELEASE").

Suggested-by: Thibaut VARÈNE 
Signed-off-by: Petr Štetiar 
(cherry picked from commit 11bb5337b8d8b5018e48f0df415efb99e2f49d0d)
[adjusted to 23.05]
Signed-off-by: Thibaut VARÈNE 
---
ma{ster,in} did not explode so let's apply to 23.05 as well.
this halves buildbot feedupdate step time.
---
 feeds.conf.default | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/feeds.conf.default b/feeds.conf.default
index f062f8545e..d467db5627 100644
--- a/feeds.conf.default
+++ b/feeds.conf.default
@@ -1,4 +1,4 @@
-src-git-full packages https://git.openwrt.org/feed/packages.git;openwrt-23.05
-src-git-full luci https://git.openwrt.org/project/luci.git;openwrt-23.05
-src-git-full routing https://git.openwrt.org/feed/routing.git;openwrt-23.05
-src-git-full telephony https://git.openwrt.org/feed/telephony.git;openwrt-23.05
+src-git packages https://git.openwrt.org/feed/packages.git;openwrt-23.05
+src-git luci https://git.openwrt.org/project/luci.git;openwrt-23.05
+src-git routing https://git.openwrt.org/feed/routing.git;openwrt-23.05
+src-git telephony https://git.openwrt.org/feed/telephony.git;openwrt-23.05
-- 
2.37.1 (Apple Git-137.1)


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[23.05 PATCH] ucode: update to Git 4dd98370ef558a62a9afd10ad6aa1cc658cf7339 (2024-06-18)

2024-07-11 Thread Thibaut VARÈNE
96f74b5be829 ubus: make ubus_context first in uc_ubus_connection_t
7e5830edfb38 nl80211: fix datatype of NL80211_BAND_IFTYPE_ATTR_HE_CAP_{MAC,PHY} 
attrs
5c8fd34bac42 nl80211: fix parsing of NL80211_BAND_ATTR_VHT_MCS_SET attribute
e8d4e4fe967d nl80211: fix decoding of NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET 
attribute
30a3f7ad0433 rtnl: store callback in listener registry only on success
9cbe8294909f rtnl: optimize reception of rtnl events
534417132e18 rtnl: increase event socket rx buffer size limit to 1 MiB
3f9811d2f7b7 compiler: close upvalues on loop control statements
ee4af9b55cb4 vm: rework object iteration
a275399dd8e2 uci: refactor uci.changes() to match documentation
1220992631d5 ubus: automatically clear error information
d6fd94014eea uci: automatically clear error information
99837f280b61 uloop: automatically clear error information
ba3855ae3775 lib: fix documentation typo for `pop()` function
be767ae197ba vm: rework `in` operator semantics
4ade84e8fb81 ubus: add explicit support for deferring incoming requests
cfe137be068a uci: remove incorrectly documentated reorder() parameter
e8d78a26da0c lib: introduce socket library
a0ad1d127ae6 build: fix symbol and library detection
674f65ee551d jsdoc: disable default module titles
a33d16a86493 socket: rework error handling
e2b81d869222 uloop: add documentation
953f36c96e8a socket: make socket.send() accept non-string data
f211d5ac666f ubus: fix uc_ubus_have_uloop for eloop+uloop combination
0662de64bd1f socket: add AF_PACKET socket type support
b594ff8a2841 socket: remove leftover debug code
0d823e702bfe socket: fix addrinfo() with omitted service argument
8cf816d615fd socket: fix potential memory leak in connect()
8f5f231d66cd socket: optimize poll() argument handling
36f106056069 socket: remove wrong documentation fragment
525fca224012 socket: uv_to_sockaddr(): fix length calculation for AF_UNIX 
addresses
3938645ad9e3 socket: support IPv6 addresses in struct conversion routines
3a586dc7ddbe socket: improve uc_socket_connect() behavior
7b269f1cd3d2 socket: improve uc_socket_listen() behavior
fc6f2b89febf socket: handle further socket option value types
d6f25797dad1 socket: add IPv6 socket options
7611487b9a05 socket: implement recvmsg(), sendmsg() and cmsg support
d2e44bfa8b54 core-lib: improved documentation
e0bab40c8578 fs: add truncate() file method
5d305cfb2ab7 fs: add lock() file method
8b0318f7fabe lib: introduce zlib library

Fixes:
Fixes: https://github.com/jow-/ucode/issues/186
Fixes: https://github.com/jow-/ucode/issues/187
Fixes: https://github.com/jow-/ucode/issues/188
Fixes: https://github.com/jow-/ucode/issues/193
Signed-off-by: Thibaut VARÈNE 
---
 package/utils/ucode/Makefile | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
---
This brings ucode in line with master (33420f039)

diff --git a/package/utils/ucode/Makefile b/package/utils/ucode/Makefile
index c1fadd8..6e3b899 100644
--- a/package/utils/ucode/Makefile
+++ b/package/utils/ucode/Makefile
@@ -12,9 +12,9 @@ PKG_RELEASE:=1
 
 PKG_SOURCE_PROTO:=git
 PKG_SOURCE_URL=https://github.com/jow-/ucode.git
-PKG_SOURCE_DATE:=2023-11-07
-PKG_SOURCE_VERSION:=a6e75e02528e36f3610a7f0073453018336def2e
-PKG_MIRROR_HASH:=e1a0f98ba865ed5911d5db3bfca55a2f1b825992bf5f7c7e324928d9412d7ae2
+PKG_SOURCE_DATE:=2024-06-18
+PKG_SOURCE_VERSION:=4dd98370ef558a62a9afd10ad6aa1cc658cf7339
+PKG_MIRROR_HASH:=45b781ad4e530b8b585a687e20e1e2b2017cc72a91db858096828659cbfb258f
 PKG_MAINTAINER:=Jo-Philipp Wich 
 PKG_LICENSE:=ISC
 
-- 
2.39.2


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel