Changeset 265

Show
Ignore:
Timestamp:
07/25/11 02:14:25 (10 months ago)
Author:
marek
Message:

ap51-flash: support for OM2P added (using the extended combined image format)

Signed-off-by: Marek Lindner <lindner_marek@…>

Location:
ap51-flash-ng
Files:
11 modified

Legend:

Unmodified
Added
Removed
  • ap51-flash-ng/commandline.c

    r256 r265  
    7171        argv += 2; 
    7272 
     73        router_images_init(); 
     74 
    7375        while (argc > 0) { 
    7476                ret = router_images_verify_path(argv[0]); 
  • ap51-flash-ng/flash.c

    r258 r265  
    4545} 
    4646 
    47 static void node_list_prepend(struct list *list) 
    48 { 
    49         if (!node_list) { 
    50                 node_list = list; 
    51                 return; 
    52         } 
    53  
    54         list->next = node_list->next; 
    55         node_list->next = list; 
    56 } 
    57  
    5847struct node *node_list_get(uint8_t *mac_addr) 
    5948{ 
     
    8675        node->image_state.fd = -1; 
    8776        list->data = node; 
    88         node_list_prepend(list); 
     77        list_prepend(&node_list, list); 
    8978        goto out; 
    9079 
     
    142131                                break; 
    143132 
    144                         ret = mr500_flash_completed(node); 
     133                        ret = tftp_client_flash_completed(node); 
    145134                        if (ret == 0) 
    146135                                break; 
  • ap51-flash-ng/flash.h

    r254 r265  
    2020void our_mac_set(struct node *node); 
    2121int flash(char *iface); 
     22 
     23static inline void list_prepend(struct list **list, struct list *list_item) 
     24{ 
     25        if (!(*list)) { 
     26                *list = list_item; 
     27                return; 
     28        } 
     29 
     30        list_item->next = (*list)->next; 
     31        (*list)->next = list_item; 
     32} 
  • ap51-flash-ng/proto.c

    r264 r265  
    161161        switch (ntohs(arphdr->arp_op)) { 
    162162        case ARPOP_REQUEST: 
    163                 /* fprintf(stderr, "[%02x:%02x:%02x:%02x:%02x:%02x]: received ARP request\n", 
     163                /* fprintf(stderr, "[%02x:%02x:%02x:%02x:%02x:%02x]: received ARP request, status: %d\n", 
    164164                        node->his_mac_addr[0], node->his_mac_addr[1], node->his_mac_addr[2], 
    165                         node->his_mac_addr[3], node->his_mac_addr[4], node->his_mac_addr[5]); */ 
     165                        node->his_mac_addr[3], node->his_mac_addr[4], node->his_mac_addr[5], 
     166                        node->status); */ 
    166167                break; 
    167168        case ARPOP_REPLY: 
    168                 /* fprintf(stderr, "[%02x:%02x:%02x:%02x:%02x:%02x]: received ARP reply\n", 
     169                /* fprintf(stderr, "[%02x:%02x:%02x:%02x:%02x:%02x]: received ARP reply, status: %d\n", 
    169170                        node->his_mac_addr[0], node->his_mac_addr[1], node->his_mac_addr[2], 
    170                         node->his_mac_addr[3], node->his_mac_addr[4], node->his_mac_addr[5]); */ 
     171                        node->his_mac_addr[3], node->his_mac_addr[4], node->his_mac_addr[5], 
     172                        node->status); */ 
    171173                break; 
    172174        default: 
    173                 /* fprintf(stderr, "ARP, unknown op code: %i\n", ntohs(arphdr->arp_op)); */ 
     175                /* fprintf(stderr, "ARP, unknown op code: %i, status: %d\n", ntohs(arphdr->arp_op), node->status); */ 
    174176                return; 
    175177        } 
     
    183185                if (ret == 1) 
    184186                        node->status = NODE_STATUS_DETECTED; 
    185                 break; 
     187                else 
     188                        break; 
    186189        case NODE_STATUS_DETECTED: 
    187190        case NODE_STATUS_FLASHING: 
     
    209212{ 
    210213        struct udphdr *udphdr; 
     214        struct file_info *file_info; 
    211215        unsigned short opcode, block; 
    212216        char *file_name; 
     
    245249                switch (node->flash_mode) { 
    246250                case FLASH_MODE_REDBOOT: 
    247                         /* combined image */ 
    248                         if (strcmp(file_name, "kernel") == 0) { 
     251                case FLASH_MODE_TFTP_CLIENT: 
     252                        file_info = router_image_get_file(node->router_type->image->file_list, file_name); 
     253                        if (!file_info) { 
     254                                fprintf(stderr, "[%02x:%02x:%02x:%02x:%02x:%02x]: %s: tftp client asks for '%s' - file not found ...\n", 
     255                                        node->his_mac_addr[0], node->his_mac_addr[1], node->his_mac_addr[2], 
     256                                        node->his_mac_addr[3], node->his_mac_addr[4], node->his_mac_addr[5], 
     257                                        node->router_type->desc, file_name); 
     258                                goto out; 
     259                        } 
     260 
     261                        if (node->image_state.fd <= 0) { 
    249262                                ret = router_images_open_path(node); 
    250263                                if (ret < 0) 
    251                                         return; 
     264                                        goto out; 
    252265                                node->status = NODE_STATUS_FLASHING; 
    253  
    254                                 node->image_state.file_size = node->router_type->image->ci_info.kernel_size; 
    255                                 node->image_state.flash_size = node->router_type->image->ci_info.kernel_fsize; 
    256                                 node->image_state.offset = node->router_type->image->ci_info.kernel_offset; 
    257  
    258                                 fprintf(stderr, "[%02x:%02x:%02x:%02x:%02x:%02x]: %s: tftp client asks for '%s', serving kernel portion of: %s (%i blocks) ...\n", 
    259                                         node->his_mac_addr[0], node->his_mac_addr[1], node->his_mac_addr[2], 
    260                                         node->his_mac_addr[3], node->his_mac_addr[4], node->his_mac_addr[5], 
    261                                         node->router_type->desc, file_name, node->router_type->image->path, 
    262                                         ((node->image_state.flash_size + TFTP_PAYLOAD_SIZE - 1) / TFTP_PAYLOAD_SIZE)); 
    263                         } else { 
    264                                 node->image_state.file_size = node->router_type->image->ci_info.rootfs_size; 
    265                                 node->image_state.flash_size = node->router_type->image->ci_info.rootfs_fsize; 
    266                                 node->image_state.offset = node->router_type->image->ci_info.rootfs_offset; 
    267  
    268                                 fprintf(stderr, "[%02x:%02x:%02x:%02x:%02x:%02x]: %s: tftp client asks for '%s', serving rootfs portion of: %s (%i blocks) ...\n", 
    269                                         node->his_mac_addr[0], node->his_mac_addr[1], node->his_mac_addr[2], 
    270                                         node->his_mac_addr[3], node->his_mac_addr[4], node->his_mac_addr[5], 
    271                                         node->router_type->desc, file_name, node->router_type->image->path, 
    272                                         ((node->image_state.flash_size + TFTP_PAYLOAD_SIZE - 1) / TFTP_PAYLOAD_SIZE)); 
    273266                        } 
    274                         break; 
    275                 case FLASH_MODE_TFTP_CLIENT: 
    276                         fprintf(stderr, "[%02x:%02x:%02x:%02x:%02x:%02x]: %s: tftp client asks for '%s', serving: %s (%i blocks) ...\n", 
     267 
     268                        fprintf(stderr, "[%02x:%02x:%02x:%02x:%02x:%02x]: %s: tftp client asks for '%s', serving %s portion of: %s (%i blocks) ...\n", 
    277269                                node->his_mac_addr[0], node->his_mac_addr[1], node->his_mac_addr[2], 
    278270                                node->his_mac_addr[3], node->his_mac_addr[4], node->his_mac_addr[5], 
    279                                 node->router_type->desc, file_name, node->router_type->image->path, 
    280                                 ((node->router_type->image->flash_size + TFTP_PAYLOAD_SIZE - 1) / TFTP_PAYLOAD_SIZE)); 
     271                                node->router_type->desc, file_name,file_info->file_name, 
     272                                node->router_type->image->path, 
     273                                ((file_info->file_fsize + TFTP_PAYLOAD_SIZE - 1) / TFTP_PAYLOAD_SIZE)); 
     274 
     275                        node->image_state.file_size = file_info->file_size; 
     276                        node->image_state.flash_size = file_info->file_fsize; 
     277                        node->image_state.offset = file_info->file_offset; 
    281278                        break; 
    282279                } 
     
    290287                if (block == 0) { 
    291288                        if (node->flash_mode == FLASH_MODE_TFTP_SERVER) { 
    292 #if defined(DEBUG) 
    293289                                fprintf(stderr, "[%02x:%02x:%02x:%02x:%02x:%02x]: %s: connection to tftp server established - uploading %i blocks ...\n", 
    294290                                        node->his_mac_addr[0], node->his_mac_addr[1], node->his_mac_addr[2], 
     
    296292                                        node->router_type->desc, 
    297293                                        ((node->router_type->image->flash_size + TFTP_PAYLOAD_SIZE - 1) / TFTP_PAYLOAD_SIZE)); 
    298 #endif 
    299                         } 
    300  
    301                         if ((node->flash_mode == FLASH_MODE_TFTP_SERVER) || 
    302                             (node->flash_mode == FLASH_MODE_TFTP_CLIENT)) { 
     294 
    303295                                ret = router_images_open_path(node); 
    304296                                if (ret < 0) 
     
    329321                        /* nothing more to send */ 
    330322                        if (node->image_state.last_packet_size == 0) { 
    331                                 switch (node->flash_mode) { 
    332                                 case FLASH_MODE_TFTP_SERVER: 
    333                                 case FLASH_MODE_TFTP_CLIENT: 
    334                                         fprintf(stderr, "[%02x:%02x:%02x:%02x:%02x:%02x]: %s: image successfully transmitted - writing image to flash ...\n", 
    335                                                 node->his_mac_addr[0], node->his_mac_addr[1], node->his_mac_addr[2], 
    336                                                 node->his_mac_addr[3], node->his_mac_addr[4], node->his_mac_addr[5], 
    337                                                 node->router_type->desc); 
    338                                         router_images_close_path(node); 
    339                                         mr500_flash_time_set(node); 
    340                                         node->status = NODE_STATUS_FINISHED; 
    341                                         break; 
     323                                node->image_state.total_bytes_sent += node->image_state.bytes_sent; 
     324 
     325                                if (node->image_state.total_bytes_sent >= node->router_type->image->file_size) { 
     326                                        switch (node->flash_mode) { 
     327                                        case FLASH_MODE_TFTP_SERVER: 
     328                                        case FLASH_MODE_TFTP_CLIENT: 
     329                                                fprintf(stderr, "[%02x:%02x:%02x:%02x:%02x:%02x]: %s: image successfully transmitted - writing image to flash ...\n", 
     330                                                        node->his_mac_addr[0], node->his_mac_addr[1], node->his_mac_addr[2], 
     331                                                        node->his_mac_addr[3], node->his_mac_addr[4], node->his_mac_addr[5], 
     332                                                        node->router_type->desc); 
     333                                                router_images_close_path(node); 
     334                                                if (node->flash_mode == FLASH_MODE_TFTP_CLIENT) 
     335                                                        tftp_client_flash_time_set(node); 
     336                                                node->status = NODE_STATUS_FINISHED; 
     337                                                break; 
     338                                        } 
    342339                                } 
    343340 
  • ap51-flash-ng/router_images.c

    r258 r265  
    1818 
    1919#include <string.h> 
     20#include <stdlib.h> 
    2021#include <stdio.h> 
    2122#include <fcntl.h> 
     
    2526 
    2627#include "types.h" 
     28#include "flash.h" 
    2729#include "router_images.h" 
    2830#include "compat.h" 
     
    3133#define TFTP_PAYLOAD_SIZE 512 
    3234 
    33 static int uboot_verify(struct router_image (*router_image)__attribute__((unused)), char *buff, int buff_len) 
    34 { 
     35struct file_info *router_image_get_file(struct list *file_list, char *file_name) 
     36{ 
     37        struct list *list; 
     38        struct file_info *file_info = NULL, *file_info_tmp; 
     39 
     40        for (list = file_list; list; list = list->next) { 
     41                file_info_tmp = (struct file_info *)list->data; 
     42 
     43                if (strcmp(file_info_tmp->file_name, file_name) != 0) 
     44                        continue; 
     45 
     46                file_info = file_info_tmp; 
     47                break; 
     48        } 
     49 
     50        return file_info; 
     51} 
     52 
     53static struct file_info *_router_image_add_file(struct router_image *router_image, 
     54                                                char *file_name) 
     55{ 
     56        struct list *list; 
     57        struct file_info *file_info; 
     58 
     59        file_info = router_image_get_file(router_image->file_list, file_name); 
     60        if (file_info) 
     61                goto out; 
     62 
     63        file_info = malloc(sizeof(struct file_info)); 
     64        if (!file_info) 
     65                goto out; 
     66 
     67        list = malloc(sizeof(struct list)); 
     68        if (!list) 
     69                goto free_node; 
     70 
     71        memset(file_info, 0, sizeof(struct file_info)); 
     72        strcpy(file_info->file_name, file_name); 
     73        list->data = file_info; 
     74        list_prepend(&router_image->file_list, list); 
     75        goto out; 
     76 
     77free_node: 
     78        free(file_info); 
     79        file_info = NULL; 
     80out: 
     81        return file_info; 
     82} 
     83 
     84static int router_image_add_file(struct router_image *router_image, char *file_name, 
     85                                 int file_size, int file_fsize, int file_offset) 
     86{ 
     87        struct file_info *file_info; 
     88 
     89        file_info = _router_image_add_file(router_image, file_name); 
     90        if (!file_info) 
     91                return 1; 
     92 
     93        file_info->file_size = file_size; 
     94        file_info->file_fsize = file_fsize; 
     95        file_info->file_offset = file_offset; 
     96        return 0; 
     97} 
     98 
     99static int uboot_verify(struct router_image *router_image, char *buff, 
     100                        int buff_len, int size) 
     101{ 
     102        int ret; 
     103 
    35104        if (buff_len < 4) 
    36105                return 0; 
     
    41110                return 0; 
    42111 
     112        ret = router_image_add_file(router_image, "mr500.bin", size, size, 0); 
     113        if (ret) 
     114                return 0; 
     115 
     116        router_image->file_size = size; 
    43117        return 1; 
    44118} 
    45119 
    46 static int ubnt_verify(struct router_image (*router_image)__attribute__((unused)), char *buff, int buff_len) 
     120static int ubnt_verify(struct router_image *router_image, char *buff, 
     121                       int buff_len, int size) 
    47122{ 
    48123        if (buff_len < 4) 
     
    54129                return 0; 
    55130 
     131        router_image->file_size = size; 
    56132        return 1; 
    57133} 
    58134 
    59 static int ci_verify(struct router_image *router_image, char *buff, int buff_len) 
     135static int ci_verify(struct router_image *router_image, char *buff, 
     136                     int buff_len, int size) 
    60137{ 
    61138        unsigned int kernel_size, rootfs_size; 
     139        int ret; 
    62140 
    63141        if (buff_len < 64) 
     
    72150                return 0; 
    73151 
    74         router_image->ci_info.kernel_offset = 64 * 1024; 
    75         router_image->ci_info.kernel_size = kernel_size; 
    76         router_image->ci_info.kernel_fsize = ((kernel_size + FLASH_PAGE_SIZE - 1) / 
    77                                                 FLASH_PAGE_SIZE) * FLASH_PAGE_SIZE; 
    78         router_image->ci_info.rootfs_offset = (64 * 1024) + kernel_size; 
    79         router_image->ci_info.rootfs_size = rootfs_size; 
    80         router_image->ci_info.rootfs_fsize = ((rootfs_size + FLASH_PAGE_SIZE - 1) / 
    81                                                 FLASH_PAGE_SIZE) * FLASH_PAGE_SIZE; 
    82  
     152        ret = router_image_add_file(router_image, "kernel", kernel_size, 
     153                                    ((kernel_size + FLASH_PAGE_SIZE - 1) / FLASH_PAGE_SIZE) * FLASH_PAGE_SIZE, 
     154                                    64 * 1024); 
     155        if (ret) 
     156                return 0; 
     157 
     158        ret = router_image_add_file(router_image, "rootfs", rootfs_size, 
     159                                    ((rootfs_size + FLASH_PAGE_SIZE - 1) / FLASH_PAGE_SIZE) * FLASH_PAGE_SIZE, 
     160                                    (64 * 1024) + kernel_size); 
     161        if (ret) 
     162                return 0; 
     163 
     164        router_image->file_size = size - (64 * 1024); 
     165        return 1; 
     166} 
     167 
     168static int ce_verify_om2p(struct router_image *router_image, char *buff, 
     169                          int buff_len, int size) 
     170{ 
     171        char name_buff[21]; 
     172        unsigned int num_files, hdr_offset, file_offset, file_size; 
     173        int ret; 
     174 
     175        hdr_offset = 14; 
     176        file_offset = 64 * 1024; 
     177 
     178        if (buff_len < 100) 
     179                return 0; 
     180 
     181        /* ext combined image magic header */ 
     182        if ((buff[0] != 'C') || (buff[1] != 'E')) 
     183                return 0; 
     184 
     185        ret = sscanf(buff, "CE%10s%02x", name_buff, &num_files); 
     186        if (ret != 2) 
     187                return 0; 
     188 
     189        if (strstr(name_buff, "OM2P") == NULL) 
     190                return 0; 
     191 
     192        while (num_files > 0) { 
     193                ret = sscanf(buff + hdr_offset, "%20s%08x", name_buff, &file_size); 
     194                if (ret != 2) 
     195                        return 0; 
     196 
     197                ret = router_image_add_file(router_image, name_buff, file_size, file_size, file_offset); 
     198                if (ret) 
     199                        return 0; 
     200 
     201                file_offset += file_size; 
     202                hdr_offset += 28; 
     203                num_files--; 
     204        } 
     205 
     206        router_image->file_size = size - (64 * 1024); 
    83207        return 1; 
    84208} 
     
    97221        .desc = "combined image", 
    98222        .image_verify = ci_verify, 
     223}; 
     224 
     225struct router_image img_ce_om2p = { 
     226        .desc = "combined ext image (OM2P)", 
     227        .image_verify = ce_verify_om2p, 
    99228}; 
    100229 
     
    103232        &img_ubnt, 
    104233        &img_ci, 
     234        &img_ce_om2p, 
    105235        NULL, 
    106236}; 
     237 
     238void router_images_init(void) 
     239{ 
     240        struct router_image **router_image; 
     241 
     242        for (router_image = router_images; *router_image; ++router_image) 
     243                (*router_image)->file_list = NULL; 
     244} 
    107245 
    108246void router_images_print_desc(void) 
     
    117255{ 
    118256        struct router_image **router_image; 
    119         char file_buff[65], found_consumer = 0; 
     257        char file_buff[100], found_consumer = 0; 
    120258        int fd, file_size, ret = -1, len; 
    121259 
     
    143281                } 
    144282 
    145                 ret = (*router_image)->image_verify((*router_image), file_buff, len); 
     283                ret = (*router_image)->image_verify((*router_image), file_buff, len, file_size); 
    146284                if (ret != 1) 
    147285                        continue; 
    148286 
    149                 (*router_image)->file_size = file_size; 
    150287                (*router_image)->flash_size = (((*router_image)->file_size + FLASH_PAGE_SIZE - 1) / 
    151288                                                        FLASH_PAGE_SIZE) * FLASH_PAGE_SIZE; 
  • ap51-flash-ng/router_images.h

    r258 r265  
    1717 */ 
    1818 
     19struct file_info *router_image_get_file(struct list *file_list, char *file_name); 
     20void router_images_init(void); 
    1921void router_images_print_desc(void); 
    2022int router_images_verify_path(char *image_path); 
     
    2628extern struct router_image img_ubnt; 
    2729extern struct router_image img_ci; 
     30extern struct router_image img_ce_om2p; 
  • ap51-flash-ng/router_redboot.c

    r259 r265  
    147147{ 
    148148        struct redboot_priv *redboot_priv = node->router_priv; 
     149        struct file_info *file_info; 
    149150        char buff[100]; 
    150151 
     
    238239                break; 
    239240        case REDBOOT_STATE_LD_ROOTFS: 
     241                file_info = router_image_get_file(node->router_type->image->file_list, "kernel"); 
     242                if (!file_info) 
     243                        return; 
     244 
    240245                sprintf(buff, "fis create -f 0x%08lx -l 0x%08lx rootfs\n", 
    241                         redboot_priv->redboot_type->flash_addr + node->router_type->image->ci_info.kernel_fsize, 
    242                         redboot_priv->redboot_type->flash_size - node->router_type->image->ci_info.kernel_fsize); 
     246                        redboot_priv->redboot_type->flash_addr + file_info->file_fsize, 
     247                        redboot_priv->redboot_type->flash_size - file_info->file_fsize); 
    243248 
    244249                printf("[%02x:%02x:%02x:%02x:%02x:%02x]: %s: flashing rootfs ...\n", 
  • ap51-flash-ng/router_tftp_client.c

    r258 r265  
    2828 
    2929static unsigned int mr500_ip = 3232260872UL; /* 192.168.99.8 */ 
     30static unsigned int om2p_ip = 3232261128UL; /* 192.168.100.8 */ 
    3031 
    3132struct mr500_priv { 
     
    3334}; 
    3435 
    35 void mr500_flash_time_set(struct node *node) 
     36struct om2p_priv { 
     37        time_t start_flash; 
     38}; 
     39 
     40static void tftp_client_detect_post(struct node *node, char *packet_buff, int packet_buff_len) 
    3641{ 
    37         struct mr500_priv *mr500_priv = node->router_priv; 
     42        struct ether_arp *arphdr; 
    3843 
    39         if (node->router_type != &mr500) 
    40                 return; 
     44        if (!len_check(packet_buff_len, sizeof(struct ether_arp), "ARP")) 
     45                goto out; 
    4146 
    42         mr500_priv->start_flash = time(NULL); 
     47        arphdr = (struct ether_arp *)packet_buff; 
     48 
     49        node->flash_mode = FLASH_MODE_TFTP_CLIENT; 
     50        node->his_ip_addr = *((unsigned int *)(arphdr->arp_spa)); 
     51        node->our_ip_addr = *((unsigned int *)(arphdr->arp_tpa)); 
     52 
     53out: 
     54        return; 
    4355} 
    4456 
    45 int mr500_flash_completed(struct node *node) 
     57void tftp_client_flash_time_set(struct node *node) 
    4658{ 
    47         struct mr500_priv *mr500_priv = node->router_priv; 
     59        struct mr500_priv *mr500_priv; 
     60        struct om2p_priv *om2p_priv; 
     61 
     62        if (node->router_type == &mr500) { 
     63                mr500_priv = node->router_priv; 
     64                mr500_priv->start_flash = time(NULL); 
     65        } else if (node->router_type == &om2p) { 
     66                om2p_priv = node->router_priv; 
     67                om2p_priv->start_flash = time(NULL); 
     68        } 
     69} 
     70 
     71int tftp_client_flash_completed(struct node *node) 
     72{ 
     73        struct mr500_priv *mr500_priv; 
     74        struct om2p_priv *om2p_priv; 
    4875        time_t time2flash; 
    4976 
    50         if (node->router_type != &mr500) 
     77        if (node->router_type == &mr500) { 
     78                mr500_priv = node->router_priv; 
     79                time2flash = mr500_priv->start_flash + 45 + (node->router_type->image->flash_size / 65536); 
     80        } else if (node->router_type == &om2p) { 
     81                om2p_priv = node->router_priv; 
     82                time2flash = om2p_priv->start_flash + (node->router_type->image->flash_size / 65536); 
     83        } else { 
    5184                return 0; 
    52  
    53         time2flash = mr500_priv->start_flash + 45 + (node->router_type->image->flash_size / 65536); 
     85        } 
    5486 
    5587        if (time(NULL) < time2flash) 
     
    80112} 
    81113 
    82 static void mr500_detect_post(struct node *node, char *packet_buff, int packet_buff_len) 
     114const struct router_type mr500 = { 
     115        .desc = "MR500 router", 
     116        .detect_pre = NULL, 
     117        .detect_main = mr500_detect_main, 
     118        .detect_post = tftp_client_detect_post, 
     119        .image = &img_uboot, 
     120        .priv_size = sizeof(struct mr500_priv), 
     121}; 
     122 
     123static int om2p_detect_main(void (*priv)__attribute__((unused)), char *packet_buff, int packet_buff_len) 
    83124{ 
    84125        struct ether_arp *arphdr; 
     126        int ret = 0; 
    85127 
    86128        if (!len_check(packet_buff_len, sizeof(struct ether_arp), "ARP")) 
     
    88130 
    89131        arphdr = (struct ether_arp *)packet_buff; 
     132        if (arphdr->ea_hdr.ar_op != htons(ARPOP_REQUEST)) 
     133                goto out; 
    90134 
    91         node->flash_mode = FLASH_MODE_TFTP_CLIENT; 
    92         node->his_ip_addr = *((unsigned int *)(arphdr->arp_spa)); 
    93         node->our_ip_addr = *((unsigned int *)(arphdr->arp_tpa)); 
     135        if (*((unsigned int *)arphdr->arp_tpa) != htonl(om2p_ip)) 
     136                goto out; 
     137 
     138        ret = 1; 
    94139 
    95140out: 
    96         return; 
     141        return ret; 
    97142} 
    98143 
    99 const struct router_type mr500 = { 
    100         .desc = "MR500 router", 
     144const struct router_type om2p = { 
     145        .desc = "OM2P router", 
    101146        .detect_pre = NULL, 
    102         .detect_main = mr500_detect_main, 
    103         .detect_post = mr500_detect_post, 
    104         .image = &img_uboot, 
    105         .priv_size = sizeof(struct mr500_priv), 
     147        .detect_main = om2p_detect_main, 
     148        .detect_post = tftp_client_detect_post, 
     149        .image = &img_ce_om2p, 
     150        .priv_size = sizeof(struct om2p_priv), 
    106151}; 
  • ap51-flash-ng/router_tftp_client.h

    r258 r265  
    1818 
    1919extern const struct router_type mr500; 
     20extern const struct router_type om2p; 
    2021 
    21 void mr500_flash_time_set(struct node *node); 
    22 int mr500_flash_completed(struct node *node); 
     22void tftp_client_flash_time_set(struct node *node); 
     23int tftp_client_flash_completed(struct node *node); 
  • ap51-flash-ng/router_types.c

    r264 r265  
    3333        &redboot, 
    3434        &mr500, 
     35        &om2p, 
    3536        NULL, 
    3637}; 
  • ap51-flash-ng/types.h

    r258 r265  
    4040#define FLASH_MODE_TFTP_CLIENT  0x03 
    4141 
    42 #define DESC_MAX_LENGTH 20 
     42#define DESC_MAX_LENGTH 30 
    4343 
    4444struct list { 
     
    4949struct image_state { 
    5050        int fd; 
    51         int bytes_sent; 
    52         int file_size; 
     51        unsigned int bytes_sent; 
     52        unsigned int file_size; 
     53        unsigned int total_bytes_sent; 
    5354        unsigned int flash_size; 
    5455        unsigned int offset; 
     
    102103}; 
    103104 
    104 struct ci_info { 
    105         unsigned int kernel_offset; 
    106         unsigned int kernel_size; 
    107         unsigned int kernel_fsize; 
    108         unsigned int rootfs_offset; 
    109         unsigned int rootfs_size; 
    110         unsigned int rootfs_fsize; 
    111         int lzma_kernel; 
     105struct file_info { 
     106        char file_name[20]; 
     107        unsigned int file_offset; 
     108        unsigned int file_size; 
     109        unsigned int file_fsize; 
    112110}; 
    113111 
    114112struct router_image { 
    115113        char desc[DESC_MAX_LENGTH]; 
    116         int (*image_verify)(struct router_image *router_image, char *buff, int buff_len); 
     114        int (*image_verify)(struct router_image *router_image, char *buff, int buff_len, int size); 
    117115        char *path; 
    118         int file_size; 
     116        unsigned int file_size; 
    119117        unsigned int flash_size; 
    120         struct ci_info ci_info; 
     118        struct list *file_list; 
    121119}; 
    122120