From de37fa0ce3f9f75634db3d747296f88c7c8acbc7 Mon Sep 17 00:00:00 2001 From: nbd Date: Tue, 17 Jul 2012 11:35:34 -0400 Subject: [PATCH 54/76] 506-MIPS-ath79-prom-parse-redboot-args Import of the above patch from openwrt trunk, as of this commit: ---------- commit c1d79f64eed0a7ac36b5b9bca52275b397bec424 Author: nbd Date: Mon Jul 16 16:26:51 2012 +0000 uboot-ar71xx: fix compile on recent mac os x versions git-svn-id: svn://svn.openwrt.org/openwrt/trunk@32750 3c298f89-4303-0410-b956-a3cf2f4a3e73 ---------- Path to patch in the repo is: target/linux/ar71xx/patches-3.3 Repo is: git://nbd.name/openwrt.git Signed-off-by: Paul Gortmaker --- arch/mips/ath79/prom.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/arch/mips/ath79/prom.c b/arch/mips/ath79/prom.c index e9cbd7c..2bc1801 100644 --- a/arch/mips/ath79/prom.c +++ b/arch/mips/ath79/prom.c @@ -19,6 +19,8 @@ #include "common.h" +static char ath79_cmdline_buf[COMMAND_LINE_SIZE] __initdata; + static inline int is_valid_ram_addr(void *addr) { if (((u32) addr > KSEG0) && @@ -32,6 +34,41 @@ static inline int is_valid_ram_addr(void *addr) return 0; } +static void __init ath79_prom_append_cmdline(const char *name, + const char *value) +{ + snprintf(ath79_cmdline_buf, sizeof(ath79_cmdline_buf), + " %s=%s", name, value); + strlcat(arcs_cmdline, ath79_cmdline_buf, sizeof(arcs_cmdline)); +} + +static const char * __init ath79_prom_find_env(char **envp, const char *name) +{ + const char *ret = NULL; + int len; + char **p; + + if (!is_valid_ram_addr(envp)) + return NULL; + + len = strlen(name); + for (p = envp; is_valid_ram_addr(*p); p++) { + if (strncmp(name, *p, len) == 0 && (*p)[len] == '=') { + ret = *p + len + 1; + break; + } + + /* RedBoot env comes in pointer pairs - key, value */ + if (strncmp(name, *p, len) == 0 && (*p)[len] == 0) + if (is_valid_ram_addr(*(++p))) { + ret = *p; + break; + } + } + + return ret; +} + static __init void ath79_prom_init_cmdline(int argc, char **argv) { int i; @@ -48,7 +85,32 @@ static __init void ath79_prom_init_cmdline(int argc, char **argv) void __init prom_init(void) { + const char *env; + char **envp; + ath79_prom_init_cmdline(fw_arg0, (char **)fw_arg1); + + envp = (char **)fw_arg2; + if (!strstr(arcs_cmdline, "ethaddr=")) { + env = ath79_prom_find_env(envp, "ethaddr"); + if (env) + ath79_prom_append_cmdline("ethaddr", env); + } + + if (!strstr(arcs_cmdline, "board=")) { + env = ath79_prom_find_env(envp, "board"); + if (env) { + /* Workaround for buggy bootloaders */ + if (strcmp(env, "RouterStation") == 0 || + strcmp(env, "Ubiquiti AR71xx-based board") == 0) + env = "UBNT-RS"; + + if (strcmp(env, "RouterStation PRO") == 0) + env = "UBNT-RSPRO"; + + ath79_prom_append_cmdline("board", env); + } + } } void __init prom_free_prom_memory(void) -- 1.7.10.4