Skip to content

Commit ef78369

Browse files
de-nordicnordicjm
authored andcommitted
Revert "bootutil: Add support for devices without erase and reduced erases"
Need to revert changes provided to support devices without erase until problme with TF-M, missing implementation of flash_area_get_sector, is resolved. This reverts commit e025689. Signed-off-by: Dominik Ermel <[email protected]>
1 parent dbbeae4 commit ef78369

11 files changed

+63
-408
lines changed

boot/boot_serial/src/boot_serial.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,7 @@ static off_t erase_range(const struct flash_area *fap, off_t start, off_t end)
856856
BOOT_LOG_DBG("Erasing range 0x%jx:0x%jx", (intmax_t)start,
857857
(intmax_t)(start + size - 1));
858858

859-
rc = boot_erase_region(fap, start, size);
859+
rc = flash_area_erase(fap, start, size);
860860
if (rc != 0) {
861861
BOOT_LOG_ERR("Error %d while erasing range", rc);
862862
return -EINVAL;
@@ -1000,7 +1000,7 @@ bs_upload(char *buf, int len)
10001000
/* Non-progressive erase erases entire image slot when first chunk of
10011001
* an image is received.
10021002
*/
1003-
rc = boot_erase_region(fap, 0, area_size);
1003+
rc = flash_area_erase(fap, 0, area_size);
10041004
if (rc) {
10051005
goto out_invalid_data;
10061006
}

boot/boot_serial/src/boot_serial_encryption.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ decrypt_region_inplace(struct boot_loader_state *state,
187187
(off + bytes_copied + idx) - hdr->ih_hdr_size, blk_sz,
188188
blk_off, &buf[idx]);
189189
}
190-
rc = boot_erase_region(fap, off + bytes_copied, chunk_sz);
190+
rc = flash_area_erase(fap, off + bytes_copied, chunk_sz);
191191
if (rc != 0) {
192192
return BOOT_EFLASH;
193193
}

boot/bootutil/src/bootutil_misc.c

-68
Original file line numberDiff line numberDiff line change
@@ -135,74 +135,6 @@ boot_trailer_sz(uint32_t min_write_sz)
135135
return boot_status_sz(min_write_sz) + boot_trailer_info_sz();
136136
}
137137

