1 |
786 |
skrzyp |
//==========================================================================
|
2 |
|
|
//
|
3 |
|
|
// gunzip.c
|
4 |
|
|
//
|
5 |
|
|
// RedBoot GZIP uncompress command
|
6 |
|
|
//
|
7 |
|
|
//==========================================================================
|
8 |
|
|
// ####ECOSGPLCOPYRIGHTBEGIN####
|
9 |
|
|
// -------------------------------------------
|
10 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
11 |
|
|
// Copyright (C) 2005 Free Software Foundation, Inc.
|
12 |
|
|
//
|
13 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
14 |
|
|
// the terms of the GNU General Public License as published by the Free
|
15 |
|
|
// Software Foundation; either version 2 or (at your option) any later
|
16 |
|
|
// version.
|
17 |
|
|
//
|
18 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT
|
19 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
20 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
21 |
|
|
// for more details.
|
22 |
|
|
//
|
23 |
|
|
// You should have received a copy of the GNU General Public License
|
24 |
|
|
// along with eCos; if not, write to the Free Software Foundation, Inc.,
|
25 |
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
26 |
|
|
//
|
27 |
|
|
// As a special exception, if other files instantiate templates or use
|
28 |
|
|
// macros or inline functions from this file, or you compile this file
|
29 |
|
|
// and link it with other works to produce a work based on this file,
|
30 |
|
|
// this file does not by itself cause the resulting work to be covered by
|
31 |
|
|
// the GNU General Public License. However the source code for this file
|
32 |
|
|
// must still be made available in accordance with section (3) of the GNU
|
33 |
|
|
// General Public License v2.
|
34 |
|
|
//
|
35 |
|
|
// This exception does not invalidate any other reasons why a work based
|
36 |
|
|
// on this file might be covered by the GNU General Public License.
|
37 |
|
|
// -------------------------------------------
|
38 |
|
|
// ####ECOSGPLCOPYRIGHTEND####
|
39 |
|
|
//==========================================================================
|
40 |
|
|
//#####DESCRIPTIONBEGIN####
|
41 |
|
|
//
|
42 |
|
|
// Author(s): Peter Korsgaard
|
43 |
|
|
// Contributors: Peter Korsgaard
|
44 |
|
|
// Date: 2005-04-04
|
45 |
|
|
// Purpose:
|
46 |
|
|
// Description:
|
47 |
|
|
//
|
48 |
|
|
// This code is part of RedBoot (tm).
|
49 |
|
|
//
|
50 |
|
|
//####DESCRIPTIONEND####
|
51 |
|
|
//
|
52 |
|
|
//==========================================================================
|
53 |
|
|
|
54 |
|
|
#include <redboot.h>
|
55 |
|
|
|
56 |
|
|
RedBoot_cmd("gunzip",
|
57 |
|
|
"Uncompress GZIP compressed data",
|
58 |
|
|
"-s <location> -d <location>",
|
59 |
|
|
do_gunzip
|
60 |
|
|
);
|
61 |
|
|
|
62 |
|
|
void
|
63 |
|
|
do_gunzip(int argc, char *argv[])
|
64 |
|
|
{
|
65 |
|
|
struct option_info opts[2];
|
66 |
|
|
unsigned long src, dst;
|
67 |
|
|
bool src_set, dst_set;
|
68 |
|
|
_pipe_t pipe;
|
69 |
|
|
_pipe_t* p = &pipe;
|
70 |
|
|
int err;
|
71 |
|
|
|
72 |
|
|
init_opts(&opts[0], 's', true, OPTION_ARG_TYPE_NUM,
|
73 |
|
|
(void *)&src, (bool *)&src_set, "source address");
|
74 |
|
|
init_opts(&opts[1], 'd', true, OPTION_ARG_TYPE_NUM,
|
75 |
|
|
(void *)&dst, (bool *)&dst_set, "destination address");
|
76 |
|
|
if (!scan_opts(argc, argv, 1, opts, 2, 0, 0, "")) {
|
77 |
|
|
return;
|
78 |
|
|
}
|
79 |
|
|
|
80 |
|
|
// Must have src and dst
|
81 |
|
|
if (!src_set || !dst_set) {
|
82 |
|
|
// try to use load_address for src
|
83 |
|
|
if (dst_set
|
84 |
|
|
&& load_address >= (CYG_ADDRESS)ram_start
|
85 |
|
|
&& load_address < load_address_end) {
|
86 |
|
|
src = load_address;
|
87 |
|
|
diag_printf("Decompressing from %p to %p\n",
|
88 |
|
|
(void*)src, (void*)dst);
|
89 |
|
|
}
|
90 |
|
|
else
|
91 |
|
|
{
|
92 |
|
|
diag_printf("usage: gunzip -s <addr> -d <addr>\n");
|
93 |
|
|
return;
|
94 |
|
|
}
|
95 |
|
|
}
|
96 |
|
|
|
97 |
|
|
p->out_buf = (unsigned char*)dst;
|
98 |
|
|
p->out_max = p->out_size = -1;
|
99 |
|
|
p->in_buf = (unsigned char*)src;
|
100 |
|
|
p->in_avail = -1;
|
101 |
|
|
|
102 |
|
|
err = (*_dc_init)(p);
|
103 |
|
|
|
104 |
|
|
if (0 == err)
|
105 |
|
|
err = (*_dc_inflate)(p);
|
106 |
|
|
|
107 |
|
|
// Free used resources, do final translation of error value.
|
108 |
|
|
err = (*_dc_close)(p, err);
|
109 |
|
|
|
110 |
|
|
if (0 != err && p->msg) {
|
111 |
|
|
entry_address = (CYG_ADDRESS)NO_MEMORY;
|
112 |
|
|
diag_printf("Decompression error: %s\n", p->msg);
|
113 |
|
|
} else {
|
114 |
|
|
load_address = entry_address = (CYG_ADDRESS)dst;
|
115 |
|
|
load_address_end = (CYG_ADDRESS)p->out_buf;
|
116 |
|
|
diag_printf("Decompressed %lu bytes\n",
|
117 |
|
|
load_address_end - load_address);
|
118 |
|
|
}
|
119 |
|
|
}
|