OpenCores
URL https://opencores.org/ocsvn/or1k_old/or1k_old/trunk

Subversion Repositories or1k_old

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /or1k_old/trunk/rc203soc/sw/uClinux/arch/armnommu/boot/compressed
    from Rev 1765 to Rev 1782
    Reverse comparison

Rev 1765 → Rev 1782

/piggyback.c
0,0 → 1,91
/*
* linux/zBoot/piggyback.c
*
* (C) 1993 Hannu Savolainen
*/
 
/*
* This program reads the compressed system image from stdin and
* encapsulates it into an object file written to the stdout.
*/
 
#include <stdio.h>
#include <unistd.h>
#include <a.out.h>
#include <sys/fcntl.h>
 
int main(int argc, char *argv[])
{
int n=0, len=0, fd = 0;
char tmp_buf[640*1024];
struct exec obj = {0x00670107}; /* object header */
char string_names[] = {"_input_data\0_input_end\0"};
 
struct nlist var_names[2] = /* Symbol table */
{
{ /* _input_data */
{(char *)4}, 7, 0, 0, 0
},
{ /* _input_len */
{(char *)16}, 7, 0, 0, 0
}
};
 
 
if (argc > 1) {
fd = open (argv[1], O_RDONLY);
if (fd < 0) {
fprintf (stderr, "%s: ", argv[0]);
perror (argv[1]);
exit (1);
}
}
 
len = 0;
while ((n = read(fd, &tmp_buf[len], sizeof(tmp_buf)-len+1)) > 0)
len += n;
 
len = (len + 3) & ~3;
 
if (n==-1) {
perror("stdin");
exit(-1);
}
 
if (len >= sizeof(tmp_buf)) {
fprintf(stderr, "%s: Input too large\n", argv[0]);
exit(-1);
}
 
if (argc < 2)
fprintf(stderr, "Compressed size %d.\n", len);
 
/*
* Output object header
*/
obj.a_data = len /* + sizeof(long) */;
obj.a_syms = sizeof(var_names);
write(1, (char *)&obj, sizeof(obj));
 
/*
* Output data segment (compressed system & len)
*/
write(1, tmp_buf, len);
 
/*
* Output symbol table
*/
var_names[1].n_value = len;
write(1, (char *)&var_names, sizeof(var_names));
 
/*
* Output string table
*/
len = sizeof(string_names) + sizeof(len);
write(1, (char *)&len, sizeof(len));
write(1, string_names, sizeof(string_names));
 
exit(0);
 
}
/Makefile.debug
0,0 → 1,16
#
# linux/arch/arm/boot/compressed/Makefile
#
# create a compressed vmlinux image from the original vmlinux
#
 
COMPRESSED_EXTRA=../../lib/ll_char_wr.o
OBJECTS=misc-debug.o $(COMPRESSED_EXTRA)
 
CFLAGS=-D__KERNEL__ -O2 -DSTDC_HEADERS -DSTANDALONE_DEBUG -Wall -I../../../../include -c
 
test-gzip: piggy.o $(OBJECTS)
$(CC) -o $@ $(OBJECTS) piggy.o
 
