diff mbox series

[OpenWrt-Devel] ramips: Fix sysupgrade for Xiaomi mir3g

Message ID 20200105141756.23473-1-hauke@hauke-m.de
State Accepted
Headers show
Series [OpenWrt-Devel] ramips: Fix sysupgrade for Xiaomi mir3g | expand

Commit Message

Hauke Mehrtens Jan. 5, 2020, 2:17 p.m. UTC
Without this change sysupgrade from 18.06 to 19.07 is only possible with
the -F option.
In OpenWrt 18.06 the nand_do_platform_check() function is called with
the board name mir3g only, if the tar does not use mir3g it will fail.
OpenWrt 19.07 and later support the metadata with the supported_devices
attribute to allow renaming. Do the renaming of the target between 19.07
and master like it is done for some other boards.

I tested the following sysupgrades successfully without -F
18.06 -> 19.07
19.07 -> master
master -> 19.07

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
---
 target/linux/ramips/image/mt7621.mk | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Hauke Mehrtens Jan. 5, 2020, 2:18 p.m. UTC | #1
On 1/5/20 3:17 PM, Hauke Mehrtens wrote:
> Without this change sysupgrade from 18.06 to 19.07 is only possible with
> the -F option.
> In OpenWrt 18.06 the nand_do_platform_check() function is called with
> the board name mir3g only, if the tar does not use mir3g it will fail.
> OpenWrt 19.07 and later support the metadata with the supported_devices
> attribute to allow renaming. Do the renaming of the target between 19.07
> and master like it is done for some other boards.
> 
> I tested the following sysupgrades successfully without -F
> 18.06 -> 19.07
> 19.07 -> master
> master -> 19.07
> 
> Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
> ---
>  target/linux/ramips/image/mt7621.mk | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 

This should only go into 19.07 and not into master.

Hauke
Adrian Schmutzler Jan. 5, 2020, 4:37 p.m. UTC | #2
Hi Hauke,

> -----Original Message-----
> From: Hauke Mehrtens [mailto:hauke@hauke-m.de]
> Sent: Sonntag, 5. Januar 2020 15:18
> To: openwrt-devel@lists.openwrt.org
> Cc: mail@adrianschmutzler.de; dev@kresin.me; Hauke Mehrtens
> <hauke@hauke-m.de>
> Subject: [PATCH] ramips: Fix sysupgrade for Xiaomi mir3g
> 
> Without this change sysupgrade from 18.06 to 19.07 is only possible with the -
> F option.
> In OpenWrt 18.06 the nand_do_platform_check() function is called with the
> board name mir3g only, if the tar does not use mir3g it will fail.
> OpenWrt 19.07 and later support the metadata with the supported_devices
> attribute to allow renaming. Do the renaming of the target between 19.07
> and master like it is done for some other boards.
> 
> I tested the following sysupgrades successfully without -F
> 18.06 -> 19.07
> 19.07 -> master
> master -> 19.07
> 
> Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
> ---
>  target/linux/ramips/image/mt7621.mk | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/target/linux/ramips/image/mt7621.mk
> b/target/linux/ramips/image/mt7621.mk
> index 7eb59188fb..39017a48e1 100644
> --- a/target/linux/ramips/image/mt7621.mk
> +++ b/target/linux/ramips/image/mt7621.mk
> @@ -269,7 +269,7 @@ define Device/xiaomi_mir3p  endef  TARGET_DEVICES
> += xiaomi_mir3p
> 
> -define Device/xiaomi_mir3g
> +define Device/mir3g
>    DTS := MIR3G
>    BLOCKSIZE := 128k
>    PAGESIZE := 2048
> @@ -282,12 +282,12 @@ define Device/xiaomi_mir3g
>    IMAGE/sysupgrade.bin := sysupgrade-tar | append-metadata
>    DEVICE_TITLE := Xiaomi Mi Router 3G
>    SUPPORTED_DEVICES += R3G
> -  SUPPORTED_DEVICES += mir3g
> +  SUPPORTED_DEVICES += xiaomi,mir3g

I do not really understand this patch, as still the names will be the same, but just the order will change. If you really rely on the first name to be mir3g, you could achieve this much easier by just using:

SUPPORTED_DEVICES := mir3g R3G xiaomi,mir3g

With that, you would not have to change the device node name at all.

Best

Adrian

