UAVCAN bootloader merge duplicate boot_app_shared

This commit is contained in:
Daniel Agar
2021-01-26 00:26:50 -05:00
committed by David Sidrane
parent e656c9c13f
commit 347c185967
11 changed files with 21 additions and 748 deletions

View File

@@ -24,4 +24,6 @@ px4_add_board(
LABEL canbootloader
TOOLCHAIN arm-none-eabi
ARCHITECTURE cortex-m4
DRIVERS
bootloaders
)

View File

@@ -34,16 +34,18 @@
px4_add_library(canbootloader
arch/stm32/board_identity.c
arch/stm32/drivers/can/driver.c
common/boot_app_shared.c
common/nuttx_stubs.c
fs/flash.c
protocol/uavcan.c
sched/timer.c
uavcan/main.c
util/crc.c
util/random.c
)
include_directories(include)
target_include_directories(canbootloader INTERFACE include)
target_compile_options(canbootloader PRIVATE -Wno-error)
target_link_libraries(canbootloader
PRIVATE
drivers_bootloaders
)

View File

@@ -51,11 +51,11 @@
#include "board.h"
#include "px4_macros.h"
#include "can.h"
#include "crc.h"
#include "timer.h"
#include <arch/board/board.h>
#include <lib/systemlib/crc.h>
#define INAK_TIMEOUT 65535

View File

