506-MIPS-ath79-prom-parse-redboot-args.patch 2.0 KB

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