static int bt_setenv(int argc, char **argv) { BT_u32 total_length = 0; BT_u32 i; for(i = 2; i < argc; i++) { total_length += strlen(argv[i]) + 1; // Add a space after each item. } if(!total_length) { clear_env(argv[1]); return 0; } char *s = BT_kMalloc(total_length+1); if(!s) { bt_printf("No memory could not allocated temporary memory to construct string\n"); return -1; } strcpy(s, ""); for(i = 2; i < argc; i++) { strcat(s, argv[i]); if(i == argc-1) { break; } strcat(s, " "); } BT_ShellSetEnv(argv[1], s, BT_ENV_T_STRING); BT_kFree(s); return 0; }
static int ext2_readblocks(unsigned char *pBuffer, unsigned int SectorAddress, unsigned int Count, void *pParam) { BT_HANDLE hVolume = (BT_HANDLE)pParam; BT_s32 slRead = BT_VolumeRead(hVolume, SectorAddress, Count, pBuffer); #if DEBUG int i, j; for(i=0;i<Count;i++) { bt_printf("%02d+%02d: ", SectorAddress, i); for(j=0;j<SECTOR_SIZE;j++) { if((j%16) == 0) bt_printf("\n "); bt_printf("%02x ", pBuffer[j]); } bt_printf("\n"); } #endif return (int) slRead; }
static int bt_boot(int argc, char **argv) { if(argc != 2 && argc != 4) { bt_printf("Usage: %s {--core [coreID]} [start-address]\n", argv[0]); return -1; } BT_u32 coreID = 0; BT_u32 addr; if(argc == 4) { if(strcmp(argv[1], "--core")) { bt_printf("Invalid argument %s\n", argv[1]); return -1; } coreID = strtol(argv[2], NULL, 10); addr = strtol(argv[3], NULL, 16); } else { addr = strtol(argv[1], NULL, 16); } void *p = (void *) addr; BT_DCacheFlush(); BT_ICacheInvalidate(); BT_DCacheDisable(); if(!coreID) { BT_StopSystemTimer(); BT_DisableInterrupts(); jump jmp = p; jmp(); while(1) { __asm__ (""); } } else { // Must use MACH core boot interface. BT_BootCore(coreID, p); } return 0; }
BT_ERROR BT_kPrint(const char *format, ... ) { va_list ap; #ifndef BT_CONFIG_KERNEL_NONE #ifdef BT_CONFIG_SYSLOG_SYSTICK BT_TICK oTicks = BT_GetKernelTick(); bt_printf("[%5d.%03d] : ", oTicks / 1000, oTicks % 1000); #else BT_u64 gt = BT_GetGlobalTimer(); BT_u32 rate = BT_GetGlobalTimerRate(); bt_printf("[%5d.%06d] : ", (BT_u32) (gt / (BT_u64)rate), (BT_u32) ((1000000 * (gt % (BT_u64)rate)) / rate )); #endif #endif va_start(ap, format); bt_kvprintf(format, bt_fputc, BT_GetStdout(), 10, ap); va_end(ap); #ifdef BT_CONFIG_SYSLOG_LINE_ENDINGS_CR bt_printf("\n"); #endif #ifdef BT_CONFIG_SYSLOG_LINE_ENDINGS_LF bt_printf("\r"); #endif #ifdef BT_CONFIG_SYSLOG_LINE_ENDINGS_CRLF bt_printf("\n\r"); #endif #ifdef BT_CONFIG_SYSLOG_LINE_ENDINGS_LFCR bt_printf("\r\n"); #endif return BT_ERR_NONE; }
static int bt_boot_jtag(int argc, char **argv) { if(argc != 3) { bt_printf("Usage: %s --core [coreID]\n", argv[0]); return -1; } BT_u32 coreID = 0; if(strcmp(argv[1], "--core")) { bt_printf("Invalid argument %s\n", argv[1]); return -1; } coreID = strtoul(argv[2], NULL, 10); void *p = (void *) wait_jtag; BT_DCacheFlush(); BT_ICacheInvalidate(); if(!coreID) { BT_StopSystemTimer(); BT_DisableInterrupts(); jump jmp = p; jmp(); while(1) { __asm__ (""); } } else { // Must use MACH core boot interface. BT_BootCore(coreID, p); } return 0; }
static int bt_gpio(int argc, char **argv) { if(argc != 3) { bt_printf("Usage: %s {gpio_nr} {1|0}\n", argv[0]); return -1; } BT_u32 gpio = strtoul(argv[1], NULL, 10); BT_u32 state = strtoul(argv[2], NULL, 10); if(!state) { state = BT_FALSE; } else { state = BT_TRUE; } BT_GpioSet(gpio, state); return 0; }
static int bt_gpio_dir(int argc, char **argv) { if(argc != 3) { bt_printf("Usage: %s {gpio_nr} {1|0}\n", argv[0]); return -1; } BT_u32 gpio = strtoul(argv[1], NULL, 10); BT_u32 state = strtoul(argv[2], NULL, 10); if(!state) { state = BT_GPIO_DIR_INPUT; } else { state = BT_GPIO_DIR_OUTPUT; } BT_GpioSetDirection(gpio, state); return 0; }
void __hidden print_dvm_bt(struct tls_info *tls, struct dvm_iface *dvm, struct dvm_bt *dvm_bt) { int ii; ii = compare_traces(tls, dvm, dvm_bt); if (ii < 0) { __bt_printf(tls, "DVM:BT_REPEAT:1:"); return; } /* else if (ii > 1) __bt_printf(tls, "DVM:BT_REPEAT:%d:", ii); */ bt_printf(tls, "DVM:BT_START:%d:", dvm_bt->count); for (ii = 0; ii < dvm_bt->count; ii++) { print_dvm_sym(tls, dvm, ii, dvm_bt->mlist[ii]); } /* bt_printf(tls, "DVM:BT_END:"); */ return; }
static int bt_load_fpga(BT_HANDLE hShell, int argc, char **argv) { BT_HANDLE hStdout = BT_ShellGetStdout(hShell); BT_ERROR Error; if(argc != 4 && argc != 5) { bt_fprintf(hStdout, "Usage: %s [buffer_address] [fpga_device] [bitstream] [length]\n", argv[0]); return -1; } BT_u32 length = 0; BT_u32 addr = strtoul(argv[1], NULL, 16); void *p = (void *) addr; if(argv[3][0] == '-' && argc == 5) { // Image loaded and length provided. length = strtoul(argv[4], NULL, 10); goto flush; } BT_HANDLE hFile = BT_Open(argv[3], BT_GetModeFlags("rb"), &Error); if(!hFile) { bt_fprintf(hStdout, "Could not open bitstream at %s\n", argv[3]); return -1; } BT_HANDLE hInode = BT_GetInode(argv[3], &Error); if(!hInode) { bt_fprintf(hStdout, "Could not stat bitstream at %s\n", argv[3]); BT_CloseHandle(hFile); return -1; } BT_INODE oInode; BT_ReadInode(hInode, &oInode); BT_kPrint("Loading %s at %08X (%llu bytes)", argv[3], addr, oInode.ullFileSize); BT_Read(hFile, 0, oInode.ullFileSize, p, &Error); BT_kPrint("Load successful"); if(hFile) { BT_CloseHandle(hFile); } if(hInode) { BT_CloseHandle(hInode); } length = oInode.ullFileSize; flush: BT_DCacheFlush(); BT_HANDLE hFPGA = BT_DeviceOpen(argv[2], &Error); if(!hFPGA) { bt_printf("Failed to open fpga device %s\n", argv[2]); return -1; } BT_Write(hFPGA, 0, length, p, &Error); BT_CloseHandle(hFPGA); return 0; }