Commit 3abad84f authored by Alejandro Mery's avatar Alejandro Mery
Browse files

bin2fex: decompile GPIO entries

parent 81fa01b7
...@@ -28,10 +28,43 @@ ...@@ -28,10 +28,43 @@
#define errf(...) fprintf(stderr, __VA_ARGS__) #define errf(...) fprintf(stderr, __VA_ARGS__)
#define pr_info(F, ...) fprintf(out, "; bin2fex: " F, __VA_ARGS__) #define pr_info(F, ...) fprintf(out, "; bin2fex: " F, __VA_ARGS__)
#define pr_err(F, ...) pr_info("ERROR" F, __VA_ARGS__) #define pr_err(F, ...) pr_info("ERROR: " F, __VA_ARGS__)
#define PTR(B, OFF) (void*)((char*)(B)+(OFF)) #define PTR(B, OFF) (void*)((char*)(B)+(OFF))
/**
*/
static int decompile_gpio(struct script_section *section, struct script_section_entry *entry, struct script_gpio_value *gpio, int length, FILE *out)
{
int ok = 1;
char port = '?';
if (length != 6) {
pr_err("%s.%s: invalid length %d (assuming %d)\n",
section->name, entry->name, length, 6);
ok = 0;
}
if (gpio->port < 1 || gpio->port > 10) {
pr_err("%s.%s: unknown GPIO port type %d\n",
section->name, entry->name, gpio->port);
ok = 0;
} else {
port = 'A' + (gpio->port-1);
}
fprintf(out, "%s\t= port:P%c%d", entry->name, port, gpio->port_num);
for (const int *p = &gpio->mul_sel, *pe = p+4; p != pe; p++) {
if (*p == -1)
fputs("<default>", out);
else
fprintf(out, "<%d>", *p);
}
fputc('\n', out);
return ok;
}
/** /**
*/ */
static int decompile_section(void *bin, size_t bin_size, static int decompile_section(void *bin, size_t bin_size,
...@@ -40,6 +73,7 @@ static int decompile_section(void *bin, size_t bin_size, ...@@ -40,6 +73,7 @@ static int decompile_section(void *bin, size_t bin_size,
{ {
struct script_section_entry *entry = PTR(bin, section->offset<<2); struct script_section_entry *entry = PTR(bin, section->offset<<2);
int i = section->length; int i = section->length;
int ok = 1;
fprintf(out, "[%s]\n", section->name); fprintf(out, "[%s]\n", section->name);
for (; i--; entry++) { for (; i--; entry++) {
...@@ -52,8 +86,8 @@ static int decompile_section(void *bin, size_t bin_size, ...@@ -52,8 +86,8 @@ static int decompile_section(void *bin, size_t bin_size,
case SCRIPT_VALUE_TYPE_SINGLE_WORD: { case SCRIPT_VALUE_TYPE_SINGLE_WORD: {
int32_t *d = data; int32_t *d = data;
if (length != 1) if (length != 1)
pr_err("%s.%s: invalid length %d (assuming 1)\n", pr_err("%s.%s: invalid length %d (assuming %d)\n",
section->name, entry->name, length); section->name, entry->name, length, 1);
/* TODO: some are preferred in hexa */ /* TODO: some are preferred in hexa */
fprintf(out, "%s\t= %d\n", entry->name, *d); fprintf(out, "%s\t= %d\n", entry->name, *d);
...@@ -69,7 +103,9 @@ static int decompile_section(void *bin, size_t bin_size, ...@@ -69,7 +103,9 @@ static int decompile_section(void *bin, size_t bin_size,
(int)(p-s), s); (int)(p-s), s);
}; break; }; break;
case SCRIPT_VALUE_TYPE_GPIO: case SCRIPT_VALUE_TYPE_GPIO:
fprintf(out, "%s\t= GPIO\n", entry->name); break; if (!decompile_gpio(section, entry, data, length, out))
ok = 0;
break;
case SCRIPT_VALUE_TYPE_NULL: case SCRIPT_VALUE_TYPE_NULL:
fprintf(out, "%s\t=\n", entry->name); fprintf(out, "%s\t=\n", entry->name);
break; break;
...@@ -82,7 +118,7 @@ static int decompile_section(void *bin, size_t bin_size, ...@@ -82,7 +118,7 @@ static int decompile_section(void *bin, size_t bin_size,
} }
fputc('\n', out); fputc('\n', out);
return 1; /* success */ return ok;
} }
/** /**
*/ */
......
...@@ -36,6 +36,15 @@ struct script_section_entry { ...@@ -36,6 +36,15 @@ struct script_section_entry {
int32_t pattern; int32_t pattern;
}; };
struct script_gpio_value {
int32_t port;
int32_t port_num;
int32_t mul_sel;
int32_t pull;
int32_t drv_level;
int32_t data;
};
enum script_value_type { enum script_value_type {
SCRIPT_VALUE_TYPE_SINGLE_WORD = 1, SCRIPT_VALUE_TYPE_SINGLE_WORD = 1,
SCRIPT_VALUE_TYPE_STRING, SCRIPT_VALUE_TYPE_STRING,
......
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