138-
int boot_trailer_scramble_offset(const struct flash_area *fa, size_t alignment,
139-
size_t *off)
140-
{
141-
int ret = 0;
142-
143-
/* Not allowed to enforce alignment smaller than device allows */
144-
if (alignment < flash_area_align(fa)) {
145-
alignment = flash_area_align(fa);
146-
}
147-
148-
if (device_requires_erase(fa)) {
149-
/* For device requiring erase align to erase unit */
150-
struct flash_sector sector;
151-
152-
ret = flash_area_get_sector(fa, flash_area_get_size(fa) - boot_trailer_sz(alignment),
153-
&sector);
154-
if (ret < 0) {
155-
return ret;
156-
}
157-
158-
*off = flash_sector_get_off(&sector);
159-
} else {
160-
/* For device not requiring erase align to write block */
161-
*off = flash_area_get_size(fa) - ALIGN_DOWN(boot_trailer_sz(alignment), alignment);
162-
}
163-
164-
return ret;
165-
}
166-
167-
int boot_header_scramble_off_sz(const struct flash_area *fa, int slot, size_t *off,
168-
size_t *size)
169-
{
170-
int ret = 0;
171-
const size_t write_block = flash_area_align(fa);
172-
size_t loff = 0;
173-
struct flash_sector sector;
174-
175-
(void)slot;
176-
#if defined(MCUBOOT_SWAP_USING_OFFSET)
177-
/* In case of swap offset, header of secondary slot image is positioned
178-
* in second sector of slot.
179-
*/
180-
if (slot == BOOT_SECONDARY_SLOT) {
181-
ret = flash_area_get_sector(fa, 0, &sector);
182-
if (ret < 0) {
183-
return ret;
184-
}
185-
loff = flash_sector_get_off(&sector);
186-
}
187-
#endif
188-
189-
if (device_requires_erase(fa)) {
190-
/* For device requiring erase align to erase unit */
191-
ret = flash_area_get_sector(fa, loff, &sector);
192-
if (ret < 0) {
193-
return ret;
194-
}
195-
196-
*size = flash_sector_get_size(&sector);
197-
} else {
198-
/* For device not requiring erase align to write block */
199-
*size = ALIGN_UP(sizeof(((struct image_header *)0)->ih_magic), write_block);
200-
}
201-
*off = loff;
202-
203-
return ret;
204-
}
205-
206138
#if MCUBOOT_SWAP_USING_SCRATCH
207139
/*
208140
* Similar to `boot_trailer_sz` but this function returns the space used to

boot/bootutil/src/bootutil_priv.h

-36
Original file line numberDiff line numberDiff line change
@@ -301,16 +301,6 @@ int boot_find_status(int image_index, const struct flash_area **fap);
301301
int boot_magic_compatible_check(uint8_t tbl_val, uint8_t val);
302302
uint32_t boot_status_sz(uint32_t min_write_sz);
303303
uint32_t boot_trailer_sz(uint32_t min_write_sz);
304-
/* Get offset of trailer aligned to either device erase unit or alignment
305-
* depending on whether device has erase or not.
306-
*/
307-
int boot_trailer_scramble_offset(const struct flash_area *fa, size_t alignment,
308-
size_t *off);
309-
/* Get size of header aligned to device erase unit or write block,
310-
* depending on whether device has erase or not.
311-
*/
312-
int boot_header_scramble_off_sz(const struct flash_area *fa, int slot, size_t *off,
313-
size_t *size);
314304
int boot_status_entries(int image_index, const struct flash_area *fap);
315305
uint32_t boot_status_off(const struct flash_area *fap);
316306
int boot_read_swap_state(const struct flash_area *fap,
@@ -344,19 +334,7 @@ int boot_copy_region(struct boot_loader_state *state,
344334
const struct flash_area *fap_dst,
345335
uint32_t off_src, uint32_t off_dst, uint32_t sz);
346336
#endif
347-
/* Prepare for write device that requires erase prior to write. This will
348-
* do nothing on devices without erase requirement.
349-
*/
350337
int boot_erase_region(const struct flash_area *fap, uint32_t off, uint32_t sz);
351-
/* Similar to boot_erase_region but will always remove data */
352-
int boot_scramble_region(const struct flash_area *fap, uint32_t off, uint32_t sz);
353-
/* Similar to boot_scramble_region but works backwards */
354-
int boot_scramble_region_backwards(const struct flash_area *fap, uint32_t off, uint32_t sz);
355-
/* Makes slot unbootable, either by scrambling header magic, header sector
356-
* or entire slot, depending on settings.
357-
* Note: slot is passed here becuase at this point there is no function
358-
* matching flash_area object to slot */
359-
int boot_scramble_slot(const struct flash_area *fap, int slot);
360338
bool boot_status_is_reset(const struct boot_status *bs);
361339

362340
#ifdef MCUBOOT_ENC_IMAGES
@@ -538,20 +516,6 @@ uint32_t bootutil_max_image_size(const struct flash_area *fap);
538516
int boot_read_image_size(struct boot_loader_state *state, int slot,
539517
uint32_t *size);
540518

541-
/* Helper macro to avoid compile errors with systems that do not
542-
* provide function to check device type.
543-
* Note: it used to be inline, but somehow compiler would not
544-
* optimize out branches that were impossible when this evaluated to
545-
* just "true".
546-
*/
547-
#if defined(MCUBOOT_SUPPORT_DEV_WITHOUT_ERASE) && defined(MCUBOOT_SUPPORT_DEV_WITH_ERASE)
548-
#define device_requires_erase(fa) (flash_area_erase_required(fa))
549-
#elif defined(MCUBOOT_SUPPORT_DEV_WITHOUT_ERASE)
550-
#define device_requires_erase(fa) (false)
551-
#else
552-
#define device_requires_erase(fa) (true)
553-
#endif
554-
555519
#ifdef __cplusplus
556520
}
557521
#endif

0 commit comments

Comments
 (0)