📄 parser.c
字号:
{ itc_printf("\r\n"); error_print(TFTP_TIMEOUT_ERROR); return 0; } break; } default: { error_print(PARSE_DL_METHOD_ERROR); return 0; } }#ifdef SHOW_DOWNLOAD_CRC itc_printf("CRC-32 of %d bytes is 0x%x\r\n", len, update_crc(INITIAL_CRC32, dest, len));#endif return 1;}////////////////////////////////////////////////////////////////////////////////// flash_parse// PURPOSE: Parses a flash command and writes to flash accordingly.// PARAMS: (IN) char *arg - argument(s) to the flash command.// RETURNS: 1 for success, 0 for failure.// NOTES: This function may not flash the boot block.////////////////////////////////////////////////////////////////////////////////intflash_parse(char const *arg){ u32 *dest = (u32 *)(flash_block_size_platform()); u32 *src = 0; int buflen = 0; if(get_number_parse(arg, (u32 *)&dest)) arg = next_token(arg); else { error_print(PARSE_INVALID_ARG_ERROR); return 0; } if(get_number_parse(arg, (u32 *)&src)) arg = next_token(arg); else { error_print(PARSE_INVALID_ARG_ERROR); return 0; } if(!get_number_parse(arg, (u32 *)&buflen)) { error_print(PARSE_INVALID_ARG_ERROR); return 0; } if((u32)dest % sizeof(u32)) { error_print(PARSE_ALIGN_ERROR); return 0; } if((u32)src % sizeof(u32)) { error_print(PARSE_ALIGN_ERROR); return 0; } if((u32)src < PLATFORM_MEMORY_BASE || (u32)src >= PLATFORM_MEMORY_MAX || (u32)dest < PLATFORM_FLASH_BASE || (u32)dest >= (PLATFORM_FLASH_BASE + PLATFORM_FLASH_SIZE) || ((u32)dest + buflen) > (PLATFORM_FLASH_BASE + PLATFORM_FLASH_SIZE)) { error_print(PARSE_RANGE_ERROR); return 0; } itc_printf("Flashing: "); return block_write_flash(dest, src, buflen, FLASH_DEFAULT);}////////////////////////////////////////////////////////////////////////////////// flashverify_parse// PURPOSE: Parses a flash command and writes to flash accordingly, with a// verify after.// PARAMS: (IN) char *arg - argument(s) to the flash command.// RETURNS: 1 for success, 0 for failure.// NOTES: This function may not flash the boot block.////////////////////////////////////////////////////////////////////////////////intflashverify_parse(char const *arg){ int retval; retval = flash_parse(arg); if(retval) { u32 *dest; u32 *src; u32 length; arg = get_number_parse(arg, (u32 *)&dest); arg = get_number_parse(arg, (u32 *)&src); arg = get_number_parse(arg, &length); if(cmp32(dest, src, (int)length / sizeof(u32))) { return 1; } else { error_print(FLASH_VERIFY_ERROR); return 0; } } return 0;} ////////////////////////////////////////////////////////////////////////////////// flashloader_parse// PURPOSE: Parses a flash command and writes to flash accordingly.// PARAMS: (IN) char *arg - argument(s) to the flash command.// RETURNS: 1 for success, 0 for failure.// NOTES: This function may flash the boot block.////////////////////////////////////////////////////////////////////////////////intflashloader_parse(char const *arg){ u32 *dest = (u32 *)(flash_block_size_platform()); u32 *src = 0; int buflen = 0; if(get_number_parse(arg, (u32 *)&dest)) arg = next_token(arg); else { error_print(PARSE_INVALID_ARG_ERROR); return 0; } if(get_number_parse(arg, (u32 *)&src)) arg = next_token(arg); else { error_print(PARSE_INVALID_ARG_ERROR); return 0; } if(!get_number_parse(arg, (u32 *)&buflen)) { error_print(PARSE_INVALID_ARG_ERROR); return 0; } if((u32)dest % sizeof(u32)) { error_print(PARSE_ALIGN_ERROR); return 0; } if((u32)src % sizeof(u32)) { error_print(PARSE_ALIGN_ERROR); return 0; } if((u32)src < PLATFORM_MEMORY_BASE || (u32)src >= PLATFORM_MEMORY_MAX || (u32)dest < PLATFORM_FLASH_BASE || (u32)dest >= (PLATFORM_FLASH_BASE + PLATFORM_FLASH_SIZE) || ((u32)dest + buflen) > PLATFORM_FLASH_SIZE) { error_print(PARSE_RANGE_ERROR); return 0; } itc_printf("Flashing: "); return block_write_flash(dest, src, buflen, FLASH_BOOT);}////////////////////////////////////////////////////////////////////////////////// kernel_param_parse// PURPOSE: Fixes a quote-mangled kernel parameter string.// PARAMS: (IN) char *mangled - Mangled string to fix.// (OUT) char *buf - buffer to write fixed string into// (IN) int bufsize - length of buffer// RETURNS: Number of characters in fixed string, or -1 for error.////////////////////////////////////////////////////////////////////////////////intkernel_param_parse(char const *mangled, char *buf, int bufsize){ int retval = 0; if (*mangled) { /* allow missing parameter string */ if(*mangled++ != '\"') { error_print(PARSE_KERN_PARAM_ERROR); return -1; } while(*mangled != 0 && *mangled != '\"' && retval < (bufsize-1)) { if(*mangled == '\\' && *(mangled + 1) == '\"') mangled++; *buf++ = *mangled++; retval++; } if(*mangled != '\"') { error_print(PARSE_KERN_PARAM_ERROR); return -1; } } *buf = 0; return retval;}////////////////////////////////////////////////////////////////////////////////// bootmem_parse// PURPOSE: Parses a bootmem command and boots from the appropriate area in// memory. Handles any OS specific things (such as CE BIN parsing)// aswell.// PARAMS: char *arg - argument string.// RETURNS: 1 for success, 0 for failure.////////////////////////////////////////////////////////////////////////////////intbootmem_parse(char const *arg){ enum { unknown, linux_kernel, ce } os; u32 addr; if(cmpstr(arg, "linux")) { os = linux_kernel; } else if(cmpstr(arg, "ce")) { os = ce; } else { os = unknown; } arg = next_token(arg); if(!get_number_parse(arg, &addr)) { error_print(PARSE_INVALID_ARG_ERROR); return 0; } arg = next_token(arg); switch(os) { case linux_kernel: { boot_linux_kernel( arg, (u8 *)addr); break; } case ce: { void (*kernel)(void); message_print(RAM_CLEAR_MESSAGE); memset32((u32 *)CE_CLEAR_BASE, 0, CE_CLEAR_SIZE / sizeof(u32)); message_print(LOADING_CE_MESSAGE); kernel = (void (*)(void))cedecode((u8 *)CE_RAM_BASE, (u8 *)addr); if((u32 *)kernel != NULL) kernel(); break; } default: { error_print(PARSE_INVALID_OS_ERROR); } } return 0;}////////////////////////////////////////////////////////////////////////////////// jump_parse// PURPOSE: Jumps to a location in memory.// PARAMS: char *arg - argument string.// RETURNS: 1 for success, 0 for failure.////////////////////////////////////////////////////////////////////////////////intjump_parse(char const *arg){ u32 addr; u32 args[4]; int rc,i; int (*func)(u32 a, u32 b, u32 c, u32 d); if(!get_number_parse(arg, &addr)) { error_print(PARSE_INVALID_ARG_ERROR); return 0; } arg = next_token(arg); for (i=0; i < countof(args); ++i) { if (*arg) { if(!get_number_parse(arg, &args[i])) { error_print(PARSE_INVALID_ARG_ERROR); return 0; } arg = next_token(arg); } else { args[i] = 0; } } if (*arg) { itc_printf("Too many arguments.\r\n"); return 0; } func = (int (*)(u32 a, u32 b, u32 c, u32 d)) addr; rc = func(args[0], args[1], args[2], args[3]); itc_printf("Program returned %d.\r\n", rc); return rc;}////////////////////////////////////////////////////////////////////////////////// boot_parse// PURPOSE: Boots the default partition.// PARAMS: (IN) char *arg - kernel config string.// RETURNS: Never returns on success, 0 for failure.////////////////////////////////////////////////////////////////////////////////intboot_parse(char const *arg){ run_os(arg); // src/libs/base/os.c return 0;}////////////////////////////////////////////////////////////////////////////////// decode_parse// PURPOSE: Parses a decode command and decodes into memory appropriately. Only// CE needs this at the moment.// PARAMS: (IN) char *arg - argument(s) to the decode command. (None)// NOTES: This is obsolete, and should be removed.// RETURNS: CE kernel address for success, 0 for failure.////////////////////////////////////////////////////////////////////////////////intdecode_parse(char const *arg){ message_print(LOADING_CE_MESSAGE); status.CEKernel = cedecode((u8 *)CE_RAM_BASE, (u8 *)CE_TEMP_RAM); status.os = CE; return (int)status.CEKernel;}////////////////////////////////////////////////////////////////////////////////// info_parse// PURPOSE: Parses an info command and prints the info table.// PARAMS: (IN) char *arg - argument(s) to the status command. Unused for the// moment.// RETURNS: 1 for success, 0 for failure.////////////////////////////////////////////////////////////////////////////////intinfo_parse(char const *arg){ char temp[5]; unsigned short mac[3]; itc_printf("IBoot version " VERSION "\r\n"); itc_printf("%s\r\n", copyright); itc_printf("Built on " __DATE__ " at " __TIME__ "\r\n"); itc_printf("Current IP: %s\r\n", iptoa(status.ciaddr)); itc_printf("Current Server IP: %s\r\n", iptoa(status.siaddr)); itc_printf("Current Gateway: %s\r\n", iptoa(status.giaddr)); itc_printf("Current Subnet Mask: %s\r\n", iptoa(status.smask));/* itc_printf("MAC Address in use: "); u16toa(htons(status.macaddr[0]), temp); itc_printf(temp); u16toa(htons(status.macaddr[1]), temp); itc_printf(temp); u16toa(htons(status.macaddr[2]), temp); itc_printf(temp); itc_printf("\r\n");*/ if (read_mac_ethernet (mac, 0)) { itc_printf("MAC Address 0: "); u16toa(htons(mac[0]), temp); itc_printf(temp); u16toa(htons(mac[1]), temp); itc_printf(temp); u16toa(htons(mac[2]), temp); itc_printf(temp); itc_printf("\r\n"); } else { itc_printf("Warning: No MAC address was found; set it now\r\n"); } if (read_mac_ethernet (mac, 1)) { itc_printf("MAC Address 1: "); u16toa(htons(mac[0]), temp); itc_printf(temp); u16toa(htons(mac[1]), temp); itc_printf(temp); u16toa(htons(mac[2]), temp); itc_printf(temp); itc_printf("\r\n"); } itc_printf("FLASH config: "); if(status.flash_chip == i128x2) { itc_printf("32 bit interleaved\r\n"); } else if(status.flash_chip == i128) { itc_printf("16 bit non-interleaved\r\n"); } itc_printf("FLASH blocks: %d x 0x%x (%d MB)\r\n", flash_size_platform() / flash_block_size_platform(), flash_block_size_platform(), (flash_size_platform() / 1024) / 1024); itc_printf("RAM size: %d MB @ 0x%x\r\n", (mem_size_platform() / 1024) / 1024, mem_base_platform()); return 1;}////////////////////////////////////////////////////////////////////////////////// set_parse// PURPOSE: Prints a messege telling the user what attributes are available// via the set command.// PARAMS: (IN) char *arg - argument(s) to the set_parse command (not used).// RETURNS: 0 (This function fails by definition, as the user has not given// us an attribute.)////////////////////////////////////////////////////////////////////////////////intset_parse(char const *arg){ message_print(PARSE_SET_VAR_MESSAGE); return 0;}////////////////////////////////////////////////////////////////////////////////// set_server_parse// PURPOSE: Parses a setserver command and changes the server IP address// accordingly.// PARAMS: (IN) char *arg - argument(s) to the setserver command.// RETURNS: 1 for success, 0 for failure.////////////////////////////////////////////////////////////////////////////////intset_server_parse(char const *arg){ u32 ip; int retval = 0; if(*arg != 0) { if(!(ip = atoip(arg))) { error_print(PARSE_INVALID_ARG_ERROR); retval = 0; } else { status.siaddr = ip; retval = 1; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -