Michal Lenc 0639a2ad7b boot/nxboot: enhance bootloader capabilities and decision logic
This commit enhances the bootloader capabilities. The image's header
is extended with header version, size, platform identifier and
pointer to optional next header. CRC32 now includes part of
the header in its calculation as well.

The change also avoids having two different magics for image uploaded
over programmer and update image. Both these images have the same
magic and this magic is changed internally by the bootloader's logic.
The change is needed because image with standard magic is automatically
considered as a confirmed image (uploaded with programmer).

The current implementation avoids tails at all, therefore the user
application uploading the image does not have to erase the tail before
new upload. The image is considered as confirmed if it has standard
magic or its recovery is present. This means the bootloader has to
erase the header of the update image after the update is done (to
avoid update loop and to mark the image as unstable). This page is
written back during the confirmation.

This is a breaking change, but necessary for the future development
of the bootloader. The added header version field will allow to
add minor/major updates while keeping the backwards compatibility.

Signed-off-by: Michal Lenc <michallenc@seznam.cz>
Co-authored-by: Pavel Pisa <pisa@fel.cvut.cz>
Co-authored-by: Karel Koci <cynerd@email.cz>
2025-03-14 10:35:49 -03:00

172 lines
5.2 KiB
C

/****************************************************************************
* apps/boot/nxboot/loader/flash.h
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __BOOT_NXBOOT_LOADER_FLASH_H
#define __BOOT_NXBOOT_LOADER_FLASH_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <stdint.h>
#include <stddef.h>
/****************************************************************************
* Public Types
****************************************************************************/
struct flash_partition_info
{
int size;
int blocksize;
int neraseblocks;
int erasesize;
};
/****************************************************************************
* Public Functions Prototypes
****************************************************************************/
/****************************************************************************
* Name: flash_partition_open
*
* Description:
* Opens the partition based on a given name and returns the file
* descriptor to it.
*
* Input parameters:
* path: Path to the device.
*
* Returned Value:
* Valid file descriptor on success, -1 on failure.
*
****************************************************************************/
int flash_partition_open(const char *path);
/****************************************************************************
* Name: flash_partition_close
*
* Description:
* Closes opened partition.
*
* Input parameters:
* fd: Valid file descriptor.
*
* Returned Value:
* 0 on success, -1 on failure.
*
****************************************************************************/
int flash_partition_close(int fd);
/****************************************************************************
* Name: flash_partition_write
*
* Description:
* Writes count data pointed to by buf at offset off to a partition
* referenced by file descriptor fd.
*
* Input parameters:
* fd: Valid file descriptor.
* buf: The pointer to data to be written.
* count: Number of bytes to be written.
* off: Write offset in bytes.
*
* Returned Value:
* 0 on success, -1 on failure.
*
****************************************************************************/
int flash_partition_write(int fd, const void *buf, size_t count, off_t off);
/****************************************************************************
* Name: flash_partition_read
*
* Description:
* Read count data to buffer buf at offset off from a partition
* referenced by file descriptor fd.
*
* Input parameters:
* fd: Valid file descriptor.
* buf: The pointer where read data are stored.
* count: Number of bytes to be read.
* off: Read offset in bytes.
*
* Returned Value:
* 0 on success, -1 on failure.
*
****************************************************************************/
int flash_partition_read(int fd, void *buf, size_t count, off_t off);
/****************************************************************************
* Name: flash_partition_erase
*
* Description:
* Erases the entire partition.
*
* Input parameters:
* fd: Valid file descriptor.
*
* Returned Value:
* 0 on success, -1 on failure.
*
****************************************************************************/
int flash_partition_erase(int fd);
/****************************************************************************
* Name: flash_partition_erase_first_sector
*
* Description:
* Erases the first sector of the partition
*
* Input parameters:
* fd: Valid file descriptor.
*
* Returned Value:
* 0 on success, -1 on failure.
*
****************************************************************************/
int flash_partition_erase_first_sector(int fd);
/****************************************************************************
* Name: flash_partition_info
*
* Description:
* Returns the size of one block.
*
* Input parameters:
* fd: Valid file descriptor.
* info: Pointer to flash_partition_info structure where info is filled.
*
* Returned Value:
* Size of the block on success, -1 on failure.
*
****************************************************************************/
int flash_partition_info(int fd, struct flash_partition_info *info);
#endif /* __BOOT_NXBOOT_LOADER_FLASH_H */