diff options
author | Marcin Bukat <marcin.bukat@gmail.com> | 2014-08-07 19:09:35 +0200 |
---|---|---|
committer | Marcin Bukat <marcin.bukat@gmail.com> | 2014-08-07 19:09:35 +0200 |
commit | 53d9f2e6a7564e487bdac87f6e28c662e8407458 (patch) | |
tree | 7c2f3c40414d568b3623a6817a65d0188bbec9d5 /utils/rk27utils/rkwtool/main.c | |
parent | 81ffd9bfeee6aca65f507a46c8123b47ca6e2803 (diff) | |
download | rockbox-53d9f2e6a7564e487bdac87f6e28c662e8407458.tar.gz rockbox-53d9f2e6a7564e487bdac87f6e28c662e8407458.zip |
rkwtool: The tool to inspect and extract update RKW files
Change-Id: Ie32d0a597b93d23a7d5946a3d9409572b41b45bc
Diffstat (limited to 'utils/rk27utils/rkwtool/main.c')
-rw-r--r-- | utils/rk27utils/rkwtool/main.c | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/utils/rk27utils/rkwtool/main.c b/utils/rk27utils/rkwtool/main.c new file mode 100644 index 0000000000..dacfd9ffab --- /dev/null +++ b/utils/rk27utils/rkwtool/main.c | |||
@@ -0,0 +1,129 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * | ||
9 | * Copyright (C) 2014 by Marcin Bukat | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or | ||
12 | * modify it under the terms of the GNU General Public License | ||
13 | * as published by the Free Software Foundation; either version 2 | ||
14 | * of the License, or (at your option) any later version. | ||
15 | * | ||
16 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
17 | * KIND, either express or implied. | ||
18 | * | ||
19 | ****************************************************************************/ | ||
20 | |||
21 | #include <getopt.h> | ||
22 | #include <stdbool.h> | ||
23 | #include <stddef.h> | ||
24 | #include <stdio.h> | ||
25 | #include "rkw.h" | ||
26 | |||
27 | #define VERSION "v0.1" | ||
28 | |||
29 | static void banner(void) | ||
30 | { | ||
31 | printf("RKWtool " VERSION " (C) Marcin Bukat 2014\n"); | ||
32 | printf("This is free software; see the source for copying conditions. There is NO\n"); | ||
33 | printf("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"); | ||
34 | } | ||
35 | |||
36 | static void usage(char *name) | ||
37 | { | ||
38 | banner(); | ||
39 | |||
40 | printf("Usage: %s [-i] [-b] [-e] [-a] [-o prefix] file.rkw\n", name); | ||
41 | printf("-i\t\tprint info about RKW file\n"); | ||
42 | printf("-b\t\textract nand bootloader images (s1.bin and s2.bin)\n"); | ||
43 | printf("-e\t\textract firmware files stored in RKST section\n"); | ||
44 | printf("-o prefix\twhen extracting firmware files put it there\n"); | ||
45 | printf("-a\t\textract additional file(s) (usually Rock27Boot.bin)\n"); | ||
46 | printf("-A\t\textract all data\n"); | ||
47 | printf("file.rkw\tRKW file to be processed\n"); | ||
48 | } | ||
49 | |||
50 | int main(int argc, char **argv) | ||
51 | { | ||
52 | int opt; | ||
53 | struct rkw_info_t *rkw_info = NULL; | ||
54 | char *prefix = NULL; | ||
55 | bool info = false; | ||
56 | bool extract = false; | ||
57 | bool bootloader = false; | ||
58 | bool addfile = false; | ||
59 | |||
60 | while ((opt = getopt(argc, argv, "iebo:aA")) != -1) | ||
61 | { | ||
62 | switch (opt) | ||
63 | { | ||
64 | case 'i': | ||
65 | info = true; | ||
66 | break; | ||
67 | |||
68 | case 'e': | ||
69 | extract = true; | ||
70 | break; | ||
71 | |||
72 | case 'b': | ||
73 | bootloader = true; | ||
74 | break; | ||
75 | |||
76 | case 'o': | ||
77 | prefix = optarg; | ||
78 | break; | ||
79 | |||
80 | case 'a': | ||
81 | addfile = true; | ||
82 | break; | ||
83 | |||
84 | case 'A': | ||
85 | extract = true; | ||
86 | bootloader = true; | ||
87 | addfile = true; | ||
88 | break; | ||
89 | |||
90 | default: | ||
91 | usage(argv[0]); | ||
92 | break; | ||
93 | } | ||
94 | } | ||
95 | |||
96 | if ((argc - optind) != 1 || | ||
97 | (!info && !extract && ! bootloader && !addfile)) | ||
98 | { | ||
99 | usage(argv[0]); | ||
100 | return -1; | ||
101 | } | ||
102 | |||
103 | banner(); | ||
104 | |||
105 | rkw_info = rkw_slurp(argv[optind]); | ||
106 | |||
107 | if (rkw_info) | ||
108 | { | ||
109 | if (info) | ||
110 | { | ||
111 | rkrs_list_named_items(rkw_info); | ||
112 | rkst_list_named_items(rkw_info); | ||
113 | } | ||
114 | |||
115 | if (extract) | ||
116 | unpack_rkst(rkw_info, prefix); | ||
117 | |||
118 | if (bootloader) | ||
119 | unpack_bootloader(rkw_info, prefix); | ||
120 | |||
121 | if (addfile) | ||
122 | unpack_addfile(rkw_info, prefix); | ||
123 | |||
124 | rkw_free(rkw_info); | ||
125 | return 0; | ||
126 | } | ||
127 | |||
128 | return -1; | ||
129 | } | ||