OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [arch/] [armnommu/] [boot/] [tools/] [build.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1622 jcastillo
#include <stdio.h>
2
#include <stdlib.h>
3
#include <a.out.h>
4
#include <string.h>
5
 
6
int main(int argc, char **argv)
7
{
8
        void *data;
9
        struct exec ex;
10
        FILE *f;
11
        int totlen;
12
 
13
        if (argc < 2) {
14
                fprintf(stderr, "Usage: build kernel-name\n");
15
                exit(1);
16
        }
17
 
18
        f = fopen(argv[1], "rb");
19
 
20
        fread(&ex, 1, sizeof(ex), f);
21
 
22
        if(N_MAGIC(ex) == ZMAGIC) {
23
                fseek(f, 4096, SEEK_SET);
24
                totlen = ex.a_text + ex.a_data;
25
        } else
26
        if(N_MAGIC(ex) == QMAGIC) {
27
                unsigned int my_header;
28
 
29
                fseek(f, 4, SEEK_SET);
30
 
31
                my_header = 0xea000006;
32
 
33
                fwrite(&my_header, 4, 1, stdout);
34
 
35
                totlen = ex.a_text + ex.a_data - 4;
36
        } else {
37
                fprintf(stderr, "Unacceptable a.out header on kernel\n");
38
                fclose(f);
39
                exit(1);
40
        }
41
 
42
        fprintf(stderr, "Kernel is %dk (%dk text, %dk data, %dk bss)\n",
43
                (ex.a_text + ex.a_data + ex.a_bss)/1024,
44
                 ex.a_text/1024, ex.a_data/1024, ex.a_bss/1024);
45
 
46
        data = malloc(totlen);
47
        fread(data, 1, totlen, f);
48
        fwrite(data, 1, totlen, stdout);
49
 
50
        free(data);
51
        fclose(f);
52
        fflush(stdout);
53
        return 0;
54
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.