Port of flash_cc2531 to FreeBSD. This is likely more just include a wiringPi compatible library for FreeBSD. Any new files are BSD licensed and NOT GPLv3 license.
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
2.9 KiB

  1. /***********************************************************************
  2. Copyright © 2019 Jean Michault.
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <https://www.gnu.org/licenses/>.
  13. *************************************************************************/
  14. #include <wiringPi.h>
  15. #include <stdlib.h>
  16. #include <stdio.h>
  17. #include <stdbool.h>
  18. #include <string.h>
  19. #include <stdint.h>
  20. #include "CCDebugger.h"
  21. void writeHexLine(FILE * fic,uint8_t *buf, int len,int offset)
  22. {
  23. int i=0;
  24. for(i=0 ; i<len ; i++)
  25. if(buf[i] != 0xff) break;
  26. if(i==len) return;
  27. int sum=len+(offset&0xff)+((offset>>8)&0xff);
  28. fprintf(fic,":%02X%04X00",len,offset);
  29. for(int i=0 ; i<len;i++)
  30. {
  31. fprintf(fic,"%02X",buf[i]);
  32. sum += buf[i];
  33. }
  34. fprintf(fic,"%02X\n",(-sum)&0xff);
  35. }
  36. uint8_t buf1[1024];
  37. uint8_t buf2[1024];
  38. void read1k(int bank,uint16_t offset,uint8_t * buf)
  39. {
  40. // get FMAP
  41. uint8_t res = cc_exec2(0xE5, 0xC7);
  42. // select bank
  43. res = (res & 0xF8) | (bank & 0x07);
  44. res = cc_exec3(0x75, 0xC7, res); // MOV direct,#data
  45. // Setup DPTR
  46. cc_execi( 0x90, 0x8000+offset ); // MOV DPTR,#data16
  47. for(int i=0 ; i<1024 ;i++)
  48. {
  49. res = cc_exec ( 0xE0 ); // MOVX A,@DPTR
  50. buf[i] = res;
  51. res = cc_exec ( 0xA3 ); // INC DPTR
  52. }
  53. }
  54. int main(int argc,char **argv)
  55. {
  56. if( argc <2 ) { fprintf(stderr,"usage : %s outfile\n",argv[0]); exit(1); }
  57. FILE * ficout = fopen(argv[1],"w");
  58. if(!ficout) { fprintf(stderr," Can't open file %s.\n",argv[1]); exit(1); }
  59. // initialize GPIO ports
  60. cc_init(24,27,28);
  61. // enter debug mode
  62. cc_enter();
  63. // get ChipID :
  64. uint16_t ID;
  65. ID = cc_getChipID();
  66. printf(" ID = %04x.\n",ID);
  67. uint16_t offset=0;
  68. uint8_t bank=0;
  69. int progress=1;
  70. for( bank=0 ; bank<8 ; bank++)
  71. {
  72. printf(".");fflush(stdout);
  73. if(! (bank&1))
  74. {
  75. uint8_t sum=2+4+(bank/2);
  76. fprintf(ficout,":02000004%04X%02X\n",bank/2,(-sum)&255 );
  77. }
  78. offset=0;
  79. int len=0;
  80. uint8_t buf[17];
  81. for ( uint16_t i=0 ; i<32 ; i++ )
  82. {
  83. do
  84. {
  85. read1k(bank,i*1024, buf1);
  86. read1k(bank,i*1024, buf2);
  87. } while(memcmp(buf1,buf2,1024));
  88. for(uint16_t j=0 ; j<64 ; j++)
  89. writeHexLine(ficout,buf1+j*16, 16,(bank&1)*32*1024+ i*1024+j*16);
  90. printf("\r reading %dk/256k",progress++);fflush(stdout);
  91. }
  92. }
  93. fprintf(ficout,":00000001FF\n");
  94. // exit from debug
  95. cc_setActive(false);
  96. fclose(ficout);
  97. }