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/] [piggyback.c] - Blame information for rev 1782

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1622 jcastillo
/*
2
 *      linux/zBoot/piggyback.c
3
 *
4
 *      (C) 1993 Hannu Savolainen
5
 */
6
 
7
/*
8
 *      This program reads the compressed system image from stdin and
9
 *      encapsulates it into an object file written to the stdout.
10
 */
11
 
12
#include <stdio.h>
13
#include <unistd.h>
14
#include <a.out.h>
15
#include <sys/fcntl.h>
16
 
17
int main(int argc, char *argv[])
18
{
19
        int n=0, len=0, fd = 0;
20
        char tmp_buf[640*1024];
21
 
22
        struct exec obj = {0x00670107}; /* object header */
23
        char string_names[] = {"_input_data\0_input_end\0"};
24
 
25
        struct nlist var_names[2] = /* Symbol table */
26
                {
27
                        {       /* _input_data  */
28
                                {(char *)4}, 7, 0, 0, 0
29
                        },
30
                        {       /* _input_len */
31
                                {(char *)16}, 7, 0, 0, 0
32
                        }
33
                };
34
 
35
 
36
        if (argc > 1) {
37
                fd = open (argv[1], O_RDONLY);
38
                if (fd < 0) {
39
                        fprintf (stderr, "%s: ", argv[0]);
40
                        perror (argv[1]);
41
                        exit (1);
42
                }
43
        }
44
 
45
        len = 0;
46
        while ((n = read(fd, &tmp_buf[len], sizeof(tmp_buf)-len+1)) > 0)
47
              len += n;
48
 
49
        len = (len + 3) & ~3;
50
 
51
        if (n==-1) {
52
                perror("stdin");
53
                exit(-1);
54
        }
55
 
56
        if (len >= sizeof(tmp_buf)) {
57
                fprintf(stderr, "%s: Input too large\n", argv[0]);
58
                exit(-1);
59
        }
60
 
61
        if (argc < 2)
62
                fprintf(stderr, "Compressed size %d.\n", len);
63
 
64
/*
65
 *      Output object header
66
 */
67
        obj.a_data = len /* + sizeof(long) */;
68
        obj.a_syms = sizeof(var_names);
69
        write(1, (char *)&obj, sizeof(obj));
70
 
71
/*
72
 *      Output data segment (compressed system & len)
73
 */
74
        write(1, tmp_buf, len);
75
 
76
/*
77
 *      Output symbol table
78
 */
79
        var_names[1].n_value = len;
80
        write(1, (char *)&var_names, sizeof(var_names));
81
 
82
/*
83
 *      Output string table
84
 */
85
        len = sizeof(string_names) + sizeof(len);
86
        write(1, (char *)&len, sizeof(len));
87
        write(1, string_names, sizeof(string_names));
88
 
89
        exit(0);
90
 
91
}

powered by: WebSVN 2.1.0

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