2002-11-03 00:24:07 +00:00
|
|
|
/*
|
2006-01-29 18:12:41 +00:00
|
|
|
* (C) Copyright 2002-2006
|
2002-11-03 00:24:07 +00:00
|
|
|
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
|
|
|
|
*
|
|
|
|
* (C) Copyright 2002
|
|
|
|
* Sysgo Real-Time Solutions, GmbH <www.elinos.com>
|
|
|
|
* Marius Groeger <mgroeger@sysgo.de>
|
|
|
|
*
|
|
|
|
* See file CREDITS for list of people who contributed to this
|
|
|
|
* project.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
2006-01-29 18:12:41 +00:00
|
|
|
/*
|
|
|
|
* To match the U-Boot user interface on ARM platforms to the U-Boot
|
|
|
|
* standard (as on PPC platforms), some messages with debug character
|
|
|
|
* are removed from the default U-Boot build.
|
|
|
|
*
|
|
|
|
* Define DEBUG here if you want additional info as shown below
|
|
|
|
* printed upon startup:
|
|
|
|
*
|
|
|
|
* U-Boot code: 00F00000 -> 00F3C774 BSS: -> 00FC3274
|
|
|
|
* IRQ Stack: 00ebff7c
|
|
|
|
* FIQ Stack: 00ebef7c
|
|
|
|
*/
|
|
|
|
|
2002-11-03 00:24:07 +00:00
|
|
|
#include <common.h>
|
|
|
|
#include <command.h>
|
2003-06-22 17:18:28 +00:00
|
|
|
#include <malloc.h>
|
2002-11-03 00:24:07 +00:00
|
|
|
#include <devices.h>
|
|
|
|
#include <version.h>
|
|
|
|
#include <net.h>
|
|
|
|
|
2004-06-09 13:37:52 +00:00
|
|
|
#ifdef CONFIG_DRIVER_SMC91111
|
|
|
|
#include "../drivers/smc91111.h"
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_DRIVER_LAN91C96
|
|
|
|
#include "../drivers/lan91c96.h"
|
|
|
|
#endif
|
|
|
|
|
2006-02-10 10:25:41 +00:00
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2003-03-26 06:55:25 +00:00
|
|
|
#if (CONFIG_COMMANDS & CFG_CMD_NAND)
|
|
|
|
void nand_init (void);
|
|
|
|
#endif
|
2002-11-03 00:24:07 +00:00
|
|
|
|
2003-05-30 12:48:29 +00:00
|
|
|
ulong monitor_flash_len;
|
|
|
|
|
2003-06-16 23:50:08 +00:00
|
|
|
#ifdef CONFIG_HAS_DATAFLASH
|
|
|
|
extern int AT91F_DataflashInit(void);
|
|
|
|
extern void dataflash_print_info(void);
|
|
|
|
#endif
|
|
|
|
|
2003-06-19 23:01:32 +00:00
|
|
|
#ifndef CONFIG_IDENT_STRING
|
|
|
|
#define CONFIG_IDENT_STRING ""
|
|
|
|
#endif
|
|
|
|
|
2002-11-03 00:24:07 +00:00
|
|
|
const char version_string[] =
|
2003-06-19 23:01:32 +00:00
|
|
|
U_BOOT_VERSION" (" __DATE__ " - " __TIME__ ")"CONFIG_IDENT_STRING;
|
2002-11-03 00:24:07 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_DRIVER_CS8900
|
|
|
|
extern void cs8900_get_enetaddr (uchar * addr);
|
|
|
|
#endif
|
|
|
|
|
2004-06-06 22:11:41 +00:00
|
|
|
#ifdef CONFIG_DRIVER_RTL8019
|
2003-12-07 00:46:27 +00:00
|
|
|
extern void rtl8019_get_enetaddr (uchar * addr);
|
|
|
|
#endif
|
|
|
|
|
2002-11-03 00:24:07 +00:00
|
|
|
/*
|
|
|
|
* Begin and End of memory area for malloc(), and current "brk"
|
|
|
|
*/
|
|
|
|
static ulong mem_malloc_start = 0;
|
|
|
|
static ulong mem_malloc_end = 0;
|
|
|
|
static ulong mem_malloc_brk = 0;
|
|
|
|
|
2002-12-03 21:28:10 +00:00
|
|
|
static
|
|
|
|
void mem_malloc_init (ulong dest_addr)
|
2002-11-03 00:24:07 +00:00
|
|
|
{
|
|
|
|
mem_malloc_start = dest_addr;
|
2002-11-03 18:03:52 +00:00
|
|
|
mem_malloc_end = dest_addr + CFG_MALLOC_LEN;
|
2002-11-03 00:24:07 +00:00
|
|
|
mem_malloc_brk = mem_malloc_start;
|
|
|
|
|
|
|
|
memset ((void *) mem_malloc_start, 0,
|
|
|
|
mem_malloc_end - mem_malloc_start);
|
|
|
|
}
|
|
|
|
|
|
|
|
void *sbrk (ptrdiff_t increment)
|
|
|
|
{
|
|
|
|
ulong old = mem_malloc_brk;
|
|
|
|
ulong new = old + increment;
|
|
|
|
|
|
|
|
if ((new < mem_malloc_start) || (new > mem_malloc_end)) {
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
mem_malloc_brk = new;
|
|
|
|
|
|
|
|
return ((void *) old);
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* Init Utilities *
|
|
|
|
************************************************************************
|
|
|
|
* Some of this code should be moved into the core functions,
|
|
|
|
* or dropped completely,
|
|
|
|
* but let's get it working (again) first...
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int init_baudrate (void)
|
|
|
|
{
|
2006-03-11 21:53:33 +00:00
|
|
|
char tmp[64]; /* long enough for environment variables */
|
2002-11-03 00:24:07 +00:00
|
|
|
int i = getenv_r ("baudrate", tmp, sizeof (tmp));
|
2003-06-22 17:18:28 +00:00
|
|
|
gd->bd->bi_baudrate = gd->baudrate = (i > 0)
|
2002-11-03 00:24:07 +00:00
|
|
|
? (int) simple_strtoul (tmp, NULL, 10)
|
|
|
|
: CONFIG_BAUDRATE;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int display_banner (void)
|
|
|
|
{
|
|
|
|
printf ("\n\n%s\n\n", version_string);
|
2006-01-29 18:12:41 +00:00
|
|
|
debug ("U-Boot code: %08lX -> %08lX BSS: -> %08lX\n",
|
|
|
|
_armboot_start, _bss_start, _bss_end);
|
2002-11-03 00:24:07 +00:00
|
|
|
#ifdef CONFIG_MODEM_SUPPORT
|
2006-01-29 18:12:41 +00:00
|
|
|
debug ("Modem Support enabled\n");
|
2002-11-03 00:24:07 +00:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_USE_IRQ
|
2006-01-29 18:12:41 +00:00
|
|
|
debug ("IRQ Stack: %08lx\n", IRQ_STACK_START);
|
|
|
|
debug ("FIQ Stack: %08lx\n", FIQ_STACK_START);
|
2002-11-03 00:24:07 +00:00
|
|
|
#endif
|
2003-10-10 10:05:42 +00:00
|
|
|
|
2002-11-03 00:24:07 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* WARNING: this code looks "cleaner" than the PowerPC version, but
|
|
|
|
* has the disadvantage that you either get nothing, or everything.
|
|
|
|
* On PowerPC, you might see "DRAM: " before the system hangs - which
|
|
|
|
* gives a simple yet clear indication which part of the
|
|
|
|
* initialization if failing.
|
|
|
|
*/
|
|
|
|
static int display_dram_config (void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2006-01-29 18:12:41 +00:00
|
|
|
#ifdef DEBUG
|
2003-12-06 19:49:23 +00:00
|
|
|
puts ("RAM Configuration:\n");
|
2002-11-03 00:24:07 +00:00
|
|
|
|
|
|
|
for(i=0; i<CONFIG_NR_DRAM_BANKS; i++) {
|
|
|
|
printf ("Bank #%d: %08lx ", i, gd->bd->bi_dram[i].start);
|
|
|
|
print_size (gd->bd->bi_dram[i].size, "\n");
|
|
|
|
}
|
2006-01-29 18:12:41 +00:00
|
|
|
#else
|
|
|
|
ulong size = 0;
|
|
|
|
|
|
|
|
for (i=0; i<CONFIG_NR_DRAM_BANKS; i++) {
|
|
|
|
size += gd->bd->bi_dram[i].size;
|
|
|
|
}
|
|
|
|
puts("DRAM: ");
|
|
|
|
print_size(size, "\n");
|
|
|
|
#endif
|
2002-11-03 00:24:07 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2006-02-28 17:05:25 +00:00
|
|
|
#ifndef CFG_NO_FLASH
|
2002-11-03 00:24:07 +00:00
|
|
|
static void display_flash_config (ulong size)
|
|
|
|
{
|
|
|
|
puts ("Flash: ");
|
|
|
|
print_size (size, "\n");
|
|
|
|
}
|
2006-02-28 17:05:25 +00:00
|
|
|
#endif /* CFG_NO_FLASH */
|
2002-11-03 00:24:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
2003-12-06 19:49:23 +00:00
|
|
|
* Breathe some life into the board...
|
2002-11-03 00:24:07 +00:00
|
|
|
*
|
2003-09-17 22:48:07 +00:00
|
|
|
* Initialize a serial port as console, and carry out some hardware
|
2002-11-03 00:24:07 +00:00
|
|
|
* tests.
|
|
|
|
*
|
|
|
|
* The first part of initialization is running from Flash memory;
|
|
|
|
* its main purpose is to initialize the RAM so that we
|
|
|
|
* can relocate the monitor code to RAM.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* All attempts to come up with a "common" initialization sequence
|
|
|
|
* that works for all boards and architectures failed: some of the
|
|
|
|
* requirements are just _too_ different. To get rid of the resulting
|
2004-02-08 19:38:38 +00:00
|
|
|
* mess of board dependent #ifdef'ed code we now make the whole
|
2002-11-03 00:24:07 +00:00
|
|
|
* initialization sequence configurable to the user.
|
|
|
|
*
|
|
|
|
* The requirements for any new initalization function is simple: it
|
|
|
|
* receives a pointer to the "global data" structure as it's only
|
|
|
|
* argument, and returns an integer return code, where 0 means
|
|
|
|
* "continue" and != 0 means "fatal error, hang the system".
|
|
|
|
*/
|
|
|
|
typedef int (init_fnc_t) (void);
|
|
|
|
|
2006-01-29 18:12:41 +00:00
|
|
|
int print_cpuinfo (void); /* test-only */
|
|
|
|
|
2002-11-03 00:24:07 +00:00
|
|
|
init_fnc_t *init_sequence[] = {
|
|
|
|
cpu_init, /* basic cpu dependent setup */
|
|
|
|
board_init, /* basic board dependent setup */
|
|
|
|
interrupt_init, /* set up exceptions */
|
|
|
|
env_init, /* initialize environment */
|
|
|
|
init_baudrate, /* initialze baudrate settings */
|
|
|
|
serial_init, /* serial communications setup */
|
2003-06-22 17:18:28 +00:00
|
|
|
console_init_f, /* stage 1 init of console */
|
2002-11-03 18:03:52 +00:00
|
|
|
display_banner, /* say that we are here */
|
2006-01-29 18:12:41 +00:00
|
|
|
#if defined(CONFIG_DISPLAY_CPUINFO)
|
|
|
|
print_cpuinfo, /* display cpu info (and speed) */
|
|
|
|
#endif
|
|
|
|
#if defined(CONFIG_DISPLAY_BOARDINFO)
|
|
|
|
checkboard, /* display board info */
|
|
|
|
#endif
|
2002-11-03 00:24:07 +00:00
|
|
|
dram_init, /* configure available RAM banks */
|
|
|
|
display_dram_config,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
void start_armboot (void)
|
|
|
|
{
|
|
|
|
init_fnc_t **init_fnc_ptr;
|
2003-04-05 00:53:31 +00:00
|
|
|
char *s;
|
2006-03-11 21:53:33 +00:00
|
|
|
#ifndef CFG_NO_FLASH
|
|
|
|
ulong size;
|
|
|
|
#endif
|
2004-07-11 18:10:30 +00:00
|
|
|
#if defined(CONFIG_VFD) || defined(CONFIG_LCD)
|
2002-11-03 00:24:07 +00:00
|
|
|
unsigned long addr;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Pointer is writable since we allocated a register for it */
|
2003-12-06 19:49:23 +00:00
|
|
|
gd = (gd_t*)(_armboot_start - CFG_MALLOC_LEN - sizeof(gd_t));
|
2004-07-01 20:28:03 +00:00
|
|
|
/* compiler optimization barrier needed for GCC >= 3.4 */
|
|
|
|
__asm__ __volatile__("": : :"memory");
|
|
|
|
|
2003-12-06 19:49:23 +00:00
|
|
|
memset ((void*)gd, 0, sizeof (gd_t));
|
|
|
|
gd->bd = (bd_t*)((char*)gd - sizeof(bd_t));
|
2002-11-03 00:24:07 +00:00
|
|
|
memset (gd->bd, 0, sizeof (bd_t));
|
|
|
|
|
2004-02-08 19:38:38 +00:00
|
|
|
monitor_flash_len = _bss_start - _armboot_start;
|
2003-05-30 12:48:29 +00:00
|
|
|
|
2002-11-03 00:24:07 +00:00
|
|
|
for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
|
|
|
|
if ((*init_fnc_ptr)() != 0) {
|
|
|
|
hang ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-28 17:05:25 +00:00
|
|
|
#ifndef CFG_NO_FLASH
|
2002-11-03 00:24:07 +00:00
|
|
|
/* configure available FLASH banks */
|
|
|
|
size = flash_init ();
|
|
|
|
display_flash_config (size);
|
2006-02-28 17:05:25 +00:00
|
|
|
#endif /* CFG_NO_FLASH */
|
2002-11-03 00:24:07 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_VFD
|
2003-12-06 19:49:23 +00:00
|
|
|
# ifndef PAGE_SIZE
|
|
|
|
# define PAGE_SIZE 4096
|
|
|
|
# endif
|
2002-11-03 00:24:07 +00:00
|
|
|
/*
|
|
|
|
* reserve memory for VFD display (always full pages)
|
|
|
|
*/
|
2004-07-11 18:10:30 +00:00
|
|
|
/* bss_end is defined in the board-specific linker script */
|
|
|
|
addr = (_bss_end + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
|
2002-11-03 00:24:07 +00:00
|
|
|
size = vfd_setmem (addr);
|
|
|
|
gd->fb_base = addr;
|
|
|
|
#endif /* CONFIG_VFD */
|
|
|
|
|
2004-07-11 18:10:30 +00:00
|
|
|
#ifdef CONFIG_LCD
|
2004-08-01 22:48:16 +00:00
|
|
|
# ifndef PAGE_SIZE
|
|
|
|
# define PAGE_SIZE 4096
|
|
|
|
# endif
|
2004-07-11 18:10:30 +00:00
|
|
|
/*
|
|
|
|
* reserve memory for LCD display (always full pages)
|
|
|
|
*/
|
|
|
|
/* bss_end is defined in the board-specific linker script */
|
|
|
|
addr = (_bss_end + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
|
|
|
|
size = lcd_setmem (addr);
|
|
|
|
gd->fb_base = addr;
|
|
|
|
#endif /* CONFIG_LCD */
|
|
|
|
|
2003-12-06 19:49:23 +00:00
|
|
|
/* armboot_start is defined in the board-specific linker script */
|
|
|
|
mem_malloc_init (_armboot_start - CFG_MALLOC_LEN);
|
|
|
|
|
2003-03-26 06:55:25 +00:00
|
|
|
#if (CONFIG_COMMANDS & CFG_CMD_NAND)
|
2006-04-25 15:00:33 +00:00
|
|
|
puts ("NAND: ");
|
2003-03-26 06:55:25 +00:00
|
|
|
nand_init(); /* go init the NAND */
|
|
|
|
#endif
|
|
|
|
|
2003-06-16 23:50:08 +00:00
|
|
|
#ifdef CONFIG_HAS_DATAFLASH
|
|
|
|
AT91F_DataflashInit();
|
|
|
|
dataflash_print_info();
|
|
|
|
#endif
|
|
|
|
|
2003-02-28 00:49:47 +00:00
|
|
|
/* initialize environment */
|
|
|
|
env_relocate ();
|
|
|
|
|
2002-11-03 00:24:07 +00:00
|
|
|
#ifdef CONFIG_VFD
|
|
|
|
/* must do this after the framebuffer is allocated */
|
|
|
|
drv_vfd_init();
|
2003-12-06 19:49:23 +00:00
|
|
|
#endif /* CONFIG_VFD */
|
2002-11-03 00:24:07 +00:00
|
|
|
|
|
|
|
/* IP Address */
|
2003-12-06 19:49:23 +00:00
|
|
|
gd->bd->bi_ip_addr = getenv_IPaddr ("ipaddr");
|
2002-11-03 00:24:07 +00:00
|
|
|
|
|
|
|
/* MAC Address */
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
ulong reg;
|
|
|
|
char *s, *e;
|
2006-03-11 21:53:33 +00:00
|
|
|
char tmp[64];
|
2002-11-03 00:24:07 +00:00
|
|
|
|
|
|
|
i = getenv_r ("ethaddr", tmp, sizeof (tmp));
|
|
|
|
s = (i > 0) ? tmp : NULL;
|
|
|
|
|
|
|
|
for (reg = 0; reg < 6; ++reg) {
|
2003-12-06 19:49:23 +00:00
|
|
|
gd->bd->bi_enetaddr[reg] = s ? simple_strtoul (s, &e, 16) : 0;
|
2002-11-03 00:24:07 +00:00
|
|
|
if (s)
|
|
|
|
s = (*e) ? e + 1 : e;
|
|
|
|
}
|
2006-01-29 18:12:41 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_HAS_ETH1
|
|
|
|
i = getenv_r ("eth1addr", tmp, sizeof (tmp));
|
|
|
|
s = (i > 0) ? tmp : NULL;
|
|
|
|
|
|
|
|
for (reg = 0; reg < 6; ++reg) {
|
|
|
|
gd->bd->bi_enet1addr[reg] = s ? simple_strtoul (s, &e, 16) : 0;
|
|
|
|
if (s)
|
|
|
|
s = (*e) ? e + 1 : e;
|
|
|
|
}
|
|
|
|
#endif
|
2002-11-03 00:24:07 +00:00
|
|
|
}
|
|
|
|
|
2003-09-17 15:10:32 +00:00
|
|
|
devices_init (); /* get the devices list going. */
|
2003-06-22 17:18:28 +00:00
|
|
|
|
2005-08-18 22:53:02 +00:00
|
|
|
#ifdef CONFIG_CMC_PU2
|
|
|
|
load_sernum_ethaddr ();
|
|
|
|
#endif /* CONFIG_CMC_PU2 */
|
|
|
|
|
2003-07-24 23:38:38 +00:00
|
|
|
jumptable_init ();
|
2003-06-22 17:18:28 +00:00
|
|
|
|
|
|
|
console_init_r (); /* fully init console as a device */
|
|
|
|
|
2002-11-03 00:24:07 +00:00
|
|
|
#if defined(CONFIG_MISC_INIT_R)
|
|
|
|
/* miscellaneous platform dependent initialisations */
|
|
|
|
misc_init_r ();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* enable exceptions */
|
|
|
|
enable_interrupts ();
|
|
|
|
|
2003-12-06 19:49:23 +00:00
|
|
|
/* Perform network card initialisation if necessary */
|
2002-11-03 00:24:07 +00:00
|
|
|
#ifdef CONFIG_DRIVER_CS8900
|
2003-02-28 00:49:47 +00:00
|
|
|
cs8900_get_enetaddr (gd->bd->bi_enetaddr);
|
2002-11-03 00:24:07 +00:00
|
|
|
#endif
|
|
|
|
|
2004-06-09 13:37:52 +00:00
|
|
|
#if defined(CONFIG_DRIVER_SMC91111) || defined (CONFIG_DRIVER_LAN91C96)
|
2003-05-12 21:50:16 +00:00
|
|
|
if (getenv ("ethaddr")) {
|
|
|
|
smc_set_mac_addr(gd->bd->bi_enetaddr);
|
|
|
|
}
|
2004-06-09 13:37:52 +00:00
|
|
|
#endif /* CONFIG_DRIVER_SMC91111 || CONFIG_DRIVER_LAN91C96 */
|
2003-05-12 21:50:16 +00:00
|
|
|
|
2003-04-05 00:53:31 +00:00
|
|
|
/* Initialize from environment */
|
|
|
|
if ((s = getenv ("loadaddr")) != NULL) {
|
|
|
|
load_addr = simple_strtoul (s, NULL, 16);
|
|
|
|
}
|
|
|
|
#if (CONFIG_COMMANDS & CFG_CMD_NET)
|
|
|
|
if ((s = getenv ("bootfile")) != NULL) {
|
|
|
|
copy_filename (BootFile, s, sizeof (BootFile));
|
|
|
|
}
|
|
|
|
#endif /* CFG_CMD_NET */
|
|
|
|
|
2004-01-20 23:12:12 +00:00
|
|
|
#ifdef BOARD_LATE_INIT
|
|
|
|
board_late_init ();
|
2002-11-03 00:24:07 +00:00
|
|
|
#endif
|
2005-10-28 20:30:33 +00:00
|
|
|
#if (CONFIG_COMMANDS & CFG_CMD_NET)
|
|
|
|
#if defined(CONFIG_NET_MULTI)
|
2005-01-09 17:12:27 +00:00
|
|
|
puts ("Net: ");
|
2005-10-28 20:30:33 +00:00
|
|
|
#endif
|
2005-01-09 17:12:27 +00:00
|
|
|
eth_initialize(gd->bd);
|
|
|
|
#endif
|
2002-11-03 00:24:07 +00:00
|
|
|
/* main_loop() can return to retry autoboot, if so just run it again. */
|
|
|
|
for (;;) {
|
|
|
|
main_loop ();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* NOTREACHED - no way out of command loop except booting */
|
|
|
|
}
|
|
|
|
|
|
|
|
void hang (void)
|
|
|
|
{
|
|
|
|
puts ("### ERROR ### Please RESET the board ###\n");
|
|
|
|
for (;;);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_MODEM_SUPPORT
|
2006-03-11 22:07:09 +00:00
|
|
|
static inline void mdm_readline(char *buf, int bufsiz);
|
|
|
|
|
2002-11-03 00:24:07 +00:00
|
|
|
/* called from main loop (common/main.c) */
|
|
|
|
extern void dbg(const char *fmt, ...);
|
|
|
|
int mdm_init (void)
|
|
|
|
{
|
|
|
|
char env_str[16];
|
|
|
|
char *init_str;
|
|
|
|
int i;
|
|
|
|
extern char console_buffer[];
|
|
|
|
extern void enable_putc(void);
|
|
|
|
extern int hwflow_onoff(int);
|
|
|
|
|
|
|
|
enable_putc(); /* enable serial_putc() */
|
|
|
|
|
|
|
|
#ifdef CONFIG_HWFLOW
|
|
|
|
init_str = getenv("mdm_flow_control");
|
|
|
|
if (init_str && (strcmp(init_str, "rts/cts") == 0))
|
|
|
|
hwflow_onoff (1);
|
|
|
|
else
|
|
|
|
hwflow_onoff(-1);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
for (i = 1;;i++) {
|
|
|
|
sprintf(env_str, "mdm_init%d", i);
|
|
|
|
if ((init_str = getenv(env_str)) != NULL) {
|
|
|
|
serial_puts(init_str);
|
|
|
|
serial_puts("\n");
|
|
|
|
for(;;) {
|
|
|
|
mdm_readline(console_buffer, CFG_CBSIZE);
|
|
|
|
dbg("ini%d: [%s]", i, console_buffer);
|
|
|
|
|
|
|
|
if ((strcmp(console_buffer, "OK") == 0) ||
|
|
|
|
(strcmp(console_buffer, "ERROR") == 0)) {
|
|
|
|
dbg("ini%d: cmd done", i);
|
|
|
|
break;
|
|
|
|
} else /* in case we are originating call ... */
|
|
|
|
if (strncmp(console_buffer, "CONNECT", 7) == 0) {
|
|
|
|
dbg("ini%d: connect", i);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
break; /* no init string - stop modem init */
|
|
|
|
|
|
|
|
udelay(100000);
|
|
|
|
}
|
|
|
|
|
|
|
|
udelay(100000);
|
|
|
|
|
|
|
|
/* final stage - wait for connect */
|
|
|
|
for(;i > 1;) { /* if 'i' > 1 - wait for connection
|
|
|
|
message from modem */
|
|
|
|
mdm_readline(console_buffer, CFG_CBSIZE);
|
|
|
|
dbg("ini_f: [%s]", console_buffer);
|
|
|
|
if (strncmp(console_buffer, "CONNECT", 7) == 0) {
|
|
|
|
dbg("ini_f: connected");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 'inline' - We have to do it fast */
|
|
|
|
static inline void mdm_readline(char *buf, int bufsiz)
|
|
|
|
{
|
|
|
|
char c;
|
|
|
|
char *p;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
n = 0;
|
|
|
|
p = buf;
|
|
|
|
for(;;) {
|
|
|
|
c = serial_getc();
|
|
|
|
|
|
|
|
/* dbg("(%c)", c); */
|
|
|
|
|
|
|
|
switch(c) {
|
|
|
|
case '\r':
|
|
|
|
break;
|
|
|
|
case '\n':
|
|
|
|
*p = '\0';
|
|
|
|
return;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if(n++ > bufsiz) {
|
|
|
|
*p = '\0';
|
|
|
|
return; /* sanity check */
|
|
|
|
}
|
|
|
|
*p = c;
|
|
|
|
p++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_MODEM_SUPPORT */
|