forked from angerman/meson64-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pkg.c
78 lines (66 loc) · 2.47 KB
/
pkg.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// blx_fix.sh
//
// This is supposed to replicate this:
// blx_fix.sh bl30.bin zero_tmp bl30_zero.bin bl301.bin bl301_zero.bin bl30_new.bin bl30
// blx_fix.sh bl2.bin zero_tmp bl2_zero.bin acs.bin bl21_zero.bin bl2_new.bin bl2
//
// bl2_new.bin bl30_new.bin
// .---------------. -- 0x0000 .---------------. -- 0x0000
// | bl2.bin~~~~~~ | | bl30.bin~~~~~ |
// : ~~~~~~~~~~~~~ : : ~~~~~~~~~~~~~ :
// | ~~~0000000000 | | ~~~0000000000 |
// | 0000000000000 | |---------------| -- 0xA000 (41K)
// |---------------| -- 0xE000 | bl301.bin~~~~ |
// | acs.bin~~~~~~ | : ~~~~~~~~~~~~~ :
// : ~~~~~~~~~~~~~ : | ~~00000000000 |
// | ~~~0000000000 | '---------------' -- 0xD400 (12K)
// '---------------' -- 0xF000
//
// ACS is probably Amlogic Configurable SPL
//
#include "types.h"
#include "lib.h"
int main(int argc, char ** argv) {
opt_values_pkg_t opt_values;
char **opt_array_view = (char**)&opt_values;
option_t opts[2] = {
{ "type", 1, 0, 0x30 }, // 0x00
{ "output", 1, 0, 0x31 } // 0x01
};
bzero(&opt_values, sizeof opt_values);
int getopt_result = 0;
while(getopt_long(argc, argv, "", opts, &getopt_result) != -1)
opt_array_view[getopt_result] = optarg;
struct stat stat_info;
// verify we have two files to package.
if(optind + 2 != argc)
exit(-EINVAL);
opt_values.base = argv[optind];
opt_values.extra = argv[optind+1];
if(opt_values.base == NULL || stat(opt_values.base, &stat_info) != 0)
exit(-ENOINPUT);
if(opt_values.extra == NULL || stat(opt_values.extra, &stat_info) != 0)
exit(-ENOINPUT);
size_t size = 0x0;
off_t extra_offset = 0x0;
if(0 == strncmp(opt_values.type, "bl2", 4)) {
size = 0xF000;
extra_offset = 0xE000;
} else if (0 == strncmp(opt_values.type, "bl30", 5)) {
size = 0xD400;
extra_offset = 0xA000;
} else
exit(-EINVAL);
uint8_t *buf = calloc(1, size);
FILE *fbase = fopen(opt_values.base, "rb");
fread(&buf[0x0], 1, extra_offset, fbase);
fclose(fbase);
FILE *fextra = fopen(opt_values.extra, "rb");
fread(&buf[extra_offset], 1, size - extra_offset, fextra);
fclose(fextra);
FILE *fout = fopen(opt_values.output, "wb+");
fwrite(&buf[0x0], 1, size, fout);
fclose(fout);
free(buf);
exit(0);
}