示例#1
0
文件: gui_read.c 项目: pelrun/CHDK
//---------------------------------------------------------
// PURPOSE:   Bind module symbols with chdk.
//		Required function
// PARAMETERS: pointer to chdk list of export
// RETURN VALUE: 1 error, 0 ok
//---------------------------------------------------------
int _module_loader( unsigned int* chdk_export_list )
{
    if ( chdk_export_list[0] != EXPORTLIST_MAGIC_NUMBER )
        return 1;

    if ( !API_VERSION_MATCH_REQUIREMENT( gui_version.common_api, 1, 0 ) )
        return 1;
    if ( !API_VERSION_MATCH_REQUIREMENT( conf.api_version, 2, 0 ) )
        return 1;

    return 0;
}
示例#2
0
文件: module_menu.c 项目: pelrun/CHDK
//---------------------------------------------------------
// PURPOSE:   Bind module symbols with chdk. 
//		Required function
// PARAMETERS: pointer to chdk list of export
// RETURN VALUE: 1 error, 0 ok
//---------------------------------------------------------
int _module_loader( unsigned int* chdk_export_list )
{
	if ( chdk_export_list[0] != EXPORTLIST_MAGIC_NUMBER )
    	return 1;

	// If "gui_menu_run_fltmodule" is 0, then menu system is changed
	if ( module_find_symbol_address(MODULESYM_GUI_MENU_RUN_FLTMODULE) == 0)
		return 1;

    if ( !API_VERSION_MATCH_REQUIREMENT( gui_version.menu_api, 1, 0 ) )
	  return 1;

	return 0;
}
示例#3
0
struct flat_hdr* module_preload(const char *name, _version_t ver)
{
    module_fd = -1;
    module_filename = name;
    flat_buf = 0;
    buf_load = 0;

    char path[60];
    struct flat_hdr flat;
    int size_flat;

    flat_module_path_make(path,module_filename);

    module_fd = open( path, O_RDONLY, 0777 );
    if ( module_fd <=0 )
    {
        moduleload_error("file not found",0);
        return 0;
    }

    // @tsv TODO - compare loaded with requested
    b_read( module_fd, (char*)&flat, sizeof(flat) );

    if ( flat.rev!=FLAT_VERSION || memcmp( flat.magic, FLAT_MAGIC_NUMBER, 4) )
    {
        moduleload_error("bad magicnum", 0);
        return 0;
    }

    size_flat = flat.reloc_start;

    flat_buf = (struct flat_hdr*)malloc( size_flat );
    if ( !flat_buf ) 
    {
        moduleload_error("malloc",0);
        return 0;
    }

    module_log_load(module_filename,flat_buf);

    if ( 0!= lseek(module_fd, 0, SEEK_SET) )
    {
        moduleload_error("read",0);
        return 0;
    }
    if ( size_flat != b_read(module_fd, (char*)flat_buf, size_flat) )
    {
        moduleload_error("read",0);
        return 0;
    }

    // Module info checks

    struct ModuleInfo *mod_info = flat_buf->_module_info = (struct ModuleInfo*)((unsigned int)flat_buf+flat_buf->_module_info_offset);

    if ( mod_info->magicnum != MODULEINFO_V1_MAGICNUM || mod_info->sizeof_struct != sizeof(struct ModuleInfo) )
    {
        moduleload_error("Malformed module info", 0 );
        return 0;
    }

    if ( mod_info->chdk_required_branch && mod_info->chdk_required_branch != CURRENT_CHDK_BRANCH )
    {
        moduleload_error("require different CHDK branch",0 );
        return 0;
    }

    if ( mod_info->chdk_required_ver > CHDK_BUILD_NUM) 
    {
        moduleload_error("require CHDK%05d", mod_info->chdk_required_ver);
        return 0;
    }

    if ( mod_info->chdk_required_platfid && mod_info->chdk_required_platfid != conf.platformid )
    {
        moduleload_error("require platfid %d", mod_info->chdk_required_platfid);
        return 0;
    }

	if ( !API_VERSION_MATCH_REQUIREMENT( mod_info->module_version, ver ) )
    {
        moduleload_error("incorrect module version", 0);
		return 0;
    }

	if ( !API_VERSION_MATCH_REQUIREMENT( conf.api_version, mod_info->conf_ver ) )
    {
        moduleload_error("incorrect CONF version", 0);
		return 0;
    }

	if ( !API_VERSION_MATCH_REQUIREMENT( camera_screen.api_version, mod_info->cam_screen_ver ) )
    {
        moduleload_error("incorrect CAM SCREEN version", 0);
		return 0;
    }

	if ( !API_VERSION_MATCH_REQUIREMENT( camera_sensor.api_version, mod_info->cam_sensor_ver ) )
    {
        moduleload_error("incorrect CAM SENSOR version", 0);
		return 0;
    }

	if ( !API_VERSION_MATCH_REQUIREMENT( camera_info.api_version, mod_info->cam_info_ver ) )
    {
        moduleload_error("incorrect CAM INFO version", 0);
		return 0;
    }

    // Make relocations

    int reloc_size = flat.import_start - flat.reloc_start;
    int reloc_count = reloc_size/sizeof(uint32_t);
    int import_size = flat.file_size - flat.import_start;
    int import_count = import_size/sizeof(uint32_t);

    if (!alloc_reloc_buf(reloc_size, import_size))
        return 0;
    if ( !module_do_action( "reloc", flat.reloc_start, reloc_count, reloc_size, module_do_relocations ) )
        return 0;
    if ( !module_do_action( "export", flat.import_start, import_count, import_size, module_do_imports ) )
        return 0;

    b_close( module_fd );
    module_fd = -1;

    // TODO these could be changed to operate on affected address ranges only
    // after relocating but before attempting to execute loaded code
    // clean data cache to ensure code is in main memory
    dcache_clean_all();
    // then flush instruction cache to ensure no addresses containing new code are cached
    icache_flush_all();

    return flat_buf;
}