static void fis_delete(int argc, char *argv[]) { char *name; int num_reserved, i, stat; void *err_addr; struct fis_image_desc *img; if (!scan_opts(argc, argv, 2, 0, 0, (void *)&name, OPTION_ARG_TYPE_STR, "image name")) { fis_usage("invalid arguments"); return; } #ifdef CYGHWR_REDBOOT_ARM_FLASH_SIB // FIXME: this is somewhat half-baked arm_fis_delete(name); return; #endif img = (struct fis_image_desc *)fis_work_block; num_reserved = 0; #ifdef CYGOPT_REDBOOT_FIS_RESERVED_BASE num_reserved++; #endif #ifdef CYGOPT_REDBOOT_FIS_REDBOOT num_reserved++; #endif #ifdef CYGOPT_REDBOOT_FIS_REDBOOT_BACKUP num_reserved++; #endif #ifdef CYGOPT_REDBOOT_FIS_REDBOOT_POST num_reserved++; #endif #if defined(CYGSEM_REDBOOT_FLASH_CONFIG) && defined(CYGHWR_REDBOOT_FLASH_CONFIG_MEDIA_FLASH) num_reserved++; #endif #if 1 // And the descriptor for the descriptor table itself num_reserved++; #endif img = fis_lookup(name, &i); if (img) { if (i < num_reserved) { diag_printf("Sorry, '%s' is a reserved image and cannot be deleted\n", img->name); return; } if (!verify_action("Delete image '%s'", name)) { return; } } else { diag_printf("No image '%s' found\n", name); return; } // Erase Data blocks (free space) if ((stat = flash_erase((void *)img->flash_base, img->size, (void **)&err_addr)) != 0) { diag_printf("Error erasing at %p: %s\n", err_addr, flash_errmsg(stat)); } else { img->name[0] = (unsigned char)0xFF; fis_update_directory(); } }
static void do_delay(int argc, char *argv[]) { struct option_info opts[1]; int count = 0x00000000; bool count_set; int value; register int i; init_opts(&opts[0], 'c', true, OPTION_ARG_TYPE_NUM, (void**)&count, &count_set, "Number of times to delay"); if (!scan_opts(argc, argv, 1, opts, sizeof(opts) / sizeof(opts[0]), (void*)&value, OPTION_ARG_TYPE_NUM, "amount of time to delay (usec)")) { return; } if (!count_set) { count = 1; } for (i = 0; i < count; i++) { diag_printf("Delaying %d useconds...", value); HAL_DELAY_US(value); diag_printf("Done\n"); } }
static void do_gpio(int argc,char *argv[]) { struct option_info opts[2]; bool set_bits_set, clr_bits_set; int set_bits, clr_bits; init_opts(&opts[0], 's', true, OPTION_ARG_TYPE_NUM, (void **)&set_bits, (bool *)&set_bits_set, "bits to set"); init_opts(&opts[1], 'c', true, OPTION_ARG_TYPE_NUM, (void **)&clr_bits, (bool *)&clr_bits_set, "bits to clear"); if (!scan_opts(argc, argv, 1, opts, 2, NULL, 0, NULL)) { return; } if ( !set_bits_set && !clr_bits_set ) { // display only diag_printf(" gpio = 0x%08lX\n", *SA11X0_GPIO_PIN_LEVEL); diag_printf(" 0x%08lX are output\n", *SA11X0_GPIO_PIN_DIRECTION); diag_printf(" 0x%08lX rising edge detect\n", *SA11X0_GPIO_RISING_EDGE_DETECT); diag_printf(" 0x%08lX falling edge detect\n", *SA11X0_GPIO_FALLING_EDGE_DETECT); diag_printf(" 0x%08lX edge detect status\n", *SA11X0_GPIO_EDGE_DETECT_STATUS); diag_printf(" 0x%08lX alternate function\n", *SA11X0_GPIO_ALTERNATE_FUNCTION); return; } diag_printf( " gpio 0x%08lX, ", *SA11X0_GPIO_PIN_LEVEL); if ( set_bits_set ) { diag_printf("set(0x%08X) ",set_bits); *SA11X0_GPIO_PIN_OUTPUT_SET = set_bits; } if ( clr_bits_set ) { diag_printf("clear(0x%08X) ",clr_bits); *SA11X0_GPIO_PIN_OUTPUT_CLEAR = clr_bits; } diag_printf( "gives 0x%08lX\n", *SA11X0_GPIO_PIN_LEVEL); }
void do_cksum(int argc, char *argv[]) { struct option_info opts[2]; unsigned long base, len, crc; bool base_set, len_set; init_opts(&opts[0], 'b', true, OPTION_ARG_TYPE_NUM, (void *)&base, (bool *)&base_set, "base address"); init_opts(&opts[1], 'l', true, OPTION_ARG_TYPE_NUM, (void *)&len, (bool *)&len_set, "length"); if (!scan_opts(argc, argv, 1, opts, 2, 0, 0, "")) { return; } if (!base_set || !len_set) { if (load_address >= (CYG_ADDRESS)ram_start && load_address_end < (CYG_ADDRESS)ram_end && load_address < load_address_end) { base = load_address; len = load_address_end - load_address; diag_printf("Computing cksum for area %lx-%lx\n", base, load_address_end); } else { diag_printf("usage: cksum -b <addr> -l <length>\n"); return; } } crc = cyg_posix_crc32((unsigned char *)base, len); diag_printf("POSIX cksum = %lu %lu (0x%08lx 0x%08lx)\n", crc, len, crc, len); }
static void do_mem(int argc, char *argv[]) { struct option_info opts[3]; bool mem_half_word, mem_byte; static int address = 0x00000000; int value; init_opts(&opts[0], 'b', false, OPTION_ARG_TYPE_FLG, (void**)&mem_byte, 0, "write a byte"); init_opts(&opts[1], 'h', false, OPTION_ARG_TYPE_FLG, (void**)&mem_half_word, 0, "write a half-word"); init_opts(&opts[2], 'a', true, OPTION_ARG_TYPE_NUM, (void**)&address, NULL, "address to write at"); if (!scan_opts(argc, argv, 1, opts, 3, (void*)&value, OPTION_ARG_TYPE_NUM, "address to set")) return; if ( mem_byte && mem_half_word ) { diag_printf("*ERR: Should not specify both byte and half-word access\n"); } else if ( mem_byte ) { *(cyg_uint8*)address = (cyg_uint8)(value & 255); diag_printf(" Set 0x%08X to 0x%02X (result 0x%02X)\n", address, value & 255, (int)*(cyg_uint8*)address ); } else if ( mem_half_word ) { if ( address & 1 ) { diag_printf( "*ERR: Badly aligned address 0x%08X for half-word store\n", address ); } else { *(cyg_uint16*)address = (cyg_uint16)(value & 0xffff); diag_printf(" Set 0x%08X to 0x%04X (result 0x%04X)\n", address, value & 0xffff, (int)*(cyg_uint16*)address ); } } else { if ( address & 3 ) { diag_printf( "*ERR: Badly aligned address 0x%08X for word store\n", address ); } else { *(cyg_uint32*)address = (cyg_uint32)value; diag_printf(" Set 0x%08X to 0x%08X (result 0x%08X)\n", address, value, (int)*(cyg_uint32*)address ); } } }
static void do_egpio(int argc,char *argv[]) { struct option_info opts[2]; bool set_bits_set, clr_bits_set; int set_bits, clr_bits; init_opts(&opts[0], 's', true, OPTION_ARG_TYPE_NUM, (void **)&set_bits, (bool *)&set_bits_set, "bits to set"); init_opts(&opts[1], 'c', true, OPTION_ARG_TYPE_NUM, (void **)&clr_bits, (bool *)&clr_bits_set, "bits to clear"); if (!scan_opts(argc, argv, 1, opts, 2, NULL, 0, NULL)) return; if ( !set_bits_set && !clr_bits_set ) { // display only diag_printf(" egpio = 0x%04X\n", (int)(_ipaq_EGPIO & 0xffff)); return; } diag_printf( " egpio 0x%04X, ", (int)(_ipaq_EGPIO & 0xffff)); if ( set_bits_set ) { diag_printf("set(0x%08X) ",set_bits); ipaq_EGPIO( set_bits, set_bits ); } if ( clr_bits_set ) { diag_printf("clear(0x%08X) ",clr_bits); ipaq_EGPIO( clr_bits, 0x0000 ); } diag_printf( "gives 0x%04X\n", (int)(_ipaq_EGPIO & 0xffff)); }
static void do_exec(int argc, char *argv[]) { unsigned long oldints; bool wait_time_set; int wait_time, res; bool cmd_line_set; struct option_info opts[4]; code_fun entry; char line[8]; char *cmd_line; int num_options; entry = (code_fun)entry_address; // Default from last 'load' operation init_opts(&opts[0], 'w', true, OPTION_ARG_TYPE_NUM, (void **)&wait_time, (bool *)&wait_time_set, "wait timeout"); init_opts(&opts[1], 'c', true, OPTION_ARG_TYPE_STR, (void **)&cmd_line, (bool *)&cmd_line_set, "kernel command line"); num_options = 2; if (!scan_opts(argc, argv, 1, opts, num_options, (void *)&entry, OPTION_ARG_TYPE_NUM, "starting address")) { return; } if (entry == (unsigned long)NO_MEMORY) { diag_printf("Can't execute Linux - invalid entry address\n"); return; } if (cmd_line_set) { memcpy((char*)CYGHWR_REDBOOT_AM33_LINUX_CMD_ADDRESS,"cmdline:",8); strncpy((char*)CYGHWR_REDBOOT_AM33_LINUX_CMD_ADDRESS+8,cmd_line,256); *(char*)(CYGHWR_REDBOOT_AM33_LINUX_CMD_ADDRESS+8+256) = 0; } else { *(char*)(CYGHWR_REDBOOT_AM33_LINUX_CMD_ADDRESS+256) = 0; } if (wait_time_set) { diag_printf("About to start execution at %p - abort with ^C within %d seconds\n", (void *)entry, wait_time); res = _rb_gets(line, sizeof(line), wait_time*1000); if (res == _GETS_CTRLC) { return; } } #ifdef CYGPKG_IO_ETH_DRIVERS eth_drv_stop(); #endif HAL_DISABLE_INTERRUPTS(oldints); HAL_DCACHE_SYNC(); HAL_ICACHE_DISABLE(); HAL_DCACHE_DISABLE(); HAL_DCACHE_SYNC(); HAL_ICACHE_INVALIDATE_ALL(); HAL_DCACHE_INVALIDATE_ALL(); (*entry)(); }
void do_baud_rate(int argc, char *argv[]) { int new_rate, ret, old_rate; bool new_rate_set; hal_virtual_comm_table_t *__chan; struct option_info opts[1]; #ifdef CYGSEM_REDBOOT_FLASH_CONFIG struct config_option opt; #endif init_opts(&opts[0], 'b', true, OPTION_ARG_TYPE_NUM, (void **)&new_rate, (bool *)&new_rate_set, "new baud rate"); if (!scan_opts(argc, argv, 1, opts, 1, 0, 0, "")) { return; } __chan = CYGACC_CALL_IF_CONSOLE_PROCS(); if (new_rate_set) { diag_printf("Baud rate will be changed to %d - update your settings\n", new_rate); _sleep(500); // Give serial time to flush old_rate = CYGACC_COMM_IF_CONTROL(*__chan, __COMMCTL_GETBAUD); ret = set_console_baud_rate(new_rate); if (ret < 0) { if (old_rate > 0) { // Try to restore set_console_baud_rate(old_rate); _sleep(500); // Give serial time to flush diag_printf("\nret = %d\n", ret); } return; // Couldn't set the desired rate } old_rate = ret; // Make sure this new rate works or back off to previous value // Sleep for a few seconds, then prompt to see if it works _sleep(3000); // Give serial time to flush if (!verify_action_with_timeout(5000, "Baud rate changed to %d", new_rate)) { _sleep(500); // Give serial time to flush set_console_baud_rate(old_rate); _sleep(500); // Give serial time to flush return; } #ifdef CYGSEM_REDBOOT_FLASH_CONFIG opt.type = CONFIG_INT; opt.enable = (char *)0; opt.enable_sense = 1; opt.key = "console_baud_rate"; opt.dflt = new_rate; flash_add_config(&opt, true); #endif } else { ret = CYGACC_COMM_IF_CONTROL(*__chan, __COMMCTL_GETBAUD); diag_printf("Baud rate = "); if (ret <= 0) { diag_printf("unknown\n"); } else { diag_printf("%d\n", ret); } } }
//// // main // int main (int argc, char **argv) { // Creat a struct for the options. struct options options = {FALSE, FALSE, NULL, FALSE, NULL, FALSE, NULL}; set_execname (argv[0]); // Set the execution name. // Get the options from the command line. scan_opts (argc, argv, &options); // char buffer[256]; bzero (buffer, 256); int sockfd, n; int portno = 1337; // Default server port number 1337 struct sockaddr_in serv_addr; struct hostent *server; // SOCKET sockfd = socket (AF_INET, SOCK_STREAM, 0); if (sockfd < 0) error ("opening socket"); // GETHOSTBYNAME server = gethostbyname (options.serverIP); if (server == NULL) error ("no such host"); bzero ((char *) &serv_addr, sizeof (serv_addr)); serv_addr.sin_family = AF_INET; bcopy ((char *) server->h_addr, (char *) &serv_addr.sin_addr.s_addr, server->h_length); serv_addr.sin_port = htons (portno); // CONNECT if (connect (sockfd, (struct sockaddr *) &serv_addr, sizeof (serv_addr)) < 0) error ("connecting"); // vote protocol if (options.vote) { // convert candidate name to all lower case char *cand = strdup (options.candidateName); char *voter = strdup (options.voterID); int i; for (i = 0; cand[i]; ++i) cand[i] = tolower (cand[i]); vote_func (sockfd, cand, voter); free (cand); // strdup uses malloc free (voter); } // results protocol if (options.results) results_func (sockfd); // finish protocol n = write (sockfd, "done", 4); if (n < 0) error ("writing to socket"); bzero (buffer, 256); // verify finish n = read (sockfd, buffer, 255); if (n < 0) error ("reading socket"); if (strcmp (buffer, "done") != 0) error ("finishing"); // CLOSE close (sockfd); return get_exitstatus(); }
static void do_set_npe_mac(int argc, char *argv[]) { bool portnum_set; int portnum, i; char *addr = 0; struct option_info opts[1]; cyg_uint8 mac[6]; init_opts(&opts[0], 'p', true, OPTION_ARG_TYPE_NUM, (void **)&portnum, (bool *)&portnum_set, "port number"); if (!scan_opts(argc, argv, 1, opts, 1, (void *)&addr, OPTION_ARG_TYPE_STR, "MAC address")) { return; } if ((!portnum_set && addr) || (portnum_set && portnum != 0 && portnum != 1)) { diag_printf("Must specify port with \"-p <0|1>\"\n"); return; } if (!portnum_set) { for (i = 0; i < 2; i++) { cyghal_get_npe_esa(i, mac); diag_printf("NPE eth%d mac: %02x:%02x:%02x:%02x:%02x:%02x\n", i, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); } return; } if (!addr) { cyghal_get_npe_esa(portnum, mac); diag_printf("NPE eth%d mac: %02x:%02x:%02x:%02x:%02x:%02x\n", portnum, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); return; } // parse MAC address from user. // acceptable formats are "nn:nn:nn:nn:nn:nn" and "nnnnnnnnnnnn" for (i = 0; i < 6; i++) { if (!_is_hex(addr[0]) || !_is_hex(addr[1])) break; mac[i] = (_from_hex(addr[0]) * 16) + _from_hex(addr[1]); addr += 2; if (*addr == ':') addr++; } if (i != 6 || *addr != '\0') { diag_printf("Malformed MAC address.\n"); return; } for (i = 0; i < 6; i++) { eeprom_write(MAC_EEPROM_OFFSET(portnum) + i, mac[i]); hal_delay_us(100000); } }
void do_gunzip(int argc, char *argv[]) { struct option_info opts[2]; unsigned long src, dst; bool src_set, dst_set; _pipe_t pipe; _pipe_t* p = &pipe; int err; init_opts(&opts[0], 's', true, OPTION_ARG_TYPE_NUM, (void *)&src, (bool *)&src_set, "source address"); init_opts(&opts[1], 'd', true, OPTION_ARG_TYPE_NUM, (void *)&dst, (bool *)&dst_set, "destination address"); if (!scan_opts(argc, argv, 1, opts, 2, 0, 0, "")) { return; } // Must have src and dst if (!src_set || !dst_set) { // try to use load_address for src if (dst_set && load_address >= (CYG_ADDRESS)ram_start && load_address < load_address_end) { src = load_address; diag_printf("Decompressing from %p to %p\n", (void*)src, (void*)dst); } else { diag_printf("usage: gunzip -s <addr> -d <addr>\n"); return; } } p->out_buf = (unsigned char*)dst; p->out_max = p->out_size = -1; p->in_buf = (unsigned char*)src; p->in_avail = -1; err = (*_dc_init)(p); if (0 == err) err = (*_dc_inflate)(p); // Free used resources, do final translation of error value. err = (*_dc_close)(p, err); if (0 != err && p->msg) { entry_address = (CYG_ADDRESS)NO_MEMORY; diag_printf("Decompression error: %s\n", p->msg); } else { load_address = entry_address = (CYG_ADDRESS)dst; load_address_end = (CYG_ADDRESS)p->out_buf; diag_printf("Decompressed %lu bytes\n", load_address_end - load_address); } }
static void do_physaddr(int argc, char *argv[]) { unsigned long phys_addr, virt_addr; if ( !scan_opts(argc,argv,1,0,0,(void*)&virt_addr, OPTION_ARG_TYPE_NUM, "virtual address") ) return; phys_addr = hal_virt_to_phys_address(virt_addr); diag_printf("Virtual addr %p = physical addr %p\n", virt_addr, phys_addr); }
void do_iopoke(int argc, char *argv[]) { struct option_info opts[5]; unsigned long base; bool base_set, value_set; bool set_32bit = false; bool set_16bit = false; bool set_8bit = false; cyg_uint32 value; int size = 1; init_opts(&opts[0], 'b', true, OPTION_ARG_TYPE_NUM, &base, &base_set, "base address"); init_opts(&opts[1], 'v', true, OPTION_ARG_TYPE_NUM, &value, &value_set, "valuex"); init_opts(&opts[2], '4', false, OPTION_ARG_TYPE_FLG, &set_32bit, 0, "output 32 bit units"); init_opts(&opts[3], '2', false, OPTION_ARG_TYPE_FLG, &set_16bit, 0, "output 16 bit units"); init_opts(&opts[4], '1', false, OPTION_ARG_TYPE_FLG, &set_8bit, 0, "output 8 bit units"); if (!scan_opts(argc, argv, 1, opts, 5, 0, 0, "")) { return; } if (!base_set) { diag_printf("iopoke what <location>?\n"); return; } if (!value_set) { diag_printf("iopoke what <value>?\n"); return; } if (set_32bit) { size = 4; } else if (set_16bit) { size = 2; } else if (set_8bit) { size = 1; } switch (size) { case 4: HAL_WRITE_UINT32 ( base, value ); break; case 2: HAL_WRITE_UINT16 ( base, value ); break; case 1: HAL_WRITE_UINT8 ( base, value ); break; } }
void do_ip_addr(int argc, char *argv[]) { struct option_info opts[3]; char *ip_addr, *host_addr; bool ip_addr_set, host_addr_set; struct sockaddr_in host; #ifdef CYGPKG_REDBOOT_NETWORKING_DNS char *dns_addr; bool dns_addr_set; #endif int num_opts; init_opts(&opts[0], 'l', true, OPTION_ARG_TYPE_STR, (void **)&ip_addr, (bool *)&ip_addr_set, "local IP address"); init_opts(&opts[1], 'h', true, OPTION_ARG_TYPE_STR, (void **)&host_addr, (bool *)&host_addr_set, "default server address"); num_opts = 2; #ifdef CYGPKG_REDBOOT_NETWORKING_DNS init_opts(&opts[2], 'd', true, OPTION_ARG_TYPE_STR, (void **)&dns_addr, (bool *)&dns_addr_set, "DNS server address"); num_opts++; #endif if (!scan_opts(argc, argv, 1, opts, num_opts, 0, 0, "")) { return; } if (ip_addr_set) { if (!_gethostbyname(ip_addr, (in_addr_t *)&host)) { diag_printf("Invalid local IP address: %s\n", ip_addr); return; } // Of course, each address goes in its own place :-) memcpy(&__local_ip_addr, &host.sin_addr, sizeof(host.sin_addr)); } if (host_addr_set) { if (!_gethostbyname(host_addr, (in_addr_t *)&host)) { diag_printf("Invalid server address: %s\n", host_addr); return; } my_bootp_info.bp_siaddr = host.sin_addr; } #ifdef CYGPKG_REDBOOT_NETWORKING_DNS if (dns_addr_set) { set_dns(dns_addr); } #endif show_addrs(); if (!have_net) { have_net = true; net_io_init(); } }
void do_go(int argc, char *argv[]) { typedef void code_fun(void); unsigned long entry; unsigned long oldints; code_fun *fun; bool wait_time_set; int wait_time, res; struct option_info opts[1]; char line[8]; entry = entry_address; // Default from last 'load' operation init_opts(&opts[0], 'w', true, OPTION_ARG_TYPE_NUM, (void **)&wait_time, (bool *)&wait_time_set, "wait timeout"); if (!scan_opts(argc, argv, 1, opts, 1, (void *)&entry, OPTION_ARG_TYPE_NUM, "starting address")) { return; } if (wait_time_set) { int script_timeout_ms = wait_time * 1000; #ifdef CYGSEM_REDBOOT_FLASH_CONFIG unsigned char *hold_script = script; script = (unsigned char *)0; #endif diag_printf("About to start execution at %p - abort with ^C within %d seconds\n", (void *)entry, wait_time); while (script_timeout_ms >= CYGNUM_REDBOOT_CLI_IDLE_TIMEOUT) { res = _rb_gets(line, sizeof(line), CYGNUM_REDBOOT_CLI_IDLE_TIMEOUT); if (res == _GETS_CTRLC) { #ifdef CYGSEM_REDBOOT_FLASH_CONFIG script = hold_script; // Re-enable script #endif return; } script_timeout_ms -= CYGNUM_REDBOOT_CLI_IDLE_TIMEOUT; } } fun = (code_fun *)entry; HAL_DISABLE_INTERRUPTS(oldints); HAL_DCACHE_SYNC(); HAL_ICACHE_DISABLE(); HAL_DCACHE_DISABLE(); HAL_DCACHE_SYNC(); HAL_ICACHE_INVALIDATE_ALL(); HAL_DCACHE_INVALIDATE_ALL(); #ifdef HAL_ARCH_PROGRAM_NEW_STACK HAL_ARCH_PROGRAM_NEW_STACK(fun); #else (*fun)(); #endif }
void do_help(int argc, char *argv[]) { struct cmd *cmd; char *which = (char *)0; if (!scan_opts(argc, argv, 1, 0, 0, (void **)&which, OPTION_ARG_TYPE_STR, "<topic>")) { diag_printf("Invalid argument\n"); return; } cmd = __RedBoot_CMD_TAB__; show_help(cmd, &__RedBoot_CMD_TAB_END__, which, ""); return; }
void do_iopeek(int argc, char *argv[]) { struct option_info opts[4]; unsigned long base; bool base_set; bool set_32bit = false; bool set_16bit = false; bool set_8bit = false; int size = 1, value; init_opts(&opts[0], 'b', true, OPTION_ARG_TYPE_NUM, &base, &base_set, "base address"); init_opts(&opts[1], '4', false, OPTION_ARG_TYPE_FLG, &set_32bit, 0, "output 32 bit units"); init_opts(&opts[2], '2', false, OPTION_ARG_TYPE_FLG, &set_16bit, 0, "output 16 bit units"); init_opts(&opts[3], '1', false, OPTION_ARG_TYPE_FLG, &set_8bit, 0, "output 8 bit units"); if (!scan_opts(argc, argv, 1, opts, 4, 0, 0, "")) { return; } if (!base_set) { diag_printf("iopeek what <location>?\n"); return; } if (set_32bit) { size = 4; } else if (set_16bit) { size = 2; } else if (set_8bit) { size = 1; } switch (size) { case 4: HAL_READ_UINT32 ( base, value ); diag_printf("0x%04lx = 0x%08x\n", base, value ); break; case 2: HAL_READ_UINT16 ( base, value ); diag_printf("0x%04lx = 0x%04x\n", base, value ); break; case 1: HAL_READ_UINT8 ( base, value ); diag_printf("0x%04lx = 0x%02x\n", base, value ); break; } }
static void fis_unlock(int argc, char *argv[]) { char *name; int stat; unsigned long length; CYG_ADDRESS flash_addr; bool flash_addr_set = false; bool length_set = false; void *err_addr; struct option_info opts[2]; init_opts(&opts[0], 'f', true, OPTION_ARG_TYPE_NUM, (void *)&flash_addr, (bool *)&flash_addr_set, "FLASH memory base address"); init_opts(&opts[1], 'l', true, OPTION_ARG_TYPE_NUM, (void *)&length, (bool *)&length_set, "length"); if (!scan_opts(argc, argv, 2, opts, 2, &name, OPTION_ARG_TYPE_STR, "image name")) { fis_usage("invalid arguments"); return; } if (name) { struct fis_image_desc *img; if ((img = fis_lookup(name, NULL)) == (struct fis_image_desc *)0) { diag_printf("No image '%s' found\n", name); return; } flash_addr = img->flash_base; length = img->size; } else if (!flash_addr_set || !length_set) { fis_usage("missing argument"); return; } if (flash_addr_set && ((stat = flash_verify_addr((void *)flash_addr)) || (stat = flash_verify_addr((void *)(flash_addr+length-1))))) { _show_invalid_flash_address(flash_addr, stat); return; } if ((stat = flash_unlock((void *)flash_addr, length, (void **)&err_addr)) != 0) { diag_printf("Error unlocking at %p: %s\n", err_addr, flash_errmsg(stat)); } }
static void fis_erase(int argc, char *argv[]) { int stat; unsigned long length; CYG_ADDRESS flash_addr; bool flash_addr_set = false; bool length_set = false; void *err_addr; struct option_info opts[2]; init_opts(&opts[0], 'f', true, OPTION_ARG_TYPE_NUM, (void *)&flash_addr, (bool *)&flash_addr_set, "FLASH memory base address"); init_opts(&opts[1], 'l', true, OPTION_ARG_TYPE_NUM, (void *)&length, (bool *)&length_set, "length"); if (!scan_opts(argc, argv, 2, opts, 2, (void **)0, 0, "")) { fis_usage("invalid arguments"); return; } if (!flash_addr_set || !length_set) { fis_usage("missing argument"); return; } if (flash_addr_set && ((stat = flash_verify_addr((void *)flash_addr)) || (stat = flash_verify_addr((void *)(flash_addr+length-1))))) { _show_invalid_flash_address(flash_addr, stat); return; } if (flash_addr_set && flash_addr & (flash_block_size-1)) { diag_printf("Invalid FLASH address: %p\n", (void *)flash_addr); diag_printf(" must be 0x%x aligned\n", flash_block_size); return; } // Safety check - make sure the address range is not within the code we're running if (flash_code_overlaps((void *)flash_addr, (void *)(flash_addr+length-1))) { diag_printf("Can't erase this region - contains code in use!\n"); return; } if ((stat = flash_erase((void *)flash_addr, length, (void **)&err_addr)) != 0) { diag_printf("Error erasing at %p: %s\n", err_addr, flash_errmsg(stat)); } }
static void do_umount(int argc, char *argv[]) { char *dir_str; int err; int i; if( mount_count == 0 ) { err_printf("fs: No filesystems mounted\n"); return; } if (!scan_opts(argc, argv, 1, NULL, 0, &dir_str, OPTION_ARG_TYPE_STR, "mountpoint")) return; if( dir_str == 0 ) dir_str = "/"; for( i = 0; i < MAX_MOUNTS; i++ ) { if( strcmp(mounts[i].mp_str, dir_str ) == 0 ) break; } if( i == MAX_MOUNTS ) { err_printf("fs unmount: unknown mountpoint %s\n",dir_str); return; } err = umount (dir_str); if (err) err_printf("fs umount: unmount failed %d\n", errno); else { mounts[i].mp_str[0] = '\0'; mount_count--; if( mount_count == 0 ) chdir( "/" ); } }
//-------------------------------------------------------------------------- // do_led -- // static void do_led (int argc, char *argv[]) { struct option_info opts[1]; unsigned long mask; bool mask_set; init_opts (&opts[0], 'm', true, OPTION_ARG_TYPE_NUM, &mask, &mask_set, "mask"); if (!scan_opts (argc, argv, 1, opts, 1, 0, 0, "")) { return; } if (!mask_set) { diag_printf ("led what <mask>?\n"); return; } hal_lpc2xxx_set_leds (mask); return; }
#if 0 //========================================================================== // // redboot_cmds.c // // OMAP1510DC EVM [platform] specific RedBoot commands // //========================================================================== // ####ECOSGPLCOPYRIGHTBEGIN#### // ------------------------------------------- // This file is part of eCos, the Embedded Configurable Operating System. // Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. // // eCos is free software; you can redistribute it and/or modify it under // the terms of the GNU General Public License as published by the Free // Software Foundation; either version 2 or (at your option) any later // version. // // eCos is distributed in the hope that it will be useful, but WITHOUT // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. // // You should have received a copy of the GNU General Public License // along with eCos; if not, write to the Free Software Foundation, Inc., // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // // As a special exception, if other files instantiate templates or use // macros or inline functions from this file, or you compile this file // and link it with other works to produce a work based on this file, // this file does not by itself cause the resulting work to be covered by // the GNU General Public License. However the source code for this file // must still be made available in accordance with section (3) of the GNU // General Public License v2. // // This exception does not invalidate any other reasons why a work based // on this file might be covered by the GNU General Public License. // ------------------------------------------- // ####ECOSGPLCOPYRIGHTEND#### //========================================================================== //#####DESCRIPTIONBEGIN#### // // Author(s): Patrick Doyle <*****@*****.**> // Contributors: Patrick Doyle <*****@*****.**> // Date: 2002-11-27 // Purpose: // Description: // // This code is part of RedBoot (tm). It was modified from "redboot_cmds" // for the iPaq by wpd in order to add some platform specific commands to // the OMAP1510DC EVM platform. // //####DESCRIPTIONEND#### // //========================================================================== #include <redboot.h> #include <cyg/hal/hal_intr.h> #include <cyg/hal/hal_cache.h> #include <cyg/hal/hal_io.h> #include <cyg/hal/hal_diag.h> #include <cyg/hal/innovator.h> static void do_mem(int argc, char *argv[]); static void do_try_reset(int argc, char *argv[]); static void do_testsdram(int argc, char *argv[]); static void do_delay(int argc, char *argv[]); RedBoot_cmd("mem", "Set a memory location", "[-h|-b] [-n] [-a <address>] <data>", do_mem ); RedBoot_cmd("try_reset", "try to reset the platform", "[-1|-2|-3|-4]", do_try_reset ); RedBoot_cmd("testsdram", "test SDRAM (very simply)", "[-l length]", do_testsdram ); RedBoot_cmd("delay", "delay specified number of usecs", "[-c count] amount", do_delay ); static void do_mem(int argc, char *argv[]) { struct option_info opts[4]; bool mem_half_word, mem_byte; bool no_verify = false; static int address = 0x00000000; int value; init_opts(&opts[0], 'b', false, OPTION_ARG_TYPE_FLG, (void**)&mem_byte, 0, "write a byte"); init_opts(&opts[1], 'h', false, OPTION_ARG_TYPE_FLG, (void**)&mem_half_word, 0, "write a half-word"); init_opts(&opts[2], 'a', true, OPTION_ARG_TYPE_NUM, (void**)&address, NULL, "address to write at"); init_opts(&opts[3], 'n', false, OPTION_ARG_TYPE_FLG, (void**)&no_verify, 0, "noverify"); if (!scan_opts(argc, argv, 1, opts, sizeof(opts) / sizeof(opts[0]), (void*)&value, OPTION_ARG_TYPE_NUM, "address to set")) { return; } if ( mem_byte && mem_half_word ) { diag_printf("*ERR: Should not specify both byte and half-word access\n"); } else if ( mem_byte ) { *(cyg_uint8*)address = (cyg_uint8)(value & 255); if (no_verify) { diag_printf(" Set 0x%08X to 0x%02X\n", address, value & 255); } else { diag_printf(" Set 0x%08X to 0x%02X (result 0x%02X)\n", address, value & 255, (int)*(cyg_uint8*)address ); } } else if ( mem_half_word ) { if ( address & 1 ) { diag_printf( "*ERR: Badly aligned address 0x%08X for half-word store\n", address ); } else { *(cyg_uint16*)address = (cyg_uint16)(value & 0xffff); if (no_verify) { diag_printf(" Set 0x%08X to 0x%04X\n", address, value & 0xffff); } else { diag_printf(" Set 0x%08X to 0x%04X (result 0x%04X)\n", address, value & 0xffff, (int)*(cyg_uint16*)address ); } } } else { if ( address & 3 ) { diag_printf( "*ERR: Badly aligned address 0x%08X for word store\n", address ); } else { *(cyg_uint32*)address = (cyg_uint32)value; if (no_verify) { diag_printf(" Set 0x%08X to 0x%08X\n", address, value); } else { diag_printf(" Set 0x%08X to 0x%08X (result 0x%08X)\n", address, value, (int)*(cyg_uint32*)address ); } } } } static void do_try_reset(int argc, char *argv[]) { struct option_info opts[4]; bool flag_1 = false; bool flag_2 = false; bool flag_3 = false; bool flag_4 = false; cyg_uint16 tmp = 0; init_opts(&opts[0], '1', false, OPTION_ARG_TYPE_FLG, (void**)&flag_1, 0, "only try phase 1"); init_opts(&opts[1], '2', false, OPTION_ARG_TYPE_FLG, (void**)&flag_2, 0, "try phase 1 & phase 2"); init_opts(&opts[2], '3', false, OPTION_ARG_TYPE_FLG, (void**)&flag_3, 0, "try phase 1 through phase 3"); init_opts(&opts[3], '4', false, OPTION_ARG_TYPE_FLG, (void**)&flag_4, 0, "try phase 1 through phase 4"); if (!scan_opts(argc, argv, 1, opts, sizeof(opts) / sizeof(opts[0]), 0, 0, 0)) { return; } diag_printf("flag_4 = %d, flag_3 = %d, flag_2 = %d, flag_1 = %d\n", flag_4, flag_3, flag_2, flag_1); if (flag_4) { flag_3 = flag_2 = flag_1 = true; } else if (flag_3) { flag_2 = flag_1 = true; } else if (flag_2) { flag_1 = true; } diag_printf("flag_4 = %d, flag_3 = %d, flag_2 = %d, flag_1 = %d\n", flag_4, flag_3, flag_2, flag_1); if (flag_1) { HAL_READ_UINT16(CLKM_ARM_IDLECT2, tmp); diag_printf("tmp = %04X\n", tmp); } if (flag_2) { tmp |= 1; diag_printf("Writing %04X to %08X\n", tmp, CLKM_ARM_IDLECT2); HAL_WRITE_UINT16(CLKM_ARM_IDLECT2, tmp | 1); } if (flag_3) { diag_printf("Writing %04X to %08X\n", 0x80F5, WATCHDOG_TIMER_MODE); HAL_WRITE_UINT16(WATCHDOG_TIMER_MODE, 0x80F5); \ } if (flag_4) { diag_printf("Writing %04X to %08X\n", 0x80F5, WATCHDOG_TIMER_MODE); HAL_WRITE_UINT16(WATCHDOG_TIMER_MODE, 0x80F5); \ } diag_printf("try_reset: done\n"); } #define SDRAM_BASE 0x10000000 #define SDRAM_LEN (32*1024*1024) /* 32 Mbytes */ static void do_testsdram(int argc, char *argv[]) { cyg_uint32 *mem_addr = (cyg_uint32 *)SDRAM_BASE; unsigned len; bool len_set; register int i; struct option_info opts[1]; init_opts(&opts[0], 'l', true, OPTION_ARG_TYPE_NUM, (void**)&len, &len_set, "length"); if (!scan_opts(argc, argv, 1, opts, 1, 0, 0, 0)) { return; } if (!len_set) { len = SDRAM_LEN / 4; } diag_printf("Length = 0x%08X\n", len); diag_printf("Writing data-equals-address pattern to SDRAM\n"); for (i = 0; i < len; i++) { mem_addr[i] = ~(cyg_uint32)(mem_addr + i); } diag_printf("Reading back pattern\n"); for (i = 0; i < len; i++) { if (mem_addr[i] != ~(cyg_uint32)(mem_addr + i)) { diag_printf("Error: mismatch at address %p, read back 0x%08x\n", mem_addr + i, mem_addr[i]); break; } } diag_printf("Done\n"); }
static void do_swab(int argc, char *argv[]) { // Fill a region of memory with a pattern struct option_info opts[4]; unsigned long base; long len; bool base_set, len_set; bool set_32bit, set_16bit; init_opts(&opts[0], 'b', true, OPTION_ARG_TYPE_NUM, (void *)&base, (bool *)&base_set, "base address"); init_opts(&opts[1], 'l', true, OPTION_ARG_TYPE_NUM, (void *)&len, (bool *)&len_set, "length"); init_opts(&opts[2], '4', false, OPTION_ARG_TYPE_FLG, (void *)&set_32bit, (bool *)0, "fill 32 bit units"); init_opts(&opts[3], '2', false, OPTION_ARG_TYPE_FLG, (void *)&set_16bit, (bool *)0, "fill 16 bit units"); if (!scan_opts(argc, argv, 1, opts, 4, 0, 0, "")) { return; } if (!base_set || !len_set) { diag_printf("usage: swab -b <addr> -l <length> [-2|-4]\n"); return; } if (set_16bit) { // 16 bits at a time while ((len -= sizeof(cyg_uint16)) >= 0) { *(cyg_uint16 *)base = CYG_SWAP16(*(cyg_uint16 *)base); base += sizeof(cyg_uint16); } } else { // Default - 32 bits while ((len -= sizeof(cyg_uint32)) >= 0) { *(cyg_uint32 *)base = CYG_SWAP32(*(cyg_uint32 *)base); base += sizeof(cyg_uint32); } } }
static void do_cd(int argc, char * argv[]) { char *dir_str; int err; if( mount_count == 0 ) { err_printf("fs: No filesystems mounted\n"); return; } if (!scan_opts(argc, argv, 1, NULL, 0, &dir_str, OPTION_ARG_TYPE_STR, "directory")) return; if( dir_str == NULL ) dir_str = "/"; err = chdir( dir_str ); if( err != 0 ) err_printf("fs cd: failed to change directory %s\n",dir_str); }
static void do_del(int argc, char * argv[]) { char *name_str = NULL; int err; if( mount_count == 0 ) { err_printf("fs: No filesystems mounted\n"); return; } if (!scan_opts(argc, argv, 1, NULL, 0, &name_str, OPTION_ARG_TYPE_STR, "file") || name_str == NULL) { fs_usage("invalid arguments"); return; } err = unlink( name_str ); if( err != 0 ) err_printf("fs del: failed to delete file %s\n",name_str); }
static void do_deldir(int argc, char * argv[]) { char *dir_str; int err; if( mount_count == 0 ) { err_printf("fs: No filesystems mounted\n"); return; } if (!scan_opts(argc, argv, 1, NULL, 0, &dir_str, OPTION_ARG_TYPE_STR, "directory") || dir_str == NULL) { fs_usage("invalid arguments"); return; } err = rmdir( dir_str ); if( err != 0 ) err_printf("fs deldir: failed to remove directory %s\n",dir_str); }
static void do_ping(int argc, char *argv[]) { struct option_info opts[7]; long count, timeout, length, rate, start_time, end_time, timer, received, tries; char *local_ip_addr, *host_ip_addr; bool local_ip_addr_set, host_ip_addr_set, count_set, timeout_set, length_set, rate_set, verbose; struct sockaddr_in local_addr, host_addr; ip_addr_t hold_addr; icmp_header_t *icmp; pktbuf_t *pkt; ip_header_t *ip; unsigned short cksum; ip_route_t dest_ip; init_opts(&opts[0], 'n', true, OPTION_ARG_TYPE_NUM, (void *)&count, (bool *) & count_set, "<count> - number of packets to test"); init_opts(&opts[1], 't', true, OPTION_ARG_TYPE_NUM, (void *)&timeout, (bool *) & timeout_set, "<timeout> - max #ms per packet [rount trip]"); init_opts(&opts[2], 'i', true, OPTION_ARG_TYPE_STR, (void *)&local_ip_addr, (bool *) & local_ip_addr_set, "local IP address"); init_opts(&opts[3], 'h', true, OPTION_ARG_TYPE_STR, (void *)&host_ip_addr, (bool *) & host_ip_addr_set, "host name or IP address"); init_opts(&opts[4], 'l', true, OPTION_ARG_TYPE_NUM, (void *)&length, (bool *) & length_set, "<length> - size of payload"); init_opts(&opts[5], 'v', false, OPTION_ARG_TYPE_FLG, (void *)&verbose, (bool *) 0, "verbose operation"); init_opts(&opts[6], 'r', true, OPTION_ARG_TYPE_NUM, (void *)&rate, (bool *) & rate_set, "<rate> - time between packets"); if (!scan_opts(argc, argv, 1, opts, 7, (void **)0, 0, "")) { diag_printf("PING - Invalid option specified\n"); return; } // Set defaults; this has to be done _after_ the scan, since it will // have destroyed all values not explicitly set. if (local_ip_addr_set) { if (!_gethostbyname(local_ip_addr, (in_addr_t *) & local_addr)) { diag_printf("PING - Invalid local name: %s\n", local_ip_addr); return; } } else { memcpy((in_addr_t *) & local_addr, __local_ip_addr, sizeof(__local_ip_addr)); } if (host_ip_addr_set) { if (!_gethostbyname(host_ip_addr, (in_addr_t *) & host_addr)) { diag_printf("PING - Invalid host name: %s\n", host_ip_addr); return; } if (__arp_lookup((ip_addr_t *) & host_addr.sin_addr, &dest_ip) < 0) { diag_printf("PING: Cannot reach server '%s' (%s)\n", host_ip_addr, inet_ntoa((in_addr_t *) & host_addr)); return; } } else { diag_printf("PING - host name or IP address required\n"); return; } #define DEFAULT_LENGTH 64 #define DEFAULT_COUNT 10 #define DEFAULT_TIMEOUT 1000 #define DEFAULT_RATE 1000 if (!rate_set) { rate = DEFAULT_RATE; } if (!length_set) { length = DEFAULT_LENGTH; } if ((length < 64) || (length > 1400)) { diag_printf("Invalid length specified: %ld\n", length); return; } if (!count_set) { count = DEFAULT_COUNT; } if (!timeout_set) { timeout = DEFAULT_TIMEOUT; } // Note: two prints here because 'inet_ntoa' returns a static pointer diag_printf("Network PING - from %s", inet_ntoa((in_addr_t *) & local_addr)); diag_printf(" to %s\n", inet_ntoa((in_addr_t *) & host_addr)); received = 0; __icmp_install_listener(handle_icmp); // Save default "local" address memcpy(hold_addr, __local_ip_addr, sizeof(hold_addr)); for (tries = 0; tries < count; tries++) { // The network stack uses the global variable '__local_ip_addr' memcpy(__local_ip_addr, &local_addr, sizeof(__local_ip_addr)); // Build 'ping' request if ((pkt = __pktbuf_alloc(ETH_MAX_PKTLEN)) == NULL) { // Give up if no packets - something is wrong break; } icmp = pkt->icmp_hdr; ip = pkt->ip_hdr; pkt->pkt_bytes = length + sizeof(icmp_header_t); icmp->type = ICMP_TYPE_ECHOREQUEST; icmp->code = 0; icmp->checksum = 0; icmp->seqnum = htons(tries + 1); cksum = __sum((word *) icmp, pkt->pkt_bytes, 0); icmp->checksum = htons(cksum); memcpy(ip->source, (in_addr_t *) & local_addr, sizeof(ip_addr_t)); memcpy(ip->destination, (in_addr_t *) & host_addr, sizeof(ip_addr_t)); ip->protocol = IP_PROTO_ICMP; ip->length = htons(pkt->pkt_bytes); __ip_send(pkt, IP_PROTO_ICMP, &dest_ip); __pktbuf_free(pkt); start_time = MS_TICKS(); timer = start_time + timeout; icmp_received = false; while (!icmp_received && (MS_TICKS_DELAY() < timer)) { if (_rb_break(1)) { goto abort; } MS_TICKS_DELAY(); __enet_poll(); } end_time = MS_TICKS(); timer = MS_TICKS() + rate; while (MS_TICKS_DELAY() < timer) { if (_rb_break(1)) { goto abort; } MS_TICKS_DELAY(); __enet_poll(); } if (icmp_received) { received++; if (verbose) { diag_printf(" seq: %ld, time: %ld (ticks)\n", ntohs(hold_hdr.seqnum), end_time - start_time); } } } abort: __icmp_remove_listener(); // Clean up memcpy(__local_ip_addr, &hold_addr, sizeof(__local_ip_addr)); // Report diag_printf("PING - received %ld of %ld expected\n", received, count); }
static void do_flash_config(int argc, char *argv[]) { bool need_update = false; struct config_option *optend = __CONFIG_options_TAB_END__; struct config_option *opt = __CONFIG_options_TAB__; struct option_info opts[5]; bool list_only; bool nicknames; bool fullnames; bool dumbterminal; int list_opt = 0; unsigned char *dp; int len, ret; char *title; char *onlyone = NULL; char *onevalue = NULL; bool doneone = false; bool init = false; #ifdef CYGHWR_REDBOOT_FLASH_CONFIG_MEDIA_FLASH if (!__flash_init) { diag_printf("Sorry, no FLASH memory is available\n"); return; } #endif memcpy(backup_config, config, sizeof(struct _config)); script = (unsigned char *)0; init_opts(&opts[0], 'l', false, OPTION_ARG_TYPE_FLG, (void *)&list_only, (bool *)0, "list configuration only"); init_opts(&opts[1], 'n', false, OPTION_ARG_TYPE_FLG, (void *)&nicknames, (bool *)0, "show nicknames"); init_opts(&opts[2], 'f', false, OPTION_ARG_TYPE_FLG, (void *)&fullnames, (bool *)0, "show full names"); init_opts(&opts[3], 'i', false, OPTION_ARG_TYPE_FLG, (void *)&init, (bool *)0, "initialize configuration database"); init_opts(&opts[4], 'd', false, OPTION_ARG_TYPE_FLG, (void *)&dumbterminal, (bool *)0, "dumb terminal: no clever edits"); // First look to see if we are setting or getting a single option // by just quoting its nickname if ( (2 == argc && '-' != argv[1][0]) || (3 == argc && '-' != argv[1][0] && '-' != argv[2][0])) { // then the command was "fconfig foo [value]" onlyone = argv[1]; onevalue = (3 == argc) ? argv[2] : NULL; list_opt = LIST_OPT_NICKNAMES; } // Next see if we are setting or getting a single option with a dumb // terminal invoked, ie. no line editing. else if (3 == argc && '-' == argv[1][0] && 'd' == argv[1][1] && 0 == argv[1][2] && '-' != argv[2][0]) { // then the command was "fconfig -d foo" onlyone = argv[2]; onevalue = NULL; list_opt = LIST_OPT_NICKNAMES | LIST_OPT_DUMBTERM; } else { if (!scan_opts(argc, argv, 1, opts, 5, 0, 0, "")) return; list_opt |= list_only ? LIST_OPT_LIST_ONLY : 0; list_opt |= nicknames ? LIST_OPT_NICKNAMES : LIST_OPT_FULLNAMES; list_opt |= fullnames ? LIST_OPT_FULLNAMES : 0; list_opt |= dumbterminal ? LIST_OPT_DUMBTERM : 0; } if (init && verify_action("Initialize non-volatile configuration")) { config_init(); need_update = true; } dp = &config->config_data[0]; while (dp < &config->config_data[sizeof(config->config_data)]) { if (CONFIG_OBJECT_TYPE(dp) == CONFIG_EMPTY) { break; } len = 4 + CONFIG_OBJECT_KEYLEN(dp) + CONFIG_OBJECT_ENABLE_KEYLEN(dp) + config_length(CONFIG_OBJECT_TYPE(dp)); // Provide a title for well known [i.e. builtin] objects title = (char *)NULL; opt = __CONFIG_options_TAB__; while (opt != optend) { if (strcmp(opt->key, CONFIG_OBJECT_KEY(dp)) == 0) { title = opt->title; break; } opt++; } if ( onlyone && 0 != strcmp(CONFIG_OBJECT_KEY(dp), onlyone) ) ret = CONFIG_OK; // skip this entry else { doneone = true; ret = get_config(dp, title, list_opt, onevalue); // do this opt } switch (ret) { case CONFIG_DONE: goto done; case CONFIG_ABORT: memcpy(config, backup_config, sizeof(struct _config)); return; case CONFIG_CHANGED: need_update = true; case CONFIG_OK: dp += len; break; case CONFIG_BACK: dp = &config->config_data[0]; continue; case CONFIG_BAD: // Nothing - make him do it again diag_printf ("** invalid entry\n"); onevalue = NULL; // request a good value be typed in - or abort/whatever } } done: if (NULL != onlyone && !doneone) { #ifdef CYGSEM_REDBOOT_ALLOW_DYNAMIC_FLASH_CONFIG_DATA if (verify_action("** entry '%s' not found - add", onlyone)) { struct config_option opt; diag_printf("Trying to add value\n"); } #else diag_printf("** entry '%s' not found\n", onlyone); #endif } if (!need_update) return; flash_write_config(true); }
static void do_try_reset(int argc, char *argv[]) { struct option_info opts[4]; bool flag_1 = false; bool flag_2 = false; bool flag_3 = false; bool flag_4 = false; cyg_uint16 tmp = 0; init_opts(&opts[0], '1', false, OPTION_ARG_TYPE_FLG, (void**)&flag_1, 0, "only try phase 1"); init_opts(&opts[1], '2', false, OPTION_ARG_TYPE_FLG, (void**)&flag_2, 0, "try phase 1 & phase 2"); init_opts(&opts[2], '3', false, OPTION_ARG_TYPE_FLG, (void**)&flag_3, 0, "try phase 1 through phase 3"); init_opts(&opts[3], '4', false, OPTION_ARG_TYPE_FLG, (void**)&flag_4, 0, "try phase 1 through phase 4"); if (!scan_opts(argc, argv, 1, opts, sizeof(opts) / sizeof(opts[0]), 0, 0, 0)) { return; } diag_printf("flag_4 = %d, flag_3 = %d, flag_2 = %d, flag_1 = %d\n", flag_4, flag_3, flag_2, flag_1); if (flag_4) { flag_3 = flag_2 = flag_1 = true; } else if (flag_3) { flag_2 = flag_1 = true; } else if (flag_2) { flag_1 = true; } diag_printf("flag_4 = %d, flag_3 = %d, flag_2 = %d, flag_1 = %d\n", flag_4, flag_3, flag_2, flag_1); if (flag_1) { HAL_READ_UINT16(CLKM_ARM_IDLECT2, tmp); diag_printf("tmp = %04X\n", tmp); } if (flag_2) { tmp |= 1; diag_printf("Writing %04X to %08X\n", tmp, CLKM_ARM_IDLECT2); HAL_WRITE_UINT16(CLKM_ARM_IDLECT2, tmp | 1); } if (flag_3) { diag_printf("Writing %04X to %08X\n", 0x80F5, WATCHDOG_TIMER_MODE); HAL_WRITE_UINT16(WATCHDOG_TIMER_MODE, 0x80F5); \ } if (flag_4) { diag_printf("Writing %04X to %08X\n", 0x80F5, WATCHDOG_TIMER_MODE); HAL_WRITE_UINT16(WATCHDOG_TIMER_MODE, 0x80F5); \ } diag_printf("try_reset: done\n"); }
void do_load(int argc, char *argv[]) { int res, num_options; int i, err; bool verbose, raw; bool base_addr_set, mode_str_set; char *mode_str; #ifdef CYGPKG_REDBOOT_NETWORKING struct sockaddr_in host; bool hostname_set, port_set; unsigned int port; // int because it's an OPTION_ARG_TYPE_NUM, // but will be cast to short char *hostname; #endif #ifdef CYGBLD_REDBOOT_LOAD_INTO_FLASH bool flash_addr_set = false; #endif bool decompress = false; int chan = -1; #if CYGNUM_HAL_VIRTUAL_VECTOR_NUM_CHANNELS > 1 bool chan_set; #endif unsigned long base = 0; unsigned long end = 0; char type[4]; char *filename = 0; struct option_info opts[9]; connection_info_t info; getc_io_funcs_t *io = NULL; struct load_io_entry *io_tab; #ifdef CYGSEM_REDBOOT_VALIDATE_USER_RAM_LOADS bool spillover_ok = false; #endif #ifdef CYGPKG_REDBOOT_NETWORKING memset((char *)&host, 0, sizeof(host)); host.sin_len = sizeof(host); host.sin_family = AF_INET; host.sin_addr = my_bootp_info.bp_siaddr; host.sin_port = 0; #endif init_opts(&opts[0], 'v', false, OPTION_ARG_TYPE_FLG, (void *)&verbose, 0, "verbose"); init_opts(&opts[1], 'r', false, OPTION_ARG_TYPE_FLG, (void *)&raw, 0, "load raw data"); init_opts(&opts[2], 'b', true, OPTION_ARG_TYPE_NUM, (void *)&base, (bool *)&base_addr_set, "load address"); init_opts(&opts[3], 'm', true, OPTION_ARG_TYPE_STR, (void *)&mode_str, (bool *)&mode_str_set, "download mode (TFTP, xyzMODEM, or disk)"); num_options = 4; #if CYGNUM_HAL_VIRTUAL_VECTOR_NUM_CHANNELS > 1 init_opts(&opts[num_options], 'c', true, OPTION_ARG_TYPE_NUM, (void *)&chan, (bool *)&chan_set, "I/O channel"); num_options++; #endif #ifdef CYGPKG_REDBOOT_NETWORKING init_opts(&opts[num_options], 'h', true, OPTION_ARG_TYPE_STR, (void *)&hostname, (bool *)&hostname_set, "host name or IP address"); num_options++; init_opts(&opts[num_options], 'p', true, OPTION_ARG_TYPE_NUM, (void *)&port, (bool *)&port_set, "TCP port"); num_options++; #endif #ifdef CYGBLD_BUILD_REDBOOT_WITH_ZLIB init_opts(&opts[num_options], 'd', false, OPTION_ARG_TYPE_FLG, (void *)&decompress, 0, "decompress"); num_options++; #endif #ifdef CYGBLD_REDBOOT_LOAD_INTO_FLASH init_opts(&opts[num_options], 'f', true, OPTION_ARG_TYPE_NUM, (void *)&base, (bool *)&flash_addr_set, "flash address"); num_options++; #endif CYG_ASSERT(num_options <= NUM_ELEMS(opts), "Too many options"); if (!scan_opts(argc, argv, 1, opts, num_options, (void *)&filename, OPTION_ARG_TYPE_STR, "file name")) { return; } #ifdef CYGPKG_REDBOOT_NETWORKING if (hostname_set) { ip_route_t rt; if (!_gethostbyname(hostname, (in_addr_t *)&host)) { err_printf("Invalid host: %s\n", hostname); return; } /* check that the host can be accessed */ if (__arp_lookup((ip_addr_t *)&host.sin_addr, &rt) < 0) { err_printf("Unable to reach host %s (%s)\n", hostname, inet_ntoa((in_addr_t *)&host)); return; } } if (port_set) host.sin_port = port; #endif if (chan >= CYGNUM_HAL_VIRTUAL_VECTOR_NUM_CHANNELS) { err_printf("Invalid I/O channel: %d\n", chan); return; } if (mode_str_set) { for (io_tab = __RedBoot_LOAD_TAB__; io_tab != &__RedBoot_LOAD_TAB_END__; io_tab++) { if (strncasecmp(&mode_str[0], io_tab->name, strlen(&mode_str[0])) == 0) { io = io_tab->funcs; break; } } if (!io) { diag_printf("Invalid 'mode': %s. Valid modes are:", mode_str); for (io_tab = __RedBoot_LOAD_TAB__; io_tab != &__RedBoot_LOAD_TAB_END__; io_tab++) { diag_printf(" %s", io_tab->name); } err_printf("\n"); } if (!io) { return; } verbose &= io_tab->can_verbose; if (io_tab->need_filename && !filename) { diag_printf("File name required\n"); err_printf("usage: load %s\n", usage); return; } } else { char *which = ""; io_tab = (struct load_io_entry *)NULL; // Default #ifdef CYGPKG_REDBOOT_NETWORKING #ifdef CYGSEM_REDBOOT_NET_TFTP_DOWNLOAD which = "TFTP"; io = &tftp_io; #elif defined(CYGSEM_REDBOOT_NET_HTTP_DOWNLOAD) which = "HTTP"; io = &http_io; #endif #endif #if 0 //def CYGPKG_REDBOOT_FILEIO // Make file I/O default if mounted if (fileio_mounted) { which = "file"; io = &fileio_io; } #endif if (!io) { #ifdef CYGBLD_BUILD_REDBOOT_WITH_XYZMODEM which = "Xmodem"; io = &xyzModem_io; verbose = false; #else err_printf("No default protocol!\n"); return; #endif } diag_printf("Using default protocol (%s)\n", which); } #ifdef CYGSEM_REDBOOT_VALIDATE_USER_RAM_LOADS #ifdef CYGBLD_REDBOOT_LOAD_INTO_FLASH if (flash_addr_set && flash_verify_addr((unsigned char *)base)) { if (!verify_action("Specified address (%p) is not believed to be in FLASH", (void*)base)) return; spillover_ok = true; } #endif if (base_addr_set && !valid_address((unsigned char *)base)) { if (!verify_action("Specified address (%p) is not believed to be in RAM", (void*)base)) return; spillover_ok = true; } #endif if (raw && !(base_addr_set #ifdef CYGBLD_REDBOOT_LOAD_INTO_FLASH || flash_addr_set #endif )) { err_printf("Raw load requires a memory address\n"); return; } info.filename = filename; info.chan = chan; info.mode = io_tab ? io_tab->mode : 0; #ifdef CYGPKG_REDBOOT_NETWORKING info.server = &host; #endif res = redboot_getc_init(&info, io, verbose, decompress); if (res < 0) { return; } #ifdef CYGBLD_REDBOOT_LOAD_INTO_FLASH flash_load_start(); #endif // Stream open, process the data if (raw) { unsigned char *mp = (unsigned char *)base; err = 0; while ((res = redboot_getc()) >= 0) { #ifdef CYGSEM_REDBOOT_VALIDATE_USER_RAM_LOADS #ifdef CYGBLD_REDBOOT_LOAD_INTO_FLASH if (flash_addr_set && flash_verify_addr(mp) && !spillover_ok) { // Only if there is no need to stop the download // before printing output can we ask confirmation // questions. redboot_getc_terminate(true); err_printf("*** Abort! RAW data spills over limit of FLASH at %p\n",(void*)mp); err = -1; break; } #endif if (base_addr_set && !valid_address(mp) && !spillover_ok) { // Only if there is no need to stop the download // before printing output can we ask confirmation // questions. redboot_getc_terminate(true); err_printf("*** Abort! RAW data spills over limit of user RAM at %p\n",(void*)mp); err = -1; break; } #endif #ifdef CYGBLD_REDBOOT_LOAD_INTO_FLASH if (flash_addr_set) { flash_load_write(mp, res); mp++; res++; } else #endif *mp++ = res; } end = (unsigned long) mp; // Save load base/top load_address = base; load_address_end = end; entry_address = base; // best guess redboot_getc_terminate(false); if (0 == err) diag_printf("Raw file loaded %p-%p, assumed entry at %p\n", (void *)base, (void *)(end - 1), (void*)base); } else { // Read initial header - to determine file [image] type for (i = 0; i < sizeof(type); i++) { if ((res = redboot_getc()) < 0) { err = getc_info.err; break; } type[i] = res; } if (res >= 0) { redboot_getc_rewind(); // Restore header to stream // Treat data as some sort of executable image if (strncmp(&type[1], "ELF", 3) == 0) { end = load_elf_image(redboot_getc, base); } else if ((type[0] == 'S') && ((type[1] >= '0') && (type[1] <= '9'))) { end = load_srec_image(redboot_getc, base); } else { redboot_getc_terminate(true); err_printf("Unrecognized image type: 0x%lx\n", *(unsigned long *)type); } } } #ifdef CYGBLD_REDBOOT_LOAD_INTO_FLASH flash_load_finish(); #endif redboot_getc_close(); // Clean up return; }