@@ -1,204 +0,0 @@
/****************************************************************************
*
* Copyright (c) 2015 PX4 Development Team. All rights reserved.
* Author: Ben Dyer <ben_dyer@mac.com>
* Pavel Kirienko <pavel.kirienko@zubax.com>
* David Sidrane <david_s5@nscdg.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name PX4 nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <string.h>
#include "chip.h"
#include "stm32.h"
#include <errno.h>
#include "boot_app_shared.h"
#include "crc.h"
#define BOOTLOADER_COMMON_APP_SIGNATURE 0xB0A04150u
#define BOOTLOADER_COMMON_BOOTLOADER_SIGNATURE 0xB0A0424Cu
/* CAN_FiRx where (i=0..27|13, x=1, 2)
* STM32_CAN1_FIR(i,x)
* Using i = 2 does not requier there block
* to be enabled nor FINIT in CAN_FMR to be set.
* todo:Validate this claim on F2, F3
*/
#define crc_HiLOC STM32_CAN1_FIR(2,1)
#define crc_LoLOC STM32_CAN1_FIR(2,2)
#define signature_LOC STM32_CAN1_FIR(3,1)
#define bus_speed_LOC STM32_CAN1_FIR(3,2)
#define node_id_LOC STM32_CAN1_FIR(4,1)
#define CRC_H 1
#define CRC_L 0
inline static void read(bootloader_app_shared_t *pshared)
{
pshared->signature = getreg32(signature_LOC);
pshared->bus_speed = getreg32(bus_speed_LOC);
pshared->node_id = getreg32(node_id_LOC);
pshared->crc.ul[CRC_L] = getreg32(crc_LoLOC);
pshared->crc.ul[CRC_H] = getreg32(crc_HiLOC);
}
inline static void write(bootloader_app_shared_t *pshared)
{
putreg32(pshared->signature, signature_LOC);
putreg32(pshared->bus_speed, bus_speed_LOC);
putreg32(pshared->node_id, node_id_LOC);
putreg32(pshared->crc.ul[CRC_L], crc_LoLOC);
putreg32(pshared->crc.ul[CRC_H], crc_HiLOC);
}
static uint64_t calulate_signature(bootloader_app_shared_t *pshared)
{
uint64_t crc;
crc = crc64_add_word(CRC64_INITIAL, pshared->signature);
crc = crc64_add_word(crc, pshared->bus_speed);
crc = crc64_add_word(crc, pshared->node_id);
crc ^= CRC64_OUTPUT_XOR;
return crc;
}
static void bootloader_app_shared_init(bootloader_app_shared_t *pshared, eRole_t role)
{
memset(pshared, 0, sizeof(bootloader_app_shared_t));
if (role != Invalid) {
pshared->signature =
(role ==
App ? BOOTLOADER_COMMON_APP_SIGNATURE :
BOOTLOADER_COMMON_BOOTLOADER_SIGNATURE);
}
}
/****************************************************************************
* Name: bootloader_app_shared_read
*
* Description:
* Based on the role requested, this function will conditionally populate
* a bootloader_app_shared_t structure from the physical locations used
* to transfer the shared data to/from an application (internal data) .
*
* The functions will only populate the structure and return a status
* indicating success, if the internal data has the correct signature as
* requested by the Role AND has a valid crc.
*
* Input Parameters:
* shared - A pointer to a bootloader_app_shared_t return the data in if
* the internal data is valid for the requested Role
* role - An eRole_t of App or BootLoader to validate the internal data
* against. For a Bootloader this would be the value of App to
* read the application passed data.
*
* Returned value:
* OK - Indicates that the internal data has been copied to callers
* bootloader_app_shared_t structure.
*
* -EBADR - The Role or crc of the internal data was not valid. The copy
* did not occur.
*
****************************************************************************/
__EXPORT int bootloader_app_shared_read(bootloader_app_shared_t *shared, eRole_t role)
{
int rv = -EBADR;
bootloader_app_shared_t working;
read(&working);
if ((role == App ? working.signature == BOOTLOADER_COMMON_APP_SIGNATURE
: working.signature == BOOTLOADER_COMMON_BOOTLOADER_SIGNATURE)
&& (working.crc.ull == calulate_signature(&working))) {
*shared = working;
rv = OK;
}
return rv;
}
/****************************************************************************
* Name: bootloader_app_shared_write
*
* Description:
* Based on the role, this function will commit the data passed
* into the physical locations used to transfer the shared data to/from
* an application (internal data) .
*
* The functions will populate the signature and crc the data
* based on the provided Role.
*
* Input Parameters:
* shared - A pointer to a bootloader_app_shared_t data to commit to
* the internal data for passing to/from an application.
* role - An eRole_t of App or BootLoader to use in the internal data
* to be passed to/from an application. For a Bootloader this
* would be the value of Bootloader to write to the passed data.
* to the application via the internal data.
*
* Returned value:
* None.
*
****************************************************************************/
__EXPORT void bootloader_app_shared_write(bootloader_app_shared_t *shared, eRole_t role)
{
bootloader_app_shared_t working = *shared;
working.signature = (role == App ? BOOTLOADER_COMMON_APP_SIGNATURE : BOOTLOADER_COMMON_BOOTLOADER_SIGNATURE);
working.crc.ull = calulate_signature(&working);
write(&working);
}
/****************************************************************************
* Name: bootloader_app_shared_invalidate
*
* Description:
* Invalidates the data passed the physical locations used to transfer
* the shared data to/from an application (internal data) .
*
* The functions will invalidate the signature and crc and shoulf be used
* to prevent deja vu.
*
* Input Parameters:
* None.
*
* Returned value:
* None.
*
****************************************************************************/
__EXPORT void bootloader_app_shared_invalidate(void)
{
bootloader_app_shared_t working;
bootloader_app_shared_init(&working, Invalid);
write(&working);
}

View File