>    DEVICE_PACKAGES := \
>  	kmod-mt7603 kmod-mt76x2 kmod-usb3 kmod-usb-ledtrig-usbport
> wpad-basic \
>  	uboot-envtools
>  endef
> -TARGET_DEVICES += xiaomi_mir3g
> +TARGET_DEVICES += mir3g
> 
>  define Device/mt7621
>    DTS := MT7621
> --
> 2.20.1
Hauke Mehrtens Jan. 5, 2020, 4:48 p.m. UTC | #3
On 1/5/20 5:37 PM, mail@adrianschmutzler.de wrote:
> Hi Hauke,
> 
>> -----Original Message-----
>> From: Hauke Mehrtens [mailto:hauke@hauke-m.de]
>> Sent: Sonntag, 5. Januar 2020 15:18
>> To: openwrt-devel@lists.openwrt.org
>> Cc: mail@adrianschmutzler.de; dev@kresin.me; Hauke Mehrtens
>> <hauke@hauke-m.de>
>> Subject: [PATCH] ramips: Fix sysupgrade for Xiaomi mir3g
>>
>> Without this change sysupgrade from 18.06 to 19.07 is only possible with the -
>> F option.
>> In OpenWrt 18.06 the nand_do_platform_check() function is called with the
>> board name mir3g only, if the tar does not use mir3g it will fail.
>> OpenWrt 19.07 and later support the metadata with the supported_devices
>> attribute to allow renaming. Do the renaming of the target between 19.07
>> and master like it is done for some other boards.
>>
>> I tested the following sysupgrades successfully without -F
>> 18.06 -> 19.07
>> 19.07 -> master
>> master -> 19.07
>>
>> Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
>> ---
>>  target/linux/ramips/image/mt7621.mk | 6 +++---
>>  1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/target/linux/ramips/image/mt7621.mk
>> b/target/linux/ramips/image/mt7621.mk
>> index 7eb59188fb..39017a48e1 100644
>> --- a/target/linux/ramips/image/mt7621.mk
>> +++ b/target/linux/ramips/image/mt7621.mk
>> @@ -269,7 +269,7 @@ define Device/xiaomi_mir3p  endef  TARGET_DEVICES
>> += xiaomi_mir3p
>>
>> -define Device/xiaomi_mir3g
>> +define Device/mir3g
>>    DTS := MIR3G
>>    BLOCKSIZE := 128k
>>    PAGESIZE := 2048
>> @@ -282,12 +282,12 @@ define Device/xiaomi_mir3g
>>    IMAGE/sysupgrade.bin := sysupgrade-tar | append-metadata
>>    DEVICE_TITLE := Xiaomi Mi Router 3G
>>    SUPPORTED_DEVICES += R3G
>> -  SUPPORTED_DEVICES += mir3g
>> +  SUPPORTED_DEVICES += xiaomi,mir3g
> 
> I do not really understand this patch, as still the names will be the same, but just the order will change. If you really rely on the first name to be mir3g, you could achieve this much easier by just using:

OpenWrt 18.06 does not support the SUPPORTED_DEVICES fully. I only added
xiaomi,mir3g there to allow a downgrade from master to 19.07, which is
not so important.

> SUPPORTED_DEVICES := mir3g R3G xiaomi,mir3g
> 
> With that, you would not have to change the device node name at all.

When I use sysupgrade in 18.06 it executes the platform_check_image()
functions which calls nand_do_platform_check("mir3g",
"/tmp/openwrt-19.07-ramips-mt7621-xiaomi_mir3g-squashfs-sysupgrade.bin")
https://git.openwrt.org/?p=openwrt/openwrt.git;a=blob;f=target/linux/ramips/base-files/lib/upgrade/platform.sh;h=ffdc5e73e0ede286c10396810954a230c8ea32fc;hb=refs/heads/openwrt-18.06#l296

The nand_do_platform_check() function is located here:
https://git.openwrt.org/?p=openwrt/openwrt.git;a=blob;f=package/base-files/files/lib/upgrade/nand.sh;h=42f488c118fab514de7d2aee78bc431f7b8be157;hb=refs/heads/openwrt-18.06#l317

It calls this:
local control_length=`(tar xf $tar_file sysupgrade-$board_name/CONTROL
-O | wc -c) 2> /dev/null`

which expands to
tar xf
/tmp/openwrt-19.07-ramips-mt7621-xiaomi_mir3g-squashfs-sysupgrade.bin
sysupgrade-mir3g/CONTROL

This file does not exists:
sysupgrade-mir3g/CONTROL
But this is there:
sysupgrade-xiaomi_mir3g/CONTROL
The system does not find it and aborts.

The control_length is set to 0 and we expect the file_type detection to
work, but it does not because the ubi is inside the tar.

The sysupgrade in 19.07 supports the SUPPORTED_DEVICES, the sysupgrade
in 18.06 does not support the metadata fully.

