Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions boot/nxboot/loader/boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ static int perform_update(struct nxboot_state *state, bool check_only)
syslog(LOG_INFO, "Creating recovery image.\n");
nxboot_progress(nxboot_progress_start, recovery_create);
copy_partition(primary, recovery, state, false);
flash_partition_flush(recovery);
nxboot_progress(nxboot_progress_end);
nxboot_progress(nxboot_progress_start, validate_recovery);
successful = validate_image(recovery);
Expand Down Expand Up @@ -444,6 +445,8 @@ static int perform_update(struct nxboot_state *state, bool check_only)
nxboot_progress(nxboot_progress_start, update_from_update);
if (copy_partition(update, primary, state, true) >= 0)
{
flash_partition_flush(primary);

/* Erase the first sector of update partition. This marks the
* partition as updated so we don't end up in an update loop.
* The sector is written back again during the image
Expand Down Expand Up @@ -884,7 +887,6 @@ int nxboot_perform_update(bool check_only)
int ret;
int primary;
struct nxboot_state state;
struct nxboot_img_header header;

ret = nxboot_get_state(&state);
if (ret < 0)
Expand All @@ -908,9 +910,9 @@ int nxboot_perform_update(bool check_only)
}
}

/* Check whether there is a valid image in the primary slot. This just
* checks whether the header is valid, but does not calculate the CRC
* of the image as this would prolong the boot process.
/* Check whether there is a valid image in the primary slot. Validates
* both the header and the full image CRC to ensure integrity before
* booting.
*/

primary = flash_partition_open(CONFIG_NXBOOT_PRIMARY_SLOT_PATH);
Expand All @@ -919,8 +921,7 @@ int nxboot_perform_update(bool check_only)
return ERROR;
}

get_image_header(primary, &header);
if (!validate_image_header(&header))
if (!validate_image(primary))
{
ret = ERROR;
}
Expand Down
20 changes: 20 additions & 0 deletions boot/nxboot/loader/flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,26 @@ int flash_partition_open(const char *path)
return fd;
}

/****************************************************************************
* Name: flash_partition_flush
*
* Description:
* Flushes any buffered writes to the underlying storage. This ensures
* data is physically committed to flash before the caller proceeds.
*
* Input parameters:
* fd: Valid file descriptor.
*
* Returned Value:
* 0 on success, -1 on failure.
*
****************************************************************************/

int flash_partition_flush(int fd)
{
return fsync(fd);
}

/****************************************************************************
* Name: flash_partition_close
*
Expand Down
16 changes: 16 additions & 0 deletions boot/nxboot/loader/flash.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,22 @@ int flash_partition_open(const char *path);

int flash_partition_close(int fd);

/****************************************************************************
* Name: flash_partition_flush
*
* Description:
* Flushes any buffered writes to the underlying storage.
*
* Input parameters:
* fd: Valid file descriptor.
*
* Returned Value:
* 0 on success, -1 on failure.
*
****************************************************************************/

int flash_partition_flush(int fd);

/****************************************************************************
* Name: flash_partition_write
*
Expand Down
Loading