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,
38 #if (CONFIG_COMMANDS & CFG_CMD_IDE)
41 #if (CONFIG_COMMANDS & CFG_CMD_SCSI)
44 #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
47 #ifdef CONFIG_STATUS_LED
48 #include <status_led.h>
51 #ifdef CFG_ALLOC_DPRAM
52 #if !(defined(CONFIG_8260)||defined(CONFIG_MPC8560))
57 #if defined(CONFIG_BAB7xx)
61 #if defined(CONFIG_POST)
64 #if defined(CONFIG_LOGBUFFER)
67 #if defined(CFG_INIT_RAM_LOCK) && defined(CONFIG_E500)
68 #include <asm/cache.h>
71 #if (CONFIG_COMMANDS & CFG_CMD_DOC)
74 #if defined(CONFIG_HARD_I2C) || \
75 defined(CONFIG_SOFT_I2C)
78 #if (CONFIG_COMMANDS & CFG_CMD_NAND)
79 void nand_init (void);
82 static char *failed = "*** failed ***\n";
84 #if defined(CONFIG_PCU_E) || defined(CONFIG_OXC)
85 extern flash_info_t flash_info[];
88 #include <environment.h>
90 #if ( ((CFG_ENV_ADDR+CFG_ENV_SIZE) < CFG_MONITOR_BASE) || \
91 (CFG_ENV_ADDR >= (CFG_MONITOR_BASE + CFG_MONITOR_LEN)) ) || \
92 defined(CFG_ENV_IS_IN_NVRAM)
93 #define TOTAL_MALLOC_LEN (CFG_MALLOC_LEN + CFG_ENV_SIZE)
95 #define TOTAL_MALLOC_LEN CFG_MALLOC_LEN
98 extern ulong __init_end;
100 ulong monitor_flash_len;
102 #if (CONFIG_COMMANDS & CFG_CMD_BEDBUG)
103 #include <bedbug/type.h>
107 * Begin and End of memory area for malloc(), and current "brk"
109 static ulong mem_malloc_start = 0;
110 static ulong mem_malloc_end = 0;
111 static ulong mem_malloc_brk = 0;
113 /************************************************************************
115 ************************************************************************
119 * The Malloc area is immediately below the monitor copy in DRAM
121 static void mem_malloc_init (void)
123 DECLARE_GLOBAL_DATA_PTR;
125 ulong dest_addr = CFG_MONITOR_BASE + gd->reloc_off;
127 mem_malloc_end = dest_addr;
128 mem_malloc_start = dest_addr - TOTAL_MALLOC_LEN;
129 mem_malloc_brk = mem_malloc_start;
131 memset ((void *) mem_malloc_start,
133 mem_malloc_end - mem_malloc_start);
136 void *sbrk (ptrdiff_t increment)
138 ulong old = mem_malloc_brk;
139 ulong new = old + increment;
141 if ((new < mem_malloc_start) || (new > mem_malloc_end)) {
144 mem_malloc_brk = new;
145 return ((void *) old);
148 char *strmhz (char *buf, long hz)
154 l = sprintf (buf, "%ld", n);
155 m = (hz % 1000000L) / 1000L;
157 sprintf (buf + l, ".%03ld", m);
162 * All attempts to come up with a "common" initialization sequence
163 * that works for all boards and architectures failed: some of the
164 * requirements are just _too_ different. To get rid of the resulting
165 * mess of board dependend #ifdef'ed code we now make the whole
166 * initialization sequence configurable to the user.
168 * The requirements for any new initalization function is simple: it
169 * receives a pointer to the "global data" structure as it's only
170 * argument, and returns an integer return code, where 0 means
171 * "continue" and != 0 means "fatal error, hang the system".
173 typedef int (init_fnc_t) (void);
175 /************************************************************************
177 ************************************************************************
178 * Some of this code should be moved into the core functions,
179 * but let's get it working (again) first...
182 static int init_baudrate (void)
184 DECLARE_GLOBAL_DATA_PTR;
186 uchar tmp[64]; /* long enough for environment variables */
187 int i = getenv_r ("baudrate", tmp, sizeof (tmp));
189 gd->baudrate = (i > 0)
190 ? (int) simple_strtoul (tmp, NULL, 10)
195 /***********************************************************************/
197 static int init_func_ram (void)
199 DECLARE_GLOBAL_DATA_PTR;
201 #ifdef CONFIG_BOARD_TYPES
202 int board_type = gd->board_type;
204 int board_type = 0; /* use dummy arg */
208 if ((gd->ram_size = initdram (board_type)) > 0) {
209 print_size (gd->ram_size, "\n");
216 /***********************************************************************/
218 #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
219 static int init_func_i2c (void)
222 i2c_init (CFG_I2C_SPEED, CFG_I2C_SLAVE);
228 /***********************************************************************/
230 #if defined(CONFIG_WATCHDOG)
231 static int init_func_watchdog_init (void)
233 puts (" Watchdog enabled\n");
237 # define INIT_FUNC_WATCHDOG_INIT init_func_watchdog_init,
239 static int init_func_watchdog_reset (void)
244 # define INIT_FUNC_WATCHDOG_RESET init_func_watchdog_reset,
246 # define INIT_FUNC_WATCHDOG_INIT /* undef */
247 # define INIT_FUNC_WATCHDOG_RESET /* undef */
248 #endif /* CONFIG_WATCHDOG */
250 /************************************************************************
251 * Initialization sequence *
252 ************************************************************************
255 init_fnc_t *init_sequence[] = {
257 #if defined(CONFIG_BOARD_PRE_INIT)
258 board_pre_init, /* very early board init code (fpga boot, etc.) */
261 get_clocks, /* get CPU and bus clocks (etc.) */
263 #ifdef CFG_ALLOC_DPRAM
264 #if !(defined(CONFIG_8260) || defined(CONFIG_MPC8560))
268 #if defined(CONFIG_BOARD_POSTCLK_INIT)
276 #if defined(CONFIG_8260)
279 #endif /* CONFIG_8260 */
281 #if defined(CONFIG_MPC5XXX)
283 #endif /* CONFIG_MPC5XXX */
285 INIT_FUNC_WATCHDOG_INIT
286 #if defined(CONFIG_BMW) || \
287 defined(CONFIG_COGENT) || \
288 defined(CONFIG_HYMOD) || \
289 defined(CONFIG_RSD_PROTO) || \
293 INIT_FUNC_WATCHDOG_RESET
294 #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
297 #if defined(CONFIG_DTT) /* Digital Thermometers and Thermostats */
303 INIT_FUNC_WATCHDOG_RESET
305 #if defined(CFG_DRAM_TEST)
307 #endif /* CFG_DRAM_TEST */
308 INIT_FUNC_WATCHDOG_RESET
310 NULL, /* Terminate this list */
313 /************************************************************************
315 * This is the first part of the initialization sequence that is
316 * implemented in C, but still running from ROM.
318 * The main purpose is to provide a (serial) console interface as
319 * soon as possible (so we can see any error messages), and to
320 * initialize the RAM so that we can relocate the monitor code to
323 * Be aware of the restrictions: global data is read-only, BSS is not
324 * initialized, and stack space is limited to a few kB.
326 ************************************************************************
329 void board_init_f (ulong bootflag)
331 DECLARE_GLOBAL_DATA_PTR;
334 ulong len, addr, addr_sp;
336 init_fnc_t **init_fnc_ptr;
340 uchar tmp[64]; /* long enough for environment variables */
343 /* Pointer is writable since we allocated a register for it */
344 gd = (gd_t *) (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET);
346 #if !(defined(CONFIG_8260) || defined(CONFIG_MPC8560))
347 /* Clear initial global data */
348 memset ((void *) gd, 0, sizeof (gd_t));
351 for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
352 if ((*init_fnc_ptr) () != 0) {
358 * Now that we have DRAM mapped and working, we can
359 * relocate the code and continue running from DRAM.
361 * Reserve memory at end of RAM for (top down in that order):
362 * - kernel log buffer
366 * - board info struct
368 len = (ulong)&_end - CFG_MONITOR_BASE;
370 #ifndef CONFIG_VERY_BIG_RAM
371 addr = CFG_SDRAM_BASE + gd->ram_size;
373 /* only allow stack below 256M */
374 addr = CFG_SDRAM_BASE +
375 (gd->ram_size > 256 << 20) ? 256 << 20 : gd->ram_size;
378 #ifdef CONFIG_LOGBUFFER
379 /* reserve kernel log buffer */
380 addr -= (LOGBUFF_RESERVE);
381 debug ("Reserving %dk for kernel logbuffer at %08lx\n", LOGBUFF_LEN, addr);
386 * reserve protected RAM
388 i = getenv_r ("pram", tmp, sizeof (tmp));
389 reg = (i > 0) ? simple_strtoul (tmp, NULL, 10) : CONFIG_PRAM;
390 addr -= (reg << 10); /* size is in kB */
391 debug ("Reserving %ldk for protected RAM at %08lx\n", reg, addr);
392 #endif /* CONFIG_PRAM */
394 /* round down to next 4 kB limit */
396 debug ("Top of RAM usable for U-Boot at: %08lx\n", addr);
399 /* reserve memory for LCD display (always full pages) */
400 addr = lcd_setmem (addr);
402 #endif /* CONFIG_LCD */
404 #if defined(CONFIG_VIDEO) && defined(CONFIG_8xx)
405 /* reserve memory for video display (always full pages) */
406 addr = video_setmem (addr);
408 #endif /* CONFIG_VIDEO */
411 * reserve memory for U-Boot code, data & bss
412 * round down to next 4 kB limit
417 debug ("Reserving %ldk for U-Boot at: %08lx\n", len >> 10, addr);
419 #ifdef CONFIG_AMIGAONEG3SE
420 gd->relocaddr = addr;
424 * reserve memory for malloc() arena
426 addr_sp = addr - TOTAL_MALLOC_LEN;
427 debug ("Reserving %dk for malloc() at: %08lx\n",
428 TOTAL_MALLOC_LEN >> 10, addr_sp);
431 * (permanently) allocate a Board Info struct
432 * and a permanent copy of the "global" data
434 addr_sp -= sizeof (bd_t);
435 bd = (bd_t *) addr_sp;
437 debug ("Reserving %d Bytes for Board Info at: %08lx\n",
438 sizeof (bd_t), addr_sp);
439 addr_sp -= sizeof (gd_t);
440 id = (gd_t *) addr_sp;
441 debug ("Reserving %d Bytes for Global Data at: %08lx\n",
442 sizeof (gd_t), addr_sp);
445 * Finally, we set up a new (bigger) stack.
447 * Leave some safety gap for SP, force alignment on 16 byte boundary
448 * Clear initial stack frame
452 *((ulong *) addr_sp)-- = 0;
453 *((ulong *) addr_sp)-- = 0;
454 debug ("Stack Pointer at: %08lx\n", addr_sp);
457 * Save local variables to board info struct
460 bd->bi_memstart = CFG_SDRAM_BASE; /* start of DRAM memory */
461 bd->bi_memsize = gd->ram_size; /* size of DRAM memory in bytes */
464 bd->bi_sramstart = SRAM_BASE; /* start of SRAM memory */
465 bd->bi_sramsize = SRAM_SIZE; /* size of SRAM memory */
467 bd->bi_sramstart = 0; /* FIXME */ /* start of SRAM memory */
468 bd->bi_sramsize = 0; /* FIXME */ /* size of SRAM memory */
471 #if defined(CONFIG_8xx) || defined(CONFIG_8260) || defined(CONFIG_5xx) || \
473 bd->bi_immr_base = CFG_IMMR; /* base of IMMR register */
475 #if defined(CONFIG_MPC5XXX)
476 bd->bi_mbar_base = CFG_MBAR; /* base of internal registers */
479 bd->bi_bootflags = bootflag; /* boot / reboot flag (for LynxOS) */
482 bd->bi_intfreq = gd->cpu_clk; /* Internal Freq, in Hz */
483 bd->bi_busfreq = gd->bus_clk; /* Bus Freq, in Hz */
484 #if defined(CONFIG_8260) || defined(CONFIG_MPC8560)
485 bd->bi_cpmfreq = gd->cpm_clk;
486 bd->bi_brgfreq = gd->brg_clk;
487 bd->bi_sccfreq = gd->scc_clk;
488 bd->bi_vco = gd->vco_out;
489 #endif /* CONFIG_8260 */
490 #if defined(CONFIG_MPC5XXX)
491 bd->bi_ipbfreq = gd->ipb_clk;
492 bd->bi_pcifreq = gd->pci_clk;
493 #endif /* CONFIG_MPC5XXX */
494 bd->bi_baudrate = gd->baudrate; /* Console Baudrate */
497 strncpy (bd->bi_s_version, "1.2", sizeof (bd->bi_s_version));
498 strncpy (bd->bi_r_version, U_BOOT_VERSION, sizeof (bd->bi_r_version));
500 bd->bi_procfreq = gd->cpu_clk; /* Processor Speed, In Hz */
501 bd->bi_plb_busfreq = gd->bus_clk;
502 #if defined(CONFIG_405GP) || defined(CONFIG_405EP)
503 bd->bi_pci_busfreq = get_PCI_freq ();
507 debug ("New Stack Pointer is: %08lx\n", addr_sp);
512 post_bootmode_init();
513 post_run (NULL, POST_ROM | post_bootmode_get(0));
518 memcpy (id, (void *)gd, sizeof (gd_t));
520 relocate_code (addr_sp, id, addr);
522 /* NOTREACHED - relocate_code() does not return */
526 /************************************************************************
528 * This is the next part if the initialization sequence: we are now
529 * running from RAM and have a "normal" C environment, i. e. global
530 * data can be written, BSS has been cleared, the stack size in not
531 * that critical any more, etc.
533 ************************************************************************
536 void board_init_r (gd_t *id, ulong dest_addr)
538 DECLARE_GLOBAL_DATA_PTR;
543 extern void malloc_bin_reloc (void);
544 #ifndef CFG_ENV_IS_NOWHERE
545 extern char * env_name_spec;
552 gd = id; /* initialize RAM version of global data */
555 gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
557 debug ("Now running in RAM - U-Boot at: %08lx\n", dest_addr);
561 gd->reloc_off = dest_addr - CFG_MONITOR_BASE;
563 monitor_flash_len = (ulong)&__init_end - dest_addr;
566 * We have to relocate the command table manually
568 for (cmdtp = &__u_boot_cmd_start; cmdtp != &__u_boot_cmd_end; cmdtp++) {
570 addr = (ulong) (cmdtp->cmd) + gd->reloc_off;
572 printf ("Command \"%s\": 0x%08lx => 0x%08lx\n",
573 cmdtp->name, (ulong) (cmdtp->cmd), addr);
576 (int (*)(struct cmd_tbl_s *, int, int, char *[]))addr;
578 addr = (ulong)(cmdtp->name) + gd->reloc_off;
579 cmdtp->name = (char *)addr;
582 addr = (ulong)(cmdtp->usage) + gd->reloc_off;
583 cmdtp->usage = (char *)addr;
587 addr = (ulong)(cmdtp->help) + gd->reloc_off;
588 cmdtp->help = (char *)addr;
592 /* there are some other pointer constants we must deal with */
593 #ifndef CFG_ENV_IS_NOWHERE
594 env_name_spec += gd->reloc_off;
599 #ifdef CONFIG_LOGBUFFER
600 logbuff_init_ptrs ();
603 post_output_backlog ();
609 #if defined(CONFIG_IP860) || defined(CONFIG_PCU_E) || defined (CONFIG_FLAGADM)
610 icache_enable (); /* it's time to enable the instruction cache */
613 #if defined(CFG_INIT_RAM_LOCK) && defined(CONFIG_E500)
614 unlock_ram_in_cache(); /* it's time to unlock D-cache in e500 */
617 #if defined(CONFIG_BAB7xx) || defined(CONFIG_CPC45)
619 * Do PCI configuration on BAB7xx and CPC45 _before_ the flash
620 * gets initialised, because we need the ISA resp. PCI_to_LOCAL bus
625 #if defined(CONFIG_BAB7xx)
627 * Initialise the ISA bridge
629 initialise_w83c553f ();
632 asm ("sync ; isync");
635 * Setup trap handlers
637 trap_init (dest_addr);
639 #if !defined(CFG_NO_FLASH)
642 if ((flash_size = flash_init ()) > 0) {
643 # ifdef CFG_FLASH_CHECKSUM
644 print_size (flash_size, "");
646 * Compute and print flash CRC if flashchecksum is set to 'y'
648 * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
650 s = getenv ("flashchecksum");
651 if (s && (*s == 'y')) {
652 printf (" CRC: %08lX",
654 (const unsigned char *) CFG_FLASH_BASE,
659 # else /* !CFG_FLASH_CHECKSUM */
660 print_size (flash_size, "\n");
661 # endif /* CFG_FLASH_CHECKSUM */
667 bd->bi_flashstart = CFG_FLASH_BASE; /* update start of FLASH memory */
668 bd->bi_flashsize = flash_size; /* size of FLASH memory (final value) */
669 # if defined(CONFIG_PCU_E) || defined(CONFIG_OXC)
670 bd->bi_flashoffset = 0;
671 # elif CFG_MONITOR_BASE == CFG_FLASH_BASE
672 bd->bi_flashoffset = monitor_flash_len; /* reserved area for startup monitor */
674 bd->bi_flashoffset = 0;
676 #else /* CFG_NO_FLASH */
678 bd->bi_flashsize = 0;
679 bd->bi_flashstart = 0;
680 bd->bi_flashoffset = 0;
681 #endif /* !CFG_NO_FLASH */
685 /* initialize higher level parts of CPU like time base and timers */
690 /* initialize malloc() area */
695 # if !defined(CFG_ENV_IS_IN_EEPROM)
701 /* relocate environment function pointers etc. */
705 * Fill in missing fields of bd_info.
706 * We do this here, where we have "normal" access to the
707 * environment; we used to do this still running from ROM,
708 * where had to use getenv_r(), which can be pretty slow when
709 * the environment is in EEPROM.
711 s = getenv ("ethaddr");
712 #if defined (CONFIG_MBX) || defined (CONFIG_RPXCLASSIC) || defined(CONFIG_IAD210)
714 board_get_enetaddr (bd->bi_enetaddr);
717 for (i = 0; i < 6; ++i) {
718 bd->bi_enetaddr[i] = s ? simple_strtoul (s, &e, 16) : 0;
720 s = (*e) ? e + 1 : e;
723 if ((gd->board_type >> 16) == 2)
724 bd->bi_ethspeed = gd->board_type & 0xFFFF;
726 bd->bi_ethspeed = 0xFFFF;
730 load_sernum_ethaddr ();
733 #if defined(CFG_GT_6426x) || defined(CONFIG_PN62) || defined(CONFIG_PPCHAMELEONEVB) || \
734 defined(CONFIG_MPC8540ADS) || defined(CONFIG_MPC8560ADS)
735 /* handle the 2nd ethernet address */
737 s = getenv ("eth1addr");
739 for (i = 0; i < 6; ++i) {
740 bd->bi_enet1addr[i] = s ? simple_strtoul (s, &e, 16) : 0;
742 s = (*e) ? e + 1 : e;
745 #if defined(CFG_GT_6426x) || defined(CONFIG_MPC8540ADS) || defined(CONFIG_MPC8560ADS)
746 /* handle the 3rd ethernet address */
748 s = getenv ("eth2addr");
750 for (i = 0; i < 6; ++i) {
751 bd->bi_enet2addr[i] = s ? simple_strtoul (s, &e, 16) : 0;
753 s = (*e) ? e + 1 : e;
758 #if defined(CONFIG_TQM8xxL) || defined(CONFIG_TQM8260) || \
760 load_sernum_ethaddr ();
763 bd->bi_ip_addr = getenv_IPaddr ("ipaddr");
767 #if defined(CONFIG_PCI) && !defined(CONFIG_BAB7xx)
769 * Do pci configuration
774 /** leave this here (after malloc(), environment and PCI are working) **/
775 /* Initialize devices */
778 /* Initialize the jump table for applications */
781 /* Initialize the console (after the relocation and devices init) */
784 #if defined(CONFIG_CCM) || \
785 defined(CONFIG_COGENT) || \
786 defined(CONFIG_CPCI405) || \
787 defined(CONFIG_EVB64260) || \
788 defined(CONFIG_KUP4K) || \
789 defined(CONFIG_LWMON) || \
790 defined(CONFIG_PCU_E) || \
791 defined(CONFIG_W7O) || \
792 defined(CONFIG_MISC_INIT_R)
793 /* miscellaneous platform dependent initialisations */
798 if (bd->bi_ethspeed != 0xFFFF)
799 hermes_start_lxt980 ((int) bd->bi_ethspeed);
802 #if (CONFIG_COMMANDS & CFG_CMD_NET) && ( \
803 defined(CONFIG_CCM) || \
804 defined(CONFIG_ELPT860) || \
805 defined(CONFIG_EP8260) || \
806 defined(CONFIG_IP860) || \
807 defined(CONFIG_IVML24) || \
808 defined(CONFIG_IVMS8) || \
809 defined(CONFIG_LWMON) || \
810 defined(CONFIG_MPC8260ADS) || \
811 defined(CONFIG_MPC8266ADS) || \
812 defined(CONFIG_MPC8560ADS) || \
813 defined(CONFIG_PCU_E) || \
814 defined(CONFIG_RPXSUPER) || \
815 defined(CONFIG_SPD823TS) )
818 debug ("Reset Ethernet PHY\n");
822 #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
828 debug ("U-Boot relocated to %08lx\n", dest_addr);
835 /* Must happen after interrupts are initialized since
836 * an irq handler gets installed
838 #ifdef CONFIG_SERIAL_SOFTWARE_FIFO
839 serial_buffered_init();
842 #ifdef CONFIG_STATUS_LED
843 status_led_set (STATUS_LED_BOOT, STATUS_LED_BLINKING);
850 /* Insert function pointers now that we have relocated the code */
852 /* Initialize from environment */
853 if ((s = getenv ("loadaddr")) != NULL) {
854 load_addr = simple_strtoul (s, NULL, 16);
856 #if (CONFIG_COMMANDS & CFG_CMD_NET)
857 if ((s = getenv ("bootfile")) != NULL) {
858 copy_filename (BootFile, s, sizeof (BootFile));
860 #endif /* CFG_CMD_NET */
864 #if (CONFIG_COMMANDS & CFG_CMD_SCSI)
870 #if (CONFIG_COMMANDS & CFG_CMD_DOC)
876 #if (CONFIG_COMMANDS & CFG_CMD_NAND)
879 nand_init(); /* go init the NAND */
882 #if (CONFIG_COMMANDS & CFG_CMD_NET) && defined(CONFIG_NET_MULTI)
889 post_run (NULL, POST_RAM | post_bootmode_get(0));
892 #if (CONFIG_COMMANDS & CFG_CMD_PCMCIA) && !(CONFIG_COMMANDS & CFG_CMD_IDE)
898 #if (CONFIG_COMMANDS & CFG_CMD_IDE)
900 # ifdef CONFIG_IDE_8xx_PCCARD
906 #endif /* CFG_CMD_IDE */
908 #ifdef CONFIG_LAST_STAGE_INIT
911 * Some parts can be only initialized if all others (like
912 * Interrupts) are up and running (i.e. the PC-style ISA
918 #if (CONFIG_COMMANDS & CFG_CMD_BEDBUG)
923 #if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
925 * Export available size of memory for Linux,
926 * taking into account the protected RAM at top of memory
934 if ((s = getenv ("pram")) != NULL) {
935 pram = simple_strtoul (s, NULL, 10);
942 #ifdef CONFIG_LOGBUFFER
943 /* Also take the logbuffer into account (pram is in kB) */
944 pram += (LOGBUFF_LEN+LOGBUFF_OVERHEAD)/1024;
946 sprintf (memsz, "%ldk", (bd->bi_memsize / 1024) - pram);
947 setenv ("mem", memsz);
951 #ifdef CONFIG_MODEM_SUPPORT
953 extern int do_mdm_init;
954 do_mdm_init = gd->do_mdm_init;
958 /* Initialization complete - start the monitor */
960 /* main_loop() can return to retry autoboot, if so just run it again. */
966 /* NOTREACHED - no way out of command loop except booting */
971 puts ("### ERROR ### Please RESET the board ###\n");
975 #ifdef CONFIG_MODEM_SUPPORT
976 /* called from main loop (common/main.c) */
977 extern void dbg(const char *fmt, ...);
983 extern char console_buffer[];
984 static inline void mdm_readline(char *buf, int bufsiz);
985 extern void enable_putc(void);
986 extern int hwflow_onoff(int);
988 enable_putc(); /* enable serial_putc() */
991 init_str = getenv("mdm_flow_control");
992 if (init_str && (strcmp(init_str, "rts/cts") == 0))
999 sprintf(env_str, "mdm_init%d", i);
1000 if ((init_str = getenv(env_str)) != NULL) {
1001 serial_puts(init_str);
1004 mdm_readline(console_buffer, CFG_CBSIZE);
1005 dbg("ini%d: [%s]", i, console_buffer);
1007 if ((strcmp(console_buffer, "OK") == 0) ||
1008 (strcmp(console_buffer, "ERROR") == 0)) {
1009 dbg("ini%d: cmd done", i);
1011 } else /* in case we are originating call ... */
1012 if (strncmp(console_buffer, "CONNECT", 7) == 0) {
1013 dbg("ini%d: connect", i);
1018 break; /* no init string - stop modem init */
1025 /* final stage - wait for connect */
1026 for(;i > 1;) { /* if 'i' > 1 - wait for connection
1027 message from modem */
1028 mdm_readline(console_buffer, CFG_CBSIZE);
1029 dbg("ini_f: [%s]", console_buffer);
1030 if (strncmp(console_buffer, "CONNECT", 7) == 0) {
1031 dbg("ini_f: connected");
1039 /* 'inline' - We have to do it fast */
1040 static inline void mdm_readline(char *buf, int bufsiz)
1051 /* dbg("(%c)", c); */
1063 return; /* sanity check */
1073 #if 0 /* We could use plain global data, but the resulting code is bigger */
1075 * Pointer to initial global data area
1077 * Here we initialize it.
1079 #undef XTRN_DECLARE_GLOBAL_DATA_PTR
1080 #define XTRN_DECLARE_GLOBAL_DATA_PTR /* empty = allocate here */
1081 DECLARE_GLOBAL_DATA_PTR = (gd_t *) (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET);
1084 /************************************************************************/