Changeset 222

Show
Ignore:
Timestamp:
02/15/10 17:12:03 (2 years ago)
Author:
marek
Message:

ap51-flash: add flash from file mode

Location:
ap51-flash/trunk
Files:
7 modified

Legend:

Unmodified
Added
Removed
  • ap51-flash/trunk/Makefile

    r221 r222  
    3232# enable packet debug output 
    3333# CFLAGS += -DPACKET_DEBUG 
     34# enable flash from file mode 
     35# CFLAGS += -DFLASH_FROM_FILE 
    3436 
    3537# if you change the names here you also need to change the ap51-flash.c code 
  • ap51-flash/trunk/ap51-flash.c

    r221 r222  
    4040 
    4141char flash_mode = MODE_NONE; 
     42int flash_from_file = 0; 
     43struct flash_from_file fff_data[FFF_NUM]; 
    4244unsigned int remote_ip; 
    4345unsigned int local_ip; 
     
    9496        /* Open the output adapter */ 
    9597        if (NULL == (pcap_fp = pcap_open_live(dev, 1500, 1, PCAP_TIMEOUT_MS, error))) { 
    96                 fprintf(stderr,"Error opening adapter: %s\n", error); 
     98                fprintf(stderr, "Error opening adapter: %s\n", error); 
    9799                return -1; 
    98100        } 
     
    378380                        unsigned long int x = 0; 
    379381                        sscanf(str_ptr, "Erase from 0x%08lx", &x); 
    380                         if (0 != x) 
    381                         { 
     382                        if (0 != x) { 
    382383                                x -= device_info->flash_addr; 
    383                                 if (x > device_info->flash_size) 
    384                                 { 
     384                                if (x > device_info->flash_size) { 
    385385                                        rootfs_part_size += (x - device_info->flash_size); 
    386386                                        printf("Rootfs partition size now 0x%08x\n", rootfs_part_size); 
     
    426426                        goto err_close; 
    427427                } 
    428                 if (tftp_bytes_sent < (unsigned long)kernel_size) 
    429                 { 
     428                if (tftp_bytes_sent < (unsigned long)kernel_size) { 
    430429                        fprintf(stderr, "Error transferring kernel, send=%ld, expected=%d\n", tftp_bytes_sent, kernel_size); 
    431430                        exit(1); 
     
    477476                s->inputbuffer[0] = 0; 
    478477                PSOCK_READTO(475, &s->p, '>'); 
    479                 if (!uncomp_loader) 
    480                 { 
    481                         sprintf(str, "fis load %s %s\n", (0x1f == kernel_buf[0] && 0x8b ==kernel_buf[1] ? "-d" : "-l"), kernelpartname); 
    482                 } 
    483                 else 
    484                 { 
    485                         sprintf(str, "fis load %s\n", kernelpartname); 
    486                 } 
     478 
     479                if (flash_from_file) { 
     480                        if (!uncomp_loader) 
     481                                sprintf(str, "fis load %s %s\n", 
     482                                        (0x1f == fff_data[FFF_KERNEL].buff[0] && 0x8b ==fff_data[FFF_KERNEL].buff[1] ? "-d" : "-l"), 
     483                                        kernelpartname); 
     484                        else 
     485                                sprintf(str, "fis load %s\n", kernelpartname); 
     486                } else { 
     487                        if (!uncomp_loader) 
     488                                sprintf(str, "fis load %s %s\n", 
     489                                        (0x1f == kernel_buf[0] && 0x8b ==kernel_buf[1] ? "-d" : "-l"), 
     490                                        kernelpartname); 
     491                        else 
     492                                sprintf(str, "fis load %s\n", kernelpartname); 
     493                } 
     494 
    487495                PSOCK_SEND_STR(477, &s->p, str); 
    488496                s->inputbuffer[0] = 0; 
     
    591599} 
    592600 
    593 int ap51_flash(char* device, char* rootfs_filename, char* kernel_filename, int nvram, int uncomp, int special) 
     601static int open_image_file(char *fname, int *fd, int *file_size, int *flash_size, unsigned char **buff) 
     602{ 
     603        char err_string[265]; 
     604 
     605        *fd = open(fname, O_RDONLY | O_BINARY); 
     606        if (*fd < 0) { 
     607                perror(fname); 
     608                goto err; 
     609        } 
     610 
     611        *file_size = lseek(*fd, 0, SEEK_END); 
     612        if (*file_size < 0) { 
     613                fprintf(stderr, "Unable to retrieve file size: %s\n", fname); 
     614                goto err_close; 
     615        } 
     616 
     617        *flash_size = ((*file_size + FLASH_PAGE_SIZE - 1) / FLASH_PAGE_SIZE) * FLASH_PAGE_SIZE; 
     618        if (*flash_size >= 8 * 1024 * 1024) { 
     619                fprintf(stderr, "File size exceeds 8MB limit: %s\n", fname); 
     620                goto err_close; 
     621        } 
     622 
     623        lseek(*fd, 0, SEEK_SET); 
     624 
     625        if (!buff) /* FLASH_FROM_FILE */ 
     626                return 0; 
     627 
     628        *buff = malloc(*flash_size); 
     629        if (!*buff) { 
     630                perror("no mem"); 
     631                goto err_close; 
     632        } 
     633 
     634        if (*file_size != read(*fd, *buff, *file_size)) { 
     635                sprintf(err_string, "%s read fails: buf=%p, size=%d", fname, *buff, *file_size); 
     636                perror(err_string); 
     637                goto err_free; 
     638        } 
     639 
     640        close(*fd); 
     641        return 1; 
     642 
     643err_free: 
     644        free(*buff); 
     645err_close: 
     646        close(*fd); 
     647err: 
     648        return -1; 
     649} 
     650 
     651int ap51_flash(char *device, char *rootfs_filename, char *kernel_filename, int nvram, int uncomp, int special) 
    594652{ 
    595653        uip_ipaddr_t netmask; 
     
    597655        pcap_if_t *alldevs = NULL, *d; 
    598656        char *pcap_device, errbuf[PCAP_ERRBUF_SIZE]; 
    599         unsigned char* buf = 0; 
    600         int i = 0, if_num = 0; 
    601         int fd, size = 0, ubnt_img = 0; 
     657        int ret, i, if_num = 0, ubnt_img = 0; 
     658        unsigned char *buf = 0; 
     659        int fd, size = 0; 
    602660 
    603661        pcap_device = device; 
     
    614672                nvram_part_size = FLASH_PAGE_SIZE; 
    615673 
    616         /* Root file name? */ 
    617         if (NULL != rootfs_filename) { 
    618                 if (-1 == (fd = open(rootfs_filename, O_RDONLY | O_BINARY))) { 
    619                         perror(rootfs_filename); 
     674#if defined(FLASH_FROM_FILE) 
     675        if (flash_from_file) { 
     676                for (i = 0; i < FFF_NUM; i++) { 
     677                        if (!fff_data[i].fname) 
     678                                continue; 
     679 
     680                        ret = open_image_file(fff_data[i].fname, &fff_data[i].fd, 
     681                                              &fff_data[i].file_size, &fff_data[i].flash_size, NULL); 
     682 
     683                        if (ret < 0) 
     684                                return 1; 
     685 
     686                        printf("Reading %s file %s with %d bytes ...\n", 
     687                               (i == 0 ? "rootfs" : (i == 1 ? "kernel" : "ubnt")), 
     688                               fff_data[i].fname, fff_data[i].flash_size); 
     689                } 
     690 
     691                goto init_pcap; 
     692        } 
     693#endif 
     694 
     695        if (rootfs_filename) { 
     696                ret = open_image_file(rootfs_filename, &fd, 
     697                                      &size, &rootfs_size, &rootfs_buf); 
     698 
     699                if (ret < 0) 
    620700                        return 1; 
    621                 } 
    622                 size = lseek(fd, 0, SEEK_END); 
    623                 rootfs_size = ((size + FLASH_PAGE_SIZE - 1) / FLASH_PAGE_SIZE) * FLASH_PAGE_SIZE; 
    624                 lseek(fd, 0, SEEK_SET); 
    625                 if (0 != (rootfs_buf = malloc(rootfs_size))) 
    626                 { 
    627                         if (size != read(fd, rootfs_buf, size) || 
    628                                 0 >= size || 8 * 1024 * 1024 < size) 
    629                         { 
    630                                 char s[265]; 
    631                                 sprintf(s, "%s fails: buf=%p, size=%d", rootfs_filename, rootfs_buf, size); 
    632                                 perror(s); 
    633                                 return 1; 
    634                         } 
    635                 } 
    636                 else 
    637                 { 
    638                         perror("no mem"); 
    639                         return 1; 
    640                 } 
    641                 printf("Reading rootfs file %s with %d bytes ...\n", rootfs_filename, size); 
     701 
     702                printf("Reading rootfs file %s with %d bytes ...\n", 
     703                       rootfs_filename, rootfs_size); 
     704 
    642705        } else { 
    643706#if defined(EMBEDDED_DATA) && defined(WIN32) 
    644707                HRSRC hRsrc; 
    645708                hRsrc = FindResource(NULL, MAKEINTRESOURCE(IDR_ROOTFS), RT_RCDATA); 
    646                 if (NULL != hRsrc) 
    647                 { 
     709                if (hRsrc) { 
    648710                        HGLOBAL hGlobal = LoadResource(NULL, hRsrc); 
    649711                        buf = LockResource(hGlobal); 
     
    655717#endif 
    656718 
    657                 if (0 != buf) 
    658                 { 
     719                if (buf) { 
    659720                        rootfs_size = ((size + FLASH_PAGE_SIZE - 1) / FLASH_PAGE_SIZE) * FLASH_PAGE_SIZE; 
    660                         if (0 != (rootfs_buf = malloc(rootfs_size))) 
    661                         { 
     721                        if (0 != (rootfs_buf = malloc(rootfs_size))) { 
    662722                                memset(rootfs_buf, 0xff, rootfs_size); 
    663723                                memmove(rootfs_buf, buf, size); 
    664                         } 
    665                         else 
    666                         { 
     724                        } else { 
    667725                                perror("no mem"); 
    668726                                return 1; 
     
    671729        } 
    672730 
    673         /* Kernel file name? */ 
    674         if (NULL != kernel_filename) 
    675         { 
    676                 if (-1 == (fd = open(kernel_filename, O_RDONLY | O_BINARY))) 
    677                 { 
    678                         perror(kernel_filename); 
     731        if (kernel_filename) { 
     732                ret = open_image_file(kernel_filename, &fd, 
     733                                      &size, &kernel_size, &kernel_buf); 
     734 
     735                if (ret < 0) 
    679736                        return 1; 
    680                 } 
    681                 size = lseek(fd, 0, SEEK_END); 
    682                 kernel_size = ((size + FLASH_PAGE_SIZE - 1) / FLASH_PAGE_SIZE) * FLASH_PAGE_SIZE; 
    683                 lseek(fd, 0, SEEK_SET); 
    684                 if (0 != (kernel_buf = malloc(kernel_size))) 
    685                 { 
    686                         if (size != read(fd, kernel_buf, size) || 
    687                                 0 >= size || 8 * 1024 * 1024 < size) 
    688                         { 
    689                                 char s[265]; 
    690                                 sprintf(s, "%s fails: buf=%p, size=%d", kernel_filename, kernel_buf, size); 
    691                                 perror(s); 
    692                                 return 1; 
    693                         } 
    694                 } 
    695                 else 
    696                 { 
    697                         perror("no mem"); 
    698                         return 1; 
    699                 } 
    700                 printf("Reading kernel file %s with %d bytes ...\n", kernel_filename, size); 
     737 
     738                printf("Reading kernel file %s with %d bytes ...\n", 
     739                       kernel_filename, kernel_size); 
    701740        } else { 
    702741#if defined(EMBEDDED_DATA) && defined(WIN32) 
    703742                HRSRC hRsrc = FindResource(NULL, MAKEINTRESOURCE(IDR_KERNEL), RT_RCDATA); 
    704                 if (NULL != hRsrc) 
    705                 { 
     743                if (hRsrc) { 
    706744                        HGLOBAL hGlobal = LoadResource(NULL, hRsrc); 
    707745                        buf = LockResource(hGlobal); 
     
    713751#endif 
    714752 
    715                 if (0 != buf) 
    716                 { 
     753                if (buf) { 
    717754                        kernel_size = ((size + FLASH_PAGE_SIZE - 1) / FLASH_PAGE_SIZE) * FLASH_PAGE_SIZE; 
    718                         if (0 != (kernel_buf = malloc(kernel_size))) 
    719                         { 
     755                        if (0 != (kernel_buf = malloc(kernel_size))) { 
    720756                                memset(kernel_buf, 0xff, kernel_size); 
    721757                                memmove(kernel_buf, buf, size); 
    722                         } 
    723                         else 
    724                         { 
     758                        } else { 
    725759                                perror("no mem"); 
    726760                                return 1; 
     
    743777                return 1; 
    744778        } 
     779 
     780#if defined(FLASH_FROM_FILE) 
     781init_pcap: 
     782#endif 
    745783 
    746784        srcmac.addr[0] = 0x00; 
     
    765803 
    766804        /* Print the list */ 
     805        i = 0; 
    767806        for (d = alldevs; d != NULL; d = d->next) { 
    768807                i++; 
     
    798837        switch (flash_mode) { 
    799838        case MODE_REDBOOT: 
    800                 if (ubnt_img) { 
    801                         fprintf(stderr, "You are trying to flash a redboot device with a ubiquiti image!\n"); 
    802                         return 1; 
     839                if (flash_from_file) { 
     840                        if ((!fff_data[FFF_ROOTFS].fname) || 
     841                            (!fff_data[FFF_KERNEL].fname)) { 
     842                                fprintf(stderr, "Error - redboot enabled device detected but rootfs & kernel file not available\n"); 
     843                                return 1; 
     844                        } 
     845                } else { 
     846                        if (ubnt_img) { 
     847                                fprintf(stderr, "Error - you are trying to flash a redboot device with a ubiquiti image!\n"); 
     848                                return 1; 
     849                        } 
    803850                } 
    804851 
     
    808855 
    809856                if (NULL == uip_connect(&dstipaddr, htons(TELNET_PORT))) { 
    810                         fprintf(stderr, "Cannot connect to port %i\n", TELNET_PORT); 
     857                        fprintf(stderr, "Error - cannot connect to port %i\n", TELNET_PORT); 
    811858                        return 1; 
    812859                } 
     
    814861        case MODE_TFTP_CLIENT: 
    815862#if defined(EMBEDDED_DATA) 
    816                 if (!rootfs_filename) { 
     863                if ((!rootfs_filename) && (!flash_from_file)) { 
    817864 
    818865                        /* free the rootfs and replace it by the ubnt image */ 
     
    845892                        ubnt_img = 1; 
    846893                } 
    847 #endif 
    848                 if (!ubnt_img) { 
    849                         fprintf(stderr, "You are trying to flash a ubiquiti device with redboot images!\n"); 
    850                         return 1; 
    851                 } 
    852  
    853                 tftp_xfer_buff = rootfs_buf; 
    854                 tftp_xfer_size = rootfs_size; 
     894#endif /* EMBEDDED_DATA */ 
     895                if (flash_from_file) { 
     896                        if (!fff_data[FFF_UBNT].fname) { 
     897                                fprintf(stderr, "Error - ubiquiti device detected but ubiquiti file not available\n"); 
     898                                return 1; 
     899                        } 
     900                } else { 
     901                        if (!ubnt_img) { 
     902                                fprintf(stderr, "Error - you are trying to flash a ubiquiti device with redboot images!\n"); 
     903                                return 1; 
     904                        } 
     905                } 
     906 
     907                tftp_xfer_buff = (flash_from_file ? (unsigned char *)&fff_data[FFF_UBNT] : rootfs_buf); 
     908                tftp_xfer_size = (flash_from_file ? fff_data[FFF_UBNT].flash_size : rootfs_size); 
    855909                printf("Ubiquiti device detected - using TFTP client to flash\n"); 
    856910                break; 
    857911        default: 
    858                 fprintf(stderr, "Could not auto-detect flash mode!\n"); 
     912                fprintf(stderr, "Error - could not auto-detect flash mode!\n"); 
    859913                return 1; 
    860914        } 
    861915 
    862         fw_upload(); 
    863         return 0; 
     916        return fw_upload(); 
    864917} 
    865918 
  • ap51-flash/trunk/ap51-flash.h

    r221 r222  
    7171}; 
    7272 
     73struct flash_from_file { 
     74        int fd; 
     75        int file_size; 
     76        int flash_size; 
     77        char *fname; 
     78        char buff[2]; 
     79}; 
     80 
    7381/* flash modes */ 
    7482enum { 
     
    7785        MODE_MAYBE_REDBOOT, 
    7886        MODE_TFTP_CLIENT, 
     87}; 
     88 
     89/* flash from file data */ 
     90enum { 
     91        FFF_ROOTFS = 0, 
     92        FFF_KERNEL, 
     93        FFF_UBNT, 
     94        FFF_NUM, 
    7995}; 
    8096 
     
    119135extern int kernel_size; 
    120136extern char flash_mode; 
     137extern int flash_from_file; 
     138extern struct flash_from_file fff_data[]; 
    121139 
    122140#endif /* __ap51_FLASH_H__ */ 
  • ap51-flash/trunk/main.c

    r202 r222  
    2020#include <stdlib.h> 
    2121#include <string.h> 
     22#if defined(FLASH_FROM_FILE) 
     23#include <getopt.h> 
     24#endif 
    2225 
    2326#include "ap51-flash.h" 
     
    3942        fprintf(stderr, "%s [ethdevice] ubnt.bin   flashes your ubiquiti image\n", prgname); 
    4043        fprintf(stderr, "%s -v   prints version information\n", prgname); 
     44 
     45#if defined(FLASH_FROM_FILE) 
     46        fprintf(stderr, "\nFlash from file mode:\n"); 
     47        fprintf(stderr, "%s --flash-from-file [file options] interface\n", prgname); 
     48        fprintf(stderr, "Options:\n"); 
     49        fprintf(stderr, "  --flash-from-file   enable 'flash from file' mode\n"); 
     50        fprintf(stderr, "  --rootfs   path to rootfs file\n"); 
     51        fprintf(stderr, "  --kernel   path to kernel file\n"); 
     52        fprintf(stderr, "  --ubnt   path to ubiquiti image\n"); 
     53#endif 
    4154 
    4255        fprintf(stderr, "\nThe 'ethdevice' has to be one of the devices that are part of the supported device list which follows.\nYou can either specify its name or the interface number.\n"); 
     
    7285int main(int argc, char* argv[]) 
    7386{ 
    74         int nvram = 0; 
    75         int uncomp = 0; 
    76         int special = 0; 
     87        int nvram = 0, uncomp = 0, special = 0; 
     88        char *iface = NULL; 
     89 
     90#if defined(FLASH_FROM_FILE) 
     91        int i, found_args = 1, optchar, option_index; 
     92        struct option long_options[] = 
     93        { 
     94                {"flash-from-file", no_argument, 0, 'f'}, 
     95                {"rootfs", required_argument, 0, 'r'}, 
     96                {"kernel", required_argument, 0, 'k'}, 
     97                {"ubnt", required_argument, 0, 'u'}, 
     98                {0, 0, 0, 0} 
     99        }; 
     100#endif 
    77101 
    78102        if ((argc == 2) && (strcmp("-v", argv[1]) == 0)) { 
     
    99123                special = 1; 
    100124        } 
    101 // #if defined(DEBUG) 
    102 //      special = 1; 
    103 // #endif 
    104125 
    105 /*      if (argc > 2 && 0 == strcmp("uncomp", argv[argc - 1])) 
    106         { 
     126        /*if (argc > 2 && strcmp("uncomp", argv[argc - 1]) == 0) { 
    107127                argc--; 
    108128                uncomp = 1; 
    109129        } 
    110130 
    111         if (argc > 1 && 0 == strcmp("nvram", argv[argc - 1])) 
    112         { 
     131        if (argc > 1 && strcmp("nvram", argv[argc - 1]) == 0) { 
    113132                argc--; 
    114133                nvram = 1; 
    115134        }*/ 
    116135 
    117         if (argc < 2) 
    118         { 
     136        if (argc < 2) { 
    119137                usage(argv[0]); 
    120138                return 1; 
    121139        } 
    122140 
    123         return ap51_flash(argv[1], 2 < argc ? argv[2] : NULL, 3 < argc ? argv[3] : NULL, nvram, uncomp, special); 
     141        iface = argv[1]; 
     142 
     143#if defined(FLASH_FROM_FILE) 
     144        for (i = 0; i < FFF_NUM; i++) 
     145                fff_data[i].fname = NULL; 
     146 
     147        while ((optchar = getopt_long(argc, argv, "fk:r:u:", long_options, &option_index)) != -1) { 
     148                switch (optchar) { 
     149                case 'f': 
     150                        flash_from_file = 1; 
     151                        found_args++; 
     152                        break; 
     153                case 'k': 
     154                        fff_data[FFF_KERNEL].fname = optarg; 
     155                        found_args += 2; 
     156                        break; 
     157                case 'r': 
     158                        fff_data[FFF_ROOTFS].fname = optarg; 
     159                        found_args += 2; 
     160                        break; 
     161                case 'u': 
     162                        fff_data[FFF_UBNT].fname = optarg; 
     163                        found_args += 2; 
     164                        break; 
     165                default: 
     166                        usage(argv[0]); 
     167                        return 1; 
     168                } 
     169        } 
     170 
     171        if (flash_from_file) { 
     172                if ((fff_data[FFF_ROOTFS].fname && !fff_data[FFF_KERNEL].fname) || 
     173                    (!fff_data[FFF_ROOTFS].fname && fff_data[FFF_KERNEL].fname)) { 
     174                        fprintf(stderr, "Error - you need to specify kernel and rootfs together or not at all\n"); 
     175                        return 1; 
     176                } 
     177 
     178                if (!fff_data[FFF_ROOTFS].fname && !fff_data[FFF_KERNEL].fname && !fff_data[FFF_UBNT].fname) { 
     179                        fprintf(stderr, "Error - you need to specify at least kernel and rootfs or ubiquiti image file\n"); 
     180                        return 1; 
     181                } 
     182 
     183                if (found_args == argc) { 
     184                        fprintf(stderr, "Error - you need to specify the interface to run 'flash from file' mode\n"); 
     185                        return 1; 
     186                } else if (found_args + 1 < argc) { 
     187                        fprintf(stderr, "Error - too many arguments to run flash from file mode\n"); 
     188                        return 1; 
     189                } 
     190 
     191                iface = argv[found_args]; 
     192        } 
     193#endif 
     194 
     195        return ap51_flash(iface, (argc > 2 ? argv[2] : NULL), (argc > 3 ? argv[3] : NULL), nvram, uncomp, special); 
    124196} 
  • ap51-flash/trunk/packet.c

    r202 r222  
    123123} 
    124124 
     125static void read_from_file(void *target_buff, void *data, int len, int seek_pos) 
     126{ 
     127        struct flash_from_file *fff = (struct flash_from_file *)data; 
     128        int read_len = len; 
     129 
     130        if (fff->file_size < seek_pos) 
     131                read_len = 0; 
     132        else if (fff->file_size < seek_pos + len) 
     133                read_len = fff->file_size - seek_pos; 
     134 
     135        if (read_len > 0) { 
     136                if (read_len != read(fff->fd, target_buff, read_len)) { 
     137                        perror(fff->fname); 
     138                        exit(1); 
     139                } 
     140        } 
     141 
     142        if (read_len != len) 
     143                memset(target_buff + read_len, 0, len - read_len); 
     144 
     145        if (seek_pos == 0) 
     146                memcpy(fff->buff, target_buff, 2); 
     147} 
     148 
    125149static void tftp_transfer(const unsigned char *packet_buff, unsigned int packet_len) 
    126150{ 
     
    146170                file_name = ((char *)rcv_udphdr) + sizeof(struct udphdr) + 2; 
    147171                if (strcmp(file_name, "kernel") == 0) { 
    148                         tftp_xfer_buff = kernel_buf; 
    149                         tftp_xfer_size = kernel_size; 
     172                        tftp_xfer_buff = (flash_from_file ? (unsigned char *)&fff_data[FFF_KERNEL] : kernel_buf); 
     173                        tftp_xfer_size = (flash_from_file ? fff_data[FFF_KERNEL].flash_size : kernel_size); 
    150174                        printf("Sending kernel, %ld blocks...\n", 
    151175                               ((tftp_xfer_size + 511) / 512)); 
    152176                } else if (strcmp(file_name, "rootfs") == 0) { 
    153                         tftp_xfer_buff = rootfs_buf; 
    154                         tftp_xfer_size = rootfs_size; 
     177                        tftp_xfer_buff = (flash_from_file ? (unsigned char *)&fff_data[FFF_ROOTFS] : rootfs_buf); 
     178                        tftp_xfer_size = (flash_from_file ? fff_data[FFF_ROOTFS].flash_size : rootfs_size); 
    155179                        printf("Sending rootfs, %ld blocks...\n", 
    156180                               ((tftp_xfer_size + 511) / 512)); 
     
    200224                *((unsigned short *)(tftp_data + 2)) = htons(block); 
    201225 
    202                 if (tftp_xfer_size - tftp_bytes_sent >= 512) { 
    203                         memcpy(tftp_data + 4, (void *)(tftp_xfer_buff + tftp_bytes_sent), 512); 
    204                         tftp_data_len = 512; 
    205                 } else { 
    206                         memcpy(tftp_data + 4, (void *)(tftp_xfer_buff + tftp_bytes_sent), tftp_xfer_size - tftp_bytes_sent); 
    207                         tftp_data_len = tftp_xfer_size - tftp_bytes_sent; 
    208                 } 
     226                tftp_data_len = tftp_xfer_size - tftp_bytes_sent > 512 ? 512 : tftp_xfer_size - tftp_bytes_sent; 
     227 
     228                if (flash_from_file) 
     229                        read_from_file(tftp_data + 4, (void *)tftp_xfer_buff, tftp_data_len, tftp_bytes_sent); 
     230                else 
     231                        memcpy(tftp_data + 4, (void *)(tftp_xfer_buff + tftp_bytes_sent), tftp_data_len); 
    209232 
    210233                tftp_bytes_sent += tftp_data_len; 
     
    231254} 
    232255 
    233 void fw_upload(void) 
     256int fw_upload(void) 
    234257{ 
    235258        const unsigned char *packet; 
     
    342365                } 
    343366        } 
    344 } 
     367 
     368        return 0; 
     369} 
  • ap51-flash/trunk/packet.h

    r202 r222  
    3434void arp_packet_init(void); 
    3535void arp_packet_send(void); 
    36 void fw_upload(void); 
     36int fw_upload(void); 
  • ap51-flash/trunk/uip-conf.h

    r194 r222  
    117117 * \hideinitializer 
    118118 */ 
    119 #define UIP_CONF_BYTE_ORDER      UIP_LITTLE_ENDIAN 
     119/* #define UIP_CONF_BYTE_ORDER      UIP_LITTLE_ENDIAN */ 
    120120 
    121121/**