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

Side by Side Diff: lib/flashrom.c

Issue 6646016: leverage flashrom fast partial read function to speed up VPD read. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/vpd.git@master
Patch Set: Created 9 years, 9 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 | « include/lib/fmap.h ('k') | lib/fmap.c » ('j') | lib/fmap.c » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2010, Google Inc. 2 * Copyright 2010, Google Inc.
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
7 * met: 7 * met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 16 matching lines...) Expand all
27 #include <stdlib.h> 27 #include <stdlib.h>
28 #include <string.h> 28 #include <string.h>
29 #include <unistd.h> 29 #include <unistd.h>
30 30
31 #include "lib/flashrom.h" 31 #include "lib/flashrom.h"
32 32
33 /* The best choice is PATH_MAX. However, it leads portibility issue. 33 /* The best choice is PATH_MAX. However, it leads portibility issue.
34 * So, define a long enough length here. */ 34 * So, define a long enough length here. */
35 #define CMD_BUF_SIZE (4096) 35 #define CMD_BUF_SIZE (4096)
36 36
37 #define PARTIAL_WRITE_AREA_NAME "pw_name"
38
39 static uint8_t layout_filename[] = "/tmp/vpd.layout.XXXXXX";
40
41 static uint8_t flashrom_cmd[] = "flashrom"; 37 static uint8_t flashrom_cmd[] = "flashrom";
42 38
43 /* The argument for flashrom. 39 /* The argument for flashrom.
44 * bus=spi: The VPD data are stored in BIOS flash, which is attached 40 * bus=spi: The VPD data are stored in BIOS flash, which is attached
45 * to the SPI bus. 41 * to the SPI bus.
46 */ 42 */
47 static uint8_t flashrom_arguments[] = " -p internal:bus=spi "; 43 static uint8_t flashrom_arguments[] = " -p internal:bus=spi ";
48 44
49 int flashromRead(const char* tmp_file) { 45 int flashromRead(const char* part_file, const char* full_file,
46 const char* partition_name) {
50 char cmd[CMD_BUF_SIZE]; 47 char cmd[CMD_BUF_SIZE];
51 int ret = 0; 48 int ret = 0;
52 49
53 snprintf(cmd, sizeof(cmd), "%s %s -r '%s' >/dev/null 2>&1", 50 snprintf(cmd, sizeof(cmd), "%s %s -i '%s':'%s' -r '%s' >/dev/null 2>&1",
54 flashrom_cmd, flashrom_arguments, tmp_file); 51 flashrom_cmd, flashrom_arguments,
52 partition_name, part_file, full_file);
55 ret = system(cmd); 53 ret = system(cmd);
56 if (ret == 0) 54 if (ret == 0)
57 return FLASHROM_OK; 55 return FLASHROM_OK;
58 else 56 else
59 return FLASHROM_FAIL; 57 return FLASHROM_FAIL;
60 } 58 }
61 59
62 int flashromPartialWrite(const char* tmp_file, 60 int flashromPartialWrite(const char* part_file, const char* full_file,
63 const off_t section_offset, 61 const char* partition_name) {
64 const size_t section_size) {
65 int fd; 62 int fd;
66 char cmd[CMD_BUF_SIZE]; 63 char cmd[CMD_BUF_SIZE];
67 FILE* fp; 64 FILE* fp;
68 int ret = 0; 65 int ret = 0;
69 66
70 fd = mkstemp(layout_filename);
71 if (fd < 0) {
72 fprintf(stderr, "mkstemp(%s) failed.\n", layout_filename);
73 return FLASHROM_FAIL;
74 } else {
75 close(fd);
76 }
77
78 /* generate layout file */
79 if (!(fp = fopen(layout_filename, "w"))) {
80 fprintf(stderr, "cannot create layout file: [%s]\n", layout_filename);
81 return FLASHROM_FAIL;
82 }
83 fprintf(fp, "0x%lx:0x%lx %s\n", section_offset,
84 section_offset + section_size - 1,
85 PARTIAL_WRITE_AREA_NAME);
86 fclose(fp);
87
88 /* write it back */ 67 /* write it back */
89 snprintf(cmd, sizeof(cmd), "%s %s -l %s -i '%s' -w '%s' >/tmp/null 2>&1", 68 snprintf(cmd, sizeof(cmd), "%s %s -i '%s':'%s' -w '%s' >/tmp/null 2>&1",
90 flashrom_cmd, flashrom_arguments, layout_filename, 69 flashrom_cmd, flashrom_arguments,
91 PARTIAL_WRITE_AREA_NAME, tmp_file); 70 partition_name, part_file, full_file);
92 ret = system(cmd); 71 ret = system(cmd);
93 72
94 if (ret == 0) 73 if (ret == 0)
95 return FLASHROM_OK; 74 return FLASHROM_OK;
96 else 75 else
97 return FLASHROM_FAIL; 76 return FLASHROM_FAIL;
98 } 77 }
OLDNEW
« no previous file with comments | « include/lib/fmap.h ('k') | lib/fmap.c » ('j') | lib/fmap.c » ('J')

Powered by Google App Engine
This is Rietveld 408576698