#include <ppcboot.h>
#include <command.h>
#include <malloc.h>
+#include <devices.h>
#if (CONFIG_COMMANDS & CFG_CMD_IDE)
#include <ide.h>
#endif
#if (CONFIG_COMMANDS & CFG_CMD_KGDB)
#include <kgdb.h>
#endif
-#ifdef CONFIG_VIDEO
-#include <video.h>
-#endif
#include <version.h>
static char *failed = "*** failed ***\n";
/* set up serial port */
serial_init (clock_mhz, baudrate);
+ /* Initialize the console (before the relocation) */
+ console_init_f ();
+
+ /* now we can use standard printf/puts/getc/tstc functions */
display_options();
printf ("Initializing...\n CPU: "); /* Check CPU */
hang();
}
+#ifdef CONFIG_COGENT
+ /* miscellaneous platform dependent initialisations */
+ if (misc_init_f() < 0) {
+ printf (failed);
+ hang();
+ }
+#endif
+
/* Map bank 4: SRAM */
printf (" DRAM: ");
*
* First reserve memory for monitor code at end of DRAM.
*/
- len = get_endaddr() - CFG_FLASH_BASE;
+ len = get_endaddr() - CFG_MONITOR_BASE;
if (len > CFG_MONITOR_LEN) {
printf ("*** PPCBoot size %ld > reserved memory (%d)\n",
len, CFG_MONITOR_LEN);
addr_sp = (ulong)bd - 128;
addr_sp &= ~0xF;
+#if defined(CFG_FLASH_ENV_BUF)
+ /*
+ * Unfortunately, some boards (like the Cogent CMA302 flash I/O
+ * Module) have ridiculously large sectors (512KB) because they
+ * have 8 x 8 bit wide flash chips arranged so that each chip has
+ * one of the byte lanes in a 64 bit word. Not only that, the
+ * Intel 28F008S5 flash chips have 64K sectors (16 of them, for
+ * 1Mbyte each). So effectively, the CMA302 has 16 x 512KB
+ * sectors. We need some space to store the data when programming
+ * one of these flash sectors, so the only way I can think of at
+ * the moment is to allocate it here, between the board data and
+ * the top of the stack.
+ */
+ addr_sp -= CFG_FLASH_ENV_BUF;
+#endif /* CFG_FLASH_ENV_BUF */
+
/*
* Save local variables to board info struct
*/
-#ifdef EXTBDINFO
- strcpy(bd->bi_s_version, "1.1");
- strcpy(bd->bi_r_version, PPCBOOT_VERSION);
-#endif
bd->bi_memstart = CFG_SDRAM_BASE; /* start of DRAM memory */
bd->bi_memsize = dram_size; /* size of DRAM memory in bytes */
bd->bi_flashstart = CFG_FLASH_BASE; /* start of FLASH memory */
bd->bi_flashsize = 0; /* size of FLASH memory (PRELIM) */
+#if CFG_MONITOR_BASE == CFG_FLASH_BASE
bd->bi_flashoffset = CFG_MONITOR_LEN; /* reserved area for startup monitor */
+#else
+ bd->bi_flashoffset = 0;
+#endif
bd->bi_sramstart = 0; /* FIXME */ /* start of SRAM memory */
bd->bi_sramsize = 0; /* FIXME */ /* size of SRAM memory */
#ifdef CONFIG_8xx
bd->bi_intfreq = clock_mhz; /* Internal Freq, in MHz */
bd->bi_busfreq = get_bus_freq(clock_mhz); /* Bus Freq, in MHz */
bd->bi_baudrate = baudrate; /* Console Baudrate */
-#ifdef EXTBDINFO
- bd->bi_procfreq = bd->bi_intfreq * 1000000; /* Processor Speed, In Hz */
- bd->bi_plb_busfreq = bd->bi_busfreq;
- bd->bi_pci_busfreq = bd->bi_busfreq;
+
+#ifdef CFG_EXTBDINFO
+ strncpy(bd->bi_s_version, "1.2", sizeof(bd->bi_s_version));
+ strncpy(bd->bi_r_version, PPCBOOT_VERSION, sizeof(bd->bi_r_version));
+
+ bd->bi_procfreq = bd->bi_intfreq * 1000000; /* Processor Speed, In Hz */
+ bd->bi_plb_busfreq = bd->bi_busfreq;
+ bd->bi_pci_busfreq = bd->bi_busfreq;
#endif
/* Function pointers must be added after code relocation */
{
cmd_tbl_t *cmdtp;
ulong flash_size;
- ulong reloc_off = dest_addr - CFG_FLASH_BASE;
+ ulong reloc_off = dest_addr - CFG_MONITOR_BASE;
+ /* Pointer to initial global data area */
+ init_data_t *idata = (init_data_t *)(CFG_INIT_RAM_ADDR + CFG_INIT_DATA_OFFSET);
extern void malloc_bin_reloc (ulong);
+
+ /* Save a global pointer to the board info struct */
+ bd_ptr = bd ;
+ /* Set the monitor function pointer to DPAM init data */
+ bd->bi_mon_fnc = &idata->bi_mon_fnc;
+
/*
* We have to relocate the command table manually
*/
}
bd->bi_flashsize = flash_size; /* size of FLASH memory (final value) */
+#if defined(CFG_FLASH_ENV_ADDR)
+ /*
+ * Protect the sector that the environment is in.
+ *
+ * This scheme (i.e. bi_flashoffset in the board info) cannot
+ * really reflect an arbitrarily placed environment flash sector,
+ * but lets just do our best, and assume that if CFG_FLASH_ENV_ADDR
+ * is defined it will be in a sensible location e.g. either the
+ * first sector, or the sector just after the monitor, if it is
+ * in flash.
+ */
+ {
+ ulong addr, newoff;
+ flash_info_t *fip;
+ int i, j;
+
+ /* address of last byte in the environment */
+ addr = CFG_FLASH_ENV_ADDR + CFG_FLASH_ENV_SIZE - 1;
+
+ /* make sure it is within the flash */
+ if ((fip = addr2info(addr)) == NULL)
+ panic("environment address 0x%08lx is not within flash!\n", addr);
+
+ /* move it to the sector boundary */
+ for (i = 0, j = 1; j < fip->sector_count; i++, j++)
+ if (addr >= fip->start[i] && addr < fip->start[j])
+ break;
+ if (j == fip->sector_count)
+ addr = fip->start[0] + fip->size;
+ else
+ addr = fip->start[j];
+
+ /* adjust flashoffset if required */
+ newoff = addr - bd->bi_flashstart;
+ if (bd->bi_flashoffset < newoff)
+ bd->bi_flashoffset = newoff;
+ }
+#endif
+
/* initialize higher level parts of CPU like time base and timers */
cpu_init_r (bd);
+#ifdef CONFIG_COGENT
+ /* miscellaneous platform dependent initialisations */
+ misc_init_r(bd);
+#endif
+
#ifdef CONFIG_SPD823TS
reset_phy ();
#endif
/* Insert function pointers now that we have relocated the code */
- bd->bi_mon_fnc.getc = serial_getc;
- bd->bi_mon_fnc.tstc = serial_tstc;
- bd->bi_mon_fnc.putc = serial_putc;
- bd->bi_mon_fnc.putstr = serial_putstr;
- bd->bi_mon_fnc.printf = printf;
-
#if defined(CONFIG_8xx)
- bd->bi_mon_fnc.install_hdlr = cpm_install_handler;
- bd->bi_mon_fnc.free_hdlr = cpm_free_handler;
+ bd->bi_mon_fnc->install_hdlr = cpm_install_handler;
+ bd->bi_mon_fnc->free_hdlr = cpm_free_handler;
#elif defined(CONFIG_4xx)
- bd->bi_mon_fnc.install_hdlr = irq_install_handler;
- bd->bi_mon_fnc.free_hdlr = irq_free_handler;
+ bd->bi_mon_fnc->install_hdlr = irq_install_handler;
+ bd->bi_mon_fnc->free_hdlr = irq_free_handler;
#else
#error No interrupt handler for this architecture
#endif
/* Initialize other board modules */
-#ifdef CONFIG_VIDEO
- printf(" Video: ");
- video_init(CONFIG_VIDEO_ADDR);
-#endif
#ifdef CONFIG_PCMCIA
printf(" PCMCIA: ");
pcmcia_init();
#endif
- bd->bi_mon_fnc.malloc = malloc;
- bd->bi_mon_fnc.free = free;
+ bd->bi_mon_fnc->malloc = malloc;
+ bd->bi_mon_fnc->free = free;
/* initialize malloc() area */
mem_malloc_init (dest_addr);
malloc_bin_reloc (reloc_off);
+/** LEAVE THIS HERE **/
+ /* Initialize devices */
+ devices_init();
+
+ /* Initialize the console (after the relocation and devices init) */
+ console_init_r ();
+ putc('\n');
+/**********************/
+
/* Initialization complete - start the monitor */
main_loop (bd);
/* NOTREACHED - start_main does not return; just in case: loop here */
- for (;;)
- ;
+ for (;;);
}
void hang(void)
#define CONFIG_PCI_PNP 1 /* include pci plug-and-play */
-#define CONFIG_DRAM_SPEED (CONFIG_BUSCLOCK) /* MHz */
-
#define CONFIG_COMMANDS \
((CONFIG_CMD_DFL | CFG_CMD_PCI | CFG_CMD_IRQ) & ~(CFG_CMD_ENV))
+/* this must be included AFTER the definition of CONFIG_COMMANDS (if any) */
+#include <cmd_confdefs.h>
+
#define CONFIG_NVRAM_ENV 1 /* use NVRAM for environment vars */
#define CFG_NVRAM_BASE_ADDR 0xf0200000 /* NVRAM base address */
#define CFG_NVRAM_SIZE (32*1024) /* NVRAM size */
(CFG_NVRAM_BASE_ADDR+CFG_NVRAM_SIZE-CFG_NVRAM_ENV_SIZE-4) /* Env */
#define CFG_NVRAM_VAR_CRC_ADDR (CFG_NVRAM_VAR_ADDR+CFG_NVRAM_ENV_SIZE)
+#undef CONFIG_WATCHDOG /* watchdog disabled */
+
/*
* Miscellaneous configurable options
*/
#define CFG_LONGHELP /* undef to save memory */
#define CFG_PROMPT "=> " /* Monitor Command Prompt */
-#if (CONFIG_COMMANDS & CFG_CMD_KGDB) && defined(KGDB_DEBUG)
+#if (CONFIG_COMMANDS & CFG_CMD_KGDB)
#define CFG_CBSIZE 1024 /* Console I/O Buffer Size */
#else
#define CFG_CBSIZE 256 /* Console I/O Buffer Size */
#define CFG_MEMTEST_START 0x0400000 /* memtest works on */
#define CFG_MEMTEST_END 0x0C00000 /* 4 ... 12 MB in DRAM */
-#define CFG_BAUDRATE_MIN 300 /* lowest possible baudrate */
-#define CFG_BAUDRATE_MAX 115200 /* highest possible baudrate */
+#define CFG_BAUDRATE_MIN 300 /* lowest possible baudrate */
+#define CFG_BAUDRATE_MAX 115200 /* highest possible baudrate */
#define CFG_BAUDRATE_DEFAULT CONFIG_BAUDRATE /* default baudrate */
#define CFG_TFTP_LOADADDR 0x100000 /* default load address */
-#define EXTBDINFO 1 /* To use extended board_into (bd_t) */
+#define CFG_EXTBDINFO 1 /* To use extended board_into (bd_t) */
/*-----------------------------------------------------------------------
* Start addresses for the final memory configuration
#else
#define CFG_FLASH_BASE 0x00FE0000
#endif
+#define CFG_MONITOR_BASE CFG_FLASH_BASE
#define CFG_MONITOR_LEN (128 << 10) /* Reserve 128 kB for Monitor */
#define CFG_MALLOC_LEN (128 << 10) /* Reserve 128 kB for malloc() */
* Cache Configuration
*/
#define CFG_CACHELINE_SIZE 16 /* For all MPC8xx CPUs */
+#if (CONFIG_COMMANDS & CFG_CMD_KGDB)
+#define CFG_CACHELINE_SHIFT 4 /* log base 2 of the above value */
+#endif
/*
* Init Memory Controller:
#include <linux/types.h>
#include <linux/string.h>
#include <asm/ptrace.h>
+#include <stdarg.h>
#ifdef CONFIG_8xx
#include <asm/8xx_immap.h>
#endif
typedef volatile unsigned long vu_long;
#include <flash.h>
+#include <image.h>
#ifdef DEBUG
#define debug(fmt,args...) printf (fmt ,##args)
int (*getc)(void);
int (*tstc)(void);
void (*putc)(const char c);
- void (*putstr)(const char *s);
+ void (*puts)(const char *s);
void (*printf)(const char *fmt, ...);
void (*install_hdlr)(int, interrupt_handler_t *, void *);
void (*free_hdlr)(int);
* ppcboot starts it up.
*/
typedef struct bd_info {
-#ifdef EXTBDINFO
- unsigned char bi_s_version[4]; /* Version of this structure */
- unsigned char bi_r_version[30]; /* Version of the ROM (IBM) */
+#ifdef CFG_EXTBDINFO
+ unsigned char bi_s_version[4]; /* Version of this structure */
#endif
- unsigned long bi_memstart; /* start of DRAM memory */
- unsigned long bi_memsize; /* size of DRAM memory in bytes */
- unsigned long bi_flashstart; /* start of FLASH memory */
- unsigned long bi_flashsize; /* size of FLASH memory */
- unsigned long bi_flashoffset; /* reserved area for startup monitor */
- unsigned long bi_sramstart; /* start of SRAM memory */
- unsigned long bi_sramsize; /* size of SRAM memory */
+ unsigned long bi_memstart; /* start of DRAM memory */
+ unsigned long bi_memsize; /* size of DRAM memory in bytes */
+ unsigned long bi_flashstart; /* start of FLASH memory */
+ unsigned long bi_flashsize; /* size of FLASH memory */
+ unsigned long bi_flashoffset; /* reserved area for startup monitor */
+ unsigned long bi_sramstart; /* start of SRAM memory */
+ unsigned long bi_sramsize; /* size of SRAM memory */
#ifdef CONFIG_8xx
- unsigned long bi_immr_base; /* base of IMMR register */
+ unsigned long bi_immr_base; /* base of IMMR register */
#endif
- unsigned long bi_bootflags; /* boot / reboot flag (for LynxOS) */
- unsigned long bi_ip_addr; /* IP Address */
- unsigned char bi_enetaddr[6]; /* Ethernet adress */
- unsigned char bi_reserved[2]; /* -- just for alignment -- */
- unsigned long bi_intfreq; /* Internal Freq, in MHz */
-#ifdef EXTBDINFO
- unsigned int bi_procfreq; /* CPU (Internal) Freq, in Hz */
+ unsigned long bi_bootflags; /* boot / reboot flag (for LynxOS) */
+ unsigned long bi_ip_addr; /* IP Address */
+ unsigned char bi_enetaddr[6]; /* Ethernet adress */
+ unsigned char bi_reserved[2]; /* -- just for alignment -- */
+ unsigned long bi_intfreq; /* Internal Freq, in MHz */
+ unsigned long bi_busfreq; /* Bus Freq, in MHz */
+ unsigned long bi_baudrate; /* Console Baudrate */
+#ifdef CFG_EXTBDINFO
+ unsigned char bi_r_version[32]; /* Version of the ROM (IBM) */
+ unsigned int bi_procfreq; /* CPU (Internal) Freq, in Hz */
+ unsigned int bi_plb_busfreq; /* PLB Bus speed, in Hz */
+ unsigned int bi_pci_busfreq; /* PCI Bus speed, in Hz */
#endif
- unsigned long bi_busfreq; /* Bus Freq, in MHz */
-#ifdef EXTBDINFO
- unsigned int bi_plb_busfreq; /* PLB Bus speed, in Hz */
- unsigned int bi_pci_busfreq; /* PCI Bus speed, in Hz */
-#endif
- unsigned long bi_baudrate; /* Console Baudrate */
- mon_fnc_t bi_mon_fnc; /* Addresses of monitor functions */
+ mon_fnc_t *bi_mon_fnc; /* Pointer to monitor functions */
} bd_t;
/* The following data structure is placed in DPRAM to allow for a
* (until we have set up the memory controller so that we can use
* RAM).
*
- * Keep it *SMALL*!
+ * Keep it *SMALL* and remember to set CFG_INIT_DATA_SIZE > sizeof(init_data_t)
*/
typedef struct init_data {
unsigned long cpu_speed; /* VCOOUT = CPU clock in Hz! */
+ unsigned long relocated; /* Set when relocated to RAM */
+ mon_fnc_t bi_mon_fnc; /* Monitor functions */
} init_data_t;
/*
int checkboard (void);
int checkflash (void);
int checkdram (void);
+#if defined(CONFIG_COGENT)
+int misc_init_f (void);
+void misc_init_r (bd_t *);
+#endif /* CONFIG_COGENT */
+
+/* common/cmd_bootm.c */
+void print_image_hdr (image_header_t *hdr);
/* common/cmd_nvedit.c */
-char *getenv (uchar *);
+char *getenv (uchar *);
+void inline setenv (char *, char *);
/* board/flash.c */
ulong flash_get_size (vu_long *addr, flash_info_t *info);
void serial_init (ulong, int);
void serial_setbrg (ulong, int);
void serial_putc (const char);
-void serial_putstr (const char *);
+void serial_puts (const char *);
void serial_addr (unsigned int);
int serial_getc (void);
int serial_tstc (void);
int checkdcache (void);
void upmconfig (unsigned int, unsigned int *, unsigned int);
void udelay (unsigned long);
+#if defined(CONFIG_WATCHDOG)
+void watchdog_reset(void);
+#endif /* CONFIG_WATCHDOG */
/* $(CPU)/speed.c */
ulong get_gclk_freq (void);
/* ppc/vsprintf.c */
ulong simple_strtoul(const char *cp,char **endp,unsigned int base);
long simple_strtol(const char *cp,char **endp,unsigned int base);
-void printf(const char *fmt, ...);
void panic(const char *fmt, ...);
int sprintf(char * buf, const char *fmt, ...);
+int vsprintf(char *buf, const char *fmt, va_list args);
/* ppc/crc32.c */
ulong crc32 (ulong, const unsigned char *, uint);
+/* disk/part_mac.c */
+void print_part_mac (int);
+
+/* common/console.c */
+bd_t *bd_ptr ;
+
+void console_init_f(void); /* Before relocation; uses the serial stuff */
+void console_init_r(void); /* After relocation; uses the console stuff */
+int console_assign (int file, char *devname); /* Assign the console */
+
+/*
+ * STDIO based functions (can always be used)
+ */
+
+/* serial stuff */
+void serial_printf (const char *fmt, ...);
+
+/* stdin */
+int getc(void);
+int tstc(void);
+
+/* stdout */
+void putc(const char c);
+void puts(const char *s);
+void printf(const char *fmt, ...);
+
+/* stderr */
+#define eputc(c) fputc(stderr, c)
+#define eputs(s) fputs(stderr, s)
+#define eprintf(fmt,args...) fprintf(stderr,fmt ,##args)
+
+/*
+ * FILE based functions (can only be used AFTER relocation!)
+ */
+
+#define stdin 0
+#define stdout 1
+#define stderr 2
+#define MAX_FILES 3
+
+void fprintf(int file, const char *fmt, ...);
+void fputs(int file, const char *s);
+void fputc(int file, const char c);
+int ftstc(int file);
+int fgetc(int file);
+
+#ifdef CONFIG_PCMCIA
+int pcmcia_init (void);
+#endif
+
#endif /* _PPCBOOT_H_ */