void fetcher_commit(fetcher_state_t *s, bool commit) { fetcher_cam_t *cam; cam = (fetcher_cam_t *) ker_shm_get( KER_FETCHER_PID, s->map.key); if( cam == NULL ) return; if( commit == true ) { ker_codemem_flush( cam->cm, KER_FETCHER_PID ); } else { ker_codemem_free( cam->cm ); } }
static int8_t request_new_module(sos_cam_t key, loader_cam_t *cam, uint8_t size, uint16_t saddr, uint8_t type) { cam->code_size = size; cam->fetcher.fetchtype = type; cam->fetcher.cm = ker_codemem_alloc( size * LOADER_SIZE_MULTIPLIER, CODEMEM_TYPE_EXECUTABLE); DEBUG_PID( KER_DFT_LOADER_PID, "request new module with size = %d\n", size * LOADER_SIZE_MULTIPLIER); if(cam->fetcher.cm == CODEMEM_INVALID) { return -ENOMEM; } if( fetcher_request( KER_DFT_LOADER_PID, key, (uint16_t)size * LOADER_SIZE_MULTIPLIER, saddr ) != SOS_OK ) { ker_codemem_free( cam->fetcher.cm ); return -ENOMEM; } block_protocol(); return SOS_OK; }
static void process_version_data( msg_version_data_t *v, uint16_t saddr ) { uint8_t i; for( i = 0; i < NUM_LOADER_PARAMS_ENTRIES + NUM_LOADER_MODULE_ENTRIES; i++ ) { sos_cam_t key = ker_cam_key( KER_DFT_LOADER_PID, i); loader_cam_t *cam; uint8_t type; uint8_t size; uint8_t ver; if( i < NUM_LOADER_PARAMS_ENTRIES) { size = (v->pam_size[i]); ver = (v->pam_ver[i]); type = FETCHTYPE_DATA; } else { size = (v->mod_size[i - NUM_LOADER_PARAMS_ENTRIES]); ver = (v->mod_ver[i - NUM_LOADER_PARAMS_ENTRIES]); type = FETCHTYPE_MODULE; } cam = ker_cam_lookup( key ); if( cam == NULL && size == 0 ) { // We cannot find entry and the size is zero // skip this slot continue; } if( cam == NULL ) { // we need to add a new module cam = (loader_cam_t*) ker_malloc(sizeof(loader_cam_t), KER_DFT_LOADER_PID); if( cam == NULL) { return; } if( ker_cam_add( key, cam ) != SOS_OK ) { ker_free( cam ); return; } } else { // we need to replace a module if( cam->version == ver ) { continue; } //! new version of module found... if( cam->fetcher.status != FETCHING_DONE ) { if( cam->fetcher.status == FETCHING_STARTED ) { st.blocked = 0; restartInterval( 0 ); } fetcher_cancel( KER_DFT_LOADER_PID, key ); ker_codemem_free(cam->fetcher.cm); } else /* if( cam->fetcher.status == FETCHING_DONE ) */ { ker_codemem_free(cam->fetcher.cm); } if( size == 0 ) { //! an rmmod case ker_cam_remove( key ); ker_free( cam ); continue; } //! an insmod case with cam } if( request_new_module( key, cam, size, saddr, type) != SOS_OK ) { ker_cam_remove( key ); ker_free( cam ); } else { // another insmod case cam->version = ver; // only do one fetching return; } } }