📄 setup.c
字号:
#include "board.h"#include "console.h"#include "utils.h"#include "bios.h"#include "bioscall.h"const unsigned long cache_value[] = { (SYS_CACHE_0K | SYS_CACHE_OFF), (SYS_CACHE_4K | SYS_CACHE_ON), (SYS_CACHE_8K | SYS_CACHE_ON)};const char *cache_text[] = { "OFF", "4K", "8K"};const unsigned long wbuf_value[] = { SYS_WBUF_OFF, SYS_WBUF_ON};const char *wbuf_text[] = { "OFF", "ON"};const unsigned long clk_value[] = { CLK_DIV_1, CLK_DIV_2, CLK_DIV_3, CLK_DIV_5};const char *clk_text[] = { "1 ", "1/2", "1/3", "1/5"};const char *dbwth_text[] = { "0 ", "8bit ", "16bit", "32bit"};const unsigned long pmc_value[] = { ROM_PMC_NORMAL, ROM_PMC_4WORD, ROM_PMC_8WORD, ROM_PMC_16WORD};const char *pmc_text[] = { "Normal-ROM ", "SRAM-4Word ", "SRAM-8Word ", "SRAM-16Word"};const unsigned long tpa_value[] = { ROM_TPA_2CYCLE, ROM_TPA_3CYCLE, ROM_TPA_4CYCLE, ROM_TPA_5CYCLE};const char *tpa_text[] = { "2", "3", "4", "5"};const unsigned long tacc_value[] = { ROM_TACC_0CYCLE, ROM_TACC_2CYCLE, ROM_TACC_3CYCLE, ROM_TACC_4CYCLE, ROM_TACC_7CYCLE};const char *tacc_text[] = { "0", "2", "3", "4", "7"};const unsigned long trcd_value[] = { DRAM_TRCD_1CYCLE, DRAM_TRCD_2CYCLE};const char *trcd_text[] = { "1", "2"};const unsigned long trp_value[] = { DRAM_TRP_1CYCLE, DRAM_TRP_2CYCLE, DRAM_TRP_3CYCLE, DRAM_TRP_4CYCLE};const char *trp_text[] = { "1", "2", "3", "4"};const unsigned long can_value[] = { DRAM_CAN_8BIT, DRAM_CAN_9BIT, DRAM_CAN_10BIT, DRAM_CAN_11BIT};const char *can_text[] = { "8bit ", "9bit ", "10bit", "11bit"};const unsigned long trc_value[] = { REF_TRC_1CYCLE, REF_TRC_2CYCLE, REF_TRC_3CYCLE, REF_TRC_4CYCLE, REF_TRC_5CYCLE, REF_TRC_6CYCLE};const char *trc_text[] = { "1", "2", "3", "4", "5", "6"};const unsigned long period_value[] = { REF_PERIOD_8US, REF_PERIOD_16US, REF_PERIOD_24US, REF_PERIOD_32US};const char *period_text[] = { "8us ", "16us", "24us", "32us"};const unsigned long etcos_value[] = { EXT_TCOS_0CYCLE, EXT_TCOS_1CYCLE, EXT_TCOS_2CYCLE, EXT_TCOS_3CYCLE, EXT_TCOS_4CYCLE, EXT_TCOS_5CYCLE, EXT_TCOS_6CYCLE, EXT_TCOS_7CYCLE};const char *etcos_text[] = { "0", "1", "2", "3", "4", "5", "6", "7"};const unsigned long etacs_value[] = { EXT_TACS_0CYCLE, EXT_TACS_1CYCLE, EXT_TACS_2CYCLE, EXT_TACS_3CYCLE, EXT_TACS_4CYCLE, EXT_TACS_5CYCLE, EXT_TACS_6CYCLE, EXT_TACS_7CYCLE};const char *etacs_text[] = { "0", "1", "2", "3", "4", "5", "6", "7"};const unsigned long etcoh_value[] = { EXT_TCOH_0CYCLE, EXT_TCOH_1CYCLE, EXT_TCOH_2CYCLE, EXT_TCOH_3CYCLE, EXT_TCOH_4CYCLE, EXT_TCOH_5CYCLE, EXT_TCOH_6CYCLE, EXT_TCOH_7CYCLE};const char *etcoh_text[] = { "0", "1", "2", "3", "4", "5", "6", "7"};const unsigned long etacc_value[] = { EXT_TACC_0CYCLE, EXT_TACC_1CYCLE, EXT_TACC_2CYCLE, EXT_TACC_3CYCLE, EXT_TACC_4CYCLE, EXT_TACC_5CYCLE, EXT_TACC_6CYCLE, EXT_TACC_7CYCLE};const char *etacc_text[] = { "0", "1", "2", "3", "4", "5", "6", "7"};int main_menu(void){ int list[] = { SETUP_CPU, SETUP_ROM, SETUP_DRAM, SETUP_EXTIO, SETUP_ETH, SETUP_BOOT_MODE, SETUP_PASSWD, SETUP_LOAD_DEF }; int select; printf("\r\n\r\nSetup Menu\r\n\r\n"); printf("1 - CPU Setup\r\n"); printf("2 - ROM Setup\r\n"); printf("3 - SDRAM Setup\r\n"); printf("4 - ExtIO Setup\r\n"); printf("5 - Ether Setup\r\n"); printf("6 - Boot Setup\r\n"); printf("7 - Passwd Setup\r\n"); printf("8 - Load default\r\n\r\n"); printf("Please Select "); select = get_select('1', '8'); printf("\r\n"); if (select < 0) return -1; return list[select];}int update_system_table(struct system_table_struct *system_table){ unsigned long offset, size, l; offset = bios_system_table_offset(); size = bios_system_table_size(); printf("\r\nUpdate System Paramters ............. "); bios_flash_erase(offset, size); bios_flash_write(offset, size, &l, (unsigned char *)system_table); printf("Done\r\n"); return 0;}int setup_cpu(void){ struct system_table_struct system_table; struct sys_cpu_cfg *cpu; char ch; printf("\r\n\r\nCPU Setup\r\n\r\n"); bios_system_table(&system_table); cpu = &(system_table.cpu); printf("Unified Cache: "); if (cpu->cache_size >= 3) cpu->cache_size = 0; printf("%s\r\n", cache_text[cpu->cache_size]); printf("Write Buffer: "); if (cpu->wbuf_on >= 2) cpu->wbuf_on = 0; printf("%s\r\n", wbuf_text[cpu->wbuf_on]); printf("Clock Dividing: "); if (cpu->clk_div >= 4) cpu->clk_div = 0; printf("%s\r\n", clk_text[cpu->clk_div]); printf("\r\n"); printf("Press Enter to setup, Esc to exit"); if (get_enter_esc() == 0) { printf("\r\n"); return 0; } printf("\r\n\r\n"); printf("Unified Cache [1=OFF, 2=4K, 3=8K]: "); ch = get_select_enter('1', '3'); if (ch >= 0) cpu->cache_size = ch; printf("\r\n"); printf("Write Buffer [1=OFF, 2=ON]: "); ch = get_select_enter('1', '2'); if (ch >= 0) cpu->wbuf_on = ch; printf("\r\n"); printf("Clock Dividing [1=1, 2=1/2, 3=1/3, 4=1/5]: "); ch = get_select_enter('1', '4'); if (ch >= 0) cpu->clk_div = ch; printf("\r\n"); cpu->reg_syscfg = ( SYS_ALWAYS_SET | cache_value[cpu->cache_size] | wbuf_value[cpu->wbuf_on]); cpu->reg_clkcon = ( CLK_ALWAYS_SET | clk_value[cpu->clk_div]); update_system_table(&system_table); return 0;}int setup_rom(void){ struct system_table_struct system_table; struct sys_rom_cfg *rom; int bank, i; char ch; printf("\r\n\r\nROM Setup\r\n\r\n"); bios_system_table(&system_table); printf("Bank Size Width Page-Mode tPA tACC\r\n"); for (i = 0; i < 6; i++) { rom = &(system_table.rom_table[i]); printf("%d 0x%08lx ", i + 1, rom->size); if (!(rom->width >= 1 && rom->width <= 3)) rom->width = 1; printf("%s ", dbwth_text[rom->width]); if (rom->pmc >= 4) rom->pmc = 0; printf("%s ", pmc_text[rom->pmc]); if (rom->tpa >= 4) rom->tpa = 0; printf("%s ", tpa_text[rom->tpa]); if (rom->tacc >= 5) rom->tacc = 0; printf("%s", tacc_text[rom->tacc]); printf("\r\n"); } printf("\r\nPlease Select ROM Bank (1 - 6) "); bank = get_select('1', '6'); if (bank < 0) { printf("\r\n"); return 0; } printf("\r\n\r\n"); rom = &(system_table.rom_table[bank]); printf("ROM Size (0x%08lx): ", rom->size); rom->size = getul(rom->size, 16); printf("\r\n"); printf("ROM Width [1=8bit, 2=16bit, 3=32bit]: "); ch = get_select_enter('1', '3'); if (ch >= 0) rom->width = ch + 1; printf("\r\n"); printf("Page-Mode [1=ROM, 2=4Word, 3=8Word, 4=16Word]: "); ch = get_select_enter('1', '4'); if (ch >= 0) rom->pmc = ch; printf("\r\n"); printf("tPA [1=2Cycle, 2=3Cycle, 3=4Cycle, 4=5Cycle]: "); ch = get_select_enter('1', '4'); if (ch >= 0) rom->tpa = ch; printf("\r\n"); printf("tACC [1=0Cycle, 2=2Cycle, 3=3Cycle, 4=4, 5=7]: "); ch = get_select_enter('1', '5'); if (ch >= 0) rom->tacc = ch; printf("\r\n"); rom->flag = ( ROM_ALWAYS_SET | pmc_value[rom->pmc] | tpa_value[rom->tpa] | tacc_value[rom->tacc]); update_system_table(&system_table); bios_set_userflag(USERFLAG_MEMORY); return 0;}int setup_dram(void){ struct system_table_struct system_table; struct sys_dram_cfg *dram; int bank, i; char ch; printf("\r\n\r\nSDRAM Setup\r\n\r\n"); bios_system_table(&system_table); printf("Bank Size Width tRCD tRP CAN tRC Refresh\r\n"); for (i = 0; i < 4; i++) { dram = &(system_table.dram_table[i]); printf("%d 0x%08lx ", i + 1, dram->size); if (!(dram->width >= 1 && dram->width <= 3)) dram->width = 1; printf("%s ", dbwth_text[dram->width]); if (dram->trcd >= 2) dram->trcd = 0; printf("%s ", trcd_text[dram->trcd]); if (dram->trp >= 4) dram->trp = 0; printf("%s ", trp_text[dram->trp]); if (dram->can >= 4) dram->can = 0; printf("%s ", can_text[dram->can]); if (dram->ref_trc >= 6) dram->ref_trc = 0; printf("%s ", trc_text[dram->ref_trc]); if (dram->ref_period >= 4) dram->ref_period = 0; printf("%s", period_text[dram->ref_period]); printf("\r\n"); } printf("\r\nPlease Select SDRAM Bank (1 - 4) "); bank = get_select('1', '4'); if (bank < 0) { printf("\r\n"); return 0; } printf("\r\n\r\n"); dram = &(system_table.dram_table[bank]); printf("SDRAM Size (%08lx): ", dram->size); system_table.dram_table[bank].size = getul(dram->size, 16); printf("\r\n"); printf("SDRAM Width [1=8bit, 2=16bit, 3=32bit]: "); ch = get_select_enter('1', '3'); if (ch >= 0) dram->width = ch + 1; printf("\r\n"); printf("tRCD [1=1Cycle, 2=2Cycle]: "); ch = get_select_enter('1', '2'); if (ch >= 0) dram->trcd = ch; printf("\r\n"); printf("tRP [1=1Cycle, 2=2Cycle, 3=3Cycle, 4=4Cycle]: "); ch = get_select_enter('1', '4'); if (ch >= 0) dram->trp = ch; printf("\r\n"); printf("CAN [1=8bit, 2=9bit, 3=10bit, 4=11bit]: "); ch = get_select_enter('1', '4'); if (ch >= 0) dram->can = ch; printf("\r\n"); printf("tRC [1=1Cycle, 2=2Cycle, 3=3Cycle, 4=4, 5=5, 6=6]: "); ch = get_select_enter('1', '6'); if (ch >= 0) dram->ref_trc = ch; printf("\r\n"); printf("Refresh [1=8us, 2=16us, 3=24us, 4=32us]: "); ch = get_select_enter('1', '4'); if (ch >= 0) dram->ref_period = ch; printf("\r\n"); dram->flag = ( DRAM_ALWAYS_SET | trcd_value[dram->trcd] | trp_value[dram->trp] | can_value[dram->can]); dram->refresh = ( REF_ALWAYS_SET | trc_value[dram->ref_trc] | period_value[dram->ref_period]); update_system_table(&system_table); bios_set_userflag(USERFLAG_MEMORY); return 0;}int setup_ext_io(void){ struct system_table_struct system_table; struct sys_ext_cfg *ext; int bank, i; char ch; printf("\r\n\r\nExternal IO Setup\r\n\r\n"); bios_system_table(&system_table); printf("Bank Width tCOS tACS tCOH tACC\r\n"); for (i = 0; i < 4; i++) { ext = &(system_table.ext_table[i]); printf("%d ", i + 1); if (!(ext->width >= 1 && ext->width <= 3)) ext->width = 1; printf("%s ", dbwth_text[ext->width]); if (ext->tcos >= 8) ext->tcos = 0; printf("%s ", etcos_text[ext->tcos]); if (ext->tacs >= 8) ext->tacs = 0; printf("%s ", etacs_text[ext->tacs]); if (ext->tcoh >= 8) ext->tcoh = 0; printf("%s ", etcoh_text[ext->tcoh]); if (ext->tacc >= 8) ext->tacc = 0; printf("%s", etacc_text[ext->tacc]); printf("\r\n"); } printf("\r\nPlease Select External IO Bank (1 - 4) "); bank = get_select('1', '4'); if (bank < 0) { printf("\r\n"); return 0; } printf("\r\n\r\n"); ext = &(system_table.ext_table[bank]); printf("IO Bank Width [1=8bit, 2=16bit, 3=32bit]: "); ch = get_select_enter('1', '3'); if (ch >= 0) ext->width = ch + 1; printf("\r\n"); printf("tCOS [1=0Cycle, 2=1Cycle, 3=2 4=3, 5=4, 6=5, 7=6, 8=7]: "); ch = get_select_enter('1', '8'); if (ch >= 0) ext->tcos = ch; printf("\r\n"); printf("tACS [1=0Cycle, 2=1Cycle, 3=2 4=3, 5=4, 6=5, 7=6, 8=7]: "); ch = get_select_enter('1', '8'); if (ch >= 0) ext->tacs = ch; printf("\r\n"); printf("tCOH [1=0Cycle, 2=1Cycle, 3=2 4=3, 5=4, 6=5, 7=6, 8=7]: "); ch = get_select_enter('1', '8'); if (ch >= 0) ext->tcoh = ch; printf("\r\n"); printf("tACC [1=0Cycle, 2=1Cycle, 3=2 4=3, 5=4, 6=5, 7=6, 8=7]: "); ch = get_select_enter('1', '8'); if (ch >= 0) ext->tacc = ch; printf("\r\n"); ext->flag = ( EXT_ALWAYS_SET | etcos_value[ext->tcos] | etacs_value[ext->tacs] | etcoh_value[ext->tcoh] | etacc_value[ext->tacc]); update_system_table(&system_table); bios_set_userflag(USERFLAG_MEMORY); return 0;}int eth_menu(void){ int list[] = { ETH_DISPLAY_IP, ETH_DISPLAY_MAC, ETH_SET_IP, ETH_SET_MAC }; int select; printf("\r\n\r\nEthernet Setup\r\n\r\n"); printf("1 - Display IP Address\r\n"); printf("2 - Display MAC Address\r\n"); printf("3 - Set IP Address\r\n"); printf("4 - Set MAC Address\r\n\r\n"); printf("Please Select "); select = get_select('1', '4'); printf("\r\n"); if (select < 0) return -1; return list[select];}int setup_eth_addr(void){ struct system_table_struct system_table; int select, i; unsigned char *s = (unsigned char *)&(system_table.eth.ip_addr); while ( (select = eth_menu()) >= 0) { printf("\r\n"); bios_system_table(&system_table); switch (select) { case ETH_DISPLAY_IP: printf("IP Address : %d.%d.%d.%d", s[3], s[2], s[1], s[0]); printf("\r\n"); break; case ETH_DISPLAY_MAC: printf("MAC Address : "); for (i = 0; i < 6; i++) { printf("%02x ", system_table.eth.mac_addr[i]); } printf("\r\n"); break; case ETH_SET_IP: for (i = 0; i < 4; i++) { printf("IP Address %d (%03d) : ", i, s[3 - i]); s[3 - i] = (unsigned char)getuc(s[3 - i], 10); printf("\r\n"); } update_system_table(&system_table); break; case ETH_SET_MAC: for (i = 0; i < 6; i++) { printf("MAC Address %01x (%02x) : ", i, system_table.eth.mac_addr[i]); system_table.eth.mac_addr[i] = getuc(system_table.eth.mac_addr[i], 16); printf("\r\n"); } update_system_table(&system_table); break; default: break; } } return 0;}int setup_boot_mode(void){ struct system_table_struct system_table; int list[] = { BOOT_MENU, BOOT_LOAD_IMAGE, }; int select; printf("\r\n\r\nBoot Mode Setup\r\n\r\n"); printf("1 - Boot Menu\r\n"); printf("2 - Load Image\r\n"); printf("\r\nPlease Select "); select = get_select('1', '2'); printf("\r\n"); if (select < 0) return 0; bios_system_table(&system_table); system_table.startup_mode = list[select]; update_system_table(&system_table); return 0;}int setup_passwd(void){ struct system_table_struct system_table; bios_system_table(&system_table); printf("\r\n\r\nPassword Setup\r\n\r\n"); printf("New Password: "); getpass(system_table.password, PASSWD_LENGTH, '*'); printf("\r\n"); update_system_table(&system_table); return 0;}int setup_load_def(void){ struct system_table_struct default_table; printf("\r\nLoad BIOS default? (Y/n)"); if (get_yes_no(1)) { printf("\r\n"); bios_default_table(&default_table); update_system_table(&default_table); bios_set_userflag(USERFLAG_BIOS); } else printf("\r\n"); return 0;}int setup(void){ int select; while ( (select = main_menu()) >= 0) { switch (select) { case SETUP_CPU: setup_cpu(); break; case SETUP_ROM: setup_rom(); break; case SETUP_DRAM: setup_dram(); break; case SETUP_EXTIO: setup_ext_io(); break; case SETUP_ETH: setup_eth_addr(); break; case SETUP_BOOT_MODE: setup_boot_mode(); break; case SETUP_PASSWD: setup_passwd(); break; case SETUP_LOAD_DEF: setup_load_def(); break; default: break; } } return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -