📄 param.c
字号:
/*****************************************************************************;; Project : Edmiax; Creator :; File : param.c; Abstract: Configuration of network parameters to support TFTP ccode;;*****************************************************************************/#include <ctype.h>#include <param.h>#include <uartdrv.h>#include <buart_extra.h>#include <bsp_cfg.h>#include <adm5120.h>#include <linuxld.h>#include <mips4kc.h>#include <helpers.h>#include <test_def.h>#ifdef MODIFIEDSRCvoid Set_Mac();void Set_TFTP_IP();/************************************//* Initial boot parameters *//************************************/static BOARD_CFG_T cfg;/****************************//* Parameter Init *//****************************//* The original code reads the initial contents of the BOARD_CFG_T structure from FLASH, beginning at LINUXLD_FLASH_BOOTPARAM_START and that's about all it does. We're not storing it in FLASH. */void boot_param_init(){ /* Default MAC address */ cfg.mac[0] = 0x00; cfg.mac[1] = 0x12; cfg.mac[2] = 0x9A; cfg.mac[3] = 0x4C; cfg.mac[4] = 0x87; cfg.mac[5] = 0x01; cfg.mac[6] = 0x00; // not used cfg.mac[7] = 0x00; // not used /* Default local IP address 192.168.1.95 */ cfg.ip = (192 << 24) | (168 << 16) | (1 << 8) | 95; /* Default network mask 255.255.0.0 */ cfg.mask = (255 << 24) | (255 << 16); /* Default gateway IP address 192.168.1.2 */ cfg.gateway = (192 << 24) | (168 << 16) | (1 << 8) | 2; /* Default TFTP server IP address 192.168.1.98 */ cfg.server_ip = (192 << 24) | (168 << 16) | (1 << 8) | 98; /* Default remote TFTP server file to retrieve */ strcpy(cfg.remote_file, "test.bin");}/******************************************/ /* MAC Address *//******************************************/int GetMAC(unsigned char *buf){ char mactmp[24]; int rc = 0; if (buf != 0) { mactostr(cfg.mac, mactmp); mactmp[17] = '\0'; strcpy(buf, mactmp); rc = 1; } return rc;}void AskMAC(){ char buf[BOOT_LINE_SIZE + 1]; // 32 char mac[8], original_mac[8]; int macinvalid = 1; memcpy(mac, cfg.mac, 6); memcpy(original_mac, cfg.mac, 6); mac[6] = mac[7] = 0; while (macinvalid) { buart_print("\r\nEnter new MAC address (aa:bb:cc:dd:ee:ff): "); buf[0] = 0; ReadLine(buf, BOOT_LINE_SIZE); if (buf[0] == 0 && mac[0] == 0x00) { /* Keep the old one */ macinvalid = 0; } else { macinvalid = ((macscanf(mac, buf) < 6) || (mac[0] != 0x00)) ? 1 : 0; } if (macinvalid) { buart_print("\r\nInvalid MAC address!"); memcpy(mac, cfg.mac, 6); } else if (memcmp(mac, original_mac, 6) != 0) { /* Change MAC address */ memcpy(cfg.mac, mac, 6); cfg.mac[6] = cfg.mac[7] = 0; ProgramMac(0, mac); eth_init(mac); buart_print("\r\nMAC address changed."); } else { buart_print("\r\nMAC address unchanged."); } } buart_nl();}/************************//* Local IP Address *//************************/int GetLocalIP(char *buf){ int rc = 0; if (buf != 0) { IpAddrToStr(cfg.ip, buf); rc = 1; } return rc;}void AskLocalIP(){ UINT32 local_ip = cfg.ip, original_ip = cfg.ip; char buf[BOOT_LINE_SIZE + 1]; int ipinvalid = 1; while (ipinvalid) { buf[0] = 0; buart_print("\r\nEnter new IP address: "); ReadLine(buf, BOOT_LINE_SIZE); if (buf[0] == 0) { /* Keep the old one */ ipinvalid = 0; } else { ipinvalid = (ipscanf(&local_ip, buf) != 4) ? 1 : 0; } if (ipinvalid) { buart_print("\r\nInvalid IP address!"); local_ip = cfg.ip; } else if (local_ip != original_ip) { /* Change IP address */ cfg.ip = local_ip; ip_reinit(); udp_init(); buart_print("\r\nIP address changed."); } else { buart_print("\r\nIP address unchanged."); } } buart_nl();}/****************************//* TFTP Server IP Address *//****************************/int GetTftpIP(char *buf){ int rc = 0; if (buf != 0) { IpAddrToStr(cfg.server_ip, buf); rc = 1; } return rc;}void AskTftpIP(){ UINT32 tftp_ip = cfg.server_ip, original_ip = cfg.server_ip; char buf[BOOT_LINE_SIZE + 1]; int ipinvalid = 1; while (ipinvalid) { buf[0] = 0; buart_print("\r\nEnter new server IP address: "); ReadLine(buf, BOOT_LINE_SIZE); if (buf[0] == 0) { /* Keep the old one */ ipinvalid = 0; } else { ipinvalid = (ipscanf(&tftp_ip, buf) != 4) ? 1 : 0; } if (ipinvalid) { buart_print("\r\nInvalid server IP address!"); tftp_ip = cfg.server_ip; } else if (tftp_ip != original_ip) { /* Change TFTP server IP address */ cfg.server_ip = tftp_ip; buart_print("\r\nTFTP server IP address changed."); } else { buart_print("\r\nTFTP server IP address unchanged."); } } buart_nl();}/****************************************//* Remote File to Download via TFTP *//****************************************/int GetRemFile(char *buf){ int rc = 0; if (buf != 0) { strcpy(buf, cfg.remote_file); rc = 1; } return rc;}void AskRemFile(){ char original_remfile[BSP_RFNAME_MAXLEN + 1]; char buf[BOOT_LINE_SIZE + 1]; int fileinvalid = 1; strcpy(original_remfile, cfg.remote_file); while (fileinvalid) { buf[0] = 0; buart_print("\r\nEnter new remote file name (15 chars max): "); ReadLine(buf, BOOT_LINE_SIZE); if (buf[0] == 0) { /* Keep the old one */ fileinvalid = 0; } else { fileinvalid = (strlen(buf) > BSP_RFNAME_MAXLEN) ? 1 : 0; } if (fileinvalid) { buart_print("\r\nInvalid remote file name!"); } else if (strcmp(buf, original_remfile) != 0) { /* Change TFTP remote file name */ strcpy(cfg.remote_file, buf); buart_print("\r\nTFTP remote file name changed."); } else { buart_print("\r\nTFTP remote file name unchanged."); } } buart_nl();}/********************************/ /* BSP Functions *//********************************/int bsp_GetMAC(unsigned char *mac){ if (mac == NULL) return -1; memcpy(mac, cfg.mac, 6); return 0;}int bsp_GetTftpIp(UINT32 *tftpip){ if (tftpip == NULL) return -1; *tftpip = cfg.ip; return 0;}/*************************************************************************************//* TFTP Parameters *//*************************************************************************************//* Called by "tftpc(char *, int)" in tftp.c */int get_tftp_param(UINT32 *servip, char *servfile){ if (servip == NULL || servfile == NULL) return -1; if (cfg.server_ip == 0) return -1; *servip = cfg.server_ip; strcpy(servfile, cfg.remote_file); return 0;}#endif /* MODIFIEDSRC */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -