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

Side by Side Diff: common/cmd_cros_bootstub.c

Issue 6650024: Factor out read_firmware_device() (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/u-boot-next.git@chromeos-v2010.09
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 | « no previous file | include/chromeos/firmware_storage.h » ('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 * Copyright (c) 2011 The Chromium OS Authors. All rights reserved. 2 * Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be 3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file. 4 * found in the LICENSE file.
5 * 5 *
6 * Alternatively, this software may be distributed under the terms of the 6 * Alternatively, this software may be distributed under the terms of the
7 * GNU General Public License ("GPL") version 2 as published by the Free 7 * GNU General Public License ("GPL") version 2 as published by the Free
8 * Software Foundation. 8 * Software Foundation.
9 */ 9 */
10 10
(...skipping 16 matching lines...) Expand all
27 if (return_code != 0) \ 27 if (return_code != 0) \
28 printf(PREFIX "%s failed, returning %d\n", \ 28 printf(PREFIX "%s failed, returning %d\n", \
29 #action, return_code); \ 29 #action, return_code); \
30 } while (0) 30 } while (0)
31 31
32 #define FIRMWARE_RECOVERY 0 32 #define FIRMWARE_RECOVERY 0
33 #define FIRMWARE_A 1 33 #define FIRMWARE_A 1
34 #define FIRMWARE_B 2 34 #define FIRMWARE_B 2
35 35
36 /* 36 /*
37 * Read <count> bytes, starting from <offset>, from firmware storage
38 * device <file> into buffer <buf>.
39 *
40 * Return 0 on success, non-zero on error.
41 */
42 int read_firmware_device(firmware_storage_t *file, off_t offset, void *buf,
43 size_t count)
44 {
45 ssize_t size;
46
47 if (file->seek(file->context, offset, SEEK_SET) < 0) {
48 debug(PREFIX "seek to address 0x%08x fail\n", offset);
49 return -1;
50 }
51
52 size = 0;
53 while (count > 0 &&
54 (size = file->read(file->context, buf, count)) > 0) {
55 count -= size;
56 buf += size;
57 }
58
59 if (size < 0) {
60 debug(PREFIX "an error occur when read firmware: %d\n", size);
61 return -1;
62 }
63
64 if (count > 0) {
65 debug(PREFIX "cannot read all data: %d\n", count);
66 return -1;
67 }
68
69 return 0;
70 }
71
72 /*
73 * Read verification block on <vblock_offset> from <file>. 37 * Read verification block on <vblock_offset> from <file>.
74 * 38 *
75 * The pointer to verification block is stored in <vblock_ptr>, and the size of 39 * The pointer to verification block is stored in <vblock_ptr>, and the size of
76 * the block is stored in <vblock_size_ptr>. 40 * the block is stored in <vblock_size_ptr>.
77 * 41 *
78 * On success, the space for storing verification block is malloc()'ed, and has 42 * On success, the space for storing verification block is malloc()'ed, and has
79 * to be free()'ed by the caller. 43 * to be free()'ed by the caller.
80 * 44 *
81 * Return 0 if success, non-zero if fail. 45 * Return 0 if success, non-zero if fail.
82 */ 46 */
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 firmware_data = malloc(CONFIG_LENGTH_RECOVERY); 331 firmware_data = malloc(CONFIG_LENGTH_RECOVERY);
368 WARN_ON_FAILURE(load_firmware_data(firmware_data)); 332 WARN_ON_FAILURE(load_firmware_data(firmware_data));
369 jump_to_firmware((void (*)(void)) firmware_data); 333 jump_to_firmware((void (*)(void)) firmware_data);
370 334
371 debug(PREFIX "error: should never reach here!\n"); 335 debug(PREFIX "error: should never reach here!\n");
372 return 1; 336 return 1;
373 } 337 }
374 338
375 U_BOOT_CMD(cros_bootstub, 1, 1, do_cros_bootstub, "verified boot stub firmware", 339 U_BOOT_CMD(cros_bootstub, 1, 1, do_cros_bootstub, "verified boot stub firmware",
376 NULL); 340 NULL);
OLDNEW
« no previous file with comments | « no previous file | include/chromeos/firmware_storage.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698