When we do the board rename between 19.07 and master it is fine, but we
should not rename the board between 18.06 and 19.07.

Hauke
Adrian Schmutzler Jan. 5, 2020, 4:57 p.m. UTC | #4
Hi,

> When I use sysupgrade in 18.06 it executes the platform_check_image() 
> functions which calls nand_do_platform_check("mir3g", 
> "/tmp/openwrt-19.07-ramips-mt7621-xiaomi_mir3g-squashfs-sysupgrade.bin") 
> https://git.openwrt.org/?p=openwrt/openwrt.git;a=blob;f=target/linux/ramips/base-files/lib/upgrade/platform.sh;h=ffdc5e73e0ede286c10396810954a230c8ea32fc;hb=refs/heads/openwrt-18.06#l296
> The nand_do_platform_check() function is located here: 
> https://git.openwrt.org/?p=openwrt/openwrt.git;a=blob;f=package/base-files/files/lib/upgrade/nand.sh;h=42f488c118fab514de7d2aee78bc431f7b8be157;hb=refs/heads/openwrt-18.06#l317
> It calls this: 
> local control_length=`(tar xf $tar_file sysupgrade-$board_name/CONTROL 
> -O | wc -c) 2> /dev/null` 
> which expands to 
> tar xf 
> /tmp/openwrt-19.07-ramips-mt7621-xiaomi_mir3g-squashfs-sysupgrade.bin 
> sysupgrade-mir3g/CONTROL 
> This file does not exists: 
> sysupgrade-mir3g/CONTROL 
> But this is there: 
> sysupgrade-xiaomi_mir3g/CONTROL 

I see. I wasn't aware that the "old" sysupgrade was effectively using the device node name here.

> The system does not find it and aborts. 
> The control_length is set to 0 and we expect the file_type detection to 
> work, but it does not because the ubi is inside the tar. 
> The sysupgrade in 19.07 supports the SUPPORTED_DEVICES, the sysupgrade 
> in 18.06 does not support the metadata fully. 
> When we do the board rename between 19.07 and master it is fine, but we 
> should not rename the board between 18.06 and 19.07. 

Since ramips in 19.07 is mixed anyway, I have no objections left.

Best

Adrian
Mathias Kresin Jan. 6, 2020, 9:33 a.m. UTC | #5
05/01/2020 15:17, Hauke Mehrtens:
> Without this change sysupgrade from 18.06 to 19.07 is only possible with
> the -F option.
> In OpenWrt 18.06 the nand_do_platform_check() function is called with
> the board name mir3g only, if the tar does not use mir3g it will fail.
> OpenWrt 19.07 and later support the metadata with the supported_devices
> attribute to allow renaming. Do the renaming of the target between 19.07
> and master like it is done for some other boards.
> 
> I tested the following sysupgrades successfully without -F
> 18.06 -> 19.07
> 19.07 -> master
> master -> 19.07
> 
> Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
> ---
>   target/linux/ramips/image/mt7621.mk | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/target/linux/ramips/image/mt7621.mk b/target/linux/ramips/image/mt7621.mk
> index 7eb59188fb..39017a48e1 100644
> --- a/target/linux/ramips/image/mt7621.mk
> +++ b/target/linux/ramips/image/mt7621.mk
> @@ -269,7 +269,7 @@ define Device/xiaomi_mir3p
>   endef
>   TARGET_DEVICES += xiaomi_mir3p
>   
> -define Device/xiaomi_mir3g
> +define Device/mir3g
>     DTS := MIR3G
>     BLOCKSIZE := 128k
>     PAGESIZE := 2048
> @@ -282,12 +282,12 @@ define Device/xiaomi_mir3g
>     IMAGE/sysupgrade.bin := sysupgrade-tar | append-metadata
>     DEVICE_TITLE := Xiaomi Mi Router 3G
>     SUPPORTED_DEVICES += R3G
> -  SUPPORTED_DEVICES += mir3g
> +  SUPPORTED_DEVICES += xiaomi,mir3g
>     DEVICE_PACKAGES := \
>   	kmod-mt7603 kmod-mt76x2 kmod-usb3 kmod-usb-ledtrig-usbport wpad-basic \
>   	uboot-envtools
>   endef
> -TARGET_DEVICES += xiaomi_mir3g
> +TARGET_DEVICES += mir3g
>   
>   define Device/mt7621
>     DTS := MT7621
> 

Wouldn't it be the easiest to force the name used for the directory in 
the sysupgrade.tar to "sysupgrade-mir3g", to be compatible with 18.06 
and earlier?

It can be done by adding "BOARD_NAME := mir3g" to the device define in 
the 19.07 branch as well as master.

