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.
 
 
 
 
 
 

85 lines
3.3 KiB

  1. /***************************************************************************
  2. * Copyright (C) 2005 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 FLASH_H
  21. #define FLASH_H
  22. #include "target.h"
  23. #include "image.h"
  24. #define FLASH_MAX_ERROR_STR (128)
  25. typedef struct flash_sector_s
  26. {
  27. u32 offset;
  28. u32 size;
  29. int is_erased;
  30. int is_protected;
  31. } flash_sector_t;
  32. struct flash_bank_s;
  33. typedef struct flash_driver_s
  34. {
  35. char *name;
  36. int (*register_commands)(struct command_context_s *cmd_ctx);
  37. int (*flash_bank_command)(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank);
  38. int (*erase)(struct flash_bank_s *bank, int first, int last);
  39. int (*protect)(struct flash_bank_s *bank, int set, int first, int last);
  40. int (*write)(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count);
  41. int (*probe)(struct flash_bank_s *bank);
  42. int (*erase_check)(struct flash_bank_s *bank);
  43. int (*protect_check)(struct flash_bank_s *bank);
  44. int (*info)(struct flash_bank_s *bank, char *buf, int buf_size);
  45. } flash_driver_t;
  46. typedef struct flash_bank_s
  47. {
  48. target_t *target;
  49. flash_driver_t *driver;
  50. void *driver_priv;
  51. u32 base;
  52. u32 size;
  53. int chip_width;
  54. int bus_width;
  55. int num_sectors;
  56. flash_sector_t *sectors;
  57. struct flash_bank_s *next;
  58. } flash_bank_t;
  59. extern int flash_register_commands(struct command_context_s *cmd_ctx);
  60. extern int flash_init(struct command_context_s *cmd_ctx);
  61. extern int flash_erase(target_t *target, u32 addr, u32 length);
  62. extern int flash_write(target_t *target, image_t *image, u32 *image_size, char **error, u32 *failed);
  63. extern flash_bank_t *get_flash_bank_by_num(int num);
  64. extern flash_bank_t *get_flash_bank_by_addr(target_t *target, u32 addr);
  65. #define ERROR_FLASH_BANK_INVALID (-900)
  66. #define ERROR_FLASH_SECTOR_INVALID (-901)
  67. #define ERROR_FLASH_OPERATION_FAILED (-902)
  68. #define ERROR_FLASH_DST_OUT_OF_BANK (-903)
  69. #define ERROR_FLASH_DST_BREAKS_ALIGNMENT (-904)
  70. #define ERROR_FLASH_BUSY (-905)
  71. #define ERROR_FLASH_SECTOR_NOT_ERASED (-906)
  72. #define ERROR_FLASH_BANK_NOT_PROBED (-907)
  73. #endif /* FLASH_H */