2 * (C) Copyright 2000-2002
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
36 #if (CONFIG_COMMANDS & CFG_CMD_IDE)
39 #if (CONFIG_COMMANDS & CFG_CMD_SCSI)
42 #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
45 #ifdef CONFIG_STATUS_LED
46 #include <status_led.h>
49 #if (CONFIG_COMMANDS & CFG_CMD_BEDBUG)
50 #include <cmd_bedbug.h>
52 #ifdef CFG_ALLOC_DPRAM
53 #if !defined(CONFIG_8260)
58 #if defined(CONFIG_BAB7xx)
62 #if defined(CONFIG_POST)
65 #if defined(CONFIG_LOGBUFFER)
69 #if (CONFIG_COMMANDS & CFG_CMD_DOC)
72 #if defined(CONFIG_HARD_I2C) || \
73 defined(CONFIG_SOFT_I2C)
76 #if (CONFIG_COMMANDS & CFG_CMD_NAND)
77 void nand_init (void);
80 static char *failed = "*** failed ***\n";
82 #if defined(CONFIG_PCU_E) || defined(CONFIG_OXC)
83 extern flash_info_t flash_info[];
86 #include <environment.h>
88 #if ( ((CFG_ENV_ADDR+CFG_ENV_SIZE) < CFG_MONITOR_BASE) || \
89 (CFG_ENV_ADDR >= (CFG_MONITOR_BASE + CFG_MONITOR_LEN)) ) || \
90 defined(CFG_ENV_IS_IN_NVRAM)
91 #define TOTAL_MALLOC_LEN (CFG_MALLOC_LEN + CFG_ENV_SIZE)
93 #define TOTAL_MALLOC_LEN CFG_MALLOC_LEN
96 extern ulong __init_end;
99 ulong monitor_flash_len;
102 * Begin and End of memory area for malloc(), and current "brk"
104 static ulong mem_malloc_start = 0;
105 static ulong mem_malloc_end = 0;
106 static ulong mem_malloc_brk = 0;
108 /************************************************************************
110 ************************************************************************
114 * The Malloc area is immediately below the monitor copy in DRAM
116 static void mem_malloc_init (void)
118 DECLARE_GLOBAL_DATA_PTR;
120 ulong dest_addr = CFG_MONITOR_BASE + gd->reloc_off;
122 mem_malloc_end = dest_addr;
123 mem_malloc_start = dest_addr - TOTAL_MALLOC_LEN;
124 mem_malloc_brk = mem_malloc_start;
126 memset ((void *) mem_malloc_start,
128 mem_malloc_end - mem_malloc_start);
131 void *sbrk (ptrdiff_t increment)
133 ulong old = mem_malloc_brk;
134 ulong new = old + increment;
136 if ((new < mem_malloc_start) || (new > mem_malloc_end)) {
139 mem_malloc_brk = new;
140 return ((void *) old);
143 char *strmhz (char *buf, long hz)
149 l = sprintf (buf, "%ld", n);
150 m = (hz % 1000000L) / 1000L;
152 sprintf (buf + l, ".%03ld", m);
156 static void syscalls_init (void)
160 syscall_tbl[SYSCALL_MALLOC] = (void *) malloc;
161 syscall_tbl[SYSCALL_FREE] = (void *) free;
163 syscall_tbl[SYSCALL_INSTALL_HDLR] = (void *) irq_install_handler;
164 syscall_tbl[SYSCALL_FREE_HDLR] = (void *) irq_free_handler;
165 syscall_tbl[SYSCALL_GET_TIMER] = (void *)get_timer;
166 syscall_tbl[SYSCALL_UDELAY] = (void *)udelay;
168 addr = (ulong *) 0xc00; /* syscall ISR addr */
171 *addr++ |= (ulong) syscall_tbl >> 16;
172 *addr++ |= (ulong) syscall_tbl & 0xFFFF;
173 *addr++ |= NR_SYSCALLS >> 16;
174 *addr++ |= NR_SYSCALLS & 0xFFFF;
177 flush_cache (0x0C00, 0x10);
179 /* Initialize syscalls stack pointer */
180 addr = (ulong *) 0xCFC;
183 flush_cache ((ulong)addr, 0x10);
188 * All attempts to come up with a "common" initialization sequence
189 * that works for all boards and architectures failed: some of the
190 * requirements are just _too_ different. To get rid of the resulting
191 * mess of board dependend #ifdef'ed code we now make the whole
192 * initialization sequence configurable to the user.
194 * The requirements for any new initalization function is simple: it
195 * receives a pointer to the "global data" structure as it's only
196 * argument, and returns an integer return code, where 0 means
197 * "continue" and != 0 means "fatal error, hang the system".
199 typedef int (init_fnc_t) (void);
201 /************************************************************************
203 ************************************************************************
204 * Some of this code should be moved into the core functions,
205 * but let's get it working (again) first...
208 static int init_baudrate (void)
210 DECLARE_GLOBAL_DATA_PTR;
212 uchar tmp[64]; /* long enough for environment variables */
213 int i = getenv_r ("baudrate", tmp, sizeof (tmp));
215 gd->baudrate = (i > 0)
216 ? (int) simple_strtoul (tmp, NULL, 10)
221 /***********************************************************************/
223 static int init_func_ram (void)
225 DECLARE_GLOBAL_DATA_PTR;
227 #ifdef CONFIG_BOARD_TYPES
228 int board_type = gd->board_type;
230 int board_type = 0; /* use dummy arg */
234 if ((gd->ram_size = initdram (board_type)) > 0) {
235 print_size (gd->ram_size, "\n");
242 /***********************************************************************/
244 #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
245 static int init_func_i2c (void)
248 i2c_init (CFG_I2C_SPEED, CFG_I2C_SLAVE);
254 /***********************************************************************/
256 #if defined(CONFIG_WATCHDOG)
257 static int init_func_watchdog_init (void)
259 puts (" Watchdog enabled\n");
263 # define INIT_FUNC_WATCHDOG_INIT init_func_watchdog_init,
265 static int init_func_watchdog_reset (void)
270 # define INIT_FUNC_WATCHDOG_RESET init_func_watchdog_reset,
272 # define INIT_FUNC_WATCHDOG_INIT /* undef */
273 # define INIT_FUNC_WATCHDOG_RESET /* undef */
274 #endif /* CONFIG_WATCHDOG */
276 /************************************************************************
277 * Initialization sequence *
278 ************************************************************************
281 init_fnc_t *init_sequence[] = {
283 #if defined(CONFIG_BOARD_PRE_INIT)
284 board_pre_init, /* very early board init code (fpga boot, etc.) */
287 get_clocks, /* get CPU and bus clocks (etc.) */
289 #ifdef CFG_ALLOC_DPRAM
290 #if !defined(CONFIG_8260)
294 #if defined(CONFIG_BOARD_POSTCLK_INIT)
302 #if defined(CONFIG_8260)
305 #endif /* CONFIG_8260 */
308 INIT_FUNC_WATCHDOG_INIT
309 #if defined(CONFIG_BMW) || \
310 defined(CONFIG_COGENT) || \
311 defined(CONFIG_HYMOD) || \
312 defined(CONFIG_RSD_PROTO) || \
316 INIT_FUNC_WATCHDOG_RESET
317 #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
320 #if defined(CONFIG_DTT) /* Digital Thermometers and Thermostats */
326 INIT_FUNC_WATCHDOG_RESET
328 #if defined(CFG_DRAM_TEST)
330 #endif /* CFG_DRAM_TEST */
331 INIT_FUNC_WATCHDOG_RESET
333 NULL, /* Terminate this list */
336 /************************************************************************
338 * This is the first part of the initialization sequence that is
339 * implemented in C, but still running from ROM.
341 * The main purpose is to provide a (serial) console interface as
342 * soon as possible (so we can see any error messages), and to
343 * initialize the RAM so that we can relocate the monitor code to
346 * Be aware of the restrictions: global data is read-only, BSS is not
347 * initialized, and stack space is limited to a few kB.
349 ************************************************************************
352 void board_init_f (ulong bootflag)
354 DECLARE_GLOBAL_DATA_PTR;
357 ulong len, addr, addr_sp;
359 init_fnc_t **init_fnc_ptr;
363 uchar tmp[64]; /* long enough for environment variables */
366 /* Pointer is writable since we allocated a register for it */
367 gd = (gd_t *) (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET);
370 /* Clear initial global data */
371 memset ((void *) gd, 0, sizeof (gd_t));
374 for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
375 if ((*init_fnc_ptr) () != 0) {
381 * Now that we have DRAM mapped and working, we can
382 * relocate the code and continue running from DRAM.
384 * Reserve memory at end of RAM for (top down in that order):
385 * - kernel log buffer
389 * - board info struct
391 len = (ulong)&_end - CFG_MONITOR_BASE;
393 #ifndef CONFIG_VERY_BIG_RAM
394 addr = CFG_SDRAM_BASE + gd->ram_size;
396 /* only allow stack below 256M */
397 addr = CFG_SDRAM_BASE +
398 (gd->ram_size > 256 << 20) ? 256 << 20 : gd->ram_size;
401 #ifdef CONFIG_LOGBUFFER
402 /* reserve kernel log buffer */
403 addr -= (LOGBUFF_RESERVE);
405 printf ("Reserving %ldk for kernel logbuffer at %08lx\n", LOGBUFF_LEN, addr);
411 * reserve protected RAM
413 i = getenv_r ("pram", tmp, sizeof (tmp));
414 reg = (i > 0) ? simple_strtoul (tmp, NULL, 10) : CONFIG_PRAM;
415 addr -= (reg << 10); /* size is in kB */
417 printf ("Reserving %ldk for protected RAM at %08lx\n", reg, addr);
419 #endif /* CONFIG_PRAM */
421 /* round down to next 4 kB limit */
424 printf ("Top of RAM usable for U-Boot at: %08lx\n", addr);
428 /* reserve memory for LCD display (always full pages) */
429 addr = lcd_setmem (addr);
431 #endif /* CONFIG_LCD */
433 #if defined(CONFIG_VIDEO) && defined(CONFIG_8xx)
434 /* reserve memory for video display (always full pages) */
435 addr = video_setmem (addr);
437 #endif /* CONFIG_VIDEO */
440 * reserve memory for U-Boot code, data & bss
441 * round down to next 4 kB limit
447 printf ("Reserving %ldk for U-Boot at: %08lx\n", len >> 10, addr);
450 #ifdef CONFIG_AMIGAONEG3SE
451 gd->relocaddr = addr;
455 * reserve memory for malloc() arena
457 addr_sp = addr - TOTAL_MALLOC_LEN;
459 printf ("Reserving %dk for malloc() at: %08lx\n",
460 TOTAL_MALLOC_LEN >> 10, addr_sp);
464 * (permanently) allocate a Board Info struct
465 * and a permanent copy of the "global" data
467 addr_sp -= sizeof (bd_t);
468 bd = (bd_t *) addr_sp;
471 printf ("Reserving %d Bytes for Board Info at: %08lx\n",
472 sizeof (bd_t), addr_sp);
474 addr_sp -= sizeof (gd_t);
475 id = (gd_t *) addr_sp;
477 printf ("Reserving %d Bytes for Global Data at: %08lx\n",
478 sizeof (gd_t), addr_sp);
482 * Finally, we set up a new (bigger) stack.
484 * Leave some safety gap for SP, force alignment on 16 byte boundary
485 * Clear initial stack frame
489 *((ulong *) addr_sp)-- = 0;
490 *((ulong *) addr_sp)-- = 0;
492 printf ("Stack Pointer at: %08lx\n", addr_sp);
496 * Save local variables to board info struct
499 bd->bi_memstart = CFG_SDRAM_BASE; /* start of DRAM memory */
500 bd->bi_memsize = gd->ram_size; /* size of DRAM memory in bytes */
503 bd->bi_sramstart = SRAM_BASE; /* start of SRAM memory */
504 bd->bi_sramsize = SRAM_SIZE; /* size of SRAM memory */
506 bd->bi_sramstart = 0; /* FIXME */ /* start of SRAM memory */
507 bd->bi_sramsize = 0; /* FIXME */ /* size of SRAM memory */
510 #if defined(CONFIG_8xx) || defined(CONFIG_8260) || defined(CONFIG_5xx)
511 bd->bi_immr_base = CFG_IMMR; /* base of IMMR register */
514 bd->bi_bootflags = bootflag; /* boot / reboot flag (for LynxOS) */
517 bd->bi_intfreq = gd->cpu_clk; /* Internal Freq, in Hz */
518 bd->bi_busfreq = gd->bus_clk; /* Bus Freq, in Hz */
519 #if defined(CONFIG_8260)
520 bd->bi_cpmfreq = gd->cpm_clk;
521 bd->bi_brgfreq = gd->brg_clk;
522 bd->bi_sccfreq = gd->scc_clk;
523 bd->bi_vco = gd->vco_out;
524 #endif /* CONFIG_8260 */
526 bd->bi_baudrate = gd->baudrate; /* Console Baudrate */
529 strncpy (bd->bi_s_version, "1.2", sizeof (bd->bi_s_version));
530 strncpy (bd->bi_r_version, U_BOOT_VERSION, sizeof (bd->bi_r_version));
532 bd->bi_procfreq = gd->cpu_clk; /* Processor Speed, In Hz */
533 bd->bi_plb_busfreq = gd->bus_clk;
534 #if defined(CONFIG_405GP) || defined(CONFIG_405EP)
535 bd->bi_pci_busfreq = get_PCI_freq ();
540 printf ("New Stack Pointer is: %08lx\n", addr_sp);
546 post_bootmode_init();
547 post_run (NULL, POST_ROM | post_bootmode_get(0));
552 memcpy (id, gd, sizeof (gd_t));
554 relocate_code (addr_sp, id, addr);
556 /* NOTREACHED - relocate_code() does not return */
560 /************************************************************************
562 * This is the next part if the initialization sequence: we are now
563 * running from RAM and have a "normal" C environment, i. e. global
564 * data can be written, BSS has been cleared, the stack size in not
565 * that critical any more, etc.
567 ************************************************************************
570 void board_init_r (gd_t *id, ulong dest_addr)
572 DECLARE_GLOBAL_DATA_PTR;
578 extern void malloc_bin_reloc (void);
579 #ifndef CFG_ENV_IS_NOWHERE
580 extern char * env_name_spec;
587 gd = id; /* initialize RAM version of global data */
590 gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
593 printf ("Now running in RAM - U-Boot at: %08lx\n", dest_addr);
598 gd->reloc_off = dest_addr - CFG_MONITOR_BASE;
600 monitor_flash_len = (ulong)&__init_end - dest_addr;
603 * We have to relocate the command table manually
605 for (cmdtp = &cmd_tbl[0]; cmdtp->name; cmdtp++) {
608 addr = (ulong) (cmdtp->cmd) + gd->reloc_off;
610 printf ("Command \"%s\": 0x%08lx => 0x%08lx\n",
611 cmdtp->name, (ulong) (cmdtp->cmd), addr);
614 (int (*)(struct cmd_tbl_s *, int, int, char *[]))addr;
616 addr = (ulong)(cmdtp->name) + gd->reloc_off;
617 cmdtp->name = (char *)addr;
620 addr = (ulong)(cmdtp->usage) + gd->reloc_off;
621 cmdtp->usage = (char *)addr;
625 addr = (ulong)(cmdtp->help) + gd->reloc_off;
626 cmdtp->help = (char *)addr;
630 /* there are some other pointer constants we must deal with */
631 #ifndef CFG_ENV_IS_NOWHERE
632 env_name_spec += gd->reloc_off;
637 #ifdef CONFIG_LOGBUFFER
638 logbuff_init_ptrs ();
641 post_output_backlog ();
647 #if defined(CONFIG_IP860) || defined(CONFIG_PCU_E) || defined (CONFIG_FLAGADM)
648 icache_enable (); /* it's time to enable the instruction cache */
651 #if defined(CONFIG_BAB7xx) || defined(CONFIG_CPC45)
653 * Do PCI configuration on BAB7xx and CPC45 _before_ the flash
654 * gets initialised, because we need the ISA resp. PCI_to_LOCAL bus
659 #if defined(CONFIG_BAB7xx)
661 * Initialise the ISA bridge
663 initialise_w83c553f ();
666 asm ("sync ; isync");
669 * Setup trap handlers
671 trap_init (dest_addr);
673 #if !defined(CFG_NO_FLASH)
676 if ((flash_size = flash_init ()) > 0) {
677 #ifdef CFG_FLASH_CHECKSUM
678 print_size (flash_size, "");
680 * Compute and print flash CRC if flashchecksum is set to 'y'
682 * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
684 s = getenv ("flashchecksum");
685 if (s && (*s == 'y')) {
686 printf (" CRC: %08lX",
688 (const unsigned char *) CFG_FLASH_BASE,
694 print_size (flash_size, "\n");
695 #endif /* CFG_FLASH_CHECKSUM */
701 bd->bi_flashstart = CFG_FLASH_BASE; /* update start of FLASH memory */
702 bd->bi_flashsize = flash_size; /* size of FLASH memory (final value) */
703 #if defined(CONFIG_PCU_E) || defined(CONFIG_OXC)
704 bd->bi_flashoffset = 0;
705 #elif CFG_MONITOR_BASE == CFG_FLASH_BASE
706 bd->bi_flashoffset = monitor_flash_len; /* reserved area for startup monitor */
708 bd->bi_flashoffset = 0;
712 bd->bi_flashsize = 0;
713 bd->bi_flashstart = 0;
714 bd->bi_flashoffset = 0;
715 #endif /* !CFG_NO_FLASH */
719 /* initialize higher level parts of CPU like time base and timers */
724 /* initialize malloc() area */
729 # if !defined(CFG_ENV_IS_IN_EEPROM)
735 /* relocate environment function pointers etc. */
739 * Fill in missing fields of bd_info.
740 * We do this here, where we have "normal" access to the
741 * environment; we used to do this still running from ROM,
742 * where had to use getenv_r(), which can be pretty slow when
743 * the environment is in EEPROM.
745 s = getenv ("ethaddr");
746 #if defined (CONFIG_MBX) || defined (CONFIG_RPXCLASSIC) || defined(CONFIG_IAD210)
748 board_get_enetaddr (bd->bi_enetaddr);
751 for (i = 0; i < 6; ++i) {
752 bd->bi_enetaddr[i] = s ? simple_strtoul (s, &e, 16) : 0;
754 s = (*e) ? e + 1 : e;
757 if ((gd->board_type >> 16) == 2)
758 bd->bi_ethspeed = gd->board_type & 0xFFFF;
760 bd->bi_ethspeed = 0xFFFF;
764 load_sernum_ethaddr ();
767 #if defined(CFG_GT_6426x) || defined(CONFIG_PN62)
768 /* handle the 2nd ethernet address */
770 s = getenv ("eth1addr");
772 for (i = 0; i < 6; ++i) {
773 bd->bi_enet1addr[i] = s ? simple_strtoul (s, &e, 16) : 0;
775 s = (*e) ? e + 1 : e;
778 #if defined(CFG_GT_6426x)
779 /* handle the 3rd ethernet address */
781 s = getenv ("eth2addr");
783 for (i = 0; i < 6; ++i) {
784 bd->bi_enet2addr[i] = s ? simple_strtoul (s, &e, 16) : 0;
786 s = (*e) ? e + 1 : e;
791 #if defined(CONFIG_TQM8xxL) || defined(CONFIG_TQM8260) || \
793 load_sernum_ethaddr ();
796 bd->bi_ip_addr = getenv_IPaddr ("ipaddr");
800 #if defined(CONFIG_PCI) && !defined(CONFIG_BAB7xx)
802 * Do pci configuration
807 /** leave this here (after malloc(), environment and PCI are working) **/
808 /* Initialize devices */
811 /* allocate syscalls table (console_init_r will fill it in */
812 syscall_tbl = (void **) malloc (NR_SYSCALLS * sizeof (void *));
814 /* Initialize the console (after the relocation and devices init) */
816 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/
819 #if defined(CONFIG_CCM) || \
820 defined(CONFIG_COGENT) || \
821 defined(CONFIG_CPCI405) || \
822 defined(CONFIG_EVB64260) || \
823 defined(CONFIG_HYMOD) || \
824 defined(CONFIG_KUP4K) || \
825 defined(CONFIG_LWMON) || \
826 defined(CONFIG_PCU_E) || \
827 defined(CONFIG_W7O) || \
828 defined(CONFIG_MISC_INIT_R)
829 /* miscellaneous platform dependent initialisations */
834 if (bd->bi_ethspeed != 0xFFFF)
835 hermes_start_lxt980 ((int) bd->bi_ethspeed);
838 #if (CONFIG_COMMANDS & CFG_CMD_NET) && ( \
839 defined(CONFIG_CCM) || \
840 defined(CONFIG_ELPT860) || \
841 defined(CONFIG_EP8260) || \
842 defined(CONFIG_IP860) || \
843 defined(CONFIG_IVML24) || \
844 defined(CONFIG_IVMS8) || \
845 defined(CONFIG_LWMON) || \
846 defined(CONFIG_MPC8260ADS) || \
847 defined(CONFIG_MPC8266ADS) || \
848 defined(CONFIG_PCU_E) || \
849 defined(CONFIG_RPXSUPER) || \
850 defined(CONFIG_SPD823TS) )
854 puts ("Reset Ethernet PHY\n");
859 #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
866 printf ("U-Boot relocated to %08lx\n", dest_addr);
874 /* Must happen after interrupts are initialized since
875 * an irq handler gets installed
877 #ifdef CONFIG_SERIAL_SOFTWARE_FIFO
878 serial_buffered_init();
881 #ifdef CONFIG_STATUS_LED
882 status_led_set (STATUS_LED_BOOT, STATUS_LED_BLINKING);
889 /* Insert function pointers now that we have relocated the code */
891 /* Initialize from environment */
892 if ((s = getenv ("loadaddr")) != NULL) {
893 load_addr = simple_strtoul (s, NULL, 16);
895 #if (CONFIG_COMMANDS & CFG_CMD_NET)
896 if ((s = getenv ("bootfile")) != NULL) {
897 copy_filename (BootFile, s, sizeof (BootFile));
899 #endif /* CFG_CMD_NET */
903 #if (CONFIG_COMMANDS & CFG_CMD_SCSI)
909 #if (CONFIG_COMMANDS & CFG_CMD_DOC)
915 #if (CONFIG_COMMANDS & CFG_CMD_NAND)
917 nand_init(); /* go init the NAND */
920 #if (CONFIG_COMMANDS & CFG_CMD_NET) && defined(CONFIG_NET_MULTI)
927 post_run (NULL, POST_RAM | post_bootmode_get(0));
928 if (post_bootmode_get(0) & POST_POWERFAIL) {
929 post_bootmode_clear();
934 #if (CONFIG_COMMANDS & CFG_CMD_PCMCIA) && !(CONFIG_COMMANDS & CFG_CMD_IDE)
940 #if (CONFIG_COMMANDS & CFG_CMD_IDE)
942 # ifdef CONFIG_IDE_8xx_PCCARD
948 #endif /* CFG_CMD_IDE */
950 #ifdef CONFIG_LAST_STAGE_INIT
953 * Some parts can be only initialized if all others (like
954 * Interrupts) are up and running (i.e. the PC-style ISA
960 #if (CONFIG_COMMANDS & CFG_CMD_BEDBUG)
965 #if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
967 * Export available size of memory for Linux,
968 * taking into account the protected RAM at top of memory
976 if ((s = getenv ("pram")) != NULL) {
977 pram = simple_strtoul (s, NULL, 10);
984 #ifdef CONFIG_LOGBUFFER
985 /* Also take the logbuffer into account (pram is in kB) */
986 pram += (LOGBUFF_LEN+LOGBUFF_OVERHEAD)/1024;
988 sprintf (memsz, "%ldk", (bd->bi_memsize / 1024) - pram);
989 setenv ("mem", memsz);
993 #ifdef CONFIG_MODEM_SUPPORT
995 extern int do_mdm_init;
996 do_mdm_init = gd->do_mdm_init;
1000 /* Initialization complete - start the monitor */
1002 /* main_loop() can return to retry autoboot, if so just run it again. */
1008 /* NOTREACHED - no way out of command loop except booting */
1013 puts ("### ERROR ### Please RESET the board ###\n");
1017 #ifdef CONFIG_MODEM_SUPPORT
1018 /* called from main loop (common/main.c) */
1019 extern void dbg(const char *fmt, ...);
1025 extern char console_buffer[];
1026 static inline void mdm_readline(char *buf, int bufsiz);
1027 extern void enable_putc(void);
1028 extern int hwflow_onoff(int);
1030 enable_putc(); /* enable serial_putc() */
1032 #ifdef CONFIG_HWFLOW
1033 init_str = getenv("mdm_flow_control");
1034 if (init_str && (strcmp(init_str, "rts/cts") == 0))
1041 sprintf(env_str, "mdm_init%d", i);
1042 if ((init_str = getenv(env_str)) != NULL) {
1043 serial_puts(init_str);
1046 mdm_readline(console_buffer, CFG_CBSIZE);
1047 dbg("ini%d: [%s]", i, console_buffer);
1049 if ((strcmp(console_buffer, "OK") == 0) ||
1050 (strcmp(console_buffer, "ERROR") == 0)) {
1051 dbg("ini%d: cmd done", i);
1053 } else /* in case we are originating call ... */
1054 if (strncmp(console_buffer, "CONNECT", 7) == 0) {
1055 dbg("ini%d: connect", i);
1060 break; /* no init string - stop modem init */
1067 /* final stage - wait for connect */
1068 for(;i > 1;) { /* if 'i' > 1 - wait for connection
1069 message from modem */
1070 mdm_readline(console_buffer, CFG_CBSIZE);
1071 dbg("ini_f: [%s]", console_buffer);
1072 if (strncmp(console_buffer, "CONNECT", 7) == 0) {
1073 dbg("ini_f: connected");
1081 /* 'inline' - We have to do it fast */
1082 static inline void mdm_readline(char *buf, int bufsiz)
1093 /* dbg("(%c)", c); */
1105 return; /* sanity check */
1115 #if 0 /* We could use plain global data, but the resulting code is bigger */
1117 * Pointer to initial global data area
1119 * Here we initialize it.
1121 #undef XTRN_DECLARE_GLOBAL_DATA_PTR
1122 #define XTRN_DECLARE_GLOBAL_DATA_PTR /* empty = allocate here */
1123 DECLARE_GLOBAL_DATA_PTR = (gd_t *) (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET);
1126 /************************************************************************/