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

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [rc203soc/] [sw/] [uClinux/] [arch/] [armnommu/] [boot/] [compressed/] [xtract.c] - Blame information for rev 1782

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1622 jcastillo
/*
2
 *  linux/zBoot/xtract.c
3
 *
4
 *  Copyright (C) 1993  Hannu Savolainen
5
 *
6
 *      Extracts the system image and writes it to the stdout.
7
 *      based on tools/build.c by Linus Torvalds
8
 */
9
 
10
#include <stdio.h>      /* fprintf */
11
#include <string.h>
12
#include <stdlib.h>     /* contains exit */
13
#include <sys/types.h>  /* unistd.h needs this */
14
#include <sys/stat.h>
15
#include <sys/sysmacros.h>
16
#include <unistd.h>     /* contains read/write */
17
#include <fcntl.h>
18
#include <a.out.h>
19
 
20
#define N_MAGIC_OFFSET 1024
21
 
22
static int GCC_HEADER = sizeof(struct exec);
23
 
24
#define STRINGIFY(x) #x
25
 
26
void die(char * str)
27
{
28
        fprintf(stderr,"%s\n",str);
29
        exit(1);
30
}
31
 
32
void usage(void)
33
{
34
        die("Usage: xtract system [ | gzip | piggyback > piggy.s]");
35
}
36
 
37
int main(int argc, char ** argv)
38
{
39
        int id, sz;
40
        char buf[1024];
41
 
42
        struct exec *ex = ((struct exec *)buf) + 1;
43
 
44
        if (argc  != 2)
45
                usage();
46
 
47
        if ((id=open(argv[1],O_RDONLY,0))<0)
48
                die("Unable to open 'system'");
49
        if (read(id,ex,GCC_HEADER) != GCC_HEADER)
50
                die("Unable to read header of 'system'");
51
 
52
        switch (N_MAGIC(*ex)) {
53
        case ZMAGIC:
54
                GCC_HEADER = N_MAGIC_OFFSET;
55
                lseek(id, GCC_HEADER, SEEK_SET);
56
                break;
57
        case QMAGIC:
58
                memset (buf, 0, GCC_HEADER);
59
                buf[0x14] = 0x20;
60
                write (1, buf, GCC_HEADER);
61
                break;
62
        default:
63
                die("Non-GCC header of 'system'");
64
        }
65
 
66
        sz = N_SYMOFF(*ex) - GCC_HEADER + 4;    /* +4 to get the same result than tools/build */
67
 
68
        fprintf(stderr, "System size is %d\n", sz);
69
 
70
        while (sz) {
71
                int l, n;
72
 
73
                l = sz;
74
                if (l > sizeof(buf)) l = sizeof(buf);
75
 
76
                if ((n=read(id, buf, l)) !=l)
77
                {
78
                        if (n == -1)
79
                           perror(argv[1]);
80
                        else
81
                           fprintf(stderr, "Unexpected EOF\n");
82
 
83
                        die("Can't read system");
84
                }
85
 
86
                write(1, buf, l);
87
                sz -= l;
88
        }
89
 
90
        close(id);
91
        return(0);
92
}

powered by: WebSVN 2.1.0

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