void command_mode() { while(1) { char c; console_title("Command mode"); console_status(status_str); c = getchar(); if (c == '\n') edit_mode(); else if (c == 'q' || c == 'Q') { extern int fileModified; if (!fileModified) return; console_status("Save changes? (y/n/c)"); while(1) { c = getchar(); if (c == 'y' || c == 'Y') { if (file_save()) { console_status(failure); getchar(); break; } return; /* done. */ } else if (c == 'n' || c == 'N') { return; /* just return; */ } else if (c == 'c' || c == 'C') { break; /* cancel; */ } } } } }
// setBoardParam: Set the board Id string, mac addresses, psi size, etc... // int setBoardParam(void) { int bChange = FALSE; int count = 0; PPARAMETER_SETTING tmpPtr = gBoardParam; int memType; while (tmpPtr->promptName != NULL) { count++; tmpPtr++; } getBoardParam(); while (1) { bChange = processPrompt(gBoardParam, count); if (strlen(gBoardParam[3].parameter) != 0) break; printf("Base Mac address is not entered. Try it again!\n"); } if (bChange) { // fill in board id string, psi and mac count nvramData.ulVersion = NVRAM_VERSION_NUMBER; nvramData.ulEnetModeFlag = 0xffffffff; // all ffs for enet mode flag memset(nvramData.szBoardId, 0, NVRAM_BOARD_ID_STRING_LEN); memcpy(nvramData.szBoardId, gBoardParam[0].parameter, NVRAM_BOARD_ID_STRING_LEN); nvramData.ulPsiSize = atoi(gBoardParam[1].parameter); nvramData.ulNumMacAddrs = atoi(gBoardParam[2].parameter); parsehwaddr(gBoardParam[3].parameter, nvramData.ucaBaseMacAddr); // set memory type thing memType = atoi(gBoardParam[4].parameter); kerSysMemoryTypeSet((int) FLASH63XX_ADDR_BOOT_ROM, (char *)&memType, sizeof(int)); if (nvramData.ulPsiSize != NVRAM_PSI_DEFAULT_6345) { printf("Are you REALLY sure persistent storage size is %d?", nvramData.ulPsiSize); if (yesno()) { nvramData.ulPsiSize = NVRAM_PSI_DEFAULT_6345; sprintf(gBoardParam[1].parameter, "%d", nvramData.ulPsiSize); return 0; } } // save the buf to nvram writeNvramData(); printf("Press any key to reset the board: \n"); while (1) if (console_status()) kerSysMipsSoftReset(); } return 0; } // setBoardParam
static int ui_cmd_timertest(ui_cmdline_t *cmd,int argc,char *argv[]) { int64_t t; t = cfe_ticks; while (!console_status()) { cfe_sleep(CFE_HZ); if (t != cfe_ticks) { xprintf("Time is %lld\n",cfe_ticks); t = cfe_ticks; } } return 0; }
static void cfe_autostart(void) { char *env; int noauto = 0; char ch = 0; uint64_t now; uint64_t timeout; int delay = 1; /* 1s */ env = env_getenv("STARTUP"); if (!env) return; leds_on(); xprintf("Auto boot\n"); now = _getticks(); timeout = now + delay *(cfe_cpu_speed/(CPUCFG_CYCLESPERCPUTICK)); while(now < timeout) { while (console_status()) { console_read(&ch,1); if (ch == 3) noauto = TRUE; /* Ctrl-C means no auto */ } if (recovery_button_status()) { noauto = TRUE; } if (noauto == TRUE) break; now = _getticks(); } leds_off(); if (noauto) { xprintf("Startup canceled\n"); return; } ui_docommands(env); }
static int ui_cmd_memtest(ui_cmdline_t *cmd,int argc,char *argv[]) { long addr = 0; int len = 0; int wtype = 0; int wlen; int idx = 0; uint64_t *ptr; int error = 0; int loopmode = 0; int pass =0; getaddrargs(cmd,&wtype,&addr,&len); wlen = 8; addr &= ~(wlen-1); if ((prev_wtype & ATYPE_TYPE_MASK) == ATYPE_TYPE_PHYS) { addr = UNCADDR(addr); } if (cmd_sw_isset(cmd,"-loop")) { loopmode = 1; } len /= wlen; ptr = (uint64_t *) addr; pass = 0; for (;;) { if (loopmode) { printf("Pass %d\n",pass); if (console_status()) break; } MEMTEST(ptr,len,(idx*8)); MEMTEST(ptr,len, 0); MEMTEST(ptr,len,0xFFFFFFFFFFFFFFFFLL); MEMTEST(ptr,len,0x5555555555555555LL); MEMTEST(ptr,len,0xAAAAAAAAAAAAAAAALL); MEMTEST(ptr,len,0xFF00FF00FF00FF00LL); MEMTEST(ptr,len,0x00FF00FF00FF00FFLL); if (!loopmode) break; pass++; } return 0; }
/* * board_final_init() * * Do any final initialization, such as adding commands to the * user interface. * * If you don't want a user interface, put the startup code here. * This routine is called just before CFE starts its user interface. * * Input parameters: * nothing * * Return value: * nothing */ void board_final_init(void) { char *addr, *mask, *wait_time; char buf[512], *cur = buf; #ifdef CFG_ROMBOOT char *laddr = NULL; #endif #if !CFG_SIM char *boot_cfg = NULL; char *go_cmd = "go;"; #endif int commit = 0; uint32 ncdl; #if CFG_WL && CFG_WLU && CFG_SIM char *ssid; #endif ui_init_bcm947xxcmds(); /* Force commit of embedded NVRAM */ commit = restore_defaults; /* Set the SDRAM NCDL value into NVRAM if not already done */ if ((getintvar(NULL, "sdram_ncdl") == 0) && ((ncdl = si_memc_get_ncdl(sih)) != 0)) { sprintf(buf, "0x%x", ncdl); nvram_set("sdram_ncdl", buf); commit = 1; } /* Set the bootloader version string if not already done */ sprintf(buf, "CFE %s", EPI_VERSION_STR); if (strcmp(nvram_safe_get("pmon_ver"), buf) != 0) { nvram_set("pmon_ver", buf); commit = 1; } /* Set the size of the nvram area if not already done */ sprintf(buf, "%d", MAX_NVRAM_SPACE); if (strcmp(nvram_safe_get("nvram_space"), buf) != 0) { nvram_set("nvram_space", buf); commit = 1; } #ifdef RTL8365MB int ret = -1, retry = 0; rtk_port_mac_ability_t pa; GPIO_INIT(); for(retry = 0; ret && retry < 10; ++retry) { ret = rtk_switch_init(); if(ret) cfe_usleep(10000); else break; } printf("rtl8354mb initialized(%d)(retry %d) %s\n", ret, retry, ret?"failed":""); ret = rtk_port_phyEnableAll_set(1); if(ret) printf("rtk port_phyEnableAll Failed!(%d)\n", ret); else printf("rtk port_phyEnableAll ok\n"); /* configure & set GMAC ports */ pa.forcemode = MAC_FORCE; pa.speed = SPD_1000M; pa.duplex = FULL_DUPLEX; pa.link = 1; pa.nway = 0; pa.rxpause = 0; pa.txpause = 0; ret = rtk_port_macForceLinkExt_set(EXT_PORT0, MODE_EXT_RGMII, &pa); if(ret) printf("rtk port_macForceLink_set ext_Port0 Failed!(%d)\n", ret); else printf("rtk port_macForceLink_set ext_Port0 ok\n"); /* asic chk */ rtk_uint32 retVal, retVal2; rtk_uint32 data, data2; if((retVal = rtl8367c_getAsicReg(0x1311, &data)) != RT_ERR_OK || (retVal2 = rtl8367c_getAsicReg(0x1305, &data2)) != RT_ERR_OK) { printf("get failed(%d)(%d). (%x)(supposed to be 0x1016)\n", retVal, retVal2, data); } else { /* get ok, then chk reg*/ printf("get ok, chk 0x1311:%x(0x1016), 0x1305:%x(b4~b7:0x1)\n", data, data2); if(data != 0x1016){ printf("\n!! rtl reg 0x1311 error: (%d)(get %x)\n", retVal, data); } if((data2 & 0xf0) != 0x10) { printf("\n!! rtl reg 0x1305 error: (%d)(get %x)\n", retVal, data2); } } /* reset tx/rx delay */ retVal = rtk_port_rgmiiDelayExt_set(EXT_PORT0, 1, 4); if (retVal != RT_ERR_OK) printf("\n!! rtl set delay failed (%d)\n", retVal); #endif #if CFG_FLASH || CFG_SFLASH || CFG_NFLASH #if !CFG_SIM /* Commit NVRAM only if in FLASH */ if ( #ifdef BCMNVRAMW !nvram_inotp() && #endif commit) { printf("Committing NVRAM..."); nvram_commit(); printf("done\n"); if (restore_defaults) { #ifdef BCM_DEVINFO /* devinfo nvram hash table sync */ devinfo_nvram_sync(); #endif printf("Waiting for wps button release..."); reset_release_wait(); printf("done\n"); } } /* Reboot after restoring defaults */ if (restore_defaults) si_watchdog(sih, 1); #endif /* !CFG_SIM */ #else if (commit) printf("Flash not configured, not commiting NVRAM...\n"); #endif /* CFG_FLASH || CFG_SFLASH || CFG_NFLASH */ /* * Read the wait_time NVRAM variable and set the tftp max retries. * Assumption: tftp_rrq_timeout & tftp_recv_timeout are set to 1sec. */ if ((wait_time = nvram_get("wait_time")) != NULL) { tftp_max_retries = atoi(wait_time); if (tftp_max_retries > MAX_WAIT_TIME) tftp_max_retries = MAX_WAIT_TIME; else if (tftp_max_retries < MIN_WAIT_TIME) tftp_max_retries = MIN_WAIT_TIME; } #ifdef CFG_ROMBOOT else if (board_bootdev_rom(sih)) { tftp_max_retries = 10; } #endif /* Configure network */ if (cfe_finddev("eth0")) { int res; if ((addr = nvram_get("lan_ipaddr")) && (mask = nvram_get("lan_netmask"))) sprintf(buf, "ifconfig eth0 -addr=%s -mask=%s", addr, mask); else sprintf(buf, "ifconfig eth0 -auto"); res = ui_docommand(buf); #ifdef CFG_ROMBOOT /* Try indefinite netboot only while booting from ROM * and we are sure that we dont have valid nvram in FLASH */ while (board_bootdev_rom(sih) && !addr) { char ch; cur = buf; /* Check if something typed at console */ if (console_status()) { console_read(&ch, 1); /* Check for Ctrl-C */ if (ch == 3) { if (laddr) MFREE(osh, laddr, MAX_SCRIPT_FSIZE); xprintf("Stopped auto netboot!!!\n"); return; } } if (!res) { char *bserver, *bfile, *load_ptr; if (!laddr) laddr = MALLOC(osh, MAX_SCRIPT_FSIZE); if (!laddr) { load_ptr = (char *) 0x00008000; xprintf("Failed malloc for boot_script, Using :0x%x\n", (unsigned int)laddr); } else { load_ptr = laddr; } bserver = (bserver = env_getenv("BOOT_SERVER")) ? bserver:"192.168.1.1"; if ((bfile = env_getenv("BOOT_FILE"))) { int len; if (((len = strlen(bfile)) > 5) && !strncmp((bfile + len - 5), "cfesh", 5)) { cur += sprintf(cur, "batch -raw -tftp -addr=0x%x -max=0x%x %s:%s;", (unsigned int)load_ptr, MAX_SCRIPT_FSIZE, bserver, bfile); } if (((len = strlen(bfile)) > 3)) { if (!strncmp((bfile + len - 3), "elf", 3)) { cur += sprintf(cur, "boot -elf -tftp -max=0x5000000 %s:%s;", bserver, bfile); } if (!strncmp((bfile + len - 3), "raw", 3)) { cur += sprintf(cur, "boot -raw -z -tftp -addr=0x00008000" " -max=0x5000000 %s:%s;", bserver, bfile); } } } else { /* Make last effort */ cur += sprintf(cur, "batch -raw -tftp -addr=0x%x -max=0x%x %s:%s;", (unsigned int)load_ptr, MAX_SCRIPT_FSIZE, bserver, "cfe_script.cfesh"); cur += sprintf(cur, "boot -elf -tftp -max=0x5000000 %s:%s;", bserver, "boot_file.elf"); cur += sprintf(cur, "boot -raw -z -tftp -addr=0x00008000" " -max=0x5000000 %s:%s;", bserver, "boot_file.raw"); } ui_docommand(buf); cfe_sleep(3*CFE_HZ); } sprintf(buf, "ifconfig eth0 -auto"); res = ui_docommand(buf); } #endif /* CFG_ROMBOOT */ } #if CFG_WL && CFG_WLU && CFG_SIM if ((ssid = nvram_get("wl0_ssid"))) { sprintf(buf, "wl join %s", ssid); ui_docommand(buf); } #endif #if !CFG_SIM /* Try to run boot_config command if configured. * make sure to leave space for "go" command. */ if ((boot_cfg = nvram_get("boot_config"))) { if (strlen(boot_cfg) < (sizeof(buf) - sizeof(go_cmd))) cur += sprintf(cur, "%s;", boot_cfg); else printf("boot_config too long, skipping to autoboot\n"); } /* Boot image */ cur += sprintf(cur, go_cmd); #endif /* !CFG_SIM */ /* Startup */ if (cur > buf) env_setenv("STARTUP", buf, ENV_FLG_NORMAL); }
static int _tftpd_open(tftp_info_t *info,char *hostname,char *filename,int mode) { ebuf_t *buf = NULL; uint16_t type; int res; int retries; char ch = 0; /* * Open a UDP socket */ info->tftp_socket = udp_socket(UDP_PROTO_TFTP); info->tftp_lastblock = 0; info->tftp_error = 0; info->tftp_filemode = mode; /* * Listen for requests */ res = udp_bind(info->tftp_socket,UDP_PROTO_TFTP); if (res < 0) return res; res = CFE_ERR_TIMEOUT; for (retries = 0; retries < tftp_max_retries; retries++) { while (console_status()) { console_read(&ch,1); if (ch == 3) break; } if (ch == 3) { res = CFE_ERR_INTR; break; } buf = udp_recv_with_timeout(info->tftp_socket,tftp_recv_timeout); if (buf == NULL) continue; /* * Process the request */ ebuf_get_u16_be(buf,type); switch (type) { case TFTP_OP_RRQ: udp_connect(info->tftp_socket,(uint16_t) buf->eb_usrdata); memcpy(info->tftp_ipaddr,buf->eb_usrptr,IP_ADDR_LEN); info->tftp_blknum = 1; info->tftp_blklen = 0; res = 0; break; case TFTP_OP_WRQ: udp_connect(info->tftp_socket,(uint16_t) buf->eb_usrdata); memcpy(info->tftp_ipaddr,buf->eb_usrptr,IP_ADDR_LEN); info->tftp_blknum = 0; res = _tftp_readmore(info); break; default: /* * we aren't expecting any of these messages */ res = CFE_ERR_PROTOCOLERR; break; } udp_free(buf); break; } if (res) { udp_close(info->tftp_socket); info->tftp_socket = -1; } return res; }
void notmain(void) { _output_type output_type = OUTPUT_TYPE_MONITOR; uint8_t mac_address[6] ALIGNED; struct ip_info ip_config; E131Params e131params; DMXParams dmxparams; uuid_t uuid; char uuid_str[UUID_STRING_LENGTH + 1] ALIGNED; hardware_init(); (void) e131params.Load(); if (e131params.isHaveCustomCid()) { memcpy(uuid_str, e131params.GetCidString(), UUID_STRING_LENGTH); uuid_str[UUID_STRING_LENGTH] = '\0'; uuid_parse((const char *)uuid_str, uuid); } else { hardware_uuid(uuid); uuid_unparse(uuid, uuid_str); } output_type = e131params.GetOutputType(); if (output_type == OUTPUT_TYPE_MONITOR) { // } else { output_type = OUTPUT_TYPE_DMX; (void) dmxparams.Load(); } printf("[V%s] %s Compiled on %s at %s\n", SOFTWARE_VERSION, hardware_board_get_model(), __DATE__, __TIME__); printf("WiFi sACN E.131 DMX Out / Real-time DMX Monitor"); console_set_top_row(3); (void) ap_params_init(); const char *ap_password = ap_params_get_password(); hardware_watchdog_init(); console_status(CONSOLE_YELLOW, "Starting Wifi ..."); wifi_init(ap_password); hardware_watchdog_stop(); printf("ESP8266 information\n"); printf(" SDK : %s\n", system_get_sdk_version()); printf(" Firmware : %s\n\n", wifi_get_firmware_version()); if (network_params_init()) { console_status(CONSOLE_YELLOW, "Changing to Station mode ..."); if (network_params_is_use_dhcp()) { wifi_station(network_params_get_ssid(), network_params_get_password()); } else { ip_config.ip.addr = network_params_get_ip_address(); ip_config.netmask.addr = network_params_get_net_mask(); ip_config.gw.addr = network_params_get_default_gateway(); wifi_station_ip(network_params_get_ssid(), network_params_get_password(), &ip_config); } } const _wifi_mode opmode = wifi_get_opmode(); if (opmode == WIFI_STA) { printf("WiFi mode : Station\n"); } else { printf("WiFi mode : Access Point (authenticate mode : %s)\n", *ap_password == '\0' ? "Open" : "WPA_WPA2_PSK"); } if (wifi_get_macaddr(mac_address)) { printf(" MAC address : "MACSTR "\n", MAC2STR(mac_address)); } else { console_error("wifi_get_macaddr"); } printf(" Hostname : %s\n", wifi_station_get_hostname()); if (wifi_get_ip_info(&ip_config)) { printf(" IP-address : " IPSTR "\n", IP2STR(ip_config.ip.addr)); printf(" Netmask : " IPSTR "\n", IP2STR(ip_config.netmask.addr)); printf(" Gateway : " IPSTR "\n", IP2STR(ip_config.gw.addr)); if (opmode == WIFI_STA) { const _wifi_station_status status = wifi_station_get_connect_status(); printf(" Status : %s\n", wifi_station_status(status)); if (status != WIFI_STATION_GOT_IP){ console_error("Not connected!"); for(;;); } } } else { console_error("wifi_get_ip_info"); } if (fota_params_init()) { console_newline(); fota(fota_params_get_server()); for(;;); } console_status(CONSOLE_YELLOW, "Starting UDP ..."); udp_begin(E131_DEFAULT_PORT); console_status(CONSOLE_YELLOW, "Join group ..."); uint32_t group_ip; (void)inet_aton("239.255.0.0", &group_ip); const uint16_t universe = e131params.GetUniverse(); group_ip = group_ip | ((uint32_t)(((uint32_t)universe & (uint32_t)0xFF) << 24)) | ((uint32_t)(((uint32_t)universe & (uint32_t)0xFF00) << 8)); udp_joingroup(group_ip); E131Bridge bridge; DMXSend dmx; DMXMonitor monitor; bridge.setCid(uuid); bridge.setUniverse(universe); bridge.setMergeMode(e131params.GetMergeMode()); if (output_type == OUTPUT_TYPE_MONITOR) { bridge.SetOutput(&monitor); console_set_top_row(20); } else { bridge.SetOutput(&dmx); dmx.SetBreakTime(dmxparams.GetBreakTime()); dmx.SetMabTime(dmxparams.GetMabTime()); const uint8_t refresh_rate = dmxparams.GetRefreshRate(); uint32_t period = (uint32_t) 0; if (refresh_rate != (uint8_t) 0) { period = (uint32_t) (1E6 / refresh_rate); } dmx.SetPeriodTime(period); } printf("\nBridge configuration\n"); const uint8_t *firmware_version = bridge.GetSoftwareVersion(); printf(" Firmware : %d.%d\n", firmware_version[0], firmware_version[1]); printf(" CID : %s\n", uuid_str); printf(" Universe : %d\n", bridge.getUniverse()); printf(" Merge mode : %s\n", bridge.getMergeMode() == E131_MERGE_HTP ? "HTP" : "LTP"); printf(" Multicast ip : " IPSTR "\n", IP2STR(group_ip)); printf(" Unicast ip : " IPSTR "\n\n", IP2STR(ip_config.ip.addr)); if (output_type == OUTPUT_TYPE_DMX) { printf("DMX Send parameters\n"); printf(" Break time : %d\n", (int) dmx.GetBreakTime()); printf(" MAB time : %d\n", (int) dmx.GetMabTime()); printf(" Refresh rate : %d\n", (int) (1E6 / dmx.GetPeriodTime())); } hardware_watchdog_init(); console_status(CONSOLE_GREEN, "Bridge is running"); for (;;) { hardware_watchdog_feed(); (void) bridge.Run(); led_blink(); } }
const bool wifi(const struct ip_info *info) { uint8_t mac_address[6] ALIGNED; char *ap_password = NULL; struct ip_info ip_config; oled_info_t oled_info = { OLED_128x64_I2C_DEFAULT }; const bool oled_connected = oled_start(&oled_info); if (!wifi_detect()){ (void) console_status(CONSOLE_YELLOW, WIFI_NOT_CONNECTED); OLED_CONNECTED(oled_connected, oled_puts(&oled_info, WIFI_NOT_CONNECTED)); return false; } (void) ap_params_init(); ap_password = (char *) ap_params_get_password(); (void) console_status(CONSOLE_YELLOW, STARTING_WIFI); OLED_CONNECTED(oled_connected, oled_status(&oled_info, STARTING_WIFI)); wifi_ap_init(ap_password); printf("ESP8266 information\n"); printf(" SDK : %s\n", system_get_sdk_version()); printf(" Firmware : %s\n\n", wifi_get_firmware_version()); if (network_params_init()) { (void) console_status(CONSOLE_YELLOW, CHANGING_TO_STATION_MODE); OLED_CONNECTED(oled_connected, oled_status(&oled_info, CHANGING_TO_STATION_MODE)); ssid = network_params_get_ssid(); if (network_params_is_use_dhcp()) { wifi_station(ssid, network_params_get_password()); } else { ip_config.ip.addr = network_params_get_ip_address(); ip_config.netmask.addr = network_params_get_net_mask(); ip_config.gw.addr = network_params_get_default_gateway(); wifi_station_ip(ssid, network_params_get_password(), &ip_config); } } opmode = wifi_get_opmode(); if (opmode == WIFI_STA) { printf("WiFi mode : Station (AP: %s)\n", network_params_get_ssid()); } else { printf("WiFi mode : Access Point (authenticate mode: %s)\n", *ap_password == '\0' ? "Open" : "WPA_WPA2_PSK"); } if (wifi_get_macaddr(mac_address)) { printf(" MAC address : "MACSTR "\n", MAC2STR(mac_address)); } else { (void) console_error("wifi_get_macaddr"); OLED_CONNECTED(oled_connected, oled_status(&oled_info, "E: wifi_get_macaddr")); } printf(" Hostname : %s\n", wifi_get_hostname()); if (wifi_get_ip_info(&ip_config)) { printf(" IP-address : " IPSTR "\n", IP2STR(ip_config.ip.addr)); printf(" Netmask : " IPSTR "\n", IP2STR(ip_config.netmask.addr)); printf(" Gateway : " IPSTR "\n", IP2STR(ip_config.gw.addr)); if (opmode == WIFI_STA) { const _wifi_station_status status = wifi_station_get_connect_status(); printf(" Status : %s\n", wifi_station_status(status)); if (status != WIFI_STATION_GOT_IP) { (void) console_error("Not connected!"); if (oled_connected) { oled_set_cursor(&oled_info, 2, 0); (void) oled_puts(&oled_info, wifi_station_status(status)); oled_set_cursor(&oled_info, 5, 0); (void) oled_printf(&oled_info, "SSID : %s\n", network_params_get_ssid()); oled_status(&oled_info, "E: Not connected!"); } for (;;) ; } } } else { (void) console_error("wifi_get_ip_info"); OLED_CONNECTED(oled_connected, oled_status(&oled_info, "E: wifi_get_ip_info")); } if (fota_params_init()) { OLED_CONNECTED(oled_connected, oled_status(&oled_info, "FOTA mode")); console_newline(); fota(fota_params_get_server()); for (;;) ; } (void) console_status(CONSOLE_GREEN, WIFI_STARTED); OLED_CONNECTED(oled_connected, oled_status(&oled_info, WIFI_STARTED)); memcpy((void *)info, (const void *)&ip_config, sizeof(struct ip_info)); return true; }
/* * board_final_init() * * Do any final initialization, such as adding commands to the * user interface. * * If you don't want a user interface, put the startup code here. * This routine is called just before CFE starts its user interface. * * Input parameters: * nothing * * Return value: * nothing */ void board_final_init(void) { char *addr, *mask, *wait_time; char buf[512], *cur = buf; #ifdef CFG_ROMBOOT char *laddr = NULL; #endif #if !CFG_SIM char *boot_cfg = NULL; char *go_cmd = "go;"; #endif int commit = 0; uint32 ncdl; #if CFG_WL && CFG_WLU && CFG_SIM char *ssid; #endif ui_init_bcm947xxcmds(); /* Force commit of embedded NVRAM */ // commit = restore_defaults; commit = 0; /* Set the SDRAM NCDL value into NVRAM if not already done */ if ((getintvar(NULL, "sdram_ncdl") == 0) && ((ncdl = si_memc_get_ncdl(sih)) != 0)) { sprintf(buf, "0x%x", ncdl); nvram_set("sdram_ncdl", buf); commit = 1; } /* Set the bootloader version string if not already done */ sprintf(buf, "CFE %s", EPI_VERSION_STR); if (strcmp(nvram_safe_get("pmon_ver"), buf) != 0) { nvram_set("pmon_ver", buf); commit = 1; } /* Set the size of the nvram area if not already done */ sprintf(buf, "%d", MAX_NVRAM_SPACE); if (strcmp(nvram_safe_get("nvram_space"), buf) != 0) { nvram_set("nvram_space", buf); commit = 1; } #if CFG_FLASH || CFG_SFLASH || CFG_NFLASH #if !CFG_SIM /* Commit NVRAM only if in FLASH */ if ( #ifdef BCMNVRAMW !nvram_inotp() && #endif commit) { printf("Committing NVRAM..."); nvram_commit(); printf("done\n"); if (restore_defaults) { printf("Waiting for reset button release..."); reset_release_wait(); printf("done\n"); } } /* Reboot after restoring defaults */ if (restore_defaults) si_watchdog(sih, 1); #endif /* !CFG_SIM */ #else if (commit) printf("Flash not configured, not commiting NVRAM...\n"); #endif /* CFG_FLASH || CFG_SFLASH || CFG_NFLASH */ /* * Read the wait_time NVRAM variable and set the tftp max retries. * Assumption: tftp_rrq_timeout & tftp_recv_timeout are set to 1sec. */ if ((wait_time = nvram_get("wait_time")) != NULL) { tftp_max_retries = atoi(wait_time); if (tftp_max_retries > MAX_WAIT_TIME) tftp_max_retries = MAX_WAIT_TIME; else if (tftp_max_retries < MIN_WAIT_TIME) tftp_max_retries = MIN_WAIT_TIME; } #ifdef CFG_ROMBOOT else if (board_bootdev_rom(sih)) { tftp_max_retries = 10; } #endif /* Configure network */ if (cfe_finddev("eth0")) { int res; if ((addr = nvram_get("lan_ipaddr")) && (mask = nvram_get("lan_netmask"))) sprintf(buf, "ifconfig eth0 -addr=%s -mask=%s", addr, mask); else sprintf(buf, "ifconfig eth0 -auto"); res = ui_docommand(buf); #ifdef CFG_ROMBOOT /* Try indefinite netboot only while booting from ROM * and we are sure that we dont have valid nvram in FLASH */ while (board_bootdev_rom(sih) && !addr) { char ch; cur = buf; /* Check if something typed at console */ if (console_status()) { console_read(&ch, 1); /* Check for Ctrl-C */ if (ch == 3) { if (laddr) MFREE(osh, laddr, MAX_SCRIPT_FSIZE); xprintf("Stopped auto netboot!!!\n"); return; } } if (!res) { char *bserver, *bfile, *load_ptr; if (!laddr) laddr = MALLOC(osh, MAX_SCRIPT_FSIZE); if (!laddr) { load_ptr = (char *) 0x00008000; xprintf("Failed malloc for boot_script, Using :0x%x\n", (unsigned int)laddr); } else { load_ptr = laddr; } bserver = (bserver = env_getenv("BOOT_SERVER")) ? bserver:"192.168.1.1"; if ((bfile = env_getenv("BOOT_FILE"))) { int len; if (((len = strlen(bfile)) > 5) && !strncmp((bfile + len - 5), "cfesh", 5)) { cur += sprintf(cur, "batch -raw -tftp -addr=0x%x -max=0x%x %s:%s;", (unsigned int)load_ptr, MAX_SCRIPT_FSIZE, bserver, bfile); } if (((len = strlen(bfile)) > 3)) { if (!strncmp((bfile + len - 3), "elf", 3)) { cur += sprintf(cur, "boot -elf -tftp -max=0x5000000 %s:%s;", bserver, bfile); } if (!strncmp((bfile + len - 3), "raw", 3)) { cur += sprintf(cur, "boot -raw -z -tftp -addr=0x00008000" " -max=0x5000000 %s:%s;", bserver, bfile); } } } else { /* Make last effort */ cur += sprintf(cur, "batch -raw -tftp -addr=0x%x -max=0x%x %s:%s;", (unsigned int)load_ptr, MAX_SCRIPT_FSIZE, bserver, "cfe_script.cfesh"); cur += sprintf(cur, "boot -elf -tftp -max=0x5000000 %s:%s;", bserver, "boot_file.elf"); cur += sprintf(cur, "boot -raw -z -tftp -addr=0x00008000" " -max=0x5000000 %s:%s;", bserver, "boot_file.raw"); } ui_docommand(buf); cfe_sleep(3*CFE_HZ); } sprintf(buf, "ifconfig eth0 -auto"); res = ui_docommand(buf); } #endif /* CFG_ROMBOOT */ } #if CFG_WL && CFG_WLU && CFG_SIM if ((ssid = nvram_get("wl0_ssid"))) { sprintf(buf, "wl join %s", ssid); ui_docommand(buf); } #endif #if !CFG_SIM /* Try to run boot_config command if configured. * make sure to leave space for "go" command. */ if ((boot_cfg = nvram_get("boot_config"))) { if (strlen(boot_cfg) < (sizeof(buf) - sizeof(go_cmd))) cur += sprintf(cur, "%s;", boot_cfg); else printf("boot_config too long, skipping to autoboot\n"); } /* Boot image */ cur += sprintf(cur, go_cmd); #endif /* !CFG_SIM */ /* Startup */ if (cur > buf) env_setenv("STARTUP", buf, ENV_FLG_NORMAL); }
int console_readline(char *prompt,char *str,int maxlen) { int reading = 1; int ch; int idx = 0; int len = 0; int t; int klen; int recall; int nosave = 0; char *x; char env[10]; console_inreadline++; recall = console_nextsave; if (console_savedlines[console_nextsave]) { KFREE(console_savedlines[console_nextsave]); console_savedlines[console_nextsave] = NULL; } console_savedlines[console_nextsave] = strdup(""); if (prompt && *prompt) console_write(prompt,strlen(prompt)); POLL(); while (reading) { /* * If someone used console_log (above) or hit Control-C (below), * redisplay the prompt and the string we've got so far. */ if (console_redisplay) { if (prompt && *prompt) console_write(prompt,strlen(prompt)); console_write(str,idx); console_redisplay = 0; continue; } #if defined(CONFIG_MIPS_BRCM) /* * If a background process has set the global g_console_abort flag, stop * reading from the keyboard. */ if (g_console_abort) { g_console_abort = 0; break; } #endif /* * if nobody's typed anything, keep polling */ if (console_status() == 0) { POLL(); continue; } /* * Get the char from the keyboard */ ch = console_readkey(); if (ch < 0) break; if (ch == 0) continue; /* * And dispatch it. Lots of yucky character manipulation follows */ switch (ch) { case CTRL('C'): /* Ctrl-C - cancel line */ console_write("^C\r\n",4); console_redisplay = 1; nosave = 1; idx = 0; break; case 0x7f: /* Backspace, Delete */ case CTRL('H'): if (idx > 0) { nosave = 0; len--; idx--; console_write("\b",1); if (len != idx) { for (t = idx; t < len; t++) str[t] = str[t+1]; console_write(&str[idx],len-idx); console_whiteout(1); console_backspace(len-idx); } else { console_whiteout(1); } } break; case CTRL('D'): /* Ctrl-D */ if ((idx >= 0) && (len != idx)) { nosave = 0; len--; for (t = idx; t < len; t++) str[t] = str[t+1]; console_write(&str[idx],len-idx); console_whiteout(1); console_backspace(len-idx); } break; case CTRL('B'): /* cursor left */ case VKEY_LEFT: if (idx > 0) { idx--; console_backspace(1); } break; case CTRL('F'): /* cursor right */ case VKEY_RIGHT: if (idx < len) { console_write(&str[idx],1); idx++; } break; case CTRL('A'): /* cursor to BOL */ console_backspace(idx); idx = 0; break; case CTRL('E'): /* cursor to EOL */ if (len-idx > 0) console_write(&str[idx],len-idx); idx = len; break; case CTRL('K'): /* Kill to EOL */ if (idx != len) { str[len] = '\0'; if (console_killbuffer) KFREE(console_killbuffer); console_killbuffer = strdup(&str[idx]); console_whiteout(len-idx); len = idx; nosave = 0; } break; case CTRL('Y'): /* Yank killed data */ if (console_killbuffer == NULL) break; klen = strlen(console_killbuffer); if (klen == 0) break; if (len + klen > maxlen) break; nosave = 0; for (t = len + klen; t > idx; t--) { str[t-1] = str[t-klen-1]; } for (t = 0; t < klen; t++) str[t+idx] = console_killbuffer[t]; len += klen; console_write(&str[idx],len-idx); idx += klen; console_backspace(len-idx-1); break; case CTRL('R'): /* Redisplay line */ str[len] = 0; console_crlf(); console_write(prompt,strlen(prompt)); console_write(str,len); console_backspace(len-idx); break; case CTRL('U'): /* Cancel line */ console_backspace(idx); console_eraseeol(); if (len > 0) nosave = 1; idx = 0; len = 0; break; case CTRL('M'): /* terminate */ case CTRL('J'): console_crlf(); reading = 0; break; case CTRL('P'): case VKEY_UP: /* recall previous line */ t = recall; t--; if (t < 0) t = MAXSAVELINES-1; if (console_savedlines[t] == NULL) break; recall = t; console_backspace(idx); strcpy(str,console_savedlines[recall]); len = idx = strlen(console_savedlines[recall]); console_eraseeol(); console_write(str,len); nosave = (t == ((console_nextsave - 1) % MAXSAVELINES)); break; case CTRL('N'): case VKEY_DOWN: /* Recall next line */ t = recall; t++; if (t == MAXSAVELINES) t = 0; if (console_savedlines[t] == NULL) break; recall = t; console_backspace(idx); strcpy(str,console_savedlines[recall]); len = idx = strlen(console_savedlines[recall]); console_eraseeol(); console_write(str,len); nosave = 1; break; case VKEY_F1: case VKEY_F2: case VKEY_F3: case VKEY_F4: case VKEY_F5: case VKEY_F6: case VKEY_F7: case VKEY_F8: case VKEY_F9: case VKEY_F10: case VKEY_F11: case VKEY_F12: sprintf(env,"F%d",ch-VKEY_F1+1); x = env_getenv(env); if (x) { console_backspace(idx); strcpy(str,x); idx = len = strlen(str); console_eraseeol(); console_write(str,len); console_crlf(); reading = 0; nosave = 1; } /* * If F12 is undefined, it means "repeat last command" */ if (ch == VKEY_F12) { t = recall; t--; if (t < 0) t = MAXSAVELINES-1; if (console_savedlines[t] == NULL) break; recall = t; console_backspace(idx); strcpy(str,console_savedlines[recall]); len = idx = strlen(console_savedlines[recall]); console_eraseeol(); console_write(str,len); console_crlf(); reading = 0; nosave = 1; } break; default: /* insert character */ if (ch >= ' ') { if (idx < (maxlen-1)) { nosave = 0; for (t = len; t > idx; t--) { str[t] = str[t-1]; } str[idx] = ch; len++; if (len != idx) { console_write(&str[idx],len-idx); console_backspace(len-idx-1); } idx++; } } break; } } POLL(); console_inreadline--; str[len] = 0; if ((len != 0) && !nosave) { if (console_savedlines[console_nextsave]) { KFREE(console_savedlines[console_nextsave]); } console_savedlines[console_nextsave] = strdup(str); console_nextsave++; if (console_nextsave == MAXSAVELINES) console_nextsave = 0; } return len; }
int console_readline_noedit(char *prompt,char *str,int len) { int reading = 1; char ch; int res = -1; int idx = 0; console_inreadline++; if (prompt && *prompt) console_write(prompt,strlen(prompt)); POLL(); while (reading) { /* * If someone used console_log (above) or hit Control-C (below), * redisplay the prompt and the string we've got so far. */ if (console_redisplay) { if (prompt && *prompt) console_write(prompt,strlen(prompt)); console_write(str,idx); console_redisplay = 0; continue; } #if defined(CONFIG_MIPS_BRCM) /* * If a background process has set the global g_console_abort flag, stop * reading from the keyboard. */ if (g_console_abort) { g_console_abort = 0; break; } #endif /* * if nobody's typed anything, keep polling */ if (console_status() == 0) { POLL(); continue; } /* * Get the char from the keyboard */ res = console_read(&ch,1); if (res < 0) break; if (res == 0) continue; /* * And dispatch it */ switch (ch) { case 3: /* Ctrl-C */ console_write("^C\r\n",4); console_redisplay = 1; idx = 0; break; case 0x7f: case '\b': if (idx > 0) { idx--; console_write("\b \b",3); } break; case 21: /* Ctrl-U */ while (idx > 0) { idx--; console_write("\b \b",3); } break; case '\r': case '\n': console_write("\r\n",2); reading = 0; break; default: if (ch >= ' ') { if (idx < (len-1)) { str[idx] = ch; idx++; console_write(&ch,1); } } break; } } POLL(); console_inreadline--; str[idx] = 0; return idx; }
static int _tftpd_open(tftp_info_t *info,char *hostname,char *filename,int mode) { ebuf_t *buf = NULL; uint16_t type; int res; int retries; char ch = 0; #ifdef RESCUE_MODE uint8_t asuslink[13] = "ASUSSPACELINK"; uint8_t maclink[13]="snxxxxxxxxxxx"; unsigned char tftpmask[4] = { 0xff, 0xff, 0xff, 0x00 }; int i; char tftpnull; uint8_t ipaddr[4] = { 0xc0, 0xa8, 0x01, 0x0c }; uint8_t hwaddr[6] = { 0x00, 0xe0, 0x18, 0x00, 0x3e, 0xc4 }; #endif /* * Open a UDP socket */ info->tftp_socket = udp_socket(UDP_PROTO_TFTP); info->tftp_lastblock = 0; info->tftp_error = 0; info->tftp_filemode = mode; /* * Listen for requests */ res = udp_bind(info->tftp_socket,UDP_PROTO_TFTP); if (res < 0) return res; res = CFE_ERR_TIMEOUT; for (retries = 0; retries < tftp_max_retries; retries++) { while (console_status()) { console_read(&ch,1); if (ch == 3) break; } if (ch == 3) { res = CFE_ERR_INTR; break; } buf = udp_recv_with_timeout(info->tftp_socket,tftp_recv_timeout); if (buf == NULL) continue; /* * Process the request */ ebuf_get_u16_be(buf,type); switch (type) { case TFTP_OP_RRQ: #ifdef RESCUE_MODE udp_connect(info->tftp_socket,(uint16_t) buf->eb_usrdata); ackport = buf->eb_usrdata; memcpy(info->tftp_ipaddr,buf->eb_usrptr,IP_ADDR_LEN); info->tftp_blknum = 1; info->tftp_blklen = 0; for (i=0; i<13; i++) { if (buf->eb_ptr[i] != asuslink[i]) break; } if (i==13) { tftpipfrom[0]=buf->eb_ptr[16]; tftpipfrom[1]=buf->eb_ptr[15]; tftpipfrom[2]=buf->eb_ptr[14]; tftpipfrom[3]=buf->eb_ptr[13]; tftpipto[0]=buf->eb_usrptr[0]; tftpipto[1]=buf->eb_usrptr[1]; tftpipto[2]=buf->eb_usrptr[2]; tftpipto[3]=buf->eb_usrptr[3]; net_setparam(NET_IPADDR,tftpipfrom); net_setparam(NET_NETMASK,tftpmask); net_setparam(NET_GATEWAY,tftpipfrom); ui_myshowifconfig(); net_setnetvars(); for (i=0; i<4; i++) ipaddr[i]=tftpipto[i]; for (i=0; i<6; i++) hwaddr[i]=buf->eb_data[6+i]; buf = udp_alloc(); if (!buf) { res = CFE_ERR_TIMEOUT; break; } ebuf_append_u16_be(buf, 3); ebuf_append_u16_be(buf, 1); ebuf_append_bytes(buf,&tftpnull, 0); arp_delete(ipaddr); arp_add(ipaddr,hwaddr); udp_send(info->tftp_socket, buf, tftpipto); } else { for (i=0; i<13; i++) { if (buf->eb_ptr[i] != maclink[i]) break; } if (i==13) { tftpipfrom[0]=buf->eb_ptr[16]; tftpipfrom[1]=buf->eb_ptr[15]; tftpipfrom[2]=buf->eb_ptr[14]; tftpipfrom[3]=buf->eb_ptr[13]; tftpipto[0]=buf->eb_usrptr[0]; tftpipto[1]=buf->eb_usrptr[1]; tftpipto[2]=buf->eb_usrptr[2]; tftpipto[3]=buf->eb_usrptr[3]; net_setparam(NET_IPADDR,tftpipfrom); net_setparam(NET_NETMASK,tftpmask); net_setparam(NET_GATEWAY,tftpipfrom); ui_myshowifconfig(); net_setnetvars(); for (i=0; i<4; i++) ipaddr[i]=tftpipto[i]; for (i=0; i<6; i++) hwaddr[i]=buf->eb_data[6+i]; buf = udp_alloc(); if (!buf) { res = CFE_ERR_TIMEOUT; break; } ebuf_append_u16_be(buf, 3); ebuf_append_u16_be(buf, 1); ebuf_append_bytes(buf,&tftpnull, 0); arp_delete(ipaddr); arp_add(ipaddr,hwaddr); udp_send(info->tftp_socket, buf, tftpipto); } } res = CFE_ERR_TIMEOUT; #else udp_connect(info->tftp_socket,(uint16_t) buf->eb_usrdata); memcpy(info->tftp_ipaddr,buf->eb_usrptr,IP_ADDR_LEN); info->tftp_blknum = 1; info->tftp_blklen = 0; res = 0; #endif break; case TFTP_OP_WRQ: udp_connect(info->tftp_socket,(uint16_t) buf->eb_usrdata); memcpy(info->tftp_ipaddr,buf->eb_usrptr,IP_ADDR_LEN); info->tftp_blknum = 0; res = _tftp_readmore(info); break; default: /* * we aren't expecting any of these messages */ res = CFE_ERR_PROTOCOLERR; break; } udp_free(buf); break; } if (res) { udp_close(info->tftp_socket); info->tftp_socket = -1; } return res; }
void notmain(void) { hardware_init(); ltc_reader_params_init(); output.console_output = ltc_reader_params_is_console_output(); output.lcd_output = ltc_reader_params_is_lcd_output(); output.midi_output = ltc_reader_params_is_midi_output(); output.artnet_output = ltc_reader_params_is_artnet_output(); if(output.midi_output) { midi_send_init(); } if (output.lcd_output) { output.lcd_output = lcd_detect(); } if (output.artnet_output) { output.artnet_output = wifi_detect(); } ltc_reader_init(&output); printf("[V%s] %s Compiled on %s at %s\n", SOFTWARE_VERSION, hardware_board_get_model(), __DATE__, __TIME__); printf("SMPTE TimeCode LTC Reader / Converter"); console_set_top_row(3); console_set_cursor(0, 12); console_puts("Console output : "); handle_bool(output.console_output); console_putc('\n'); console_puts("LCD output : "); handle_bool(output.lcd_output); console_putc('\n'); console_puts("MIDI output : "); handle_bool(output.midi_output); console_putc('\n'); console_puts("ArtNet output : "); handle_bool(output.artnet_output);console_puts(" (not implemented)\n"); if (output.artnet_output) { uint8_t mac_address[6]; struct ip_info ip_config; (void) ap_params_init(); const char *ap_password = ap_params_get_password(); console_status(CONSOLE_YELLOW, "Starting Wifi ..."); wifi_init(ap_password); printf("\nESP8266 information\n"); printf(" SDK : %s\n", system_get_sdk_version()); printf(" Firmware : %s\n\n", wifi_get_firmware_version()); if (network_params_init()) { console_status(CONSOLE_YELLOW, "Changing to Station mode ..."); if (network_params_is_use_dhcp()) { wifi_station(network_params_get_ssid(), network_params_get_password()); } else { ip_config.ip.addr = network_params_get_ip_address(); ip_config.netmask.addr = network_params_get_net_mask(); ip_config.gw.addr = network_params_get_default_gateway(); wifi_station_ip(network_params_get_ssid(), network_params_get_password(), &ip_config); } } const _wifi_mode opmode = wifi_get_opmode(); if (opmode == WIFI_STA) { printf("WiFi mode : Station\n"); } else { printf("WiFi mode : Access Point (authenticate mode : %s)\n", *ap_password == '\0' ? "Open" : "WPA_WPA2_PSK"); } if (wifi_get_macaddr(mac_address)) { printf(" MAC address : "MACSTR "\n", MAC2STR(mac_address)); } else { console_error("wifi_get_macaddr"); } printf(" Hostname : %s\n", wifi_station_get_hostname()); if (wifi_get_ip_info(&ip_config)) { printf(" IP-address : " IPSTR "\n", IP2STR(ip_config.ip.addr)); printf(" Netmask : " IPSTR "\n", IP2STR(ip_config.netmask.addr)); printf(" Gateway : " IPSTR "\n", IP2STR(ip_config.gw.addr)); if (opmode == WIFI_STA) { const _wifi_station_status status = wifi_station_get_connect_status(); printf(" Status : %s\n", wifi_station_status(status)); if (status != WIFI_STATION_GOT_IP){ console_error("Not connected!"); for(;;); } } } else { console_error("wifi_get_ip_info"); } console_status(CONSOLE_YELLOW, "Starting UDP ..."); udp_begin(6454); console_status(CONSOLE_GREEN, "Wifi is started"); } for (;;) { ltc_reader(); } }