Changeset 1482


Ignore:
Timestamp:
12/25/11 10:12:16 (5 months ago)
Author:
stefanct
Message:

Add deferred --image processing

The general idea and most of the code are based on the following
commits in the chromiumos flashrom tree:

8fc0740356ca15d02fb1c65ab43b10844f148c3b
bb9049c66ca55e0dc621dd2c70b5d2cb6e5179bf
Signed-off-by: Louis Yung-Chieh Lo <yjlou@…>

and the main part:
d0ea9ed71e7f86bb8e8db2ca7c32a96de25343d8
Signed-off-by: David Hendricks <dhendrix@…>

This implementation does not defer the processing until doit(), but after the
argument parsing loop only (doit() should not contain argument checks).

This allows to specify -i and -l parameters in any order.

Signed-off-by: Stefan Tauner <stefan.tauner@…>
Acked-by: David Hendricks <dhendrix@…>

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/cli_classic.c

    r1479 r1482  
    296296                        break; 
    297297                case 'i': 
    298                         /* FIXME: -l has to be specified before -i. */ 
    299298                        tempstr = strdup(optarg); 
    300                         if (find_romentry(tempstr) < 0) { 
    301                                 fprintf(stderr, "Error: image %s not found in " 
    302                                         "layout file or -i specified before " 
    303                                         "-l\n", tempstr); 
    304                                 cli_classic_abort_usage(); 
    305                         } 
     299                        if (register_include_arg(tempstr)) 
     300                                cli_classic_abort_usage(); 
    306301                        break; 
    307302                case 'L': 
     
    395390                cli_classic_abort_usage(); 
    396391        } 
     392 
     393        if (process_include_args()) 
     394                cli_classic_abort_usage(); 
    397395 
    398396        /* FIXME: Print the actions flashrom will take. */ 
  • trunk/flash.h

    r1475 r1482  
    290290 
    291291/* layout.c */ 
     292int register_include_arg(char *name); 
     293int process_include_args(void); 
    292294int read_romlayout(char *name); 
    293 int find_romentry(char *name); 
    294295int handle_romentries(struct flashctx *flash, uint8_t *oldcontents, uint8_t *newcontents); 
    295296 
  • trunk/layout.c

    r1481 r1482  
    4242} romlayout_t; 
    4343 
     44/* include_args lists arguments specified at the command line with -i. They 
     45 * must be processed at some point so that desired regions are marked as 
     46 * "included" in the rom_entries list. 
     47 */ 
     48static char *include_args[MAX_ROMLAYOUT]; 
     49static int num_include_args = 0; /* the number of valid entries. */ 
    4450static romlayout_t rom_entries[MAX_ROMLAYOUT]; 
    4551 
     
    157163                if (romimages >= MAX_ROMLAYOUT) { 
    158164                        msg_gerr("Maximum number of ROM images (%i) in layout " 
    159                                  "file reached before end of layout file.\n", 
    160                                  MAX_ROMLAYOUT); 
    161                         msg_gerr("Ignoring the rest of the layout file.\n"); 
    162                         break; 
     165                                 "file reached.\n", MAX_ROMLAYOUT); 
     166                        return 1; 
    163167                } 
    164168                if (2 != fscanf(romlayout, "%s %s\n", tempstr, rom_entries[romimages].name)) 
     
    195199#endif 
    196200 
    197 int find_romentry(char *name) 
     201/* register an include argument (-i) for later processing */ 
     202int register_include_arg(char *name) 
     203{ 
     204        if (num_include_args >= MAX_ROMLAYOUT) { 
     205                msg_gerr("Too many regions included (%i).\n", num_include_args); 
     206                return 1; 
     207        } 
     208 
     209        if (name == NULL) { 
     210                msg_gerr("<NULL> is a bad region name.\n"); 
     211                return 1; 
     212        } 
     213 
     214        include_args[num_include_args] = name; 
     215        num_include_args++; 
     216        return 0; 
     217} 
     218 
     219/* returns the index of the entry (or a negative value if it is not found) */ 
     220static int find_romentry(char *name) 
    198221{ 
    199222        int i; 
     
    202225                return -1; 
    203226 
    204         msg_ginfo("Looking for \"%s\"... ", name); 
    205  
     227        msg_gspew("Looking for region \"%s\"... ", name); 
    206228        for (i = 0; i < romimages; i++) { 
    207229                if (!strcmp(rom_entries[i].name, name)) { 
    208230                        rom_entries[i].included = 1; 
    209                         msg_ginfo("found.\n"); 
     231                        msg_gspew("found.\n"); 
    210232                        return i; 
    211233                } 
    212234        } 
    213         msg_ginfo("not found.\n");      // Not found. Error. 
    214  
     235        msg_gspew("not found.\n"); 
    215236        return -1; 
     237} 
     238 
     239/* process -i arguments 
     240 * returns 0 to indicate success, >0 to indicate failure 
     241 */ 
     242int process_include_args(void) 
     243{ 
     244        int i; 
     245        unsigned int found = 0; 
     246 
     247        if (num_include_args == 0) 
     248                return 0; 
     249 
     250        for (i = 0; i < num_include_args; i++) { 
     251                /* User has specified an area, but no layout file is loaded. */ 
     252                if (!romimages) { 
     253                        msg_gerr("Region requested (with -i \"%s\"), " 
     254                                 "but no layout data is available.\n", 
     255                                 include_args[i]); 
     256                        return 1; 
     257                } 
     258 
     259                if (find_romentry(include_args[i]) < 0) { 
     260                        msg_gerr("Invalid region specified: \"%s\"\n", 
     261                                 include_args[i]); 
     262                        return 1; 
     263                } 
     264                found++; 
     265        } 
     266 
     267        msg_ginfo("Using region%s: \"%s\"", num_include_args > 1 ? "s" : "", 
     268                  include_args[0]); 
     269        for (i = 1; i < num_include_args; i++) 
     270                msg_ginfo(", \"%s\"", include_args[i]); 
     271        msg_ginfo(".\n"); 
     272        return 0; 
    216273} 
    217274 
     
    249306        unsigned int size = flash->total_size * 1024; 
    250307 
    251         /* If no layout file was specified or the layout file was empty, assume 
    252          * that the user wants to flash the complete new image. 
    253          */ 
    254         if (!romimages) 
    255                 return 0; 
     308        /* If no regions were specified for inclusion, assume 
     309         * that the user wants to write the complete new image. 
     310         */ 
     311        if (num_include_args == 0) 
     312                return 0; 
     313 
    256314        /* Non-included romentries are ignored. 
    257315         * The union of all included romentries is used from the new image. 
     
    265323                        break; 
    266324                } 
     325                /* For non-included region, copy from old content. */ 
    267326                if (entry->start > start) 
    268327                        memcpy(newcontents + start, oldcontents + start, 
Note: See TracChangeset for help on using the changeset viewer.