misc-debug.o: misc.c
$(CC) $(CFLAGS) -o $@ misc.c
/head.S
0,0 → 1,102
/*
* linux/arch/arm/boot/compressed/head.S
*
* Copyright (C) 1996 Russell King
*/
.text
/*
* sort out different calling conventions
*/
start: teq r0, #0
beq newparams
mov r4, #0x02000000
add r4, r4, #0x7C000
mov r3, #0x4000
sub r3, r3, #4
1: ldmia r0!, {r5 - r12}
stmia r4!, {r5 - r12}
subs r3, r3, #32
bpl 1b
newparams: adr r2, LC0
ldmia r2, {r2, r3, r4, r5, r6, sp}
adr r7, start
sub r6, r7, r6
/*
* Relocate pointers
*/
add r2, r2, r6
add r3, r3, r6
add r5, r5, r6
add sp, sp, r6
/*
* Clear zero-init
*/
mov r6, #0
1: str r6, [r2], #4
cmp r2, r3
blt 1b
str r1, [r5] @ save architecture
/*
* Uncompress the kernel
*/
mov r1, #0x8000
add r2, r2, r1, lsl #1 @ Add 64k for malloc
sub r1, r1, #1
add r2, r2, r1
bic r5, r2, r1 @ decompress kernel to after end of the compressed
mov r0, r5
bl _decompress_kernel
add r0, r0, #7
bic r2, r0, #7
/*
* Now move the kernel to the correct location (r5 -> r4, len r0)
*/
mov r0, r4 @ r0 = start of real kernel
mov r1, r5 @ r1 = start of kernel image
add r3, r5, r2 @ r3 = end of kernel
adr r4, movecode
adr r5, movecodeend
1: ldmia r4!, {r6 - r12, lr}
stmia r3!, {r6 - r12, lr}
cmp r4, r5
blt 1b
mrc p15, 0, r5, c0, c0
eor r5, r5, #0x44 << 24
eor r5, r5, #0x01 << 16
eor r5, r5, #0xa1 << 8
movs r5, r5, lsr #4
mov r5, #0
mcreq p15, 0, r5, c7, c5, 0 @ flush I cache
ldr r5, LC0 + 12 @ get architecture
ldr r5, [r5]
add pc, r1, r2 @ Call move code
 
/*
* r0 = length, r1 = to, r2 = from
*/
movecode: add r3, r1, r2
mov r4, r0
1: ldmia r1!, {r6 - r12, lr}
stmia r0!, {r6 - r12, lr}
cmp r1, r3
blt 1b
mrc p15, 0, r0, c0, c0
eor r0, r0, #0x44 << 24
eor r0, r0, #0x01 << 16
eor r0, r0, #0xa1 << 8
movs r0, r0, lsr #4
mov r0, #0
mcreq p15, 0, r0, c7, c5, 0 @ flush I cache
mov r1, r5 @ call kernel correctly
add pc, r4, #0x20 @ call via EXEC entry
 
movecodeend:
LC0: .word __edata
.word __end
.word LOADADDR
.word _architecture
.word start
.word _user_stack+4096
 
.bss
_architecture: .word 0
/xtract.c
0,0 → 1,92
/*
* linux/zBoot/xtract.c
*
* Copyright (C) 1993 Hannu Savolainen
*
* Extracts the system image and writes it to the stdout.
* based on tools/build.c by Linus Torvalds
*/
 
#include <stdio.h> /* fprintf */
#include <string.h>
#include <stdlib.h> /* contains exit */
#include <sys/types.h> /* unistd.h needs this */
#include <sys/stat.h>
#include <sys/sysmacros.h>
#include <unistd.h> /* contains read/write */
#include <fcntl.h>
#include <a.out.h>
 
#define N_MAGIC_OFFSET 1024
 
static int GCC_HEADER = sizeof(struct exec);
 
#define STRINGIFY(x) #x
 
void die(char * str)
{
fprintf(stderr,"%s\n",str);
exit(1);
}
 
void usage(void)
{
die("Usage: xtract system [ | gzip | piggyback > piggy.s]");
}
 
int main(int argc, char ** argv)
{
int id, sz;
char buf[1024];
 
struct exec *ex = ((struct exec *)buf) + 1;
 
if (argc != 2)
usage();
if ((id=open(argv[1],O_RDONLY,0))<0)
die("Unable to open 'system'");
if (read(id,ex,GCC_HEADER) != GCC_HEADER)
die("Unable to read header of 'system'");
 
switch (N_MAGIC(*ex)) {
case ZMAGIC:
GCC_HEADER = N_MAGIC_OFFSET;
lseek(id, GCC_HEADER, SEEK_SET);
break;
case QMAGIC:
memset (buf, 0, GCC_HEADER);
buf[0x14] = 0x20;
write (1, buf, GCC_HEADER);
break;
default:
die("Non-GCC header of 'system'");
}
 
sz = N_SYMOFF(*ex) - GCC_HEADER + 4; /* +4 to get the same result than tools/build */
 
fprintf(stderr, "System size is %d\n", sz);
 
while (sz) {
int l, n;
 
l = sz;
if (l > sizeof(buf)) l = sizeof(buf);
 
if ((n=read(id, buf, l)) !=l)
{
if (n == -1)
perror(argv[1]);
else
fprintf(stderr, "Unexpected EOF\n");
 
die("Can't read system");
}
 
write(1, buf, l);
sz -= l;
}
 
close(id);
return(0);
}
/misc.c
0,0 → 1,305
/*
* misc.c
*
* This is a collection of several routines from gzip-1.0.3
* adapted for Linux.
*
* malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
*/
 
