Changeset 586 for trunk/softs/tsar_boot/src/reset_elf_loader.c
- Timestamp:
- Dec 4, 2013, 7:59:21 PM (10 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/softs/tsar_boot/src/reset_elf_loader.c
r570 r586 1 1 /** 2 * \file : boot_elf_loader.c2 * \file : reset_elf_loader.c 3 3 * \date : August 2012 4 4 * \author : Cesar Fuguet 5 5 * 6 * This file defines an elf file loader which reads an executable elf file7 * starting at a sector passed as argument o fa disk and copy the different6 * This file defines an elf file loader which reads an executable .elf file 7 * starting at a sector passed as argument on a disk and copy the different 8 8 * ELF program segments in the appropriate memory address using as information 9 * the virtual address read from the elf file.9 * the virtual address read from the .elf file. 10 10 */ 11 11 12 #include < boot_ioc.h>12 #include <reset_ioc.h> 13 13 #include <elf-types.h> 14 #include < boot_tty.h>15 #include < boot_utils.h>14 #include <reset_tty.h> 15 #include <reset_utils.h> 16 16 #include <defs.h> 17 17 18 #if (BOOT_DEBUG == 1) 19 static char const * const init_state_str[] = { 18 #if (RESET_DEBUG == 1) 19 static char const * const init_state_str[] = 20 { 20 21 "ELF_HEADER_STATE", 21 22 "ELF_PROGRAM_HEADER_STATE", … … 26 27 #endif 27 28 28 unsigned char boot_elf_loader_buffer[512] __attribute__((aligned(CACHE_LINE_SIZE))); 29 30 void * boot_elf_loader(unsigned int lba) 29 unsigned char reset_elf_loader_buffer[512] __attribute__((aligned(CACHE_LINE_SIZE))); 30 31 ///////////////////////////////////////////////////////////////////////////////////// 32 void * reset_elf_loader(unsigned int lba) 33 ///////////////////////////////////////////////////////////////////////////////////// 31 34 { 32 35 /* 33 * Temporary variables used by the bootloader36 * Temporary variables used by the loader 34 37 */ 35 38 Elf32_Ehdr elf_header; … … 67 70 init_state = ELF_HEADER_STATE; 68 71 69 #if ( BOOT_DEBUG == 1)72 #if (RESET_DEBUG == 1) 70 73 elf_loader_t init_state_debug; 71 74 init_state_debug = ELF_END_STATE; 72 75 #endif 73 76 74 boot_puts("Starting boot_elf_loader function...\n\r"); 77 reset_puts("\n[RESET] Start reset_elf_loader at cycle "); 78 reset_putd( proctime() ); 79 reset_puts("\n"); 75 80 76 81 nb_block = lba; … … 86 91 if (nb_available == 0 ) 87 92 { 88 buffer_ptr = & boot_elf_loader_buffer[0];89 90 if ( boot_ioc_read(nb_block , buffer_ptr, 1))93 buffer_ptr = &reset_elf_loader_buffer[0]; 94 95 if (reset_ioc_read(nb_block , buffer_ptr, 1)) 91 96 { 92 boot_puts ( 93 "ERROR: " 94 "boot_ioc_read() failed" 95 "\n" 96 ); 97 98 boot_exit(); 97 reset_puts ("[RESET ERROR] reset_ioc_read() failed\n"); 98 reset_exit(); 99 99 } 100 100 … … 106 106 offset += nb_read; 107 107 108 #if ( BOOT_DEBUG == 1)108 #if (RESET_DEBUG == 1) 109 109 if (init_state != init_state_debug) 110 110 { 111 boot_puts("\ninit_state = ");112 boot_puts(init_state_str[init_state]);113 boot_puts("\n");111 reset_puts("\ninit_state = "); 112 reset_puts(init_state_str[init_state]); 113 reset_puts("\n"); 114 114 init_state_debug = init_state; 115 115 } … … 129 129 { 130 130 nb_rest = elf_ehdr_ptr->e_phnum * elf_ehdr_ptr->e_phentsize; 131 132 131 /* 133 132 * Verification of ELF Magic Number … … 138 137 (elf_ehdr_ptr->e_ident[EI_MAG3] != ELFMAG3) ) 139 138 { 140 boot_puts( 141 "ERROR: " 142 "Input file does not use ELF format" 143 "\n" 144 ); 145 146 boot_exit(); 139 reset_puts("[RESET ERROR] boot-loader file is not an ELF format\n"); 140 reset_exit(); 147 141 } 148 142 … … 154 148 if (elf_ehdr_ptr->e_phnum > PHDR_ARRAY_SIZE) 155 149 { 156 boot_puts( 157 "ERROR: " 158 "ELF PHDR table size is bigger than the allocated" 159 "work space" 160 "\n" 161 ); 162 163 boot_exit(); 150 reset_puts("[RESET ERROR] ELF PHDR table size too large\n"); 151 reset_exit(); 164 152 } 165 153 … … 191 179 if(elf_phdr_ptr[pseg].p_type == PT_LOAD) 192 180 { 193 #if ( BOOT_DEBUG == 1)194 boot_puts("loadable segment found:\n");195 boot_print_elf_phdr(&elf_phdr_ptr[pseg]);181 #if (RESET_DEBUG == 1) 182 reset_puts("loadable segment found:\n"); 183 reset_print_elf_phdr(&elf_phdr_ptr[pseg]); 196 184 #endif 197 185 if (elf_phdr_ptr[pseg].p_offset < offset) … … 218 206 if (pseg == elf_ehdr_ptr->e_phnum) 219 207 { 220 boot_puts( 221 "ERROR: " 222 "No PT_LOAD found" 223 "\n" 224 ); 225 boot_exit(); 208 reset_puts("[RESET ERROR] No PT_LOAD found\n"); 209 reset_exit(); 226 210 } 227 211 … … 270 254 (pseg_start < 0xBFC00000 && pseg_end > 0xBFC10000)) 271 255 { 272 boot_puts( 273 "ERROR: " 274 "Program segment conflits with pre-loader memory space" 275 "\n" 276 ); 277 boot_exit(); 256 reset_puts("[RESET ERROR] conflict with pre-loader memory space\n"); 257 reset_exit(); 278 258 } 279 259 … … 304 284 elf_phdr_ptr[pseg].p_filesz ; 305 285 306 memset(pseg_ptr, 0, pseg_remainder); 307 308 boot_puts("Copied segment at address "); 309 boot_putx(elf_phdr_ptr[pseg].p_vaddr); 310 boot_puts("\n"); 286 // memset(pseg_ptr, 0, pseg_remainder); 287 288 reset_puts("\n[RESET] Segment loaded : address = "); 289 reset_putx(elf_phdr_ptr[pseg].p_vaddr); 290 reset_puts(" / size = "); 291 reset_putx(elf_phdr_ptr[pseg].p_filesz); 292 reset_puts("\n"); 311 293 312 294 /* … … 317 299 if(elf_phdr_ptr[pseg].p_type == PT_LOAD) 318 300 { 319 #if ( BOOT_DEBUG == 1)320 boot_puts("loadable segment found:\n");321 boot_print_elf_phdr(&elf_phdr_ptr[pseg]);301 #if (RESET_DEBUG == 1) 302 reset_puts("loadable segment found:\n"); 303 reset_print_elf_phdr(&elf_phdr_ptr[pseg]); 322 304 #endif 323 305 nb_rest = elf_phdr_ptr[pseg].p_offset - offset; … … 347 329 } 348 330 349 boot_puts ( 350 "Finishing boot_elf_loader function.\n" 351 "Entry point address: " 352 ); 353 354 boot_putx(elf_ehdr_ptr->e_entry); 355 boot_puts("\n"); 331 reset_puts("\n[RESET] Complete reset_elf_loader at cycle "); 332 reset_putd( proctime() ); 333 reset_puts(" / boot entry = "); 334 reset_putx( (unsigned int)(elf_ehdr_ptr->e_entry) ); 335 reset_puts("\n"); 356 336 357 337 return ((void *) elf_ehdr_ptr->e_entry);
Note: See TracChangeset
for help on using the changeset viewer.