Commit 62dc7368 authored by Alejandro Mery's avatar Alejandro Mery
Browse files

bin2fex: refactored method to choose the format of single datums

parent 36b4ce7a
...@@ -34,18 +34,19 @@ ...@@ -34,18 +34,19 @@
/** /**
*/ */
static int name_in_list(const char *s, const char **list) static inline size_t strlen2(const char *s)
{ {
size_t l = strlen(s); size_t l = strlen(s);
{ /* remove trailing digits */
const char *p = &s[l-1]; const char *p = &s[l-1];
while (l && *p >= '0' && *p <= '9') { while (l && *p >= '0' && *p <= '9') {
l--; l--;
p--; p--;
} }
} return l;
}
static int find_full_match(const char *s, size_t l, const char **list)
{
while (*list) { while (*list) {
if (memcmp(s, *list, l) == 0) if (memcmp(s, *list, l) == 0)
return 1; return 1;
...@@ -93,12 +94,8 @@ static inline int decompile_gpio(struct script_section *section, ...@@ -93,12 +94,8 @@ static inline int decompile_gpio(struct script_section *section,
/** /**
*/ */
static inline int decompile_single(struct script_section *section, static int decompile_single_mode(const char *name)
struct script_section_entry *entry,
int32_t *d,
int length, FILE *out)
{ {
int ok = 1;
static const char *hexa_entries[] = { static const char *hexa_entries[] = {
"dram_baseaddr", "dram_zq", "dram_tpr", "dram_emr", "dram_baseaddr", "dram_zq", "dram_tpr", "dram_emr",
"g2d_size", "g2d_size",
...@@ -107,6 +104,20 @@ static inline int decompile_single(struct script_section *section, ...@@ -107,6 +104,20 @@ static inline int decompile_single(struct script_section *section,
"lcd_gamma_tbl_", "lcd_gamma_tbl_",
"gsensor_twi_addr", "gsensor_twi_addr",
NULL }; NULL };
size_t l = strlen2(name);
if (find_full_match(name, l, hexa_entries))
return 0;
else
return -1;
}
static inline int decompile_single(struct script_section *section,
struct script_section_entry *entry,
int32_t *d,
int length, FILE *out)
{
int ok = 1;
int mode;
if (length != 1) { if (length != 1) {
pr_err("%s.%s: invalid length %d (assuming %d)\n", pr_err("%s.%s: invalid length %d (assuming %d)\n",
...@@ -114,11 +125,16 @@ static inline int decompile_single(struct script_section *section, ...@@ -114,11 +125,16 @@ static inline int decompile_single(struct script_section *section,
ok = 0; ok = 0;
} }
mode = decompile_single_mode(entry->name);
fprintf(out, "%s\t= ", entry->name); fprintf(out, "%s\t= ", entry->name);
if (name_in_list(entry->name, hexa_entries)) if (mode < 0)
fprintf(out, "0x%x", *d);
else
fprintf(out, "%d", *d); fprintf(out, "%d", *d);
else if (mode > 0)
fprintf(out, "0x%0*x", mode, *d);
else
fprintf(out, "0x%x", *d);
fputc('\n', out); fputc('\n', out);
return ok; return ok;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment