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.
 
 
 
 
 
 

86 lines
1.4 KiB

  1. /*
  2. * Spansion FM4 flash write algorithm
  3. *
  4. * Copyright (c) 2015 Andreas Färber
  5. *
  6. * Based on S6E2CC_MN709-00007 for S6E2CC/C5/C4/C3/C2/C1 series
  7. */
  8. #include "fm4.h"
  9. #define RESULT_OKAY 0
  10. #define RESULT_NONE 1
  11. #define RESULT_TIMEOUT 2
  12. .macro busy_wait, res, addr, data, tmp1, tmp2, tmp3
  13. ldrb \tmp1, [\addr] /* ignore */
  14. and \tmp2, \data, #FLASH_DPOL
  15. 1001:
  16. ldrb \tmp1, [\addr]
  17. and \tmp3, \tmp1, #FLASH_DPOL
  18. cmp \tmp3, \tmp2
  19. beq 1010f
  20. and \tmp3, \tmp1, #FLASH_TLOV
  21. cmp \tmp3, #0
  22. beq 1001b
  23. ldrb \tmp1, [\addr]
  24. and \tmp3, \tmp1, #FLASH_DPOL
  25. cmp \tmp3, \tmp2
  26. beq 1010f
  27. mov \res, #RESULT_TIMEOUT
  28. bkpt #0
  29. 1010:
  30. .endm
  31. .macro write_one, res, cmdseqaddr1, cmdseqaddr2, pa, pd, tmp1, tmp2, tmp3
  32. mov \tmp1, #0xAA
  33. strh \tmp1, [\cmdseqaddr1]
  34. mov \tmp1, #0x55
  35. strh \tmp1, [\cmdseqaddr2]
  36. mov \tmp1, #0xA0
  37. strh \tmp1, [\cmdseqaddr1]
  38. strh \pd, [\pa]
  39. busy_wait \res, \pa, \pd, \tmp1, \tmp2, \tmp3
  40. .endm
  41. .macro write, cmdseqaddr1, cmdseqaddr2, dest, src, cnt, res, tmp1, tmp2, tmp3, tmp4
  42. mov \res, #RESULT_NONE
  43. 2001:
  44. cbz \cnt, 2010f
  45. ldrh \tmp1, [\src]
  46. write_one \res, \cmdseqaddr1, \cmdseqaddr2, \dest, \tmp1, \tmp2, \tmp3, \tmp4
  47. sub \cnt, \cnt, #1
  48. add \dest, \dest, #2
  49. add \src, \src, #2
  50. b 2001b
  51. 2010:
  52. mov \res, #RESULT_OKAY
  53. .endm
  54. /* r0 = 0xAA8
  55. * r1 = 0x554
  56. * r2 = dest
  57. * r3 = src
  58. * r4 = cnt
  59. * r5 = result
  60. */
  61. write:
  62. write r0, r1, r2, r3, r4, r5, r6, r7, r8, r9
  63. bkpt #0
  64. data: