source: svn/trunk/newcon3bcm2_21bu/dta/src/jar/jar_main.c

Last change on this file was 2, checked in by jglee, 11 years ago

first commit

  • Property svn:executable set to *
File size: 2.6 KB
RevLine 
[2]1/***************************************************************************
2 *     Copyright (c) 2003-2010, Broadcom Corporation
3 *     All Rights Reserved
4 *     Confidential Property of Broadcom Corporation
5 *
6 *  THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE
7 *  AGREEMENT  BETWEEN THE USER AND BROADCOM.  YOU HAVE NO RIGHT TO USE OR
8 *  EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT.
9 *
10 * $brcm_Workfile: $
11 * $brcm_Revision: $
12 * $brcm_Date: $
13 *
14 * Module Description:
15 *
16 * Revision History:
17 *
18 * $brcm_Log: $
19 *
20 *
21 ***************************************************************************/
22
23#include "fast_heap.h"
24#include "zlib.h"
25
26#define RAM_TEXT_BASE 0x80016000
27#define RAM_TEXT_SIZE 0x01000000
28
29extern void clear_all_d_cache(void);
30extern void invalidate_all_i_cache(void);
31
32static int decompress(unsigned char *in_buf, unsigned int in_size, unsigned char * out_buf, unsigned int out_size);
33static void run_compressed(unsigned char * data, unsigned int len);
34
35extern unsigned int comp_size;
36extern unsigned int _edata;
37extern unsigned int _end;
38
39void bcm_main(void)
40{
41    unsigned char * compressed_image;
42    unsigned int compressed_size;
43
44    fast_heap_init((unsigned long)&_end);
45
46    compressed_size = (unsigned int) &comp_size;
47    compressed_image = (unsigned char *) &_edata;
48    run_compressed(compressed_image, compressed_size);
49    while(1);
50}
51
52void *memset(void *dest,int c,size_t count)
53{
54    uint8_t *d = dest;
55    for(;count>0;count--) {
56        *d++ = c;
57    }
58    return dest;
59}
60
61typedef void (*entry_t)(void);
62
63void run_compressed(unsigned char * data, unsigned int len)
64{
65    int rc;
66    unsigned char * text;
67    entry_t entry;
68
69    text = (unsigned char *)RAM_TEXT_BASE;
70    rc = decompress(data, len, text, RAM_TEXT_SIZE);
71    if(rc > 0){
72        entry = (entry_t) RAM_TEXT_BASE;
73        clear_all_d_cache();
74        invalidate_all_i_cache();
75        entry();
76    }
77}
78
79int decompress(unsigned char *in_buf, unsigned int in_size, unsigned char * out_buf, unsigned int out_size)
80{
81    z_stream strm;
82    int ret;
83
84    memset(&strm,0,sizeof(strm));
85    strm.avail_in = in_size;
86    strm.next_in = in_buf;
87    strm.avail_out = out_size;
88    strm.next_out = out_buf;
89    ret = inflateInit2(&strm, 15+32);
90    if (ret == Z_OK)
91    {
92        ret = inflate(&strm, Z_FINISH);
93        inflateEnd(&strm);
94        if ((ret == Z_STREAM_END) || (ret == Z_OK))
95        {
96            return strm.total_out;
97        }
98        else if (ret > 0)
99        {
100            return -ret;
101        }
102    }
103    return ret;
104}
105
106/* Please do not remove! */
107/* Local Variables: */
108/* mode: C */
109/* indent-tabs-mode: nil */
110/* End: */
Note: See TracBrowser for help on using the repository browser.