@@ -1,216 +0,0 @@
/****************************************************************************
*
* Copyright (c) 2015 PX4 Development Team. All rights reserved.
* Author: Ben Dyer <ben_dyer@mac.com>
* Pavel Kirienko <pavel.kirienko@zubax.com>
* David Sidrane <david_s5@nscdg.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name PX4 nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#pragma once
#include <nuttx/compiler.h>
__BEGIN_DECLS
/* Define the signature for the Application descriptor as 'APDesc' and a
* revision number of 00 used in app_descriptor_t
*/
#define APP_DESCRIPTOR_SIGNATURE_ID 'A','P','D','e','s','c'
#define APP_DESCRIPTOR_SIGNATURE_REV '0','0'
#define APP_DESCRIPTOR_SIGNATURE APP_DESCRIPTOR_SIGNATURE_ID, APP_DESCRIPTOR_SIGNATURE_REV
/* N.B. the .ld file must emit this sections */
# define boot_app_shared_section __attribute__((section(".app_descriptor")))
/* eRole defines the role of the bootloader_app_shared_t structure */
typedef enum eRole {
Invalid,
App,
BootLoader
} eRole_t;
/****************************************************************************
*
* Bootloader and Application shared structure.
*
* The data in this structure is passed in SRAM or the the CAN filter
* registers from bootloader to application and application to bootloader.
*
* Do not assume any mapping or location for the passing of this data
* that is done in the read and write routines and is abstracted by design.
*
* For reference, the following is performed based on eRole in API calls
* defined below:
*
* The application must write BOOTLOADER_COMMON_APP_SIGNATURE to the
* signature field when passing data to the bootloader; when the
* bootloader passes data to the application, it must write
* BOOTLOADER_COMMON_BOOTLOADER_SIGNATURE to the signature field.
*
* The CRC is calculated over the structure from signature to the
* last byte. The resulting values are then copied to the CAN filter
* registers by bootloader_app_shared_read and
* bootloader_app_shared_write.
*
****************************************************************************/
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wattributes"
typedef begin_packed_struct struct bootloader_app_shared_t {
union {
uint64_t ull;
uint32_t ul[2];
uint8_t valid;
} crc;
uint32_t signature;
uint32_t bus_speed;
uint32_t node_id;
} end_packed_struct bootloader_app_shared_t;
#pragma GCC diagnostic pop
/****************************************************************************
*
* Application firmware descriptor.
*
* This structure located by the linker script somewhere after the vector table.
* (within the first several kilobytes of the beginning address of the
* application);
*
* This structure must be aligned on an 8-byte boundary.
*
* The bootloader will scan through the application FLASH image until it
* finds the signature.
*
* The image_crc is calculated as follows:
* 1) All fields of this structure must be initialized with the correct
* information about the firmware image bin file
* (Here after refereed to as image)
* 2) image_crc set to 0;
* 3) The CRC 64 is calculated over the image from offset 0 up to and including the
* last byte of the image file.
* 4) The calculated CRC 64 is stored in image_crc
* 5) The new image file is then written to a file a ".img" extension.
*
****************************************************************************/
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wattributes"
#pragma GCC diagnostic ignored "-Wpacked"
typedef begin_packed_struct struct app_descriptor_t {
uint8_t signature[sizeof(uint64_t)];
uint64_t image_crc;
uint32_t image_size;
uint32_t vcs_commit;
uint8_t major_version;
uint8_t minor_version;
uint8_t reserved[6];
} end_packed_struct app_descriptor_t;
#pragma GCC diagnostic pop
/****************************************************************************
* Name: bootloader_app_shared_read
*
* Description:
* Based on the role requested, this function will conditionally populate
* a bootloader_app_shared_t structure from the physical locations used
* to transfer the shared data to/from an application (internal data) .
*
* The functions will only populate the structure and return a status
* indicating success, if the internal data has the correct signature as
* requested by the Role AND has a valid crc.
*
* Input Parameters:
* shared - A pointer to a bootloader_app_shared_t return the data in if
* the internal data is valid for the requested Role
* role - An eRole_t of App or BootLoader to validate the internal data
* against. For a Bootloader this would be the value of App to
* read the application passed data.
*
* Returned value:
* OK - Indicates that the internal data has been copied to callers
* bootloader_app_shared_t structure.
*
* -EBADR - The Role or crc of the internal data was not valid. The copy
* did not occur.
*
****************************************************************************/
int bootloader_app_shared_read(bootloader_app_shared_t *shared, eRole_t role);
/****************************************************************************
* Name: bootloader_app_shared_write
*
* Description:
* Based on the role, this function will commit the data passed
* into the physical locations used to transfer the shared data to/from
* an application (internal data) .
*
* The functions will populate the signature and crc the data
* based on the provided Role.
*
* Input Parameters:
* shared - A pointer to a bootloader_app_shared_t data to commit to
* the internal data for passing to/from an application.
* role - An eRole_t of App or BootLoader to use in the internal data
* to be passed to/from an application. For a Bootloader this
* would be the value of Bootloader to write to the passed data.
* to the application via the internal data.
*
* Returned value:
* None.
*
****************************************************************************/
void bootloader_app_shared_write(bootloader_app_shared_t *shared, eRole_t role);
/****************************************************************************
* Name: bootloader_app_shared_invalidate
*
* Description:
* Invalidates the data passed the physical locations used to transfer
* the shared data to/from an application (internal data) .
*
* The functions will invalidate the signature and crc and should be used
* to prevent deja vu.
*
* Input Parameters:
* None.
*
* Returned value:
* None.
*
****************************************************************************/
void bootloader_app_shared_invalidate(void);
__END_DECLS