#include <asm/segment.h>
#include <asm/arch/uncompress.h>
#include <asm/proc/uncompress.h>
 
#ifdef STANDALONE_DEBUG
#define puts printf
#endif
 
#define __ptr_t void *
 
/*
* Optimised C version of memzero for the ARM.
*/
extern __inline__ __ptr_t __memzero (__ptr_t s, size_t n)
{
union { void *vp; unsigned long *ulp; unsigned char *ucp; } u;
int i;
 
u.vp = s;
 
for (i = n >> 5; i > 0; i--) {
*u.ulp++ = 0;
*u.ulp++ = 0;
*u.ulp++ = 0;
*u.ulp++ = 0;
*u.ulp++ = 0;
*u.ulp++ = 0;
*u.ulp++ = 0;
*u.ulp++ = 0;
}
 
if (n & 1 << 4) {
*u.ulp++ = 0;
*u.ulp++ = 0;
*u.ulp++ = 0;
*u.ulp++ = 0;
}
 
if (n & 1 << 3) {
*u.ulp++ = 0;
*u.ulp++ = 0;
}
 
if (n & 1 << 2)
*u.ulp++ = 0;
 
if (n & 1 << 1) {
*u.ucp++ = 0;
*u.ucp++ = 0;
}
 
if (n & 1)
*u.ucp++ = 0;
return s;
}
 
#define memzero(s,n) __memzero(s,n)
 
extern __inline__ __ptr_t memcpy(__ptr_t __dest, __const __ptr_t __src,
size_t __n)
{
int i = 0;
unsigned char *d = (unsigned char *)__dest, *s = (unsigned char *)__src;
 
for (i = __n >> 3; i > 0; i--) {
*d++ = *s++;
*d++ = *s++;
*d++ = *s++;
*d++ = *s++;
*d++ = *s++;
*d++ = *s++;
*d++ = *s++;
*d++ = *s++;
}
 
if (__n & 1 << 2) {
*d++ = *s++;
*d++ = *s++;
*d++ = *s++;
*d++ = *s++;
}
 
if (__n & 1 << 1) {
*d++ = *s++;
*d++ = *s++;
}
 
if (__n & 1)
*d++ = *s++;
 
return __dest;
}
 
/*
* gzip delarations
*/
#define OF(args) args
#define STATIC static
 
typedef unsigned char uch;
typedef unsigned short ush;
typedef unsigned long ulg;
 
#define WSIZE 0x8000 /* Window size must be at least 32k, */
/* and a power of two */
 
static uch *inbuf; /* input buffer */
static uch window[WSIZE]; /* Sliding window buffer */
 
static unsigned insize; /* valid bytes in inbuf */
static unsigned inptr; /* index of next byte to be processed in inbuf */
static unsigned outcnt; /* bytes in output buffer */
 
/* gzip flag byte */
#define ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */
#define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
#define ORIG_NAME 0x08 /* bit 3 set: original file name present */
#define COMMENT 0x10 /* bit 4 set: file comment present */
#define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */
#define RESERVED 0xC0 /* bit 6,7: reserved */
 
#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())
 
/* Diagnostic functions */
#ifdef DEBUG
# define Assert(cond,msg) {if(!(cond)) error(msg);}
# define Trace(x) fprintf x
# define Tracev(x) {if (verbose) fprintf x ;}
# define Tracevv(x) {if (verbose>1) fprintf x ;}
# define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
# define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
#else
# define Assert(cond,msg)
# define Trace(x)
# define Tracev(x)
# define Tracevv(x)
# define Tracec(c,x)
# define Tracecv(c,x)
#endif
 
static int fill_inbuf(void);
static void flush_window(void);
static void error(char *m);
static void gzip_mark(void **);
static void gzip_release(void **);
 
extern char input_data[], input_end[];
 
static uch *output_data;
static ulg output_ptr;
static ulg bytes_out;
 
static void *malloc(int size);
static void free(void *where);
static void error(char *m);
static void gzip_mark(void **);
static void gzip_release(void **);
 
