2 * Copyright (C) 2014 Thadeu Lima de Souza Cascardo <cascardo@cascardo.eti.br>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 static int dump(int fd, size_t len, int pgsz, char *fname)
36 out = open(fname, O_WRONLY | O_CREAT | O_EXCL, 0644);
39 npages = (len + pgsz - 1) / pgsz;
40 for (i = 1; i <= npages; i++) {
42 len = len & (pgsz - 1);
44 r = read(fd, page, len);
47 r = write(out, page, len);
52 r = read(fd, page, pgsz);
55 r = write(out, page, pgsz);
70 int main(int argc, char **argv)
73 uint32_t kernel, initrd, second, pgsz;
80 fd = open(argv[1], O_RDONLY);
84 r = read(fd, buffer, sizeof(buffer));
88 if (strncmp(buffer, "ANDROID!", 8)) {
91 kernel = *(uint32_t *) p;
93 initrd = *(uint32_t *) p;
95 second = *(uint32_t *) p;
97 pgsz = *(uint32_t *) p;
100 lseek(fd, offset, SEEK_SET);
101 dump(fd, kernel, pgsz, "kernel");
103 offset += ((kernel + pgsz - 1) / pgsz) * pgsz;
105 lseek(fd, offset, SEEK_SET);
106 dump(fd, initrd, pgsz, "initrd");
108 offset += ((initrd + pgsz - 1) / pgsz) * pgsz;
110 lseek(fd, offset, SEEK_SET);
111 dump(fd, second, pgsz, "second");