@@ -70,7 +70,7 @@ uint32_t supervisor_flash_get_block_size(void) {
70
70
}
71
71
72
72
uint32_t supervisor_flash_get_block_count (void ) {
73
- return INTERNAL_FLASH_PART1_START_BLOCK + INTERNAL_FLASH_PART1_NUM_BLOCKS ;
73
+ return INTERNAL_FLASH_PART1_NUM_BLOCKS ;
74
74
}
75
75
76
76
void supervisor_flash_flush (void ) {
@@ -80,116 +80,54 @@ void flash_flush(void) {
80
80
supervisor_flash_flush ();
81
81
}
82
82
83
- static void build_partition (uint8_t * buf , int boot , int type , uint32_t start_block , uint32_t num_blocks ) {
84
- buf [0 ] = boot ;
85
-
86
- if (num_blocks == 0 ) {
87
- buf [1 ] = 0 ;
88
- buf [2 ] = 0 ;
89
- buf [3 ] = 0 ;
90
- } else {
91
- buf [1 ] = 0xff ;
92
- buf [2 ] = 0xff ;
93
- buf [3 ] = 0xff ;
94
- }
95
-
96
- buf [4 ] = type ;
97
-
98
- if (num_blocks == 0 ) {
99
- buf [5 ] = 0 ;
100
- buf [6 ] = 0 ;
101
- buf [7 ] = 0 ;
102
- } else {
103
- buf [5 ] = 0xff ;
104
- buf [6 ] = 0xff ;
105
- buf [7 ] = 0xff ;
106
- }
107
-
108
- buf [8 ] = start_block ;
109
- buf [9 ] = start_block >> 8 ;
110
- buf [10 ] = start_block >> 16 ;
111
- buf [11 ] = start_block >> 24 ;
112
-
113
- buf [12 ] = num_blocks ;
114
- buf [13 ] = num_blocks >> 8 ;
115
- buf [14 ] = num_blocks >> 16 ;
116
- buf [15 ] = num_blocks >> 24 ;
117
- }
118
-
119
83
static int32_t convert_block_to_flash_addr (uint32_t block ) {
120
- if (INTERNAL_FLASH_PART1_START_BLOCK <= block && block < INTERNAL_FLASH_PART1_START_BLOCK + INTERNAL_FLASH_PART1_NUM_BLOCKS ) {
84
+ if (0 <= block && block < INTERNAL_FLASH_PART1_NUM_BLOCKS ) {
121
85
// a block in partition 1
122
- block -= INTERNAL_FLASH_PART1_START_BLOCK ;
123
86
return INTERNAL_FLASH_MEM_SEG1_START_ADDR + block * FILESYSTEM_BLOCK_SIZE ;
124
87
}
125
88
// bad block
126
89
return -1 ;
127
90
}
128
91
129
92
bool supervisor_flash_read_block (uint8_t * dest , uint32_t block ) {
130
- if (block == 0 ) {
131
- // fake the MBR so we can decide on our own partition table
132
-
133
- for (int i = 0 ; i < 446 ; i ++ ) {
134
- dest [i ] = 0 ;
135
- }
136
-
137
- build_partition (dest + 446 , 0 , 0x01 /* FAT12 */ , INTERNAL_FLASH_PART1_START_BLOCK , INTERNAL_FLASH_PART1_NUM_BLOCKS );
138
- build_partition (dest + 462 , 0 , 0 , 0 , 0 );
139
- build_partition (dest + 478 , 0 , 0 , 0 , 0 );
140
- build_partition (dest + 494 , 0 , 0 , 0 , 0 );
141
-
142
- dest [510 ] = 0x55 ;
143
- dest [511 ] = 0xaa ;
144
-
145
- return true;
146
-
147
- } else {
148
- // non-MBR block, get data from flash memory
149
- int32_t src = convert_block_to_flash_addr (block );
150
- if (src == -1 ) {
151
- // bad block number
152
- return false;
153
- }
154
- int32_t error_code = flash_read (& supervisor_flash_desc , src , dest , FILESYSTEM_BLOCK_SIZE );
155
- return error_code == ERR_NONE ;
93
+ // non-MBR block, get data from flash memory
94
+ int32_t src = convert_block_to_flash_addr (block );
95
+ if (src == -1 ) {
96
+ // bad block number
97
+ return false;
156
98
}
99
+ int32_t error_code = flash_read (& supervisor_flash_desc , src , dest , FILESYSTEM_BLOCK_SIZE );
100
+ return error_code == ERR_NONE ;
157
101
}
158
102
159
103
bool supervisor_flash_write_block (const uint8_t * src , uint32_t block ) {
160
- if (block == 0 ) {
161
- // can't write MBR, but pretend we did
162
- return true;
163
-
164
- } else {
165
- #ifdef MICROPY_HW_LED_MSC
166
- port_pin_set_output_level (MICROPY_HW_LED_MSC , true);
167
- #endif
168
- temp_status_color (ACTIVE_WRITE );
169
- // non-MBR block, copy to cache
170
- int32_t dest = convert_block_to_flash_addr (block );
171
- if (dest == -1 ) {
172
- // bad block number
173
- return false;
174
- }
175
- int32_t error_code ;
176
- error_code = flash_erase (& supervisor_flash_desc ,
177
- dest ,
178
- FILESYSTEM_BLOCK_SIZE / flash_get_page_size (& supervisor_flash_desc ));
179
- if (error_code != ERR_NONE ) {
180
- return false;
181
- }
104
+ #ifdef MICROPY_HW_LED_MSC
105
+ port_pin_set_output_level (MICROPY_HW_LED_MSC , true);
106
+ #endif
107
+ temp_status_color (ACTIVE_WRITE );
108
+ // non-MBR block, copy to cache
109
+ int32_t dest = convert_block_to_flash_addr (block );
110
+ if (dest == -1 ) {
111
+ // bad block number
112
+ return false;
113
+ }
114
+ int32_t error_code ;
115
+ error_code = flash_erase (& supervisor_flash_desc ,
116
+ dest ,
117
+ FILESYSTEM_BLOCK_SIZE / flash_get_page_size (& supervisor_flash_desc ));
118
+ if (error_code != ERR_NONE ) {
119
+ return false;
120
+ }
182
121
183
- error_code = flash_append (& supervisor_flash_desc , dest , src , FILESYSTEM_BLOCK_SIZE );
184
- if (error_code != ERR_NONE ) {
185
- return false;
186
- }
187
- clear_temp_status ();
188
- #ifdef MICROPY_HW_LED_MSC
189
- port_pin_set_output_level (MICROPY_HW_LED_MSC , false);
190
- #endif
191
- return true;
122
+ error_code = flash_append (& supervisor_flash_desc , dest , src , FILESYSTEM_BLOCK_SIZE );
123
+ if (error_code != ERR_NONE ) {
124
+ return false;
192
125
}
126
+ clear_temp_status ();
127
+ #ifdef MICROPY_HW_LED_MSC
128
+ port_pin_set_output_level (MICROPY_HW_LED_MSC , false);
129
+ #endif
130
+ return true;
193
131
}
194
132
195
133
mp_uint_t supervisor_flash_read_blocks (uint8_t * dest , uint32_t block_num , uint32_t num_blocks ) {
0 commit comments