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

📄 bios.c

📁 ARM开发用的启动代码
💻 C
字号:
#include "types.h"#include "bios.h"#include "board.h"#include "console.h"#include "utils.h"#include "gunzip.h"extern const unsigned long _rom_base;extern const unsigned long system_table_offset;extern const unsigned char sysinit_data[];extern const unsigned char biosapi_data[];extern const unsigned char setup_data[];extern const unsigned char fdisk_data[];extern const unsigned char tftp_data[];int sys_init(struct system_table_struct *system_table, unsigned long rom_base, unsigned long dram_base){	typedef int (SYSINIT)(struct system_table_struct *, unsigned long, unsigned long);	SYSINIT *sys_init_ptr;	memcpy((char *)SRAM_BASE, sysinit_data, 1024 * 3);	sys_init_ptr = (SYSINIT *)SRAM_BASE;	sys_init_ptr(system_table, rom_base, dram_base);	return 0;}int biosapi_init(void){	unsigned char *inbuf;	unsigned long insize;	unsigned char *outbuf;	unsigned long outsize;	struct biosapi_init_struct init_param;	BIOSCALL *fp;	inbuf = (unsigned char *)biosapi_data;	outbuf = (unsigned char *)BIOS_API_ADDR;	insize = 0x7fffffff;	outsize = 0x7fffffff;	gunzip(inbuf, &insize, outbuf, &outsize);	init_param.rom_base = _rom_base;	init_param.dram_base = DRAM_BASE;	init_param.system_table_offset = system_table_offset;	fp = (BIOSCALL *)outbuf;	return (*fp)(0, (unsigned long)&init_param);  // Init BIOS call}int get_active_partition(struct partition_table_struct *partition_table){	int i;	for (i = 0; i < MAX_PARTITION_NUM; i++)		if (partition_table->partition[i].flags & PARTITION_FLAGS_ACTIVE)			return i;	return -1;}unsigned char *load_firmware(struct system_table_struct *system_table){	unsigned char *inbuf;	unsigned long insize;	unsigned char *outbuf;	unsigned long outsize;	unsigned char *rom_base;	struct partition_table_struct *partition_table;	struct partition_struct *partition;	int i, err;	printf("Loading Firmware ...................... ");	rom_base = (unsigned char *)_rom_base;	partition_table = (struct partition_table_struct *)		(rom_base + system_table->partition_table_offset);	err = -1;	i = get_active_partition(partition_table);	if (i >= 0) {		partition = &partition_table->partition[i];		inbuf = (unsigned char *)(rom_base + partition->offset);		outbuf = (unsigned char *)(partition->param);		insize = partition->size;		outsize = 0x7fffffff;		if ((err = gunzip(inbuf, &insize, outbuf, &outsize)) != 0) {			printf("Error!\r\n\r\n");		} else			printf("Done.\r\n\r\n");	} else		printf("Not Found.\r\n\r\n");	if (err != 0)		return NULL;	return outbuf;}int load_setup(void){	typedef int (SETUP)(void);	unsigned char *inbuf;	unsigned long insize;	unsigned char *outbuf;	unsigned long outsize;	unsigned long ip;	SETUP *setup_ptr;	inbuf = (unsigned char *)setup_data;	outbuf = (unsigned char *)SETUP_ADDR;	insize = 0x7fffffff;	outsize = 0x7fffffff;	gunzip(inbuf, &insize, outbuf, &outsize);	setup_ptr = (SETUP *)SETUP_ADDR;	setup_ptr();	return 0;}int load_fdisk(void){	typedef int (FDISK)(void);	unsigned char *inbuf;	unsigned long insize;	unsigned char *outbuf;	unsigned long outsize;	unsigned long ip;	FDISK *fdisk_ptr;	inbuf = (unsigned char *)fdisk_data;	outbuf = (unsigned char *)FDISK_ADDR;	insize = 0x7fffffff;	outsize = 0x7fffffff;	gunzip(inbuf, &insize, outbuf, &outsize);	fdisk_ptr = (FDISK *)FDISK_ADDR;	fdisk_ptr();	return 0;}int load_tftp(unsigned long mode, unsigned long param){	typedef int (TFTP)(unsigned long, unsigned long, unsigned long);	unsigned char *inbuf;	unsigned long insize;	unsigned char *outbuf;	unsigned long outsize;	unsigned long ip;	TFTP *tftp_ptr;	inbuf = (unsigned char *)tftp_data;	outbuf = (unsigned char *)TFTP_ADDR;	insize = 0x7fffffff;	outsize = 0x7fffffff;	gunzip(inbuf, &insize, outbuf, &outsize);	tftp_ptr = (TFTP *)TFTP_ADDR;	ip = bios_tftp_ipaddr();	tftp_ptr(ip, mode, param);	return 0;}int select_partition(struct system_table_struct *system_table){	struct partition_table_struct *partition_table;	struct partition_struct *partition;	int ch, partition_num;	int i;	partition_table = (struct partition_table_struct *)		(_rom_base + system_table->partition_table_offset);	for (i = 0; i < MAX_PARTITION_NUM; i++) {		partition = &partition_table->partition[i];		printf("Partition %01d : ", i + 1);		if (partition->type == 0) {			printf("None");		} else {			printf("0x%08x - 0x%08x" , partition->offset,				partition->offset + partition->size - 1);		}		printf("\r\n");	}	printf("\r\n");	printf("Please Select Partition (1 - 8) ");	partition_num = get_select('1', '8');	printf("\r\n\r\n");	return partition_num;}int main_menu(struct system_table_struct *system_table){	int list[] = {		BOOT_LOAD_FIRMWARE,		BOOT_LOAD_PROGRAM,		BOOT_BIOS_SETUP,		BOOT_FDISK_UTILITY,		BOOT_UPDATE_BIOS,		BOOT_UPDATE_SYSPARAMETERS,		BOOT_UPDATE_PARTITIONTABLE,		BOOT_UPDATE_PARTITION,		BOOT_UPDATE_FIRMWARE		};	int select;	int ch;	printf("Main Menu\r\n\r\n");	printf("1 - Load Firmware\r\n");	printf("2 - Load Program (HEX)\r\n");	printf("3 - Bios Setup\r\n");	printf("4 - Fdisk Utility\r\n");	printf("5 - Update Bios\r\n");	printf("6 - Update System Parameters\r\n");	printf("7 - Update Partition Table\r\n");	printf("8 - Update Partition\r\n");	printf("9 - Update Firmware\r\n");	printf("\r\n");	printf("Please Select ");	while (1) {		ch = getch();		if (ch >= '1' && ch <= '9') {			putch(ch);			select = list[ch - '1'];			break;		}	}	printf("\r\n\r\n");	return select;}int menu(struct system_table_struct *system_table){	int select, partition_num = 0;	while (1) {		select = main_menu(system_table);		if (select == BOOT_LOAD_FIRMWARE) {			select = BOOT_LOAD_FIRMWARE;			break;		}		if (select == BOOT_UPDATE_PARTITION) {			partition_num = select_partition(system_table);			if (partition_num < 0)				continue;		}		switch (select) {		case BOOT_FDISK_UTILITY:			load_fdisk();			break;		case BOOT_BIOS_SETUP:			load_setup();			break;		case BOOT_LOAD_PROGRAM:		case BOOT_UPDATE_BIOS:		case BOOT_UPDATE_SYSPARAMETERS:		case BOOT_UPDATE_PARTITIONTABLE:		case BOOT_UPDATE_FIRMWARE:		case BOOT_UPDATE_PARTITION:			load_tftp(select, partition_num);			break;		default:			break;		}	}	return select;}/* *  Main BIOS functions */unsigned char *bios_main(void){	struct system_table_struct *system_table;	unsigned char *exec_addr;	unsigned long startup_mode;	int i, ch;	system_table = (struct system_table_struct *)(_rom_base + system_table_offset);	sys_init(system_table, _rom_base, DRAM_BASE);	console_init();        	printf("\r\n\r\n");	printf(" BIOS for SAMSUNG S3C4510B  (build 2004/8/30 by witrace)\r\n\r\n");	biosapi_init();	printf("\r\n");        Led();	startup_mode = bios_startup_mode();	for (i = 0; i < 1000; i++) {		if (kbhit()) {			if (getch() == KEY_ENTER) {				startup_mode = BOOT_MENU;				break;			}		}	}	if (startup_mode == BOOT_MENU) {		startup_mode = menu(system_table);	}	switch (startup_mode) {	case BOOT_LOAD_FIRMWARE:		exec_addr = load_firmware(system_table);		if (exec_addr != NULL)			return exec_addr;		load_tftp(BOOT_UPDATE_FIRMWARE, 0);		break;	case BOOT_FDISK_UTILITY:		load_fdisk();		break;	case BOOT_BIOS_SETUP:		load_setup();		break;	case BOOT_LOAD_PROGRAM:	case BOOT_UPDATE_BIOS:	case BOOT_UPDATE_SYSPARAMETERS:	case BOOT_UPDATE_PARTITIONTABLE:	case BOOT_UPDATE_PARTITION:	case BOOT_UPDATE_FIRMWARE:		load_tftp(startup_mode, 0);		break;	default:		break;	}	return (unsigned char *)_rom_base;}int Led(void){   int *ppp;   ppp=(int *)0x3ff5000; *ppp|=0xff;  ppp=(int *)0x3ff5008;  *ppp=0;}

⌨️ 快捷键说明

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