热度 14
2012-12-3 22:33
1249 次阅读|
0 个评论
bootloader_elf_from_flash /* *bootloader.c * * *Loads an ELF kernel from flash memory. * *auther:hegs * *mail:sammhe@tom.com */ #include "stdio.h" #include "xio.h" #include "xparameters.h" #include "elf.h" #include "string.h" #define FLASH_MEM0_BASEADDR XPAR_FLASH_MEM0_BASEADDR #define LED_BASEADDR XPAR_LED_BASEADDR /* *bootloader.c * * *Loads an ELF kernel from flash memory. * *auther:hegs * *mail:sammhe@tom.com */ #include "bootloader.h" void main(void) { static char *mem = (char *)FLASH_MEM0_BASEADDR; Elf32_Ehdr *elf; //elf file header Elf32_Phdr *elf_phdr; /* program segment header */ unsigned long e_entry, e_phoff, //program head offset (at file) e_phnum; //phdr number int i; while(1) { elf = (Elf32_Ehdr *) mem; if (elf-e_ident !=0x7f || elf-e_ident !='E' || elf-e_ident !='L' || elf-e_ident !='F' ) { print("not an ELF file\n"); continue; /?flash ?? } if (elf-e_type != ET_EXEC) { print("not an ELF executable\n"); continue; } e_entry = elf-e_entry; e_phnum = elf-e_phnum; e_phoff = elf-e_phoff; for (i = 0; i e_phnum; ++i) { elf_phdr = (Elf32_Phdr *) (e_phoff+mem); e_phoff += sizeof(*elf_phdr); if (elf_phdr-p_type != PT_LOAD) continue; memcpy((void *)(elf_phdr-p_vaddr), (void*)(elf_phdr-p_offset+mem), elf_phdr-p_filesz); memset((char*)(elf_phdr-p_vaddr+elf_phdr-p_filesz), 0, elf_phdr-p_memsz - elf_phdr-p_filesz); } print("starting kernel...\n"); void (*boot)(); boot=(void*)e_entry; boot(); /?????????? #ifdef LED_BASEADDR XIo_Out32(LED_BASEADDR, 0x55); XIo_Out32(LED_BASEADDR, 0xaa); #endif } }