| [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 | |
|---|
| 29 | extern void clear_all_d_cache(void); |
|---|
| 30 | extern void invalidate_all_i_cache(void); |
|---|
| 31 | |
|---|
| 32 | static int decompress(unsigned char *in_buf, unsigned int in_size, unsigned char * out_buf, unsigned int out_size); |
|---|
| 33 | static void run_compressed(unsigned char * data, unsigned int len); |
|---|
| 34 | |
|---|
| 35 | extern unsigned int comp_size; |
|---|
| 36 | extern unsigned int _edata; |
|---|
| 37 | extern unsigned int _end; |
|---|
| 38 | |
|---|
| 39 | void 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 | |
|---|
| 52 | void *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 | |
|---|
| 61 | typedef void (*entry_t)(void); |
|---|
| 62 | |
|---|
| 63 | void 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 | |
|---|
| 79 | int 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: */ |
|---|