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.
 
 
 
 
 
 

105 lines
2.8 KiB

  1. /*
  2. #####ECOSGPLCOPYRIGHTBEGIN####
  3. ## -------------------------------------------
  4. ## This file is part of eCos, the Embedded Configurable Operating System.
  5. ## Copyright (C) 2008 Øyvind Harboe
  6. ##
  7. ## eCos is free software; you can redistribute it and/or modify it under
  8. ## the terms of the GNU General Public License as published by the Free
  9. ## Software Foundation; either version 2 or (at your option) any later version.
  10. ##
  11. ## eCos is distributed in the hope that it will be useful, but WITHOUT ANY
  12. ## WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  14. ## for more details.
  15. ##
  16. ## You should have received a copy of the GNU General Public License along
  17. ## with eCos; if not, write to the Free Software Foundation, Inc.,
  18. ## 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
  19. ##
  20. ## As a special exception, if other files instantiate templates or use macros
  21. ## or inline functions from this file, or you compile this file and link it
  22. ## with other works to produce a work based on this file, this file does not
  23. ## by itself cause the resulting work to be covered by the GNU General Public
  24. ## License. However the source code for this file must still be made available
  25. ## in accordance with section (3) of the GNU General Public License.
  26. ##
  27. ## This exception does not invalidate any other reasons why a work based on
  28. ## this file might be covered by the GNU General Public License.
  29. ## -------------------------------------------
  30. #####ECOSGPLCOPYRIGHTEND####
  31. */
  32. #include <string.h>
  33. #define _FLASH_PRIVATE_
  34. #include <cyg/io/flash.h>
  35. int myprintf(char *format, ...)
  36. {
  37. return 0;
  38. }
  39. extern char _start_bss_clear;
  40. extern char __bss_end__;
  41. int init()
  42. {
  43. // set up runtime environment
  44. char *t;
  45. for (t=&_start_bss_clear; t<&__bss_end__; t++)
  46. {
  47. *t=0;
  48. }
  49. return flash_init((_printf *)&myprintf);
  50. }
  51. int checkFlash(void *addr, int len)
  52. {
  53. // Return error for illegal addresses
  54. if ((addr<flash_info.start)||(addr>flash_info.end))
  55. return FLASH_ERR_INVALID;
  56. if ((((cyg_uint8 *)addr)+len)>(cyg_uint8 *)flash_info.end)
  57. return FLASH_ERR_INVALID;
  58. return FLASH_ERR_OK;
  59. }
  60. int erase(void *address, int len)
  61. {
  62. int retval;
  63. void *failAddress;
  64. retval=checkFlash(address, len);
  65. if (retval!=0)
  66. return retval;
  67. retval=init();
  68. if (retval!=0)
  69. return retval;
  70. return flash_erase(address, len, &failAddress);
  71. }
  72. extern char _end;
  73. // Data follows immediately after program, long word aligned.
  74. int program(void *buffer, void *address, int len)
  75. {
  76. int retval;
  77. void *failAddress;
  78. retval=checkFlash(address, len);
  79. if (retval!=0)
  80. return retval;
  81. retval=init();
  82. if (retval!=0)
  83. return retval;
  84. //int flash_program(void *_addr, void *_data, int len, void **err_addr)
  85. return flash_program(address, buffer, len, &failAddress);
  86. }