Beginning with 19.07, nand_do_platform_check() isn't used for ramips and 
nand_upgrade_tar() doesn't rely on the boardname either any longer. 
Instead, nand_upgrade_tar() will grab the kernel and rootfs from the 
first found directory matching the pattern "sysupgrade-.*". Means, we 
wouldn't introduce another compatibility issue.

Of course, a downgrade from master to 19.07 and earlier would still 
require the force argument due to the not matching name in the image 
metadata. Considering that we don't adjust the running config to be 
compatible with earlier releases during downgrade, I rather see this as 
a pro than as con.

Mathias
Adrian Schmutzler Jan. 7, 2020, 11:39 a.m. UTC | #6
Hi Hauke,

since you seem to have a mir3g, maybe you can look into the following MAC address issue/question when you find some time:

For the mir3g, 02_network sets the lan_mac to factory 0xe006, while the address from 0xe000 set to &ethernet is (thus) used for wan:
https://github.com/openwrt/openwrt/blob/master/target/linux/ramips/mt7621/base-files/etc/board.d/02_network#L262

That's the opposite of what's usual for mt7621 (lan: 0xe000, wan: 0xe006). Therefore, if you happen to have some spare time, it would be interesting to check which assignment is correct (with vendor OS). When dealing with this anyway, it would also be interesting whether the device has a label MAC address.

However, this is not really a pressing issue, so if you're short on time just ignore me.

Best

Adrian
Hauke Mehrtens Jan. 7, 2020, 10:04 p.m. UTC | #7
On 1/7/20 12:39 PM, Adrian Schmutzler wrote:
> Hi Hauke,
> 
> since you seem to have a mir3g, maybe you can look into the following MAC address issue/question when you find some time:
> 
> For the mir3g, 02_network sets the lan_mac to factory 0xe006, while the address from 0xe000 set to &ethernet is (thus) used for wan:
> https://github.com/openwrt/openwrt/blob/master/target/linux/ramips/mt7621/base-files/etc/board.d/02_network#L262
> 
> That's the opposite of what's usual for mt7621 (lan: 0xe000, wan: 0xe006). Therefore, if you happen to have some spare time, it would be interesting to check which assignment is correct (with vendor OS). When dealing with this anyway, it would also be interesting whether the device has a label MAC address.
> 
> However, this is not really a pressing issue, so if you're short on time just ignore me.
> 
> Best
> 
> Adrian
> 

Hi,

I haven't checked the vendor FW, I only have OpenWrt on it and would
have to flash somehow back.

The LAN MAC in OpenWrt is: 40:31:3c:02:8f:b8
The WAN MAC in OpenWrt is: 40:31:3c:02:8f:b7

The label says: 40:31:3C:02:8F:B8

In the bootlog of the vendor FW I see this:
[    7.520000] set LAN/WAN LWLLL
[    7.530000] GMAC1_MAC_ADRH -- : 0x00004031
[    7.530000] GMAC1_MAC_ADRL -- : 0x3c028fb7
[    7.530000] GDMA2_MAC_ADRH -- : 0x00004031
[    7.540000] GDMA2_MAC_ADRL -- : 0x3c028fb8
[    7.540000] eth1: ===> VirtualIF_open

Hauke
diff mbox series

Patch

diff --git a/target/linux/ramips/image/mt7621.mk b/target/linux/ramips/image/mt7621.mk
index 7eb59188fb..39017a48e1 100644
--- a/target/linux/ramips/image/mt7621.mk
+++ b/target/linux/ramips/image/mt7621.mk
@@ -269,7 +269,7 @@  define Device/xiaomi_mir3p
 endef
 TARGET_DEVICES += xiaomi_mir3p
 
-define Device/xiaomi_mir3g
+define Device/mir3g
   DTS := MIR3G
   BLOCKSIZE := 128k
   PAGESIZE := 2048
@@ -282,12 +282,12 @@  define Device/xiaomi_mir3g
   IMAGE/sysupgrade.bin := sysupgrade-tar | append-metadata
   DEVICE_TITLE := Xiaomi Mi Router 3G
   SUPPORTED_DEVICES += R3G
-  SUPPORTED_DEVICES += mir3g
+  SUPPORTED_DEVICES += xiaomi,mir3g
   DEVICE_PACKAGES := \
 	kmod-mt7603 kmod-mt76x2 kmod-usb3 kmod-usb-ledtrig-usbport wpad-basic \
 	uboot-envtools
 endef
-TARGET_DEVICES += xiaomi_mir3g
+TARGET_DEVICES += mir3g
 
 define Device/mt7621
   DTS := MT7621