⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 基于ecos的redboot
💻 C
📖 第 1 页 / 共 2 页
字号:
//==========================================================================
//
//      main.c
//
//      RedBoot main routine
//
//==========================================================================
//####COPYRIGHTBEGIN####
//                                                                          
// -------------------------------------------                              
// The contents of this file are subject to the Red Hat eCos Public License 
// Version 1.1 (the "License"); you may not use this file except in         
// compliance with the License.  You may obtain a copy of the License at    
// http://www.redhat.com/                                                   
//                                                                          
// Software distributed under the License is distributed on an "AS IS"      
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See the 
// License for the specific language governing rights and limitations under 
// the License.                                                             
//                                                                          
// The Original Code is eCos - Embedded Configurable Operating System,      
// released September 30, 1998.                                             
//                                                                          
// The Initial Developer of the Original Code is Red Hat.                   
// Portions created by Red Hat are                                          
// Copyright (C) 1998, 1999, 2000, 2001 Red Hat, Inc.                             
// All Rights Reserved.                                                     
// -------------------------------------------                              
//                                                                          
//####COPYRIGHTEND####
//==========================================================================
//#####DESCRIPTIONBEGIN####
//
// Author(s):    gthomas
// Contributors: gthomas
// Date:         2000-07-14
// Purpose:      
// Description:  
//              
// This code is part of RedBoot (tm).
//
//####DESCRIPTIONEND####
//
//==========================================================================

#define  DEFINE_VARS
#include <redboot.h>
#include <cyg/hal/hal_arch.h>
#include <cyg/hal/hal_intr.h>
#include <cyg/hal/hal_if.h>
#include <cyg/hal/hal_cache.h>
#include <cyg/io/i2c.h>
#include <cyg/hal/cfg_utility.h>
#include CYGHWR_MEMORY_LAYOUT_H

#include <cyg/hal/hal_tables.h>

#ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
#ifdef CYGBLD_HAL_PLATFORM_STUB_H
#include CYGBLD_HAL_PLATFORM_STUB_H
#else
#include <cyg/hal/plf_stub.h>
#endif
#endif
#include <netdev.h>
#include <eth_drv.h>

// Builtin Self Test (BIST)
externC void bist(void);
externC cyg_uint32 cpld_rev;
externC int qdr_ch_sz_array[MAX_QDR_CHANNEL];

#ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
// GDB interfaces
extern void breakpoint(void);
#endif

// CLI command processing (defined in this file)
RedBoot_cmd("version", 
            "Display RedBoot version information",
            "",
            do_version
    );
RedBoot_cmd("help", 
            "Help about help?", 
            "[<topic>]",
            do_help 
    );
RedBoot_cmd("go", 
            "Execute code at a location", 
            "[-w <timeout>] [entry]",
            do_go 
    );
RedBoot_cmd("dump", 
            "Display (hex dump) a range of memory", 
            "-b <location> [-l <length>]",
            do_dump 
    );
RedBoot_cmd("cksum", 
            "Compute a 32bit checksum [POSIX algorithm] for a range of memory", 
            "-b <location> -l <length>",
            do_cksum
    );
RedBoot_cmd("cache", 
            "Manage machine caches", 
            "[ON | OFF]",
            do_caches 
    );
#ifdef HAL_PLATFORM_RESET
RedBoot_cmd("reset", 
            "Reset the system", 
            "",
            do_reset 
    );
#endif
#ifdef CYGSEM_REDBOOT_VARIABLE_BAUD_RATE
RedBoot_cmd("baudrate", 
            "Set/Query the system console baud rate", 
            "[-b <rate>]",
            do_baud_rate
    );
#endif

// Define table boundaries
CYG_HAL_TABLE_BEGIN( __RedBoot_INIT_TAB__, RedBoot_inits );
CYG_HAL_TABLE_END( __RedBoot_INIT_TAB_END__, RedBoot_inits );
extern struct init_tab_entry __RedBoot_INIT_TAB__[], __RedBoot_INIT_TAB_END__;

CYG_HAL_TABLE_BEGIN( __RedBoot_CMD_TAB__, RedBoot_commands );
CYG_HAL_TABLE_END( __RedBoot_CMD_TAB_END__, RedBoot_commands );
extern struct cmd __RedBoot_CMD_TAB__[], __RedBoot_CMD_TAB_END__;

