Skip to content

Commit

Permalink
feat(h7): firmware description header
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelcoeffic authored and gagarinlg committed Jan 10, 2025
1 parent 299b814 commit 98d8eea
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 0 deletions.
11 changes: 11 additions & 0 deletions radio/src/boards/generic_stm32/linker/firmware.ld
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,16 @@ SECTIONS
. = BOOTLOADER_SIZE;
} > REGION_BOOTLOADER

/* Used only with H7 */
.firmware_header :
{
KEEP(*(.fwdescription))
} > REGION_TEXT AT> REGION_TEXT_STORAGE

/* ISR vector to be loaded */
.isr_vector :
{
. = ALIGN(4);
_sisr_vector = .;
KEEP(*(.isr_vector))

Expand Down Expand Up @@ -44,4 +51,8 @@ SECTIONS
_text_load = LOADADDR(.text);

INCLUDE common_sections.ld

.text_end_section : {} > REGION_TEXT AT > REGION_TEXT_STORAGE
_firmware_length = LOADADDR(.text_end_section) - LOADADDR(.firmware_header);
_firmware_version = _text_load;
}
39 changes: 39 additions & 0 deletions radio/src/fw_desc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/

#include "fw_desc.h"

// Symbols from linker script
extern uint32_t _estack;
extern uint32_t _firmware_length;
extern uint32_t _firmware_version;

extern void Reset_Handler();

__attribute__((section(".fwdescription"), used))
firmware_description_t _fw_desc = {
.stack_address = &_estack,
.reset_handler = (void*)Reset_Handler,
.length = (uint32_t)&_firmware_length,
.version_ptr = (uintptr_t)&_firmware_version,
};


38 changes: 38 additions & 0 deletions radio/src/fw_desc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/

#pragma once

#include <stdint.h>

typedef struct {
// Allows the bootloader to load
// the firmware as if this would
// be the vector table.
void* stack_address;
void* reset_handler;

// TODO: insert some magic tag here
uint32_t length;
uint32_t version_ptr;
// .. and here ?
} firmware_description_t;

5 changes: 5 additions & 0 deletions radio/src/targets/common/arm/stm32/h7/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,9 @@ if(NOT NATIVE_BUILD)
# System and FreeRTOS port files
#
set(FIRMWARE_SRC ${FIRMWARE_SRC} $<TARGET_OBJECTS:freertos>)

#
# Firmware description
#
set(FIRMWARE_SRC ${FIRMWARE_SRC} fw_desc.c)
endif()

0 comments on commit 98d8eea

Please sign in to comment.