|
9 | 9 | #include <stddef.h>
|
10 | 10 | #include <stdint.h>
|
11 | 11 | #include <stdbool.h>
|
12 |
| -#include "eboot.h" |
| 12 | +#include "flash.h" |
13 | 13 | #include "eboot_command.h"
|
14 |
| -extern void* flashchip; |
15 | 14 |
|
16 | 15 | #define SWRST do { (*((volatile uint32_t*) 0x60000700)) |= 0x80000000; } while(0);
|
17 | 16 |
|
@@ -73,53 +72,21 @@ int load_app_from_flash_raw(const uint32_t flash_addr)
|
73 | 72 |
|
74 | 73 |
|
75 | 74 |
|
76 |
| -int erase(const uint32_t start, const uint32_t size) |
77 |
| -{ |
78 |
| - if (start & (FLASH_SECTOR_SIZE - 1) != 0) { |
79 |
| - return 1; |
80 |
| - } |
81 |
| - |
82 |
| - const uint32_t sectors_per_block = FLASH_BLOCK_SIZE / FLASH_SECTOR_SIZE; |
83 |
| - uint32_t current_sector = start / FLASH_SECTOR_SIZE; |
84 |
| - uint32_t sector_count = (size + FLASH_SECTOR_SIZE - 1) / FLASH_SECTOR_SIZE; |
85 |
| - const uint32_t end = current_sector + sector_count; |
86 |
| - |
87 |
| - for (; current_sector < end && (current_sector & (sectors_per_block-1)); |
88 |
| - ++current_sector, --sector_count) { |
89 |
| - if (SPIEraseSector(current_sector)) { |
90 |
| - return 2; |
91 |
| - } |
92 |
| - } |
93 |
| - |
94 |
| - for (;current_sector + sectors_per_block <= end; |
95 |
| - current_sector += sectors_per_block, |
96 |
| - sector_count -= sectors_per_block) { |
97 |
| - if (SPIEraseBlock(current_sector / sectors_per_block)) { |
98 |
| - return 3; |
99 |
| - } |
100 |
| - } |
101 |
| - |
102 |
| - for (; current_sector < end; |
103 |
| - ++current_sector, --sector_count) { |
104 |
| - if (SPIEraseSector(current_sector)) { |
105 |
| - return 4; |
106 |
| - } |
107 |
| - } |
108 |
| - |
109 |
| - return 0; |
110 |
| -} |
111 |
| - |
112 | 75 | int copy_raw(const uint32_t src_addr,
|
113 | 76 | const uint32_t dst_addr,
|
114 | 77 | const uint32_t size)
|
115 | 78 | {
|
| 79 | + ets_putc('\n'); |
| 80 | + ets_putc('c'); |
| 81 | + ets_putc('p'); |
| 82 | + ets_putc('\n'); |
116 | 83 | // require regions to be aligned
|
117 | 84 | if (src_addr & 0xfff != 0 ||
|
118 | 85 | dst_addr & 0xfff != 0) {
|
119 | 86 | return 1;
|
120 | 87 | }
|
121 | 88 |
|
122 |
| - if (erase(dst_addr, size)) { |
| 89 | + if (SPIEraseAreaEx(dst_addr, size)) { |
123 | 90 | return 2;
|
124 | 91 | }
|
125 | 92 |
|
@@ -153,17 +120,25 @@ void main()
|
153 | 120 | int res = 9;
|
154 | 121 | struct eboot_command cmd;
|
155 | 122 |
|
156 |
| - eboot_command_read(&cmd); |
| 123 | + if (eboot_command_read(&cmd)) { |
| 124 | + cmd.action = ACTION_LOAD_APP; |
| 125 | + cmd.args[0] = 0; |
| 126 | + ets_putc('e'); |
| 127 | + } else { |
| 128 | + ets_putc('@'); |
| 129 | + } |
| 130 | + eboot_command_clear(); |
157 | 131 |
|
158 | 132 | if (cmd.action == ACTION_COPY_RAW) {
|
159 | 133 | res = copy_raw(cmd.args[0], cmd.args[1], cmd.args[2]);
|
160 | 134 | if (res == 0) {
|
161 | 135 | cmd.action = ACTION_LOAD_APP;
|
| 136 | + cmd.args[0] = cmd.args[1]; |
162 | 137 | }
|
163 | 138 | }
|
164 | 139 |
|
165 | 140 | if (cmd.action == ACTION_LOAD_APP) {
|
166 |
| - res = load_app_from_flash_raw(0); |
| 141 | + res = load_app_from_flash_raw(cmd.args[0]); |
167 | 142 | }
|
168 | 143 |
|
169 | 144 | if (res) {
|
|
0 commit comments