loader_prompt.c (161370) | loader_prompt.c (163597) |
---|---|
1/****************************************************************************** 2 * 3 * Filename: loader_prompt.c 4 * 5 * Instantiation of the interactive loader functions. 6 * 7 * Revision information: 8 * --- 5 unchanged lines hidden (view full) --- 14 * No warranty, expressed or implied, is included with this software. It is 15 * provided "AS IS" and no warranty of any kind including statutory or aspects 16 * relating to merchantability or fitness for any purpose is provided. All 17 * intellectual property rights of others is maintained with the respective 18 * owners. This software is not copyrighted and is intended for reference 19 * only. 20 * END_BLOCK 21 * | 1/****************************************************************************** 2 * 3 * Filename: loader_prompt.c 4 * 5 * Instantiation of the interactive loader functions. 6 * 7 * Revision information: 8 * --- 5 unchanged lines hidden (view full) --- 14 * No warranty, expressed or implied, is included with this software. It is 15 * provided "AS IS" and no warranty of any kind including statutory or aspects 16 * relating to merchantability or fitness for any purpose is provided. All 17 * intellectual property rights of others is maintained with the respective 18 * owners. This software is not copyrighted and is intended for reference 19 * only. 20 * END_BLOCK 21 * |
22 * $FreeBSD: head/sys/boot/arm/at91/bootspi/loader_prompt.c 161370 2006-08-16 23:39:58Z imp $ | 22 * $FreeBSD: head/sys/boot/arm/at91/bootspi/loader_prompt.c 163597 2006-10-21 22:44:26Z imp $ |
23 *****************************************************************************/ 24 25#include "at91rm9200_lowlevel.h" 26#include "at91rm9200.h" 27#include "emac.h" 28#include "loader_prompt.h" 29#include "env_vars.h" 30#include "lib.h" 31#include "spi_flash.h" | 23 *****************************************************************************/ 24 25#include "at91rm9200_lowlevel.h" 26#include "at91rm9200.h" 27#include "emac.h" 28#include "loader_prompt.h" 29#include "env_vars.h" 30#include "lib.h" 31#include "spi_flash.h" |
32#include "fpga.h" 33#include "ee.h" |
|
32 33/******************************* GLOBALS *************************************/ 34 35 36/*********************** PRIVATE FUNCTIONS/DATA ******************************/ 37 38static char inputBuffer[MAX_INPUT_SIZE]; 39static int buffCount; --- 20 unchanged lines hidden (view full) --- 60 {COMMAND_LOAD_SPI_KERNEL, "k"}, 61 {COMMAND_REPLACE_KERNEL_VIA_XMODEM, "K"}, 62 {COMMAND_REPLACE_FLASH_VIA_XMODEM, "I"}, 63 {COMMAND_REPLACE_FPGA_VIA_XMODEM, "F"}, 64 {COMMAND_REPLACE_ID_EEPROM, "E"}, 65 {COMMAND_FINAL_FLAG, 0} 66}; 67 | 34 35/******************************* GLOBALS *************************************/ 36 37 38/*********************** PRIVATE FUNCTIONS/DATA ******************************/ 39 40static char inputBuffer[MAX_INPUT_SIZE]; 41static int buffCount; --- 20 unchanged lines hidden (view full) --- 62 {COMMAND_LOAD_SPI_KERNEL, "k"}, 63 {COMMAND_REPLACE_KERNEL_VIA_XMODEM, "K"}, 64 {COMMAND_REPLACE_FLASH_VIA_XMODEM, "I"}, 65 {COMMAND_REPLACE_FPGA_VIA_XMODEM, "F"}, 66 {COMMAND_REPLACE_ID_EEPROM, "E"}, 67 {COMMAND_FINAL_FLAG, 0} 68}; 69 |
70#ifdef TSC_FPGA 71#include "fpga.h" 72 73const struct fpga main_fpga = 74{ 75 AT91C_BASE_PIOB, AT91C_PIO_PB0, 76 AT91C_BASE_PIOC, AT91C_PIO_PC11, 77 AT91C_BASE_PIOB, AT91C_PIO_PB2, 78 AT91C_BASE_PIOC, AT91C_PIO_PC12 79}; 80 81void 82fpga_load(void) 83{ 84 int len, off, i, offset; 85 char *addr = (char *)SDRAM_BASE + (1 << 20); /* Load to base + 1MB */ 86 87 len = FPGA_LEN; 88 offset = FPGA_OFFSET; 89 for (i = 0; i < len; i+= FLASH_PAGE_SIZE) { 90 off = i + offset; 91 SPI_ReadFlash(off, addr + i, FLASH_PAGE_SIZE); 92 } 93 fpga_init(&main_fpga); 94 fpga_clear(&main_fpga); 95 fpga_write_bytes(&main_fpga, addr, len); 96 fpga_done(&main_fpga); 97} 98#endif 99 |
|
68/* 69 * .KB_C_FN_DEFINITION_START 70 * unsigned BuildIP(void) 71 * This private function packs the test IP info to an unsigned value. 72 * .KB_C_FN_DEFINITION_END 73 */ 74static unsigned 75BuildIP(void) --- 12 unchanged lines hidden (view full) --- 88 * .KB_C_FN_DEFINITION_END 89 */ 90static int 91StringToCommand(char *cPtr) 92{ 93 int i; 94 95 for (i = 0; CommandTable[i].command != COMMAND_FINAL_FLAG; ++i) | 100/* 101 * .KB_C_FN_DEFINITION_START 102 * unsigned BuildIP(void) 103 * This private function packs the test IP info to an unsigned value. 104 * .KB_C_FN_DEFINITION_END 105 */ 106static unsigned 107BuildIP(void) --- 12 unchanged lines hidden (view full) --- 120 * .KB_C_FN_DEFINITION_END 121 */ 122static int 123StringToCommand(char *cPtr) 124{ 125 int i; 126 127 for (i = 0; CommandTable[i].command != COMMAND_FINAL_FLAG; ++i) |
96 if (!p_strcmp(CommandTable[i].c_string, cPtr)) | 128 if (!strcmp(CommandTable[i].c_string, cPtr)) |
97 return (CommandTable[i].command); 98 99 return (COMMAND_INVALID); 100} 101 102 103/* 104 * .KB_C_FN_DEFINITION_START --- 40 unchanged lines hidden (view full) --- 145static void 146UpdateEEProm(int eeaddr) 147{ 148 char *addr = (char *)SDRAM_BASE + (1 << 20); /* Load to base + 1MB */ 149 int len; 150 151 while ((len = xmodem_rx(addr)) == -1) 152 continue; | 129 return (CommandTable[i].command); 130 131 return (COMMAND_INVALID); 132} 133 134 135/* 136 * .KB_C_FN_DEFINITION_START --- 40 unchanged lines hidden (view full) --- 177static void 178UpdateEEProm(int eeaddr) 179{ 180 char *addr = (char *)SDRAM_BASE + (1 << 20); /* Load to base + 1MB */ 181 int len; 182 183 while ((len = xmodem_rx(addr)) == -1) 184 continue; |
153 printf("\r\nDownloaded %u bytes.\r\n", len); | 185 printf("\nDownloaded %u bytes.\n", len); |
154 WriteEEPROM(eeaddr, 0, addr, len); 155} 156#endif 157 158static void 159UpdateFlash(int offset) 160{ 161 char *addr = (char *)SDRAM_BASE + (1 << 20); /* Load to base + 1MB */ 162 int len, i, off; 163 164 while ((len = xmodem_rx(addr)) == -1) 165 continue; | 186 WriteEEPROM(eeaddr, 0, addr, len); 187} 188#endif 189 190static void 191UpdateFlash(int offset) 192{ 193 char *addr = (char *)SDRAM_BASE + (1 << 20); /* Load to base + 1MB */ 194 int len, i, off; 195 196 while ((len = xmodem_rx(addr)) == -1) 197 continue; |
166 printf("\r\nDownloaded %u bytes.\r\n", len); | 198 printf("\nDownloaded %u bytes.\n", len); |
167 for (i = 0; i < len; i+= FLASH_PAGE_SIZE) { 168 off = i + offset; 169 SPI_WriteFlash(off, addr + i, FLASH_PAGE_SIZE); 170 } 171} 172 173static void 174LoadKernelFromSpi(char *addr) --- 90 unchanged lines hidden (view full) --- 265 case COMMAND_XMODEM: 266 // "x <address>" 267 // download X-modem record at address 268 if (argc > 1) 269 xmodem_rx((char *)p_ASCIIToHex(argv[1])); 270 break; 271 272 case COMMAND_RESET: | 199 for (i = 0; i < len; i+= FLASH_PAGE_SIZE) { 200 off = i + offset; 201 SPI_WriteFlash(off, addr + i, FLASH_PAGE_SIZE); 202 } 203} 204 205static void 206LoadKernelFromSpi(char *addr) --- 90 unchanged lines hidden (view full) --- 297 case COMMAND_XMODEM: 298 // "x <address>" 299 // download X-modem record at address 300 if (argc > 1) 301 xmodem_rx((char *)p_ASCIIToHex(argv[1])); 302 break; 303 304 case COMMAND_RESET: |
273 printf("Reset\r\n"); | 305 printf("Reset\n"); |
274 reset(); 275 while (1) continue; 276 break; 277 278 case COMMAND_REPLACE_KERNEL_VIA_XMODEM: | 306 reset(); 307 while (1) continue; 308 break; 309 310 case COMMAND_REPLACE_KERNEL_VIA_XMODEM: |
279 printf("Updating KERNEL image\r\n"); | 311 printf("Updating KERNEL image\n"); |
280 UpdateFlash(KERNEL_OFFSET); 281 break; 282 case COMMAND_REPLACE_FPGA_VIA_XMODEM: | 312 UpdateFlash(KERNEL_OFFSET); 313 break; 314 case COMMAND_REPLACE_FPGA_VIA_XMODEM: |
283 printf("Updating FPGA image\r\n"); | 315 printf("Updating FPGA image\n"); |
284 UpdateFlash(FPGA_OFFSET); 285 break; 286 case COMMAND_REPLACE_FLASH_VIA_XMODEM: | 316 UpdateFlash(FPGA_OFFSET); 317 break; 318 case COMMAND_REPLACE_FLASH_VIA_XMODEM: |
287 printf("Updating FLASH image\r\n"); | 319 printf("Updating FLASH image\n"); |
288 UpdateFlash(FLASH_OFFSET); 289 break; 290 | 320 UpdateFlash(FLASH_OFFSET); 321 break; 322 |
323 case COMMAND_REPLACE_ID_EEPROM: 324 { 325 char buf[25]; 326 printf("Testing Config EEPROM\n"); 327 EEWrite(0, "This is a test", 15); 328 EERead(0, buf, 15); 329 printf("Found '%s'\n", buf); 330 break; 331 } |
|
291 default: 292 break; 293 } 294 | 332 default: 333 break; 334 } 335 |
295 printf("\r\n"); | 336 printf("\n"); |
296} 297 298 299/* 300 * .KB_C_FN_DEFINITION_START 301 * void ServicePrompt(char) 302 * This private function process each character checking for valid commands. 303 * This function is only executed if the character is considered valid. | 337} 338 339 340/* 341 * .KB_C_FN_DEFINITION_START 342 * void ServicePrompt(char) 343 * This private function process each character checking for valid commands. 344 * This function is only executed if the character is considered valid. |
304 * Each command is terminated with NULL (0) or '\r'. | 345 * Each command is terminated with NULL (0) or ''. |
305 * .KB_C_FN_DEFINITION_END 306 */ 307static void 308ServicePrompt(char p_char) 309{ 310 if (p_char == '\r') 311 p_char = 0; 312 --- 5 unchanged lines hidden (view full) --- 318 } 319 return; 320 } 321 if (buffCount < MAX_INPUT_SIZE - 1) { 322 inputBuffer[buffCount++] = p_char; 323 putchar(p_char); 324 } 325 if (!p_char) { | 346 * .KB_C_FN_DEFINITION_END 347 */ 348static void 349ServicePrompt(char p_char) 350{ 351 if (p_char == '\r') 352 p_char = 0; 353 --- 5 unchanged lines hidden (view full) --- 359 } 360 return; 361 } 362 if (buffCount < MAX_INPUT_SIZE - 1) { 363 inputBuffer[buffCount++] = p_char; 364 putchar(p_char); 365 } 366 if (!p_char) { |
326 printf("\r\n"); | 367 printf("\n"); |
327 ParseCommand(inputBuffer); 328 p_memset(inputBuffer, 0, MAX_INPUT_SIZE); 329 buffCount = 0; | 368 ParseCommand(inputBuffer); 369 p_memset(inputBuffer, 0, MAX_INPUT_SIZE); 370 buffCount = 0; |
330 printf("\r\n>"); | 371 printf("\n>"); |
331 } 332} 333 334 335/* ************************** GLOBAL FUNCTIONS ********************************/ 336 337 338/* --- 8 unchanged lines hidden (view full) --- 347void 348Bootloader(int(*inputFunction)(int)) 349{ 350 int ch = 0; 351 352 p_memset((void*)inputBuffer, 0, sizeof(inputBuffer)); 353 buffCount = 0; 354 | 372 } 373} 374 375 376/* ************************** GLOBAL FUNCTIONS ********************************/ 377 378 379/* --- 8 unchanged lines hidden (view full) --- 388void 389Bootloader(int(*inputFunction)(int)) 390{ 391 int ch = 0; 392 393 p_memset((void*)inputBuffer, 0, sizeof(inputBuffer)); 394 buffCount = 0; 395 |
355 printf("\r\n>"); | 396 printf("\n>"); |
356 357 while (1) 358 if ((ch = ((*inputFunction)(0))) > 0) 359 ServicePrompt(ch); 360} | 397 398 while (1) 399 if ((ch = ((*inputFunction)(0))) > 0) 400 ServicePrompt(ch); 401} |