CYG_HAL_TABLE_BEGIN( __RedBoot_IDLE_TAB__, RedBoot_idle );
CYG_HAL_TABLE_END( __RedBoot_IDLE_TAB_END__, RedBoot_idle );
extern struct idle_tab_entry __RedBoot_IDLE_TAB__[], __RedBoot_IDLE_TAB_END__;

#ifdef HAL_ARCH_PROGRAM_NEW_STACK
extern void HAL_ARCH_PROGRAM_NEW_STACK(void *fun);
#endif

#ifdef CYGSEM_REDBOOT_FLASH_ALIASES
externC void expand_aliases(char *line, int len);
#endif

void
do_version(int argc, char *argv[])
{
    extern char RedBoot_version[];
	int i;

#ifdef CYGPKG_IO_FLASH
    externC void _flash_info(void);
#endif

    printf(RedBoot_version);
#ifdef HAL_PLATFORM_CPU
    printf("Platform: %s (%s) %s\n", HAL_PLATFORM_BOARD, HAL_PLATFORM_CPU, HAL_PLATFORM_EXTRA);
#endif
    printf("Copyright (C) 2000, 2001, Red Hat, Inc.\n\n");
    printf("SDRAM(%dM): %p - %p, %p - %p available\n", (hal_dram_size / (1024 * 1024)),
           (void*)ram_start, (void*)ram_end,
           (void*)user_ram_start, (void *)user_ram_end);
	for(i = 0; i < MAX_QDR_CHANNEL; i++)
	{
		if(qdr_ch_sz_array[i])
		{
			printf("SRAM Channel %d(%dM): %p - %p\n", i, (qdr_ch_sz_array[i] / (1024 * 1024)),
				(void *)(SRAM_BASE + (i * 0x10000000)), (void *)(SRAM_BASE + (i * 0x10000000) + qdr_ch_sz_array[i]));
		}
		else
		{
			printf("No SRAM found on channel %d\n", i);
		}
	}
#ifdef CYGPKG_IO_FLASH
    _flash_info();
#endif
	printf("CPLD Rev. is %d.%d\n", ((cpld_rev & 0xF0) >> 4), (cpld_rev & 0xF));
}

void
do_idle(bool is_idle)
{
    struct idle_tab_entry *idle_entry;

    for (idle_entry = __RedBoot_IDLE_TAB__; 
         idle_entry != &__RedBoot_IDLE_TAB_END__;  idle_entry++) {
        (*idle_entry->fun)(is_idle);
    }
}

//
// This is the main entry point for RedBoot
//
void
cyg_start(void)
{
    int res = 0;
    bool prompt = true;
    static char line[CYGPKG_REDBOOT_MAX_CMD_LINE];
    struct cmd *cmd;
    int cur;
    struct init_tab_entry *init_entry;

    // Make sure the channels are properly initialized.
    hal_if_diag_init();

    // Force console to output raw text - but remember the old setting
    // so it can be restored if interaction with a debugger is
    // required.
    cur = CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT);
    CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_HAL_VIRTUAL_VECTOR_DEBUG_CHANNEL);
#ifdef CYGPKG_REDBOOT_ANY_CONSOLE
    console_selected = false;
#endif
    console_echo = true;
    CYGACC_CALL_IF_DELAY_US((cyg_int32)2*100000);

    ram_start = (unsigned char *)CYGMEM_REGION_ram;
    ram_end = (unsigned char *)(CYGMEM_REGION_ram+CYGMEM_REGION_ram_SIZE);
#ifdef HAL_MEM_REAL_REGION_TOP
    {
        unsigned char *ram_end_tmp = ram_end;
        ram_end = HAL_MEM_REAL_REGION_TOP( ram_end_tmp );
    }
#endif
#ifdef CYGMEM_SECTION_heap1
    workspace_start = (unsigned char *)CYGMEM_SECTION_heap1;
    workspace_end = (unsigned char *)ram_end;
    workspace_size = workspace_end - workspace_start;
#else
    workspace_start = (unsigned char *)CYGMEM_REGION_ram;
    workspace_end = (unsigned char *)(CYGMEM_REGION_ram+CYGMEM_REGION_ram_SIZE);
    workspace_size = CYGMEM_REGION_ram_SIZE;
#endif

    if ( ram_end < workspace_end ) {
        // when *less* SDRAM is installed than the possible maximum,
        // but the heap1 region remains greater...
        workspace_end = ram_end;
        workspace_size = workspace_end - workspace_start;
    }

    bist();

    for (init_entry = __RedBoot_INIT_TAB__; init_entry != &__RedBoot_INIT_TAB_END__;  init_entry++) {
        (*init_entry->fun)();
    }

