cmd.c
来自「ADS下的bios工程」· C语言 代码 · 共 863 行 · 第 1/2 页
C
863 行
if (!str_ncmp("boot.bin", argv[3], strlen(argv[3]))) { branch = 1; } else if (!str_ncmp("bios.bin", argv[3], strlen(argv[3]))) { branch = 2; } else if (!str_ncmp("zImage", argv[3], strlen(argv[3]))) { branch = 3; } else if (!str_ncmp("romdisk.img", argv[3], strlen(argv[3]))) { branch = 4; } else if (!str_ncmp("ramdisk.gz", argv[3], strlen(argv[3]))) { branch = 5; } else if (!str_ncmp("jffs.img", argv[3], strlen(argv[3]))) { branch = 6; } else if (!str_ncmp("jffs2.img", argv[3], strlen(argv[3]))) { branch = 7; } else { branch = 8; } block = (unsigned int)strtoint(argv[2], strlen(argv[2])); switch (branch) { case 1: if (block != NAND_BOOT_BLOCK) printf("This file must have to write 0 block of NAND Flash!\n"); break ; case 2: if (block != NAND_BIOS_BLOCK) printf("This file must have to write %d block of NAND Flash!\n", NAND_BIOS_BLOCK); break ; case 3: if (block != NAND_KERNEL_BLOCK) printf("This file must have to write %d block of NAND Flash!\n", NAND_KERNEL_BLOCK); break ; case 4: if (block != NAND_APPS_BLOCK) printf("This file must have to write %d block of NAND Flash!\n", NAND_APPS_BLOCK); break ; case 5: if (block != NAND_APPS_BLOCK) printf("This file must have to write %d block of NAND Flash!\n", NAND_APPS_BLOCK); break ; case 6: if (block != NAND_APPS_BLOCK) printf("This file must have to write %d block of NAND Flash!\n", NAND_APPS_BLOCK); break ; case 7: if (block != NAND_APPS_BLOCK) printf("This file must have to write %d block of NAND Flash!\n", NAND_APPS_BLOCK); break ; default: break ; } if (loader -> fn -> init()) return ERROR_BOOT_DEV_INIT; if (loader -> fn -> start()) return ERROR_BOOT_DEV_START; if (!loader -> fn -> load()) { printf("\n%d bytes receive done.\n", bios_recv_bytes); loader -> fn -> stop(); if (!bios_recv_bytes) return FLASH_PROGRAM_FAIL; } else { loader -> fn -> stop(); return ERROR_BOOT_DEV_LOAD; } if (block == 0) { if (bios_recv_bytes > 4096) { printf("\nBoot size overflow!!!\n"); return FLASH_PROGRAM_FAIL; } } nand_flash_control(nand_write, block, 0, (u8 *)load_addr, bios_recv_bytes); printf("\n\n<<< NAND Flash Write Done.[%d] >>>\n\n", block); bios_recv_bytes = 0; sprintf(BOOT_FILE, "%s", "/home/tftp/zImage"); return BIOS_SUCCESS;}u32 DownLoadCmdLi(u8 argc, char (*argv)[MAX_LENGTHOF_ARGS], CMDPOOL *pCmd) { struct BOOT_LOADER *loader; int i; loader = &boot_loader[0]; bios_recv_bytes = 0; if (argc < 3 ) { printfHelpMessage(argv[0]); printf("Usage: %s <loader> <Dest Address> <file name>\n",argv[0]) ; printf(" <loader> = [ net | serial ]\n") ; printf(" <Dest Address> = relative address to SDRAM Base.\n") ; printf(" <file name> = [ ramdisk.gz | diag.bin | bios.bin ]\n") ; printf(" * Excutable download image will be loaded to Dest and run.\n"); return ERROR_MISS_ARGUMENTS; } /* Search the boot loader */ for (i = 0; i < boot_loader_size; i ++) { if (!str_ncmp(loader -> fn -> name, argv[1], strlen(argv[1]))) { printf("\n%s trying to load image....\n",loader -> fn -> name); break ; } loader ++; } if (i == boot_loader_size) return ERROR_NOT_SUPPORT; load_addr = hexstrtohex(argv[2], strlen(argv[2])); sprintf(BOOT_FILE, "%s", "/home/tftp/"); strcat(BOOT_FILE, argv[3]); if (loader -> fn -> init()) return ERROR_BOOT_DEV_INIT; if (loader -> fn -> start()) return ERROR_BOOT_DEV_START; if (!loader -> fn -> load()) loader -> fn -> stop(); else { loader -> fn -> stop(); return ERROR_BOOT_DEV_LOAD; } sprintf(BOOT_FILE, "%s", "/home/tftp/zImage"); if (!str_ncmp("load", argv[0], strlen(argv[0]))) return BIOS_SUCCESS; else boot_image(bios_recv_bytes); bios_recv_bytes = 0; return BIOS_SUCCESS;}u32 BootCmdLi(u8 argc, char (*argv)[MAX_LENGTHOF_ARGS], CMDPOOL *pCmd) { int ret; if (argc < 3) { printfHelpMessage("boot"); printf("Usage: %s <loader> <filesystem>\n", argv[0]) ; printf(" <loader> = [ rom | serial | net ]\n"); printf(" <filesystem> = [ ramdisk | romdisk ]\n"); return ERROR_MISS_ARGUMENTS; } if (!str_ncmp("net", argv[1], strlen(argv[1]))) { if (!str_ncmp("ramdisk", argv[2], strlen(argv[1]))) nand_flash_control(nand_read, NAND_APPS_BLOCK, 0, (u8 *)0x30800000, 0x400000); } if (!str_ncmp("rom", argv[1], strlen(argv[1]))) { if (!str_ncmp("ramdisk", argv[2], strlen(argv[1]))) nand_flash_control(nand_read, NAND_APPS_BLOCK, 0, (u8 *)0x30800000, 0x400000); } if ((ret = manual_boot(argv[1])) != BIOS_SUCCESS) return ret; return BIOS_SUCCESS;}static u32 SysParams(u8 argc, char (*argv)[MAX_LENGTHOF_ARGS], CMDPOOL *pCmd) { if (argc < 2 ) { printfHelpMessage(argv[0]); printf("Usage: %s <command>\n", argv[0]); printf(" <command> = [view | set]\n"); printf(" view : view the system parameter\n"); printf(" set : set up system parameter\n"); return ERROR_MISS_ARGUMENTS; } if (!str_ncmp("set", argv[1], strlen(argv[1]))) sysconf_set(); else if (!str_ncmp("view", argv[1], strlen(argv[1]))) sysconf_view(); else { printf("ERROR : Unkown arguments\n"); return ERROR_MISS_ARGUMENTS; } return BIOS_SUCCESS;}u32 sysconf_set(void) { unsigned int n[6] = {0, 0, 0, 0, 0, 0}; int i, j; char *p, ch; unsigned char cmdline[128]; memset((u8 *)&sysconf, 0, sizeof(sysconf)); printf("\n\n*** Configure the System parameters ***\n\n"); printf("\n") ; printf("=============\n") ; printf(" Boot Method \n"); printf("-------------\n") ; printf(" 1. Auto \n"); printf(" 2. Manual \n"); printf(" 3. Serial \n"); printf(" 4. net \n"); printf(" 5. Parallel \n"); printf("=============\n") ; printf("\n"); printf("-> Select number : "); while (!(ch = getc())) ; putc(ch); switch (ch) { case '1': sprintf(BOOT_FLAGS, "%s", "auto"); break ; case '2': sprintf(BOOT_FLAGS, "%s", "manual"); break ; case '3': sprintf(BOOT_FLAGS, "%s", "serial"); break ; case '4': sprintf(BOOT_FLAGS, "%s", "net"); break ; case '5': sprintf(BOOT_FLAGS, "%s", "\0"); printf("\nCurrent, thisoption didn't support. " "Please, select another!!!!!!"); break ; default: sprintf(BOOT_FLAGS, "%s", "\0"); printf("\nNo boot flags"); break ; } printf("\nCOMPANY NAME > "); if (gets(VENDOR_NAME) == 0) sprintf(VENDOR_NAME,"%s", "ut"); printf("\nBoot file name [/home/tftp/zImage]> "); if (gets(BOOT_FILE) == 0) sprintf(BOOT_FILE,"%s", "/home/tftp/zImage"); memset(cmdline, 0, sizeof(cmdline)); printf("\nTarget system's IP [%s]> ", CONFIG_NET_IP); if (gets(cmdline) == 0) sprintf(cmdline, "%s", CONFIG_NET_IP); IP_ADDRESS = in_aton(cmdline); memset(cmdline, 0, sizeof(cmdline)); printf("\nServer IP [%s]> ", CONFIG_NET_SERVER_IP); if (gets(cmdline) == 0) sprintf(cmdline,"%s", CONFIG_NET_SERVER_IP); SERVER_IP = in_aton(cmdline); memset(cmdline, 0, sizeof(cmdline)); printf("\nDefault Gateway [%s]> ", CONFIG_NET_GATEWAY); if (gets(cmdline) == 0) sprintf(cmdline,"%s", CONFIG_NET_GATEWAY); DEFAULT_GW = in_aton(cmdline); memset(cmdline, 0, sizeof(cmdline)); printf("\nConfig Netmask [%s]> ", CONFIG_NET_NETMASK); if (gets(cmdline) == 0) sprintf(cmdline,"%s", CONFIG_NET_NETMASK); NET_MASK = in_aton(cmdline); memset(cmdline, 0, sizeof(cmdline)); printf("\nMAC address [%s] > ", CONFIG_NET_HWADDR); if (gets(cmdline) == 0) sprintf(cmdline,"%s", CONFIG_NET_HWADDR); p = (char *)&cmdline; while (isspace(*p)) p++; /* get the next charactor */ for (i = 0; i < 6; i ++) { j = 1; while (*p != '\0') { if (isdigit(*p)) n[i] += (*p - '0') << (4 * j); else if (isxdigit(*p)) n[i] += ((toupper(*p) - 'A') + 10) << (4 * j); if (*p == ':') { p ++; break ; } p ++; j ^= 1; } MAC_ADDR[i] = n[i]; } /* Set paramters to valid */ sprintf(CONFIG_FLAGS, "%s", CONFIG_PARAMS_VALID); nand_flash_control(nand_write, 1, 0, (u8 *)&sysconf, sizeof(sysconf)); printf("\n\n Save system parameter to variable..."); printf("Done!\n\n"); return BIOS_SUCCESS;}u32 sysconf_view(void) { int i; memset((u8 *)&sysconf, 0, sizeof(sysconf)); printf("\n\nRead system parameters from NAND Flash Device..."); nand_flash_control(nand_read, 1, 0, (u8 *)&sysconf, sizeof(sysconf)); printf("Done!\n\n"); printf("+==================================================+\n"); printf("| System Configuration Table |\n"); printf("+==================================================+\n"); if (!str_ncmp(CONFIG_FLAGS, CONFIG_PARAMS_VALID, strlen(CONFIG_PARAMS_VALID))) printf("| Configuration Parameter valid !!! |\n"); else printf("| Configuration Parameter Invalid !!! |\n"); printf("| Boot Configuration |\n"); printf("+--------------------------------------------------+\n"); printf("| BOOT Method : %-30s |\n", BOOT_FLAGS); if (!BOOT_FLAGS) printf("| Invalid Boot Method |\n"); printf("| Boot File Name : %-29s |\n",BOOT_FILE); printf("| TFTP Server IP Address : %-21s |\n", in_ntoa(SERVER_IP) ); printf("+--------------------------------------------------+\n"); printf("| Ethernet Configuration |\n"); printf("+--------------------------------------------------+\n"); printf("| Host Name : %-34s |\n",VENDOR_NAME); printf("| Ethernet IP Address : %-24s |\n",in_ntoa(IP_ADDRESS)); printf("| Ethernet Default Gateway : %-19s |\n",in_ntoa(DEFAULT_GW)); printf("| Ethernet Default Subnet Mask : %-15s |\n",in_ntoa(NET_MASK)); printf("| Ethernet H/W Address : "); for (i = 0; i < 6; i ++) { printf("%2.2x%c", MAC_ADDR[i], i == 5 ? ' ': ':'); } printf(" |\n"); printf("+--------------------------------------------------+\n"); printf("| Touch Configuration |\n"); printf("+--------------------------------------------------+\n"); printf("+==================================================+\n\n"); return BIOS_SUCCESS;}int get_params(void){ /* Read System parameters */ memset((u8 *)&sysconf, 0, sizeof(sysconf)); if (getc_timed(10) == ESC) { printf("Clear system parameters..."); nand_flash_control(nand_write, 1, 0, (u8 *)&sysconf, sizeof(sysconf)); } else { printf("Read system parameters..."); nand_flash_control(nand_read, 1, 0, (u8 *)&sysconf, sizeof(sysconf)); } printf("Done!\n"); /* check valid for configuration parameter */ if (str_ncmp(CONFIG_FLAGS, CONFIG_PARAMS_VALID, strlen(CONFIG_PARAMS_VALID))) { sysconf_set(); sysconf_view(); } if (!str_ncmp(BOOT_FLAGS, AUTO_BOOT, strlen(AUTO_BOOT))) { printf("auto_boot()!\n"); auto_boot(); } else if (!str_ncmp(BOOT_FLAGS, SERIAL_BOOT, strlen(SERIAL_BOOT))) { printf("manual_boot()!\n"); manual_boot(SERIAL_BOOT); } return 0;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?