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.
 
 
 
 
 
 

108 lines
3.3 KiB

  1. /***************************************************************************
  2. * Copyright (C) 2007 by Pavel Chromy *
  3. * chromy@asix.cz *
  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. #include "platform.h"
  21. #include <flash/nor/ocl.h>
  22. #include "dcc.h"
  23. #include "samflash.h"
  24. #define BUFSIZE 1024 /* words, i.e. 4 KiB */
  25. uint32 buffer[1024];
  26. void cmd_flash(uint32 cmd)
  27. {
  28. unsigned int len;
  29. uint32 adr;
  30. uint32 chksum;
  31. unsigned int bi; /* buffer index */
  32. unsigned int bi_start; /* receive start mark */
  33. unsigned int bi_end; /* receive end mark */
  34. unsigned int ofs;
  35. int pagenum;
  36. int result;
  37. adr = dcc_rd();
  38. len = cmd&0xffff;
  39. ofs = adr%flash_page_size;
  40. bi_start = ofs/4;
  41. bi_end = (ofs + len + 3)/4;
  42. if (bi_end > BUFSIZE) {
  43. dcc_wr(OCL_BUFF_OVER);
  44. return;
  45. }
  46. chksum = OCL_CHKS_INIT;
  47. for (bi = 0; bi < bi_end; bi++) chksum^=buffer[bi]=dcc_rd();
  48. if (dcc_rd() != chksum) {
  49. dcc_wr(OCL_CHKS_FAIL);
  50. return;
  51. }
  52. /* fill in unused positions with unprogrammed values */
  53. for (bi = 0; bi < bi_start; bi++) buffer[bi]=0xffffffff;
  54. for (bi = bi_end; bi%flash_page_size; bi++) buffer[bi]=0xffffffff;
  55. result = 0;
  56. pagenum = adr/flash_page_size;
  57. for (bi = 0; bi < bi_end; bi += flash_page_size/4) {
  58. result = flash_page_program(buffer + bi, pagenum++);
  59. if (result) break;
  60. }
  61. /* verify written data */
  62. if (!result) result = flash_verify(adr, len, ((uint8 *)buffer) + ofs);
  63. dcc_wr(OCL_CMD_DONE | result);
  64. }
  65. int main (void)
  66. {
  67. uint32 cmd;
  68. for (;;) {
  69. cmd = dcc_rd();
  70. switch (cmd&OCL_CMD_MASK) {
  71. case OCL_PROBE:
  72. dcc_wr(OCL_CMD_DONE | flash_init());
  73. dcc_wr(0x100000); /* base */
  74. dcc_wr(flash_page_count*flash_page_size); /* size */
  75. dcc_wr(1); /* num_sectors */
  76. dcc_wr(4096 | ((unsigned long) flash_page_size << 16)); /* buflen and bufalign */
  77. break;
  78. case OCL_ERASE_ALL:
  79. dcc_wr(OCL_CMD_DONE | flash_erase_all());
  80. break;
  81. case OCL_FLASH_BLOCK:
  82. cmd_flash(cmd);
  83. break;
  84. default:
  85. /* unknown command */
  86. dcc_wr(OCL_CMD_ERR);
  87. break;
  88. }
  89. }
  90. return(0); /* we shall never get here, just to supress compiler warning */
  91. }