#ifdef CYGPKG_COMPRESS_ZLIB
#define ZLIB_COMPRESSION_OVERHEAD 0xB800
#else
#define ZLIB_COMPRESSION_OVERHEAD 0
#endif
    user_ram_start = workspace_start + ZLIB_COMPRESSION_OVERHEAD;
    user_ram_end = workspace_end;
    do_version(0,0);

	display_led(DISPLAY_NULL, 'I', '2', 'C');

	{
		int i;
		char dev_id;
		unsigned char slave_addr[] = {0xA2, 0xA4, 0xA6, 0xA8};

		for(i = 0; i < 4; i++)
		{
			if(i2c_read(slave_addr[i], DEV_ID_ADDR, &dev_id))
                continue;

			switch(dev_id)
			{
			case KI_DEV_ID:
				printf("Found IXMB2400 (device id = 0x%02x) at device address = 0x%02x\n", dev_id, slave_addr[i]);
				break;
			case BI_DEV_ID:
				printf("Found IXSF2400 (device id = 0x%02x) at device address = 0x%02x\n", dev_id, slave_addr[i]);
				break;
			case MI_DEV_ID:
				printf("Found IXQDR2408 (device id = 0x%02x) at device address = 0x%02x\n", dev_id, slave_addr[i]);
				break;
			case BD_DEV_ID:
				printf("Found IXD2448 (device id = 0x%02x) at device address = 0x%02x\n", dev_id, slave_addr[i]);
				break;
			case BW_DEV_ID:
				printf("Found IXD2412 (device id = 0x%02x) at device address = 0x%02x\n", dev_id, slave_addr[i]);
				break;
			case PL_DEV_ID:
				printf("Found IXD2410 (device id = 0x%02x) at device address = 0x%02x\n", dev_id, slave_addr[i]);
				break;
			case TC_DEV_ID:
				printf("Found TCAM module (device id = 0x%02x) at device address = 0x%02x\n", dev_id, slave_addr[i]);
				break;
			default:
				printf("Unrecognized card (device id = 0x%02x) at device address = 0x%02x\n", dev_id, slave_addr[i]);
				break;
			}
		}
	}
	// display system good on system LED.
	*(SYSTEM_LED_REG) = 0x0;
	display_led('I', 'X', 'D', 'P');

#ifdef CYGFUN_REDBOOT_BOOT_SCRIPT
# ifdef CYGDAT_REDBOOT_DEFAULT_BOOT_SCRIPT
    if (!script) {
      script = CYGDAT_REDBOOT_DEFAULT_BOOT_SCRIPT;
#  ifndef CYGSEM_REDBOOT_FLASH_CONFIG
      script_timeout = CYGNUM_REDBOOT_BOOT_SCRIPT_DEFAULT_TIMEOUT;
#  endif
    }
# endif
    if (script) {
        // Give the guy a chance to abort any boot script
        unsigned char *hold_script = script;
        int script_timeout_ms = script_timeout * CYGNUM_REDBOOT_BOOT_SCRIPT_TIMEOUT_RESOLUTION;
        printf("== Executing boot script in %d.%03d seconds - enter ^C to abort\n", 
               script_timeout_ms/1000, script_timeout_ms%1000);
        script = (unsigned char *)0;
        res = _GETS_CTRLC;  // Treat 0 timeout as ^C
        while (script_timeout_ms >= CYGNUM_REDBOOT_CLI_IDLE_TIMEOUT) {
            res = gets(line, sizeof(line), CYGNUM_REDBOOT_CLI_IDLE_TIMEOUT);
            if (res >= _GETS_OK) {
                printf("== Executing boot script in %d.%03d seconds - enter ^C to abort\n", 
                       script_timeout_ms/1000, script_timeout_ms%1000);
                continue;  // Ignore anything but ^C
            }
            if (res != _GETS_TIMEOUT) break;
            script_timeout_ms -= CYGNUM_REDBOOT_CLI_IDLE_TIMEOUT;
        }
        if (res == _GETS_CTRLC) {
            script = (unsigned char *)0;  // Disable script
        } else {
            script = hold_script;  // Re-enable script
        }
    }
#endif

    while (true) {
        if (prompt) {
			if(strap_options_val() & CFG_PCI_BOOT_HOST)
			{
				printf("Master-RedBoot> ");
			}
			else
			{
				printf("Slave-RedBoot> ");
			}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -