Commit 99dfc787 authored by Fabio Utzig's avatar Fabio Utzig Committed by Fabio Utzig
Browse files

Remove usage of hal_flash_* functions

Update `flash_area_*()` functions to call `sim_flash_*()` directly
instead of using `hal_flash_*()` functions that were not part of the
main bootloader anymore.

Signed-off-by: default avatarFabio Utzig <utzig@apache.org>
parent 455cad5a
Loading
Loading
Loading
Loading
+17 −48
Changes for sim/mcuboot-sys/csupport/run.c: 17 added lines, 48 removed lines.
Original line number Diff line number Diff line
@@ -29,9 +29,11 @@
#define BOOT_LOG_LEVEL BOOT_LOG_LEVEL_ERROR
#include <bootutil/bootutil_log.h>

extern int sim_flash_erase(uint32_t offset, uint32_t size);
extern int sim_flash_read(uint32_t offset, uint8_t *dest, uint32_t size);
extern int sim_flash_write(uint32_t offset, const uint8_t *src, uint32_t size);
extern int sim_flash_erase(uint8_t flash_id, uint32_t offset, uint32_t size);
extern int sim_flash_read(uint8_t flash_id, uint32_t offset, uint8_t *dest,
        uint32_t size);
extern int sim_flash_write(uint8_t flash_id, uint32_t offset, const uint8_t *src,
        uint32_t size);

static jmp_buf boot_jmpbuf;
int flash_counter;
@@ -252,41 +254,6 @@ int invoke_boot_go(struct area_desc *adesc)
    }
}

int hal_flash_read(uint8_t flash_id, uint32_t address, void *dst,
                   uint32_t num_bytes)
{
    (void)flash_id;
    // printf("hal_flash_read: %d, 0x%08x (0x%x)\n",
    //        flash_id, address, num_bytes);
    return sim_flash_read(address, dst, num_bytes);
}

int hal_flash_write(uint8_t flash_id, uint32_t address,
                    const void *src, int32_t num_bytes)
{
    (void)flash_id;
    // printf("hal_flash_write: 0x%08x (0x%x)\n", address, num_bytes);
    // fflush(stdout);
    if (--flash_counter == 0) {
        jumped++;
        longjmp(boot_jmpbuf, 1);
    }
    return sim_flash_write(address, src, num_bytes);
}

int hal_flash_erase(uint8_t flash_id, uint32_t address,
                    uint32_t num_bytes)
{
    (void)flash_id;
    // printf("hal_flash_erase: 0x%08x, (0x%x)\n", address, num_bytes);
    // fflush(stdout);
    if (--flash_counter == 0) {
        jumped++;
        longjmp(boot_jmpbuf, 1);
    }
    return sim_flash_erase(address, num_bytes);
}

void *os_malloc(size_t size)
{
    // printf("os_malloc 0x%x bytes\n", size);
@@ -329,9 +296,7 @@ int flash_area_read(const struct flash_area *area, uint32_t off, void *dst,
{
    BOOT_LOG_DBG("%s: area=%d, off=%x, len=%x",
                 __func__, area->fa_id, off, len);
    return hal_flash_read(area->fa_id,
                          area->fa_off + off,
                          dst, len);
    return sim_flash_read(area->fa_device_id, area->fa_off + off, dst, len);
}

int flash_area_write(const struct flash_area *area, uint32_t off, const void *src,
@@ -339,18 +304,22 @@ int flash_area_write(const struct flash_area *area, uint32_t off, const void *sr
{
    BOOT_LOG_DBG("%s: area=%d, off=%x, len=%x", __func__,
                 area->fa_id, off, len);
    return hal_flash_write(area->fa_id,
                           area->fa_off + off,
                           src, len);
    if (--flash_counter == 0) {
        jumped++;
        longjmp(boot_jmpbuf, 1);
    }
    return sim_flash_write(area->fa_device_id, area->fa_off + off, src, len);
}

int flash_area_erase(const struct flash_area *area, uint32_t off, uint32_t len)
{
    BOOT_LOG_DBG("%s: area=%d, off=%x, len=%x", __func__,
                 area->fa_id, off, len);
    return hal_flash_erase(area->fa_id,
                           area->fa_off + off,
                           len);
    if (--flash_counter == 0) {
        jumped++;
        longjmp(boot_jmpbuf, 1);
    }
    return sim_flash_erase(area->fa_device_id, area->fa_off + off, len);
}

int flash_area_read_is_empty(const struct flash_area *area, uint32_t off,
@@ -362,7 +331,7 @@ int flash_area_read_is_empty(const struct flash_area *area, uint32_t off,

    BOOT_LOG_DBG("%s: area=%d, off=%x, len=%x", __func__, area->fa_id, off, len);

    rc = hal_flash_read(area->fa_device_id, area->fa_off + off, dst, len);
    rc = sim_flash_read(area->fa_device_id, area->fa_off + off, dst, len);
    if (rc) {
        return -1;
    }
+3 −3
Changes for sim/mcuboot-sys/src/api.rs: 3 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -33,20 +33,20 @@ macro_rules! get_flash {
// This isn't meant to call directly, but by a wrapper.

#[no_mangle]
pub extern fn sim_flash_erase(offset: u32, size: u32) -> libc::c_int {
pub extern fn sim_flash_erase(_id: u8, offset: u32, size: u32) -> libc::c_int {
    let dev = unsafe { get_flash!() };
    map_err(dev.erase(offset as usize, size as usize))
}

#[no_mangle]
pub extern fn sim_flash_read(offset: u32, dest: *mut u8, size: u32) -> libc::c_int {
pub extern fn sim_flash_read(_id: u8, offset: u32, dest: *mut u8, size: u32) -> libc::c_int {
    let dev = unsafe { get_flash!() };
    let mut buf: &mut[u8] = unsafe { slice::from_raw_parts_mut(dest, size as usize) };
    map_err(dev.read(offset as usize, &mut buf))
}

#[no_mangle]
pub extern fn sim_flash_write(offset: u32, src: *const u8, size: u32) -> libc::c_int {
pub extern fn sim_flash_write(_id: u8, offset: u32, src: *const u8, size: u32) -> libc::c_int {
    let dev = unsafe { get_flash!() };
    let buf: &[u8] = unsafe { slice::from_raw_parts(src, size as usize) };
    map_err(dev.write(offset as usize, &buf))