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

Side by Side Diff: flashrom.c

Issue 6611015: Support -i partition:file feature for both read and write. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/flashrom.git@master
Patch Set: fixed according to code review and security check. 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 | « flash.h ('k') | layout.c » ('j') | 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 * This file is part of the flashrom project. 2 * This file is part of the flashrom project.
3 * 3 *
4 * Copyright (C) 2000 Silicon Integrated System Corporation 4 * Copyright (C) 2000 Silicon Integrated System Corporation
5 * Copyright (C) 2004 Tyan Corp <yhlu@tyan.com> 5 * Copyright (C) 2004 Tyan Corp <yhlu@tyan.com>
6 * Copyright (C) 2005-2008 coresystems GmbH 6 * Copyright (C) 2005-2008 coresystems GmbH
7 * Copyright (C) 2008,2009 Carl-Daniel Hailfinger 7 * Copyright (C) 2008,2009 Carl-Daniel Hailfinger
8 * 8 *
9 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by 10 * it under the terms of the GNU General Public License as published by
(...skipping 1298 matching lines...) Expand 10 before | Expand all | Expand 10 after
1309 return 1; 1309 return 1;
1310 } 1310 }
1311 return 0; 1311 return 0;
1312 } 1312 }
1313 1313
1314 int read_flash_to_file(struct flashchip *flash, char *filename) 1314 int read_flash_to_file(struct flashchip *flash, char *filename)
1315 { 1315 {
1316 unsigned long size = flash->total_size * 1024; 1316 unsigned long size = flash->total_size * 1024;
1317 unsigned char *buf = calloc(size, sizeof(char)); 1317 unsigned char *buf = calloc(size, sizeof(char));
1318 int ret = 0; 1318 int ret = 0;
1319 int i;
1319 1320
1320 msg_cinfo("Reading flash... "); 1321 msg_cinfo("Reading flash... ");
1321 if (!buf) { 1322 if (!buf) {
1322 msg_gerr("Memory allocation failed!\n"); 1323 msg_gerr("Memory allocation failed!\n");
1323 msg_cinfo("FAILED.\n"); 1324 msg_cinfo("FAILED.\n");
1324 return 1; 1325 return 1;
1325 } 1326 }
1327
1328 /* To support partial read, fill buffer to all 0xFF at beginning to make
1329 * debug easier. */
1330 memset(buf, 0xFF, size);
1331
1326 if (!flash->read) { 1332 if (!flash->read) {
1327 msg_cerr("No read function available for this flash chip.\n"); 1333 msg_cerr("No read function available for this flash chip.\n");
1328 ret = 1; 1334 ret = 1;
1329 goto out_free; 1335 goto out_free;
1330 } 1336 }
1331 » if (flash->read(flash, buf, 0, size)) { 1337
1338 » /* First try to handle partial read case, rather than read the whole
1339 » * flash, which is slow. */
1340 » ret = handle_partial_read(flash, buf, flash->read);
1341 » if (ret < 0) {
1342 » » msg_cerr("Partial read operation failed!\n");
1343 » » ret = 1;
1344 » » goto out_free;
1345 » } else if (ret > 0) {
1346 » » /* Partial read has been handled, pass the whole flash read. */
1347 » } else if (flash->read(flash, buf, 0, size)) {
1332 msg_cerr("Read operation failed!\n"); 1348 msg_cerr("Read operation failed!\n");
1333 ret = 1; 1349 ret = 1;
1334 goto out_free; 1350 goto out_free;
1335 } 1351 }
1336 1352
1337 ret = write_buf_to_file(buf, flash->total_size * 1024, filename); 1353 ret = write_buf_to_file(buf, flash->total_size * 1024, filename);
1338 out_free: 1354 out_free:
1339 free(buf); 1355 free(buf);
1340 if (ret) 1356 if (ret)
1341 msg_cerr("FAILED."); 1357 msg_cerr("FAILED.");
(...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after
1980 out_nofree: 1996 out_nofree:
1981 chip_restore(); /* must be done before programmer_shutdown() */ 1997 chip_restore(); /* must be done before programmer_shutdown() */
1982 /* 1998 /*
1983 * programmer_shutdown() call is moved to cli_mfg() in chromium os 1999 * programmer_shutdown() call is moved to cli_mfg() in chromium os
1984 * tree. This is because some operations, such as write protection, 2000 * tree. This is because some operations, such as write protection,
1985 * requires programmer_shutdown() but does not call doit(). 2001 * requires programmer_shutdown() but does not call doit().
1986 */ 2002 */
1987 // programmer_shutdown(); 2003 // programmer_shutdown();
1988 return ret; 2004 return ret;
1989 } 2005 }
OLDNEW
« no previous file with comments | « flash.h ('k') | layout.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698