📄 main.c
字号:
prompt = false;
}
res = gets(line, sizeof(line), CYGNUM_REDBOOT_CLI_IDLE_TIMEOUT);
if (res == _GETS_TIMEOUT) {
// No input arrived
} else {
#ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
if (res == _GETS_GDB) {
int dbgchan;
hal_virtual_comm_table_t *__chan;
int i;
// Special case of '$' - need to start GDB protocol
gdb_active = true;
// Mask interrupts on all channels
for (i = 0; i < CYGNUM_HAL_VIRTUAL_VECTOR_NUM_CHANNELS; i++) {
CYGACC_CALL_IF_SET_CONSOLE_COMM(i);
__chan = CYGACC_CALL_IF_CONSOLE_PROCS();
CYGACC_COMM_IF_CONTROL( *__chan, __COMMCTL_IRQ_DISABLE );
}
CYGACC_CALL_IF_SET_CONSOLE_COMM(cur);
#ifdef HAL_ARCH_PROGRAM_NEW_STACK
HAL_ARCH_PROGRAM_NEW_STACK(breakpoint);
#else
breakpoint(); // Get GDB stubs started, with a proper environment, etc.
#endif
dbgchan = CYGACC_CALL_IF_SET_DEBUG_COMM(CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT);
CYGACC_CALL_IF_SET_CONSOLE_COMM(dbgchan);
} else
#endif // CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
{
#ifdef CYGSEM_REDBOOT_FLASH_ALIASES
expand_aliases(line, sizeof(line));
#endif
if (strlen(line) > 0) {
if ((cmd = parse(line, &argc, &argv[0])) != (struct cmd *)0) {
(cmd->fun)(argc, argv);
} else {
printf("** Error: Illegal command: \"%s\"\n", argv[0]);
}
}
prompt = true;
}
}
}
}
void
do_caches(int argc, char *argv[])
{
unsigned long oldints;
int dcache_on=0, icache_on=0;
#ifdef HAL_DCACHE_IS_ENABLED
HAL_DCACHE_IS_ENABLED(dcache_on);
#endif
#ifdef HAL_ICACHE_IS_ENABLED
HAL_ICACHE_IS_ENABLED(icache_on);
#endif
if (argc == 2) {
if (strcmpci(argv[1], "on") == 0) {
if((!dcache_on) || (!icache_on))
{
HAL_DISABLE_INTERRUPTS(oldints);
HAL_ICACHE_ENABLE();
HAL_DCACHE_ENABLE();
HAL_RESTORE_INTERRUPTS(oldints);
}
else
{
printf("Cache is already on\n");
}
} else if (strcmpci(argv[1], "off") == 0) {
if(dcache_on || icache_on)
{
HAL_DISABLE_INTERRUPTS(oldints);
HAL_DCACHE_SYNC();
HAL_ICACHE_DISABLE();
HAL_DCACHE_DISABLE();
HAL_DCACHE_SYNC();
HAL_ICACHE_INVALIDATE_ALL();
HAL_DCACHE_INVALIDATE_ALL();
HAL_RESTORE_INTERRUPTS(oldints);
}
else
{
printf("Cache is already off\n");
}
} else {
printf("Invalid cache mode: %s\n", argv[1]);
}
} else {
printf("Data cache: %s, Instruction cache: %s\n", dcache_on?"On":"Off", icache_on?"On":"Off");
}
}
void
do_help(int argc, char *argv[])
{
struct cmd *cmd;
char *which = (char *)0;
bool show;
int len = 0;
if (!scan_opts(argc, argv, 1, 0, 0, (void **)&which, OPTION_ARG_TYPE_STR, "<topic>")) {
printf("Invalid argument\n");
return;
}
if (which) {
len = strlen(which);
}
cmd = __RedBoot_CMD_TAB__;
while (cmd != &__RedBoot_CMD_TAB_END__) {
show = true;
if (which && (strncmpci(which, cmd->str, len) != 0)) {
show = false;
}
if (show) {
printf("%s\n %s %s\n", cmd->help, cmd->str, cmd->usage);
}
cmd++;
}
return;
}
void
do_dump(int argc, char *argv[])
{
struct option_info opts[2];
unsigned long base, len;
bool base_set, len_set;
static unsigned long _base, _len;
init_opts(&opts[0], 'b', true, OPTION_ARG_TYPE_NUM,
(void **)&base, (bool *)&base_set, "base address");
init_opts(&opts[1], 'l', true, OPTION_ARG_TYPE_NUM,
(void **)&len, (bool *)&len_set, "length");
if (!scan_opts(argc, argv, 1, opts, 2, 0, 0, "")) {
return;
}
if (!base_set) {
if (_base == 0) {
printf("Dump what [location]?\n");
return;
}
base = _base;
if (!len_set) {
len = _len;
len_set = true;
}
}
if (!len_set) {
len = 32;
}
dump_buf((void *)base, len);
_base = base + len;
_len = len;
}
void
do_cksum(int argc, char *argv[])
{
// Compute a CRC, using the POSIX 1003 definition
extern unsigned long
posix_crc32(unsigned char *s, int len);
struct option_info opts[2];
unsigned long base, len, crc;
bool base_set, len_set;
init_opts(&opts[0], 'b', true, OPTION_ARG_TYPE_NUM,
(void **)&base, (bool *)&base_set, "base address");
init_opts(&opts[1], 'l', true, OPTION_ARG_TYPE_NUM,
(void **)&len, (bool *)&len_set, "length");
if (!scan_opts(argc, argv, 1, opts, 2, 0, 0, "")) {
return;
}
if (!base_set || !len_set) {
printf("usage: cksum -b <addr> -l <length>\n");
return;
}
crc = posix_crc32((unsigned char *)base, len);
printf("POSIX cksum = 0x%08lx (%lu)\n", crc, crc);
}
void
do_go(int argc, char *argv[])
{
typedef void code_fun(void);
unsigned long entry;
unsigned long oldints;
code_fun *fun;
bool wait_time_set;
int wait_time, res;
struct option_info opts[1];
char line[8];
#ifdef RESET_NIC
cyg_netdevtab_entry_t *t;
#endif
entry = (unsigned long)entry_address; // Default from last 'load' operation
init_opts(&opts[0], 'w', true, OPTION_ARG_TYPE_NUM,
(void **)&wait_time, (bool *)&wait_time_set, "wait timeout");
if (!scan_opts(argc, argv, 1, opts, 1, (void *)&entry, OPTION_ARG_TYPE_NUM, "starting address"))
{
return;
}
if (wait_time_set) {
int script_timeout_ms = wait_time * 1000;
#ifdef CYGSEM_REDBOOT_FLASH_CONFIG
unsigned char *hold_script = script;
script = (unsigned char *)0;
#endif
printf("About to start execution at %p - abort with ^C within %d seconds\n",
(void *)entry, wait_time);
while (script_timeout_ms >= CYGNUM_REDBOOT_CLI_IDLE_TIMEOUT) {
res = gets(line, sizeof(line), CYGNUM_REDBOOT_CLI_IDLE_TIMEOUT);
if (res == _GETS_CTRLC) {
#ifdef CYGSEM_REDBOOT_FLASH_CONFIG
script = hold_script; // Re-enable script
#endif
return;
}
script_timeout_ms -= CYGNUM_REDBOOT_CLI_IDLE_TIMEOUT;
}
}
#ifdef RESET_NIC
// bring down all network devices
for (t = &__NETDEVTAB__[0]; t != &__NETDEVTAB_END__; t++) {
struct eth_drv_sc *sc = (struct eth_drv_sc *)t->device_instance;
(sc->funs->stop)(sc);
}
#endif
fun = (code_fun *)entry;
HAL_DISABLE_INTERRUPTS(oldints);
HAL_DCACHE_SYNC();
HAL_ICACHE_DISABLE();
HAL_DCACHE_DISABLE();
HAL_DCACHE_SYNC();
HAL_ICACHE_INVALIDATE_ALL();
HAL_DCACHE_INVALIDATE_ALL();
// save the entry point in mailbox register so that program can find out its starting address
*(MAILBOX_1_REG) = (unsigned int)flash_entry_address;
*(MAILBOX_2_REG) = entry;
// set slow port back to 32 bit mode
*(SP_FRM_REG) = USE_32_BIT_DATA;
#ifdef HAL_ARCH_PROGRAM_NEW_STACK
HAL_ARCH_PROGRAM_NEW_STACK(fun);
#else
(*fun)();
#endif
}
#ifdef HAL_PLATFORM_RESET
void
do_reset(int argc, char *argv[])
{
if(strap_options_val() & CFG_PCI_BOOT_HOST)
{
printf("... Resetting.");
CYGACC_CALL_IF_DELAY_US(2*100000);
printf("\n");
CYGACC_CALL_IF_RESET();
printf("!! oops, RESET not working on this platform\n");
}
else
{
printf("Only master can reset the system\n");
}
}
#endif
#ifdef CYGSEM_REDBOOT_VARIABLE_BAUD_RATE
#ifdef CYGSEM_REDBOOT_FLASH_CONFIG
#include <flash_config.h>
#endif
void
set_console_baud_rate(int rate)
{
hal_virtual_comm_table_t *__chan;
int ret;
static int current_rate = CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL_BAUD;
if (rate != current_rate) {
__chan = CYGACC_CALL_IF_CONSOLE_PROCS();
ret = CYGACC_COMM_IF_CONTROL(*__chan, __COMMCTL_SETBAUD, rate);
if (ret <= 0) {
printf("Failed\n");
}
current_rate = rate;
}
}
void
do_baud_rate(int argc, char *argv[])
{
int new_rate, ret;
bool new_rate_set;
hal_virtual_comm_table_t *__chan;
struct option_info opts[1];
#ifdef CYGSEM_REDBOOT_FLASH_CONFIG
struct config_option opt;
#endif
init_opts(&opts[0], 'b', true, OPTION_ARG_TYPE_NUM,
(void **)&new_rate, (bool *)&new_rate_set, "new baud rate");
if (!scan_opts(argc, argv, 1, opts, 1, 0, 0, "")) {
return;
}
__chan = CYGACC_CALL_IF_CONSOLE_PROCS();
if (new_rate_set) {
#ifdef CYGSEM_REDBOOT_FLASH_CONFIG
opt.type = CONFIG_INT;
opt.enable = (char *)0;
opt.enable_sense = 1;
opt.key = "console_baud_rate";
opt.dflt = new_rate;
flash_add_config(&opt, true);
#endif
set_console_baud_rate(new_rate);
} else {
ret = CYGACC_COMM_IF_CONTROL(*__chan, __COMMCTL_GETBAUD);
printf("Baud rate = ");
if (ret <= 0) {
printf("unknown\n");
} else {
printf("%d\n", ret);
}
}
}
#endif
//
// [Null] Builtin [Power On] Self Test
//
void bist(void) CYGBLD_ATTRIB_WEAK;
void
bist(void)
{
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -