Guest User

Untitled

a guest
Jul 19th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. #define LEDRED (*((int*)0xC02200A0))
  2. #define LEDBLUE (*((int*)0xC0220000))
  3. #define LEDON 0x46
  4. #define LEDOFF 0x44
  5.  
  6. #define FW_ADDRESS 0xFF810000
  7. #define BOOT_FLAG 0xf8000000
  8.  
  9. #define BOOTLOADER_FROM 0xffff25f4
  10. #define BOOTLOADER_TO 0x00100000
  11. #define BOOTLOADER_SIZE 0x3300
  12. #define FLAG_BUF_SIZE (0x80 / sizeof(int))
  13.  
  14. typedef void (*ft_read_bootflag)(void* buf1, void* buf2);
  15. typedef void (*ft_write_bootflag)(void* buf1, void* buf2);
  16.  
  17. void Delay(int i) {
  18. while(--i) {
  19. int j = (1 << 8);
  20. while (--j) {
  21. asm("NOP");asm("NOP");asm("NOP");asm("NOP");
  22. }
  23. }
  24. }
  25.  
  26. // copy bootloader to 0x00100000
  27. void Copy() {
  28. int *from = (int*)BOOTLOADER_FROM;
  29. int *to = (int*)BOOTLOADER_TO;
  30. int i = 0;
  31. for (; i < BOOTLOADER_SIZE; i++, from++, to++)
  32. *to = *from;
  33. }
  34.  
  35. // zero memory
  36. void Zero(int* buf, int size) {
  37. int i = 0;
  38. for (; i < size; i++)
  39. buf = 0;
  40. }
  41.  
  42. /* *, -1, * run(1) from cf
  43. *, 0, 0 run(1) from cf
  44. -1, 0, -1 run(5) from flash
  45.  
  46. original flag in camera: 0,0,-1
  47. */
  48.  
  49. //fopen 0xffa41664
  50.  
  51. void main()
  52. {
  53. ft_read_bootflag read_bootflag;
  54. ft_write_bootflag write_bootflag;
  55. int buf1[FLAG_BUF_SIZE];
  56. int buf2[FLAG_BUF_SIZE];
  57. int *boot_flag = (int*)BOOT_FLAG;
  58.  
  59. Copy();
  60. read_bootflag = (ft_read_bootflag)0x001059b0;
  61. write_bootflag = (ft_write_bootflag)0x0010586c;
  62. Delay(1 << 14);
  63.  
  64. Zero(buf1, FLAG_BUF_SIZE);
  65. Zero(buf2, FLAG_BUF_SIZE);
  66. read_bootflag(buf1, buf2);
  67.  
  68. //if (buf1[0] == 0 && buf1[1] == 0 && buf1[2] == -1)
  69. if (buf1[0] != boot_flag[0] || buf1[1] != boot_flag[1] || buf1[2] != boot_flag[2]) {
  70. LEDRED = LEDON;
  71. } else {
  72. LEDBLUE = LEDON;
  73. Delay(1 << 14);
  74.  
  75. LEDBLUE = LEDON;
  76. LEDRED = LEDON;
  77. // enable / disable boot from cf card
  78. if (buf1[1] == 0)
  79. buf1[1] = -1;
  80. else
  81. buf1[1] = 0;
  82. // write to flash
  83. write_bootflag(buf1, buf2);
  84. Delay(1 << 14);
  85. LEDBLUE = LEDOFF;
  86. LEDRED = LEDOFF;
  87. Delay(1 << 14);
  88.  
  89. // verify, blue = ok
  90. //if (boot_flag[0] == 0 && boot_flag[1] == -1 && boot_flag[2] == -1)
  91. if (buf1[0] == boot_flag[0] && buf1[1] == boot_flag[1] && buf1[2] == boot_flag[2])
  92. LEDBLUE = LEDON;
  93. else
  94. LEDRED = LEDON;
  95. }
  96.  
  97. for (;;);
  98. }
Add Comment
Please, Sign In to add comment