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

📄 bloader.c

📁 Boot code for ADM5120 with serial console for Edimax router.
💻 C
字号:
/*****************************************************************************;;    Project : Edimax;    Creator :;    File    : bloader.c;    Abstract: ;;*****************************************************************************/#include <mips4kc.h>#include <adm5120.h>#include <hw_profile.h>#include <ctype.h>#include <mx29lv320.h>#include <flash.h>#include <bconfig.h>#include <uartdrv.h>#include <if_5120.h>#include <linuxld.h>#include <banner.h>#include <param.h>#include <bsp_cfg.h>#include <buart.h>#include <buart_extra.h>#include <info.h>#include <test_def.h>#define LOADER_BACK_DOOR_TIME   3#define LOADER_BACK_DOOR_CHAR	(' ')#define LOADER_BACK_DOOR_COUNT  3/* External functions called from the menu selection */void xmodem_download(void);void update_bootloader(void);void boot_linux(void);void tftp_init();void dl_run_plugin();/* Test functions */void hexdump(unsigned char *, int);void write_region(unsigned char *);void toggle_extio();void dump_ss();void flash_whack_ss();void flash_erase_ss();void update_ss();void flash_toggle_ss();void flash_exit_ss();void mem_peek();char hexdigit[] = "0123456789abcdef";char bt_name[] = "\r\nADM0000 Mod Bootloader:";int extiobyte_on;extern int ssopen;extern void _icache_sync_all(void);/* * This routine prints the main menu  */static void print_menu(){#ifdef SECSECTOR	buart_print("\r\n"				"\r\nSecurity Sector Boot Loader Menu"				"\r\n======================================="				"\r\n [1] Download vmlinuz to flash (Xmodem)"				"\r\n [2] Download vmlinuz to flash (TFTP)"				"\r\n [3] Download vmlinuz to SDRAM (TFTP)"				"\r\n [4] Update Security Sector (Xmodem)"				"\r\n [5] Print System Values"				"\r\n [6] Download & Run Plugin (TFTP)"				"\r\n [7] Peek memory location"				"\r\n [8] Reboot"				"\r\n [9] Exit"				"\r\n\r\nMake a selection: ");#else	buart_print("\r\n"				"\r\nBoot Loader Menu"				"\r\n======================================="				"\r\n [1] Update Security Sector (Xmodem)"				"\r\n [2] Hex Dump Security Sector"				"\r\n [3] Erase Security Sector"				"\r\n [4] Toggle SS open/close"				"\r\n [5] Hex Dump Boot Sector"				"\r\n [6] Print Misc Info"				"\r\n [7] Reboot"				"\r\n [8] Exit"				"\r\n\r\nMake a selection: ");#endif	/* SECSECTOR */}/* * This routine is the C entry pointer of the loader  */void c_entry(UINT old_sp, UINT old_gp){	int type;	register int i;	register int c;	void (*funcptr)(int);	UINT save_sp = old_sp;	UINT save_gp = old_gp;	unsigned long tick1, tick2;#ifdef SECSECTOR	volatile unsigned long *gpio_conf0  = (unsigned long *) (PA2VA(ADM5120_SWCTRL_BASE) + GPIO_conf0_REG);	volatile unsigned long *gpio_conf2  = (unsigned long *) (PA2VA(ADM5120_SWCTRL_BASE) + GPIO_conf2_REG);	volatile unsigned long *sw_mem_ctrl = (unsigned long *) (PA2VA(ADM5120_SWCTRL_BASE) + Mem_control_REG);	unsigned long mem_control;#else	int countdown = 9;#endif	/* SECSECTOR */	/*	Zero when we enter */	extiobyte_on = 0;	ssopen = 0;	/*	Drop out of the Security Sector.  This won't hurt */	/*	even if it's not open, since we're running in RAM */	/*	by now anyway.                                    */	flash_exit_ss();#ifdef SECSECTOR	/*	Things done near the start of FW_Start in Hawking32k_loader.idb */	*gpio_conf2 = 0;	*gpio_conf0 = (GPIO0_INPUT_MODE					| GPIO0_INPUT_MASK | GPIO1_INPUT_MASK | GPIO2_INPUT_MASK | GPIO3_INPUT_MASK					| GPIO4_INPUT_MASK | GPIO5_INPUT_MASK | GPIO6_INPUT_MASK | GPIO7_INPUT_MASK					| GPIO0_OUTPUT_EN | GPIO1_OUTPUT_EN | GPIO2_OUTPUT_EN | GPIO3_OUTPUT_EN					| GPIO4_OUTPUT_EN | GPIO5_OUTPUT_EN | GPIO6_OUTPUT_EN | GPIO7_OUTPUT_EN					| GPIO0_OUTPUT_HI);#if 1	/*	This should already be set up!  WTF?  From Hawking32k_loader.idb it appears that */	/*	Hawking also had some problems with this memory control setup.                   */	mem_control = *sw_mem_ctrl;	/* NOTE NOTE NOTE NOTE */	/* This MUST be set to 0x304 or else the official Hawking firmware will NOT run! */	mem_control = 0x304;	mem_control &= 0xFFF8F8FF;	// Turn off 3-bits each for SRAM0 size and SRAM1 size	mem_control |= 0x00050400;	// Set SRAM0 size to 4 MB and SRAM1 size to 8 MB ?!?!?!?!?!  WTF?!?!?!?!?	mem_control = 0x00050400;	// TEST - Booting a Hawking kernel and looking at Mem_Cont register shows this.	mem_control = 0x00050404;	// TEST - Booting a Hawking kernel and looking at Mem_Cont register shows this.	*sw_mem_ctrl = mem_control;	// This is really fucked up.#endif#endif	/* SECSECTOR */	/*	Initialize the UART, Timer and NOR Flash */	buart_init();	/*	Initialize memory space */	memlib_init();	/*	Initialize Timer */	InitTimer();#if (HWPF_5120_SMEM0_BANK_SIZE == 0x400000)	mx29lv320_init();	/*	There is no SRAM1 so should this really be done? */	/*	ADM5120_SW_REG(Mem_control_REG) |= 0x050000; */#elif (HWPF_5120_SMEM0_BANK_SIZE == 0x200000)	mx29lv160_init();#endif	flash_init();	i = ADM5120_SW_REG(CODE_REG) & CODE_ID_MASK;	bt_name[5] = hexdigit[(i>>12)&0xf];	bt_name[6] = hexdigit[(i>>8)&0xf];	bt_name[7] = hexdigit[(i>>4)&0xf];	bt_name[8] = hexdigit[i&0xf];	buart_print(bt_name);	buart_print("\r\n\r\n");	buart_print("\r\nCPU: ADM");buart_print(CPU_NO);buart_put('-');buart_print(CPU_CLOCK);	buart_print("\r\nSDRAM: ");buart_print(SDRAM_SIZE);	buart_print("\r\nFlash: ");buart_print(FLASH_TYPE);buart_put('-');buart_print(FLASH_SIZE);	buart_print("\r\nBoot System: ");buart_print(BOOT_SYSTEM);	buart_print("\r\nLoader Version: ");buart_print(LOADER_VERSION);	buart_print("\r\nCreation Date: ");buart_print(CREATE_DATE);	buart_nl();#ifdef NOTIMEOUT	/*	The Security Sector implementation is only invoked		after the user has already hit space 3 times at the		main bootloader prompt.  No need to do it again. */	/*	Setup the Network configuration data */	boot_param_init();	/*	Initialize ADM5120 Switch */	if (if5120_init() != 0) {		buart_print("\r\nSwitch init failed!");		panic();	}	/* Initialize network for TFTP */	tftp_init();#else	/*	The non-Security Sector implementation is designed		to be run as a proxy "kernel".  This means that it		appears just like Linux does to the bootloader.		TODO: When do we want to do the timeout exactly? */	/*	Wait 9 seconds for back door */	buart_put(countdown + '0');	tick1 = UpTime();	for (i = 0; i < 3; ) {		tick2 = UpTime();		if ((tick2 - tick1) >= 200) {			countdown--;			if (countdown < 0)				break;			buart_put('\r');			buart_put(countdown + '0');			tick1 = UpTime();		}		c = buart_get(0);		switch (c) {			case -1:				break;			case LOADER_BACK_DOOR_CHAR:				if (++i == LOADER_BACK_DOOR_COUNT)					goto main_menu;				break;			default:				i = 0;				break;		}	}	/*	Boot Linux kernel */	boot_linux();	/*	Enter the menu through the back door */main_menu:	/* UGH */#endif	/* NOTIMEOUT */	/*	Bootloader functions */	while (1) {		print_menu();		c = buart_getchar();		buart_put(c);		switch ((int) c) {#ifdef SECSECTOR			case '1':				xmodem_download();				break;			case '2':				tftpc_download_to_flash();				break;			case '3':				tftpc_download_to_sdram();				break;			case '4':				update_ss();				// winds up at mx29lv320_update_ss() which erases and writes				break;			case '5':				adm_info();				break;			case '6':				dl_run_plugin();				break;			case '7':				mem_peek();				break;			case '8':				buart_print("\r\n\r\n");				tick1 = UpTime();				while (1) {					tick2 = UpTime();					if ((tick2 - tick1) >= 300)						break;				}				reboot_router();				break;			case '9':				boot_linux();				break;#else			case '1':				update_ss();				// winds up at mx29lv320_update_ss() which erases and writes				break;			case '2':				dump_ss();				break;			case '3':				flash_erase_ss();				break;			case '4':				flash_toggle_ss();				break;			case '5':				hexdump((unsigned char *) 0xbfc00000, 64);				break;			case '6':				misc_info(save_sp, save_gp);				break;			case '7':				buart_print("\r\n\r\n");				tick1 = UpTime();				while (1) {					tick2 = UpTime();					if ((tick2 - tick1) >= 300)						break;				}				reboot_router();				break;			case '8':				boot_linux();				break;#endif	/* SECSECTOR */			default:				break;		}	}}/*	Some other routines that have been used at times from the security sector menu...	[6] Print Misc Info ==> misc_info(save_sp, save_gp);				"\r\n [6] Print Misc Info" */

⌨️ 快捷键说明

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