ar71xx: improve support for the My Net Wi-Fi Range Extender device
[openwrt.git] / target / linux / ar71xx / patches-3.10 / 506-MIPS-ath79-prom-parse-redboot-args.patch
1 --- a/arch/mips/ath79/prom.c
2 +++ b/arch/mips/ath79/prom.c
3 @@ -19,6 +19,8 @@
4  
5  #include "common.h"
6  
7 +static char ath79_cmdline_buf[COMMAND_LINE_SIZE] __initdata;
8 +
9  static inline int is_valid_ram_addr(void *addr)
10  {
11         if (((u32) addr > KSEG0) &&
12 @@ -32,6 +34,41 @@ static inline int is_valid_ram_addr(void
13         return 0;
14  }
15  
16 +static void __init ath79_prom_append_cmdline(const char *name,
17 +                                             const char *value)
18 +{
19 +       snprintf(ath79_cmdline_buf, sizeof(ath79_cmdline_buf),
20 +                " %s=%s", name, value);
21 +       strlcat(arcs_cmdline, ath79_cmdline_buf, sizeof(arcs_cmdline));
22 +}
23 +
24 +static const char * __init ath79_prom_find_env(char **envp, const char *name)
25 +{
26 +       const char *ret = NULL;
27 +       int len;
28 +       char **p;
29 +
30 +       if (!is_valid_ram_addr(envp))
31 +               return NULL;
32 +
33 +       len = strlen(name);
34 +       for (p = envp; is_valid_ram_addr(*p); p++) {
35 +               if (strncmp(name, *p, len) == 0 && (*p)[len] == '=') {
36 +                       ret = *p + len + 1;
37 +                       break;
38 +               }
39 +
40 +               /* RedBoot env comes in pointer pairs - key, value */
41 +               if (strncmp(name, *p, len) == 0 && (*p)[len] == 0)
42 +                       if (is_valid_ram_addr(*(++p))) {
43 +                               ret = *p;
44 +                               break;
45 +                       }
46 +       }
47 +
48 +       return ret;
49 +}
50 +
51  static __init void ath79_prom_init_cmdline(int argc, char **argv)
52  {
53         int i;
54 @@ -48,7 +85,32 @@ static __init void ath79_prom_init_cmdli
55  
56  void __init prom_init(void)
57  {
58 +       const char *env;
59 +       char **envp;
60 +
61         ath79_prom_init_cmdline(fw_arg0, (char **)fw_arg1);
62 +
63 +       envp = (char **)fw_arg2;
64 +       if (!strstr(arcs_cmdline, "ethaddr=")) {
65 +               env = ath79_prom_find_env(envp, "ethaddr");
66 +               if (env)
67 +                       ath79_prom_append_cmdline("ethaddr", env);
68 +       }
69 +
70 +       if (!strstr(arcs_cmdline, "board=")) {
71 +               env = ath79_prom_find_env(envp, "board");
72 +               if (env) {
73 +                       /* Workaround for buggy bootloaders */
74 +                       if (strcmp(env, "RouterStation") == 0 ||
75 +                           strcmp(env, "Ubiquiti AR71xx-based board") == 0)
76 +                               env = "UBNT-RS";
77 +
78 +                       if (strcmp(env, "RouterStation PRO") == 0)
79 +                               env = "UBNT-RSPRO";
80 +
81 +                       ath79_prom_append_cmdline("board", env);
82 +               }
83 +       }
84  }
85  
86  void __init prom_free_prom_memory(void)