Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Side by Side Diff: utility/bmpblk_utility.cc

Issue 6482001: New commandline args are clearer, and prepare for compression. (Closed) Base URL: http://git.chromium.org/git/vboot_reference.git@master
Patch Set: Move bmpblk_util.h out of firmware/include Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // 4 //
5 // Utility for manipulating firmware screen block (BMPBLOCK) in GBB. 5 // Utility for manipulating firmware screen block (BMPBLOCK) in GBB.
6 // 6 //
7 7
8 #include "bmpblk_utility.h" 8 #include "bmpblk_utility.h"
9 9
10 #include <assert.h> 10 #include <assert.h>
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 if (r != 1) { 475 if (r != 1) {
476 perror(filename); 476 perror(filename);
477 exit(errno); 477 exit(errno);
478 } 478 }
479 } 479 }
480 480
481 } // namespace vboot_reference 481 } // namespace vboot_reference
482 482
483 #ifdef WITH_UTIL_MAIN 483 #ifdef WITH_UTIL_MAIN
484 484
485 /////////////////////////////////////////////////////////////////////// 485 //////////////////////////////////////////////////////////////////////////////
486 // Command line utilities 486 // Command line utilities.
487
488 extern "C" {
489 #include "bmpblk_util.h"
490 }
487 491
488 using vboot_reference::BmpBlockUtil; 492 using vboot_reference::BmpBlockUtil;
489 493
490 // utility function: provide usage of this utility and exit. 494 // utility function: provide usage of this utility and exit.
491 static void usagehelp_exit(const char *prog_name) { 495 static void usagehelp_exit(const char *prog_name) {
492 printf( 496 printf(
493 "Utility to manage firmware screen block (BMPBLOCK)\n"
494 "Usage: %s -c|-l|-x [options] BMPBLOCK_FILE\n"
495 "\n" 497 "\n"
496 "Main Operation Mode:\n" 498 "To create a new BMPBLOCK file:\n"
Randall Spangler 2011/02/10 21:45:10 To create a new BMPBLOCK file using config from YA
497 " -c, --create Create a new BMPBLOCK file. Should specify --config.\n"
498 " -l, --list List the contents of a BMPBLOCK file.\n"
499 " -x, --extract Extract embedded images and config file from a BMPBLOCK\n"
500 " file.\n"
501 "\n" 499 "\n"
502 "Other Options:\n" 500 " %s [-z NUM] -c YAML BMPBLOCK\n"
503 " -C, --config=CONFIG_FILE Config file describing screen layouts and\n"
504 " embedded images. (default: bmpblk.cfg)\n"
505 "\n" 501 "\n"
506 "Example:\n" 502 " -z NUM = compression algorithm to use\n"
507 " %s --create --config=screens.cfg bmpblk.bin\n" 503 " 0 = none\n"
508 , prog_name, prog_name); 504 " 1 = EFIv1\n"
505 " 2 = TBD\n"
506 "\n", prog_name);
507 printf(
508 "To display the contents of a BMPBLOCK:\n"
509 "\n"
510 " %s BMPBLOCK\n"
511 "\n", prog_name);
512 printf(
513 "To unpack a BMPBLOCK file:\n"
514 "\n"
515 " %s -x [-d DIR] [-f] BMPBLOCK\n"
516 "\n"
517 " -d DIR = directory to use (default '.')\n"
518 " -f = force overwriting existing files\n"
519 "\n", prog_name);
509 exit(1); 520 exit(1);
510 } 521 }
511 522
512 /////////////////////////////////////////////////////////////////////// 523 ///////////////////////////////////////////////////////////////////////
513 // main 524 // main
514 525
515 int main(int argc, char *argv[]) { 526 int main(int argc, char *argv[]) {
516 const char *prog_name = argv[0];
517 BmpBlockUtil util;
518 527
519 struct BmpBlockUtilOptions { 528 const char *prog_name = strrchr(argv[0], '/');
520 bool create_mode, list_mode, extract_mode; 529 if (prog_name)
521 string config_fn, bmpblock_fn; 530 prog_name++;
522 } options; 531 else
532 prog_name = argv[0];
523 533
524 int longindex, opt; 534 int force = 0, extract_mode = 0;
525 static struct option longopts[] = { 535 int compression = 0;
526 {"create", 0, NULL, 'c'}, 536 const char *config_fn = 0, *bmpblock_fn = 0, *extract_dir = ".";
527 {"list", 0, NULL, 'l'},
528 {"extract", 0, NULL, 'x'},
529 {"config", 1, NULL, 'C'},
530 { NULL, 0, NULL, 0 },
531 };
532 537
533 while ((opt = getopt_long(argc, argv, "clxC:", longopts, &longindex)) >= 0) { 538 int opt;
539 opterr = 0; // quiet
540 int errorcnt = 0;
541 char *e = 0;
542 while ((opt = getopt(argc, argv, ":c:xz:fd:")) != -1) {
534 switch (opt) { 543 switch (opt) {
535 case 'c': 544 case 'c':
536 options.create_mode = true; 545 config_fn = optarg;
537 break; 546 break;
538 case 'l': 547 case 'x':
539 options.list_mode = true; 548 extract_mode = 1;
540 break; 549 break;
541 case 'x': 550 case 'z':
542 options.extract_mode = true; 551 compression = (int)strtoul(optarg, &e, 0);
543 break; 552 if (!*optarg || (e && *e)) {
544 case 'C': 553 fprintf(stderr, "%s: invalid argument to -%c: \"%s\"\n",
545 options.config_fn = optarg; 554 prog_name, opt, optarg);
546 break; 555 errorcnt++;
547 default: 556 }
548 case '?': 557 if (compression >= MAX_COMPRESS) {
549 usagehelp_exit(prog_name); 558 fprintf(stderr, "%s: compression type must be less than %d\n",
550 break; 559 prog_name, compression);
560 errorcnt++;
561 }
562 break;
563 case 'f':
564 force = 1;
565 break;
566 case 'd':
567 extract_dir= optarg;
568 break;
569 case ':':
570 fprintf(stderr, "%s: missing argument to -%c\n",
571 prog_name, optopt);
572 errorcnt++;
573 break;
574 default:
575 fprintf(stderr, "%s: unrecognized switch: -%c\n",
576 prog_name, optopt);
577 errorcnt++;
578 break;
551 } 579 }
552 } 580 }
553 argc -= optind; 581 argc -= optind;
554 argv += optind; 582 argv += optind;
555 583
556 if (argc == 1) { 584 if (argc >= 1) {
557 options.bmpblock_fn = argv[0]; 585 bmpblock_fn = argv[0];
558 } else { 586 } else {
559 usagehelp_exit(prog_name); 587 fprintf(stderr, "%s: missing BMPBLOCK name\n", prog_name);
588 errorcnt++;
560 } 589 }
561 590
562 if (options.create_mode) { 591 if (errorcnt)
563 util.load_from_config(options.config_fn.c_str()); 592 usagehelp_exit(prog_name);
593
594 BmpBlockUtil util;
595
596 if (config_fn) {
597 printf("compression is %d\n", compression);
598 util.load_from_config(config_fn);
564 util.pack_bmpblock(); 599 util.pack_bmpblock();
565 util.write_to_bmpblock(options.bmpblock_fn.c_str()); 600 util.write_to_bmpblock(bmpblock_fn);
566 printf("The BMPBLOCK is sucessfully created in: %s.\n", 601 printf("The BMPBLOCK is sucessfully created in: %s.\n",
567 options.bmpblock_fn.c_str()); 602 bmpblock_fn);
568 } 603 }
569 604
570 if (options.list_mode) { 605 else if (extract_mode) {
606 return extract_bmpblock(bmpblock_fn, extract_dir, force);
607 printf("extract parts from %s into %s %s overwriting\n",
608 bmpblock_fn, extract_dir, force ? "with" : "without");
609 /* TODO(waihong): Implement the list mode. */
610 error("Extract mode hasn't been implemented yet.\n");
611 }
612
613 else {
614 return display_bmpblock(bmpblock_fn);
615 printf("display content of %s\n", bmpblock_fn);
571 /* TODO(waihong): Implement the list mode. */ 616 /* TODO(waihong): Implement the list mode. */
572 error("List mode hasn't been implemented yet.\n"); 617 error("List mode hasn't been implemented yet.\n");
573 } 618 }
574 619
575 if (options.extract_mode) {
576 /* TODO(waihong): Implement the extract mode. */
577 error("Extract mode hasn't been implemented yet.\n");
578 }
579
580 return 0; 620 return 0;
581 } 621 }
582 622
583 #endif // WITH_UTIL_MAIN 623 #endif // WITH_UTIL_MAIN
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698