View File

@@ -1,95 +0,0 @@
/****************************************************************************
*
* Copyright (c) 2015 PX4 Development Team. All rights reserved.
* Author: Ben Dyer <ben_dyer@mac.com>
* Pavel Kirienko <pavel.kirienko@zubax.com>
* David Sidrane <david_s5@nscdg.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name PX4 nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#pragma once
#define CRC16_INITIAL 0xFFFFu
#define CRC16_OUTPUT_XOR 0x0000u
#define CRC64_INITIAL 0xFFFFFFFFFFFFFFFFull
#define CRC64_OUTPUT_XOR 0xFFFFFFFFFFFFFFFFull
/****************************************************************************
* Name: crc16_add
*
* Description:
* Use to calculates a CRC-16-CCITT using the polynomial of
* 0x1021 by adding a value successive values.
*
* Input Parameters:
* crc - The running total of the crc 16
* value - The value to add
*
* Returned Value:
* The current crc16 with the value processed.
*
****************************************************************************/
uint16_t crc16_add(uint16_t crc, uint8_t value);
/****************************************************************************
* Name: crc16_signature
*
* Description:
* Calculates a CRC-16-CCITT using the crc16_add
* function
*
* Input Parameters:
* initial - The Initial value to uses as the crc's starting point
* length - The number of bytes to add to the crc
* bytes - A pointer to any array of length bytes
*
* Returned Value:
* The crc16 of the array of bytes
*
****************************************************************************/
uint16_t crc16_signature(uint16_t initial, size_t length, const uint8_t *bytes);
/****************************************************************************
* Name: crc64_add_word
*
* Description:
* Calculates a CRC-64-WE using the polynomial of 0x42F0E1EBA9EA3693
* See http://reveng.sourceforge.net/crc-catalogue/17plus.htm#crc.cat-bits.64
* Check: 0x62EC59E3F1A4F00A
*
* Input Parameters:
* crc - The running total of the crc 64
* value - The value to add
*
* Returned Value:
* The current crc64 with the value processed.
*
****************************************************************************/
uint64_t crc64_add_word(uint64_t crc, uint32_t value);

View File

@@ -51,7 +51,8 @@
#include "timer.h"
#include "uavcan.h"
#include "can.h"
#include "crc.h"
#include <lib/systemlib/crc.h>
#define CAN_REQUEST_TIMEOUT 1000
#define ANY_NODE_ID 0

View File

@@ -55,8 +55,9 @@
#include "can.h"
#include "uavcan.h"
#include "random.h"
#include "crc.h"
#include "boot_app_shared.h"
#include <drivers/bootloaders/boot_app_shared.h>
#include <lib/systemlib/crc.h>
//#define DEBUG_APPLICATION_INPLACE 1 /* Never leave defined */
#define DEBUG_NO_FW_UPDATE 1 /* With DEBUG_APPLICATION_INPLACE

View File

