📄 bios.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 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 load_tftp(unsigned long mode, unsigned long param){ unsigned char *ip_s; 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; //Modify to your ip addr, default is : 10.1.1.118 //add by dailzh, more information for visiting http://www.dailzh.net ip_s=(unsigned char *)&ip; ip_s[3]=192; ip_s[2]=168; ip_s[1]=168; ip_s[0]=101; inbuf = (unsigned char *)tftp_data; outbuf = (unsigned char *)TFTP_ADDR; insize = 0x7fffffff; outsize = 0x7fffffff; gunzip(inbuf, &insize, outbuf, &outsize); tftp_ptr = (TFTP *)TFTP_ADDR; //when modify ip addr, note this line //ip = bios_tftp_ipaddr(); tftp_ptr(ip, mode, param); return 0;}int main_menu(struct system_table_struct *system_table){ int list[] = { BOOT_UPDATE_FIRMWARE, BOOT_LOAD_PROGRAM, }; int select; int ch; printf("1 - Update FirmWare\r\n"); printf("2 - Load uClinux to SDRAM\r\n"); printf("\r\n"); printf("Enter your choice:"); while (1) { ch = getch(); if (ch >= '1' && ch <= '2') { putch(ch); select = list[ch - '1']; break; } } printf("\r\n\r\n"); return select;}int menu(struct system_table_struct *system_table){ int select; while (1) { select = main_menu(system_table); switch (select) { case BOOT_LOAD_PROGRAM: load_tftp(select, 0); break; case BOOT_UPDATE_FIRMWARE: 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; struct system_table_struct system_table1 = { bios_size: 0xc000, vendor_id: 0x11F6, device_id: 0x8000, sub_vendor_id: 0x11F6, sub_device_id: 0x8000, rev: 0, sys_reg_base: 0x03ff0000, sys_clock: fMCLK_MHz, ext_clock: 0xffffffff, rom_table: {{0x00080000, 16, 0x00000060}, {0x00000000, 8, 0x00000060}, {0x00000000, 8, 0x00000060}, {0x00000000, 8, 0x00000060}, {0x00000000, 8, 0x00000060}, {0x00000000, 8, 0x00000060}}, dram_table: {{0x01000000, 32, 0x00000398}, {0x00000000, 32, 0x00000398}, {0x00000000, 32, 0x00000398}, {0x00000000, 32, 0x00000398}}, system_table_size: sizeof(struct system_table_struct), partition_table_offset: 0x0000f000, partition_table_size: sizeof(struct partition_table_struct), ext_base: 0x03fd0000, ext_table: {{ 32, 0x00000fff}, { 32, 0x00000fff}, { 32, 0x00000fff}, { 32, 0x00000fff}}, iop: {0x00020070, 0x2ad00300, ~0x00020070}, uart: {{0x80000000, 0, 0, 0, 0, 0, 0}, {0x80000000, 1, 0, 0, 0, 0, 0}}, eth: {0x80000000, {0x00, 0x80, 0x48, 0x88, 0x00, 0x00}}, ne2000: {0x80000000, 0, {0x00, 0x80, 0x48, 0x88, 0x00, 0x01}}, uart16550: {0x80000000, 1, 13000000}, pc97338: {0x80000000, 1}, startup_mode: BOOT_MENU, tftp_ipaddr: 0xc0a8a865, //* ip=192.168.168.101}; //system_table = (struct system_table_struct *)(_rom_base + system_table_offset); system_table =(struct system_able_struct *) (&system_table1); sys_init(system_table, _rom_base, DRAM_BASE); console_init(); printf("\r\n\r\n"); printf("This program is base on the BIOS, rewrited by www.dailzh.net\r\n"); printf("uClinux BootLoader for SAMSUNG S3C4510B v1.0 \r\n\r\n"); biosapi_init(); printf("\r\n"); menu(system_table); return (unsigned char *)_rom_base;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -