/* ************************************************************************ * * This is the next part if the initialization sequence: we are now * running from RAM and have a "normal" C environment, i. e. global * data can be written, BSS has been cleared, the stack size in not * that critical any more, etc. * ************************************************************************ */ void board_init_r(gd_t *id, ulong dest_addr) { char *s; //bd_t *bd; ulong malloc_start; #ifdef CONFIG_NONCACHE_MEMORY uint malloc_noncache_start; #endif #if !defined(CONFIG_SYS_NO_FLASH) ulong flash_size; #endif int workmode; int ret; #ifdef CONFIG_SUNXI_HDCP_IN_SECURESTORAGE int hdcpkey_enable=0; #endif char storage_type_buf[24] = {0}; char boot_mmc_buf[24] = {0}; gd = id; //bd = gd->bd; gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */ monitor_flash_len = _end_ofs; malloc_start = dest_addr - TOTAL_MALLOC_LEN - sizeof(struct spare_boot_head_t); #ifdef CONFIG_NONCACHE_MEMORY_SIZE malloc_start &= (~(0x00100000 -1)); malloc_noncache_start = malloc_start - CONFIG_NONCACHE_MEMORY_SIZE; gd->malloc_noncache_start = malloc_noncache_start; #endif /* Enable caches */ enable_caches(); debug("monitor flash len: %08lX\n", monitor_flash_len); board_init(); /* Setup chipselects */ #ifdef CONFIG_SERIAL_MULTI serial_initialize(); #endif debug("Now running in RAM - U-Boot at: %08lx\n", dest_addr); #ifdef CONFIG_LOGBUFFER logbuff_init_ptrs(); #endif #ifdef CONFIG_POST post_output_backlog(); #endif /* The Malloc area is immediately below the monitor copy in DRAM */ mem_malloc_init (malloc_start, TOTAL_MALLOC_LEN); #ifdef CONFIG_SMALL_MEMSIZE save_config(); #endif #ifdef CONFIG_NONCACHE_MEMORY mem_noncache_malloc_init(malloc_noncache_start, CONFIG_NONCACHE_MEMORY_SIZE); #endif #if defined(CONFIG_ARCH_HOMELET) check_physical_key_early(); #endif workmode = uboot_spare_head.boot_data.work_mode; debug("work mode %d\n", workmode); axp_reinit(); //uboot_spare_head.boot_data.work_mode = WORK_MODE_CARD_PRODUCT; #if defined(CONFIG_CPUS_STANDBY) //Ŀǰֻ��homelet��ʹ�� do_box_standby(); #endif #ifdef CONFIG_ARCH_HOMELET gpio_control(); #endif #if 0 #if !defined(CONFIG_SYS_NO_FLASH) puts("Flash: "); flash_size = flash_init(); if (flash_size > 0) { # ifdef CONFIG_SYS_FLASH_CHECKSUM print_size(flash_size, ""); /* * Compute and print flash CRC if flashchecksum is set to 'y' * * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX */ s = getenv("flashchecksum"); if (s && (*s == 'y')) { printf(" CRC: %08X", crc32(0, (const unsigned char *) CONFIG_SYS_FLASH_BASE, flash_size)); } putc('\n'); # else /* !CONFIG_SYS_FLASH_CHECKSUM */ print_size(flash_size, "\n"); # endif /* CONFIG_SYS_FLASH_CHECKSUM */ } else { puts(failed); hang(); } #endif #endif /* set up exceptions */ interrupt_init(); /* enable exceptions */ enable_interrupts(); sunxi_dma_init(); #ifdef CONFIG_USE_CIR //����ӿڣ�Ŀǰֻ���ں��� A20 if (uboot_spare_head.boot_data.work_mode == WORK_MODE_BOOT) { ir_setup(); } #endif #ifdef DEBUG puts("ready to config storage\n"); #endif #ifdef CONFIG_ARCH_HOMELET //for homlet to use one-key-recovery ret = sunxi_flash_handle_init(); if(!ret) { sunxi_partition_init(); } #endif #ifndef CONFIG_ARCH_SUN8IW8P1 if((workmode == WORK_MODE_BOOT) || (workmode == WORK_MODE_CARD_PRODUCT) || (workmode == WORK_MODE_SPRITE_RECOVERY)) { #else if((workmode == WORK_MODE_CARD_PRODUCT) || (workmode == WORK_MODE_SPRITE_RECOVERY)) { #endif #if (defined(CONFIG_SUNXI_DISPLAY) || defined(CONFIG_SUN7I_DISPLAY)) drv_disp_init(); #endif #ifdef CONFIG_SUNXI_HDCP_IN_SECURESTORAGE int tmp = 0; tmp = script_parser_fetch("hdmi_para", "hdmi_hdcp_enable", &hdcpkey_enable, 1); if((tmp) || (hdcpkey_enable != 1)) { board_display_device_open(); board_display_layer_request(); } #else board_display_device_open(); board_display_layer_request(); #endif } #ifndef CONFIG_ARCH_HOMELET //for pad used ret = sunxi_flash_handle_init(); if(!ret) { sunxi_partition_init(); } #endif #ifdef CONFIG_SUNXI_HDCP_IN_SECURESTORAGE //here: write key to hardware if(hdcpkey_enable==1) { char buffer[4096]; int data_len; int ret0; memset(buffer, 0, 4096); ret0 = sunxi_secure_storage_init(); if(ret0) { printf("sunxi init secure storage failed\n"); } else { ret0 = sunxi_secure_object_read("hdcpkey", buffer, 4096, &data_len); if(ret0) { printf("probe hdcp key failed\n"); } else { ret0 = smc_aes_bssk_decrypt_to_keysram(buffer, data_len); if(ret0) { printf("push hdcp key failed\n"); } else { board_display_device_open(); board_display_layer_request(); } } } } #endif #ifdef CONFIG_BOOT_A15 if(sunxi_sprite_download_boot0_simple()) { printf("rewrite boot0 to save boot cpu failed\n"); } #endif #ifndef CONFIG_SUNXI_SPINOR_PLATFORM sunxi_keydata_burn_by_usb(); #endif //#else //#if defined(CONFIG_CMD_NAND) // if(!storage_type){ // puts("NAND: "); // nand_init(); /* go init the NAND */ // } //#endif/*CONFIG_CMD_NAND*/ // //#if defined(CONFIG_GENERIC_MMC) // if(storage_type){ // puts("MMC: "); // mmc_initialize(bd); // } //#endif/*CONFIG_GENERIC_MMC*/ #ifdef CONFIG_HAS_DATAFLASH AT91F_DataflashInit(); dataflash_print_info(); #endif /* initialize environment */ env_relocate(); /* setenv storage_type */ sprintf(storage_type_buf, "%d", uboot_spare_head.boot_data.storage_type); if (setenv("storage_type", storage_type_buf)) printf("set storage_type=%s fail\n", storage_type_buf); if (uboot_spare_head.boot_data.storage_type == 1) sprintf(boot_mmc_buf, "%s", "0"); else sprintf(boot_mmc_buf, "%s", "2"); setenv("boot_mmc", boot_mmc_buf); #if defined(CONFIG_CMD_PCI) || defined(CONFIG_PCI) arm_pci_init(); #endif /* IP Address */ gd->bd->bi_ip_addr = getenv_IPaddr("ipaddr"); stdio_init(); /* get the devices list going. */ jumptable_init(); #if defined(CONFIG_API) /* Initialize API */ api_init(); #endif console_init_r(); /* fully init console as a device */ #if defined(CONFIG_ARCH_MISC_INIT) /* miscellaneous arch dependent initialisations */ arch_misc_init(); #endif #if defined(CONFIG_MISC_INIT_R) /* miscellaneous platform dependent initialisations */ misc_init_r(); #endif /* Perform network card initialisation if necessary */ #if defined(CONFIG_DRIVER_SMC91111) || defined (CONFIG_DRIVER_LAN91C96) /* XXX: this needs to be moved to board init */ if (getenv("ethaddr")) { uchar enetaddr[6]; eth_getenv_enetaddr("ethaddr", enetaddr); smc_set_mac_addr(enetaddr); } #endif /* CONFIG_DRIVER_SMC91111 || CONFIG_DRIVER_LAN91C96 */ /* Initialize from environment */ s = getenv("loadaddr"); if (s != NULL) load_addr = simple_strtoul(s, NULL, 16); #if defined(CONFIG_CMD_NET) s = getenv("bootfile"); if (s != NULL) copy_filename(BootFile, s, sizeof(BootFile)); #endif #ifdef BOARD_LATE_INIT board_late_init(); #endif #ifdef CONFIG_BITBANGMII bb_miiphy_init(); #endif #if defined(CONFIG_CMD_NET) #if defined(CONFIG_NET_MULTI) puts("Net: "); #endif eth_initialize(gd->bd); #if defined(CONFIG_RESET_PHY_R) debug("Reset Ethernet PHY\n"); reset_phy(); #endif #endif #ifdef CONFIG_POST post_run(NULL, POST_RAM | post_bootmode_get(0)); #endif #if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER) /* * Export available size of memory for Linux, * taking into account the protected RAM at top of memory */ { ulong pram; uchar memsz[32]; #ifdef CONFIG_PRAM char *s; s = getenv("pram"); if (s != NULL) pram = simple_strtoul(s, NULL, 10); else pram = CONFIG_PRAM; #else pram = 0; #endif #ifdef CONFIG_LOGBUFFER #ifndef CONFIG_ALT_LB_ADDR /* Also take the logbuffer into account (pram is in kB) */ pram += (LOGBUFF_LEN + LOGBUFF_OVERHEAD) / 1024; #endif #endif sprintf((char *)memsz, "%ldk", (gd->ram_size / 1024) - pram); setenv("mem", (char *)memsz); } #endif //sprite_cartoon_test(); if(workmode == WORK_MODE_BOOT) { #if defined(CONFIG_SUNXI_SCRIPT_REINIT) { FATFS script_mount; int ret; uint read_bytes = 0; FILE script_fs; uchar *buf = NULL; f_mount_ex(0, &script_mount, 0); ret = f_open (&script_fs, "0:script.bin", FA_OPEN_EXISTING | FA_READ | FA_WRITE ); if(ret) { printf("cant open script.bin, maybe it is not exist\n"); } else { buf = (uchar *)malloc(100 * 1024); memset(buf, 0, 100 * 1024); if(!f_read(&script_fs, buf, 100 * 1024, &read_bytes)) { printf("f_read read bytes = %d\n", read_bytes); } f_close(&script_fs); puts("try to unlink file "); printf("%d\n", f_unlink("0:script.bin")); } f_mount(0, NULL, NULL); if(read_bytes > 0) { char *tmp_target_buffer = (char *)(CONFIG_SYS_TEXT_BASE - 0x01000000); sunxi_flash_exit(1); memcpy(tmp_target_buffer + uboot_spare_head.boot_head.uboot_length, buf, read_bytes); sunxi_sprite_download_uboot(tmp_target_buffer, uboot_spare_head.boot_data.storage_type, 1); reset_cpu(0); } if(buf) { free(buf); } } #endif printf("WORK_MODE_BOOT\n"); #if (defined(CONFIG_SUNXI_DISPLAY) || defined(CONFIG_SUN7I_DISPLAY)) if(!ret) { #ifndef CONFIG_ARCH_HOMELET printf("board_status_probe\n"); board_status_probe(0); #endif if(!gd->chargemode) { if(sunxi_advert_disp_probe()) { printf("sunxi_bmp_logo_display\n"); sunxi_bmp_display("bootlogo.bmp"); } else { if(sunxi_advert_display("Reserve0", "advert.bmp")) { printf("sunxi_bmp_logo_display\n"); sunxi_bmp_display("bootlogo.bmp"); } } } else { printf("sunxi_bmp_charger_display\n"); sunxi_bmp_display("bat\\battery_charge.bmp"); } } #endif #ifdef CONFIG_READ_LOGO_FOR_KERNEL sunxi_read_bootlogo("boot_logo"); #endif } /* main_loop() can return to retry autoboot, if so just run it again. */ for (;;) { main_loop(); } hang(); /* NOTREACHED - no way out of command loop except booting */ } void hang(void) { puts("### ERROR ### Please RESET the board ###\n"); for (;;); }
/* * Display a dialog box for entering a date */ int dialog_timebox(const char *title, const char *subtitle, int height, int width, int hour, int minute, int second) { BOX hr_box, mn_box, sc_box; int key = 0, key2, button = sOK; int result = -2; WINDOW *dialog; time_t now_time = time((time_t *) 0); struct tm current; STATES state = sOK; const char **buttons = dlg_ok_labels(); char *prompt = strclone(subtitle); now_time = time((time_t *) 0); current = *localtime(&now_time); auto_size(title, prompt, &height, &width, 0, 0); height += MIN_HIGH; if (width < MIN_WIDE) width = MIN_WIDE; dlg_button_layout(buttons, &width); print_size(height, width); ctl_size(height, width); /* FIXME: how to make this resizable? */ dialog = new_window(height, width, box_y_ordinate(height), box_x_ordinate(width)); draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr); draw_bottom_box(dialog); draw_title(dialog, title); wattrset(dialog, dialog_attr); print_autowrap(dialog, prompt, height, width); /* compute positions of hour, month and year boxes */ memset(&hr_box, 0, sizeof(hr_box)); memset(&mn_box, 0, sizeof(mn_box)); memset(&sc_box, 0, sizeof(sc_box)); if (init_object(&hr_box, dialog, (width - MIN_WIDE + 1) / 2 + MARGIN, (height - MIN_HIGH + MARGIN), ONE_WIDE, ONE_HIGH, 24, hour >= 0 ? hour : current.tm_hour, 'H') < 0 || DrawObject(&hr_box) < 0) return -1; mvwprintw(dialog, hr_box.y, hr_box.x + ONE_WIDE + MARGIN, ":"); if (init_object(&mn_box, dialog, hr_box.x + (ONE_WIDE + 2 * MARGIN + 1), hr_box.y, hr_box.width, hr_box.height, 60, minute >= 0 ? minute : current.tm_min, 'M') < 0 || DrawObject(&mn_box) < 0) return -1; mvwprintw(dialog, mn_box.y, mn_box.x + ONE_WIDE + MARGIN, ":"); if (init_object(&sc_box, dialog, mn_box.x + (ONE_WIDE + 2 * MARGIN + 1), mn_box.y, mn_box.width, mn_box.height, 60, second >= 0 ? second : current.tm_sec, 'S') < 0 || DrawObject(&sc_box) < 0) return -1; while (result == -2) { BOX *obj = (state == sHR ? &hr_box : (state == sMN ? &mn_box : (state == sSC ? &sc_box : 0))); button = (state == sCANCEL) ? 1 : 0; dlg_draw_buttons(dialog, height - 2, 0, buttons, button, FALSE, width); if (obj != 0) dlg_set_focus(dialog, obj->window); key = mouse_wgetch(dialog); if ((key2 = dlg_char_to_button(key, buttons)) >= 0) { result = key2; } else { switch (key) { case M_EVENT + 0: result = DLG_EXIT_OK; break; case M_EVENT + 1: result = DLG_EXIT_CANCEL; break; case M_EVENT + 'H': state = sHR; break; case M_EVENT + 'M': state = sMN; break; case M_EVENT + 'S': state = sSC; break; case ESC: result = -1; break; case ' ': case '\n': result = button; break; case KEY_BTAB: state = prev_object(state); break; case TAB: state = next_object(state); break; default: if (obj != 0) { int step = next_or_previous(key); if (step != 0) { obj->value += step; while (obj->value < 0) obj->value += obj->period; obj->value %= obj->period; (void) DrawObject(obj); } } break; } } } del_window(dialog); sprintf(dialog_vars.input_result, "%02d:%02d:%02d\n", hr_box.value, mn_box.value, sc_box.value); mouse_free_regions(); return result; }
/* * Initialize SDRAM memory on the Local Bus. */ void sdram_init(void) { #if defined(CONFIG_SYS_OR2_PRELIM) && defined(CONFIG_SYS_BR2_PRELIM) uint idx; volatile fsl_lbc_t *lbc = LBC_BASE_ADDR; uint *sdram_addr = (uint *)CONFIG_SYS_LBC_SDRAM_BASE; uint cpu_board_rev; uint lsdmr_common; puts(" SDRAM: "); print_size (CONFIG_SYS_LBC_SDRAM_SIZE * 1024 * 1024, "\n"); /* * Setup SDRAM Base and Option Registers */ set_lbc_or(2, CONFIG_SYS_OR2_PRELIM); set_lbc_br(2, CONFIG_SYS_BR2_PRELIM); lbc->lbcr = CONFIG_SYS_LBC_LBCR; asm("msync"); lbc->lsrt = CONFIG_SYS_LBC_LSRT; lbc->mrtpr = CONFIG_SYS_LBC_MRTPR; asm("msync"); /* * MPC8548 uses "new" 15-16 style addressing. */ cpu_board_rev = get_cpu_board_revision(); lsdmr_common = CONFIG_SYS_LBC_LSDMR_COMMON; lsdmr_common |= LSDMR_BSMA1516; /* * Issue PRECHARGE ALL command. */ lbc->lsdmr = lsdmr_common | LSDMR_OP_PCHALL; asm("sync;msync"); *sdram_addr = 0xff; ppcDcbf((unsigned long) sdram_addr); udelay(100); /* * Issue 8 AUTO REFRESH commands. */ for (idx = 0; idx < 8; idx++) { lbc->lsdmr = lsdmr_common | LSDMR_OP_ARFRSH; asm("sync;msync"); *sdram_addr = 0xff; ppcDcbf((unsigned long) sdram_addr); udelay(100); } /* * Issue 8 MODE-set command. */ lbc->lsdmr = lsdmr_common | LSDMR_OP_MRW; asm("sync;msync"); *sdram_addr = 0xff; ppcDcbf((unsigned long) sdram_addr); udelay(100); /* * Issue NORMAL OP command. */ lbc->lsdmr = lsdmr_common | LSDMR_OP_NORMAL; asm("sync;msync"); *sdram_addr = 0xff; ppcDcbf((unsigned long) sdram_addr); udelay(200); /* Overkill. Must wait > 200 bus cycles */ #endif /* enable SDRAM init */ }
static void display_flash_config (ulong size) { puts ("Flash: "); print_size (size, "\n"); }
void board_init_r(gd_t *id, ulong dest_addr) { ulong malloc_start; #if !defined(CONFIG_SYS_NO_FLASH) ulong flash_size; #endif gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */ bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_R, "board_init_r"); monitor_flash_len = (ulong)&__rel_dyn_end - (ulong)_start; /* Enable caches */ enable_caches(); debug("monitor flash len: %08lX\n", monitor_flash_len); board_init(); /* Setup chipselects */ /* * TODO: printing of the clock inforamtion of the board is now * implemented as part of bdinfo command. Currently only support for * davinci SOC's is added. Remove this check once all the board * implement this. */ #ifdef CONFIG_CLOCKS set_cpu_clk_info(); /* Setup clock information */ #endif serial_initialize(); debug("Now running in RAM - U-Boot at: %08lx\n", dest_addr); #ifdef CONFIG_LOGBUFFER logbuff_init_ptrs(); #endif #ifdef CONFIG_POST post_output_backlog(); #endif /* The Malloc area is immediately below the monitor copy in DRAM */ malloc_start = dest_addr - TOTAL_MALLOC_LEN; mem_malloc_init (malloc_start, TOTAL_MALLOC_LEN); #ifdef CONFIG_ARCH_EARLY_INIT_R arch_early_init_r(); #endif power_init_board(); #if !defined(CONFIG_SYS_NO_FLASH) puts("Flash: "); flash_size = flash_init(); if (flash_size > 0) { # ifdef CONFIG_SYS_FLASH_CHECKSUM print_size(flash_size, ""); /* * Compute and print flash CRC if flashchecksum is set to 'y' * * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX */ if (getenv_yesno("flashchecksum") == 1) { printf(" CRC: %08X", crc32(0, (const unsigned char *) CONFIG_SYS_FLASH_BASE, flash_size)); } putc('\n'); # else /* !CONFIG_SYS_FLASH_CHECKSUM */ print_size(flash_size, "\n"); # endif /* CONFIG_SYS_FLASH_CHECKSUM */ } else { puts(failed); hang(); } #endif #if defined(CONFIG_CMD_NAND) puts("NAND: "); nand_init(); /* go init the NAND */ #endif #if defined(CONFIG_CMD_ONENAND) onenand_init(); #endif #ifdef CONFIG_GENERIC_MMC puts("MMC: "); mmc_initialize(gd->bd); #endif #ifdef CONFIG_CMD_SCSI puts("SCSI: "); scsi_init(); #endif #ifdef CONFIG_HAS_DATAFLASH AT91F_DataflashInit(); dataflash_print_info(); #endif /* initialize environment */ if (should_load_env()) env_relocate(); else set_default_env(NULL); #if defined(CONFIG_CMD_PCI) || defined(CONFIG_PCI) arm_pci_init(); #endif stdio_init(); /* get the devices list going. */ jumptable_init(); #if defined(CONFIG_API) /* Initialize API */ api_init(); #endif console_init_r(); /* fully init console as a device */ #ifdef CONFIG_DISPLAY_BOARDINFO_LATE # ifdef CONFIG_OF_CONTROL /* Put this here so it appears on the LCD, now it is ready */ display_fdt_model(gd->fdt_blob); # else checkboard(); # endif #endif #if defined(CONFIG_ARCH_MISC_INIT) /* miscellaneous arch dependent initialisations */ arch_misc_init(); #endif #if defined(CONFIG_MISC_INIT_R) /* miscellaneous platform dependent initialisations */ misc_init_r(); #endif /* set up exceptions */ interrupt_init(); /* enable exceptions */ enable_interrupts(); /* Initialize from environment */ load_addr = getenv_ulong("loadaddr", 16, load_addr); #ifdef CONFIG_BOARD_LATE_INIT board_late_init(); #endif #ifdef CONFIG_BITBANGMII bb_miiphy_init(); #endif #if defined(CONFIG_CMD_NET) puts("Net: "); eth_initialize(gd->bd); #if defined(CONFIG_RESET_PHY_R) debug("Reset Ethernet PHY\n"); reset_phy(); #endif #endif #ifdef CONFIG_POST post_run(NULL, POST_RAM | post_bootmode_get(0)); #endif #if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER) /* * Export available size of memory for Linux, * taking into account the protected RAM at top of memory */ { ulong pram = 0; uchar memsz[32]; #ifdef CONFIG_PRAM pram = getenv_ulong("pram", 10, CONFIG_PRAM); #endif #ifdef CONFIG_LOGBUFFER #ifndef CONFIG_ALT_LB_ADDR /* Also take the logbuffer into account (pram is in kB) */ pram += (LOGBUFF_LEN + LOGBUFF_OVERHEAD) / 1024; #endif #endif sprintf((char *)memsz, "%ldk", (gd->ram_size / 1024) - pram); setenv("mem", (char *)memsz); } #endif /* main_loop() can return to retry autoboot, if so just run it again. */ for (;;) { main_loop(); } /* NOTREACHED - no way out of command loop except booting */ }
void board_init_f(ulong bootflag) { bd_t *bd; unsigned char *s; init_fnc_t **init_fnc_ptr; int j; #ifndef CONFIG_SYS_NO_FLASH ulong flash_size; #endif gd = (gd_t *) (CONFIG_SYS_GBL_DATA_OFFSET); /* Clear initial global data */ memset((void *)gd, 0, sizeof(gd_t)); gd->bd = (bd_t *) (gd + 1); /* At end of global data */ gd->baudrate = CONFIG_BAUDRATE; gd->cpu_clk = CONFIG_SYS_CLK_FREQ; bd = gd->bd; bd->bi_memstart = CONFIG_SYS_RAM_BASE; bd->bi_memsize = CONFIG_SYS_RAM_SIZE; bd->bi_flashstart = CONFIG_SYS_FLASH_BASE; #if defined(CONFIG_SYS_SRAM_BASE) && defined(CONFIG_SYS_SRAM_SIZE) bd->bi_sramstart = CONFIG_SYS_SRAM_BASE; bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE; #endif bd->bi_baudrate = CONFIG_BAUDRATE; bd->bi_bootflags = bootflag; /* boot / reboot flag (for LynxOS) */ gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */ gd->reloc_off = CONFIG_SYS_RELOC_MONITOR_BASE - CONFIG_SYS_MONITOR_BASE; for (init_fnc_ptr = init_sequence, j = 0; *init_fnc_ptr; ++init_fnc_ptr, j++) { #ifdef DEBUG_INIT_SEQUENCE if (j > 9) str_init_seq[9] = '0' + (j / 10); str_init_seq[10] = '0' + (j - (j / 10) * 10); serial_puts(str_init_seq); #endif if ((*init_fnc_ptr + gd->reloc_off) () != 0) { hang(); } } #ifdef DEBUG_INIT_SEQUENCE serial_puts(str_init_seq_done); #endif /* * Now that we have DRAM mapped and working, we can * relocate the code and continue running from DRAM. * * Reserve memory at end of RAM for (top down in that order): * - kernel log buffer * - protected RAM * - LCD framebuffer * - monitor code * - board info struct */ #ifdef DEBUG_MEM_LAYOUT printf("CONFIG_SYS_MONITOR_BASE: 0x%lx\n", CONFIG_SYS_MONITOR_BASE); printf("CONFIG_ENV_ADDR: 0x%lx\n", CONFIG_ENV_ADDR); printf("CONFIG_SYS_RELOC_MONITOR_BASE: 0x%lx (%d)\n", CONFIG_SYS_RELOC_MONITOR_BASE, CONFIG_SYS_MONITOR_LEN); printf("CONFIG_SYS_MALLOC_BASE: 0x%lx (%d)\n", CONFIG_SYS_MALLOC_BASE, CONFIG_SYS_MALLOC_LEN); printf("CONFIG_SYS_INIT_SP_OFFSET: 0x%lx (%d)\n", CONFIG_SYS_INIT_SP_OFFSET, CONFIG_SYS_STACK_SIZE); printf("CONFIG_SYS_PROM_OFFSET: 0x%lx (%d)\n", CONFIG_SYS_PROM_OFFSET, CONFIG_SYS_PROM_SIZE); printf("CONFIG_SYS_GBL_DATA_OFFSET: 0x%lx (%d)\n", CONFIG_SYS_GBL_DATA_OFFSET, GENERATED_GBL_DATA_SIZE); #endif #ifdef CONFIG_POST post_bootmode_init(); post_run(NULL, POST_ROM | post_bootmode_get(0)); #endif #if defined(CONFIG_NEEDS_MANUAL_RELOC) /* * We have to relocate the command table manually */ fixup_cmdtable(&__u_boot_cmd_start, (ulong)(&__u_boot_cmd_end - &__u_boot_cmd_start)); #endif /* defined(CONFIG_NEEDS_MANUAL_RELOC) */ #if defined(CONFIG_CMD_AMBAPP) && defined(CONFIG_SYS_AMBAPP_PRINT_ON_STARTUP) puts("AMBA:\n"); do_ambapp_print(NULL, 0, 0, NULL); #endif /* initialize higher level parts of CPU like time base and timers */ cpu_init_r(); /* start timer */ timer_interrupt_init(); /* * Enable Interrupts before any calls to udelay, * the flash driver may use udelay resulting in * a hang if not timer0 IRQ is enabled. */ interrupt_init(); /* The Malloc area is immediately below the monitor copy in RAM */ mem_malloc_init(CONFIG_SYS_MALLOC_BASE, CONFIG_SYS_MALLOC_END - CONFIG_SYS_MALLOC_BASE); malloc_bin_reloc(); #if !defined(CONFIG_SYS_NO_FLASH) puts("Flash: "); if ((flash_size = flash_init()) > 0) { # ifdef CONFIG_SYS_FLASH_CHECKSUM print_size(flash_size, ""); /* * Compute and print flash CRC if flashchecksum is set to 'y' * * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX */ s = getenv("flashchecksum"); if (s && (*s == 'y')) { printf(" CRC: %08lX", crc32(0, (const unsigned char *)CONFIG_SYS_FLASH_BASE, flash_size) ); } putc('\n'); # else /* !CONFIG_SYS_FLASH_CHECKSUM */ print_size(flash_size, "\n"); # endif /* CONFIG_SYS_FLASH_CHECKSUM */ } else { puts(failed); hang(); } bd->bi_flashstart = CONFIG_SYS_FLASH_BASE; /* update start of FLASH memory */ bd->bi_flashsize = flash_size; /* size of FLASH memory (final value) */ #if CONFIG_SYS_MONITOR_BASE == CONFIG_SYS_FLASH_BASE bd->bi_flashoffset = monitor_flash_len; /* reserved area for startup monitor */ #else bd->bi_flashoffset = 0; #endif #else /* CONFIG_SYS_NO_FLASH */ bd->bi_flashsize = 0; bd->bi_flashstart = 0; bd->bi_flashoffset = 0; #endif /* !CONFIG_SYS_NO_FLASH */ #ifdef CONFIG_SPI # if !defined(CONFIG_ENV_IS_IN_EEPROM) spi_init_f(); # endif spi_init_r(); #endif /* relocate environment function pointers etc. */ env_relocate(); #if defined(CONFIG_BOARD_LATE_INIT) board_late_init(); #endif #ifdef CONFIG_ID_EEPROM mac_read_from_eeprom(); #endif /* IP Address */ bd->bi_ip_addr = getenv_IPaddr("ipaddr"); #if defined(CONFIG_PCI) /* * Do pci configuration */ pci_init(); #endif /* Initialize stdio devices */ stdio_init(); /* Initialize the jump table for applications */ jumptable_init(); /* Initialize the console (after the relocation and devices init) */ console_init_r(); #ifdef CONFIG_STATUS_LED status_led_set(STATUS_LED_BOOT, STATUS_LED_BLINKING); #endif udelay(20); /* Initialize from environment */ load_addr = getenv_ulong("loadaddr", 16, load_addr); #if defined(CONFIG_CMD_NET) if ((s = getenv("bootfile")) != NULL) { copy_filename(BootFile, s, sizeof(BootFile)); } #endif /* CONFIG_CMD_NET */ WATCHDOG_RESET(); #if defined(CONFIG_CMD_DOC) WATCHDOG_RESET(); puts("DOC: "); doc_init(); #endif #ifdef CONFIG_BITBANGMII bb_miiphy_init(); #endif #if defined(CONFIG_CMD_NET) WATCHDOG_RESET(); puts("Net: "); eth_initialize(bd); #endif #if defined(CONFIG_CMD_NET) && defined(CONFIG_RESET_PHY_R) WATCHDOG_RESET(); debug("Reset Ethernet PHY\n"); reset_phy(); #endif #ifdef CONFIG_POST post_run(NULL, POST_RAM | post_bootmode_get(0)); #endif #if defined(CONFIG_CMD_IDE) WATCHDOG_RESET(); puts("IDE: "); ide_init(); #endif /* CONFIG_CMD_IDE */ #ifdef CONFIG_LAST_STAGE_INIT WATCHDOG_RESET(); /* * Some parts can be only initialized if all others (like * Interrupts) are up and running (i.e. the PC-style ISA * keyboard). */ last_stage_init(); #endif #ifdef CONFIG_PS2KBD puts("PS/2: "); kbd_init(); #endif prom_init(); /* main_loop */ for (;;) { WATCHDOG_RESET(); main_loop(); } }
int main(int argc, char *argv[]) { DIR *dsp; struct dirent *entlist[MAXDIRS] = {0}; struct stat stat_buf; struct tm *tsp; char path[DSIZE]; int show_perm = 0; /* show file permissions */ int show_size = 0; /* atarimae darou */ int show_last_access = 0; int c, j; int i = 0; while ((c = getopt(argc, argv, "spt")) != -1) switch(c) { case 'p': show_perm = 1; break; case 's': show_size = 1; break; case 't': show_last_access = 1; break; default: break; } /* if a directory name is provided, use it */ if (argv[optind]) strcpy(path, argv[optind]); else getcwd(path, sizeof(path)); dsp = opendir(path); if (dsp) { while ((entlist[i++] = readdir(dsp))) ; i--; /* number of entries */ printf("TOTAL ENTRIES: %d \n", i); qsort(entlist, i, sizeof(struct dirent *), compare_direntp); j = 0; while (j < i) { stat(entlist[j]->d_name, &stat_buf); if (show_perm) print_perms(stat_buf); if (show_size) print_size(stat_buf); if (show_last_access) { tsp = gmtime(&(stat_buf.st_atime)); printf("%-2d:%-2d:%-2d ", tsp->tm_hour, tsp->tm_min, tsp->tm_sec); } /* print yellow text if directory */ if (S_ISDIR(stat_buf.st_mode)) printf(COLOUR_NANDEMO "%s\n" COLOUR_RESET, entlist[j]->d_name); /* print blue text if regular and executable by owner */ else if (S_ISREG(stat_buf.st_mode) && (stat_buf.st_mode & S_IXUSR)) printf(COLOUR_BLUE "%s \n" COLOUR_RESET, entlist[j]->d_name); else printf("%s \n", entlist[j]->d_name); j++; } closedir(dsp); } else perror("error: could not access directory\n"); return 0; }
void board_init_r(gd_t *id, ulong dest_addr) { char *s; bd_t *bd; ulong malloc_start; #if !defined(CONFIG_SYS_NO_FLASH) ulong flash_size; #endif gd = id; bd = gd->bd; gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */ monitor_flash_len = _end_ofs; /* Enable caches */ enable_caches(); // debug("monitor flash len: %08lX\n", monitor_flash_len); #ifdef CONFIG_ALLWINNER #ifdef DEBUG // printf("sunxi script init\n"); #endif sw_gpio_init(); if(script_parser_fetch("target", "storage_type", &storage_type, sizeof(int))) storage_type = 0; if((storage_type <= 0) || (storage_type > 2)) { int used; used = 1; script_parser_patch("nand_para", "nand_used", &used, 1); used = 0; script_parser_patch("mmc2_para", "sdc_used", &used, 1); storage_type = 0; } else if(1 == storage_type) { mmc_card_no = 0; } else { int used; used = 0; script_parser_patch("nand_para", "nand_used", &used, 1); used = 1; script_parser_patch("mmc2_para", "sdc_used", &used, 1); mmc_card_no = 2; } #ifdef DEBUG { int used; printf("test storage_type=%d, mmc_card_no=%d\n", storage_type, mmc_card_no); if(!script_parser_fetch("nand_para", "nand_used", &used, sizeof(int))) { printf("nand_para nand_used = %d\n", used); } if(!script_parser_fetch("mmc2_para", "sdc_used", &used, sizeof(int))) { printf("mmc2_para sdc_used = %d\n", used); } printf("test over\n"); } #endif if(script_parser_fetch("uart_para", "uart_debug_port", &uart_console, sizeof(int))) uart_console = 0; #endif board_init(); /* Setup chipselects */ #ifdef CONFIG_SERIAL_MULTI serial_initialize(); #endif debug("Now running in RAM - U-Boot at: %08lx\n", dest_addr); #ifdef CONFIG_LOGBUFFER logbuff_init_ptrs(); #endif #ifdef CONFIG_POST post_output_backlog(); #endif /* The Malloc area is immediately below the monitor copy in DRAM */ malloc_start = dest_addr - TOTAL_MALLOC_LEN; mem_malloc_init (malloc_start, TOTAL_MALLOC_LEN); #if !defined(CONFIG_SYS_NO_FLASH) puts("Flash: "); flash_size = flash_init(); if (flash_size > 0) { # ifdef CONFIG_SYS_FLASH_CHECKSUM print_size(flash_size, ""); /* * Compute and print flash CRC if flashchecksum is set to 'y' * * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX */ s = getenv("flashchecksum"); if (s && (*s == 'y')) { printf(" CRC: %08X", crc32(0, (const unsigned char *) CONFIG_SYS_FLASH_BASE, flash_size)); } putc('\n'); # else /* !CONFIG_SYS_FLASH_CHECKSUM */ print_size(flash_size, "\n"); # endif /* CONFIG_SYS_FLASH_CHECKSUM */ } else { puts(failed); hang(); } #endif #ifdef CONFIG_ALLWINNER if(!storage_type){ puts("NAND: "); nand_init(); /* go init the NAND */ } else{ puts("MMC: "); mmc_initialize(bd); } sunxi_flash_handle_init(); sunxi_partition_init(); #else #if defined(CONFIG_CMD_NAND) if(!storage_type){ puts("NAND: "); nand_init(); /* go init the NAND */ } #endif/*CONFIG_CMD_NAND*/ #if defined(CONFIG_GENERIC_MMC) if(storage_type){ puts("MMC: "); mmc_initialize(bd); } #endif/*CONFIG_GENERIC_MMC*/ #endif/*CONFIG_ALLWINNER*/ #if defined(CONFIG_CMD_ONENAND) onenand_init(); #endif #ifdef CONFIG_HAS_DATAFLASH AT91F_DataflashInit(); dataflash_print_info(); #endif /* initialize environment */ env_relocate(); #if defined(CONFIG_CMD_PCI) || defined(CONFIG_PCI) arm_pci_init(); #endif /* IP Address */ gd->bd->bi_ip_addr = getenv_IPaddr("ipaddr"); stdio_init(); /* get the devices list going. */ jumptable_init(); #if defined(CONFIG_API) /* Initialize API */ api_init(); #endif console_init_r(); /* fully init console as a device */ #if defined(CONFIG_ARCH_MISC_INIT) /* miscellaneous arch dependent initialisations */ arch_misc_init(); #endif #if defined(CONFIG_MISC_INIT_R) /* miscellaneous platform dependent initialisations */ misc_init_r(); #endif /* set up exceptions */ interrupt_init(); /* enable exceptions */ enable_interrupts(); /* Perform network card initialisation if necessary */ #if defined(CONFIG_DRIVER_SMC91111) || defined (CONFIG_DRIVER_LAN91C96) /* XXX: this needs to be moved to board init */ if (getenv("ethaddr")) { uchar enetaddr[6]; eth_getenv_enetaddr("ethaddr", enetaddr); smc_set_mac_addr(enetaddr); } #endif /* CONFIG_DRIVER_SMC91111 || CONFIG_DRIVER_LAN91C96 */ /* Initialize from environment */ s = getenv("loadaddr"); if (s != NULL) load_addr = simple_strtoul(s, NULL, 16); #if defined(CONFIG_CMD_NET) s = getenv("bootfile"); if (s != NULL) copy_filename(BootFile, s, sizeof(BootFile)); #endif #ifdef BOARD_LATE_INIT board_late_init(); #endif #ifdef CONFIG_BITBANGMII bb_miiphy_init(); #endif #if defined(CONFIG_CMD_NET) #if defined(CONFIG_NET_MULTI) puts("Net: "); #endif eth_initialize(gd->bd); #if defined(CONFIG_RESET_PHY_R) debug("Reset Ethernet PHY\n"); reset_phy(); #endif #endif #ifdef CONFIG_POST post_run(NULL, POST_RAM | post_bootmode_get(0)); #endif #if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER) /* * Export available size of memory for Linux, * taking into account the protected RAM at top of memory */ { ulong pram; uchar memsz[32]; #ifdef CONFIG_PRAM char *s; s = getenv("pram"); if (s != NULL) pram = simple_strtoul(s, NULL, 10); else pram = CONFIG_PRAM; #else pram = 0; #endif #ifdef CONFIG_LOGBUFFER #ifndef CONFIG_ALT_LB_ADDR /* Also take the logbuffer into account (pram is in kB) */ pram += (LOGBUFF_LEN + LOGBUFF_OVERHEAD) / 1024; #endif #endif sprintf((char *)memsz, "%ldk", (gd->ram_size / 1024) - pram); setenv("mem", (char *)memsz); } #endif /* main_loop() can return to retry autoboot, if so just run it again. */ for (;;) { main_loop(); } /* NOTREACHED - no way out of command loop except booting */ }
/* * Initialize SDRAM memory on the Local Bus. */ void sdram_init(void) { #if defined(CONFIG_SYS_OR2_PRELIM) && defined(CONFIG_SYS_BR2_PRELIM) uint idx; volatile ccsr_lbc_t *lbc = (void *)(CONFIG_SYS_MPC85xx_LBC_ADDR); uint *sdram_addr = (uint *)CONFIG_SYS_LBC_SDRAM_BASE; uint cpu_board_rev; uint lsdmr_common; puts(" SDRAM: "); print_size (CONFIG_SYS_LBC_SDRAM_SIZE * 1024 * 1024, "\n"); /* * Setup SDRAM Base and Option Registers */ lbc->or2 = CONFIG_SYS_OR2_PRELIM; asm("msync"); lbc->br2 = CONFIG_SYS_BR2_PRELIM; asm("msync"); lbc->lbcr = CONFIG_SYS_LBC_LBCR; asm("msync"); lbc->lsrt = CONFIG_SYS_LBC_LSRT; lbc->mrtpr = CONFIG_SYS_LBC_MRTPR; asm("msync"); /* * Determine which address lines to use baed on CPU board rev. */ cpu_board_rev = get_cpu_board_revision(); lsdmr_common = CONFIG_SYS_LBC_LSDMR_COMMON; if (cpu_board_rev == MPC85XX_CPU_BOARD_REV_1_0) { lsdmr_common |= CONFIG_SYS_LBC_LSDMR_BSMA1617; } else if (cpu_board_rev == MPC85XX_CPU_BOARD_REV_1_1) { lsdmr_common |= CONFIG_SYS_LBC_LSDMR_BSMA1516; } else { /* * Assume something unable to identify itself is * really old, and likely has lines 16/17 mapped. */ lsdmr_common |= CONFIG_SYS_LBC_LSDMR_BSMA1617; } /* * Issue PRECHARGE ALL command. */ lbc->lsdmr = lsdmr_common | CONFIG_SYS_LBC_LSDMR_OP_PCHALL; asm("sync;msync"); *sdram_addr = 0xff; ppcDcbf((unsigned long) sdram_addr); udelay(100); /* * Issue 8 AUTO REFRESH commands. */ for (idx = 0; idx < 8; idx++) { lbc->lsdmr = lsdmr_common | CONFIG_SYS_LBC_LSDMR_OP_ARFRSH; asm("sync;msync"); *sdram_addr = 0xff; ppcDcbf((unsigned long) sdram_addr); udelay(100); } /* * Issue 8 MODE-set command. */ lbc->lsdmr = lsdmr_common | CONFIG_SYS_LBC_LSDMR_OP_MRW; asm("sync;msync"); *sdram_addr = 0xff; ppcDcbf((unsigned long) sdram_addr); udelay(100); /* * Issue NORMAL OP command. */ lbc->lsdmr = lsdmr_common | CONFIG_SYS_LBC_LSDMR_OP_NORMAL; asm("sync;msync"); *sdram_addr = 0xff; ppcDcbf((unsigned long) sdram_addr); udelay(200); /* Overkill. Must wait > 200 bus cycles */ #endif /* enable SDRAM init */ }
static int blockset_open_file(struct blockstore *blockStore, struct blockset *bs) { uint64 offset; mtime_t ts; int res; res = file_open(bs->filename, 0 /* R/O */, 0 /* !unbuf */, &bs->desc); if (res) { return res; } bs->filesize = file_getsize(bs->desc); if (bs->filesize < 0) { return errno; } if (bs->filesize > 0) { char *s = print_size(bs->filesize); char *name = file_getname(bs->filename); Log(LGPFX " reading file %s -- %s -- %llu headers.\n", name, s, bs->filesize / sizeof(btc_block_header)); free(name); free(s); } ts = time_get(); offset = 0; while (offset < bs->filesize) { btc_block_header buf[10000]; size_t numRead; size_t numBytes; int numHeaders; int i; numBytes = MIN(bs->filesize - offset, sizeof buf); res = file_pread(bs->desc, offset, buf, numBytes, &numRead); if (res != 0) { break; } if (btc->stop != 0) { res = 1; NOT_TESTED(); break; } numHeaders = numRead / sizeof(btc_block_header); for (i = 0; i < numHeaders; i++) { struct blockentry *be; uint256 hash; be = blockstore_alloc_entry(buf + i); be->written = 1; hash256_calc(buf + i, sizeof buf[0], &hash); if (!blockstore_validate_chkpt(&hash, blockStore->height + 1)) { return 1; } blockstore_add_entry(blockStore, be, &hash); if (i == numHeaders - 1) { bitcui_set_status("loading headers .. %llu%%", (offset + numBytes) * 100 / bs->filesize); } if (i == numHeaders - 1 || (numBytes < sizeof buf && i > numHeaders - 256)) { bitcui_set_last_block_info(&hash, blockStore->height, be->header.timestamp); } } offset += numRead; } ts = time_get() - ts; char hashStr[80]; char *latStr; uint256_snprintf_reverse(hashStr, sizeof hashStr, &blockStore->best_hash); Log(LGPFX " loaded blocks up to %s\n", hashStr); latStr = print_latency(ts); Log(LGPFX " this took %s\n", latStr); free(latStr); return res; }
void sdram_init(void) { volatile immap_t *immap = (immap_t *)CFG_IMMRBAR; volatile lbus8349_t *lbc= &immap->lbus; uint *sdram_addr = (uint *)CFG_LBC_SDRAM_BASE; puts("\n SDRAM on Local Bus: "); print_size (CFG_LBC_SDRAM_SIZE * 1024 * 1024, "\n"); /* * Setup SDRAM Base and Option Registers, already done in cpu_init.c */ /* setup mtrpt, lsrt and lbcr for LB bus */ lbc->lbcr = CFG_LBC_LBCR; lbc->mrtpr = CFG_LBC_MRTPR; lbc->lsrt = CFG_LBC_LSRT; asm("sync"); /* * Configure the SDRAM controller Machine Mode Register. */ lbc->lsdmr = CFG_LBC_LSDMR_5; /* 0x40636733; normal operation */ lbc->lsdmr = CFG_LBC_LSDMR_1; /* 0x68636733; precharge all the banks */ asm("sync"); *sdram_addr = 0xff; udelay(100); lbc->lsdmr = CFG_LBC_LSDMR_2; /* 0x48636733; auto refresh */ asm("sync"); /*1 times*/ *sdram_addr = 0xff; udelay(100); /*2 times*/ *sdram_addr = 0xff; udelay(100); /*3 times*/ *sdram_addr = 0xff; udelay(100); /*4 times*/ *sdram_addr = 0xff; udelay(100); /*5 times*/ *sdram_addr = 0xff; udelay(100); /*6 times*/ *sdram_addr = 0xff; udelay(100); /*7 times*/ *sdram_addr = 0xff; udelay(100); /*8 times*/ *sdram_addr = 0xff; udelay(100); /* 0x58636733; mode register write operation */ lbc->lsdmr = CFG_LBC_LSDMR_4; asm("sync"); *sdram_addr = 0xff; udelay(100); lbc->lsdmr = CFG_LBC_LSDMR_5; /* 0x40636733; normal operation */ asm("sync"); *sdram_addr = 0xff; udelay(100); }
unsigned long flash_init (void) { unsigned int i; unsigned long size_b0 = 0, size_b1 = 0; unsigned long base, flash_size; /* Init: no FLASHes known */ for (i=0; i<CONFIG_SYS_MAX_FLASH_BANKS; ++i) { flash_info[i].flash_id = FLASH_UNKNOWN; } /* the boot flash */ base = CONFIG_SYS_FLASH_BASE; #ifndef CONFIG_SYS_BOOT_FLASH_WIDTH #define CONFIG_SYS_BOOT_FLASH_WIDTH 1 #endif size_b0 = flash_get_size(CONFIG_SYS_BOOT_FLASH_WIDTH, (vu_long *)base, &flash_info[0]); #ifndef CONFIG_P3G4 printf("["); print_size (size_b0, ""); printf("@%08lX] ", base); #endif if (flash_info[0].flash_id == FLASH_UNKNOWN) { printf ("## Unknown FLASH at %08lx: Size = 0x%08lx = %ld MB\n", base, size_b0, size_b0<<20); } base = memoryGetDeviceBaseAddress(CONFIG_SYS_EXTRA_FLASH_DEVICE); for(i=1; i<CONFIG_SYS_MAX_FLASH_BANKS; i++) { unsigned long size = flash_get_size(CONFIG_SYS_EXTRA_FLASH_WIDTH, (vu_long *)base, &flash_info[i]); #ifndef CONFIG_P3G4 printf("["); print_size (size, ""); printf("@%08lX] ", base); #endif if (flash_info[i].flash_id == FLASH_UNKNOWN) { if(i==1) { printf ("## Unknown FLASH at %08lx: Size = 0x%08lx = %ld MB\n", base, size_b1, size_b1<<20); } break; } size_b1+=size; base+=size; } #if CONFIG_SYS_MONITOR_BASE >= CONFIG_SYS_FLASH_BASE /* monitor protection ON by default */ flash_protect(FLAG_PROTECT_SET, CONFIG_SYS_MONITOR_BASE, CONFIG_SYS_MONITOR_BASE + monitor_flash_len - 1, flash_get_info(CONFIG_SYS_MONITOR_BASE)); #endif #ifdef CONFIG_ENV_IS_IN_FLASH /* ENV protection ON by default */ flash_protect(FLAG_PROTECT_SET, CONFIG_ENV_ADDR, CONFIG_ENV_ADDR + CONFIG_ENV_SIZE - 1, flash_get_info(CONFIG_ENV_ADDR)); #endif flash_size = size_b0 + size_b1; return flash_size; }
/*----------------------------------------------------------------------- */ void flash_print_info (flash_info_t *info) { int i; if (info->flash_id == FLASH_UNKNOWN) { printf ("missing or unknown FLASH type\n"); return; } switch (info->flash_id & FLASH_VENDMASK) { case FLASH_MAN_AMD: printf ("AMD "); break; case FLASH_MAN_FUJ: printf ("FUJITSU "); break; case FLASH_MAN_INTEL: printf ("INTEL "); break; default: printf ("Unknown Vendor "); break; } switch (info->flash_id & FLASH_TYPEMASK) { case FLASH_AM040: printf ("AM29LV040B (4 Mbit, bottom boot sect)\n"); break; case FLASH_AM400B: printf ("AM29LV400B (4 Mbit, bottom boot sect)\n"); break; case FLASH_AM400T: printf ("AM29LV400T (4 Mbit, top boot sector)\n"); break; case FLASH_AM800B: printf ("AM29LV800B (8 Mbit, bottom boot sect)\n"); break; case FLASH_AM800T: printf ("AM29LV800T (8 Mbit, top boot sector)\n"); break; case FLASH_AM160B: printf ("AM29LV160B (16 Mbit, bottom boot sect)\n"); break; case FLASH_AM160T: printf ("AM29LV160T (16 Mbit, top boot sector)\n"); break; case FLASH_AM320B: printf ("AM29LV320B (32 Mbit, bottom boot sect)\n"); break; case FLASH_AM320T: printf ("AM29LV320T (32 Mbit, top boot sector)\n"); break; case FLASH_28F640J3A: printf ("28F640J3A (64 Mbit)\n"); break; case FLASH_28F128J3A: printf ("28F128J3A (128 Mbit)\n"); break; case FLASH_ROM: printf ("ROM\n"); break; case FLASH_RAM: printf ("RAM\n"); break; default: printf ("Unknown Chip Type\n"); break; } puts (" Size: "); print_size (info->size, ""); printf (" in %d Sectors\n", info->sector_count); printf (" Sector Start Addresses:"); for (i=0; i<info->sector_count; ++i) { if ((i % 5) == 0) printf ("\n "); printf (" %08lX%s", info->start[i], info->protect[i] ? " (RO)" : " " ); } printf ("\n"); return; }
static void display_flash_config (void) { puts ("Flash: "); print_size(gd->bd->bi_flashsize, " "); printf("at address 0x%08lx\n", gd->bd->bi_flashstart); }
/* * Display a menu for choosing among a number of options */ int dialog_menu(const char *title, const char *cprompt, int height, int width, int menu_height, int item_no, char **items) { int i, j, x, y, cur_x, cur_y, box_x, box_y; int key = 0, fkey; int button = 0; int choice = dlg_default_item(items, MENUBOX_TAGS); int result = DLG_EXIT_UNKNOWN; int scrollamt = 0; int max_choice, min_width; int found; int use_width, name_width, text_width; WINDOW *dialog, *menu; char *prompt = strclone(cprompt); const char **buttons = dlg_ok_labels(); tab_correct_str(prompt); if (menu_height == 0) { min_width = calc_listw(item_no, items, MENUBOX_TAGS) + 10; /* calculate height without items (4) */ auto_size(title, prompt, &height, &width, 4, MAX(26, min_width)); calc_listh(&height, &menu_height, item_no); } else { auto_size(title, prompt, &height, &width, 4 + menu_height, 26); } print_size(height, width); ctl_size(height, width); /* Find out maximal number of displayable items at once. */ max_choice = MIN(menu_height, RowHeight(item_no)); if (dialog_vars.input_menu) max_choice /= INPUT_ROWS; x = box_x_ordinate(width); y = box_y_ordinate(height); dialog = new_window(height, width, y, x); mouse_setbase(x, y); draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr); draw_bottom_box(dialog); draw_title(dialog, title); wattrset(dialog, dialog_attr); print_autowrap(dialog, prompt, height, width); menu_width = width - 6; getyx(dialog, cur_y, cur_x); box_y = cur_y + 1; box_x = (width - menu_width) / 2 - 1; /* create new window for the menu */ menu = sub_window(dialog, menu_height, menu_width, y + box_y + 1, x + box_x + 1); /* draw a box around the menu items */ draw_box(dialog, box_y, box_x, menu_height + 2, menu_width + 2, menubox_border_attr, menubox_attr); name_width = 0; text_width = 0; /* Find length of longest item to center menu * * only if --menu was given, using --inputmenu * * won't be centered. */ for (i = 0; i < item_no; i++) { name_width = MAX(name_width, dlg_count_columns(ItemName(i))); text_width = MAX(text_width, dlg_count_columns(ItemText(i))); } /* If the name+text is wider than the list is allowed, then truncate * one or both of them. If the name is no wider than 1/4 of the list, * leave it intact. */ use_width = (menu_width - GUTTER); if (text_width + name_width > use_width) { int need = 0.25 * use_width; if (name_width > need) { int want = use_width * ((double) name_width) / (text_width + name_width); name_width = (want > need) ? want : need; } text_width = use_width - name_width; } tag_x = (dialog_vars.input_menu ? 0 : (use_width - text_width - name_width) / 2); item_x = name_width + tag_x + GUTTER; if (choice - scrollamt >= max_choice) { scrollamt = choice - (max_choice - 1); choice = max_choice - 1; } /* Print the menu */ for (i = 0; i < max_choice; i++) print_item(menu, ItemData(i + scrollamt), i, i == choice); (void) wnoutrefresh(menu); /* register the new window, along with its borders */ mouse_mkbigregion(box_y + 1, box_x, menu_height + 2, menu_width + 2, KEY_MAX, 1, 1, 1 /* by lines */ ); dlg_draw_arrows(dialog, scrollamt, scrollamt + max_choice < item_no, box_x + tag_x + 1, box_y, box_y + menu_height + 1); dlg_draw_buttons(dialog, height - 2, 0, buttons, button, FALSE, width); wtimeout(dialog, WTIMEOUT_VAL); while (result == DLG_EXIT_UNKNOWN) { key = mouse_wgetch(dialog, &fkey); if (!fkey) { fkey = TRUE; switch (key) { case '\n': case '\r': key = KEY_ENTER; break; case '-': key = KEY_UP; break; case '+': key = KEY_DOWN; break; case ' ': case TAB: key = KEY_RIGHT; break; case ESC: result = DLG_EXIT_ESC; continue; default: fkey = FALSE; break; } } found = FALSE; if (fkey) { /* * Allow a mouse-click on a box to switch selection to that box. * Handling a button click is a little more complicated, since we * push a KEY_ENTER back onto the input stream so we'll put the * cursor at the right place before handling the "keypress". */ if (key >= (M_EVENT + KEY_MAX)) { key -= (M_EVENT + KEY_MAX); i = RowToItem(key); found = TRUE; } else if (key >= M_EVENT && dlg_ok_buttoncode(key - M_EVENT) >= 0) { button = (key - M_EVENT); ungetch('\n'); continue; } } else { /* * Check if key pressed matches first character of any item tag in * list. If there is more than one match, we will cycle through * each one as the same key is pressed repeatedly. */ for (j = scrollamt + choice + 1; j < item_no; j++) { if (dlg_match_char(dlg_last_getc(), ItemName(j))) { found = TRUE; i = j - scrollamt; break; } } if (!found) { for (j = 0; j <= scrollamt + choice; j++) { if (dlg_match_char(dlg_last_getc(), ItemName(j))) { found = TRUE; i = j - scrollamt; break; } } } if (found) dlg_flush_getc(); /* * A single digit (1-9) positions the selection to that line in the * current screen. */ if (!found && (key <= '9') && (key > '0') && (key - '1' < max_choice)) { found = TRUE; i = key - '1'; } } if (!found && fkey) { found = TRUE; switch (key) { case KEY_HOME: i = -scrollamt; break; case KEY_LL: case KEY_END: i = item_no - 1 - scrollamt; break; case M_EVENT + KEY_PPAGE: case KEY_PPAGE: if (choice) i = 0; else if (scrollamt != 0) i = -MIN(scrollamt, max_choice); else continue; break; case M_EVENT + KEY_NPAGE: case KEY_NPAGE: i = MIN(choice + max_choice, item_no - scrollamt - 1); break; case KEY_UP: i = choice - 1; if (choice == 0 && scrollamt == 0) continue; break; case KEY_DOWN: i = choice + 1; if (scrollamt + choice >= item_no - 1) continue; break; default: found = FALSE; break; } } if (found) { if (i != choice) { getyx(dialog, cur_y, cur_x); if (i < 0 || i >= max_choice) { #if defined(NCURSES_VERSION_MAJOR) && NCURSES_VERSION_MAJOR < 5 /* * Using wscrl to assist ncurses scrolling is not needed * in version 5.x */ if (i == -1) { if (menu_height > 1) { /* De-highlight current first item */ print_item(menu, ItemData(scrollamt), 0, FALSE); scrollok(menu, TRUE); wscrl(menu, -RowHeight(1)); scrollok(menu, FALSE); } scrollamt--; print_item(menu, ItemData(scrollamt), 0, TRUE); } else if (i == max_choice) { if (menu_height > 1) { /* De-highlight current last item before scrolling up */ print_item(menu, ItemData(scrollamt + max_choice - 1), max_choice - 1, FALSE); scrollok(menu, TRUE); wscrl(menu, RowHeight(1)); scrollok(menu, FALSE); } scrollamt++; print_item(menu, ItemData(scrollamt + max_choice - 1), max_choice - 1, TRUE); } else #endif { if (i < 0) { scrollamt += i; choice = 0; } else { choice = max_choice - 1; scrollamt += (i - max_choice + 1); } for (i = 0; i < max_choice; i++) { print_item(menu, ItemData(scrollamt + i), i, i == choice); } } /* Clean bottom lines */ if (dialog_vars.input_menu) { int spare_lines, x_count; spare_lines = menu_height % INPUT_ROWS; wattrset(menu, menubox_attr); for (; spare_lines; spare_lines--) { wmove(menu, menu_height - spare_lines, 0); for (x_count = 0; x_count < menu_width; x_count++) { waddch(menu, ' '); } } } (void) wnoutrefresh(menu); dlg_draw_arrows(dialog, scrollamt, scrollamt + choice < item_no - 1, box_x + tag_x + 1, box_y, box_y + menu_height + 1); } else { /* De-highlight current item */ print_item(menu, ItemData(scrollamt + choice), choice, FALSE); /* Highlight new item */ choice = i; print_item(menu, ItemData(scrollamt + choice), choice, TRUE); (void) wnoutrefresh(menu); (void) wmove(dialog, cur_y, cur_x); wrefresh(dialog); } } continue; /* wait for another key press */ } if (fkey) { switch (key) { case KEY_BTAB: case KEY_LEFT: button = dlg_prev_button(buttons, button); dlg_draw_buttons(dialog, height - 2, 0, buttons, button, FALSE, width); break; case KEY_RIGHT: button = dlg_next_button(buttons, button); dlg_draw_buttons(dialog, height - 2, 0, buttons, button, FALSE, width); break; case KEY_ENTER: del_window(dialog); result = handle_button(dlg_ok_buttoncode(button), items, scrollamt + choice); if (dialog_vars.input_menu && result == DLG_EXIT_EXTRA) { char *tmp; tmp = input_menu_edit(menu, ItemData(scrollamt + choice), choice); dialog_vars.input_result[0] = '\0'; dlg_add_result("RENAMED "); dlg_add_result(ItemName(scrollamt + choice)); dlg_add_result(" "); dlg_add_result(tmp); free(tmp); dlg_draw_buttons(dialog, height - 2, 0, buttons, button, FALSE, width); } break; default: flash(); break; } } } mouse_free_regions(); del_window(dialog); free(prompt); return result; }