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.
 
 
 
 
 
 

114 lines
3.7 KiB

  1. /***************************************************************************
  2. * Copyright (C) 2007 by Dominic Rath *
  3. * Dominic.Rath@gmx.de *
  4. * *
  5. * This program is free software; you can redistribute it and/or modify *
  6. * it under the terms of the GNU General Public License as published by *
  7. * the Free Software Foundation; either version 2 of the License, or *
  8. * (at your option) any later version. *
  9. * *
  10. * This program is distributed in the hope that it will be useful, *
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  13. * GNU General Public License for more details. *
  14. * *
  15. * You should have received a copy of the GNU General Public License *
  16. * along with this program; if not, write to the *
  17. * Free Software Foundation, Inc., *
  18. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  19. ***************************************************************************/
  20. #ifndef IMAGE_H
  21. #define IMAGE_H
  22. #ifdef HAVE_CONFIG_H
  23. #include "config.h"
  24. #endif
  25. #ifdef HAVE_ELF_H
  26. #include <elf.h>
  27. #endif
  28. #include "replacements.h"
  29. #include "fileio.h"
  30. #include "target.h"
  31. #define IMAGE_MAX_ERROR_STRING (256)
  32. #define IMAGE_MAX_SECTIONS (128)
  33. #define IMAGE_MEMORY_CACHE_SIZE (1024)
  34. typedef enum image_type
  35. {
  36. IMAGE_BINARY, /* plain binary */
  37. IMAGE_IHEX, /* intel hex-record format */
  38. IMAGE_MEMORY, /* target-memory pseudo-image */
  39. IMAGE_ELF, /* ELF binary */
  40. IMAGE_SRECORD, /* motorola s19 */
  41. IMAGE_BUILDER, /* when building a new image */
  42. } image_type_t;
  43. typedef struct image_section_s
  44. {
  45. u32 base_address;
  46. u32 size;
  47. int flags;
  48. void *private; /* private data */
  49. } image_section_t;
  50. typedef struct image_s
  51. {
  52. image_type_t type; /* image type (plain, ihex, ...) */
  53. void *type_private; /* type private data */
  54. int num_sections; /* number of sections contained in the image */
  55. image_section_t *sections; /* array of sections */
  56. int base_address_set; /* whether the image has a base address set (for relocation purposes) */
  57. int base_address; /* base address, if one is set */
  58. int start_address_set; /* whether the image has a start address (entry point) associated */
  59. u32 start_address; /* start address, if one is set */
  60. char error_str[IMAGE_MAX_ERROR_STRING];
  61. } image_t;
  62. typedef struct image_binary_s
  63. {
  64. fileio_t fileio;
  65. } image_binary_t;
  66. typedef struct image_ihex_s
  67. {
  68. fileio_t fileio;
  69. u8 *buffer;
  70. } image_ihex_t;
  71. typedef struct image_memory_s
  72. {
  73. target_t *target;
  74. u8 *cache;
  75. u32 cache_address;
  76. } image_memory_t;
  77. typedef struct fileio_elf_s
  78. {
  79. fileio_t fileio;
  80. Elf32_Ehdr *header;
  81. Elf32_Phdr *segments;
  82. u32 segment_count;
  83. u8 endianness;
  84. } image_elf_t;
  85. typedef struct image_mot_s
  86. {
  87. fileio_t fileio;
  88. u8 *buffer;
  89. } image_mot_t;
  90. extern int image_open(image_t *image, char *url, char *type_string);
  91. extern int image_read_section(image_t *image, int section, u32 offset, u32 size, u8 *buffer, u32 *size_read);
  92. extern int image_close(image_t *image);
  93. extern int image_add_section(image_t *image, u32 base, u32 size, int flags, u8 *data);
  94. #define ERROR_IMAGE_FORMAT_ERROR (-1400)
  95. #define ERROR_IMAGE_TYPE_UNKNOWN (-1401)
  96. #define ERROR_IMAGE_TEMPORARILY_UNAVAILABLE (-1402)
  97. #define ERROR_IMAGE_CHECKSUM (-1403)
  98. #endif /* IMAGE_H */