1 #include <pkgconf/system.h> /* which packages are enabled/disabled */
2 #include <pkgconf/kernel.h>
3 #include <pkgconf/libc_startup.h>
4 #include <cyg/compress/zlib.h>
5 #include <cyg/hal/hal_arch.h> /* CYGNUM_HAL_STACK_SIZE_TYPICAL */
6 #include <cyg/hal/hal_intr.h>
7 #include <cyg/hal/hal_diag.h>
9 #include <cyg/kernel/kapi.h>
10 #include <cyg/io/io.h> /* I/O functions */
11 #include <cyg/infra/diag.h> // diag_printf
13 #include <cyg/compress/zlib.h>
16 #include "addresses.h"
18 cyg_uint8 inflateBuffer
[8192];
20 #define NONCACHE_RAM_APPLICATION_START (0x80000000 | RAM_APPLICATION_START)
21 #define NONCACHE_ROM_APPLICATION_START (0x80000000 | ROM_APPLICATION_START)
23 int main(int argc
, char **argv
)
25 cyg_interrupt_disable();
26 diag_printf("Deflating application...\n");
28 cyg_uint8
*DRAM
= (cyg_uint8
*)NONCACHE_RAM_APPLICATION_START
;
30 z_stream d_stream
; /* decompression stream */
31 d_stream
.zalloc
= Z_NULL
;
32 d_stream
.zfree
= Z_NULL
;
33 d_stream
.opaque
= Z_NULL
;
35 d_stream
.next_in
= NONCACHE_ROM_APPLICATION_START
;
36 d_stream
.avail_in
= 0x1000000;
38 int err
= inflateInit(&d_stream
);
40 if (err
== Z_MEM_ERROR
)
42 diag_printf("Failed to deflate application %d\n", err
);
50 d_stream
.avail_out
= sizeof(inflateBuffer
);
51 d_stream
.next_out
= inflateBuffer
;
53 int err
= inflate(&d_stream
, Z_NO_FLUSH
);
54 int len
= sizeof(inflateBuffer
) - d_stream
.avail_out
;
56 memcpy(DRAM
+ offset
, inflateBuffer
, len
);
60 if (err
== Z_STREAM_END
)
62 diag_printf("Launching application(%d bytes)...\n", offset
);
63 /* launch application! */
64 ((void(*)(void))(NONCACHE_RAM_APPLICATION_START
))();
72 diag_printf("Failed to deflate application %d\n", err
);
77 diag_printf("Failed to deflate application %d\n", err
);