00001
00028 #include "wl_api.h"
00029 #include "fw_download.h"
00030 #include "nor_flash.h"
00031 #include "printf-stdarg.h"
00032
00033 int fw_download_init(void)
00034 {
00035 flash_init();
00036 return 0;
00037 }
00038
00039 void fw_download_cb(void* ctx, uint8_t** buf, uint32_t* len)
00040 {
00041
00042 static uint8_t* fw_buf = NULL;
00043 static uint32_t offset = 0;
00044
00045
00046
00047
00048
00049 if (*len == 0) {
00050 if (fw_buf)
00051 free(fw_buf);
00052 return;
00053 }
00054
00055
00056
00057
00058 if (fw_buf == NULL) {
00059 fw_buf = malloc(SECTOR_SIZE);
00060
00061 if (fw_buf == NULL) {
00062 printk("could not allocate firmware buffer\n");
00063 *len = 0;
00064 return;
00065 }
00066 }
00067
00068
00069
00070
00071 uint32_t fw_len = *len > SECTOR_SIZE ? SECTOR_SIZE : *len;
00072
00073
00074 flash_read(offset, fw_buf, fw_len);
00075 *buf = fw_buf;
00076 *len = fw_len;
00077
00078
00079 offset += fw_len;
00080 }
00081