You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

image.c 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #include "dev.h"
  2. #include "buffer.h"
  3. #include "load_buffer.h"
  4. #include "image.h"
  5. static struct image images[0] __image_start;
  6. static struct image images_end[0] __image_end;
  7. /*
  8. * Print all images
  9. *
  10. */
  11. void print_images ( void ) {
  12. struct image *image;
  13. for ( image = images ; image < images_end ; image++ ) {
  14. printf ( "%s ", image->name );
  15. }
  16. }
  17. #if 0
  18. /*
  19. * Identify the image format
  20. *
  21. */
  22. static struct image * identify_image ( physaddr_t start, physaddr_t len,
  23. void **context ) {
  24. struct image *image;
  25. for ( image = images ; image < images_end ; image++ ) {
  26. if ( image->probe ( start, len, context ) )
  27. return image;
  28. }
  29. return NULL;
  30. }
  31. /*
  32. * Load an image into memory at a location determined by the image
  33. * format
  34. *
  35. */
  36. int autoload ( struct dev *dev, struct image **image, void **context ) {
  37. struct buffer buffer;
  38. int rc = 0;
  39. /* Prepare the load buffer */
  40. if ( ! init_load_buffer ( &buffer ) ) {
  41. DBG ( "IMAGE could not initialise load buffer\n" );
  42. goto out;
  43. }
  44. /* Load the image into the load buffer */
  45. if ( ! load ( dev, &buffer ) ) {
  46. DBG ( "IMAGE could not load image\n" );
  47. goto out_free;
  48. }
  49. /* Shrink the load buffer */
  50. trim_load_buffer ( &buffer );
  51. /* Identify the image type */
  52. *image = identify_image ( buffer.start, buffer.fill, context );
  53. if ( ! *image ) {
  54. DBG ( "IMAGE could not identify image type\n" );
  55. goto out_free;
  56. }
  57. /* Move the image into the target location */
  58. if ( ! (*image)->load ( buffer.start, buffer.fill, *context ) ) {
  59. DBG ( "IMAGE could not move to target location\n" );
  60. goto out_free;
  61. }
  62. /* Return success */
  63. rc = 1;
  64. out_free:
  65. /* Free the load buffer */
  66. done_load_buffer ( &buffer );
  67. out:
  68. return rc;
  69. }
  70. #endif