From: wdenk Date: Tue, 1 May 2001 16:11:50 +0000 (+0000) Subject: PPCBoot now supports NetBSD both as host (build PPCBoot) and target X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=b399e724051f1d9cb05e7ccef7ada057a21a9afb;p=users%2Frw%2Fppcboot.git PPCBoot now supports NetBSD both as host (build PPCBoot) and target system (boots NetBSD/mpc8xx). Fix bug in flash write code for PCU E. --- diff --git a/CHANGELOG b/CHANGELOG index 407059a..25c8a0d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -56,6 +56,10 @@ To do: Modifications for 0.9.2: ====================================================================== +* PPCBoot now supports NetBSD both as host (build PPCBoot) and target + system (boots NetBSD/mpc8xx). + (Patch by Dr. Bruno Achauer, 1 May 2001) + * Fix confusion of CFG_FLASH_BASE and CFG_MONITOR_BASE in many source files (maybe I've missed a few places, be careful!) diff --git a/CREDITS b/CREDITS index 324767a..dd3c8e0 100644 --- a/CREDITS +++ b/CREDITS @@ -14,6 +14,10 @@ # Wolfgang Denk #---------- +N: Dr. Bruno Achauer +E: bruno@exet-ag.de +D: Support for NetBSD (both as host and target system) + N: Andre Beaudin E: D: PCMCIA, Ethernet, TFTP diff --git a/Makefile b/Makefile index 7112eba..146c6bc 100644 --- a/Makefile +++ b/Makefile @@ -22,12 +22,18 @@ # HOSTARCH := $(shell uname -m | \ - sed -e s/i.86/i386/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/) + sed -e s/i.86/i386/ \ + -e s/sun4u/sparc64/ \ + -e s/arm.*/arm/ \ + -e s/sa110/arm/ \ + -e s/macppc/ppc/) + +HOSTOS := $(shell uname -s | tr A-Z a-z) ifeq ($(HOSTARCH),ppc) CROSS_COMPILE = else -CROSS_COMPILE = powerpc-linux- +CROSS_COMPILE = powerpc-$(HOSTOS)- endif export CROSS_COMPILE HOSTARCH diff --git a/README b/README index 8fedddf..99b565d 100644 --- a/README +++ b/README @@ -620,8 +620,8 @@ Building the Software: Building PPCBoot has been tested in native PPC environments (on a PowerBook G# running LinuxPPC 2000) and in cross environments -(running RedHat 6.0 and 6.2 Linux on x86, and Solaris 2.6 on a -SPARC). +(running RedHat 6.x and 7.x Linux on x86, Solaris 2.6 on a SPARC, and +NetBSD 1.5 on x86). If you are not using a native PPC environment, it is assumed that you have the GNU cross compiling tools available in your path and named @@ -1241,6 +1241,24 @@ Hit 'q': [q, b, e, ?] ## Application terminated, rc = 0x0 +NetBSD Notes: +============= + +Starting at version 0.9.2, PPCBoot supports NetBSD both as host +(build PPCBoot) and target system (boots NetBSD/mpc8xx). + +Building requires a cross environment; it is known to work on +NetBSD/i386 with the cross-powerpc-netbsd-1.3 package (you will also +need gmake since the Makefiles are not compatible with BSD make). +Native builds *don't* work due to incompatibilities between native +and PPCBoot include files. + +Booting assumes that (the first part of) the image booted is a +stage-2 loader which in turn loads and then invokes the kernel +proper. Loader sources will eventually appear in the NetBSD source +tree (probably in sys/arc/mpc8xx/stand/ppcboot_stage2/); in the +meantime, send mail to bruno@exet-ag.de and/or wd@denx.de for +details. Implementation Internals: diff --git a/board/pcu_e/flash.c b/board/pcu_e/flash.c index 3ad5ef6..418e459 100644 --- a/board/pcu_e/flash.c +++ b/board/pcu_e/flash.c @@ -168,6 +168,7 @@ unsigned long flash_init (void) //XXX memctl->memc_or1 = CFG_OR_TIMING_FLASH | (-size_b1 & 0xFFFF8000); //XXX memctl->memc_br1 = ((base - size_b1) & BR_BA_MSK) | +//XXX BR_PS_16 | BR_MS_GPCM | BR_V; memctl->memc_or6 = CFG_OR_TIMING_FLASH | (-size_b1 & 0xFFFF8000); memctl->memc_br6 = ((base - size_b1) & BR_BA_MSK) | BR_PS_16 | BR_MS_GPCM | BR_V; @@ -598,7 +599,7 @@ static int write_data (flash_info_t *info, ulong dest, ulong data) int flag; /* Check if Flash is (sufficiently) erased */ - if ((*addr & sdata) != sdata) { + if ((*((vu_short *)dest) & sdata) != sdata) { return (2); } /* Disable interrupts which might cause a timeout here */ diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c index 5548596..d2afcaa 100644 --- a/common/cmd_bootm.c +++ b/common/cmd_bootm.c @@ -1,5 +1,5 @@ /* - * (C) Copyright 2000 + * (C) Copyright 2000, 2001 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. * * See file CREDITS for list of people who contributed to this @@ -44,6 +44,23 @@ static void image_info (unsigned long addr); #endif static void print_type (image_header_t *hdr); +/* + * Continue booting an OS image; caller already has: + * - copied image header to global variable `header' + * - checked header magic number, checksums (both header & image), + * - verified image architecture (PPC) and type (KERNEL or MULTI), + * - loaded (first part of) image to header load address, + * - disabled interrupts. + */ +typedef void boot_os_Fcn (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[], + ulong addr, /* of image to boot */ + ulong *len_ptr, /* multi-file image length table */ + ulong data, /* points to first image */ + int verify); /* getenv("verify")[0] != 'n' */ + +static boot_os_Fcn do_bootm_linux; +static boot_os_Fcn do_bootm_netbsd; + image_header_t header; ulong load_addr = CFG_LOAD_ADDR; /* Default Load Address */ @@ -52,32 +69,16 @@ void do_bootm (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[]) { ulong iflag; ulong addr; - ulong sp; ulong data, len, checksum; - ulong initrd_start, initrd_end; - ulong cmd_start, cmd_end; ulong *len_ptr; - ulong initrd_high; int i, verify; - char *cmdline; char *name, *s; - bd_t *kbd; int (*appl)(cmd_tbl_t *, bd_t *, int, int, char *[]); - void (*kernel)(bd_t *, ulong, ulong, ulong, ulong); image_header_t *hdr = &header; s = getenv ("verify"); verify = (s && (*s == 'n')) ? 0 : 1; - if ((s = getenv ("initrd_high")) != NULL) { - /* a value of "no" or a similar string will act like 0, - * turning the "load high" feature off. This is intentional. - */ - initrd_high = simple_strtoul(s, NULL, 16); - } else { /* not set, no restrictions to load high */ - initrd_high = ~0; - } - if (argc < 2) { addr = load_addr; } else { @@ -87,7 +88,7 @@ void do_bootm (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[]) #ifdef CONFIG_HERMES hermes_set_led (1); #endif - printf ("## Booting Linux kernel at %08lx ...\n", addr); + printf ("## Booting image at %08lx ...\n", addr); /* Copy header so we can blank CRC field for re-calculation */ memcpy (&header, (char *)addr, sizeof(image_header_t)); @@ -216,6 +217,52 @@ void do_bootm (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[]) hermes_set_led (8); #endif + switch (hdr->ih_os) + { + default: /* handled by (original) Linux case */ + case IH_OS_LINUX: + do_bootm_linux (cmdtp, bd, flag, argc, argv, + addr, len_ptr, data, verify); + break; + case IH_OS_NETBSD: + do_bootm_netbsd (cmdtp, bd, flag, argc, argv, + addr, len_ptr, data, verify); + break; + } + +#ifdef DEBUG + printf ("\n## Control returned to monitor - resetting...\n"); + do_reset (cmdtp, bd, flag, argc, argv); +#endif +} + +static void +do_bootm_linux (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[], + ulong addr, + ulong *len_ptr, + ulong data, + int verify) +{ + ulong sp; + ulong len, checksum; + ulong initrd_start, initrd_end; + ulong cmd_start, cmd_end; + ulong initrd_high; + char *cmdline; + char *s; + bd_t *kbd; + void (*kernel)(bd_t *, ulong, ulong, ulong, ulong); + image_header_t *hdr = &header; + + if ((s = getenv ("initrd_high")) != NULL) { + /* a value of "no" or a similar string will act like 0, + * turning the "load high" feature off. This is intentional. + */ + initrd_high = simple_strtoul(s, NULL, 16); + } else { /* not set, no restrictions to load high */ + initrd_high = ~0; + } + /* * Booting a (Linux) kernel image * @@ -409,13 +456,88 @@ void do_bootm (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[]) * r7: End of command line string */ (*kernel) (kbd, initrd_start, initrd_end, cmd_start, cmd_end); +} -#ifdef DEBUG - printf ("\n## Control returned to monitor - resetting...\n"); - do_reset (cmdtp, bd, flag, argc, argv); +static void +do_bootm_netbsd (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[], + ulong addr, + ulong *len_ptr, + ulong data, + int verify) +{ + image_header_t *hdr = &header; + + void (*loader)(bd_t *, image_header_t *, char *, char *); + image_header_t *img_addr; + char *consdev; + char *cmdline; + + + /* + * Booting a (NetBSD) kernel image + * + * This process is pretty similar to a standalone application: + * The (first part of an multi-) image must be a stage-2 loader, + * which in turn is responsible for loading & invoking the actual + * kernel. The only differences are the parameters being passed: + * besides the board info strucure, the loader expects a command + * line, the name of the console device, and (optionally) the + * address of the original image header. + */ + + img_addr = 0; + if ((hdr->ih_type==IH_TYPE_MULTI) && (len_ptr[1])) + img_addr = (image_header_t *) addr; + + + consdev = ""; +#if defined (CONFIG_8xx_CONS_SMC1) + consdev = "smc1"; +#elif defined (CONFIG_8xx_CONS_SMC2) + consdev = "smc2"; +#elif defined (CONFIG_8xx_CONS_SCC2) + consdev = "scc2"; +#elif defined (CONFIG_8xx_CONS_SCC3) + consdev = "scc3"; #endif -} + if (argc > 2) { + ulong len; + int i; + + for (i=2, len=0 ; i 2) + cmdline[len++] = ' '; + strcpy (&cmdline[len], argv[i]); + len += strlen (argv[i]); + } + } else if ((cmdline = getenv("bootargs")) == NULL) { + cmdline = ""; + } + + loader = (void (*)(bd_t *, image_header_t *, char *, char *)) hdr->ih_ep; + + printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n", + (ulong)loader); + +#ifdef CONFIG_HERMES + hermes_set_led (15); +#endif + + /* + * NetBSD Stage-2 Loader Parameters: + * r3: ptr to board info data + * r4: image address + * r5: console device + * r6: boot args string + */ + (*loader) (bd, img_addr, consdev, cmdline); +} #if (CONFIG_COMMANDS & CFG_CMD_BOOTD) void do_bootd (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[]) @@ -494,7 +616,7 @@ print_image_hdr (image_header_t *hdr) printf (" Image Name: %.*s\n", IH_NMLEN, hdr->ih_name); #if (CONFIG_COMMANDS & CFG_CMD_DATE) to_tm (timestamp, &tm); - printf (" Created: %4d-%02d-%02d %2d:%02d:%02d\n", + printf (" Created: %4d-%02d-%02d %2d:%02d:%02d UTC\n", tm.tm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); #endif /* CFG_CMD_DATE */ @@ -524,6 +646,7 @@ print_type (image_header_t *hdr) switch (hdr->ih_os) { case IH_OS_INVALID: os = "Invalid OS"; break; + case IH_OS_NETBSD: os = "NetBSD"; break; case IH_OS_LINUX: os = "Linux"; break; default: os = "Unknown OS"; break; } diff --git a/config.mk b/config.mk index 5eda497..eba0a37 100644 --- a/config.mk +++ b/config.mk @@ -26,6 +26,17 @@ PLATFORM_RELFLAGS= PLATFORM_CPPFLAGS= +# When cross-compiling on NetBSD, we have to define __PPC__ or else we +# will pick up a va_list declaration that is incompatible with the +# actual argument lists emitted by the compiler. +# +# [Tested on NetBSD/i386 1.5 + cross-powerpc-netbsd-1.3] + +ifeq ($(CROSS_COMPILE),powerpc-netbsd-) +PLATFORM_CPPFLAGS+= -D__PPC__ +endif + + ifdef ARCH sinclude $(TOPDIR)/$(ARCH)/config.mk # include architecture dependend rules endif @@ -78,13 +89,20 @@ AFLAGS := -D__ASSEMBLY__ $(CPPFLAGS) LDFLAGS += -Bstatic -T $(LDSCRIPT) -Ttext $(TEXT_BASE) -#OBJCFLAGS = --remove-section=.stab \ -# --remove-section=.comment \ -# --remove-section=.stabstr \ -# --change-section-lma=.data+$(TEXT_BASE) \ -# --change-section-lma=__ex_table+$(TEXT_BASE) \ -# --change-section-lma=.bss+$(TEXT_BASE) \ -# --set-section-flags=.bss=contents,alloc,load,data +# Location of a usable BFD library, where we define "usable" as +# "built for ${HOST}, supports ${TARGET}". Sensible values are +# - When cross-compiling: the root of the cross-environment +# - Linux/ppc (native): /usr +# - NetBSD/ppc (native): you lose ... (must extract these from the +# binutils build directory, plus the native and ppcboot include +# files don't like each other) +# +# So far, this is used only by tools/gdb/Makefile. + +#BFD_ROOT_DIR = /LinuxPPC/CDK # Linux/i386 +#BFD_ROOT_DIR = /usr/pkg/cross # NetBSD/i386 +#BFD_ROOT_DIR = /usr # native +BFD_ROOT_DIR = /opt/powerpc ######################################################################### diff --git a/include/config_pcu_e.h b/include/config_pcu_e.h index e0b0ef3..1f4b862 100644 --- a/include/config_pcu_e.h +++ b/include/config_pcu_e.h @@ -135,6 +135,11 @@ #define CFG_INIT_DATA_OFFSET (CFG_INIT_RAM_END - CFG_INIT_DATA_SIZE) #define CFG_INIT_SP_OFFSET CFG_INIT_DATA_OFFSET +/*----------------------------------------------------------------------- + * Address accessed to reset the board - must not be mapped/assigned + */ +#define CFG_RESET_ADDRESS 0xFEFFFFFF + /*----------------------------------------------------------------------- * Start addresses for the final memory configuration * (Set up by the startup code) diff --git a/tools/Makefile b/tools/Makefile index d4018c1..3fdda0d 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -27,7 +27,23 @@ BINS = img2srec mkimage envcrc gen_eth_addr OBJS = img2srec.o mkimage.o crc32.o envcrc.o gen_eth_addr.o -TOOLSUBDIRS = gdb +HOSTARCH := $(shell uname -m | \ + sed -e s/i.86/i386/ \ + -e s/sun4u/sparc64/ \ + -e s/arm.*/arm/ \ + -e s/sa110/arm/ \ + -e s/macppc/ppc/) + +HOSTOS := $(shell uname -s | tr A-Z a-z) + +TOOLSUBDIRS = + +# The gdb tools won't build natively on NetBSD since bfd.h (and ansidecl.h) +# are not installed -- just skip them, they are not really essential. +# +ifneq ($(HOSTOS)-$(HOSTARCH),netbsd-ppc) +TOOLSUBDIRS+= gdb +endif # # Use native tools and options diff --git a/tools/gdb/Makefile b/tools/gdb/Makefile index 670d3ca..4ef25fb 100644 --- a/tools/gdb/Makefile +++ b/tools/gdb/Makefile @@ -30,7 +30,7 @@ OBJS = gdbsend.o gdbcont.o astest.o error.o remote.o serial.o # # Use native tools and options # -CPPFLAGS = -Wall -pedantic -O -I/opt/powerpc/include +CPPFLAGS = -Wall -pedantic -O -I$(BFD_ROOT_DIR)/include CFLAGS = $(CPPFLAGS) CC = $(HOSTCC) MAKEDEPEND = makedepend @@ -48,7 +48,7 @@ gdbcont: gdbcont.o error.o remote.o serial.o $(CC) $(CFLAGS) -o $@ $^ astest: astest.o error.o - $(CC) $(CFLAGS) -o $@ $^ -L/opt/powerpc/lib -lbfd -liberty + $(CC) $(CFLAGS) -o $@ $^ -L$(BFD_ROOT_DIR)/lib -lbfd -liberty clean: rm -f $(OBJS)