1 //==========================================================================
5 // RedBoot GZIP uncompress command
7 //==========================================================================
8 //####ECOSGPLCOPYRIGHTBEGIN####
9 // -------------------------------------------
10 // This file is part of eCos, the Embedded Configurable Operating System.
11 // Copyright (C) 2005 eCosCentric Ltd
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 version.
17 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 // You should have received a copy of the GNU General Public License along
23 // with eCos; if not, write to the Free Software Foundation, Inc.,
24 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
26 // As a special exception, if other files instantiate templates or use macros
27 // or inline functions from this file, or you compile this file and link it
28 // with other works to produce a work based on this file, this file does not
29 // by itself cause the resulting work to be covered by the GNU General Public
30 // License. However the source code for this file must still be made available
31 // in accordance with section (3) of the GNU General Public License.
33 // This exception does not invalidate any other reasons why a work based on
34 // this file might be covered by the GNU General Public License.
35 // -------------------------------------------
36 //####ECOSGPLCOPYRIGHTEND####
37 //==========================================================================
38 //#####DESCRIPTIONBEGIN####
40 // Author(s): Peter Korsgaard
41 // Contributors: Peter Korsgaard
46 // This code is part of RedBoot (tm).
48 //####DESCRIPTIONEND####
50 //==========================================================================
55 "Uncompress GZIP compressed data",
56 "-s <location> -d <location>",
61 do_gunzip(int argc, char *argv[])
63 struct option_info opts[2];
64 unsigned long src, dst;
65 bool src_set, dst_set;
70 init_opts(&opts[0], 's', true, OPTION_ARG_TYPE_NUM,
71 (void *)&src, (bool *)&src_set, "source address");
72 init_opts(&opts[1], 'd', true, OPTION_ARG_TYPE_NUM,
73 (void *)&dst, (bool *)&dst_set, "destination address");
74 if (!scan_opts(argc, argv, 1, opts, 2, 0, 0, "")) {
78 // Must have src and dst
79 if (!src_set || !dst_set) {
80 // try to use load_address for src
82 && load_address >= (CYG_ADDRESS)ram_start
83 && load_address < load_address_end) {
85 diag_printf("Decompressing from %p to %p\n",
86 (void*)src, (void*)dst);
90 diag_printf("usage: gunzip -s <addr> -d <addr>\n");
95 p->out_buf = (unsigned char*)dst;
96 p->out_max = p->out_size = -1;
97 p->in_buf = (unsigned char*)src;
100 err = (*_dc_init)(p);
103 err = (*_dc_inflate)(p);
105 // Free used resources, do final translation of error value.
106 err = (*_dc_close)(p, err);
108 if (0 != err && p->msg) {
109 entry_address = (CYG_ADDRESS)NO_MEMORY;
110 diag_printf("Decompression error: %s\n", p->msg);
112 load_address = entry_address = (CYG_ADDRESS)dst;
113 load_address_end = (CYG_ADDRESS)p->out_buf;
114 diag_printf("Decompressed %lu bytes\n",
115 load_address_end - load_address);