[OpenWrt-Devel] [PATCH 2/8] bootargs: Add mangled bootargs for ATAG to DTB

Adrian Panella ianchi74 at outlook.com
Thu Mar 31 21:10:49 EDT 2016


From: Adrian Panella <ianchi74 at outlook.com>

Date: Thu, 17 Mar 2016 22:07:38 -0600

Subject: [PATCH 2/8] bootargs: Add mangled bootargs for ATAG to DTB

 

Enables reading bootloader supplied bootargs and

append them to the DTB as a new key (bootloader-args), so that

they are known but won't break the automatisms OpenWrt uses.

It appends to the kernel command line the mumber of the mtd partition

that has to be set as root (this is needed for the dual boot mechanism)

using the option mangled_rootblock=XX

Needs the following options to be set in Kernel config

            CONFIG_ARM_ATAG_DTB_COMPAT=y

            CONFIG_ARM_ATAG_DTB_COMPAT_CMDLINE_EXTEND=y

 

Signed-off-by: Adrian Panella <ianchi74 at outlook.com>

---

.../patches-3.18/100-find_active_root.patch        | 61 +++++++++++++++

.../patches-3.18/110-ATAG-mangled-bootargs.patch   | 86
++++++++++++++++++++++

target/linux/ipq806x/config-3.18                | 5 ++++-

3 files changed, 151 insertions(+), 1 deletion(-)

create mode 100644
target/linux/ipq806x/patches-3.18/100-find_active_root.patch

create mode 100644
target/linux/ipq806x/patches-3.18/110-ATAG-mangled-bootargs.patch

 

diff --git a/target/linux/ipq806x/patches-3.18/100-find_active_root.patch
b/target/linux/ipq806x/patches-3.18/100-find_active_root.patch

new file mode 100644

index 0000000..e32b608

--- /dev/null

+++ b/target/linux/ipq806x/patches-3.18/100-find_active_root.patch

@@ -0,0 +1,61 @@

+The WRT1900AC among other Linksys routers uses a dual-firmware layout.

+Dynamically rename the active partition to "ubi".

+

+Signed-off-by: Imre Kaloz <kaloz at openwrt.org>

+

+--- a/drivers/mtd/ofpart.c

++++ b/drivers/mtd/ofpart.c

+@@ -25,12 +25,15 @@ static bool node_has_compatible(struct d

+     return of_get_property(pp, "compatible", NULL);

+ }

+ 

++static int mangled_rootblock;

++

+ static int parse_ofpart_partitions(struct mtd_info *master,

+                          struct mtd_partition **pparts,

+                          struct mtd_part_parser_data *data)

+ {

+     struct device_node *node;

+     const char *partname;

++    const char *owrtpart = "ubi";

+     struct device_node *pp;

+     int nr_parts, i;

+ 

+@@ -78,9 +81,15 @@ static int parse_ofpart_partitions(struc

+           (*pparts)[i].offset = of_read_number(reg, a_cells);

+           (*pparts)[i].size = of_read_number(reg + a_cells, s_cells);

+ 

+-          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);

++          }

++

+           (*pparts)[i].name = partname;

+ 

+           if (of_get_property(pp, "read-only", &len))

+@@ -178,6 +187,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);

diff --git
a/target/linux/ipq806x/patches-3.18/110-ATAG-mangled-bootargs.patch
b/target/linux/ipq806x/patches-3.18/110-ATAG-mangled-bootargs.patch

new file mode 100644

index 0000000..34da86c

--- /dev/null

+++ b/target/linux/ipq806x/patches-3.18/110-ATAG-mangled-bootargs.patch

@@ -0,0 +1,86 @@

+--- a/arch/arm/boot/compressed/atags_to_fdt.c

++++ b/arch/arm/boot/compressed/atags_to_fdt.c

+@@ -66,6 +66,55 @@ static uint32_t get_cell_size(const void

+     return cell_size;

+ }

+ 

++#if defined(CONFIG_MANGLE_BOOTARGS)

++

++static char *append_mangled_root(char *dest, char *str, int len)

