Commit 30f6b2a9 authored by Fabio Utzig's avatar Fabio Utzig Committed by Fabio Utzig
Browse files

Fix boot_serial to follow flash write alignment

This fixes an issue found on stm32f3 where newtmgr after writing an odd
sized packet, would hardfault on the next write due to trying to write an
odd address which is not valid on stm32f3 flash.

Signed-off-by: default avatarFabio Utzig <utzig@apache.org>
parent 1d46c944
Loading
Loading
Loading
Loading
+7 −2
Changes for boot/boot_serial/src/boot_serial.c: 7 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -188,6 +188,7 @@ bs_upload(char *buf, int len)
    uint8_t img_data[400];
    long long unsigned int off = UINT_MAX;
    size_t img_blen = 0;
    uint8_t rem_bytes;
    long long unsigned int data_len = UINT_MAX;
    const struct cbor_attr_t attr[4] = {
        [0] = {
@@ -222,7 +223,6 @@ bs_upload(char *buf, int len)
        goto out;
    }


    rc = flash_area_open(flash_area_id_from_image_slot(0), &fap);
    if (rc) {
        rc = MGMT_ERR_EINVAL;
@@ -246,6 +246,12 @@ bs_upload(char *buf, int len)
        rc = 0;
        goto out;
    }
    if (curr_off + img_blen < img_size) {
        rem_bytes = img_blen % flash_area_align(fap);
        if (rem_bytes) {
            img_blen -= rem_bytes;
        }
    }
    rc = flash_area_write(fap, curr_off, img_data, img_blen);
    if (rc) {
        rc = MGMT_ERR_EINVAL;
@@ -322,7 +328,6 @@ boot_serial_input(char *buf, int len)
    bs_writer.bytes_written = 0;
    cbor_encoder_init(&bs_root, &bs_writer, 0);


    /*
     * Limited support for commands.
     */