Skip to content

Commit

Permalink
ramips: mt7621: Add Dual Partition support, for Linksys EA7300v2 and …
Browse files Browse the repository at this point in the history
…EA7500v2

Enable dual partition operation for these Linksys routers - program to the
alternative partition (similar to other dual partition routers). Tested and working.

Signed-off-by: Russell Morris <rmorris@rkmorris.us>
  • Loading branch information
arrmo committed Apr 21, 2022
1 parent 0d2d52d commit b1201a8
Show file tree
Hide file tree
Showing 7 changed files with 215 additions and 9 deletions.
10 changes: 4 additions & 6 deletions target/linux/ramips/dts/mt7621_linksys_ea7xxx.dtsi
Expand Up @@ -115,25 +115,23 @@
};

partition@180000 {
label = "kernel";
label = "kernel1";
reg = <0x180000 0x400000>;
};

partition@580000 {
label = "ubi";
label = "rootfs1";
reg = <0x580000 0x2400000>;
};

partition@2980000 {
label = "alt_kernel";
label = "kernel2";
reg = <0x2980000 0x400000>;
read-only;
};

partition@2d80000 {
label = "alt_rootfs";
label = "rootfs2";
reg = <0x2d80000 0x2400000>;
read-only;
};

partition@5180000 {
Expand Down
76 changes: 76 additions & 0 deletions target/linux/ramips/mt7621/base-files/lib/upgrade/linksys.sh
@@ -0,0 +1,76 @@
#
# Copyright (C) 2014 OpenWrt.org
#

linksys_get_target_firmware() {

local cur_boot_part mtd_ubi0

cur_boot_part=$(/usr/sbin/fw_printenv -n boot_part)
if [ -z "${cur_boot_part}" ] ; then
mtd_ubi0=$(cat /sys/devices/virtual/ubi/ubi0/mtd_num)
case $(grep -E ^mtd${mtd_ubi0}: /proc/mtd | cut -d '"' -f 2) in
kernel|rootfs)
cur_boot_part=1
;;
alt_kernel|alt_rootfs)
cur_boot_part=2
;;
esac
>&2 printf "Current boot_part='%s' selected from ubi0/mtd_num='%s'" \
"${cur_boot_part}" "${mtd_ubi0}"
fi

case $cur_boot_part in
1)
fw_setenv -s - <<-EOF
boot_part 2
bootcmd "run altnandboot"
EOF
printf "kernel2"
return
;;
2)
fw_setenv -s - <<-EOF
boot_part 1
bootcmd "run nandboot"
EOF
printf "kernel1"
return
;;
*)
return
;;
esac
}

platform_do_upgrade_linksys() {
local magic_long="$(get_magic_long "$1")"

mkdir -p /var/lock
local part_label="$(linksys_get_target_firmware)"
touch /var/lock/fw_printenv.lock

if [ ! -n "$part_label" ]
then
echo "cannot find target partition"
exit 1
fi

local target_mtd=$(find_mtd_part $part_label)

[ "$magic_long" = "73797375" ] && {
CI_KERNPART="$part_label"
if [ "$part_label" = "kernel1" ]
then
CI_UBIPART="rootfs1"
else
CI_UBIPART="rootfs2"
fi

nand_upgrade_tar "$1"
}
[ "$magic_long" = "27051956" ] && {
get_image "$1" | mtd write - $part_label
}
}
8 changes: 5 additions & 3 deletions target/linux/ramips/mt7621/base-files/lib/upgrade/platform.sh
Expand Up @@ -65,9 +65,6 @@ platform_do_upgrade() {
jcg,q20|\
linksys,e5600|\
linksys,ea6350-v4|\
linksys,ea7300-v1|\
linksys,ea7300-v2|\
linksys,ea7500-v2|\
linksys,ea8100-v1|\
linksys,ea8100-v2|\
netgear,r6220|\
Expand Down Expand Up @@ -105,6 +102,11 @@ platform_do_upgrade() {
iodata_mstc_upgrade_prepare "0x1fe75"
nand_do_upgrade "$1"
;;
linksys,ea7300-v1|\
linksys,ea7300-v2|\
linksys,ea7500-v2)
platform_do_upgrade_linksys "$1"
;;
ubnt,edgerouter-x|\
ubnt,edgerouter-x-sfp)
platform_upgrade_ubnt_erx "$1"
Expand Down
3 changes: 3 additions & 0 deletions target/linux/ramips/mt7621/config-5.10
Expand Up @@ -287,3 +287,6 @@ CONFIG_WEAK_REORDERING_BEYOND_LLSC=y
CONFIG_XPS=y
CONFIG_ZLIB_DEFLATE=y
CONFIG_ZLIB_INFLATE=y
# CONFIG_MIPS_CMDLINE_FROM_DTB is not set
CONFIG_MIPS_CMDLINE_DTB_EXTEND=y
CONFIG_MANGLE_BOOTARGS=y
3 changes: 3 additions & 0 deletions target/linux/ramips/mt7621/config-5.15
Expand Up @@ -305,3 +305,6 @@ CONFIG_ZLIB_DEFLATE=y
CONFIG_ZLIB_INFLATE=y
CONFIG_ZSTD_COMPRESS=y
CONFIG_ZSTD_DECOMPRESS=y
# CONFIG_MIPS_CMDLINE_FROM_DTB is not set
CONFIG_MIPS_CMDLINE_DTB_EXTEND=y
CONFIG_MANGLE_BOOTARGS=y
@@ -0,0 +1,62 @@
The WRT1900AC among other Linksys routers uses a dual-firmware layout.
Dynamically rename the active partition to "ubi".

