|
From: Andy P. <at...@us...> - 2002-04-10 18:39:17
|
Update of /cvsroot/linux-vax/kernel-2.4/arch/ppc/boot/chrp
In directory usw-pr-cvs1:/tmp/cvs-serv25860/ppc/boot/chrp
Added Files:
Makefile main.c misc.S start.c
Log Message:
synch 2.4.15 commit 43
--- NEW FILE ---
# BK Id: SCCS/s.Makefile 1.13 07/27/01 20:24:17 trini
#
# Makefile for making ELF bootable images for booting on CHRP
# using Open Firmware.
#
# Geert Uytterhoeven September 1997
#
# Based on coffboot by Paul Mackerras
ifeq ($(CONFIG_PPC64BRIDGE),y)
MSIZE=.64
AFLAGS += -Wa,-mppc64bridge
else
MSIZE=
endif
.c.o:
$(CC) $(CFLAGS) -DKERNELBASE=$(KERNELBASE) -c -o $*.o $<
.S.o:
$(CC) $(AFLAGS) -traditional -c -o $*.o $<
LD_ARGS = -Ttext 0x00400000
OBJS = ../common/crt0.o start.o main.o misc.o ../common/string.o image.o \
../common/ofcommon.o
LIBS = $(TOPDIR)/lib/lib.a ../lib/zlib.a
ADDNOTE = ../utils/addnote
PIGGYBACK = ../utils/piggyback
ifeq ($(CONFIG_SMP),y)
TFTPIMAGE=/tftpboot/zImage.chrp.smp$(MSIZE)
else
TFTPIMAGE=/tftpboot/zImage.chrp$(MSIZE)
endif
all: zImage
znetboot: zImage
ifdef CONFIG_SMP
cp -f $(TOPDIR)/vmlinux /tftpboot/vmlinux.smp
else
cp -f $(TOPDIR)/vmlinux /tftpboot/vmlinux
endif
ifdef CONFIG_PPC64BRIDGE
cp -f $(TOPDIR)/vmlinux /tftpboot/vmlinux.64
endif
cp ../images/zImage.chrp $(TFTPIMAGE)
znetboot.initrd: zImage.initrd
cp ../images/zImage.initrd.chrp $(TFTPIMAGE)
floppy: zImage
mcopy zImage a:zImage
image.o: $(PIGGYBACK) ../images/vmlinux.gz
$(PIGGYBACK) image < ../images/vmlinux.gz | $(AS) -o $@
sysmap.o: $(PIGGYBACK) $(TOPDIR)/System.map
$(PIGGYBACK) sysmap < $(TOPDIR)/System.map | $(AS) -o $@
initrd.o: ../images/ramdisk.image.gz $(PIGGYBACK)
$(PIGGYBACK) initrd < ../images/ramdisk.image.gz | $(AS) -o $@
zImage: $(OBJS) $(LIBS) ../common/no_initrd.o $(ADDNOTE) ../images/vmlinux.gz
$(LD) $(LD_ARGS) -o ../images/$@.chrp $(OBJS) ../common/no_initrd.o $(LIBS)
cp ../images/$@.chrp ../images/$@.chrp-rs6k
$(ADDNOTE) ../images/$@.chrp-rs6k
zImage.initrd: $(OBJS) $(LIBS) initrd.o $(ADDNOTE) ../images/vmlinux.gz
$(LD) $(LD_ARGS) -o ../images/$@.chrp $(OBJS) initrd.o $(LIBS)
cp ../images/$@.chrp ../images/$@.chrp-rs6k
$(ADDNOTE) ../images/$@.chrp-rs6k
include $(TOPDIR)/Rules.make
--- NEW FILE ---
/*
* BK Id: SCCS/s.main.c 1.13 07/27/01 20:24:17 trini
*/
/*
* Copyright (C) Paul Mackerras 1997.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*/
#include "nonstdio.h"
#include <asm/processor.h>
extern char _end[];
extern char initrd_data[];
extern char image_data[];
extern char sysmap_data[];
extern int getprop(void *, const char *, void *, int);
extern int initrd_len;
extern int image_len;
extern int sysmap_len;
extern unsigned int heap_max;
extern void claim(unsigned int virt, unsigned int size, unsigned int align);
extern void *finddevice(const char *);
extern void flush_cache(void *, unsigned long);
extern void gunzip(void *, int, unsigned char *, int *);
extern void make_bi_recs(unsigned long addr, char *name, unsigned int mach,
unsigned int progend);
extern void pause(void);
char *avail_ram;
char *begin_avail, *end_avail;
char *avail_high;
#define RAM_START 0x00000000
#define RAM_END (64<<20)
#define BOOT_START ((unsigned long)_start)
#define BOOT_END ((unsigned long)(_end + 0xFFF) & ~0xFFF)
#define RAM_FREE ((unsigned long)(_end+0x1000)&~0xFFF)
#define PROG_START 0x00010000
#define PROG_SIZE 0x00400000 /* 4MB */
#define SCRATCH_SIZE (128 << 10)
static char scratch[SCRATCH_SIZE]; /* 1MB of scratch space for gunzip */
void
chrpboot(int a1, int a2, void *prom)
{
unsigned sa, len;
void *dst;
unsigned char *im;
unsigned initrd_start=0, initrd_size=0;
extern char _start;
printf("chrpboot starting: loaded at 0x%p\n\r", &_start);
if (initrd_len) {
initrd_size = initrd_len;
initrd_start = (RAM_END - initrd_size) & ~0xFFF;
claim(initrd_start, RAM_END - initrd_start, 0);
printf("initial ramdisk moving 0x%x <- 0x%p (%x bytes)\n\r",
initrd_start, initrd_data, initrd_size);
memcpy((char *)initrd_start, initrd_data, initrd_size);
}
im = image_data;
len = image_len;
/* claim 4MB starting at PROG_START */
claim(PROG_START, PROG_SIZE - PROG_START, 0);
dst = (void *) PROG_START;
if (im[0] == 0x1f && im[1] == 0x8b) {
avail_ram = scratch;
begin_avail = avail_high = avail_ram;
end_avail = scratch + sizeof(scratch);
printf("gunzipping (0x%p <- 0x%p:0x%p)...", dst, im, im+len);
gunzip(dst, 0x400000, im, &len);
printf("done %u bytes\n\r", len);
printf("%u bytes of heap consumed, max in use %u\n\r",
avail_high - begin_avail, heap_max);
} else {
memmove(dst, im, len);
}
flush_cache(dst, len);
make_bi_recs(((unsigned long) dst + len), "chrpboot", _MACH_chrp,
(PROG_START + PROG_SIZE));
sa = (unsigned long)PROG_START;
printf("start address = 0x%x\n\r", sa);
(*(void (*)())sa)(a1, a2, prom, initrd_start, initrd_size);
printf("returned?\n\r");
pause();
}
--- NEW FILE ---
/*
* BK Id: SCCS/s.misc.S 1.6 05/18/01 15:16:59 cort
*/
/*
* Copyright (C) Paul Mackerras 1997.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*/
.text
/*
* Use the BAT0 registers to map the 1st 8MB of RAM to 0x90000000.
*/
.globl setup_bats
setup_bats:
mfpvr 3
rlwinm 3,3,16,16,31 /* r3 = 1 for 601, 4 for 604 */
cmpi 0,3,1
lis 4,0x9000
bne 4f
ori 4,4,4 /* set up BAT registers for 601 */
li 5,0x7f
b 5f
4: ori 4,4,0xff /* set up BAT registers for 604 */
li 5,2
mtdbatu 3,4
mtdbatl 3,5
5: mtibatu 3,4
mtibatl 3,5
isync
blr
/*
* Flush the dcache and invalidate the icache for a range of addresses.
*
* flush_cache(addr, len)
*/
.global flush_cache
flush_cache:
addi 4,4,0x1f /* len = (len + 0x1f) / 0x20 */
rlwinm. 4,4,27,5,31
mtctr 4
beqlr
1: dcbf 0,3
icbi 0,3
addi 3,3,0x20
bdnz 1b
sync
isync
blr
--- NEW FILE ---
/*
* BK Id: SCCS/s.start.c 1.8 07/25/01 18:13:07 trini
*/
/*
* Copyright (C) Paul Mackerras 1997.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*/
#include <stdarg.h>
int (*prom)();
void *chosen_handle;
void *stdin;
void *stdout;
void *stderr;
void exit(void);
void *finddevice(const char *name);
int getprop(void *phandle, const char *name, void *buf, int buflen);
void printk(char *fmt, ...);
extern void chrpboot(int a1, int a2, void *prom);
extern int strlen(const char *s);
void
start(int a1, int a2, void *promptr)
{
prom = (int (*)()) promptr;
chosen_handle = finddevice("/chosen");
if (chosen_handle == (void *) -1)
exit();
if (getprop(chosen_handle, "stdout", &stdout, sizeof(stdout)) != 4)
exit();
stderr = stdout;
if (getprop(chosen_handle, "stdin", &stdin, sizeof(stdin)) != 4)
exit();
chrpboot(a1, a2, promptr);
for (;;)
exit();
}
int
write(void *handle, void *ptr, int nb)
{
struct prom_args {
char *service;
int nargs;
int nret;
void *ihandle;
void *addr;
int len;
int actual;
} args;
args.service = "write";
args.nargs = 3;
args.nret = 1;
args.ihandle = handle;
args.addr = ptr;
args.len = nb;
args.actual = -1;
(*prom)(&args);
return args.actual;
}
int
read(void *handle, void *ptr, int nb)
{
struct prom_args {
char *service;
int nargs;
int nret;
void *ihandle;
void *addr;
int len;
int actual;
} args;
args.service = "read";
args.nargs = 3;
args.nret = 1;
args.ihandle = handle;
args.addr = ptr;
args.len = nb;
args.actual = -1;
(*prom)(&args);
return args.actual;
}
void
exit(void)
{
struct prom_args {
char *service;
} args;
for (;;) {
args.service = "exit";
(*prom)(&args);
}
}
void
pause(void)
{
struct prom_args {
char *service;
} args;
args.service = "enter";
(*prom)(&args);
}
void *
finddevice(const char *name)
{
struct prom_args {
char *service;
int nargs;
int nret;
const char *devspec;
void *phandle;
} args;
args.service = "finddevice";
args.nargs = 1;
args.nret = 1;
args.devspec = name;
args.phandle = (void *) -1;
(*prom)(&args);
return args.phandle;
}
void *
claim(unsigned int virt, unsigned int size, unsigned int align)
{
struct prom_args {
char *service;
int nargs;
int nret;
unsigned int virt;
unsigned int size;
unsigned int align;
void *ret;
} args;
args.service = "claim";
args.nargs = 3;
args.nret = 1;
args.virt = virt;
args.size = size;
args.align = align;
(*prom)(&args);
return args.ret;
}
int
getprop(void *phandle, const char *name, void *buf, int buflen)
{
struct prom_args {
char *service;
int nargs;
int nret;
void *phandle;
const char *name;
void *buf;
int buflen;
int size;
} args;
args.service = "getprop";
args.nargs = 4;
args.nret = 1;
args.phandle = phandle;
args.name = name;
args.buf = buf;
args.buflen = buflen;
args.size = -1;
(*prom)(&args);
return args.size;
}
int
putc(int c, void *f)
{
char ch = c;
if (c == '\n')
putc('\r', f);
return write(f, &ch, 1) == 1? c: -1;
}
int
putchar(int c)
{
return putc(c, stdout);
}
int
fputs(char *str, void *f)
{
int n = strlen(str);
return write(f, str, n) == n? 0: -1;
}
int
readchar()
{
char ch;
for (;;) {
switch (read(stdin, &ch, 1)) {
case 1:
return ch;
case -1:
printk("read(stdin) returned -1\r\n");
return -1;
}
}
}
static char line[256];
static char *lineptr;
static int lineleft;
int
getchar(void)
{
int c;
if (lineleft == 0) {
lineptr = line;
for (;;) {
c = readchar();
if (c == -1 || c == 4)
break;
if (c == '\r' || c == '\n') {
*lineptr++ = '\n';
putchar('\n');
break;
}
switch (c) {
case 0177:
case '\b':
if (lineptr > line) {
putchar('\b');
putchar(' ');
putchar('\b');
--lineptr;
}
break;
case 'U' & 0x1F:
while (lineptr > line) {
putchar('\b');
putchar(' ');
putchar('\b');
--lineptr;
}
break;
default:
if (lineptr >= &line[sizeof(line) - 1])
putchar('\a');
else {
putchar(c);
*lineptr++ = c;
}
}
}
lineleft = lineptr - line;
lineptr = line;
}
if (lineleft == 0)
return -1;
--lineleft;
return *lineptr++;
}
extern int vsprintf(char *buf, const char *fmt, va_list args);
static char sprint_buf[1024];
void
printk(char *fmt, ...)
{
va_list args;
int n;
va_start(args, fmt);
n = vsprintf(sprint_buf, fmt, args);
va_end(args);
write(stdout, sprint_buf, n);
}
int
printf(char *fmt, ...)
{
va_list args;
int n;
va_start(args, fmt);
n = vsprintf(sprint_buf, fmt, args);
va_end(args);
write(stdout, sprint_buf, n);
return n;
}
|