This is the mail archive of the
ecos-patches@sources.redhat.com
mailing list for the eCos project.
Redboot 'gunzip' command
- From: Peter Korsgaard <jacmet at sunsite dot dk>
- To: ecos-patches at ecos dot sourceware dot org
- Date: Mon, 04 Apr 2005 22:29:34 +0200
- Subject: Redboot 'gunzip' command
Hi,
The following little patch adds a 'gunzip' command to Redboot for
uncompressing GZIP compressed data from one memory location to
another (similar to fis load -d, but for any source/dest memory
location).
We use it as part of a custom upgrade procedure where we boot into a
RAM mode Redboot with a compiled in bootscript.
Index: packages/redboot/current/cdl/redboot.cdl
===================================================================
RCS file: /cvs/ecos/ecos/packages/redboot/current/cdl/redboot.cdl,v
retrieving revision 1.70
diff -u -r1.70 redboot.cdl
--- packages/redboot/current/cdl/redboot.cdl 9 Nov 2004 19:12:54 -0000 1.70
+++ packages/redboot/current/cdl/redboot.cdl 4 Apr 2005 20:19:30 -0000
@@ -203,6 +203,15 @@
This CDL indicates whether flash images can
be decompressed from gzip/zlib format into RAM."
}
+
+ cdl_option CYGBLD_BUILD_REDBOOT_WITH_GUNZIP {
+ display "Include GZIP uncompress command"
+ default_value 0
+ description "
+ Enable this option to include a 'gunzip' command
+ to uncompress GZIP compressed data."
+ compile -library=libextras.a gunzip.c
+ }
}
cdl_option CYGBLD_BUILD_REDBOOT_WITH_XYZMODEM {
Index: packages/redboot/current/doc/redboot_cmds.sgml
===================================================================
RCS file: /cvs/ecos/ecos/packages/redboot/current/doc/redboot_cmds.sgml,v
retrieving revision 1.11
diff -u -r1.11 redboot_cmds.sgml
--- packages/redboot/current/doc/redboot_cmds.sgml 9 Nov 2004 19:12:55 -0000 1.11
+++ packages/redboot/current/doc/redboot_cmds.sgml 4 Apr 2005 20:19:35 -0000
@@ -863,6 +863,8 @@
fconfig [-i] [-l] [-n] [-f] [-d] | [-d] nickname [value]
Execute code at a location
go [-w <timeout>] [entry]
+Uncompress GZIP compressed data
+ gunzip -s <location> -d <location>
Help about help?
help [<topic>]
Read I/O location
@@ -1083,6 +1085,68 @@
</refsect1>
</refentry>
+<!-- ******** gunzip *************************************************** -->
+ <refentry id="gunzip-command">
+ <refnamediv>
+ <refname>gunzip</refname>
+ <refpurpose>Uncompress GZIP compressed data</refpurpose>
+ </refnamediv>
+ <refsynopsisdiv>
+ <cmdsynopsis>
+ <command>gunzip</command>
+ <arg choice="req">-s <replaceable>source</replaceable></arg>
+ <arg choice="req">-d <replaceable>destination</replaceable></arg>
+ </cmdsynopsis>
+ </refsynopsisdiv>
+ <refsect1>
+ <title>Arguments</title>
+ <informaltable frame="all">
+ <tgroup cols="4" colsep="1" rowsep="1" align="left">
+ <colspec colname="c1">
+ <colspec colname="c2">
+ <colspec colname="c3">
+ <colspec colname="c4">
+ <thead>
+ <row>
+ <entry>Name</entry>
+ <entry>Type</entry>
+ <entry>Description</entry>
+ <entry>Default</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>-s <replaceable>location1</replaceable></entry>
+ <entry>Memory address</entry>
+ <entry>Location of GZIP compressed data to uncompress.</entry>
+ <entry>Value set by last <command>load</command> or <command>fis load</command> command.</entry>
+ </row>
+ <row>
+ <entry>-d <replaceable>location2</replaceable></entry>
+ <entry>Memory address</entry>
+ <entry>Destination to write uncompressed data to.</entry>
+ <entry><emphasis>none</emphasis></entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </informaltable>
+ </refsect1>
+ <refsect1>
+ <title>Description</title>
+ <para>Uncompress GZIP compressed data.</para>
+ </refsect1>
+ <refsect1>
+ <title>Examples</title>
+ <para>
+Uncompress data at location 0x100000 to 0x200000.
+<screen>
+RedBoot> <userinput>gunzip -s 0x100000 -d 0x200000</userinput>
+Decompressed 38804 bytes
+</screen>
+</para>
+ </refsect1>
+ </refentry>
+
<!-- ******** ip_address *************************************************** -->
<refentry id="ip-address-command">
<refnamediv>
Index: packages/redboot/current/src/gunzip.c
===================================================================
RCS file: packages/redboot/current/src/gunzip.c
diff -N packages/redboot/current/src/gunzip.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ packages/redboot/current/src/gunzip.c 4 Apr 2005 20:19:35 -0000
@@ -0,0 +1,119 @@
+//==========================================================================
+//
+// gunzip.c
+//
+// RedBoot GZIP uncompress command
+//
+//==========================================================================
+//####ECOSGPLCOPYRIGHTBEGIN####
+// -------------------------------------------
+// This file is part of eCos, the Embedded Configurable Operating System.
+// Copyright (C) 2005 eCosCentric Ltd
+//
+// eCos is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 2 or (at your option) any later version.
+//
+// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with eCos; if not, write to the Free Software Foundation, Inc.,
+// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+//
+// As a special exception, if other files instantiate templates or use macros
+// or inline functions from this file, or you compile this file and link it
+// with other works to produce a work based on this file, this file does not
+// by itself cause the resulting work to be covered by the GNU General Public
+// License. However the source code for this file must still be made available
+// in accordance with section (3) of the GNU General Public License.
+//
+// This exception does not invalidate any other reasons why a work based on
+// this file might be covered by the GNU General Public License.
+//
+// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
+// at http://sources.redhat.com/ecos/ecos-license/
+// -------------------------------------------
+//####ECOSGPLCOPYRIGHTEND####
+//==========================================================================
+//#####DESCRIPTIONBEGIN####
+//
+// Author(s): Peter Korsgaard
+// Contributors: Peter Korsgaard
+// Date: 2005-04-04
+// Purpose:
+// Description:
+//
+// This code is part of RedBoot (tm).
+//
+//####DESCRIPTIONEND####
+//
+//==========================================================================
+
+#include <redboot.h>
+
+RedBoot_cmd("gunzip",
+ "Uncompress GZIP compressed data",
+ "-s <location> -d <location>",
+ do_gunzip
+ );
+
+void
+do_gunzip(int argc, char *argv[])
+{
+ struct option_info opts[2];
+ unsigned long src, dst;
+ bool src_set, dst_set;
+ _pipe_t pipe;
+ _pipe_t* p = &pipe;
+ int err;
+
+ init_opts(&opts[0], 's', true, OPTION_ARG_TYPE_NUM,
+ (void *)&src, (bool *)&src_set, "source address");
+ init_opts(&opts[1], 'd', true, OPTION_ARG_TYPE_NUM,
+ (void *)&dst, (bool *)&dst_set, "destination address");
+ if (!scan_opts(argc, argv, 1, opts, 2, 0, 0, "")) {
+ return;
+ }
+
+ // Must have src and dst
+ if (!src_set || !dst_set) {
+ // try to use load_address for src
+ if (dst_set
+ && load_address >= (CYG_ADDRESS)ram_start
+ && load_address < load_address_end) {
+ src = load_address;
+ diag_printf("Decompressing from %p to %p\n", src, dst);
+ }
+ else
+ {
+ diag_printf("usage: gunzip -s <addr> -d <addr>\n");
+ return;
+ }
+ }
+
+ p->out_buf = (unsigned char*)dst;
+ p->out_max = p->out_size = -1;
+ p->in_buf = (unsigned char*)src;
+ p->in_avail = -1;
+
+ err = (*_dc_init)(p);
+
+ if (0 == err)
+ err = (*_dc_inflate)(p);
+
+ // Free used resources, do final translation of error value.
+ err = (*_dc_close)(p, err);
+
+ if (0 != err && p->msg) {
+ entry_address = (CYG_ADDRESS)NO_MEMORY;
+ diag_printf("Decompression error: %s\n", p->msg);
+ } else {
+ load_address = entry_address = (CYG_ADDRESS)dst;
+ load_address_end = (CYG_ADDRESS)p->out_buf;
+ diag_printf("Decompressed %d bytes\n",
+ load_address_end - load_address);
+ }
+}
--
Bye, Peter Korsgaard