|
rcbench
Servo and ESC test bench: panel, IOmcu and shared C
|
The panel's application image, read from memory: what it is, whether it is whole, and whether it is one this panel should run. More...
Go to the source code of this file.
Data Structures | |
| struct | fw_version_t |
| struct | fw_image_info_t |
Macros | |
| #define | FW_HEAD_BYTES 288u |
| Image header, first segment header and the application descriptor. | |
| #define | FW_IMAGE_MAGIC 0xE9u |
| #define | FW_CHIP_ESP32P4 0x0012u |
| esp_chip_id_t of the ESP32-P4: ESP_CHIP_ID_ESP32P4, 0x0012, in ESP-IDF's esp_app_format.h. | |
| #define | FW_DESC_MAGIC 0xABCD5432uL |
| #define | FW_PROJECT "rcbench-panel" |
| The CMake project name, which the descriptor carries. | |
| #define | FW_TEXT_MAX 32u |
| esp_app_desc_t.version and .project_name, terminator included. | |
| #define | FW_MAX_SEGMENTS 16u |
Enumerations | |
| enum | fw_err_t { FW_OK = 0 , FW_ERR_EMPTY , FW_ERR_SHORT , FW_ERR_TOO_BIG , FW_ERR_NOT_IMAGE , FW_ERR_CHIP , FW_ERR_NO_DESC , FW_ERR_PROJECT , FW_ERR_VERSION , FW_ERR_NO_HASH , FW_ERR_LENGTH , FW_ERR_HASH , FW_ERR_READ , FW_ERR_RUNNING , FW_ERR_MEMORY , FW_ERR_FLASH , FW_ERR_BUSY , FW_ERR_COUNT } |
| enum | fw_offer_t { FW_OFFER_NEWER = 0 , FW_OFFER_OLDER , FW_OFFER_REBUILD , FW_OFFER_INSTALLED } |
| What a checked image is to the panel running now. More... | |
Functions | |
| const char * | fw_err_str (fw_err_t e) |
The English name of e, for the console. | |
| bool | fw_version_parse (const char *text, size_t n, fw_version_t *out) |
Parses "MAJOR.MINOR.PATCH" from at most n bytes of text: digits only, each number 0 to 65535, terminated by '\0' or by the end of the field. | |
| int | fw_version_cmp (fw_version_t a, fw_version_t b) |
| Compares two versions. | |
| fw_err_t | fw_image_head (const uint8_t *head, uint32_t have, uint32_t bytes, uint32_t slot, fw_image_info_t *out) |
Checks the first have bytes of an image of bytes in all, for a slot of slot bytes: size, magic, chip, descriptor, project and version. | |
| fw_err_t | fw_image_check (const uint8_t *img, uint32_t bytes, uint32_t slot, fw_image_info_t *out) |
Checks a whole image of bytes at img for a slot of slot bytes: everything fw_image_head() checks, then that the segments add up to the image's length and that the last 32 bytes are the SHA-256 of all bytes before them. | |
| fw_offer_t | fw_offer (const fw_image_info_t *running, const fw_image_info_t *image) |
| Classifies a checked image against the panel running now. | |
| bool | fw_offer_installable (fw_offer_t o) |
| Whether an offer is one INSTALL may act on. | |
The panel's application image, read from memory: what it is, whether it is whole, and whether it is one this panel should run.
An ESP-IDF (Espressif Internet-of-Things Development Framework) app image starts with a 24-byte image header (first byte 0xE9, the chip ID at offset 12, the hash flag at 23), then the first segment's 8-byte header, then the 256-byte application descriptor (esp_app_desc_t) at offset 32: magic word 0xABCD5432, version at 48, project name at 80, the ELF (Executable and Linkable Format) file's SHA-256 at 176. The segments follow, then padding and a checksum byte to the next 16-byte boundary, then the SHA-256 of every byte before it.
Two depths of check. fw_image_head() reads the first FW_HEAD_BYTES, which is what an image says about itself. fw_image_check() reads the whole image and is the gate before the first erase: header, chip, descriptor, project name, version, length, size against the slot and the appended SHA-256. Neither knows where the bytes came from.
Pure C, no ESP-IDF.
SPDX-License-Identifier: MIT
| #define FW_DESC_MAGIC 0xABCD5432uL |
magic word of the application descriptor
| #define FW_IMAGE_MAGIC 0xE9u |
first byte of an ESP-IDF app image
| #define FW_MAX_SEGMENTS 16u |
ESP_IMAGE_MAX_SEGMENTS.
| enum fw_err_t |
Why an image is refused; FW_OK is none of them.
| enum fw_offer_t |
| const char * fw_err_str | ( | fw_err_t | e | ) |
The English name of e, for the console.
| e | the result |
| fw_err_t fw_image_check | ( | const uint8_t * | img, |
| uint32_t | bytes, | ||
| uint32_t | slot, | ||
| fw_image_info_t * | out ) |
Checks a whole image of bytes at img for a slot of slot bytes: everything fw_image_head() checks, then that the segments add up to the image's length and that the last 32 bytes are the SHA-256 of all bytes before them.
out is filled on FW_OK.
| img | the image |
| bytes | the length of the image |
| slot | the size of the slot, bytes |
| out | what the image says about itself |
| fw_err_t fw_image_head | ( | const uint8_t * | head, |
| uint32_t | have, | ||
| uint32_t | bytes, | ||
| uint32_t | slot, | ||
| fw_image_info_t * | out ) |
Checks the first have bytes of an image of bytes in all, for a slot of slot bytes: size, magic, chip, descriptor, project and version.
The length and the hash need the whole image and are not checked. have below FW_HEAD_BYTES with bytes at or above it reads as the source failing (FW_ERR_READ). out is filled on FW_OK.
| head | the first bytes of the image |
| have | the number of bytes at head |
| bytes | the length of the image |
| slot | the size of the slot, bytes |
| out | what the image says about itself |
| fw_offer_t fw_offer | ( | const fw_image_info_t * | running, |
| const fw_image_info_t * | image ) |
Classifies a checked image against the panel running now.
| running | the running image |
| image | the image offered |
| bool fw_offer_installable | ( | fw_offer_t | o | ) |
Whether an offer is one INSTALL may act on.
| o | the offer |
| int fw_version_cmp | ( | fw_version_t | a, |
| fw_version_t | b ) |
Compares two versions.
| a | the first version |
| b | the second version |
a is older, the same or newer | bool fw_version_parse | ( | const char * | text, |
| size_t | n, | ||
| fw_version_t * | out ) |
Parses "MAJOR.MINOR.PATCH" from at most n bytes of text: digits only, each number 0 to 65535, terminated by '\0' or by the end of the field.
Anything else ("4184795", "0.19.0-dirty", "1..2") is false.
| text | the version text |
| n | the bytes of text that may be read |
| out | the version, written on success |