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

Side by Side Diff: parse.c

Issue 6625006: Add the SDRAM parameters support for cbootimage. (Closed) Base URL: http://git.chromium.org/git/cbootimage.git@master
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 | « parse.h ('k') | set.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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 parse_value_u32(build_image_context *context, parse_token token, char *rest); 73 parse_value_u32(build_image_context *context, parse_token token, char *rest);
74 static int 74 static int
75 parse_bct_file(build_image_context *context, parse_token token, char *rest); 75 parse_bct_file(build_image_context *context, parse_token token, char *rest);
76 static int 76 static int
77 parse_addon(build_image_context *context, parse_token token, char *rest); 77 parse_addon(build_image_context *context, parse_token token, char *rest);
78 static char *parse_string(char *statement, char *uname, int chars_remaining); 78 static char *parse_string(char *statement, char *uname, int chars_remaining);
79 static char 79 static char
80 *parse_end_state(char *statement, char *uname, int chars_remaining); 80 *parse_end_state(char *statement, char *uname, int chars_remaining);
81 static int 81 static int
82 parse_dev_param(build_image_context *context, parse_token token, char *rest); 82 parse_dev_param(build_image_context *context, parse_token token, char *rest);
83 static int
84 parse_sdram_param(build_image_context *context, parse_token token, char *rest);
83 85
84 static int process_statement(build_image_context *context, char *statement); 86 static int process_statement(build_image_context *context, char *statement);
85 87
86 static enum_item s_devtype_table[] = 88 static enum_item s_devtype_table[] =
87 { 89 {
88 { "NvBootDevType_Sdmmc", nvbct_lib_id_dev_type_sdmmc }, 90 { "NvBootDevType_Sdmmc", nvbct_lib_id_dev_type_sdmmc },
89 { "NvBootDevType_Spi", nvbct_lib_id_dev_type_spi }, 91 { "NvBootDevType_Spi", nvbct_lib_id_dev_type_spi },
90 { "NvBootDevType_Nand", nvbct_lib_id_dev_type_nand }, 92 { "NvBootDevType_Nand", nvbct_lib_id_dev_type_nand },
91 { "Sdmmc", nvbct_lib_id_dev_type_sdmmc }, 93 { "Sdmmc", nvbct_lib_id_dev_type_sdmmc },
92 { "Spi", nvbct_lib_id_dev_type_spi }, 94 { "Spi", nvbct_lib_id_dev_type_spi },
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 138
137 139
138 { "PllPOut0", nvbct_lib_id_spi_clock_source_pllp_out0 }, 140 { "PllPOut0", nvbct_lib_id_spi_clock_source_pllp_out0 },
139 { "PllCOut0", nvbct_lib_id_spi_clock_source_pllc_out0 }, 141 { "PllCOut0", nvbct_lib_id_spi_clock_source_pllc_out0 },
140 { "PllMOut0", nvbct_lib_id_spi_clock_source_pllm_out0 }, 142 { "PllMOut0", nvbct_lib_id_spi_clock_source_pllm_out0 },
141 { "ClockM", nvbct_lib_id_spi_clock_source_clockm }, 143 { "ClockM", nvbct_lib_id_spi_clock_source_clockm },
142 144
143 { NULL, 0 } 145 { NULL, 0 }
144 }; 146 };
145 147
148 static enum_item s_nvboot_memory_type_table[] =
149 {
150 { "NvBootMemoryType_None", nvbct_lib_id_memory_type_none },
151 { "NvBootMemoryType_Ddr2", nvbct_lib_id_memory_type_ddr2 },
152 { "NvBootMemoryType_Ddr", nvbct_lib_id_memory_type_ddr },
153 { "NvBootMemoryType_LpDdr2", nvbct_lib_id_memory_type_lpddr2 },
154 { "NvBootMemoryType_LpDdr", nvbct_lib_id_memory_type_lpddr },
155
156 { "None", nvbct_lib_id_memory_type_none },
157 { "Ddr2", nvbct_lib_id_memory_type_ddr2 },
158 { "Ddr", nvbct_lib_id_memory_type_ddr },
159 { "LpDdr2", nvbct_lib_id_memory_type_lpddr2 },
160 { "LpDdr", nvbct_lib_id_memory_type_lpddr },
161
162 { NULL, 0 }
163 };
164
165 static field_item s_sdram_field_table[] =
166 {
167 { "MemoryType", token_memory_type,
168 field_type_enum, s_nvboot_memory_type_table },
169 { "PllMChargePumpSetupControl", token_pllm_charge_pump_setup_ctrl,
170 field_type_u32, NULL },
171 { "PllMLoopFilterSetupControl", token_pllm_loop_filter_setup_ctrl,
172 field_type_u32, NULL },
173 { "PllMInputDivider", token_pllm_input_divider,
174 field_type_u32, NULL },
175 { "PllMFeedbackDivider", token_pllm_feedback_divider,
176 field_type_u32, NULL },
177 { "PllMPostDivider", token_pllm_post_divider,
178 field_type_u32, NULL },
179 { "PllMStableTime", token_pllm_stable_time,
180 field_type_u32, NULL },
181 { "EmcClockDivider", token_emc_clock_divider,
182 field_type_u32, NULL },
183 { "EmcAutoCalInterval", token_emc_auto_cal_interval,
184 field_type_u32, NULL },
185 { "EmcAutoCalConfig", token_emc_auto_cal_config,
186 field_type_u32, NULL },
187 { "EmcAutoCalWait", token_emc_auto_cal_wait,
188 field_type_u32, NULL },
189 { "EmcPinProgramWait", token_emc_pin_program_wait,
190 field_type_u32, NULL },
191 { "EmcRc", token_emc_rc,
192 field_type_u32, NULL },
193 { "EmcRfc", token_emc_rfc,
194 field_type_u32, NULL },
195 { "EmcRas", token_emc_ras,
196 field_type_u32, NULL },
197 { "EmcRp", token_emc_rp,
198 field_type_u32, NULL },
199 { "EmcR2w", token_emc_r2w,
200 field_type_u32, NULL },
201 { "EmcW2r", token_emc_w2r,
202 field_type_u32, NULL },
203 { "EmcR2p", token_emc_r2p,
204 field_type_u32, NULL },
205 { "EmcW2p", token_emc_w2p,
206 field_type_u32, NULL },
207 { "EmcRrd", token_emc_rrd,
208 field_type_u32, NULL },
209 { "EmcRdRcd", token_emc_rd_rcd,
210 field_type_u32, NULL },
211 { "EmcWrRcd", token_emc_wr_rcd,
212 field_type_u32, NULL },
213 { "EmcRext", token_emc_rext,
214 field_type_u32, NULL },
215 { "EmcWdv", token_emc_wdv,
216 field_type_u32, NULL },
217 { "EmcQUseExtra", token_emc_quse_extra,
218 field_type_u32, NULL },
219 { "EmcQUse", token_emc_quse,
220 field_type_u32, NULL },
221 { "EmcQRst", token_emc_qrst,
222 field_type_u32, NULL },
223 { "EmcQSafe", token_emc_qsafe,
224 field_type_u32, NULL },
225 { "EmcRdv", token_emc_rdv,
226 field_type_u32, NULL },
227 { "EmcRefresh", token_emc_refresh,
228 field_type_u32, NULL },
229 { "EmcBurstRefreshNum", token_emc_burst_refresh_num,
230 field_type_u32, NULL },
231 { "EmcPdEx2Wr", token_emc_pdex2wr,
232 field_type_u32, NULL },
233 { "EmcPdEx2Rd", token_emc_pdex2rd,
234 field_type_u32, NULL },
235 { "EmcPChg2Pden", token_emc_pchg2pden,
236 field_type_u32, NULL },
237 { "EmcAct2Pden", token_emc_act2pden,
238 field_type_u32, NULL },
239 { "EmcAr2Pden", token_emc_ar2pden,
240 field_type_u32, NULL },
241 { "EmcRw2Pden", token_emc_rw2pden,
242 field_type_u32, NULL },
243 { "EmcTxsr", token_emc_txsr,
244 field_type_u32, NULL },
245 { "EmcTcke", token_emc_tcke,
246 field_type_u32, NULL },
247 { "EmcTfaw", token_emc_tfaw,
248 field_type_u32, NULL },
249 { "EmcTrpab", token_emc_trpab,
250 field_type_u32, NULL },
251 { "EmcTClkStable", token_emc_tclkstable,
252 field_type_u32, NULL },
253 { "EmcTClkStop", token_emc_tclkstop,
254 field_type_u32, NULL },
255 { "EmcTRefBw", token_emc_trefbw,
256 field_type_u32, NULL },
257 { "EmcFbioCfg1", token_emc_fbio_cfg1,
258 field_type_u32, NULL },
259 { "EmcFbioDqsibDlyMsb", token_emc_fbio_dqsib_dly_msb,
260 field_type_u32, NULL },
261 { "EmcFbioDqsibDly", token_emc_fbio_dqsib_dly,
262 field_type_u32, NULL },
263 { "EmcFbioQuseDlyMsb", token_emc_fbio_quse_dly_msb,
264 field_type_u32, NULL },
265 { "EmcFbioQuseDly", token_emc_fbio_quse_dly,
266 field_type_u32, NULL },
267 { "EmcFbioCfg5", token_emc_fbio_cfg5,
268 field_type_u32, NULL },
269 { "EmcFbioCfg6", token_emc_fbio_cfg6,
270 field_type_u32, NULL },
271 { "EmcFbioSpare", token_emc_fbio_spare,
272 field_type_u32, NULL },
273 { "EmcMrsResetDllWait", token_emc_mrs_reset_dll_wait,
274 field_type_u32, NULL },
275 { "EmcMrsResetDll", token_emc_mrs_reset_dll,
276 field_type_u32, NULL },
277 { "EmcMrsDdr2DllReset", token_emc_mrs_ddr2_dll_reset,
278 field_type_u32, NULL },
279 { "EmcMrs", token_emc_mrs,
280 field_type_u32, NULL },
281 { "EmcEmrsEmr2", token_emc_emrs_emr2,
282 field_type_u32, NULL },
283 { "EmcEmrsEmr3", token_emc_emrs_emr3,
284 field_type_u32, NULL },
285 { "EmcEmrsDdr2DllEnable", token_emc_emrs_ddr2_dll_enable,
286 field_type_u32, NULL },
287 { "EmcEmrsDdr2OcdCalib", token_emc_emrs_ddr2_ocd_calib,
288 field_type_u32, NULL },
289 { "EmcEmrs", token_emc_emrs,
290 field_type_u32, NULL },
291 { "EmcMrw1", token_emc_mrw1,
292 field_type_u32, NULL },
293 { "EmcMrw2", token_emc_mrw2,
294 field_type_u32, NULL },
295 { "EmcMrw3", token_emc_mrw3,
296 field_type_u32, NULL },
297 { "EmcMrwResetCommand", token_emc_mrw_reset_command,
298 field_type_u32, NULL },
299 { "EmcMrwResetNInitWait", token_emc_mrw_reset_ninit_wait,
300 field_type_u32, NULL },
301 { "EmcAdrCfg1", token_emc_adr_cfg1,
302 field_type_u32, NULL },
303 { "EmcAdrCfg", token_emc_adr_cfg,
304 field_type_u32, NULL },
305 { "McEmemCfg", token_mc_emem_Cfg,
306 field_type_u32, NULL },
307 { "McLowLatencyConfig", token_mc_lowlatency_config,
308 field_type_u32, NULL },
309 { "EmcCfg2", token_emc_cfg2,
310 field_type_u32, NULL },
311 { "EmcCfgDigDll", token_emc_cfg_dig_dll,
312 field_type_u32, NULL },
313 { "EmcCfgClktrim0", token_emc_cfg_clktrim0,
314 field_type_u32, NULL },
315 { "EmcCfgClktrim1", token_emc_cfg_clktrim1,
316 field_type_u32, NULL },
317 { "EmcCfgClktrim2", token_emc_cfg_clktrim2,
318 field_type_u32, NULL },
319 { "EmcCfg", token_emc_cfg,
320 field_type_u32, NULL },
321 { "EmcDbg", token_emc_dbg,
322 field_type_u32, NULL },
323 { "AhbArbitrationXbarCtrl", token_ahb_arbitration_xbar_ctrl,
324 field_type_u32, NULL },
325 { "EmcDllXformDqs", token_emc_dll_xform_dqs,
326 field_type_u32, NULL },
327 { "EmcDllXformQUse", token_emc_dll_xform_quse,
328 field_type_u32, NULL },
329 { "WarmBootWait", token_warm_boot_wait,
330 field_type_u32, NULL },
331 { "EmcCttTermCtrl", token_emc_ctt_term_ctrl,
332 field_type_u32, NULL },
333 { "EmcOdtWrite", token_emc_odt_write,
334 field_type_u32, NULL },
335 { "EmcOdtRead", token_emc_odt_read,
336 field_type_u32, NULL },
337 { "EmcZcalRefCnt", token_emc_zcal_ref_cnt,
338 field_type_u32, NULL },
339 { "EmcZcalWaitCnt", token_emc_zcal_wait_cnt,
340 field_type_u32, NULL },
341 { "EmcZcalMrwCmd", token_emc_zcal_mrw_cmd,
342 field_type_u32, NULL },
343 { "EmcMrwZqInitDev0", token_emc_mrw_zq_init_dev0,
344 field_type_u32, NULL },
345 { "EmcMrwZqInitDev1", token_emc_mrw_zq_init_dev1,
346 field_type_u32, NULL },
347 { "EmcMrwZqInitWait", token_emc_mrw_zq_init_wait,
348 field_type_u32, NULL },
349 { "EmcDdr2Wait", token_emc_ddr2_wait,
350 field_type_u32, NULL },
351 { "PmcDdrPwr", token_pmc_ddr_pwr,
352 field_type_u32, NULL },
353 { "ApbMiscGpXm2CfgAPadCtrl", token_apb_misc_gp_xm2cfga_pad_ctrl,
354 field_type_u32, NULL },
355 { "ApbMiscGpXm2CfgCPadCtrl2", token_apb_misc_gp_xm2cfgc_pad_ctrl2,
356 field_type_u32, NULL },
357 { "ApbMiscGpXm2CfgCPadCtrl", token_apb_misc_gp_xm2cfgc_pad_ctrl,
358 field_type_u32, NULL },
359 { "ApbMiscGpXm2CfgDPadCtrl2", token_apb_misc_gp_xm2cfgd_pad_ctrl2,
360 field_type_u32, NULL },
361 { "ApbMiscGpXm2CfgDPadCtrl", token_apb_misc_gp_xm2cfgd_pad_ctrl,
362 field_type_u32, NULL },
363 { "ApbMiscGpXm2ClkCfgPadCtrl", token_apb_misc_gp_xm2clkcfg_Pad_ctrl,
364 field_type_u32, NULL },
365 { "ApbMiscGpXm2CompPadCtrl", token_apb_misc_gp_xm2comp_pad_ctrl,
366 field_type_u32, NULL },
367 { "ApbMiscGpXm2VttGenPadCtrl", token_apb_misc_gp_xm2vttgen_pad_ctrl
368 ,field_type_u32, NULL },
369
370 { NULL, 0, 0, NULL }
371 };
372
146 static field_item s_nand_table[] = 373 static field_item s_nand_table[] =
147 { 374 {
148 { "ClockDivider", token_clock_divider, field_type_u32, NULL }, 375 { "ClockDivider", token_clock_divider, field_type_u32, NULL },
149 /* Note: NandTiming2 must appear before NandTiming, because NandTiming 376 /* Note: NandTiming2 must appear before NandTiming, because NandTiming
150 * is a prefix of NandTiming2 and would otherwise match first. 377 * is a prefix of NandTiming2 and would otherwise match first.
151 */ 378 */
152 { "NandTiming2", token_nand_timing2, field_type_u32, NULL }, 379 { "NandTiming2", token_nand_timing2, field_type_u32, NULL },
153 { "NandTiming", token_nand_timing, field_type_u32, NULL }, 380 { "NandTiming", token_nand_timing, field_type_u32, NULL },
154 { "BlockSizeLog2", token_block_size_log2, field_type_u32, NULL }, 381 { "BlockSizeLog2", token_block_size_log2, field_type_u32, NULL },
155 { "PageSizeLog2", token_page_size_log2, field_type_u32, NULL }, 382 { "PageSizeLog2", token_page_size_log2, field_type_u32, NULL },
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 static parse_item s_top_level_items[] = 420 static parse_item s_top_level_items[] =
194 { 421 {
195 { "Bctfile=", token_bct_file, parse_bct_file }, 422 { "Bctfile=", token_bct_file, parse_bct_file },
196 { "Attribute=", token_attribute, parse_value_u32 }, 423 { "Attribute=", token_attribute, parse_value_u32 },
197 { "Attribute[", token_attribute, parse_array }, 424 { "Attribute[", token_attribute, parse_array },
198 { "PageSize=", token_page_size, parse_value_u32 }, 425 { "PageSize=", token_page_size, parse_value_u32 },
199 { "BlockSize=", token_block_size, parse_value_u32 }, 426 { "BlockSize=", token_block_size, parse_value_u32 },
200 { "PartitionSize=", token_partition_size, parse_value_u32 }, 427 { "PartitionSize=", token_partition_size, parse_value_u32 },
201 { "DevType[", token_dev_type, parse_array }, 428 { "DevType[", token_dev_type, parse_array },
202 { "DeviceParam[", token_dev_param, parse_dev_param }, 429 { "DeviceParam[", token_dev_param, parse_dev_param },
430 { "SDRAM[", token_sdram, parse_sdram_param },
203 { "BootLoader=", token_bootloader, parse_bootloader }, 431 { "BootLoader=", token_bootloader, parse_bootloader },
204 { "Redundancy=", token_redundancy, parse_value_u32 }, 432 { "Redundancy=", token_redundancy, parse_value_u32 },
205 { "Version=", token_version, parse_value_u32 }, 433 { "Version=", token_version, parse_value_u32 },
206 { "AddOn[", token_addon, parse_addon }, 434 { "AddOn[", token_addon, parse_addon },
207 { NULL, 0, NULL } /* Must be last */ 435 { NULL, 0, NULL } /* Must be last */
208 }; 436 };
209 437
210 /* Macro to simplify parser code a bit. */ 438 /* Macro to simplify parser code a bit. */
211 #define PARSE_COMMA(x) if (*rest != ',') return (x); rest++ 439 #define PARSE_COMMA(x) if (*rest != ',') return (x); rest++
212 440
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 if (rest == NULL) 917 if (rest == NULL)
690 return 1; 918 return 1;
691 return device_item->process(context, 919 return device_item->process(context,
692 index, field->token, value); 920 index, field->token, value);
693 } 921 }
694 } 922 }
695 923
696 return 1; 924 return 1;
697 925
698 } 926 }
927
928 static int
929 parse_sdram_param(build_image_context *context, parse_token token, char *rest)
930 {
931 u_int32_t value;
932 field_item *field;
933 u_int32_t index;
934
935 assert(context != NULL);
936 assert(rest != NULL);
937
938 /* Parse the index. */
939 rest = parse_u32(rest, &index);
940 if (rest == NULL)
941 return 1;
942
943 /* Parse the closing bracket. */
944 if (*rest != ']')
945 return 1;
946 rest++;
947
948 /* Parse the following '.' */
949 if (*rest != '.')
950 return 1;
951 rest++;
952
953 /* Parse the field name. */
954 rest = parse_field_name(rest, s_sdram_field_table, &field);
955 if (rest == NULL)
956 return 1;
957
958 /* Parse the equals sign.*/
959 if (*rest != '=')
960 return 1;
961 rest++;
962
963 /* Parse the value based on the field table. */
964 rest = parse_field_value(context, rest, field, &value);
965 if (rest == NULL)
966 return 1;
967
968 /* Store the result. */
969 return set_sdram_param(context, index, field->token, value);
970
971 }
699 /* Return 0 on success, 1 on error */ 972 /* Return 0 on success, 1 on error */
700 static int 973 static int
701 process_statement(build_image_context *context, char *statement) 974 process_statement(build_image_context *context, char *statement)
702 { 975 {
703 int i; 976 int i;
704 char *rest; 977 char *rest;
705 978
706 for (i = 0; s_top_level_items[i].prefix != NULL; i++) { 979 for (i = 0; s_top_level_items[i].prefix != NULL; i++) {
707 if (!strncmp(s_top_level_items[i].prefix, statement, 980 if (!strncmp(s_top_level_items[i].prefix, statement,
708 strlen(s_top_level_items[i].prefix))) { 981 strlen(s_top_level_items[i].prefix))) {
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 break; 1093 break;
821 } 1094 }
822 } 1095 }
823 1096
824 return; 1097 return;
825 1098
826 error: 1099 error:
827 printf("Error parsing: %s\n", buffer); 1100 printf("Error parsing: %s\n", buffer);
828 exit(1); 1101 exit(1);
829 } 1102 }
OLDNEW
« no previous file with comments | « parse.h ('k') | set.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698