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)
77 static char *failed = "*** failed ***\n";
79 #if defined(CONFIG_PCU_E) || defined(CONFIG_OXC)
80 extern flash_info_t flash_info[];
83 #include <environment.h>
85 #if ( ((CFG_ENV_ADDR+CFG_ENV_SIZE) < CFG_MONITOR_BASE) || \
86 (CFG_ENV_ADDR >= (CFG_MONITOR_BASE + CFG_MONITOR_LEN)) ) || \
87 defined(CFG_ENV_IS_IN_NVRAM)
88 #define TOTAL_MALLOC_LEN (CFG_MALLOC_LEN + CFG_ENV_SIZE)
90 #define TOTAL_MALLOC_LEN CFG_MALLOC_LEN
94 * Begin and End of memory area for malloc(), and current "brk"
96 static ulong mem_malloc_start = 0;
97 static ulong mem_malloc_end = 0;
98 static ulong mem_malloc_brk = 0;
100 /************************************************************************
102 ************************************************************************
106 * The Malloc area is immediately below the monitor copy in DRAM
108 static void mem_malloc_init (void)
110 DECLARE_GLOBAL_DATA_PTR;
112 ulong dest_addr = CFG_MONITOR_BASE + gd->reloc_off;
114 mem_malloc_end = dest_addr;
115 mem_malloc_start = dest_addr - TOTAL_MALLOC_LEN;
116 mem_malloc_brk = mem_malloc_start;
118 memset ((void *) mem_malloc_start,
120 mem_malloc_end - mem_malloc_start);
123 void *sbrk (ptrdiff_t increment)
125 ulong old = mem_malloc_brk;
126 ulong new = old + increment;
128 if ((new < mem_malloc_start) || (new > mem_malloc_end)) {
131 mem_malloc_brk = new;
132 return ((void *) old);
135 char *strmhz (char *buf, long hz)
141 l = sprintf (buf, "%ld", n);
142 m = (hz % 1000000L) / 1000L;
144 sprintf (buf + l, ".%03ld", m);
148 static void syscalls_init (void)
152 syscall_tbl[SYSCALL_MALLOC] = (void *) malloc;
153 syscall_tbl[SYSCALL_FREE] = (void *) free;
155 syscall_tbl[SYSCALL_INSTALL_HDLR] = (void *) irq_install_handler;
156 syscall_tbl[SYSCALL_FREE_HDLR] = (void *) irq_free_handler;
157 syscall_tbl[SYSCALL_GET_TIMER] = (void *)get_timer;
158 syscall_tbl[SYSCALL_UDELAY] = (void *)udelay;
160 addr = (ulong *) 0xc00; /* syscall ISR addr */
163 *addr++ |= (ulong) syscall_tbl >> 16;
164 *addr++ |= (ulong) syscall_tbl & 0xFFFF;
165 *addr++ |= NR_SYSCALLS >> 16;
166 *addr++ |= NR_SYSCALLS & 0xFFFF;
169 flush_cache (0x0C00, 0x10);
171 /* Initialize syscalls stack pointer */
172 addr = (ulong *) 0xCFC;
175 flush_cache ((ulong)addr, 0x10);
180 * All attempts to come up with a "common" initialization sequence
181 * that works for all boards and architectures failed: some of the
182 * requirements are just _too_ different. To get rid of the resulting
183 * mess of board dependend #ifdef'ed code we now make the whole
184 * initialization sequence configurable to the user.
186 * The requirements for any new initalization function is simple: it
187 * receives a pointer to the "global data" structure as it's only
188 * argument, and returns an integer return code, where 0 means
189 * "continue" and != 0 means "fatal error, hang the system".
191 typedef int (init_fnc_t) (void);
193 /************************************************************************
195 ************************************************************************
196 * Some of this code should be moved into the core functions,
197 * but let's get it working (again) first...
200 static int init_baudrate (void)
202 DECLARE_GLOBAL_DATA_PTR;
204 uchar tmp[64]; /* long enough for environment variables */
205 int i = getenv_r ("baudrate", tmp, sizeof (tmp));
207 gd->baudrate = (i > 0)
208 ? (int) simple_strtoul (tmp, NULL, 10)
213 /***********************************************************************/
215 static int init_func_ram (void)
217 DECLARE_GLOBAL_DATA_PTR;
219 #ifdef CONFIG_BOARD_TYPES
220 int board_type = gd->board_type;
222 int board_type = 0; /* use dummy arg */
226 if ((gd->ram_size = initdram (board_type)) > 0) {
227 print_size (gd->ram_size, "\n");
234 /***********************************************************************/
236 #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
237 static int init_func_i2c (void)
240 i2c_init (CFG_I2C_SPEED, CFG_I2C_SLAVE);
246 /***********************************************************************/
248 #if defined(CONFIG_WATCHDOG)
249 static int init_func_watchdog_init (void)
251 puts (" Watchdog enabled\n");
255 # define INIT_FUNC_WATCHDOG_INIT init_func_watchdog_init,
257 static int init_func_watchdog_reset (void)
262 # define INIT_FUNC_WATCHDOG_RESET init_func_watchdog_reset,
264 # define INIT_FUNC_WATCHDOG_INIT /* undef */
265 # define INIT_FUNC_WATCHDOG_RESET /* undef */
266 #endif /* CONFIG_WATCHDOG */
268 /************************************************************************
269 * Initialization sequence *
270 ************************************************************************
273 init_fnc_t *init_sequence[] = {
275 #if defined(CONFIG_BOARD_PRE_INIT)
276 board_pre_init, /* very early board init code (fpga boot, etc.) */
279 get_clocks, /* get CPU and bus clocks (etc.) */
281 #ifdef CFG_ALLOC_DPRAM
282 #if !defined(CONFIG_8260)
286 #if defined(CONFIG_BOARD_POSTCLK_INIT)
294 #if defined(CONFIG_8260)
297 #endif /* CONFIG_8260 */
300 INIT_FUNC_WATCHDOG_INIT
301 #if defined(CONFIG_BMW) || \
302 defined(CONFIG_COGENT) || \
303 defined(CONFIG_HYMOD) || \
304 defined(CONFIG_RSD_PROTO) || \
308 INIT_FUNC_WATCHDOG_RESET
309 #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
312 #if defined(CONFIG_DTT) /* Digital Thermometers and Thermostats */
318 INIT_FUNC_WATCHDOG_RESET
320 #if defined(CFG_DRAM_TEST)
322 #endif /* CFG_DRAM_TEST */
323 INIT_FUNC_WATCHDOG_RESET
325 NULL, /* Terminate this list */
328 /************************************************************************
330 * This is the first part of the initialization sequence that is
331 * implemented in C, but still running from ROM.
333 * The main purpose is to provide a (serial) console interface as
334 * soon as possible (so we can see any error messages), and to
335 * initialize the RAM so that we can relocate the monitor code to
338 * Be aware of the restrictions: global data is read-only, BSS is not
339 * initialized, and stack space is limited to a few kB.
341 ************************************************************************
344 void board_init_f (ulong bootflag)
346 DECLARE_GLOBAL_DATA_PTR;
349 ulong len, addr, addr_sp;
351 init_fnc_t **init_fnc_ptr;
355 uchar tmp[64]; /* long enough for environment variables */
358 /* Pointer is writable since we allocated a register for it */
359 gd = (gd_t *) (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET);
362 /* Clear initial global data */
363 memset ((void *) gd, 0, sizeof (gd_t));
366 for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
367 if ((*init_fnc_ptr) () != 0) {
373 * Now that we have DRAM mapped and working, we can
374 * relocate the code and continue running from DRAM.
376 * Reserve memory at end of RAM for (top down in that order):
377 * - kernel log buffer
381 * - board info struct
383 len = get_endaddr () - CFG_MONITOR_BASE;
385 if (len > CFG_MONITOR_LEN) {
386 printf ("*** U-Boot size %ld > reserved memory (%d)\n",
387 len, CFG_MONITOR_LEN);
391 if (CFG_MONITOR_LEN > len)
392 len = CFG_MONITOR_LEN;
394 #ifndef CONFIG_VERY_BIG_RAM
395 addr = CFG_SDRAM_BASE + gd->ram_size;
397 /* only allow stack below 256M */
398 addr = CFG_SDRAM_BASE +
399 (gd->ram_size > 256 << 20) ? 256 << 20 : gd->ram_size;
402 #ifdef CONFIG_LOGBUFFER
403 /* reserve kernel log buffer */
404 addr -= (LOGBUFF_RESERVE);
406 printf ("Reserving %ldk for kernel logbuffer at %08lx\n", LOGBUFF_LEN, addr);
412 * reserve protected RAM
414 i = getenv_r ("pram", tmp, sizeof (tmp));
415 reg = (i > 0) ? simple_strtoul (tmp, NULL, 10) : CONFIG_PRAM;
416 addr -= (reg << 10); /* size is in kB */
418 printf ("Reserving %ldk for protected RAM at %08lx\n", reg, addr);
420 #endif /* CONFIG_PRAM */
422 /* round down to next 4 kB limit */
425 printf ("Top of RAM usable for U-Boot at: %08lx\n", addr);
429 /* reserve memory for LCD display (always full pages) */
430 addr = lcd_setmem (addr);
432 #endif /* CONFIG_LCD */
434 #if defined(CONFIG_VIDEO) && defined(CONFIG_8xx)
435 /* reserve memory for video display (always full pages) */
436 addr = video_setmem (addr);
438 #endif /* CONFIG_VIDEO */
441 * reserve memory for U-Boot code, data & bss
442 * round down to next 4 kB limit
448 printf ("Reserving %ldk for U-Boot at: %08lx\n", len >> 10, addr);
451 #ifdef CONFIG_AMIGAONEG3SE
452 gd->relocaddr = addr;
456 * reserve memory for malloc() arena
458 addr_sp = addr - TOTAL_MALLOC_LEN;
460 printf ("Reserving %dk for malloc() at: %08lx\n",
461 TOTAL_MALLOC_LEN >> 10, addr_sp);
465 * (permanently) allocate a Board Info struct
466 * and a permanent copy of the "global" data
468 addr_sp -= sizeof (bd_t);
469 bd = (bd_t *) addr_sp;
472 printf ("Reserving %d Bytes for Board Info at: %08lx\n",
473 sizeof (bd_t), addr_sp);
475 addr_sp -= sizeof (gd_t);
476 id = (gd_t *) addr_sp;
478 printf ("Reserving %d Bytes for Global Data at: %08lx\n",
479 sizeof (gd_t), addr_sp);
483 * Finally, we set up a new (bigger) stack.
485 * Leave some safety gap for SP, force alignment on 16 byte boundary
486 * Clear initial stack frame
490 *((ulong *) addr_sp)-- = 0;
491 *((ulong *) addr_sp)-- = 0;
493 printf ("Stack Pointer at: %08lx\n", addr_sp);
497 * Save local variables to board info struct
500 bd->bi_memstart = CFG_SDRAM_BASE; /* start of DRAM memory */
501 bd->bi_memsize = gd->ram_size; /* size of DRAM memory in bytes */
504 bd->bi_sramstart = SRAM_BASE; /* start of SRAM memory */
505 bd->bi_sramsize = SRAM_SIZE; /* size of SRAM memory */
507 bd->bi_sramstart = 0; /* FIXME */ /* start of SRAM memory */
508 bd->bi_sramsize = 0; /* FIXME */ /* size of SRAM memory */
511 #if defined(CONFIG_8xx) || defined(CONFIG_8260) || defined(CONFIG_5xx)
512 bd->bi_immr_base = CFG_IMMR; /* base of IMMR register */
515 bd->bi_bootflags = bootflag; /* boot / reboot flag (for LynxOS) */
518 bd->bi_intfreq = gd->cpu_clk; /* Internal Freq, in Hz */
519 bd->bi_busfreq = gd->bus_clk; /* Bus Freq, in Hz */
520 #if defined(CONFIG_8260)
521 bd->bi_cpmfreq = gd->cpm_clk;
522 bd->bi_brgfreq = gd->brg_clk;
523 bd->bi_sccfreq = gd->scc_clk;
524 bd->bi_vco = gd->vco_out;
525 #endif /* CONFIG_8260 */
527 bd->bi_baudrate = gd->baudrate; /* Console Baudrate */
530 strncpy (bd->bi_s_version, "1.2", sizeof (bd->bi_s_version));
531 strncpy (bd->bi_r_version, U_BOOT_VERSION, sizeof (bd->bi_r_version));
533 bd->bi_procfreq = gd->cpu_clk; /* Processor Speed, In Hz */
534 bd->bi_plb_busfreq = gd->bus_clk;
536 bd->bi_pci_busfreq = get_PCI_freq ();
541 printf ("New Stack Pointer is: %08lx\n", addr_sp);
547 post_bootmode_init();
548 post_run (NULL, POST_ROM | post_bootmode_get(0));
553 memcpy (id, gd, sizeof (gd_t));
555 relocate_code (addr_sp, id, addr);
557 /* NOTREACHED - relocate_code() does not return */
561 /************************************************************************
563 * This is the next part if the initialization sequence: we are now
564 * running from RAM and have a "normal" C environment, i. e. global
565 * data can be written, BSS has been cleared, the stack size in not
566 * that critical any more, etc.
568 ************************************************************************
571 void board_init_r (gd_t *id, ulong dest_addr)
573 DECLARE_GLOBAL_DATA_PTR;
579 extern void malloc_bin_reloc (void);
580 #ifndef CFG_ENV_IS_NOWHERE
581 extern char * env_name_spec;
588 gd = id; /* initialize RAM version of global data */
591 gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
594 printf ("Now running in RAM - U-Boot at: %08lx\n", dest_addr);
599 gd->reloc_off = dest_addr - CFG_MONITOR_BASE;
602 * We have to relocate the command table manually
604 for (cmdtp = &cmd_tbl[0]; cmdtp->name; cmdtp++) {
607 addr = (ulong) (cmdtp->cmd) + gd->reloc_off;
609 printf ("Command \"%s\": 0x%08lx => 0x%08lx\n",
610 cmdtp->name, (ulong) (cmdtp->cmd), addr);
613 (int (*)(struct cmd_tbl_s *, int, int, char *[]))addr;
615 addr = (ulong)(cmdtp->name) + gd->reloc_off;
616 cmdtp->name = (char *)addr;
619 addr = (ulong)(cmdtp->usage) + gd->reloc_off;
620 cmdtp->usage = (char *)addr;
624 addr = (ulong)(cmdtp->help) + gd->reloc_off;
625 cmdtp->help = (char *)addr;
629 /* there are some other pointer constants we must deal with */
630 #ifndef CFG_ENV_IS_NOWHERE
631 env_name_spec += gd->reloc_off;
636 #ifdef CONFIG_LOGBUFFER
637 logbuff_init_ptrs ();
640 post_output_backlog ();
646 #if defined(CONFIG_IP860) || defined(CONFIG_PCU_E) || defined (CONFIG_FLAGADM)
647 icache_enable (); /* it's time to enable the instruction cache */
650 #if defined(CONFIG_BAB7xx) || defined(CONFIG_CPC45)
652 * Do PCI configuration on BAB7xx and CPC45 _before_ the flash
653 * gets initialised, because we need the ISA resp. PCI_to_LOCAL bus
658 #if defined(CONFIG_BAB7xx)
660 * Initialise the ISA bridge
662 initialise_w83c553f ();
665 asm ("sync ; isync");
668 * Setup trap handlers
670 trap_init (dest_addr);
672 #if !defined(CFG_NO_FLASH)
675 if ((flash_size = flash_init ()) > 0) {
676 #ifdef CFG_FLASH_CHECKSUM
677 print_size (flash_size, "");
679 * Compute and print flash CRC if flashchecksum is set to 'y'
681 * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
683 s = getenv ("flashchecksum");
684 if (s && (*s == 'y')) {
685 printf (" CRC: %08lX",
687 (const unsigned char *) CFG_FLASH_BASE,
693 print_size (flash_size, "\n");
694 #endif /* CFG_FLASH_CHECKSUM */
700 bd->bi_flashstart = CFG_FLASH_BASE; /* update start of FLASH memory */
701 bd->bi_flashsize = flash_size; /* size of FLASH memory (final value) */
702 #if defined(CONFIG_PCU_E) || defined(CONFIG_OXC)
703 bd->bi_flashoffset = 0;
704 #elif CFG_MONITOR_BASE == CFG_FLASH_BASE
705 bd->bi_flashoffset = CFG_MONITOR_LEN; /* reserved area for startup monitor */
707 bd->bi_flashoffset = 0;
711 bd->bi_flashsize = 0;
712 bd->bi_flashstart = 0;
713 bd->bi_flashoffset = 0;
714 #endif /* !CFG_NO_FLASH */
718 /* initialize higher level parts of CPU like time base and timers */
723 /* initialize malloc() area */
728 # if !defined(CFG_ENV_IS_IN_EEPROM)
734 /* relocate environment function pointers etc. */
738 * Fill in missing fields of bd_info.
739 * We do this here, where we have "normal" access to the
740 * environment; we used to do this still running from ROM,
741 * where had to use getenv_r(), which can be pretty slow when
742 * the environment is in EEPROM.
744 s = getenv ("ethaddr");
745 #if defined (CONFIG_MBX) || defined (CONFIG_RPXCLASSIC) || defined(CONFIG_IAD210)
747 board_get_enetaddr (bd->bi_enetaddr);
750 for (i = 0; i < 6; ++i) {
751 bd->bi_enetaddr[i] = s ? simple_strtoul (s, &e, 16) : 0;
753 s = (*e) ? e + 1 : e;
756 if ((gd->board_type >> 16) == 2)
757 bd->bi_ethspeed = gd->board_type & 0xFFFF;
759 bd->bi_ethspeed = 0xFFFF;
763 load_sernum_ethaddr ();
766 #if defined(CFG_GT_6426x) || defined(CONFIG_PN62)
767 /* handle the 2nd ethernet address */
769 s = getenv ("eth1addr");
771 for (i = 0; i < 6; ++i) {
772 bd->bi_enet1addr[i] = s ? simple_strtoul (s, &e, 16) : 0;
774 s = (*e) ? e + 1 : e;
777 #if defined(CFG_GT_6426x)
778 /* handle the 3rd ethernet address */
780 s = getenv ("eth2addr");
782 for (i = 0; i < 6; ++i) {
783 bd->bi_enet2addr[i] = s ? simple_strtoul (s, &e, 16) : 0;
785 s = (*e) ? e + 1 : e;
790 #if defined(CONFIG_TQM8xxL) || defined(CONFIG_TQM8260) || \
792 load_sernum_ethaddr ();
795 bd->bi_ip_addr = getenv_IPaddr ("ipaddr");
799 #if defined(CONFIG_PCI) && !defined(CONFIG_BAB7xx)
801 * Do pci configuration
806 /** leave this here (after malloc(), environment and PCI are working) **/
807 /* Initialize devices */
810 /* allocate syscalls table (console_init_r will fill it in */
811 syscall_tbl = (void **) malloc (NR_SYSCALLS * sizeof (void *));
813 /* Initialize the console (after the relocation and devices init) */
815 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/
818 #if defined(CONFIG_CCM) || \
819 defined(CONFIG_COGENT) || \
820 defined(CONFIG_CPCI405) || \
821 defined(CONFIG_EVB64260) || \
822 defined(CONFIG_HYMOD) || \
823 defined(CONFIG_KUP4K) || \
824 defined(CONFIG_LWMON) || \
825 defined(CONFIG_PCU_E) || \
826 defined(CONFIG_W7O) || \
827 defined(CONFIG_MISC_INIT_R)
828 /* miscellaneous platform dependent initialisations */
833 if (bd->bi_ethspeed != 0xFFFF)
834 hermes_start_lxt980 ((int) bd->bi_ethspeed);
837 #if (CONFIG_COMMANDS & CFG_CMD_NET) && ( \
838 defined(CONFIG_CCM) || \
839 defined(CONFIG_ELPT860) || \
840 defined(CONFIG_EP8260) || \
841 defined(CONFIG_IP860) || \
842 defined(CONFIG_IVML24) || \
843 defined(CONFIG_IVMS8) || \
844 defined(CONFIG_LWMON) || \
845 defined(CONFIG_MPC8260ADS) || \
846 defined(CONFIG_MPC8266ADS) || \
847 defined(CONFIG_PCU_E) || \
848 defined(CONFIG_RPXSUPER) || \
849 defined(CONFIG_SPD823TS) )
853 puts ("Reset Ethernet PHY\n");
858 #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
865 printf ("U-Boot relocated to %08lx\n", dest_addr);
873 /* Must happen after interrupts are initialized since
874 * an irq handler gets installed
876 #ifdef CONFIG_SERIAL_SOFTWARE_FIFO
877 serial_buffered_init();
880 #ifdef CONFIG_STATUS_LED
881 status_led_set (STATUS_LED_BOOT, STATUS_LED_BLINKING);
888 /* Insert function pointers now that we have relocated the code */
890 /* Initialize from environment */
891 if ((s = getenv ("loadaddr")) != NULL) {
892 load_addr = simple_strtoul (s, NULL, 16);
894 #if (CONFIG_COMMANDS & CFG_CMD_NET)
895 if ((s = getenv ("bootfile")) != NULL) {
896 copy_filename (BootFile, s, sizeof (BootFile));
898 #endif /* CFG_CMD_NET */
902 #if (CONFIG_COMMANDS & CFG_CMD_SCSI)
908 #if (CONFIG_COMMANDS & CFG_CMD_DOC)
914 #if (CONFIG_COMMANDS & CFG_CMD_NET) && defined(CONFIG_NET_MULTI)
921 post_run (NULL, POST_RAM | post_bootmode_get(0));
922 if (post_bootmode_get(0) & POST_POWERFAIL) {
923 post_bootmode_clear();
928 #if (CONFIG_COMMANDS & CFG_CMD_PCMCIA) && !(CONFIG_COMMANDS & CFG_CMD_IDE)
934 #if (CONFIG_COMMANDS & CFG_CMD_IDE)
936 # ifdef CONFIG_IDE_8xx_PCCARD
942 #endif /* CFG_CMD_IDE */
944 #ifdef CONFIG_LAST_STAGE_INIT
947 * Some parts can be only initialized if all others (like
948 * Interrupts) are up and running (i.e. the PC-style ISA
954 #if (CONFIG_COMMANDS & CFG_CMD_BEDBUG)
959 #if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
961 * Export available size of memory for Linux,
962 * taking into account the protected RAM at top of memory
970 if ((s = getenv ("pram")) != NULL) {
971 pram = simple_strtoul (s, NULL, 10);
978 #ifdef CONFIG_LOGBUFFER
979 /* Also take the logbuffer into account (pram is in kB) */
980 pram += (LOGBUFF_LEN+LOGBUFF_OVERHEAD)/1024;
982 sprintf (memsz, "%ldk", (bd->bi_memsize / 1024) - pram);
983 setenv ("mem", memsz);
987 #ifdef CONFIG_MODEM_SUPPORT
989 extern int do_mdm_init;
990 do_mdm_init = gd->do_mdm_init;
994 /* Initialization complete - start the monitor */
996 /* main_loop() can return to retry autoboot, if so just run it again. */
1002 /* NOTREACHED - no way out of command loop except booting */
1007 puts ("### ERROR ### Please RESET the board ###\n");
1011 #ifdef CONFIG_MODEM_SUPPORT
1012 /* called from main loop (common/main.c) */
1013 extern void dbg(const char *fmt, ...);
1019 extern char console_buffer[];
1020 static inline void mdm_readline(char *buf, int bufsiz);
1021 extern void enable_putc(void);
1022 extern int hwflow_onoff(int);
1024 enable_putc(); /* enable serial_putc() */
1026 #ifdef CONFIG_HWFLOW
1027 init_str = getenv("mdm_flow_control");
1028 if (init_str && (strcmp(init_str, "rts/cts") == 0))
1035 sprintf(env_str, "mdm_init%d", i);
1036 if ((init_str = getenv(env_str)) != NULL) {
1037 serial_puts(init_str);
1040 mdm_readline(console_buffer, CFG_CBSIZE);
1041 dbg("ini%d: [%s]", i, console_buffer);
1043 if ((strcmp(console_buffer, "OK") == 0) ||
1044 (strcmp(console_buffer, "ERROR") == 0)) {
1045 dbg("ini%d: cmd done", i);
1047 } else /* in case we are originating call ... */
1048 if (strncmp(console_buffer, "CONNECT", 7) == 0) {
1049 dbg("ini%d: connect", i);
1054 break; /* no init string - stop modem init */
1061 /* final stage - wait for connect */
1062 for(;i > 1;) { /* if 'i' > 1 - wait for connection
1063 message from modem */
1064 mdm_readline(console_buffer, CFG_CBSIZE);
1065 dbg("ini_f: [%s]", console_buffer);
1066 if (strncmp(console_buffer, "CONNECT", 7) == 0) {
1067 dbg("ini_f: connected");
1075 /* 'inline' - We have to do it fast */
1076 static inline void mdm_readline(char *buf, int bufsiz)
1087 /* dbg("(%c)", c); */
1099 return; /* sanity check */
1109 #if 0 /* We could use plain global data, but the resulting code is bigger */
1111 * Pointer to initial global data area
1113 * Here we initialize it.
1115 #undef XTRN_DECLARE_GLOBAL_DATA_PTR
1116 #define XTRN_DECLARE_GLOBAL_DATA_PTR /* empty = allocate here */
1117 DECLARE_GLOBAL_DATA_PTR = (gd_t *) (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET);
1120 /************************************************************************/