static void puts(const char *);
 
extern int end;
static ulg free_mem_ptr;
static ulg free_mem_ptr_end;
 
#define HEAP_SIZE 0x2000
 
#include "../../../../lib/inflate.c"
 
#ifndef STANDALONE_DEBUG
static void *malloc(int size)
{
void *p;
 
if (size <0) error("Malloc error\n");
if (free_mem_ptr <= 0) error("Memory error\n");
 
free_mem_ptr = (free_mem_ptr + 3) & ~3; /* Align */
 
p = (void *)free_mem_ptr;
free_mem_ptr += size;
 
if (free_mem_ptr >= free_mem_ptr_end)
error("Out of memory");
return p;
}
 
static void free(void *where)
{ /* gzip_mark & gzip_release do the free */
}
 
static void gzip_mark(void **ptr)
{
*ptr = (void *) free_mem_ptr;
}
 
static void gzip_release(void **ptr)
{
free_mem_ptr = (long) *ptr;
}
#else
static void gzip_mark(void **ptr)
{
}
 
static void gzip_release(void **ptr)
{
}
#endif
 
/* ===========================================================================
* Fill the input buffer. This is called only when the buffer is empty
* and at least one byte is really needed.
*/
int fill_inbuf()
{
if (insize != 0)
error("ran out of input data\n");
 
inbuf = input_data;
insize = input_end - input_data;
inptr = 1;
return inbuf[0];
}
 
/* ===========================================================================
* Write the output window window[0..outcnt-1] and update crc and bytes_out.
* (Used for the decompressed data only.)
*/
void flush_window()
{
ulg c = crc;
unsigned n;
uch *in, *out, ch;
 
in = window;
out = &output_data[output_ptr];
for (n = 0; n < outcnt; n++) {
ch = *out++ = *in++;
c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
}
crc = c;
bytes_out += (ulg)outcnt;
output_ptr += (ulg)outcnt;
outcnt = 0;
}
 
static void error(char *x)
{
int ptr;
 
puts("\n\n");
puts(x);
puts("\n\n -- System halted");
 
while(1); /* Halt */
}
 
#define STACK_SIZE (4096)
 
ulg user_stack [STACK_SIZE];
 
#ifndef STANDALONE_DEBUG
 
ulg decompress_kernel(ulg output_start)
{
free_mem_ptr = (ulg)&end;
free_mem_ptr_end = output_start;
 
proc_decomp_setup ();
arch_decomp_setup ();
 
output_data = (uch *)output_start; /* Points to kernel start */
 
makecrc();
puts("Uncompressing Linux...");
gunzip();
puts("done.\nNow booting the kernel\n");
return output_ptr;
}
#else
 
char output_buffer[1024*1024];
 
int main()
{
output_data = output_buffer;
 
makecrc();
puts("Uncompressing Linux...");
gunzip();
puts("done.\n");
return 0;
}
#endif
/Makefile
0,0 → 1,38
#
# linux/arch/arm/boot/compressed/Makefile
#
# create a compressed vmlinuz image from the original vmlinux
#
# With this config, max compressed image size = 640k
# Uncompressed image size = 1.3M (text+data)
 
 
HEAD = head.o
SYSTEM = $(TOPDIR)/vmlinux
OBJS = $(HEAD) misc.o $(COMPRESSED_EXTRA)
 
CFLAGS = -O2 -DSTDC_HEADERS $(CFLAGS_PROC)
ARFLAGS = rc
 
all: vmlinux
 
vmlinux: piggy.o $(OBJS)
$(LD) $(ZLINKFLAGS) -o vmlinux $(OBJS) piggy.o
 
head.o: head.S
$(CC) -traditional -DLOADADDR=$(ZRELADDR) -c head.S
 
piggy.o: $(SYSTEM) xtract piggyback
./xtract $(SYSTEM) | gzip -9 | ./piggyback > $@
 
# rules for extracting & piggybacking the kernel
 
xtract: xtract.c
$(HOSTCC) $(HOSTCFLAGS) -o xtract xtract.c
 
piggyback: piggyback.c
$(HOSTCC) $(HOSTCFLAGS) -o piggyback piggyback.c
 
clean:
rm -f xtract piggyback vmlinux core
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.