Esempio n. 1
0
void _unlzma_veneer(){
	uart_write('D'); uart_write(' ');
	int res = unlzma((uint8_t *)code, (uint8_t *)SYSMEM_BASE, 16384);
	if(res != 0) error_loop();
//	uart_write('S'); uart_write(' ');
	long_jump_to_start();
}
Esempio n. 2
0
static int lzma_uncompress(struct squashfs_sb_info *msblk, void **buffer,
	struct buffer_head **bh, int b, int offset, int length, int srclength,
	int pages)
{
	struct squashfs_lzma *stream = msblk->stream;
	void *buff = stream->input;
	int avail, i, bytes = length, res;

	mutex_lock(&lzma_mutex);

	for (i = 0; i < b; i++) {
		wait_on_buffer(bh[i]);
		if (!buffer_uptodate(bh[i]))
			goto block_release;

		avail = min(bytes, msblk->devblksize - offset);
		memcpy(buff, bh[i]->b_data + offset, avail);
		buff += avail;
		bytes -= avail;
		offset = 0;
		put_bh(bh[i]);
	}

	lzma_error = 0;
	res = unlzma(stream->input, length, NULL, NULL, stream->output, NULL,
							error);
	if (res || lzma_error)
		goto failed;

	/* uncompressed size is stored in the LZMA header (5 byte offset) */
	res = bytes = get_unaligned_le32(stream->input + 5);
	for (i = 0, buff = stream->output; bytes && i < pages; i++) {
		avail = min_t(int, bytes, PAGE_CACHE_SIZE);
		memcpy(buffer[i], buff, avail);
		buff += avail;
		bytes -= avail;
	}
	if (bytes)
		goto failed;

	mutex_unlock(&lzma_mutex);
	return res;

block_release:
	for (; i < b; i++)
		put_bh(bh[i]);

failed:
	mutex_unlock(&lzma_mutex);

	ERROR("lzma decompression failed, data probably corrupt\n");
	return -EIO;
}
Esempio n. 3
0
void flashboot()
{
	unsigned int *flashbase;
	unsigned int length;
	unsigned int crc;
	unsigned int got_crc;
	int lzma;
	int r;

	printf("I: Booting from flash...\n");
	if(rescue)
		flashbase = (unsigned int *)FLASH_OFFSET_RESCUE_APP;
	else
		flashbase = (unsigned int *)FLASH_OFFSET_REGULAR_APP;
	length = *flashbase++;
	if(length & 0x80000000) {
		length &= 0x7fffffff;
		lzma = 1;
	} else
		lzma = 0;
	crc = *flashbase++;
	if((length < 32) || (length > 4*1024*1024)) {
		printf("E: Invalid flash boot image length\n");
		return;
	}
	if(lzma) {
		printf("I: Decompressing %d bytes from flash...\n", length);
		got_crc = crc32((unsigned char *)flashbase, length);
		if(crc != got_crc) {
			printf("E: CRC failed (expected %08x, got %08x)\n", crc, got_crc);
			return;
		}
		r = unlzma((unsigned char *)flashbase, length, NULL, NULL, (void *)SDRAM_BASE, NULL, lzma_error);
		if(r < 0)
			return;
	} else {
		printf("I: Loading %d bytes from flash...\n", length);
		memcpy((void *)SDRAM_BASE, flashbase, length);
		got_crc = crc32((unsigned char *)SDRAM_BASE, length);
		if(crc != got_crc) {
			printf("E: CRC failed (expected %08x, got %08x)\n", crc, got_crc);
			return;
		}
	}
	printf("I: Booting...\n");
	boot(0, 0, 0, rescue, SDRAM_BASE);
}
int __init decompress(void *inbuf, unsigned int len, void *outbuf)
{
#if 0 /* Not needed here yet. */
    if ( len >= 2 &&
         (!memcmp(inbuf, "\037\213", 2) || !memcmp(inbuf, "\037\236", 2)) )
        return gunzip(inbuf, len, NULL, NULL, outbuf, NULL, error);
#endif

    if ( len >= 3 && !memcmp(inbuf, "\x42\x5a\x68", 3) )
        return bunzip2(inbuf, len, NULL, NULL, outbuf, NULL, error);

    if ( len >= 2 && !memcmp(inbuf, "\135\000", 2) )
        return unlzma(inbuf, len, NULL, NULL, outbuf, NULL, error);

    if ( len >= 5 && !memcmp(inbuf, "\x89LZO", 5) )
        return unlzo(inbuf, len, NULL, NULL, outbuf, NULL, error);

    return 1;
}
Esempio n. 5
0
void flashboot(void)
{
	unsigned int *flashbase;
	unsigned int length;
	unsigned int crc;
#ifdef FIXME
	unsigned int got_crc;
	int r = 0;
#endif
	int lzma;
	//int i;

	
	if(rescue) {
	    printf("G: Booting from flash (rescue)...\n");
		flashbase = (unsigned int *)FLASH_OFFSET_RESCUE_APP;
	}
	else {
	    //printf("F: Booting from flash...\n");
		flashbase = (unsigned int *)FLASH_OFFSET_REGULAR_APP;
	}
	length = *flashbase++;
	if(length & 0x80000000) {
		length &= 0x7fffffff;
		lzma = 1;
		printf("E: LZMA mode enable\n");
	} else
		lzma = 0;
	crc = *flashbase++;
	
    length = 2628328;
    
	if(length < 32) {
		printf("E: Invalid flash boot image length: length < 32\n");
		return;
	}
	if(length > 4*1024*1024) {
		printf("E: Invalid flash boot image length: length > 4*1024*1024\n");
		return;
	}

	if(lzma) {
	printf("D: Decompressing LZMA\n");
#ifdef FIXME
		printf("I: Decompressing %d bytes from flash...\n", length);
		got_crc = crc32((unsigned char *)flashbase, length);
		if(crc != got_crc) {
			printf("E: CRC failed (expected %08x, got %08x)\n", crc, got_crc);
			return;
		}

		r = unlzma((unsigned char *)flashbase, length, NULL, NULL, (void *)SDRAM_BASE, NULL, lzma_error);

		if(r < 0)
			return;
#endif
	} else {
		//printf("I: Loading %d bytes from flash...\n", length);
        //printf("A: Start Loading bytes from flash...\n");
		if((memcpy((void *)SDRAM_BASE, flashbase, length)) == NULL)
		    printf("C: memcpy return NULL.\n");
	   // printf("B: Loading bytes from flash over...\n");
#ifdef FIXME
		got_crc = crc32((unsigned char *)SDRAM_BASE, length);
		if(crc != got_crc) {
			printf("E: CRC failed (expected %08x, got %08x)\n", crc, got_crc);
			return;
		}
#endif
	}

	//printf("H: Booting...\n");
	boot(0, 0, 0, rescue, SDRAM_BASE);
}