Skip to content

Commit

Permalink
Make the size of the code properly include the version information
Browse files Browse the repository at this point in the history
  • Loading branch information
leptun committed Mar 9, 2024
1 parent c2d4f8a commit 956b335
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ if(CMAKE_CROSSCOMPILING)
# limit the text section to 28K (32K - 4k reserved for the bootloader)
target_link_options(firmware PUBLIC -Wl,--defsym=__TEXT_REGION_LENGTH__=28K)

# place the user_signatures section at the end of the user flash
target_link_options(firmware PUBLIC -Wl,--defsym=__USER_SIGNATURE_REGION_LENGTH__=6)
# place the version information at the end of the app flash
target_link_options(firmware PUBLIC -Wl,--defsym=__VERSION_REGION_LENGTH__=6)

# generate firmware .hex file
objcopy(firmware "ihex" ".hex")
Expand Down
10 changes: 9 additions & 1 deletion src/avr5.xn
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ MEMORY
fuse (rw!x) : ORIGIN = 0x820000, LENGTH = __FUSE_REGION_LENGTH__
lock (rw!x) : ORIGIN = 0x830000, LENGTH = __LOCK_REGION_LENGTH__
signature (rw!x) : ORIGIN = 0x840000, LENGTH = __SIGNATURE_REGION_LENGTH__
user_signatures (r) : ORIGIN = __TEXT_REGION_ORIGIN__ + __TEXT_REGION_LENGTH__ - __USER_SIGNATURE_REGION_LENGTH__, LENGTH = __USER_SIGNATURE_REGION_LENGTH__
user_signatures (rw!x) : ORIGIN = 0x850000, LENGTH = __USER_SIGNATURE_REGION_LENGTH__
version (r) : ORIGIN = __TEXT_REGION_ORIGIN__ + __TEXT_REGION_LENGTH__ - __VERSION_REGION_LENGTH__, LENGTH = __VERSION_REGION_LENGTH__
}
SECTIONS
{
Expand Down Expand Up @@ -166,6 +167,13 @@ SECTIONS
KEEP (*(.fini0))
_etext = . ;
} > text

/* It is placed in .bootloader so that avr-size correctly includes it in the Program size calculation */
.bootloader :
{
KEEP(*(.version*))
} > version

.data :
{
PROVIDE (__data_start = .) ;
Expand Down
4 changes: 3 additions & 1 deletion src/version.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#include <version.hpp>


// Define structure at the end of flash which contains information about the version of the firmware
struct Signatures {
uint8_t project_major;
uint8_t project_minor;
uint16_t project_revision;
uint16_t project_build_number;
} const signatures __attribute__((section(".user_signatures"), used)) = {
} static constexpr signatures __attribute__((section(".version"), used)) = {
PROJECT_VERSION_MAJOR,
PROJECT_VERSION_MINOR,
PROJECT_VERSION_REV,
Expand Down

0 comments on commit 956b335

Please sign in to comment.