| 95 | | static void pagesetup(void) |
|---|
| 96 | | { |
|---|
| | 95 | struct firmware_formats { |
|---|
| | 96 | char *name; |
|---|
| | 97 | int (*fw_check_image) (unsigned char *, unsigned long, int); |
|---|
| | 98 | }; |
|---|
| | 99 | |
|---|
| | 100 | static const struct firmware_formats fw_formats[] = { |
|---|
| | 101 | {.name = "DD-WRT",.fw_check_image = fw_check_image_ddwrt}, |
|---|
| | 102 | {.name = "UBIQUITI",.fw_check_image = fw_check_image_ubnt}, |
|---|
| | 103 | {.name = "WILIGEAR",.fw_check_image = fw_check_image_wili}, |
|---|
| | 104 | {.name = "SENAO",.fw_check_image = fw_check_image_senao}, |
|---|
| | 105 | }; |
|---|
| | 106 | |
|---|
| | 107 | static void do_flash_update(unsigned long base_addr, unsigned long len, |
|---|
| | 108 | int index) |
|---|
| | 109 | { |
|---|
| | 110 | int rc; |
|---|
| 128 | | |
|---|
| 129 | | } |
|---|
| 130 | | |
|---|
| 131 | | void do_flash_update_ddwrt(unsigned long base_addr, unsigned long len) |
|---|
| 132 | | { |
|---|
| 133 | | int rc; |
|---|
| 134 | | pagesetup(); |
|---|
| 135 | | /* do_flash = 1, write to flash */ |
|---|
| 136 | | rc = fw_check_image_ddwrt((char *)base_addr, len, 1); |
|---|
| 137 | | memset((unsigned char *)base_addr, 0, len); |
|---|
| 138 | | flashresult(rc); |
|---|
| 139 | | } |
|---|
| 140 | | |
|---|
| 141 | | void do_flash_update_ubnt(unsigned long base_addr, unsigned long len) |
|---|
| 142 | | { |
|---|
| 143 | | int rc; |
|---|
| 144 | | pagesetup(); |
|---|
| 145 | | /* do_flash = 1, write to flash */ |
|---|
| 146 | | rc = fw_check_image_ubnt((char *)base_addr, len, 1); |
|---|
| 147 | | |
|---|
| 148 | | memset((unsigned char *)base_addr, 0, len); |
|---|
| 149 | | flashresult(rc); |
|---|
| 150 | | } |
|---|
| 151 | | |
|---|
| 152 | | void do_flash_update_wili(unsigned long base_addr, unsigned long len) |
|---|
| 153 | | { |
|---|
| 154 | | int rc; |
|---|
| 155 | | pagesetup(); |
|---|
| 156 | | /* do_flash = 1, write to flash */ |
|---|
| 157 | | rc = fw_check_image_wili((char *)base_addr, len, 1); |
|---|
| 158 | | |
|---|
| 159 | | memset((unsigned char *)base_addr, 0, len); |
|---|
| 160 | | flashresult(rc); |
|---|
| 161 | | } |
|---|
| 162 | | |
|---|
| 163 | | void do_flash_update_senao(unsigned long base_addr, unsigned long len) |
|---|
| 164 | | { |
|---|
| 165 | | int rc; |
|---|
| 166 | | pagesetup(); |
|---|
| 167 | | /* do_flash = 1, write to flash */ |
|---|
| 168 | | rc = fw_check_image_senao((char *)base_addr, len, 1); |
|---|
| 169 | | |
|---|
| 170 | | memset((unsigned char *)base_addr, 0, len); |
|---|
| 171 | | flashresult(rc); |
|---|
| 267 | | int isddwrt = 0; |
|---|
| 268 | | int isubnt = 0; |
|---|
| 269 | | int iswili = 0; |
|---|
| 270 | | int issenao = 0; |
|---|
| 271 | | isddwrt = fw_check_image_ddwrt((char *)BASE_ADDR, |
|---|
| 272 | | ptr - BASE_ADDR, 0) == 0; |
|---|
| 273 | | if (!isddwrt) |
|---|
| 274 | | isubnt = |
|---|
| 275 | | fw_check_image_ubnt((char *)BASE_ADDR, |
|---|
| 276 | | ptr - BASE_ADDR, |
|---|
| 277 | | 0) == 0; |
|---|
| 278 | | |
|---|
| 279 | | if (!isubnt && !isddwrt) |
|---|
| 280 | | iswili = |
|---|
| 281 | | fw_check_image_wili((char *)BASE_ADDR, |
|---|
| 282 | | ptr - BASE_ADDR, |
|---|
| 283 | | 0) == 0; |
|---|
| 284 | | |
|---|
| 285 | | if (!isubnt && !isddwrt && !iswili) |
|---|
| 286 | | issenao = |
|---|
| 287 | | fw_check_image_senao((char *)BASE_ADDR, |
|---|
| 288 | | ptr - BASE_ADDR, |
|---|
| 289 | | 0) == 0; |
|---|
| 290 | | |
|---|
| 291 | | if (isddwrt || isubnt || iswili || issenao) /* third parameter 0 - do not write to flash */ |
|---|
| | 235 | int detect = 0; |
|---|
| | 236 | int i; |
|---|
| | 237 | for (i = 0; |
|---|
| | 238 | i < |
|---|
| | 239 | sizeof(fw_formats) / |
|---|
| | 240 | sizeof(struct firmware_formats); i++) { |
|---|
| | 241 | int v = |
|---|
| | 242 | fw_formats[i]. |
|---|
| | 243 | fw_check_image((char *)BASE_ADDR, |
|---|
| | 244 | ptr - BASE_ADDR, 0) == 0; |
|---|
| | 245 | if (v) { |
|---|
| | 246 | detect = i; |
|---|
| | 247 | break; |
|---|
| | 248 | } |
|---|
| | 249 | } |
|---|
| | 250 | |
|---|
| | 251 | if (detect) /* third parameter 0 - do not write to flash */ |
|---|
| 301 | | if (isddwrt) { |
|---|
| 302 | | diag_printf |
|---|
| 303 | | ("DD-WRT firmware format detected\n"); |
|---|
| 304 | | do_flash_update_ddwrt(BASE_ADDR, |
|---|
| 305 | | ptr - BASE_ADDR); |
|---|
| 306 | | } |
|---|
| 307 | | if (isubnt) { |
|---|
| 308 | | diag_printf("UBNT firmware format detected\n"); |
|---|
| 309 | | do_flash_update_ubnt(BASE_ADDR, |
|---|
| 310 | | ptr - BASE_ADDR); |
|---|
| 311 | | } |
|---|
| 312 | | if (iswili) { |
|---|
| 313 | | diag_printf |
|---|
| 314 | | ("WILIGEAR firmware format detected\n"); |
|---|
| 315 | | do_flash_update_wili(BASE_ADDR, |
|---|
| 316 | | ptr - BASE_ADDR); |
|---|
| 317 | | } |
|---|
| 318 | | if (issenao) { |
|---|
| 319 | | diag_printf("SENAO firmware format detected\n"); |
|---|
| 320 | | do_flash_update_senao(BASE_ADDR, |
|---|
| 321 | | ptr - BASE_ADDR); |
|---|
| 322 | | } |
|---|
| | 261 | diag_printf("%s: firmware format detected\n", |
|---|
| | 262 | fw_formats[detect].name); |
|---|
| | 263 | do_flash_update(BASE_ADDR, ptr - BASE_ADDR, detect); |
|---|