|  | @@ -157,6 +157,32 @@ int image_set_cmdline ( struct image *image, const char *cmdline ) {
 | 
		
	
		
			
			| 157 | 157 |  	return 0;
 | 
		
	
		
			
			| 158 | 158 |  }
 | 
		
	
		
			
			| 159 | 159 |  
 | 
		
	
		
			
			|  | 160 | +/**
 | 
		
	
		
			
			|  | 161 | + * Determine image type
 | 
		
	
		
			
			|  | 162 | + *
 | 
		
	
		
			
			|  | 163 | + * @v image		Executable image
 | 
		
	
		
			
			|  | 164 | + * @ret rc		Return status code
 | 
		
	
		
			
			|  | 165 | + */
 | 
		
	
		
			
			|  | 166 | +static int image_probe ( struct image *image ) {
 | 
		
	
		
			
			|  | 167 | +	struct image_type *type;
 | 
		
	
		
			
			|  | 168 | +	int rc;
 | 
		
	
		
			
			|  | 169 | +
 | 
		
	
		
			
			|  | 170 | +	/* Try each type in turn */
 | 
		
	
		
			
			|  | 171 | +	for_each_table_entry ( type, IMAGE_TYPES ) {
 | 
		
	
		
			
			|  | 172 | +		if ( ( rc = type->probe ( image ) ) == 0 ) {
 | 
		
	
		
			
			|  | 173 | +			image->type = type;
 | 
		
	
		
			
			|  | 174 | +			DBGC ( image, "IMAGE %s is %s\n",
 | 
		
	
		
			
			|  | 175 | +			       image->name, type->name );
 | 
		
	
		
			
			|  | 176 | +			break;
 | 
		
	
		
			
			|  | 177 | +		}
 | 
		
	
		
			
			|  | 178 | +		DBGC ( image, "IMAGE %s is not %s: %s\n", image->name,
 | 
		
	
		
			
			|  | 179 | +		       type->name, strerror ( rc ) );
 | 
		
	
		
			
			|  | 180 | +	}
 | 
		
	
		
			
			|  | 181 | +
 | 
		
	
		
			
			|  | 182 | +	DBGC ( image, "IMAGE %s format not recognised\n", image->name );
 | 
		
	
		
			
			|  | 183 | +	return -ENOTSUP;
 | 
		
	
		
			
			|  | 184 | +}
 | 
		
	
		
			
			|  | 185 | +
 | 
		
	
		
			
			| 160 | 186 |  /**
 | 
		
	
		
			
			| 161 | 187 |   * Register executable image
 | 
		
	
		
			
			| 162 | 188 |   *
 | 
		
	
	
		
			
			|  | @@ -189,6 +215,14 @@ int register_image ( struct image *image ) {
 | 
		
	
		
			
			| 189 | 215 |  	       image->name, user_to_phys ( image->data, 0 ),
 | 
		
	
		
			
			| 190 | 216 |  	       user_to_phys ( image->data, image->len ) );
 | 
		
	
		
			
			| 191 | 217 |  
 | 
		
	
		
			
			|  | 218 | +	/* Try to detect image type, if applicable.  Ignore failures,
 | 
		
	
		
			
			|  | 219 | +	 * since we expect to handle some unrecognised images
 | 
		
	
		
			
			|  | 220 | +	 * (e.g. kernel initrds, multiboot modules, random files
 | 
		
	
		
			
			|  | 221 | +	 * provided via our EFI virtual filesystem, etc).
 | 
		
	
		
			
			|  | 222 | +	 */
 | 
		
	
		
			
			|  | 223 | +	if ( ! image->type )
 | 
		
	
		
			
			|  | 224 | +		image_probe ( image );
 | 
		
	
		
			
			|  | 225 | +
 | 
		
	
		
			
			| 192 | 226 |  	return 0;
 | 
		
	
		
			
			| 193 | 227 |  }
 | 
		
	
		
			
			| 194 | 228 |  
 | 
		
	
	
		
			
			|  | @@ -226,36 +260,6 @@ struct image * find_image ( const char *name ) {
 | 
		
	
		
			
			| 226 | 260 |  	return NULL;
 | 
		
	
		
			
			| 227 | 261 |  }
 | 
		
	
		
			
			| 228 | 262 |  
 | 
		
	
		
			
			| 229 |  | -/**
 | 
		
	
		
			
			| 230 |  | - * Determine image type
 | 
		
	
		
			
			| 231 |  | - *
 | 
		
	
		
			
			| 232 |  | - * @v image		Executable image
 | 
		
	
		
			
			| 233 |  | - * @ret rc		Return status code
 | 
		
	
		
			
			| 234 |  | - */
 | 
		
	
		
			
			| 235 |  | -int image_probe ( struct image *image ) {
 | 
		
	
		
			
			| 236 |  | -	struct image_type *type;
 | 
		
	
		
			
			| 237 |  | -	int rc;
 | 
		
	
		
			
			| 238 |  | -
 | 
		
	
		
			
			| 239 |  | -	/* Succeed if we already have a type */
 | 
		
	
		
			
			| 240 |  | -	if ( image->type )
 | 
		
	
		
			
			| 241 |  | -		return 0;
 | 
		
	
		
			
			| 242 |  | -
 | 
		
	
		
			
			| 243 |  | -	/* Try each type in turn */
 | 
		
	
		
			
			| 244 |  | -	for_each_table_entry ( type, IMAGE_TYPES ) {
 | 
		
	
		
			
			| 245 |  | -		if ( ( rc = type->probe ( image ) ) == 0 ) {
 | 
		
	
		
			
			| 246 |  | -			image->type = type;
 | 
		
	
		
			
			| 247 |  | -			DBGC ( image, "IMAGE %s is %s\n",
 | 
		
	
		
			
			| 248 |  | -			       image->name, type->name );
 | 
		
	
		
			
			| 249 |  | -			return 0;
 | 
		
	
		
			
			| 250 |  | -		}
 | 
		
	
		
			
			| 251 |  | -		DBGC ( image, "IMAGE %s is not %s: %s\n", image->name,
 | 
		
	
		
			
			| 252 |  | -		       type->name, strerror ( rc ) );
 | 
		
	
		
			
			| 253 |  | -	}
 | 
		
	
		
			
			| 254 |  | -
 | 
		
	
		
			
			| 255 |  | -	DBGC ( image, "IMAGE %s format not recognised\n", image->name );
 | 
		
	
		
			
			| 256 |  | -	return -ENOEXEC;
 | 
		
	
		
			
			| 257 |  | -}
 | 
		
	
		
			
			| 258 |  | -
 | 
		
	
		
			
			| 259 | 263 |  /**
 | 
		
	
		
			
			| 260 | 264 |   * Execute image
 | 
		
	
		
			
			| 261 | 265 |   *
 | 
		
	
	
		
			
			|  | @@ -288,9 +292,11 @@ int image_exec ( struct image *image ) {
 | 
		
	
		
			
			| 288 | 292 |  	 */
 | 
		
	
		
			
			| 289 | 293 |  	current_image = image_get ( image );
 | 
		
	
		
			
			| 290 | 294 |  
 | 
		
	
		
			
			| 291 |  | -	/* Check that this image can be selected for execution */
 | 
		
	
		
			
			| 292 |  | -	if ( ( rc = image_select ( image ) ) != 0 )
 | 
		
	
		
			
			|  | 295 | +	/* Check that this image can be executed */
 | 
		
	
		
			
			|  | 296 | +	if ( ! ( image->type && image->type->exec ) ) {
 | 
		
	
		
			
			|  | 297 | +		rc = -ENOEXEC;
 | 
		
	
		
			
			| 293 | 298 |  		goto err;
 | 
		
	
		
			
			|  | 299 | +	}
 | 
		
	
		
			
			| 294 | 300 |  
 | 
		
	
		
			
			| 295 | 301 |  	/* Check that image is trusted (if applicable) */
 | 
		
	
		
			
			| 296 | 302 |  	if ( require_trusted_images && ! ( image->flags & IMAGE_TRUSTED ) ) {
 | 
		
	
	
		
			
			|  | @@ -382,8 +388,8 @@ int image_replace ( struct image *replacement ) {
 | 
		
	
		
			
			| 382 | 388 |  	}
 | 
		
	
		
			
			| 383 | 389 |  
 | 
		
	
		
			
			| 384 | 390 |  	/* Check that the replacement image can be executed */
 | 
		
	
		
			
			| 385 |  | -	if ( ( rc = image_probe ( replacement ) ) != 0 )
 | 
		
	
		
			
			| 386 |  | -		return rc;
 | 
		
	
		
			
			|  | 391 | +	if ( ! ( replacement->type && replacement->type->exec ) )
 | 
		
	
		
			
			|  | 392 | +		return -ENOEXEC;
 | 
		
	
		
			
			| 387 | 393 |  
 | 
		
	
		
			
			| 388 | 394 |  	/* Clear any existing replacement */
 | 
		
	
		
			
			| 389 | 395 |  	image_put ( image->replacement );
 | 
		
	
	
		
			
			|  | @@ -404,16 +410,13 @@ int image_replace ( struct image *replacement ) {
 | 
		
	
		
			
			| 404 | 410 |   */
 | 
		
	
		
			
			| 405 | 411 |  int image_select ( struct image *image ) {
 | 
		
	
		
			
			| 406 | 412 |  	struct image *tmp;
 | 
		
	
		
			
			| 407 |  | -	int rc;
 | 
		
	
		
			
			| 408 | 413 |  
 | 
		
	
		
			
			| 409 | 414 |  	/* Unselect all other images */
 | 
		
	
		
			
			| 410 | 415 |  	for_each_image ( tmp )
 | 
		
	
		
			
			| 411 | 416 |  		tmp->flags &= ~IMAGE_SELECTED;
 | 
		
	
		
			
			| 412 | 417 |  
 | 
		
	
		
			
			| 413 | 418 |  	/* Check that this image can be executed */
 | 
		
	
		
			
			| 414 |  | -	if ( ( rc = image_probe ( image ) ) != 0 )
 | 
		
	
		
			
			| 415 |  | -		return rc;
 | 
		
	
		
			
			| 416 |  | -	if ( ! image->type->exec )
 | 
		
	
		
			
			|  | 419 | +	if ( ! ( image->type && image->type->exec ) )
 | 
		
	
		
			
			| 417 | 420 |  		return -ENOEXEC;
 | 
		
	
		
			
			| 418 | 421 |  
 | 
		
	
		
			
			| 419 | 422 |  	/* Mark image as selected */
 | 
		
	
	
		
			
			|  | @@ -472,9 +475,7 @@ int image_pixbuf ( struct image *image, struct pixel_buffer **pixbuf ) {
 | 
		
	
		
			
			| 472 | 475 |  	int rc;
 | 
		
	
		
			
			| 473 | 476 |  
 | 
		
	
		
			
			| 474 | 477 |  	/* Check that this image can be used to create a pixel buffer */
 | 
		
	
		
			
			| 475 |  | -	if ( ( rc = image_probe ( image ) ) != 0 )
 | 
		
	
		
			
			| 476 |  | -		return rc;
 | 
		
	
		
			
			| 477 |  | -	if ( ! image->type->pixbuf )
 | 
		
	
		
			
			|  | 478 | +	if ( ! ( image->type && image->type->pixbuf ) )
 | 
		
	
		
			
			| 478 | 479 |  		return -ENOTSUP;
 | 
		
	
		
			
			| 479 | 480 |  
 | 
		
	
		
			
			| 480 | 481 |  	/* Try creating pixel buffer */
 |