Skip to content

Commit

Permalink
soc: arm: rpi_pico: Add basic support for binary info feature
Browse files Browse the repository at this point in the history
Enable embedding binary info to flash.
As a default, information collects from the build configuration.

It can override by the Kconfig configurations, such as

```
CONFIG_RP2_BINARY_INFO_PROGRAM_NAME_OVERRIDE=y
CONFIG_RP2_BINARY_INFO_PROGRAM_NAME="my program name"
```

Signed-off-by: TOKITA Hiroshi <[email protected]>
  • Loading branch information
soburi committed Feb 2, 2023
1 parent ca2d807 commit d0736a3
Show file tree
Hide file tree
Showing 7 changed files with 238 additions and 0 deletions.
16 changes: 16 additions & 0 deletions modules/hal_rpi_pico/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,20 @@ if(CONFIG_HAS_RPI_PICO)
COMPILE_FLAGS $<TARGET_PROPERTY:compiler,warning_no_pointer_arithmetic>
)

# binary info settings

zephyr_compile_definitions_ifdef(CONFIG_RP2_BINARY_INFO PICO_NO_BINARY_INFO=0)

get_filename_component(APPLICATION_SOURCE_DIR_BASE ${APPLICATION_SOURCE_DIR} NAME)
zephyr_compile_definitions_ifdef(CONFIG_RP2_BINARY_INFO APPLICATION_SOURCE_DIR_BASE="${APPLICATION_SOURCE_DIR_BASE}")

if (NOT "${flash_type}" STREQUAL "")
zephyr_compile_definitions_ifdef(CONFIG_RP2_BINARY_INFO PICO_BOOT_STAGE2_CHOOSE_${flash_type}=1)
endif()

if ("${PICO_SDK_VERSION_STRING}" STREQUAL "")
include(${ZEPHYR_HAL_RPI_PICO_MODULE_DIR}/pico_sdk_version.cmake)
endif()
zephyr_compile_definitions_ifdef(CONFIG_RP2_BINARY_INFO PICO_SDK_VERSION_STRING="${PICO_SDK_VERSION_STRING}")

endif()
5 changes: 5 additions & 0 deletions soc/arm/rpi_pico/rp2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@
zephyr_library()

zephyr_library_sources(soc.c)
zephyr_library_sources(binary_info.c)
zephyr_library_sources(binary_info_header.S)

