]> www.infradead.org Git - users/rw/ppcboot.git/commitdiff
PPCBoot now supports NetBSD both as host (build PPCBoot) and target
authorwdenk <wdenk>
Tue, 1 May 2001 16:11:50 +0000 (16:11 +0000)
committerwdenk <wdenk>
Tue, 1 May 2001 16:11:50 +0000 (16:11 +0000)
system (boots NetBSD/mpc8xx).

Fix bug in flash write code for PCU E.

CHANGELOG
CREDITS
Makefile
README
board/pcu_e/flash.c
common/cmd_bootm.c
config.mk
include/config_pcu_e.h
tools/Makefile
tools/gdb/Makefile

index 407059a81d8e1ddff4e5c7a39fd302b123918ab3..25c8a0d71017d3be94a67e76e7cc97d460a9b997 100644 (file)
--- 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 324767a8c1b1786a06c16be0130e955a0524741e..dd3c8e05b96bec402908406d585241eaab8572b7 100644 (file)
--- a/CREDITS
+++ b/CREDITS
 #                       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: <andre.beaudin@colubris.com>
 D: PCMCIA, Ethernet, TFTP
index 7112ebac12a89cb29ebe9d7e1675b38352077f9a..146c6bce4d0112e5e20d7acfd3a5ea45a0f82452 100644 (file)
--- a/Makefile
+++ b/Makefile
 #
 
 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 8fedddf4e1bd6b4affd70fbde37b791bdacb94c3..99b565d6ba2670e83ce48e4fe51bdd662cf510bb 100644 (file)
--- 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:
index 3ad5ef6725a5dd534f4e723405847c7906e1ac65..418e4599dbf773a105a26c3e273598c0c3ad5e74 100644 (file)
@@ -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 */
index 5548596c95c9b69be48978669c5b62450ebefe09..d2afcaa9254caf937268799bb9c87db91b26216b 100644 (file)
@@ -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<argc ; i+=1)
+                       len += strlen (argv[i]) + 1;
+               cmdline = malloc (len);
+
+               for (i=2, len=0 ; i<argc ; i+=1)
+               {
+                       if (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;
        }
index 5eda497835f2d000f623cbfd24b15d26c340fe89..eba0a37afcb0015515c2d63f19f266f571097700 100644 (file)
--- a/config.mk
+++ b/config.mk
 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
 
 #########################################################################
 
index e0b0ef3c9b0163b6791920372d4e0148ecb43831..1f4b8629ae51a0131ff1e87c164a547cfe3aa57f 100644 (file)
 #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)
index d4018c1539815a272c61d3bf5f4ce7b58b878edf..3fdda0dce56e578b8386d2b6a548bb0d4e2000ca 100644 (file)
@@ -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
index 670d3cadd2b53c2027ed8e32f2d8720aa65a5779..4ef25fbf9cecab7b97fb40e7ee2ffbd670711583 100644 (file)
@@ -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)