efs_device_t fs_device_ftl_flash_open (uint32 which_device) { fs_device_t ftl_flash_dev; efs_device_t base_dev; uint32 partition_name_cnt; if (which_device >= FS_DEVICE_FTL_MAX_DEVICES) FS_ERR_FATAL ("Max device limit exceeded...",0,0,0); /* Sanity check for number of supported partitions. */ partition_name_cnt = sizeof (ftl_partition_names) / sizeof (char*); if (FS_DEVICE_FTL_MAX_DEVICES >= partition_name_cnt) FS_ERR_FATAL ("check FTL partition-names config...",0,0,0); base_dev = &fs_base_ftl_device[which_device]; ftl_flash_dev = flash_open (ftl_partition_names[which_device], 0); if (ftl_flash_dev == FS_NO_DEVICE) return NULL; base_dev->efs_device_type = FS_DEVICE_TYPE_FTL_NAND; fs_device_ftl_flash_init_ops (base_dev); base_dev->priv.ftl_flash = ftl_flash_dev; return base_dev; }
static void *get_ec(void) { if (!ec) ec = flash_open("ec", NULL); return ec; }
/*! ******************************************************************************* ** ** \brief Get the number of flash sectors occupied by the boot image ** ** This function calculates the number of flash sectors occupied by the ** boot image and the leading boot block which contains some size and copy ** information as well as a variable number of register/value settings. ** ** \param device The type of boot device ** \param sectors The address of a buffer where to write the result into ** ** \return ** - GD_OK if successfull, the sectors argument contains the number of ** occupied sectors ** - non-GD_OK in case of error, see the GD_FLASH documentation for possible ** return values ** ******************************************************************************* */ GERR GD_SYS_BootImageGetSectors( GD_SYS_BOOT_DEVICE_E device, U16* sectors ) { GERR status; GD_HANDLE handle; GD_SYS_BOOT_S bootblock; U32 index; U16 u16words; U32 u32words; U32 address; U16 sector; GERR (*flash_open)(GD_HANDLE*); GERR (*flash_close)(GD_HANDLE*); GERR (*flash_get_sector)(GD_HANDLE,U32,U16*); #if !defined (SMARTMPEG_D) if( device == GD_SYS_BOOT_DEVICE_FLASH ) { flash_open = GD_FL_Open; flash_close = GD_FL_Close; flash_get_sector = GD_FL_GetSector; } else // device == GD_SYS_BOOT_DEVICE_SFLASH #endif { #if defined(SMARTMPEG_C) || defined(SMARTMPEG_M) || defined(SMARTMPEG_D) || defined(GK6105S) || defined(GK6106) flash_open = GD_SFLASH_Open; flash_close = GD_SFLASH_Close; flash_get_sector = GD_SFLASH_GetSector; #else return( GD_ERR_BAD_PARAMETER ); #endif } status = flash_open( &handle ); if( status == GD_OK ) { u16words = sizeof(bootblock) / sizeof(U16); u32words = sizeof(bootblock) / sizeof(U32); #if !defined(SMARTMPEG_D) if( device == GD_SYS_BOOT_DEVICE_FLASH ) { status = GD_FL_Read( handle, 0, (U16*)(void*)&bootblock, u16words ); } else #endif { #if defined(SMARTMPEG_C) || defined(SMARTMPEG_M) || defined(SMARTMPEG_D) || defined(GK6105S) || defined(GK6106) status = GD_SFLASH_Read( handle, 0, (U32*)(void*)&bootblock, u32words ); #else status = GD_ERR_BAD_PARAMETER; #endif } //GM_Printf( "bootblock.magic_id = 0x%08x\n", bootblock.magic_id ); //GM_Printf( "bootblock.image_words = 0x%08x\n", bootblock.image_words ); //GM_Printf( "bootblock.target_address = 0x%08x\n", bootblock.target_address ); //GM_Printf( "bootblock.start_address = 0x%08x\n", bootblock.start_address ); //for( index=0; bootblock.register_defs[index].address != 0x00000000; index++ ) //{ // GM_Printf( "bootblock.register_defs[%d] = 0x%08x:0x%08x\n", index, bootblock.register_defs[index].address, bootblock.register_defs[index].data ); //} if( status == GD_OK ) { if( ( bootblock.magic_id == GD_SYS_MAGIC_ID_SMARTMPEG ) || ( bootblock.magic_id == GD_SYS_MAGIC_ID_SMARTMPEG_E1 ) || ( bootblock.magic_id == GD_SYS_MAGIC_ID_SMARTMPEG_E2 ) || ( bootblock.magic_id == GD_SYS_MAGIC_ID_SMARTMPEG_L1 ) || ( bootblock.magic_id == GD_SYS_MAGIC_ID_SMARTMPEG_L2 ) || ( bootblock.magic_id == GD_SYS_MAGIC_ID_SMARTMPEG_C1 ) || ( bootblock.magic_id == GD_SYS_MAGIC_ID_SMARTMPEG_C2 ) || ( bootblock.magic_id == GD_SYS_MAGIC_ID_SMARTMPEG_C4 ) || ( bootblock.magic_id == GD_SYS_MAGIC_ID_SMARTMPEG_M1 ) || ( bootblock.magic_id == GD_SYS_MAGIC_ID_SMARTMPEG_M2 ) || ( bootblock.magic_id == GD_SYS_MAGIC_ID_SMARTMPEG_M4 ) || ( bootblock.magic_id == GD_SYS_MAGIC_ID_SMARTMPEG_G1 ) || ( bootblock.magic_id == GD_SYS_MAGIC_ID_SMARTMPEG_G2 ) || ( bootblock.magic_id == GD_SYS_MAGIC_ID_SMARTMPEG_G4 ) ) { // search for the termination of register/value pairs for( index=0; bootblock.register_defs[index].address != 0x00000000; index++ ) ; u32words = 4 + ( index * ( sizeof(GD_SYS_BOOT_REG_S)/sizeof(U32) ) ) + 1; // calculate the required size in bytes for the // boot image plus the leading boot block information // containing the register/value pair settings u32words += bootblock.image_words; #if defined(SMARTMPEG_C) || defined(SMARTMPEG_M) || defined(SMARTMPEG_D) || defined(GK6105S) || defined(GK6106) if( device == GD_SYS_BOOT_DEVICE_SFLASH ) { address = u32words * sizeof(U32); } else { address = ( u32words * sizeof(U32) ) / sizeof(U16); } #else // SMARTMPEG, SMARTMPEG-L, SMARTMPEG-E address = ( u32words * sizeof(U32) ) / sizeof(U16); #endif status = flash_get_sector( handle, address, §or ); *sectors = sector + 1; } else { u32words = 0; *sectors = 0; } } } flash_close( &handle ); if( status != GD_OK ) { u32words = 0; *sectors = 0; } //GM_Printf( "first free (s)flash address = %d\n", address ); //GM_Printf( "used boot image sectors = %d\n", *sectors ); return( status ); }
int update_fw(const Value *fw_file, const Value *ec_file, int force) { int res = -EINVAL; struct flash_device *img, *spi, *ec; size_t size; char *fwid; char cur_part = vboot_get_mainfw_act(); char *version = fdt_read_string("firmware-version"); if (!version) { ALOGW("Cannot read firmware version from FDT\n"); return -EIO; } ALOGD("Running firmware: %s / partition %c\n", version, cur_part); img = flash_open("file", fw_file); if (!img) goto out_free; fwid = reinterpret_cast<char*>(fmap_read_section(img, "RW_FWID_A", &size, NULL)); if (!fwid) { ALOGD("Cannot find firmware image version\n"); goto out_close_img; } /* TODO: force update if keyblock does not match */ if (!strncmp(version, fwid, size) && !force) { ALOGI("Firmware already up-to-date: %s\n", version); free(fwid); res = 0; goto out_close_img; } free(fwid); ec = flash_open("ec", NULL); if (!ec) goto out_close_img; spi = flash_open("spi", NULL); if (!spi) goto out_close_ec; if (0) res = update_ap_fw(spi, img); if (cur_part == 'R') /* Recovery mode */ res = update_recovery_fw(spi, ec, img, ec_file); else /* Normal mode */ res = update_rw_fw(spi, img, cur_part); if (!res) /* successful update : record it */ res = 1; flash_close(spi); out_close_ec: flash_close(ec); out_close_img: flash_close(img); out_free: free(version); return res; }
bool emu_start(unsigned int port_gdb, unsigned int port_rdbg, const char *snapshot_file) { gui_busy_raii gui_busy; if(snapshot_file) { // Open snapshot size_t snapshot_size = gzip_filesize(snapshot_file); if(snapshot_size < sizeof(emu_snapshot)) return false; FILE *fp = fopen_utf8(snapshot_file, "rb"); if(!fp) return false; int dupfd = dup(fileno(fp)); fclose(fp); fp = nullptr; // gzdopen takes ownership of the fd gzFile gzf = gzdopen(dupfd, "r"); if(!gzf) { close(dupfd); return false; } auto snapshot = (struct emu_snapshot *) malloc(snapshot_size); if(!snapshot) { gzclose(gzf); return false; } if((size_t) gzread(gzf, snapshot, snapshot_size) != snapshot_size) { gzclose(gzf); free(snapshot); return false; } gzclose(gzf); //sched_reset(); sched.items[SCHED_THROTTLE].clock = CLOCK_27M; sched.items[SCHED_THROTTLE].proc = throttle_interval_event; // TODO: Max length path_boot1 = std::string(snapshot->path_boot1); path_flash = std::string(snapshot->path_flash); // TODO: Pass snapshot_size to flash_resume to avoid reading after the buffer // Resume components uint32_t sdram_size; if(snapshot->sig != SNAPSHOT_SIG || snapshot->version != SNAPSHOT_VER || !flash_resume(snapshot) || !flash_read_settings(&sdram_size, &product, &features, &asic_user_flags) || !cpu_resume(snapshot) || !memory_resume(snapshot) || !sched_resume(snapshot)) { emu_cleanup(); free(snapshot); return false; } free(snapshot); } else { if (!flash_open(path_flash.c_str())) return false; uint32_t sdram_size; flash_read_settings(&sdram_size, &product, &features, &asic_user_flags); flash_set_bootorder(boot_order); if(!memory_initialize(sdram_size)) { emu_cleanup(); return false; } } if(debug_on_start) cpu_events |= EVENT_DEBUG_STEP; uint8_t *rom = mem_areas[0].ptr; memset(rom, -1, 0x80000); for (int i = 0x00000; i < 0x80000; i += 4) RAM_FLAGS(&rom[i]) = RF_READ_ONLY; /* Load the ROM */ FILE *f = fopen_utf8(path_boot1.c_str(), "rb"); if (!f) { gui_perror(path_boot1.c_str()); emu_cleanup(); return false; } (void)fread(rom, 1, 0x80000, f); fclose(f); #ifndef NO_TRANSLATION if(!translate_init()) { gui_debug_printf("Could not init JIT, disabling translation.\n"); do_translate = false; } #endif addr_cache_init(); throttle_timer_on(); if(port_gdb) gdbstub_init(port_gdb); if(port_rdbg) rdebug_bind(port_rdbg); usblink_queue_reset(); if(!snapshot_file) emu_reset(); return true; }