zephyr_linker_sources(ROM_START SORT_KEY 0x0binary_info_header binary_info_header.ld)
zephyr_linker_sources(RODATA binary_info.ld)
81 changes: 81 additions & 0 deletions soc/arm/rpi_pico/rp2/Kconfig.soc
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,84 @@ config RP2_FLASH_AT25SF128A
help
Configure RP2 to use a AT25SF128A flash chip, or similar. Should be selected
by the board definition, not the user.
config RP2_BINARY_INFO
bool "Generate RaspberryPi Pico binary info"
default y
help
Binary info is able to embed machine readable information with the binary in FLASH.
It can read with picotool(https://github.com/raspberrypi/picotool).

config RP2_BINARY_INFO_RP_PROGRAM_BUILD_DATE_OVERRIDE
bool "Override build date in binary info"
help
Override RP_PROGRAM_BUILD_DATE_STRING field of binary info
by RP2_BINARY_INFO_RP_PROGRAM_BUILD_DATE value.
If not specified, set the value of __DATE__ macro to the field.

config RP2_BINARY_INFO_RP_PROGRAM_BUILD_DATE
string "Override string for build date in binary info"
depends on RP2_BINARY_INFO_RP_PROGRAM_BUILD_DATE_OVERRIDE

config RP2_BINARY_INFO_RP_PROGRAM_NAME_OVERRIDE
bool "Override program name in binary info"
help
Override RP_PROGRAM_NAME field of binary info
by RP2_BINARY_INFO_RP_PROGRAM_NAME value.
If not specified, set the directory name of the project to the field.

config RP2_BINARY_INFO_RP_PROGRAM_NAME
string "Override string for program name in binary info"
depends on RP2_BINARY_INFO_RP_PROGRAM_NAME_OVERRIDE

config RP2_BINARY_INFO_RP_PICO_BOARD_OVERRIDE
bool "Override board in binary info"
help
Override RP_PICO_BOARD field of binary info
by RP2_BINARY_INFO_RP_PICO_BOARD value.
If not specified, set the 'CONFIG_BOARD' value to this field.

config RP2_BINARY_INFO_RP_PICO_BOARD
string "Override string for board in binary info"
depends on RP2_BINARY_INFO_RP_PICO_BOARD_OVERRIDE

config RP2_BINARY_INFO_RP_SDK_VERSION_STRING_OVERRIDE
bool "Override sdk version in binary info"
help
Override RP_SDK_VERSION field of binary info
by RP2_BINARY_INFO_SDK_VERSION_STRING value.
If not specified, set the SDK version defined in the pico-sdk to the field.

config RP2_BINARY_INFO_RP_SDK_VERSION_STRING
string "Override string for sdk version in binary info"
depends on RP2_BINARY_INFO_RP_SDK_VERSION_STRING_OVERRIDE

config RP2_BINARY_INFO_RP_PROGRAM_VERSION_STRING_OVERRIDE
bool "Override program version in binary info"
help
Override RP_PROGRAM_VERSION_STRING field of binary info
by RP2_BINARY_INFO_RP_PROGRAM_VERSION_STRING value.
If not specified, set the zephyr's BUILD_VERSION definition to the field.

config RP2_BINARY_INFO_RP_PROGRAM_VERSION_STRING
string "Override string for program version in binary info"
depends on RP2_BINARY_INFO_RP_PROGRAM_VERSION_STRING_OVERRIDE

config RP2_BINARY_INFO_RP_PROGRAM_DESCRIPTION_OVERRIDE
bool "Override program descrpition in binary info"
help
Override RP_PROGRAM_DESCRIPTION field of binary info
by RP2_BINARY_INFO_RP_PROGRAM_DESCRIPTION value.
If not specified, set an empty string to the field.

config RP2_BINARY_INFO_RP_PROGRAM_DESCRIPTION
string "String for program description in binary info"

config RP2_BINARY_INFO_RP_PROGRAM_URL_OVERRIDE
bool "Override program url in binary info"
help
Override RP_PROGRAM_URL field of binary info
by RP2_BINARY_INFO_RP_PROGRAM_URL value.
If not specified, set an empty string to the field.

config RP2_BINARY_INFO_RP_PROGRAM_URL
string "String for program description in binary info"
95 changes: 95 additions & 0 deletions soc/arm/rpi_pico/rp2/binary_info.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* Copyright (c) 2023 TOKITA Hiroshi <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/kernel.h>
#include <soc.h>

#include <pico/binary_info.h>
#include <boot_stage2/config.h>

#include <version.h>

#ifdef CONFIG_RP2_BINARY_INFO_RP_PROGRAM_NAME_OVERRIDE
#define BI_PROGRAM_NAME CONFIG_RP2_BINARY_INFO_RP_PROGRAM_NAME
#else
#define BI_PROGRAM_NAME APPLICATION_SOURCE_DIR_BASE
#endif

#ifdef CONFIG_RP2_BINARY_INFO_RP_PICO_BOARD_OVERRIDE
#define BI_PICO_BOARD CONFIG_RP2_BINARY_INFO_RP_PICO_BOARD
#else
#define BI_PICO_BOARD CONFIG_BOARD
#endif

#ifdef CONFIG_RP2_BINARY_INFO_RP_SDK_VERSION_STRING_OVERRIDE
#define BI_SDK_VERSION_STRING CONFIG_RP2_BINARY_INFO_RP_SDK_VERSION_STRING
#else
#define BI_SDK_VERSION_STRING PICO_SDK_VERSION_STRING
#endif

#ifdef CONFIG_RP2_BINARY_INFO_RP_PROGRAM_VERSION_STRING_OVERRIDE
#define BI_PROGRAM_VERSION_STRING CONFIG_RP2_BINARY_INFO_RP_PROGRAM_VERSION_STRING
#else
#define BI_PROGRAM_VERSION_STRING STRINGIFY(BUILD_VERSION)
#endif

#ifdef CONFIG_RP2_BINARY_INFO_RP_PROGRAM_BUILD_DATE_OVERRIDE
#define BI_PROGRAM_BUILD_DATE CONFIG_RP2_BINARY_INFO_RP_PROGRAM_BUILD_DATE
#else
#define BI_PROGRAM_BUILD_DATE __DATE__
#endif

#ifdef CONFIG_RP2_BINARY_INFO_RP_PROGRAM_DESCRIPTION_OVERRIDE
#define BI_PROGRAM_DESCRIPTION CONFIG_RP2_BINARY_INFO_RP_PROGRAM_DESCRIPTION
#endif

#ifdef CONFIG_RP2_BINARY_INFO_RP_PROGRAM_URL_OVERRIDE
#define BI_PROGRAM_URL CONFIG_RP2_BINARY_INFO_RP_PROGRAM_URL
#endif

extern uint32_t __rom_region_end;
bi_decl(bi_binary_end((intptr_t)&__rom_region_end));

#ifdef BI_PROGRAM_NAME
bi_decl(bi_program_name((uint32_t)BI_PROGRAM_NAME));
#endif

#ifdef BI_PICO_BOARD
bi_decl(bi_string(BINARY_INFO_TAG_RASPBERRY_PI, BINARY_INFO_ID_RP_PICO_BOARD,
(uint32_t)BI_PICO_BOARD));
#endif

#ifdef BI_SDK_VERSION_STRING
bi_decl(bi_string(BINARY_INFO_TAG_RASPBERRY_PI, BINARY_INFO_ID_RP_SDK_VERSION,
(uint32_t)BI_SDK_VERSION_STRING));
#endif

#ifdef BI_PROGRAM_VERSION_STRING
bi_decl(bi_program_version_string((uint32_t)BI_PROGRAM_VERSION_STRING));
#endif

#ifdef BI_PROGRAM_DESCRIPTION
bi_decl(bi_program_description((uint32_t)BI_PROGRAM_DESCRIPTION));
#endif

#ifdef BI_PROGRAM_URL
bi_decl(bi_program_url((uint32_t)BI_PROGRAM_URL));
#endif

#ifdef BI_PROGRAM_BUILD_DATE
bi_decl(bi_program_build_date_string((uint32_t)BI_PROGRAM_BUILD_DATE));
#endif

#ifdef BI_BOOT_STAGE2_NAME
bi_decl(bi_string(BINARY_INFO_TAG_RASPBERRY_PI, BINARY_INFO_ID_RP_BOOT2_NAME,
(uint32_t)BI_BOOT_STAGE2_NAME));
#endif

#ifndef NDEBUG
bi_decl(bi_program_build_attribute((uint32_t) "Debug"));
#else
bi_decl(bi_program_build_attribute((uint32_t) "Release"));
#endif
11 changes: 11 additions & 0 deletions soc/arm/rpi_pico/rp2/binary_info.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright (c) 2023 TOKITA Hiroshi <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/

. = ALIGN(4);
__binary_info_start = .;
KEEP(*(.binary_info.keep.*))
*(.binary_info.*)
__binary_info_end = .;
23 changes: 23 additions & 0 deletions soc/arm/rpi_pico/rp2/binary_info_header.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (c) 2023 TOKITA Hiroshi <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/

#include "pico/binary_info/defs.h"

.section .binary_info_header

/* binary_info_header */
binary_info_header:
.word BINARY_INFO_MARKER_START
.word __binary_info_start
.word __binary_info_end
.word data_cpy_table // we may need to decode pointers that are in RAM at runtime.
.word BINARY_INFO_MARKER_END

.align 2

/* data_cpy_table */
data_cpy_table:
.word 0 /* centinel */
7 changes: 7 additions & 0 deletions soc/arm/rpi_pico/rp2/binary_info_header.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* Copyright (c) 2023 TOKITA Hiroshi <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/

KEEP (*(.binary_info_header))

0 comments on commit d0736a3

Please sign in to comment.