|
|
|
@ -202,26 +202,15 @@ int is_offset_valid(char * fdt, int offset, int len)
|
|
|
|
|
|
|
|
|
|
|
|
#define WINDOW_SIZE 512
|
|
|
|
#define WINDOW_SIZE 512
|
|
|
|
|
|
|
|
|
|
|
|
static int fdt_dump_node_data(const char *outname, const char *filename, int offset)
|
|
|
|
static int fdt_node_get_prop(char * filename, char * fdt, char * strings, int offset, const char * prop_name, int * data_offset, int * data_len)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
char *buf = malloc(WINDOW_SIZE);
|
|
|
|
char * buf = malloc(WINDOW_SIZE);
|
|
|
|
int readed = firmware_fdt_read_chunk(filename, buf, WINDOW_SIZE, 0);
|
|
|
|
int readed = firmware_fdt_read_chunk(filename, buf, WINDOW_SIZE, offset);
|
|
|
|
if (readed <= 0)
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
char *fdt = buf;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
buf = malloc(WINDOW_SIZE);
|
|
|
|
|
|
|
|
readed = firmware_fdt_read_chunk(filename, buf, WINDOW_SIZE, offset);
|
|
|
|
|
|
|
|
if (readed <= 0)
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
char * strings = malloc(WINDOW_SIZE);
|
|
|
|
|
|
|
|
readed = firmware_fdt_read_chunk(filename, strings, WINDOW_SIZE, fdt_off_dt_strings(fdt));
|
|
|
|
|
|
|
|
if (readed <= 0)
|
|
|
|
if (readed <= 0)
|
|
|
|
return -1;
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
|
|
int data_offset = 0;
|
|
|
|
*data_offset = 0;
|
|
|
|
int data_len = 0;
|
|
|
|
*data_len = 0;
|
|
|
|
do {
|
|
|
|
do {
|
|
|
|
int nextoffset = guess_next_tag(fdt, offset, buf);
|
|
|
|
int nextoffset = guess_next_tag(fdt, offset, buf);
|
|
|
|
readed = firmware_fdt_read_chunk(filename, buf, WINDOW_SIZE, nextoffset);
|
|
|
|
readed = firmware_fdt_read_chunk(filename, buf, WINDOW_SIZE, nextoffset);
|
|
|
|
@ -244,15 +233,25 @@ static int fdt_dump_node_data(const char *outname, const char *filename, int off
|
|
|
|
|
|
|
|
|
|
|
|
if (strcmp(name, "data"))
|
|
|
|
if (strcmp(name, "data"))
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
data_offset = prop->data - (char *)prop + offset;
|
|
|
|
*data_offset = prop->data - (char *)prop + offset;
|
|
|
|
data_len = fdt32_to_cpu(prop->len);
|
|
|
|
*data_len = fdt32_to_cpu(prop->len);
|
|
|
|
debug("Property \"data\" at offset %x len %d\n", data_offset, data_len);
|
|
|
|
debug("Property \"data\" at offset %x len %d\n", data_offset, data_len);
|
|
|
|
break;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (FDT_END != fdt32_to_cpu(*(int *)(fdt_offset_ptr_(fdt, buf, 0))));
|
|
|
|
} while (FDT_END != fdt32_to_cpu(*(int *)(fdt_offset_ptr_(fdt, buf, 0))));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int fdt_dump_node_data(char * fdt, char * strings, const char *outname, const char *filename, int offset)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int data_offset = 0;
|
|
|
|
|
|
|
|
int data_len = 0;
|
|
|
|
|
|
|
|
if (fdt_node_get_prop(filename, fdt, strings, offset, "data", &data_offset, &data_len))
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
|
|
char * data = malloc(data_len);
|
|
|
|
char * data = malloc(data_len);
|
|
|
|
readed = firmware_fdt_read_chunk(filename, data, data_len,
|
|
|
|
int readed = firmware_fdt_read_chunk(filename, data, data_len,
|
|
|
|
fdt_off_dt_struct(fdt) + data_offset);
|
|
|
|
fdt_off_dt_struct(fdt) + data_offset);
|
|
|
|
if (readed <= 0)
|
|
|
|
if (readed <= 0)
|
|
|
|
return -1;
|
|
|
|
return -1;
|
|
|
|
@ -346,12 +345,17 @@ int b()
|
|
|
|
|
|
|
|
|
|
|
|
debug("Yay\n");
|
|
|
|
debug("Yay\n");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
char * strings = malloc(WINDOW_SIZE);
|
|
|
|
|
|
|
|
readed = firmware_fdt_read_chunk(filename, strings, WINDOW_SIZE, fdt_off_dt_strings(fdt));
|
|
|
|
|
|
|
|
if (readed <= 0)
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < sizeof(node_offsets) / sizeof(*node_offsets); i++)
|
|
|
|
for (int i = 0; i < sizeof(node_offsets) / sizeof(*node_offsets); i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
printf("%s offset: %x\n", node_offsets[i].name, node_offsets[i].offset);
|
|
|
|
printf("%s offset: %x\n", node_offsets[i].name, node_offsets[i].offset);
|
|
|
|
readed = firmware_fdt_read_chunk(filename, buf, WINDOW_SIZE,
|
|
|
|
readed = firmware_fdt_read_chunk(filename, buf, WINDOW_SIZE,
|
|
|
|
node_offsets[i].offset);
|
|
|
|
node_offsets[i].offset);
|
|
|
|
int writed = fdt_dump_node_data(node_offsets[i].name, filename, node_offsets[i].offset);
|
|
|
|
int writed = fdt_dump_node_data(fdt, strings, node_offsets[i].name, filename, node_offsets[i].offset);
|
|
|
|
printf("Written %d bytes\n", writed);
|
|
|
|
printf("Written %d bytes\n", writed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|