@@ -1,138 +0,0 @@
/****************************************************************************
*
* Copyright (c) 2015 PX4 Development Team. All rights reserved.
* Author: Ben Dyer <ben_dyer@mac.com>
* Pavel Kirienko <pavel.kirienko@zubax.com>
* David Sidrane <david_s5@nscdg.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name PX4 nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#include <stdint.h>
#include <stdlib.h>
#include "crc.h"
/****************************************************************************
* Name: crc16_add
*
* Description:
* Use to calculates a CRC-16-CCITT using the polynomial of
* 0x1021 by adding a value successive values.
*
* Input Parameters:
* crc - The running total of the crc 16
* value - The value to add
*
* Returned Value:
* The current crc16 with the value processed.
*
****************************************************************************/
uint16_t crc16_add(uint16_t crc, uint8_t value)
{
uint32_t i;
const uint16_t poly = 0x1021u;
crc ^= (uint16_t)((uint16_t) value << 8u);
for (i = 0; i < 8; i++) {
if (crc & (1u << 15u)) {
crc = (uint16_t)((crc << 1u) ^ poly);
} else {
crc = (uint16_t)(crc << 1u);
}
}
return crc;
}
/****************************************************************************
* Name: crc16_signature
*
* Description:
* Calculates a CRC-16-CCITT using the crc16_add
* function
*
* Input Parameters:
* initial - The Initial value to uses as the crc's starting point
* length - The number of bytes to add to the crc
* bytes - A pointer to any array of length bytes
*
* Returned Value:
* The crc16 of the array of bytes
*
****************************************************************************/
uint16_t crc16_signature(uint16_t initial, size_t length, const uint8_t *bytes)
{
size_t i;
for (i = 0u; i < length; i++) {
initial = crc16_add(initial, bytes[i]);
}
return initial ^ CRC16_OUTPUT_XOR;
}
/****************************************************************************
* Name: crc64_add_word
*
* Description:
* Calculates a CRC-64-WE using the polynomial of 0x42F0E1EBA9EA3693
* See http://reveng.sourceforge.net/crc-catalogue/17plus.htm#crc.cat-bits.64
* Check: 0x62EC59E3F1A4F00A
*
* Input Parameters:
* crc - The running total of the crc 64
* value - The value to add
*
* Returned Value:
* The current crc64 with the value processed.
*
****************************************************************************/
__EXPORT uint64_t crc64_add_word(uint64_t crc, uint32_t value)
{
uint32_t i, j;
uint8_t byte;
const uint64_t poly = 0x42F0E1EBA9EA3693ull;
for (j = 0; j < 4; j++) {
byte = ((uint8_t *) &value)[j];
crc ^= (uint64_t) byte << 56u;
for (i = 0; i < 8; i++) {
if (crc & (1ull << 63u)) {
crc = (uint64_t)(crc << 1u) ^ poly;
} else {
crc = (uint64_t)(crc << 1u);
}
}
}
return crc;
}

View File