++{

++    char *ptr, *end;

++    char *root="root=";

++    int i;

++    

++    //ARM doesn't have __HAVE_ARCH_STRSTR, so search manually

++    ptr=str-1;

++

++    do {

++          ptr++;

++          //first find an 'r' at the begining or after a space

++          do {

++                ptr=strchr(ptr, 'r');

++                if(!ptr) return dest;

++                

++          } while (ptr!=str && *(ptr-1)!=' ');

++    

++          //then check for the rest

++          for(i=1; i<=4;i++)

++                if(*(ptr+i)!=*(root+i)) break;

++

++    } while (i!=5);

++

++

++    end=strchr(ptr, ' ');

++    end= end ? (end-1) : (strchr(ptr, 0)-1);

++    

++    

++    //find partition number (assumes format root=/dev/mtdXX |
/dev/mtdblockXX | yy:XX)

++    for(i=0;end >= ptr && *end >='0' && *end <='9' ; end--, i++);

++    ptr=end+1;

++

++

++    //append mangled_root=XX

++    len=COMMAND_LINE_SIZE-len ;

++    if (len + 19 + i +1  < COMMAND_LINE_SIZE) {

++          memcpy(dest," mangled_rootblock=", 19);

++          dest+=19;

++          memcpy(dest, ptr, i);

++          dest+=i;

++    }

++

++    return dest;

++}

++#endif

++

+ static void merge_fdt_bootargs(void *fdt, const char *fdt_cmdline)

+ {

+     char cmdline[COMMAND_LINE_SIZE];

+@@ -85,16 +134,27 @@ static void merge_fdt_bootargs(void *fdt

+ 

+     /* and append the ATAG_CMDLINE */

+     if (fdt_cmdline) {

++    

++#if defined(CONFIG_MANGLE_BOOTARGS)

++

++          //save original bootloader args 

++          //and append mangled_root with root partition number to current
cmdline

++          setprop_string(fdt, "/chosen", "bootloader-args", fdt_cmdline);

++          ptr=append_mangled_root(ptr, fdt_cmdline, len);

++

++#else           

+           len = strlen(fdt_cmdline);

+           if (ptr - cmdline + len + 2 < COMMAND_LINE_SIZE) {

+                 *ptr++ = ' ';

+                 memcpy(ptr, fdt_cmdline, len);

+                 ptr += len;

+           }

++#endif 

+     }

+     *ptr = '\0';

+ 

+     setprop_string(fdt, "/chosen", "bootargs", cmdline);

++    

+ }

+ 

+ /*

diff --git a/target/linux/ipq806x/config-3.18
b/target/linux/ipq806x/config-3.18

index 40e3a75..908f7f1 100644

--- a/target/linux/ipq806x/config-3.18

+++ b/target/linux/ipq806x/config-3.18

@@ -36,7 +36,9 @@ CONFIG_ARM_AMBA=y

CONFIG_ARM_APPENDED_DTB=y

CONFIG_ARM_ARCH_TIMER=y

CONFIG_ARM_ARCH_TIMER_EVTSTREAM=y

-# CONFIG_ARM_ATAG_DTB_COMPAT is not set

+CONFIG_ARM_ATAG_DTB_COMPAT=y

+CONFIG_ARM_ATAG_DTB_COMPAT_CMDLINE_EXTEND=y

+# CONFIG_ARM_ATAG_DTB_COMPAT_CMDLINE_FROM_BOOTLOADER is not set

CONFIG_ARM_CPU_SUSPEND=y

CONFIG_ARM_GIC=y

CONFIG_ARM_HAS_SG_CHAIN=y

@@ -247,6 +249,7 @@ CONFIG_LIBFDT=y

CONFIG_LOCKUP_DETECTOR=y

CONFIG_LZO_COMPRESS=y

CONFIG_LZO_DECOMPRESS=y

+CONFIG_MANGLE_BOOTARGS=y

CONFIG_MDIO_BITBANG=y

CONFIG_MDIO_BOARDINFO=y

CONFIG_MDIO_GPIO=y

-- 

1.9.1

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.infradead.org/pipermail/openwrt-devel/attachments/20160331/67a1ba57/attachment.htm>
-------------- next part --------------
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel


More information about the openwrt-devel mailing list