-
Notifications
You must be signed in to change notification settings - Fork 22
/
qcdt_v2.c
58 lines (52 loc) · 1.69 KB
/
qcdt_v2.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <stdbool.h>
#include "dtimgextract.h"
typedef struct {
uint32_t platform_id;
uint32_t variant_id;
uint32_t sec_rev;
uint32_t unknown;
uint32_t offset;
uint32_t len;
} dtb_entry_v2;
void dump_files_v2(FILE *fd, qca_head header, uint32_t headerat) {
int i;
dtb_entry_v2 *images = malloc(header.num * sizeof(dtb_entry_v2));
printf("\nPid\tVid\tSrev\tUnknown\tOffset\tlen\n");
for ( i = 0; i < header.num ; i++ ){
fread(&images[i], sizeof(dtb_entry_v2), 1, fd);
printf("%x\t%x\t%x\t%x\t%x\t%x\n", images[i].platform_id, images[i].variant_id,
images[i].sec_rev, images[i].unknown,
images[i].offset, images[i].len);
}
printf("\n");
fseek(fd, headerat, SEEK_SET);
for ( i = 0; i < header.num; i++ ){
char dtbname[256];
char *dtb;
FILE *out_fd = NULL;
sprintf(dtbname, "%x_%x_%x.dtb", images[i].platform_id, images[i].variant_id,
images[i].sec_rev);
printf("Writing %s(%x bytes)\n", dtbname, images[i].len);
dtb = malloc(images[i].len);
fseek(fd, images[i].offset + headerat, SEEK_SET);
fread(dtb, images[i].len, 1, fd);
out_fd = fopen(dtbname, "wb");
fwrite(dtb, images[i].len, 1, out_fd);
free(dtb);
fclose(out_fd);
}
free(images);
}
dt_parser v2_parser = {
.dt_file_dumper = &dump_files_v2,
.version = 2,
.extended = 0,
};
int __attribute__((constructor)) register_v2_parser(void) {
add_dt_parser(&v2_parser);
return 0;
}