Changeset 758 for trunk/softs/tsar_boot/src
- Timestamp:
- Jul 24, 2014, 3:19:18 PM (10 years ago)
- Location:
- trunk/softs/tsar_boot/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/softs/tsar_boot/src/reset.S
r755 r758 24 24 * - Each processor initialises its private XICU WTI mask register. 25 25 * - Only processor 0 executes the reset_load_elf function to load into memory 26 * the system specific boot-loader stored on disk at BOOT_LOADER_LBA26 * the system specific boot-loader stored on disk at RESET_LOADER_LBA 27 27 * - All other processors wait in a low power consumption mode that the 28 28 * processor 0 wakes them using an IPI (Inter Processor Interruption) … … 86 86 move t3, t0 87 87 88 la k0, NB_PROCS 88 la k0, NB_PROCS_MAX /* k0 <= # of processors per cluster */ 89 89 divu t3, k0 90 90 mfhi t1 /* t1 <= lpid = pid % NB_PROCS */ … … 101 101 */ 102 102 103 la t3, ICU_PADDR_BASE /* t3 <= ICU base address*/104 move t4, t1 /* t4 <= local_id*/105 li t5, IRQ_PER_PROC /* t5 <= IRQ_PER_PROC*/103 la t3, SEG_XCU_BASE /* t3 <= ICU base address */ 104 move t4, t1 /* t4 <= local_id */ 105 li t5, IRQ_PER_PROCESSOR /* t5 <= IRQ_PER_PROCESSOR */ 106 106 multu t4, t5 107 107 mflo t6 /* t6 <= IRQ_PER_PROC * local_id */ … … 142 142 143 143 la a0, versionstr 144 la k0, reset_puts 145 jalr k0 146 nop 147 148 149 #if USE_SPI 150 151 /* Processor 0 Initialize the SPI controller */ 152 153 la k0, reset_ioc_init 154 jalr k0 155 nop 156 157 #endif 144 jal reset_puts 145 nop 146 147 /* Processor 0 initializes the block device */ 148 149 jal reset_ioc_init 150 nop 158 151 159 152 /* … … 162 155 */ 163 156 164 la k0, reset_elf_loader 165 li a0, BOOT_LOADER_LBA 166 jalr k0 157 li a0, RESET_LOADER_LBA 158 jal reset_elf_loader 167 159 nop 168 160 -
trunk/softs/tsar_boot/src/reset_elf_loader.c
r701 r758 38 38 * Load ELF PROGRAM HEADER TABLE 39 39 */ 40 Elf32_Phdr elf_pht[ PHDR_ARRAY_SIZE];40 Elf32_Phdr elf_pht[RESET_PHDR_ARRAY_SIZE]; 41 41 size_t phdr_nbyte = sizeof(Elf32_Phdr) * elf_header.e_phnum; 42 42 size_t phdr_off = elf_header.e_phoff; -
trunk/softs/tsar_boot/src/reset_ioc.c
r654 r758 1 /** 2 * \file reset_ioc.c 3 * \date December 2013 4 * \author Cesar Fuguet 5 * 6 * \brief API for accessing the disk controller 7 * 8 * \note These functions call the specific disk controller driver depending 9 * on the USE_IOC_BDV, USE_IOC_SPI or USE_RAMDISK constants 10 */ 11 1 12 #include <reset_ioc.h> 13 #include <defs.h> 2 14 3 #if USE_SPI 4 static struct sdcard_dev _sdcard_device; 5 static struct spi_dev *const _spi_device = (struct spi_dev*) IOC_PADDR_BASE; 15 #if !defined(USE_IOC_BDV) && !defined(USE_IOC_SPI) && !defined(USE_RAMDISK) 16 # error "One of the USE_IOC_* constants must be defined in the hard_config.h" 6 17 #endif 7 18 8 #define SDCARD_RESET_ITER_MAX 4 19 #if (USE_IOC_BDV + USE_IOC_SPI + USE_RAMDISK) != 1 20 # error "Only one disk controller must be used" 21 #endif 9 22 10 /////////////////////////////////// 11 inline void reset_sleep(int cycles) 23 #if USE_IOC_SPI 24 #include <reset_sdc.h> 25 #endif 26 27 #if USE_IOC_BDV 28 #include <reset_bdv.h> 29 #endif 30 31 #if USE_RAMDISK 32 #include <reset_rdk.h> 33 #endif 34 35 /** 36 * \brief Initialize the disk controller 37 */ 38 int reset_ioc_init() 12 39 { 13 int i; 14 for (i = 0; i < cycles; i++); 40 #if USE_IOC_BDV 41 return reset_bdv_init(); 42 #elif USE_IOC_SPI 43 return reset_sdc_init(); 44 #elif USE_RAMDISK 45 return reset_rdk_init(); 46 #else 47 # error "reset_ioc_init() : Not supported disk controller chosen" 48 #endif 15 49 } 16 50 17 #if USE_SPI 18 /////////////////////////////////////////////////////////////////////////////// 19 // reset_ioc_init 20 // This function initializes the SDCARD / required for FPGA. 21 /////////////////////////////////////////////////////////////////////////////// 22 int reset_ioc_init() 51 /** 52 * \param lba : first block index on the disk 53 * \param buffer: base address of the memory buffer 54 * \param count : number of blocks to be transfered 55 * 56 * \brief Transfer data from disk to a memory buffer 57 * 58 * \note This is a blocking function. The function returns once the transfer 59 * is completed. 60 */ 61 int reset_ioc_read( unsigned int lba, void* buffer, unsigned int count ) 23 62 { 24 unsigned char sdcard_rsp; 25 26 reset_puts("Initializing block device\n\r"); 27 28 /** 29 * Initializing the SPI controller 30 */ 31 spi_dev_config ( 32 _spi_device , 33 200000 , /**< SPI_clk: 200 Khz */ 34 SYSCLK_FREQ , /**< Sys_clk */ 35 8 , /**< Charlen: 8 */ 36 SPI_TX_NEGEDGE, 37 SPI_RX_POSEDGE 38 ); 39 40 /** 41 * Initializing the SD Card 42 */ 43 unsigned int iter = 0; 44 while(1) 45 { 46 reset_puts("Trying to initialize SD card... "); 47 48 sdcard_rsp = sdcard_dev_open(&_sdcard_device, _spi_device, 0); 49 if (sdcard_rsp == 0) 50 { 51 reset_puts("OK\n"); 52 break; 53 } 54 55 reset_puts("KO\n"); 56 reset_sleep(1000); 57 if (++iter >= SDCARD_RESET_ITER_MAX) 58 { 59 reset_puts("\nERROR: During SD card reset to IDLE state\n" 60 "/ card response = "); 61 reset_putx(sdcard_rsp); 62 reset_puts("\n"); 63 reset_exit(); 64 } 65 } 66 67 /** 68 * Set the block length of the SD Card 69 */ 70 sdcard_rsp = sdcard_dev_set_blocklen(&_sdcard_device, 512); 71 if (sdcard_rsp) 72 { 73 reset_puts("ERROR: During SD card blocklen initialization\n"); 74 reset_exit(); 75 } 76 77 /** 78 * Incrementing SDCARD clock frequency for normal function 79 */ 80 spi_dev_config ( 81 _spi_device , 82 10000000 , /**< SPI_clk 10 Mhz */ 83 SYSCLK_FREQ , /**< Sys_clk */ 84 -1 , /**< Charlen: 8 */ 85 -1 , 86 -1 87 ); 88 89 reset_puts("Finish block device initialization\n\r"); 90 91 return 0; 92 } // end reset_ioc_init() 93 #endif 94 95 ////////////////////////////////////////////////////////////////////////////// 96 // reset_bdv_read() 97 ///////////////////////////////////////////////////////////////////////////// 98 #if USE_BDV 99 int reset_bdv_read( unsigned int lba, 100 void* buffer, 101 unsigned int count ) 102 { 103 unsigned int * ioc_address = (unsigned int*)IOC_PADDR_BASE; 104 105 // block_device configuration 106 iowrite32( &ioc_address[BLOCK_DEVICE_BUFFER], (unsigned int) buffer ); 107 iowrite32( &ioc_address[BLOCK_DEVICE_COUNT], count ); 108 iowrite32( &ioc_address[BLOCK_DEVICE_LBA], lba ); 109 iowrite32( &ioc_address[BLOCK_DEVICE_IRQ_ENABLE], 0 ); 110 111 // block_device trigger transfer 112 iowrite32( &ioc_address[BLOCK_DEVICE_OP], ( unsigned int ) 113 BLOCK_DEVICE_READ ); 114 115 unsigned int status = 0; 116 while ( 1 ) 117 { 118 status = ioread32(&ioc_address[BLOCK_DEVICE_STATUS]); 119 if ( status == BLOCK_DEVICE_READ_SUCCESS ) 120 { 121 break; 122 } 123 if ( status == BLOCK_DEVICE_READ_ERROR ) { 124 reset_puts("ERROR during read on the BLK device\n"); 125 return 1; 126 } 127 } 128 #if (CACHE_COHERENCE == 0) || USE_IOB 129 reset_buf_invalidate(buffer, CACHE_LINE_SIZE, count * 512); 130 #endif 131 return 0; 132 } 133 #endif 134 135 ////////////////////////////////////////////////////////////////////////////// 136 // reset_spi_read() 137 ///////////////////////////////////////////////////////////////////////////// 138 #if USE_SPI 139 static int reset_spi_read( unsigned int lba, 140 void* buffer, 141 unsigned int count ) 142 { 143 unsigned int sdcard_rsp; 144 unsigned int i; 145 146 sdcard_dev_lseek(&_sdcard_device, lba); 147 for(i = 0; i < count; i++) 148 { 149 unsigned char* buf = (unsigned char *) buffer + (512 * i); 150 if (( sdcard_rsp = sdcard_dev_read ( &_sdcard_device, buf, 512 ) )) 151 { 152 reset_puts("ERROR during read on the SDCARD device. Code: "); 153 reset_putx(sdcard_rsp); 154 reset_puts("\n"); 155 return 1; 156 } 157 } 158 return 0; 159 } 160 #endif 161 162 ////////////////////////////////////////////////////////////////////////////// 163 // reset_rdk_read() 164 ///////////////////////////////////////////////////////////////////////////// 165 #if USE_RDK 166 static int reset_rdk_read( unsigned int lba, 167 void* buffer, 168 unsigned int count ) 169 { 170 unsigned int* rdk_address = (unsigned int*) RDK_PADDR_BASE; 171 char* src = (char*) rdk_address + (lba * 512); 172 173 memcpy(buffer, (void*) src, count * 512); 174 return 0; 175 } 176 #endif 177 178 /////////////////////////////////////////////////////////////////////////////// 179 // reset_ioc_read() 180 // Transfer data from disk to a memory buffer 181 // - param lba : first block index on the disk 182 // - param buffer : base address of the memory buffer 183 // - param count : number of blocks to be transfered 184 // This is a blocking function. The function returns once the transfer is 185 // completed. 186 // 187 // The USE_BDV, USE_SPI and USE_RDK variables signal if the disk is accessed 188 // through a BLOCK DEVICE, SPI or RAMDISK respectively 189 /////////////////////////////////////////////////////////////////////////////// 190 int reset_ioc_read( unsigned int lba, 191 void* buffer, 192 unsigned int count ) 193 { 194 #if USE_BDV 63 #if USE_IOC_BDV 195 64 return reset_bdv_read(lba, buffer, count); 196 #elif USE_ SPI197 return reset_s pi_read(lba, buffer, count);198 #elif USE_R DK65 #elif USE_IOC_SPI 66 return reset_sdc_read(lba, buffer, count); 67 #elif USE_RAMDISK 199 68 return reset_rdk_read(lba, buffer, count); 200 69 #else 201 # error "reset_ioc_read() : No supported disk controller chosen"70 # error "reset_ioc_read() : Not supported disk controller chosen" 202 71 #endif 203 72 } 204 73 205 74 /* 206 * vim: tabstop=4 : s hiftwidth=4 : expandtab75 * vim: tabstop=4 : softtabstop=4 : shiftwidth=4 : expandtab 207 76 */ -
trunk/softs/tsar_boot/src/reset_utils.c
r703 r758 8 8 9 9 #include <reset_utils.h> 10 11 /* 12 * pread(size_t file_offset, void* buf, size_t nbyte, size_t offset) 13 * 14 * read from disk into buffer "nbyte" bytes from (file_offset + offset) 15 * 10 #include <reset_tty.h> 11 #include <reset_ioc.h> 12 #include <io.h> 13 14 /** 16 15 * \param file_offset: Disk relative offset of file 17 16 * \param buf: Destination buffer 18 17 * \param nbyte: Number of bytes to read 19 18 * \param offset: File relative offset 19 * 20 * \brief read from disk into buffer "nbyte" bytes from (file_offset + offset) 20 21 * 21 22 * \note Absolute disk offset (in bytes) is (file_offset + offset) … … 57 58 if (offset_blk != blk_buf_idx) { 58 59 if (reset_ioc_read(offset_blk, (void*)&blk_buf, 1)) { 59 return -1; 60 return -1; 60 61 } 61 62 } 62 63 blk_buf_idx = offset_blk; 63 read_nbyte = (nbyte > unaligned_nbyte) ? unaligned_nbyte : nbyte; 64 read_nbyte = (nbyte > unaligned_nbyte) ? unaligned_nbyte : nbyte; 64 65 memcpy((void*)dst, (void*)&blk_buf.b[offset], read_nbyte); 65 66 nbyte -= read_nbyte; … … 70 71 * Read aligned bytes directly to buffer 71 72 */ 72 size_t nblk = nbyte / BLOCK_SIZE; 73 size_t nblk = nbyte / BLOCK_SIZE; 73 74 if (nblk) { 74 75 if (reset_ioc_read(offset_blk, (void*)&dst[read_nbyte], nblk)) { … … 91 92 read_nbyte += nbyte; 92 93 } 93 return read_nbyte; 94 } 95 96 /******************************************************************** 97 * proctime() 98 * 99 * Returns processor local time. 100 ********************************************************************/ 101 inline unsigned int proctime() 102 { 103 unsigned int ret; 104 asm volatile ("mfc0 %0, $9":"=r" (ret)); 105 return ret; 106 } 107 108 /******************************************************************** 109 * memcpy( _dst, _src, size ) 110 * 111 * Transfer data between two memory buffers. 112 * 113 * \param _dst : Destination buffer base address 94 return read_nbyte; 95 } 96 97 /** 98 * \param _dst : Destination buffer base address 114 99 * \param _src : Source buffer base address 115 * \param size : Number of bytes to transfer 116 * 117 ********************************************************************/ 100 * \param size : Number of bytes to transfer 101 * 102 * \brief Transfer data between two memory buffers. 103 */ 118 104 void* memcpy(void *_dst, const void *_src, size_t n) 119 105 { … … 135 121 } 136 122 137 /******************************************************************** 138 * memset( _dst, value, size ) 139 * 140 * Initialize memory buffers with predefined value. 141 * 142 * \param _dst : Destination buffer base address 143 * \param value : Initialization value 123 /** 124 * \param _dst : Destination buffer base address 125 * \param value : Initialization value 144 126 * \param size : Number of bytes to initialize 145 127 * 146 ********************************************************************/ 128 * \brief Initialize memory buffers with predefined value. 129 */ 147 130 void* memset(void *_dst, int c, size_t len) 148 131 { … … 179 162 } 180 163 181 /******************************************************************** 182 * check_elf_header(Elf32_Ehdr*) 183 * 184 * Verify that ELF file is valid and that the number of program 185 * headers does not exceed the defined maximum 186 * 164 /** 187 165 * \param ehdr : ELF header pointer 188 166 * 189 ********************************************************************/ 167 * \brief Verify that ELF file is valid and that the number of program headers 168 * does not exceed the defined maximum 169 */ 190 170 void check_elf_header(Elf32_Ehdr *ehdr) 191 171 { … … 205 185 * Verification of Program Headers table size. It must be 206 186 * smaller than the work size allocated for the 207 * elf_pht[ PHDR_ARRAY_SIZE] array208 */ 209 if (ehdr->e_phnum > PHDR_ARRAY_SIZE)187 * elf_pht[RESET_PHDR_ARRAY_SIZE] array 188 */ 189 if (ehdr->e_phnum > RESET_PHDR_ARRAY_SIZE) 210 190 { 211 191 reset_puts("[RESET ERROR] ELF PHDR table size too large\n"); … … 214 194 } 215 195 216 /******************************************************************** 217 * reset_print_elf_phdr( elf_phdr_ptr ) 218 * 219 * Print some fields of a ELF program header 220 * 196 /** 221 197 * \param elf_phdr_ptr : Pointer to the ELF program header to print 222 198 * 223 ********************************************************************/ 199 * \brief Print some fields of a ELF program header 200 */ 224 201 void reset_print_elf_phdr(Elf32_Phdr * elf_phdr_ptr) 225 202 { … … 243 220 } 244 221 245 246 /******************************************************************** 247 * reset_mcc_inval() 248 * 249 * Invalidate all data cache lines corresponding to a memory buffer 250 * (identified by an address and a size) in L2 cache. 251 ********************************************************************/ 252 #if USE_IOB 253 void reset_mcc_invalidate (const void * buffer, size_t size) 254 { 255 addr_t *mcc_address = (addr_t*)MCC_PADDR_BASE; 256 257 // get the hard lock assuring exclusive access to MEMC 258 while (ioread32(&mcc_address[MCC_LOCK])); 259 260 // write invalidate paremeters on the memory cache this preloader 261 // use only the cluster 0 and then the HI bits are not used 262 263 iowrite32(&mcc_address[MCC_ADDR_LO], (unsigned int) buffer); 264 iowrite32(&mcc_address[MCC_ADDR_HI], (unsigned int) 0); 265 iowrite32(&mcc_address[MCC_LENGTH] , (unsigned int) size); 266 iowrite32(&mcc_address[MCC_CMD] , (unsigned int) MCC_CMD_INVAL); 267 268 // release the lock protecting MEMC 269 iowrite32(&mcc_address[MCC_LOCK], (unsigned int) 0); 270 } 271 #endif 272 273 /******************************************************************** 274 * reset_dcache_buf_invalidate() 275 * 276 * Invalidate all data cache lines corresponding to a memory buffer 277 * (identified by an address and a size) in L1 cache and L2 cache. 278 ********************************************************************/ 279 #if (CACHE_COHERENCE == 0) || USE_IOB 280 void reset_buf_invalidate (const void * buffer, size_t line_size, size_t size) 281 { 282 unsigned int i; 283 284 // iterate on cache lines 285 for (i = 0; i <= size; i += line_size) 286 { 287 asm volatile( 288 " cache %0, %1" 289 :// no outputs 290 :"i" (0x11), "R" (*((unsigned char *) buffer + i)) 291 ); 292 } 293 294 #if USE_IOB 295 reset_mcc_invalidate(buffer, size); 296 #endif 297 } 298 #endif 299 300 // vim: tabstop=4 : softtabstop=4 : shiftwidth=4 : expandtab 222 /* 223 * vim: tabstop=4 : softtabstop=4 : shiftwidth=4 : expandtab 224 */
Note: See TracChangeset
for help on using the changeset viewer.