@@ -34,10 +34,6 @@
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
@@ -47,17 +43,14 @@
#include "stm32.h"
#include <errno.h>
#include "boot_app_shared.h"
#include "systemlib/crc.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#include "boot_app_shared.h"
#include <lib/systemlib/crc.h>
#define BOOTLOADER_COMMON_APP_SIGNATURE 0xB0A04150u
#define BOOTLOADER_COMMON_BOOTLOADER_SIGNATURE 0xB0A0424Cu
/* CAN_FiRx where (i=0..27|13, x=1, 2)
* STM32_CAN1_FIR(i,x)
* Using i = 2 does not requier there block
@@ -73,30 +66,6 @@
#define CRC_H 1
#define CRC_L 0
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: read
****************************************************************************/
inline static void read(bootloader_app_shared_t *pshared)
{
pshared->signature = getreg32(signature_LOC);
@@ -104,13 +73,8 @@ inline static void read(bootloader_app_shared_t *pshared)
pshared->node_id = getreg32(node_id_LOC);
pshared->crc.ul[CRC_L] = getreg32(crc_LoLOC);
pshared->crc.ul[CRC_H] = getreg32(crc_HiLOC);
}
/****************************************************************************
* Name: write
****************************************************************************/
inline static void write(bootloader_app_shared_t *pshared)
{
putreg32(pshared->signature, signature_LOC);
@@ -118,13 +82,8 @@ inline static void write(bootloader_app_shared_t *pshared)
putreg32(pshared->node_id, node_id_LOC);
putreg32(pshared->crc.ul[CRC_L], crc_LoLOC);
putreg32(pshared->crc.ul[CRC_H], crc_HiLOC);
}
/****************************************************************************
* Name: calulate_signature
****************************************************************************/
static uint64_t calulate_signature(bootloader_app_shared_t *pshared)
{
uint64_t crc;
@@ -135,9 +94,6 @@ static uint64_t calulate_signature(bootloader_app_shared_t *pshared)
return crc;
}
/****************************************************************************
* Name: bootloader_app_shared_init
****************************************************************************/
static void bootloader_app_shared_init(bootloader_app_shared_t *pshared, eRole_t role)
{
memset(pshared, 0, sizeof(bootloader_app_shared_t));
@@ -148,12 +104,8 @@ static void bootloader_app_shared_init(bootloader_app_shared_t *pshared, eRole_t
App ? BOOTLOADER_COMMON_APP_SIGNATURE :
BOOTLOADER_COMMON_BOOTLOADER_SIGNATURE);
}
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: bootloader_app_shared_read
*
@@ -181,10 +133,7 @@ static void bootloader_app_shared_init(bootloader_app_shared_t *pshared, eRole_t
* did not occur.
*
****************************************************************************/
__EXPORT
int bootloader_app_shared_read(bootloader_app_shared_t *shared,
eRole_t role)
__EXPORT int bootloader_app_shared_read(bootloader_app_shared_t *shared, eRole_t role)
{
int rv = -EBADR;
bootloader_app_shared_t working;
@@ -224,18 +173,12 @@ int bootloader_app_shared_read(bootloader_app_shared_t *shared,
* None.
*
****************************************************************************/
__EXPORT
void bootloader_app_shared_write(bootloader_app_shared_t *shared,
eRole_t role)
__EXPORT void bootloader_app_shared_write(bootloader_app_shared_t *shared, eRole_t role)
{
bootloader_app_shared_t working = *shared;
working.signature =
(role ==
App ? BOOTLOADER_COMMON_APP_SIGNATURE :
BOOTLOADER_COMMON_BOOTLOADER_SIGNATURE);
working.signature = (role == App ? BOOTLOADER_COMMON_APP_SIGNATURE : BOOTLOADER_COMMON_BOOTLOADER_SIGNATURE);
working.crc.ull = calulate_signature(&working);
write(&working);
}
/****************************************************************************
@@ -255,9 +198,7 @@ void bootloader_app_shared_write(bootloader_app_shared_t *shared,
* None.
*
****************************************************************************/
__EXPORT
void bootloader_app_shared_invalidate(void)
__EXPORT void bootloader_app_shared_invalidate(void)
{
bootloader_app_shared_t working;
bootloader_app_shared_init(&working, Invalid);

View File

@@ -36,18 +36,10 @@
#pragma once
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/compiler.h>
__BEGIN_DECLS
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Define the signature for the Application descriptor as 'APDesc' and a
* revision number of 00 used in app_descriptor_t
*/
@@ -59,10 +51,6 @@ __BEGIN_DECLS
/* N.B. the .ld file must emit this sections */
# define boot_app_shared_section __attribute__((section(".app_descriptor")))
/****************************************************************************
* Public Type Definitions
****************************************************************************/
/* eRole defines the role of the bootloader_app_shared_t structure */
typedef enum eRole {
@@ -149,13 +137,6 @@ typedef begin_packed_struct struct app_descriptor_t {
} end_packed_struct app_descriptor_t;
#pragma GCC diagnostic pop
/****************************************************************************
* Global Variables
****************************************************************************/
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: bootloader_app_shared_read
*
@@ -184,8 +165,7 @@ typedef begin_packed_struct struct app_descriptor_t {
*
****************************************************************************/
int bootloader_app_shared_read(bootloader_app_shared_t *shared,
eRole_t role);
int bootloader_app_shared_read(bootloader_app_shared_t *shared, eRole_t role);
/****************************************************************************
* Name: bootloader_app_shared_write
@@ -211,8 +191,7 @@ int bootloader_app_shared_read(bootloader_app_shared_t *shared,
*
****************************************************************************/
void bootloader_app_shared_write(bootloader_app_shared_t *shared,
eRole_t role);
void bootloader_app_shared_write(bootloader_app_shared_t *shared, eRole_t role);
/****************************************************************************
* Name: bootloader_app_shared_invalidate