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

Side by Side Diff: nvbctlib_ap20.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 | « nvbctlib.h ('k') | nvboot_bct.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 10 matching lines...) Expand all
21 */ 21 */
22 22
23 #include "nvbctlib.h" 23 #include "nvbctlib.h"
24 #include "nvboot_bct.h" 24 #include "nvboot_bct.h"
25 #include "string.h" 25 #include "string.h"
26 #include "cbootimage.h" 26 #include "cbootimage.h"
27 27
28 /* nvbctlib_ap20.c: The implementation of the nvbctlib API for AP20. */ 28 /* nvbctlib_ap20.c: The implementation of the nvbctlib API for AP20. */
29 29
30 /* Definitions that simplify the code which follows. */ 30 /* Definitions that simplify the code which follows. */
31 #define CASE_GET_DEV_PARAM(dev, x) \
32 case nvbct_lib_id_##dev##_##x:\
33 *data = bct_ptr->dev_params[set].dev##_params.x; \
34 break
35
36 #define CASE_SET_DEV_PARAM(dev, x) \
37 case nvbct_lib_id_##dev##_##x:\
38 bct_ptr->dev_params[set].dev##_params.x = data; \
39 break
40
31 #define CASE_GET_BL_PARAM(x) \ 41 #define CASE_GET_BL_PARAM(x) \
32 case nvbct_lib_id_bl_##x:\ 42 case nvbct_lib_id_bl_##x:\
33 *data = bct_ptr->bootloader[set].x; \ 43 *data = bct_ptr->bootloader[set].x; \
34 break 44 break
35 45
36 #define CASE_SET_BL_PARAM(x) \ 46 #define CASE_SET_BL_PARAM(x) \
37 case nvbct_lib_id_bl_##x:\ 47 case nvbct_lib_id_bl_##x:\
38 bct_ptr->bootloader[set].x = *data; \ 48 bct_ptr->bootloader[set].x = *data; \
39 break 49 break
40 50
41 #define CASE_GET_NVU32(id) \ 51 #define CASE_GET_NVU32(id) \
42 case nvbct_lib_id_##id:\ 52 case nvbct_lib_id_##id:\
43 if (bct == NULL) return -ENODATA; \ 53 if (bct == NULL) return -ENODATA; \
44 *data = bct_ptr->id; \ 54 *data = bct_ptr->id; \
45 break 55 break
46 56
47 #define CASE_GET_CONST(id, val) \ 57 #define CASE_GET_CONST(id, val) \
48 case nvbct_lib_id_##id:\ 58 case nvbct_lib_id_##id:\
49 *data = val; \ 59 *data = val; \
50 break 60 break
51 61
52 #define CASE_GET_CONST_PREFIX(id, val_prefix) \ 62 #define CASE_GET_CONST_PREFIX(id, val_prefix) \
53 case nvbct_lib_id_##id:\ 63 case nvbct_lib_id_##id:\
54 » *data = val_prefix##id; \ 64 » *data = val_prefix##_##id; \
55 break 65 break
56 66
57 #define CASE_SET_NVU32(id) \ 67 #define CASE_SET_NVU32(id) \
58 case nvbct_lib_id_##id:\ 68 case nvbct_lib_id_##id:\
59 bct_ptr->id = data; \ 69 bct_ptr->id = data; \
60 break 70 break
61 71
62 #define CASE_GET_DATA(id, size) \ 72 #define CASE_GET_DATA(id, size) \
63 case nvbct_lib_id_##id:\ 73 case nvbct_lib_id_##id:\
64 if (*length < size) return -ENODATA;\ 74 if (*length < size) return -ENODATA;\
65 memcpy(data, &(bct_ptr->id), size); \ 75 memcpy(data, &(bct_ptr->id), size); \
66 *length = size;\ 76 *length = size;\
67 break 77 break
68 78
69 #define CASE_SET_DATA(id, size) \ 79 #define CASE_SET_DATA(id, size) \
70 case nvbct_lib_id_##id:\ 80 case nvbct_lib_id_##id:\
71 if (length < size) return -ENODATA;\ 81 if (length < size) return -ENODATA;\
72 memcpy(&(bct_ptr->id), data, size); \ 82 memcpy(&(bct_ptr->id), data, size); \
73 break 83 break
74 84
85 static int
86 getdev_param(u_int32_t set,
87 nvbct_lib_id id,
88 u_int32_t *data,
89 u_int8_t *bct)
90 {
91 nvboot_config_table *bct_ptr = (nvboot_config_table*)bct;
92
93 if (data == NULL || bct == NULL)
94 return -ENODATA;
95
96 switch (id) {
97 CASE_GET_DEV_PARAM(sdmmc, clock_divider);
98 CASE_GET_DEV_PARAM(sdmmc, data_width);
99 CASE_GET_DEV_PARAM(sdmmc, max_power_class_supported);
100
101 CASE_GET_DEV_PARAM(spiflash, clock_source);
102 CASE_GET_DEV_PARAM(spiflash, clock_divider);
103 CASE_GET_DEV_PARAM(spiflash, read_command_type_fast);
104
105 case nvbct_lib_id_dev_type:
106 *data = bct_ptr->dev_type[set];
107 break;
108
109 default:
110 return -ENODATA;
111 }
112
113 return 0;
114 }
115
116 static int
117 setdev_param(u_int32_t set,
118 nvbct_lib_id id,
119 u_int32_t data,
120 u_int8_t *bct)
121 {
122 nvboot_config_table *bct_ptr = (nvboot_config_table*)bct;
123
124 if (bct == NULL)
125 return -ENODATA;
126
127 switch (id) {
128 CASE_SET_DEV_PARAM(sdmmc, clock_divider);
129 CASE_SET_DEV_PARAM(sdmmc, data_width);
130 CASE_SET_DEV_PARAM(sdmmc, max_power_class_supported);
131
132 CASE_SET_DEV_PARAM(spiflash, clock_source);
133 CASE_SET_DEV_PARAM(spiflash, clock_divider);
134 CASE_SET_DEV_PARAM(spiflash, read_command_type_fast);
135
136 case nvbct_lib_id_dev_type:
137 bct_ptr->dev_type[set] = data;
138 break;
139
140 default:
141 return -ENODATA;
142 }
143
144 return 0;
145
146 }
75 147
76 static int 148 static int
77 getbl_param(u_int32_t set, 149 getbl_param(u_int32_t set,
78 nvbct_lib_id id, 150 nvbct_lib_id id,
79 u_int32_t *data, 151 u_int32_t *data,
80 u_int8_t *bct) 152 u_int8_t *bct)
81 { 153 {
82 nvboot_config_table *bct_ptr = (nvboot_config_table*)bct; 154 nvboot_config_table *bct_ptr = (nvboot_config_table*)bct;
83 155
84 if (set >= NVBOOT_MAX_BOOTLOADERS) 156 if (set >= NVBOOT_MAX_BOOTLOADERS)
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 return -ENODATA; 231 return -ENODATA;
160 232
161 switch (id) { 233 switch (id) {
162 /* 234 /*
163 * Simple BCT fields 235 * Simple BCT fields
164 */ 236 */
165 CASE_GET_NVU32(boot_data_version); 237 CASE_GET_NVU32(boot_data_version);
166 CASE_GET_NVU32(block_size_log2); 238 CASE_GET_NVU32(block_size_log2);
167 CASE_GET_NVU32(page_size_log2); 239 CASE_GET_NVU32(page_size_log2);
168 CASE_GET_NVU32(partition_size); 240 CASE_GET_NVU32(partition_size);
241 CASE_GET_NVU32(num_param_sets);
169 CASE_GET_NVU32(bootloader_used); 242 CASE_GET_NVU32(bootloader_used);
170 243
171 /* 244 /*
172 * Constants. 245 * Constants.
173 */ 246 */
174 247
175 CASE_GET_CONST(bootloaders_max, NVBOOT_MAX_BOOTLOADERS); 248 CASE_GET_CONST(bootloaders_max, NVBOOT_MAX_BOOTLOADERS);
176 CASE_GET_CONST(reserved_size, NVBOOT_BCT_RESERVED_SIZE); 249 CASE_GET_CONST(reserved_size, NVBOOT_BCT_RESERVED_SIZE);
177 250
178 case nvbct_lib_id_reserved_offset: 251 case nvbct_lib_id_reserved_offset:
(...skipping 13 matching lines...) Expand all
192 - (u_int8_t*)&samplebct; 265 - (u_int8_t*)&samplebct;
193 break; 266 break;
194 267
195 case nvbct_lib_id_crypto_length: 268 case nvbct_lib_id_crypto_length:
196 /* size of region in BCT to encrypt & sign */ 269 /* size of region in BCT to encrypt & sign */
197 *data = sizeof(nvboot_config_table) - sizeof(nvboot_hash); 270 *data = sizeof(nvboot_config_table) - sizeof(nvboot_hash);
198 break; 271 break;
199 272
200 CASE_GET_CONST(max_bct_search_blks, NVBOOT_MAX_BCT_SEARCH_BLOCKS); 273 CASE_GET_CONST(max_bct_search_blks, NVBOOT_MAX_BCT_SEARCH_BLOCKS);
201 274
275 CASE_GET_CONST_PREFIX(dev_type_sdmmc, nvboot);
276 CASE_GET_CONST_PREFIX(dev_type_spi, nvboot);
277 CASE_GET_CONST_PREFIX(sdmmc_data_width_4bit, nvboot);
278 CASE_GET_CONST_PREFIX(sdmmc_data_width_8bit, nvboot);
279 CASE_GET_CONST_PREFIX(spi_clock_source_pllp_out0, nvboot);
280 CASE_GET_CONST_PREFIX(spi_clock_source_pllc_out0, nvboot);
281 CASE_GET_CONST_PREFIX(spi_clock_source_pllm_out0, nvboot);
282 CASE_GET_CONST_PREFIX(spi_clock_source_clockm, nvboot);
283
202 default: 284 default:
203 return -ENODATA; 285 return -ENODATA;
204 } 286 }
205 return 0; 287 return 0;
206 } 288 }
207 289
208 static int 290 static int
209 bct_set_value(nvbct_lib_id id, u_int32_t data, u_int8_t *bct) 291 bct_set_value(nvbct_lib_id id, u_int32_t data, u_int8_t *bct)
210 { 292 {
211 nvboot_config_table *bct_ptr = (nvboot_config_table*)bct; 293 nvboot_config_table *bct_ptr = (nvboot_config_table*)bct;
212 294
213 if (bct == NULL) 295 if (bct == NULL)
214 return -ENODATA; 296 return -ENODATA;
215 297
216 switch (id) { 298 switch (id) {
217 /* 299 /*
218 * Simple BCT fields 300 * Simple BCT fields
219 */ 301 */
220 CASE_SET_NVU32(boot_data_version); 302 CASE_SET_NVU32(boot_data_version);
221 CASE_SET_NVU32(block_size_log2); 303 CASE_SET_NVU32(block_size_log2);
222 CASE_SET_NVU32(page_size_log2); 304 CASE_SET_NVU32(page_size_log2);
223 CASE_SET_NVU32(partition_size); 305 CASE_SET_NVU32(partition_size);
306 CASE_SET_NVU32(num_param_sets);
224 CASE_SET_NVU32(bootloader_used); 307 CASE_SET_NVU32(bootloader_used);
225 308
226 default: 309 default:
227 return -ENODATA; 310 return -ENODATA;
228 } 311 }
229 312
230 return 0; 313 return 0;
231 } 314 }
232 315
233 316
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 nvbct_lib_get_fns(nvbct_lib_fns *fns) 355 nvbct_lib_get_fns(nvbct_lib_fns *fns)
273 { 356 {
274 fns->get_value = bct_get_value; 357 fns->get_value = bct_get_value;
275 fns->set_value = bct_set_value; 358 fns->set_value = bct_set_value;
276 359
277 fns->get_data = bct_get_data; 360 fns->get_data = bct_get_data;
278 fns->set_data = bct_set_data; 361 fns->set_data = bct_set_data;
279 362
280 fns->getbl_param = getbl_param; 363 fns->getbl_param = getbl_param;
281 fns->setbl_param = setbl_param; 364 fns->setbl_param = setbl_param;
365
366 fns->getdev_param = getdev_param;
367 fns->setdev_param = setdev_param;
368
282 } 369 }
OLDNEW
« no previous file with comments | « nvbctlib.h ('k') | nvboot_bct.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698