diff options
author | Ralf Baechle <ralf@linux-mips.org> | 1998-03-17 22:26:36 +0000 |
---|---|---|
committer | Ralf Baechle <ralf@linux-mips.org> | 1998-03-17 22:26:36 +0000 |
commit | c2490369ec947d1e8f4877754496c59bdc03a739 (patch) | |
tree | c9be12f43fe14f346e48060725273cfae8af8d82 /arch/arm/boot/tools/build.c | |
parent | 27cfca1ec98e91261b1a5355d10a8996464b63af (diff) |
Forgot those ...
Diffstat (limited to 'arch/arm/boot/tools/build.c')
-rw-r--r-- | arch/arm/boot/tools/build.c | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/arch/arm/boot/tools/build.c b/arch/arm/boot/tools/build.c new file mode 100644 index 000000000..ac1297564 --- /dev/null +++ b/arch/arm/boot/tools/build.c @@ -0,0 +1,70 @@ +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <stdarg.h> +#include <a.out.h> + +typedef unsigned char byte; +typedef unsigned short word; +typedef unsigned long u32; + +void die(const char * str, ...) +{ + va_list args; + va_start(args, str); + vfprintf(stderr, str, args); + fputc('\n', stderr); + exit (1); +} + +int main(int argc, char **argv) +{ + void *data; + struct exec ex; + FILE *f; + int totlen; + + if (argc < 2) { + fprintf(stderr, "Usage: build kernel-name\n"); + exit(1); + } + + f = fopen(argv[1], "rb"); + if (!f) + die("Unable to open `%s': %m", argv[1]); + + fread(&ex, 1, sizeof(ex), f); + + if(N_MAGIC(ex) == ZMAGIC) { + fseek(f, 4096, SEEK_SET); + totlen = ex.a_text + ex.a_data; + } else + if(N_MAGIC(ex) == QMAGIC) { + unsigned long my_header; + + fseek(f, 4, SEEK_SET); + + my_header = 0xea000006; + + fwrite(&my_header, 4, 1, stdout); + + totlen = ex.a_text + ex.a_data - 4; + } else { + fprintf(stderr, "Unacceptable a.out header on kernel\n"); + fclose(f); + exit(1); + } + + fprintf(stderr, "Kernel is %dk (%dk text, %dk data, %dk bss)\n", + (ex.a_text + ex.a_data + ex.a_bss)/1024, + ex.a_text/1024, ex.a_data/1024, ex.a_bss/1024); + + data = malloc(totlen); + fread(data, 1, totlen, f); + fwrite(data, 1, totlen, stdout); + + free(data); + fclose(f); + fflush(stdout); + return 0; +} |