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

📄 bootmenu.c

📁 em86xx 完整启动程序,支持网络下载与串通下载
💻 C
📖 第 1 页 / 共 5 页
字号:
{    static char s_helpstr[] =         CONFIG_ARCH " boot loader " BOOTLOADER_VERSIONSTR "\n"        "Copyright (C) 2002-2005 by Sigma Designs, Inc\n"        "\n"        "Command List :\n"        ;#ifndef CONFIG_DISABLE_HELP_MSGS    int i;    if (argc == 1) {        // help on all        uart_puts(s_helpstr);        for (i = 0; s_cmdtable[i].cmd != NULL; ++i)             if (s_cmdtable[i].helpbrief)                uart_puts(s_cmdtable[i].helpbrief);    } else {            // help on command        for (i = 0; s_cmdtable[i].cmd != NULL; ++i) {            if (strcmp(s_cmdtable[i].cmd, argv[1]) == 0) {                if (s_cmdtable[i].helpbrief)                    uart_puts(s_cmdtable[i].helpbrief);                if (s_cmdtable[i].helpmsg)                    uart_puts(s_cmdtable[i].helpmsg);                return 0;            }        }        uart_puts("Unknown command\n");    }#else    uart_puts(s_helpstr);    uart_puts(no_help_msg);#endif    return 0;}int bootmenu_boot(int argc, char *argv[]){    unsigned int addr = 0;    int doboot = 0;            if (argc == 1) {#ifndef CONFIG_DISABLE_HELP_MSGS        uart_puts(s_help_boot_brief);        uart_puts(s_help_boot);#else        uart_puts(no_help_msg);#endif        return 0;    }    if (argv[2])        addr = atoi(argv[2]);    if (strcmp(argv[1], "rom") == 0) {        // boot rom [addr]        doboot = doboot_romfs_rom(addr);#ifdef CONFIG_ENABLE_CRYPTO    } else if (strcmp(argv[1], "romcrypt") == 0) {        doboot = doboot_romfs_rom_crypt(addr);#endif    } else if (strcmp(argv[1], "kernel") == 0) {        // boot kernel [addr]        if (addr == 0)            addr = loadaddr_kernel;        doboot = 1;        uart_printf("Boot kernel @ 0x%08x\n", addr);    } else if (strcmp(argv[1], "initrd") == 0) {        // boot initrd [addr]        if (addr == 0)            addr = loadaddr_kernelfs;        doboot = 1;        uart_printf("Boot kernel @ 0x%08x with INITRD @ 0x%08lx\n", addr, loadaddr_initrd);    } else if (strcmp(argv[1], "boot") == 0) {	// boot boot        addr = 0x118 + loadaddr_boot;        doboot = 1;        uart_printf(jmp_msg, addr);    } else if (argv[1][0] >= '0' && argv[1][0] <= '9') {        // boot <addr>        addr = atoi(argv[1]);        doboot = 1;        uart_printf(jmp_msg, addr);    } #ifdef CONFIG_ENABLE_FULLFUNCTION    else if (strcmp(argv[1], "romfs") == 0) {        // boot romfs [addr]        doboot = doboot_romfs_ram(addr);    }#endif#ifdef CONFIG_ENABLE_IDE    else if (strcmp(argv[1], "ide") == 0) {        int drive, part, subpart = 0;        if (argv[2] == NULL && argv[3] == NULL) {            // boot ide [addr]            doboot = doboot_idedisk(addr);        } else {            // boot ide <drive> <part> [subpart] [addr]            if ((drive = bootmenu_ide_checkdrive(argv[2], IDE_ATA, 1)) >= 0)                if ((part = bootmenu_ide_checkblock(argv[3], 1, 1, drive)) >= 0) {                    if (argv[4])                        subpart = atoi(argv[4]);                    addr = (argv[5]) ? atoi(argv[5]) : 0;                    doboot = doboot_ide(drive, part, subpart, addr);                }        }    } else if (strcmp(argv[1], "cd") == 0) {        int drive;        if (argv[2] == NULL) {            // boot cd            doboot = doboot_idecd(addr);        } else {            // boot cd <drive> [addr]            if ((drive = bootmenu_ide_checkdrive(argv[2], IDE_ATAPI, 1)) >= 0) {                addr = atoi(argv[3]) ? atoi(argv[3]) : 0;                doboot = doboot_cd(drive, addr);            }        }    }#ifdef CONFIG_ENABLE_CRYPTO    else if (strcmp(argv[1], "cdcrypt") == 0) {        int drive;        if (argv[2] == NULL) {            // boot cd            doboot = doboot_idecd_crypt(addr);        } else {            // boot cd <drive> [addr]            if ((drive = bootmenu_ide_checkdrive(argv[2], IDE_ATAPI, 1)) >= 0) {                addr = atoi(argv[3]) ? atoi(argv[3]) : 0;                doboot = doboot_cd_crypt(drive, addr);            }        }    }#endif // CONFIG_ENABLE_CRYPTO#endif // CONFIG_ENABLE_IDE#ifdef CONFIG_ENABLE_NETWORK    else if (strcmp(argv[1], "net") == 0) {        if (argv[2])            doboot = doboot_net(addr, argv[2]);        else            doboot = doboot_net(addr, NULL);    }#ifdef CONFIG_ENABLE_CRYPTO    else if (strcmp(argv[1], "netcrypt") == 0) {        if (argv[2])            doboot = doboot_net_crypt(addr, argv[2]);        else            doboot = doboot_net_crypt(addr, NULL);    }#endif#endif    else         uart_puts("Unknown boot method\n");    if (doboot) {#ifdef CONFIG_ENABLE_FIP        fip_write_text(0, fiptext = "BOOT", FIP_CENTER);#endif        do_boot(addr);    }    return 0;}int bootmenu_config(int argc, char *argv[]){    static int s_baudrate = DEFAULT_UART_BAUDRATE;            if (argc == 1) {#ifndef CONFIG_DISABLE_HELP_MSGS        uart_puts(s_help_config_brief);        uart_puts(s_help_config);#else        uart_puts(no_help_msg);#endif        return 0;    }    if (strcmp(argv[1], "cmd") == 0) {        int i;        char cmdline[256];                for (i = 2, cmdline[0] = 0; i < argc; ++i) {            strcat(cmdline, argv[i]);            strcat(cmdline, " ");        }        strcpy(g_bootconfig.kernel_cmdline, cmdline);        uart_printf("New command line : (%d) %s\n", strlen(cmdline), cmdline);        build_kernel_param_tag();    } else if (strcmp(argv[1], "clock") == 0) {        uart_printf("Current freq.: %dMHz\n", em86xx_getclockmhz());        if (argv[2]) {            int clock = atoi(argv[2]);            if (clock < CPU_CLOCK_MIN || clock > CPU_CLOCK_MAX) {                uart_printf("Out of valid range (valid range: %d-%d).\n",                     CPU_CLOCK_MIN, CPU_CLOCK_MAX);            } else {                em86xx_setclockmhz(clock);#ifdef CONFIG_USE_SYSCLK                uart_reset();#endif                uart_printf("New freq.: %dMHz\n", em86xx_getclockmhz());            }        }    } else if (strcmp(argv[1], "serial") == 0) {        static int s_validbaudrate[] = {            9600, 19200, 38400, 57600, 115200, 230400, 0 };        int i, baudrate = DEFAULT_UART_BAUDRATE;        if (argv[2] == NULL)             uart_printf("Setup UART as default baud rate %d\n", baudrate);        else {            if (strcmp(argv[2], "fast") == 0)                baudrate = 115200;            else if (strncmp(argv[2], "def", 3) == 0)                baudrate = 38400;            else                baudrate = atoi(argv[2]);            for (i = 0; s_validbaudrate[i] != 0; ++i)                if (s_validbaudrate[i] == baudrate)                     break;            if (s_validbaudrate[i] == 0) {                uart_printf("Invalid baud rate %d\n", baudrate);                baudrate = 0;            } else                uart_printf("Setup UART baud rate: %d\n", baudrate);        }        if (baudrate) {            s_baudrate = baudrate;            uart_init_port(DEFAULT_UART_PORT, baudrate, 1);        }    } #ifdef CONFIG_ENABLE_NETWORK    else if (strcmp(argv[1], "net") == 0) {        char str[128];        int i;        while (1) {            uart_printf("  Protocol    : (0) None (1) Static IP (2) BOOTP (3) DHCP : (%d) ", g_bootconfig.protocol);            uart_gets(str, sizeof str, 0);            if ((trim(str))[0] == 0)                break;            i = atoi(str);            if (i >= BOOTNET_NONE && i <= BOOTNET_DHCP) {                g_bootconfig.protocol = i;                break;            }        }         if (g_bootconfig.protocol != BOOTNET_NONE) {            struct {                char *title;                int common;                unsigned int *addr;            } asklist[] = {                { "IP Address ", 0, &g_bootconfig.ipaddr },                { "Netmask    ", 0, &g_bootconfig.netmask },                { "Gateway    ", 0, &g_bootconfig.gateway },                { "DNS        ", 0, &g_bootconfig.dns },                { "Server     ", 1, &g_bootconfig.server },                { NULL, 0, NULL },            };            in_addr_t ipaddr = g_bootconfig.ipaddr, newipaddr = ipaddr;            in_addr_t netmask = g_bootconfig.netmask;            int class = ipv4_get_ipaddr_class(ipaddr), newclass = class;            unsigned int addr;            unsigned char *cp;                        for (i = 0; asklist[i].title != NULL; ++i) {                if (g_bootconfig.protocol != BOOTNET_STATIC && !asklist[i].common)                    continue;                while (1) {                    // if the class of IP address has changed                     // or the current netmask value is invalid,                    // validate the netmask as default                    if (i == 1) {                        if (netmask == INADDR_ANY || netmask == INADDR_BROADCAST ||                            (ipaddr != newipaddr && class != newclass && ipv4_ipaddr_valid(newipaddr))) {                            g_bootconfig.netmask = ipv4_get_default_netmask(newipaddr);                        }                    }                    addr = htonl(*asklist[i].addr);                    cp = (unsigned char *) &addr;                                        // Get the string                    uart_printf("  %s : (%d.%d.%d.%d) ",                         asklist[i].title,                        cp[0], cp[1], cp[2], cp[3]);                    uart_gets(str, sizeof str, 0);                    if ((trim(str))[0] == 0)                        break;                    // Parse the string                    if (parse_netaddr(str, cp, 4) == 0) {                        addr = ntohl(addr);                        // if IP address class has changed, adjust netmask                        if (i == 0) {                            if (!ipv4_ipaddr_valid(addr))                                continue;                            newipaddr = addr;                            newclass = ipv4_get_ipaddr_class(newipaddr);                        }                        *asklist[i].addr = addr;                        break;                    }                }            }        }    } #endif    else if (strcmp(argv[1], "file") == 0) {        struct {            char *title;            unsigned char *value;        } asklist[] = {            { "boot loader", g_bootconfig.loader_filename },#ifdef CONFIG_ENABLE_2NDBOOT            { "2ndboot loader", g_bootconfig.scnd_loader_filename },#endif#ifdef CONFIG_ENABLE_USERPREF            { "user preference", g_bootconfig.userpref_filename },#endif#ifdef CONFIG_ENABLE_VSYNCPARAM            { "VSYNC parameters structure", g_bootconfig.vsyncparam_filename },#endif#ifdef CONFIG_ENABLE_DVI            { "I2C commands to control silicon image", g_bootconfig.dvi_filename },#endif            { "ROM filesystem", g_bootconfig.romfs_filename },            { "Kernel", g_bootconfig.kernel_filename },            { "KernelFS", g_bootconfig.kernelfs_filename },            { "initrd image", g_bootconfig.initrd_filename },            { "Binary", g_bootconfig.misc_filename },            { "Installable file", g_bootconfig.inst_filename },#ifdef CONFIG_ENABLE_IRQHANDLER            { "IRQ handler", g_bootconfig.irqhandler_filename },#endif#ifdef CONFIG_ENABLE_BITMAPS            { "Bitmap", g_bootconfig.bitmap_filename },#endif#ifdef CONFIG_ENABLE_UCODES            { "uCode", g_bootconfig.ucode_filename },#endif            { NULL, NULL },        };        int i;        unsigned char str[BOOTCONFIG_PATHLEN];                for (i = 0; asklist[i].title != NULL; ++i) {            uart_printf("  %s filename : (%s) ", asklist[i].title, asklist[i].value);            uart_gets(str, sizeof str, 0);            if ((trim(str))[0] != 0)                strcpy(asklist[i].value, str);        }    }     else if (strcmp(argv[1], "cache") == 0 || strcmp(argv[1], "dcache") == 0 || strcmp(argv[1], "icache") == 0 || strcmp(argv[1], "data") == 0 || strcmp(argv[1], "writeback") == 0) {        unsigned int icache = -1, dcache = -1, writeback = -1;        if (argv[1][0] == 'c')            icache = dcache = writeback = 1;        else if (argv[1][0] == 'd') {            if (argv[1][1] == 'c')                dcache = writeback = 1;            else                dcache = 1;        } else if (argv[1][0] == 'w')            writeback = 1;        else             icache = 1;                    if (strcmp(argv[2], "on") == 0) {#ifndef CONFIG_ENABLE_CACHE            uart_puts("Cache is disabled by default\n");#else            em86xx_enable_cache(icache, dcache, writeback);            uart_puts("Caches are enabled\n");#endif        } else if (strcmp(argv[2], "off") == 0) {#ifndef CONFIG_ENABLE_CACHE            uart_puts("Cache is disabled by default\n");#else            if (icache == 1)                icache = 0;            if (dcache == 1)                dcache = 0;            if (writeback == 1)                writeback = 0;            em86xx_enable_cache(icache, dcache, writeback);            uart_puts("Caches are disabled\n");#endif        }        em86xx_get_cache_state(&icache, &dcache, &writeback);        uart_puts("Cache status : \n");        uart_printf("  I-CACHE = %s\n", icache ? "on" : "off");        uart_printf("  D-CACHE = %s\n", dcache ? "on" : "off");        uart_printf("  Writeback CACHE = %s\n", writeback ? "on" : "off");    } else         uart_puts("Unknown configuration\n");    return 0;

⌨️ 快捷键说明

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