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

Side by Side Diff: vpd.c

Issue 6849018: Support -g option to dump value string only (no key string, no quotes). (Closed) Base URL: ssh://gitrw.chromium.org:9222/vpd.git@master
Patch Set: remove newline Created 9 years, 8 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
« no previous file with comments | « lib/lib_vpd.c ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. 2 * Copyright (C) 2010 Google Inc.
3 * 3 *
4 * This program is free software; you can redistribute it and/or 4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License 5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2 6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version. 7 * of the License, or (at your option) any later version.
8 * 8 *
9 * This program is distributed in the hope that it will be useful, 9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 printf("Usage: %s [OPTION] ...\n", progname); 541 printf("Usage: %s [OPTION] ...\n", progname);
542 printf(" OPTIONs include:\n"); 542 printf(" OPTIONs include:\n");
543 printf(" -h This help page and version.\n"); 543 printf(" -h This help page and version.\n");
544 printf(" -f <filename> The output file name.\n"); 544 printf(" -f <filename> The output file name.\n");
545 printf(" -E <address> EPS base address (default:0x240000).\n"); 545 printf(" -E <address> EPS base address (default:0x240000).\n");
546 printf(" -s <key=value> To add/change a string value.\n"); 546 printf(" -s <key=value> To add/change a string value.\n");
547 printf(" -p <pad length> Pad if length is shorter.\n"); 547 printf(" -p <pad length> Pad if length is shorter.\n");
548 printf(" -i <partition> Specify VPD partition name in fmap.\n"); 548 printf(" -i <partition> Specify VPD partition name in fmap.\n");
549 printf(" -l List content in the file.\n"); 549 printf(" -l List content in the file.\n");
550 printf(" -O Overwrite and re-format VPD partition.\n"); 550 printf(" -O Overwrite and re-format VPD partition.\n");
551 printf(" -g <key> Print value string only.\n");
551 printf("\n"); 552 printf("\n");
552 } 553 }
553 554
554 int main(int argc, char *argv[]) { 555 int main(int argc, char *argv[]) {
555 int opt; 556 int opt;
556 int option_index = 0; 557 int option_index = 0;
557 int retval = 0; 558 int retval = 0;
558 const char *optstring = "hf:E:s:p:i:lO"; 559 const char *optstring = "hf:E:s:p:i:lOg:";
559 static struct option long_options[] = { 560 static struct option long_options[] = {
560 {"help", 0, 0, 'h'}, 561 {"help", 0, 0, 'h'},
561 {"file", 0, 0, 'f'}, 562 {"file", 0, 0, 'f'},
562 {"epsbase", 0, 0, 'E'}, 563 {"epsbase", 0, 0, 'E'},
563 {"string", 0, 0, 's'}, 564 {"string", 0, 0, 's'},
564 {"pad", 0, 0, 'p'}, 565 {"pad", 0, 0, 'p'},
565 {"partition", 0, 0, 'i'}, 566 {"partition", 0, 0, 'i'},
566 {"list", 0, 0, 'l'}, 567 {"list", 0, 0, 'l'},
567 {"overwrite", 0, 0, 'O'}, 568 {"overwrite", 0, 0, 'O'},
569 {"filter", 0, 0, 'g'},
568 {0, 0, 0, 0} 570 {0, 0, 0, 0}
569 }; 571 };
570 char *filename = NULL; 572 char *filename = NULL;
573 char *filter_str = NULL;
571 int write_back_to_flash = 0; 574 int write_back_to_flash = 0;
572 int list_it = 0; 575 int list_it = 0;
573 int overwrite_it = 0; 576 int overwrite_it = 0;
574 int modified = 0; 577 int modified = 0;
575 int fd; 578 int fd;
576 579
577 initContainer(&file); 580 initContainer(&file);
578 initContainer(&argument); 581 initContainer(&argument);
579 582
580 while ((opt = getopt_long(argc, argv, optstring, 583 while ((opt = getopt_long(argc, argv, optstring,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 case 'l': 636 case 'l':
634 list_it = 1; 637 list_it = 1;
635 break; 638 break;
636 639
637 case 'O': 640 case 'O':
638 overwrite_it = 1; 641 overwrite_it = 1;
639 modified = 1; /* This option forces to write empty data back even 642 modified = 1; /* This option forces to write empty data back even
640 * no new pair is given. */ 643 * no new pair is given. */
641 break; 644 break;
642 645
646 case 'g':
647 filter_str = strdup(optarg);
648 break;
649
643 default: 650 default:
644 fprintf(stderr, "Invalid option, use --help for usage.\n"); 651 fprintf(stderr, "Invalid option (%s), use --help for usage.\n", optarg);
645 retval = 1; 652 retval = 1;
646 goto teardown; 653 goto teardown;
647 break; 654 break;
648 } 655 }
649 } 656 }
650 657
651 if (optind < argc) { 658 if (optind < argc) {
652 fprintf(stderr, "[ERROR] unexpected argument: %s\n\n", argv[optind]); 659 fprintf(stderr, "[ERROR] unexpected argument: %s\n\n", argv[optind]);
653 usage(argv[0]); 660 usage(argv[0]);
654 retval = 1; 661 retval = 1;
655 goto teardown; 662 goto teardown;
656 } 663 }
657 664
658 if (generateTempFilenames() < 0) { 665 if (generateTempFilenames() < 0) {
666 fprintf(stderr, "[ERROR] generateTempFilenames() returns failed.\n");
659 retval = 1; 667 retval = 1;
660 goto teardown; 668 goto teardown;
661 } 669 }
670
671 if (list_it && filter_str) {
672 fprintf(stderr, "[ERROR] -l and -g must be mutually exclusive.\n");
673 retval = 1;
674 goto teardown;
675 }
662 676
663 /* to avoid malicious attack, we replace suspicious chars. */ 677 /* to avoid malicious attack, we replace suspicious chars. */
664 fmapNormalizeAreaName(fmap_vpd_area_name); 678 fmapNormalizeAreaName(fmap_vpd_area_name);
665 679
666 /* if no filename is specified, call flashrom to read from flash. */ 680 /* if no filename is specified, call flashrom to read from flash. */
667 if (!filename) { 681 if (!filename) {
668 if (FLASHROM_OK != flashromRead(tmp_part_file, tmp_full_file, 682 if (FLASHROM_OK != flashromRead(tmp_part_file, tmp_full_file,
669 fmap_vpd_area_name)) { 683 fmap_vpd_area_name)) {
670 fprintf(stderr, "flashromRead() error!\n"); 684 fprintf(stderr, "flashromRead() error!\n");
671 retval = 1; 685 retval = 1;
672 goto teardown; 686 goto teardown;
673 } 687 }
674 write_back_to_flash = 1; 688 write_back_to_flash = 1;
675 filename = strdup(tmp_part_file); 689 filename = strdup(tmp_part_file);
676 } 690 }
677 691
678 if (retval = loadFile(filename, &file, overwrite_it)) { 692 if (retval = loadFile(filename, &file, overwrite_it)) {
679 fprintf(stderr, "loadFile('%s') error.\n", filename); 693 fprintf(stderr, "loadFile('%s') error.\n", filename);
680 goto teardown; 694 goto teardown;
681 } 695 }
682 696
683 mergeContainer(&file, &argument); 697 mergeContainer(&file, &argument);
684 698
685 if (list_it) { 699 if (list_it || filter_str) {
686 /* Reserve larger size because the exporting generates longer string than 700 /* Reserve larger size because the exporting generates longer string than
687 * the encoded data. */ 701 * the encoded data. */
688 uint8_t list_buf[BUF_LEN * 2]; 702 uint8_t list_buf[BUF_LEN * 2];
689 int list_len = 0; 703 int list_len = 0;
690 704
691 if (VPD_OK != exportContainer(VPD_EXPORT_KEY_VALUE, &file, 705 if (filter_str) setContainerFilter(&file, filter_str);
692 sizeof(list_buf), list_buf, &list_len)) { 706 if (VPD_OK != exportContainer(
707 (filter_str) ? VPD_EXPORT_VALUE : VPD_EXPORT_KEY_VALUE,
708 &file, sizeof(list_buf), list_buf, &list_len)) {
693 fprintf(stderr, "exportContainer(): Cannot generate string.\n"); 709 fprintf(stderr, "exportContainer(): Cannot generate string.\n");
694 retval = 1; 710 retval = 1;
695 goto teardown; 711 goto teardown;
696 } 712 }
697 printf("%s", list_buf); 713 printf("%s", list_buf);
698 } 714 }
699 715
700 if (modified) { 716 if (modified) {
701 if (retval = saveFile(&file, filename)) { 717 if (retval = saveFile(&file, filename)) {
702 fprintf(stderr, "saveFile('%s') error.\n", filename); 718 fprintf(stderr, "saveFile('%s') error.\n", filename);
703 goto teardown; 719 goto teardown;
704 } 720 }
705 721
706 if (write_back_to_flash) { 722 if (write_back_to_flash) {
707 if (FLASHROM_OK != flashromPartialWrite(filename, tmp_full_file, 723 if (FLASHROM_OK != flashromPartialWrite(filename, tmp_full_file,
708 fmap_vpd_area_name)) { 724 fmap_vpd_area_name)) {
709 fprintf(stderr, "flashromPartialWrite() error.\n"); 725 fprintf(stderr, "flashromPartialWrite() error.\n");
710 retval = 1; 726 retval = 1;
711 goto teardown; 727 goto teardown;
712 } 728 }
713 } 729 }
714 } 730 }
715 731
716 teardown: 732 teardown:
717 if (spd_data) free(spd_data); 733 if (spd_data) free(spd_data);
718 if (filename) free(filename); 734 if (filename) free(filename);
735 if (filter_str) free(filter_str);
719 destroyContainer(&file); 736 destroyContainer(&file);
720 destroyContainer(&argument); 737 destroyContainer(&argument);
721 738
722 return retval; 739 return retval;
723 } 740 }
OLDNEW
« no previous file with comments | « lib/lib_vpd.c ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698