brcm47xx: add missing breaks into the nvram read code in the switch case statements
[openwrt.git] / target / linux / brcm47xx / patches-3.2 / 029-bcm47xx-read-nvram-from-sflash.patch
1 --- a/arch/mips/bcm47xx/nvram.c
2 +++ b/arch/mips/bcm47xx/nvram.c
3 @@ -20,11 +20,12 @@
4 #include <asm/addrspace.h>
5 #include <asm/mach-bcm47xx/nvram.h>
6 #include <asm/mach-bcm47xx/bcm47xx.h>
7 +#include <asm/mach-bcm47xx/bus.h>
8
9 static char nvram_buf[NVRAM_SPACE];
10
11 /* Probe for NVRAM header */
12 -static void early_nvram_init(void)
13 +static void early_nvram_init_pflash(void)
14 {
15 #ifdef CONFIG_BCM47XX_SSB
16 struct ssb_chipcommon *ssb_cc;
17 @@ -50,9 +51,6 @@ static void early_nvram_init(void)
18 #ifdef CONFIG_BCM47XX_BCMA
19 case BCM47XX_BUS_TYPE_BCMA:
20 bcma_cc = &bcm47xx_bus.bcma.bus.drv_cc;
21 - if (bcma_cc->flash_type != BCMA_PFLASH)
22 - return;
23 -
24 base = bcma_cc->pflash.window;
25 lim = bcma_cc->pflash.window_size;
26 break;
27 @@ -86,7 +84,110 @@ found:
28 for (i = 0; i < sizeof(struct nvram_header); i += 4)
29 *dst++ = *src++;
30 for (; i < header->len && i < NVRAM_SPACE; i += 4)
31 - *dst++ = le32_to_cpu(*src++);
32 + *dst++ = *src++;
33 +}
34 +
35 +static int early_nvram_init_sflash(void)
36 +{
37 + struct nvram_header header;
38 + u32 off;
39 + int ret;
40 + char *dst;
41 + int len;
42 +
43 + /* check if the struct is already initilized */
44 + if (!bcm47xx_sflash.size)
45 + return -1;
46 +
47 + off = FLASH_MIN;
48 + while (off <= bcm47xx_sflash.size) {
49 + ret = bcm47xx_sflash.read(&bcm47xx_sflash, off - NVRAM_SPACE, sizeof(header), (u8 *)&header);
50 + if (ret != sizeof(header))
51 + return ret;
52 + if (header.magic == NVRAM_HEADER)
53 + goto found;
54 + off <<= 1;
55 + }
56 +
57 + off = FLASH_MIN;
58 + while (off <= bcm47xx_sflash.size) {
59 + ret = bcm47xx_sflash.read(&bcm47xx_sflash, off - (2 * NVRAM_SPACE), sizeof(header), (u8 *)&header);
60 + if (ret != sizeof(header))
61 + return ret;
62 + if (header.magic == NVRAM_HEADER)
63 + goto found;
64 + off <<= 1;
65 + }
66 + return -1;
67 +
68 +found:
69 + len = NVRAM_SPACE;
70 + dst = nvram_buf;
71 + while (len) {
72 + ret = bcm47xx_sflash.read(&bcm47xx_sflash, off - (2 * NVRAM_SPACE), len, dst);
73 + if (ret < 0)
74 + return ret;
75 + off += ret;
76 + len -= ret;
77 + dst += ret;
78 + }
79 + return 0;
80 +}
81 +
82 +#ifdef CONFIG_BCM47XX_SSB
83 +static void early_nvram_init_ssb(void)
84 +{
85 + int err;
86 +
87 + switch (bcm47xx_bus.ssb.chipco.flash_type) {
88 + case SSB_PFLASH:
89 + early_nvram_init_pflash();
90 + break;
91 + case SSB_SFLASH:
92 + err = early_nvram_init_sflash();
93 + if (err < 0)
94 + printk(KERN_WARNING "can not read from flash: %i\n", err);
95 + break;
96 + default:
97 + printk(KERN_WARNING "unknow flash type\n");
98 + }
99 +}
100 +#endif
101 +
102 +#ifdef CONFIG_BCM47XX_BCMA
103 +static void early_nvram_init_bcma(void)
104 +{
105 + int err;
106 +
107 + switch (bcm47xx_bus.bcma.bus.drv_cc.flash_type) {
108 + case BCMA_PFLASH:
109 + early_nvram_init_pflash();
110 + break;
111 + case BCMA_SFLASH:
112 + err = early_nvram_init_sflash();
113 + if (err < 0)
114 + printk(KERN_WARNING "can not read from flash: %i\n", err);
115 + break;
116 + default:
117 + printk(KERN_WARNING "unknow flash type\n");
118 + }
119 +}
120 +#endif
121 +
122 +static void early_nvram_init(void)
123 +{
124 + switch (bcm47xx_bus_type) {
125 +#ifdef CONFIG_BCM47XX_SSB
126 + case BCM47XX_BUS_TYPE_SSB:
127 + early_nvram_init_ssb();
128 + break;
129 +#endif
130 +#ifdef CONFIG_BCM47XX_BCMA
131 + case BCM47XX_BUS_TYPE_BCMA:
132 + early_nvram_init_bcma();
133 + break;
134 +#endif
135 + }
136 }
137
138 int nvram_getenv(char *name, char *val, size_t val_len)
This page took 0.047334 seconds and 5 git commands to generate.