* [cbootimage PATCH 1/3] Allow users to specify the handler to process special configuration
@ 2014-01-28 7:24 Vince Hsu
[not found] ` <1390893857-18716-1-git-send-email-vinceh-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
0 siblings, 1 reply; 4+ messages in thread
From: Vince Hsu @ 2014-01-28 7:24 UTC (permalink / raw)
To: swarren-DDmLM1+adcrQT0dZR+AlfA
Cc: linux-tegra-u79uwXL29TY76Z2rM5mHXA, Vince Hsu
Signed-off-by: Vince Hsu <vinceh-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
---
src/cbootimage.c | 4 ++--
src/parse.c | 13 +++++++++----
src/parse.h | 3 ++-
3 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/src/cbootimage.c b/src/cbootimage.c
index 1332c5f118b5..0fe164fa5421 100644
--- a/src/cbootimage.c
+++ b/src/cbootimage.c
@@ -200,14 +200,14 @@ main(int argc, char *argv[])
/* first, if we aren't generating the bct, read in config file */
if (context.generate_bct == 0) {
- process_config_file(&context, 1);
+ process_config_file(&context, 1, NULL);
}
/* Generate the new bct file */
else {
/* Initialize the bct memory */
init_bct(&context);
/* Parse & process the contents of the config file. */
- process_config_file(&context, 0);
+ process_config_file(&context, 0, NULL);
/* Update the BCT */
begin_update(&context);
/* Signing the bct. */
diff --git a/src/parse.c b/src/parse.c
index 464ee8ff40e4..92490b8c5768 100644
--- a/src/parse.c
+++ b/src/parse.c
@@ -698,7 +698,8 @@ process_statement(build_image_context *context,
* @param context The main context pointer
* @param simple_parse Simple parse flag
*/
-void process_config_file(build_image_context *context, u_int8_t simple_parse)
+void process_config_file(build_image_context *context, u_int8_t simple_parse,
+ int (*special_handler)(build_image_context *context, char *buffer))
{
char buffer[MAX_BUFFER];
int space = 0;
@@ -707,6 +708,7 @@ void process_config_file(build_image_context *context, u_int8_t simple_parse)
u_int8_t comment = 0;
u_int8_t string = 0;
u_int8_t equal_encounter = 0;
+ int e;
assert(context != NULL);
assert(context->config_file != NULL);
@@ -737,11 +739,14 @@ void process_config_file(build_image_context *context, u_int8_t simple_parse)
case ';':
if (!string && !comment) {
buffer[space++] = '\0';
+ if (special_handler)
+ e = special_handler(context, buffer);
+ else
+ e = process_statement(context, buffer, simple_parse);
- if (process_statement(context,
- buffer,
- simple_parse))
+ if (e)
goto error;
+
space = 0;
equal_encounter = 0;
} else if (string)
diff --git a/src/parse.h b/src/parse.h
index 80f42c4269b1..239946c7fa7a 100644
--- a/src/parse.h
+++ b/src/parse.h
@@ -763,7 +763,8 @@ typedef struct cbootimage_soc_config_rec {
parse_subfield_item *device_type_table;
} cbootimage_soc_config;
-void process_config_file(build_image_context *context, u_int8_t simple_parse);
+void process_config_file(build_image_context *context, u_int8_t simple_parse,
+ int (*special_handler)(build_image_context *context, char *buffer));
void t124_get_soc_config(build_image_context *context,
cbootimage_soc_config **soc_config);
--
1.8.1.5
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [cbootimage PATCH 2/3] Export several parsing functions for external use
[not found] ` <1390893857-18716-1-git-send-email-vinceh-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
@ 2014-01-28 7:24 ` Vince Hsu
2014-01-28 7:24 ` [cbootimage PATCH 3/3] Implement the utility gen_sdram_array Vince Hsu
1 sibling, 0 replies; 4+ messages in thread
From: Vince Hsu @ 2014-01-28 7:24 UTC (permalink / raw)
To: swarren-DDmLM1+adcrQT0dZR+AlfA
Cc: linux-tegra-u79uwXL29TY76Z2rM5mHXA, Vince Hsu
Signed-off-by: Vince Hsu <vinceh-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
---
src/parse.c | 14 +++-----------
src/parse.h | 7 +++++++
2 files changed, 10 insertions(+), 11 deletions(-)
diff --git a/src/parse.c b/src/parse.c
index 92490b8c5768..ac2c183595f1 100644
--- a/src/parse.c
+++ b/src/parse.c
@@ -43,20 +43,12 @@ set_array(build_image_context *context,
u_int32_t index,
parse_token token,
u_int32_t value);
-static char *parse_u32(char *str, u_int32_t *val);
static char *parse_u8(char *str, u_int32_t *val);
static char *parse_filename(char *str, char *name, int chars_remaining);
static char *parse_enum(build_image_context *context,
char *str,
enum_item *table,
u_int32_t *val);
-static char
-*parse_field_name(char *rest, field_item *field_table, field_item **field);
-static char
-*parse_field_value(build_image_context *context,
- char *rest,
- field_item *field,
- u_int32_t *value);
static int
parse_array(build_image_context *context, parse_token token, char *rest);
static int
@@ -115,7 +107,7 @@ static parse_item s_top_level_items[] = {
* @param val Returns value that was parsed
* @return the remainder of the string after the number was parsed
*/
-static char *
+char *
parse_u32(char *str, u_int32_t *val)
{
u_int32_t value = 0;
@@ -206,7 +198,7 @@ parse_filename(char *str, char *name, int chars_remaining)
* @param field Returns the field item that was parsed
* @return NULL or the remainder of the string after the field item was parsed
*/
-static char
+char
*parse_field_name(char *rest, field_item *field_table, field_item **field)
{
u_int32_t i;
@@ -245,7 +237,7 @@ static char
* @param value Returns the value that was parsed
* @return the remainder of the string after the value was parsed
*/
-static char
+char
*parse_field_value(build_image_context *context,
char *rest,
field_item *field,
diff --git a/src/parse.h b/src/parse.h
index 239946c7fa7a..17bb3b90781b 100644
--- a/src/parse.h
+++ b/src/parse.h
@@ -921,4 +921,11 @@ extern parse_subfield_item s_device_type_table_t30[];
extern parse_subfield_item s_device_type_table_t114[];
extern parse_subfield_item s_device_type_table_t124[];
+char *parse_u32(char *str, u_int32_t *val);
+char *parse_field_name(char *rest, field_item *field_table, field_item **field);
+char *parse_field_value(build_image_context *context,
+ char *rest,
+ field_item *field,
+ u_int32_t *value);
+
#endif /* #ifndef INCLUDED_PARSE_H */
--
1.8.1.5
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [cbootimage PATCH 3/3] Implement the utility gen_sdram_array
[not found] ` <1390893857-18716-1-git-send-email-vinceh-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2014-01-28 7:24 ` [cbootimage PATCH 2/3] Export several parsing functions for external use Vince Hsu
@ 2014-01-28 7:24 ` Vince Hsu
[not found] ` <1390893857-18716-3-git-send-email-vinceh-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
1 sibling, 1 reply; 4+ messages in thread
From: Vince Hsu @ 2014-01-28 7:24 UTC (permalink / raw)
To: swarren-DDmLM1+adcrQT0dZR+AlfA
Cc: linux-tegra-u79uwXL29TY76Z2rM5mHXA, Vince Hsu
This patch implemtns the ubility to generate a header file from
multiple sdram config files which each has one set of sdram
parameters inside only.
Signed-off-by: Vince Hsu <vinceh-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
---
src/Makefile.am | 34 +++++-
src/gen_sdram_array.c | 305 ++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 338 insertions(+), 1 deletion(-)
create mode 100644 src/gen_sdram_array.c
diff --git a/src/Makefile.am b/src/Makefile.am
index a0b95a90750a..c16ae84609eb 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -2,7 +2,7 @@ AUTOMAKE_OPTIONS = subdir-objects
AM_CFLAGS = -Wall -std=c99
-bin_PROGRAMS = cbootimage bct_dump
+bin_PROGRAMS = cbootimage bct_dump gen_sdram_array
cbootimage_SOURCES = \
cbootimage.c \
data_layout.c \
@@ -68,3 +68,35 @@ bct_dump_SOURCES = \
t114/nvboot_sdram_param_t114.h \
t124/nvboot_bct_t124.h \
t124/nvboot_sdram_param_t124.h
+
+gen_sdram_array_SOURCES = \
+ gen_sdram_array.c \
+ data_layout.c \
+ set.c \
+ crypto.c \
+ aes_ref.c \
+ context.c \
+ parse.c \
+ t124/parse_t124.c \
+ t114/parse_t114.c \
+ t30/parse_t30.c \
+ t20/parse_t20.c \
+ t124/nvbctlib_t124.c \
+ t114/nvbctlib_t114.c \
+ t30/nvbctlib_t30.c \
+ t20/nvbctlib_t20.c \
+ cbootimage.h \
+ context.h \
+ crypto.h \
+ data_layout.h \
+ nvaes_ref.h \
+ parse.h \
+ set.h \
+ t20/nvboot_bct_t20.h \
+ t20/nvboot_sdram_param_t20.h \
+ t30/nvboot_bct_t30.h \
+ t30/nvboot_sdram_param_t30.h \
+ t114/nvboot_bct_t114.h \
+ t114/nvboot_sdram_param_t114.h \
+ t124/nvboot_bct_t124.h \
+ t124/nvboot_sdram_param_t124.h
diff --git a/src/gen_sdram_array.c b/src/gen_sdram_array.c
new file mode 100644
index 000000000000..6e055387018b
--- /dev/null
+++ b/src/gen_sdram_array.c
@@ -0,0 +1,305 @@
+/*
+ * Copyright (c) 2014, NVIDIA CORPORATION. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ */
+
+#include "cbootimage.h"
+#include "crypto.h"
+#include "data_layout.h"
+#include "context.h"
+#include "parse.h"
+#include "t20/nvboot_bct_t20.h"
+#include <string.h>
+#include <strings.h>
+#include <getopt.h>
+
+#define MAX_SDRAM_NUM 16
+
+struct sdram_config_file {
+ FILE *file;
+ char file_name[MAX_STR_LEN];
+};
+
+static int help_only; /* Only print help & exit */
+static struct sdram_config_file input_file[MAX_SDRAM_NUM];
+static int input_file_num;
+static FILE *output_file;
+static char output_file_name[MAX_STR_LEN];
+
+int enable_debug;
+cbootimage_soc_config * g_soc_config;
+
+static int parse_sdram(build_image_context *context, parse_token token,
+ char *rest);
+
+struct option cmd[] = {
+ {"help", 0, NULL, 'h'},
+ {"debug", 0, NULL, 'd'},
+ {"soc", 1, NULL, 's'},
+ {"input", 1, NULL, 'i'},
+ {"output", 1, NULL, 'o'},
+ {0, 0, 0, 0},
+};
+
+/* Only care about SDRAM items */
+static parse_item parse_sdram_items[] =
+{
+ { "SDRAM[", token_sdram, parse_sdram },
+ { NULL, 0, NULL } /* Must be last */
+};
+
+static void usage(void)
+{
+ printf("Usage: gen_sdram_array [options] configfile imagename\n");
+ printf(" options:\n");
+ printf(" -h, --help, -? Display this message.\n");
+ printf(" -d, --debug Output debugging information.\n");
+ printf(" -s|--soc tegraNN Select target device. Must be one of:\n");
+ printf(" tegra20, tegra30, tegra114, tegra124.\n");
+ printf(" Default: tegra20.\n");
+ printf(" -i configfile File with configuration information\n");
+ printf(" -o output file Output file name\n");
+}
+
+static int process_command_line(int argc, char *argv[],
+ build_image_context *context)
+{
+ int c;
+
+ while ((c = getopt_long(argc, argv, "hds:i:o:", cmd, NULL)) != -1) {
+ switch (c) {
+ case 'h':
+ help_only = 1;
+ usage();
+ return 0;
+ case 's':
+ if (strncmp("tegra", optarg, 5)) {
+ printf("Unsupported chipname!\n");
+ usage();
+ return -EINVAL;
+ }
+ optarg += 5;
+
+ /* Assign the soc_config based on the chip. */
+ if (!strcasecmp("20", optarg)) {
+ t20_get_soc_config(context, &g_soc_config);
+ } else if (!strcasecmp("30", optarg)) {
+ t30_get_soc_config(context, &g_soc_config);
+ } else if (!strcasecmp("114", optarg)) {
+ t114_get_soc_config(context, &g_soc_config);
+ } else if (!strcasecmp("124", optarg)) {
+ t124_get_soc_config(context, &g_soc_config);
+ } else {
+ printf("Unsupported chipname!\n");
+ usage();
+ return -EINVAL;
+ }
+ break;
+ case 'i':
+ if (input_file_num >= MAX_SDRAM_NUM) {
+ printf("Only support at most 16 input files\n");
+ return -EINVAL;
+ }
+ if (strlen(optarg) > MAX_STR_LEN - 1) {
+ printf("File name is limited to %d characters\n",
+ MAX_STR_LEN - 1);
+ return -EINVAL;
+ }
+ strncpy(input_file[input_file_num].file_name, optarg,
+ strlen(optarg));
+ input_file[input_file_num].file_name[strlen(optarg) + 1] = '\0';
+ input_file_num++;
+ break;
+ case 'o':
+ if (strlen(optarg) > MAX_STR_LEN - 1) {
+ printf("File name is limited to %d characters\n",
+ MAX_STR_LEN - 1);
+ return -EINVAL;
+ }
+ strncpy(output_file_name, optarg, strlen(optarg));
+ output_file_name[strlen(optarg) + 1] = '\0';
+ break;
+ }
+ }
+
+ if (!input_file_num || !strlen(output_file_name)) {
+ usage();
+ return -EINVAL;
+ }
+
+ /* If SoC is not specified, make the default soc_config to t20. */
+ if (!context->boot_data_version)
+ t20_get_soc_config(context, &g_soc_config);
+
+ return 0;
+}
+
+/*
+ * Parse the given string and find sdram parameter and value in config
+ * file. If match, call the corresponding function set the sdram parameter.
+ *
+ * @param context The main context pointer
+ * @param token The parse token value
+ * @param rest String to parse
+ * @return 0 and 1 for success and failure
+ */
+static int parse_sdram(build_image_context *context, parse_token token,
+ char *rest)
+{
+ u_int32_t value;
+ field_item *field;
+ u_int32_t index;
+
+ assert(context != NULL);
+ assert(rest != NULL);
+
+ /* Parse the index. */
+ rest = parse_u32(rest, &index);
+ if (rest == NULL)
+ return 1;
+
+ /* Parse the closing bracket. */
+ if (*rest != ']')
+ return 1;
+ rest++;
+
+ /* Parse the following '.' */
+ if (*rest != '.')
+ return 1;
+ rest++;
+
+ /* Parse the field name. */
+ rest = parse_field_name(rest, g_soc_config->sdram_field_table, &field);
+
+ if (rest == NULL)
+ return 1;
+
+ /* Parse the equals sign.*/
+ if (*rest != '=')
+ return 1;
+ rest++;
+
+ /* Parse the value based on the field table. */
+ rest = parse_field_value(context, rest, field, &value);
+ if (rest == NULL)
+ return 1;
+
+ fprintf(output_file, "\t.%s\t= 0x%08x,\n", field->name, value);
+
+ return 0;
+}
+
+static int process_sdram_config(build_image_context *context, char *str)
+{
+ int i;
+ char *rest;
+ parse_item *cfg_parse_item;
+
+ cfg_parse_item = parse_sdram_items;
+
+ for (i = 0; cfg_parse_item[i].prefix != NULL; i++) {
+ if (!strncmp(cfg_parse_item[i].prefix, str,
+ strlen(cfg_parse_item[i].prefix))) {
+ rest = str + strlen(cfg_parse_item[i].prefix);
+
+ return cfg_parse_item[i].process(context,
+ cfg_parse_item[i].token,
+ rest);
+ }
+ }
+
+ /* If this point was reached, there was a processing error. */
+ return 1;
+}
+
+static int init_files()
+{
+ int i;
+ FILE *file;
+
+ for (i = 0; i < input_file_num; i++) {
+ char *name = input_file[i].file_name;
+ if (strlen(name)) {
+ file = fopen(name, "r");
+ if (!file) {
+ printf("Failed to open file %s\n", name);
+ return -EINVAL;
+ }
+ input_file[i].file = file;
+ }
+ }
+
+ output_file = fopen(output_file_name, "w+");
+ if (!output_file) {
+ printf("Failed to open file %s\n", output_file_name);
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static void cleanup_files()
+{
+ int i;
+
+ for (i = 0; i < input_file_num; i++)
+ if (input_file[i].file)
+ fclose(input_file[i].file);
+
+ if (output_file)
+ fclose(output_file);
+}
+
+int main(int argc, char *argv[])
+{
+ int e;
+ build_image_context context;
+ int i;
+
+ memset(&context, 0, sizeof(build_image_context));
+
+ /* Process command line arguments. */
+ if (process_command_line(argc, argv, &context) != 0)
+ return -EINVAL;
+
+ if (help_only)
+ return 0;
+
+ assert(g_soc_config != NULL);
+
+ e = init_context(&context);
+ if (e != 0) {
+ printf("context initialization failed. Aborting.\n");
+ return e;
+ }
+
+ e = init_files();
+ if (e != 0)
+ goto fail;
+
+ for (i = 0; i < input_file_num; i++) {
+ context.config_file = input_file[i].file;
+ fprintf(output_file, "{\n");
+ process_config_file(&context, 0, process_sdram_config);
+ fprintf(output_file, "},\n");
+ }
+
+fail:
+ cleanup_files();
+
+ return e;
+}
--
1.8.1.5
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [cbootimage PATCH 3/3] Implement the utility gen_sdram_array
[not found] ` <1390893857-18716-3-git-send-email-vinceh-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
@ 2014-01-28 17:04 ` Stephen Warren
0 siblings, 0 replies; 4+ messages in thread
From: Stephen Warren @ 2014-01-28 17:04 UTC (permalink / raw)
To: Vince Hsu, swarren-DDmLM1+adcrQT0dZR+AlfA
Cc: linux-tegra-u79uwXL29TY76Z2rM5mHXA
On 01/28/2014 12:24 AM, Vince Hsu wrote:
> This patch implemtns the ubility to generate a header file from
> multiple sdram config files which each has one set of sdram
> parameters inside only.
I have no idea what this patch is meant to do. What kind of header file,
what are the input and output formats *exactly*, is there an example
somewhere?
Reading the code doesn't give me much more of a clue. but I /think/ the
following might do the same thing?
cat all_the_input_files | sed -e 's/SDRAM[\d+]//'
?
If so, then I'm not sure it's worth even putting this feature into
cbootimage at all, and if it is, a shell script might be a better idea.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-01-28 17:04 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-28 7:24 [cbootimage PATCH 1/3] Allow users to specify the handler to process special configuration Vince Hsu
[not found] ` <1390893857-18716-1-git-send-email-vinceh-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2014-01-28 7:24 ` [cbootimage PATCH 2/3] Export several parsing functions for external use Vince Hsu
2014-01-28 7:24 ` [cbootimage PATCH 3/3] Implement the utility gen_sdram_array Vince Hsu
[not found] ` <1390893857-18716-3-git-send-email-vinceh-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2014-01-28 17:04 ` Stephen Warren
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).