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

Side by Side Diff: cbootimage.c

Issue 6469010: Factor out the context specific functions into their own file. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/cbootimage.git@master
Patch Set: 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
« no previous file with comments | « GNUmakefile ('k') | context.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 NVIDIA Corporation. All rights reserved. 2 * Copyright (c) 2011 NVIDIA Corporation. All rights reserved.
3 * 3 *
4 * See file CREDITS for list of people who contributed to this 4 * See file CREDITS for list of people who contributed to this
5 * project. 5 * project.
6 * 6 *
7 * This program is free software; you can redistribute it and/or 7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as 8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of 9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version. 10 * the License, or (at your option) any later version.
(...skipping 12 matching lines...) Expand all
23 /* 23 /*
24 * cbootimage.c - Implementation of the cbootimage tool. 24 * cbootimage.c - Implementation of the cbootimage tool.
25 */ 25 */
26 26
27 #include "cbootimage.h" 27 #include "cbootimage.h"
28 #include "nvbctlib.h" 28 #include "nvbctlib.h"
29 #include "crypto.h" 29 #include "crypto.h"
30 #include "data_layout.h" 30 #include "data_layout.h"
31 #include "parse.h" 31 #include "parse.h"
32 #include "set.h" 32 #include "set.h"
33 #include "context.h"
33 34
34 /* 35 /*
35 * Global data 36 * Global data
36 */ 37 */
37 int enable_debug = 0; 38 int enable_debug = 0;
38 39
39 static int help_only = 0; // Only print help & exit 40 static int help_only = 0; // Only print help & exit
40 41
41 /* 42 /*
42 * Function prototypes 43 * Function prototypes
43 */ 44 */
44 int main(int argc, char *argv[]); 45 int main(int argc, char *argv[]);
45 46
46 static int
47 query_alloc(build_image_context *context,
48 nvbct_lib_id size_id,
49 u_int8_t **dst)
50 {
51 u_int32_t size;
52
53 /* Note: 3rd argument not used in this particular query. */
54 if (context->bctlib.get_value(size_id,
55 &size, context->bct) != 0)
56 return -ENODATA;
57 *dst = malloc(size);
58
59 if (*dst == NULL)
60 return -ENOMEM;
61
62 memset(*dst, 0, size);
63
64 return 0;
65 }
66
67 static void
68 cleanup_context(build_image_context *context)
69 {
70 destroy_block_list(context->memory);
71 destroy_addon_list(context->addon_tbl.addon_item_list);
72 free(context->bct);
73 }
74
75 static int
76 init_context(build_image_context *context)
77 {
78 int e = 0;
79
80 /* Set defaults */
81 context->memory = new_block_list();
82 context->journal_blk = 1; /* Default to 1st block */
83
84 /* Allocate space for the bct.
85 * Note that this is different from the old code which pointed directly
86 * into a memory image.
87 */
88 e = query_alloc(context, nvbct_lib_id_bct_size, &(context->bct));
89 if (e != 0)
90 goto fail;
91
92 context_set_value(context, token_page_size, 2048);
93 context_set_value(context, token_redundancy, 1);
94 context_set_value(context, token_version, 1);
95
96 return 0;
97
98 fail:
99 cleanup_context(context);
100
101 return e;
102 }
103
104 int 47 int
105 write_image_file(build_image_context *context) 48 write_image_file(build_image_context *context)
106 { 49 {
107 assert(context != NULL); 50 assert(context != NULL);
108 51
109 return write_block_raw(context); 52 return write_block_raw(context);
110 } 53 }
111 54
112 static void 55 static void
113 usage(void) 56 usage(void)
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 fail: 192 fail:
250 /* Close the file(s). */ 193 /* Close the file(s). */
251 if (context.raw_file) 194 if (context.raw_file)
252 fclose(context.raw_file); 195 fclose(context.raw_file);
253 196
254 /* Clean up memory. */ 197 /* Clean up memory. */
255 cleanup_context(&context); 198 cleanup_context(&context);
256 199
257 return e; 200 return e;
258 } 201 }
OLDNEW
« no previous file with comments | « GNUmakefile ('k') | context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698