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.

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