Signed-off-by: Imre Kaloz <kaloz@openwrt.org>
---
--- a/drivers/mtd/parsers/ofpart_core.c
+++ b/drivers/mtd/parsers/ofpart_core.c
@@ -38,6 +38,8 @@ static bool node_has_compatible(struct d
return of_get_property(pp, "compatible", NULL);
}

+static int mangled_rootblock;
+
static int parse_fixed_partitions(struct mtd_info *master,
const struct mtd_partition **pparts,
struct mtd_part_parser_data *data)
@@ -47,6 +49,7 @@ static int parse_fixed_partitions(struct
struct mtd_partition *parts;
struct device_node *mtd_node;
struct device_node *ofpart_node;
+ const char *owrtpart = "ubi";
const char *partname;
struct device_node *pp;
int nr_parts, i, ret = 0;
@@ -133,9 +136,15 @@ static int parse_fixed_partitions(struct
parts[i].size = of_read_number(reg + a_cells, s_cells);
parts[i].of_node = pp;

- partname = of_get_property(pp, "label", &len);
- if (!partname)
- partname = of_get_property(pp, "name", &len);
+ if (mangled_rootblock && (i == mangled_rootblock)) {
+ partname = owrtpart;
+ } else {
+ partname = of_get_property(pp, "label", &len);
+
+ if (!partname)
+ partname = of_get_property(pp, "name", &len);
+ }
+
parts[i].name = partname;

if (of_get_property(pp, "read-only", &len))
@@ -252,6 +261,18 @@ static int __init ofpart_parser_init(voi
return 0;
}

+static int __init active_root(char *str)
+{
+ get_option(&str, &mangled_rootblock);
+
+ if (!mangled_rootblock)
+ return 1;
+
+ return 1;
+}
+
+__setup("mangled_rootblock=", active_root);
+
static void __exit ofpart_parser_exit(void)
{
deregister_mtd_parser(&ofpart_parser);
@@ -0,0 +1,62 @@
The WRT1900AC among other Linksys routers uses a dual-firmware layout.
Dynamically rename the active partition to "ubi".

Signed-off-by: Imre Kaloz <kaloz@openwrt.org>
---
--- a/drivers/mtd/parsers/ofpart_core.c
+++ b/drivers/mtd/parsers/ofpart_core.c
@@ -38,6 +38,8 @@ static bool node_has_compatible(struct d
return of_get_property(pp, "compatible", NULL);
}

+static int mangled_rootblock;
+
static int parse_fixed_partitions(struct mtd_info *master,
const struct mtd_partition **pparts,
struct mtd_part_parser_data *data)
@@ -47,6 +49,7 @@ static int parse_fixed_partitions(struct
struct mtd_partition *parts;
struct device_node *mtd_node;
struct device_node *ofpart_node;
+ const char *owrtpart = "ubi";
const char *partname;
struct device_node *pp;
int nr_parts, i, ret = 0;
@@ -133,9 +136,15 @@ static int parse_fixed_partitions(struct
parts[i].size = of_read_number(reg + a_cells, s_cells);
parts[i].of_node = pp;

- partname = of_get_property(pp, "label", &len);
- if (!partname)
- partname = of_get_property(pp, "name", &len);
+ if (mangled_rootblock && (i == mangled_rootblock)) {
+ partname = owrtpart;
+ } else {
+ partname = of_get_property(pp, "label", &len);
+
+ if (!partname)
+ partname = of_get_property(pp, "name", &len);
+ }
+
parts[i].name = partname;

if (of_get_property(pp, "read-only", &len))
@@ -252,6 +261,18 @@ static int __init ofpart_parser_init(voi
return 0;
}

+static int __init active_root(char *str)
+{
+ get_option(&str, &mangled_rootblock);
+
+ if (!mangled_rootblock)
+ return 1;
+
+ return 1;
+}
+
+__setup("mangled_rootblock=", active_root);
+
static void __exit ofpart_parser_exit(void)
{
deregister_mtd_parser(&ofpart_parser);

0 comments on commit b1201a8

Please sign in to comment.