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

Side by Side Diff: set.c

Issue 6579034: Add the device type/parameters support for cbootimage tool. (Closed) Base URL: http://git.chromium.org/git/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 | « set.h ('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) 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.
11 * 11 *
12 * This program is distributed in the hope that it will be useful, 12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details. 15 * GNU General Public License for more details.
16 * 16 *
17 * You should have received a copy of the GNU General Public License 17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software 18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 * MA 02111-1307 USA 20 * MA 02111-1307 USA
21 */ 21 */
22 22
23 /* 23 /*
24 * set.c - State setting support for the cbootimage tool 24 * set.c - State setting support for the cbootimage tool
25 */ 25 */
26 26
27 #include <math.h>
27 #include "set.h" 28 #include "set.h"
28 #include "cbootimage.h" 29 #include "cbootimage.h"
29 #include "crypto.h" 30 #include "crypto.h"
30 #include "data_layout.h" 31 #include "data_layout.h"
31 32
32 /* 33 /*
33 * Function prototypes 34 * Function prototypes
34 * 35 *
35 * ParseXXX() parses XXX in the input 36 * ParseXXX() parses XXX in the input
36 * SetXXX() sets state based on the parsing results but does not perform 37 * SetXXX() sets state based on the parsing results but does not perform
37 * any parsing of its own 38 * any parsing of its own
38 * A ParseXXX() function may call other parse functions and set functions. 39 * A ParseXXX() function may call other parse functions and set functions.
39 * A SetXXX() function may not call any parseing functions. 40 * A SetXXX() function may not call any parseing functions.
40 */ 41 */
41 42
43 #define NV_MAX(a, b) (((a) > (b)) ? (a) : (b))
44
45 #define CASE_DEVICE_VALUE(prefix, id) \
46 case token_##id: \
47 (void)context->bctlib.setdev_param(index, \
48 nvbct_lib_id_##prefix##_##id, \
49 value, \
50 context->bct); \
51 break
52
53 #define DEFAULT() \
54 default: \
55 printf("Unexpected token %d at line %d\n", \
56 token, __LINE__); \
57 return 1
58
42 int 59 int
43 read_from_image(char *filename, 60 read_from_image(char *filename,
44 u_int32_t page_size, 61 u_int32_t page_size,
45 u_int8_t **image, 62 u_int8_t **image,
46 u_int32_t *storage_size, 63 u_int32_t *storage_size,
47 u_int32_t *actual_size, 64 u_int32_t *actual_size,
48 file_type f_type) 65 file_type f_type)
49 { 66 {
50 int result = 0; /* 0 = success, 1 = failure */ 67 int result = 0; /* 0 = success, 1 = failure */
51 FILE *fp; 68 FILE *fp;
52 struct stat stats; 69 struct stat stats;
53 70
54 fp = fopen(filename, "r"); 71 fp = fopen(filename, "r");
55 if (fp == NULL) { 72 if (fp == NULL) {
56 result = 1; 73 result = 1;
57 return result; 74 return result;
58 } 75 }
59 76
60 if (stat(filename, &stats) != 0) { 77 if (stat(filename, &stats) != 0) {
61 printf("Error: Unable to query info on bootloader path %s\n", 78 printf("Error: Unable to query info on bootloader path %s\n",
62 » » filename); 79 » » » filename);
63 result = 1; 80 result = 1;
64 goto cleanup; 81 goto cleanup;
65 } 82 }
66 83
67 *actual_size = (u_int32_t)stats.st_size; 84 *actual_size = (u_int32_t)stats.st_size;
68 *storage_size = 85 *storage_size =
69 (u_int32_t)(ICEIL(stats.st_size, page_size) * page_size); 86 (u_int32_t)(ICEIL(stats.st_size, page_size) * page_size);
70 87
71 if (f_type == file_type_bl) { 88 if (f_type == file_type_bl) {
72 if (stats.st_size > MAX_BOOTLOADER_SIZE) { 89 if (stats.st_size > MAX_BOOTLOADER_SIZE) {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 assert(context->bct != NULL); 157 assert(context->bct != NULL);
141 158
142 switch (token) { 159 switch (token) {
143 case token_attribute: 160 case token_attribute:
144 (void)context->bctlib.setbl_param(index, 161 (void)context->bctlib.setbl_param(index,
145 nvbct_lib_id_bl_attribute, 162 nvbct_lib_id_bl_attribute,
146 &value, 163 &value,
147 context->bct); 164 context->bct);
148 break; 165 break;
149 166
150 » » DEFAULT(); 167 » case token_dev_type:
168 » » (void)context->bctlib.setdev_param(index,
169 » » » » nvbct_lib_id_dev_type,
170 » » » » value,
171 » » » » context->bct);
172 » » break;
173
174 » DEFAULT();
151 } 175 }
152 return 0; 176 return 0;
153 } 177 }
154 178
155 /* 179 /*
156 * context_set_value(): General handler for setting values in config files. 180 * context_set_value(): General handler for setting values in config files.
157 */ 181 */
158 int context_set_value(build_image_context *context, 182 int context_set_value(build_image_context *context,
159 parse_token token, 183 parse_token token,
160 u_int32_t value) 184 u_int32_t value)
161 { 185 {
162 assert(context != NULL); 186 assert(context != NULL);
163 187
164 switch (token) { 188 switch (token) {
165 case token_attribute: 189 case token_attribute:
166 context->newbl_attr = value; 190 context->newbl_attr = value;
167 break; 191 break;
168 192
193 case token_block_size:
194 context->block_size = value;
195 context->block_size_log2 = log2(value);
196
197 if (context->memory != NULL) {
198 printf("Error: Too late to change block size.\n");
199 return 1;
200 }
201
202 if (value != (u_int32_t)(1 << context->block_size_log2)) {
203 printf("Error: Block size must be a power of 2.\n");
204 return 1;
205 }
206 context->pages_per_blk= 1 << (context->block_size_log2-
207 context->page_size_log2);
208 SET_VALUE(block_size_log2, context->block_size_log2);
209 break;
210
211 case token_partition_size:
212 if (context->memory != NULL) {
213 printf("Error: Too late to change block size.\n");
214 return 1;
215 }
216
217 context->partition_size= value;
218 SET_VALUE(partition_size, value);
219 break;
220
169 case token_page_size: 221 case token_page_size:
170 context->page_size = value; 222 context->page_size = value;
223 context->page_size_log2 = log2(value);
224 context->pages_per_blk= 1 << (context->block_size_log2-
225 context->page_size_log2);
226
227 SET_VALUE(page_size_log2, context->page_size_log2);
171 break; 228 break;
172 case token_redundancy: 229 case token_redundancy:
173 context->redundancy = value; 230 context->redundancy = value;
174 break; 231 break;
175 232
176 case token_version: 233 case token_version:
177 context->version = value; 234 context->version = value;
178 break; 235 break;
179 236
180 DEFAULT(); 237 DEFAULT();
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 else 354 else
298 memcpy((*current)->item.reserve, 355 memcpy((*current)->item.reserve,
299 other_str, 16); 356 other_str, 16);
300 } else 357 } else
301 current = &((*current)->next); 358 current = &((*current)->next);
302 } 359 }
303 return 0; 360 return 0;
304 361
305 } 362 }
306 363
364 static void
365 update_num_param_sets(build_image_context *context, u_int32_t index)
366 {
367 u_int32_t num_params;
368
369 GET_VALUE(num_param_sets, &num_params);
370 num_params = NV_MAX(num_params, index + 1);
371 SET_VALUE(num_param_sets, num_params);
372 }
373
374 /*
375 * set_sdmmc_param(): Processes commands to set MoviNand parameters.
376 */
377 int
378 set_sdmmc_param(build_image_context *context,
379 u_int32_t index,
380 parse_token token,
381 u_int32_t value)
382 {
383 assert(context != NULL);
384 assert(context->bct != NULL);
385
386 update_num_param_sets(context, index);
387
388 switch (token) {
389 CASE_DEVICE_VALUE(sdmmc, clock_divider);
390 CASE_DEVICE_VALUE(sdmmc, data_width);
391 CASE_DEVICE_VALUE(sdmmc, max_power_class_supported);
392 DEFAULT();
393 }
394
395 return 0;
396 }
397
398 /*
399 * set_spiflash_param(): Processes commands to set SpiFlash parameters.
400 */
401 int
402 set_spiflash_param(build_image_context *context,
403 u_int32_t index,
404 parse_token token,
405 u_int32_t value)
406 {
407 assert(context != NULL);
408 assert(context->bct != NULL);
409
410 update_num_param_sets(context, index);
411
412 switch (token) {
413 CASE_DEVICE_VALUE(spiflash, clock_divider);
414 CASE_DEVICE_VALUE(spiflash, clock_source);
415 CASE_DEVICE_VALUE(spiflash, read_command_type_fast);
416 DEFAULT();
417 }
418
419 return 0;
420 }
OLDNEW
« no previous file with comments | « set.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698