Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow temporarily disabling device protection #2770

Merged
merged 35 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
122fb42
Allow temporarily disabling protected device mode via a backup register
sergeuz May 16, 2024
8f20dec
Add a control request for temporarily disabling device protection
sergeuz May 20, 2024
8241e99
Minor fixes
sergeuz May 21, 2024
dd232bf
Add timeout for confirmation request
sergeuz May 23, 2024
ad2609d
Minor bugfixes and refactoring
sergeuz May 23, 2024
92634b9
Use a fake server key for testing
sergeuz May 24, 2024
7527d73
Bugfixes
sergeuz May 24, 2024
fc1568d
Allow disabling device protection on the fly
sergeuz May 29, 2024
126ce4d
Include server nonce in device signature
sergeuz May 29, 2024
276ae45
Check if the device is protected on every log operation
sergeuz May 30, 2024
e6b0f95
Remove the test key
sergeuz Jun 7, 2024
6ef4697
Bugfixes
sergeuz Jun 7, 2024
5145cb2
Regenerate Protobuf definitions; update submodule refs
sergeuz Jun 10, 2024
d4f6c0e
Bugfix
sergeuz Jun 10, 2024
49cd770
Regenerate Protobuf definitions; update submodule refs
sergeuz Jun 10, 2024
06ed956
Add device/server key fingerprints; minor refactoring
sergeuz Jun 10, 2024
0ea7f26
Minor fix
sergeuz Jun 10, 2024
0d0b6a4
Regenerate Protobuf definitions; update submodule refs
sergeuz Jun 10, 2024
171a6de
Minor fixes
sergeuz Jun 10, 2024
6633aca
Bugfix
sergeuz Jun 11, 2024
dd2f50c
Refactoring
sergeuz Jun 12, 2024
4cac07d
Do not disable logging when the device is protected
sergeuz Jun 12, 2024
46d4e6d
Disable Serial if the device is protected
sergeuz Jun 12, 2024
0b0a07f
Allow unprotecting the device over BLE
sergeuz Jun 14, 2024
f314d64
Fix GCC build
sergeuz Jun 14, 2024
2e07037
Fix newhal build
sergeuz Jun 14, 2024
03b1275
Fix rtl872x builds
sergeuz Jun 14, 2024
c116ce7
Clear the device protection override if the bootloader is not protected
sergeuz Jun 14, 2024
3c92c5d
Minor refactoring
sergeuz Jun 14, 2024
2a023fc
[gen3] disable IP_FRAG and IP_REASSEMBLY to save flash space
avtolstoy Jun 18, 2024
13605e3
Add a custom DfuSe command for entring safe mode
sergeuz Jun 18, 2024
dcf2c8f
[tracker] enable -fipa-pta (interprocedural pointer analysis and inte…
avtolstoy Jun 18, 2024
700bfc9
[build] extra -fdevirtualize-at-ltrans optimization for tracker
avtolstoy Jun 19, 2024
ad6f4d5
[build] clean up LTO usage
avtolstoy Jun 19, 2024
edefb7e
[build] more optimizations
avtolstoy Jun 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bootloader/src/nRF52840/nrf_it.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "hw_config.h"
#include "button_hal.h"
#include "hal_platform_nrf52840_config.h"
#include "security_mode.h"

extern void Timing_Decrement(void);

Expand Down Expand Up @@ -120,6 +121,7 @@ void UsageFault_Handler(void)
void SysTick_Handler(void)
{
System1MsTick();
security_mode_notify_system_tick();
Timing_Decrement();

#if HAL_PLATFORM_BUTTON_DEBOUNCE_IN_SYSTICK
Expand Down
11 changes: 10 additions & 1 deletion bootloader/src/nRF52840/usbd_dfu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include <cstring>
#include "hal_irq_flag.h"
#include "security_mode.h"
#include "core_hal.h"
#include "syshealth_hal.h"

using namespace particle::usbd;
using namespace particle::usbd::dfu;
Expand Down Expand Up @@ -215,8 +217,9 @@ int DfuClassDriver::handleDfuUpload(SetupRequest* req) {
transferBuf_[0] = detail::DFUSE_COMMAND_GET_COMMAND;
transferBuf_[1] = detail::DFUSE_COMMAND_SET_ADDRESS_POINTER;
transferBuf_[2] = detail::DFUSE_COMMAND_ERASE;
transferBuf_[3] = detail::DFUSE_COMMAND_ENTER_SAFE_MODE;
setState(detail::dfuIDLE);
dev_->setupReply(req, transferBuf_, 3);
dev_->setupReply(req, transferBuf_, 4);
} else if (req_.wValue > 1) {
/* Normal request */
setState(detail::dfuUPLOAD_IDLE);
Expand Down Expand Up @@ -488,6 +491,12 @@ int DfuClassDriver::inDone(uint8_t ep, unsigned status) {
}
break;
}
case detail::DFUSE_COMMAND_ENTER_SAFE_MODE: {
HAL_Core_Write_Backup_Register(BKP_DR_01, ENTER_SAFE_MODE_APP_REQUEST);
setState(detail::dfuMANIFEST_SYNC);
setStatus(detail::OK);
break;
}
case detail::DFUSE_COMMAND_READ_UNPROTECT: {
/* Unsupported */
setError(detail::errUNKNOWN);
Expand Down
3 changes: 2 additions & 1 deletion bootloader/src/nRF52840/usbd_dfu.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ enum DfuseCommand {
DFUSE_COMMAND_GET_COMMAND = 0x00,
DFUSE_COMMAND_SET_ADDRESS_POINTER = 0x21,
DFUSE_COMMAND_ERASE = 0x41,
DFUSE_COMMAND_READ_UNPROTECT = 0x92
DFUSE_COMMAND_READ_UNPROTECT = 0x92,
DFUSE_COMMAND_ENTER_SAFE_MODE = 0xfa /* Particle's extension */
};

#pragma pack(push, 1)
Expand Down
2 changes: 2 additions & 0 deletions bootloader/src/rtl872x/rtl_it.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "button_hal.h"
#include "hal_platform_config.h"
#include "interrupts_irq.h"
#include "security_mode.h"

extern void Timing_Decrement(void);

Expand Down Expand Up @@ -170,6 +171,7 @@ void SecureFault_Handler(void) {
void SysTick_Handler(void)
{
System1MsTick();
security_mode_notify_system_tick();
Timing_Decrement();

#if HAL_PLATFORM_BUTTON_DEBOUNCE_IN_SYSTICK
Expand Down
11 changes: 10 additions & 1 deletion bootloader/src/rtl872x/usbd_dfu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include "hal_irq_flag.h"
#include <algorithm>
#include "security_mode.h"
#include "core_hal.h"
#include "syshealth_hal.h"

using namespace particle::usbd;
using namespace particle::usbd::dfu;
Expand Down Expand Up @@ -216,8 +218,9 @@ int DfuClassDriver::handleDfuUpload(SetupRequest* req) {
transferBuf_[0] = detail::DFUSE_COMMAND_GET_COMMAND;
transferBuf_[1] = detail::DFUSE_COMMAND_SET_ADDRESS_POINTER;
transferBuf_[2] = detail::DFUSE_COMMAND_ERASE;
transferBuf_[3] = detail::DFUSE_COMMAND_ENTER_SAFE_MODE;
setState(detail::dfuIDLE);
dev_->setupReply(req, transferBuf_, 3);
dev_->setupReply(req, transferBuf_, 4);
} else if (req_.wValue > 1) {
/* Normal request */
setState(detail::dfuUPLOAD_IDLE);
Expand Down Expand Up @@ -473,6 +476,12 @@ int DfuClassDriver::dataIn(unsigned ep, particle::usbd::EndpointEvent ev, size_t
}
break;
}
case detail::DFUSE_COMMAND_ENTER_SAFE_MODE: {
HAL_Core_Write_Backup_Register(BKP_DR_01, ENTER_SAFE_MODE_APP_REQUEST);
setState(detail::dfuMANIFEST_SYNC);
setStatus(detail::OK);
break;
}
case detail::DFUSE_COMMAND_READ_UNPROTECT: {
/* Unsupported */
setError(detail::errUNKNOWN);
Expand Down
3 changes: 2 additions & 1 deletion bootloader/src/rtl872x/usbd_dfu.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ enum DfuseCommand {
DFUSE_COMMAND_GET_COMMAND = 0x00,
DFUSE_COMMAND_SET_ADDRESS_POINTER = 0x21,
DFUSE_COMMAND_ERASE = 0x41,
DFUSE_COMMAND_READ_UNPROTECT = 0x92
DFUSE_COMMAND_READ_UNPROTECT = 0x92,
DFUSE_COMMAND_ENTER_SAFE_MODE = 0xfa /* Particle's extension */
};

#pragma pack(push, 1)
Expand Down
16 changes: 16 additions & 0 deletions build/arm-tools.mk
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,19 @@ CPPFLAGS += $(LTO_FLAGS) -fno-use-cxa-atexit
CONLYFLAGS += $(LTO_FLAGS)
LDFLAGS += -fno-use-cxa-atexit

USE_LTO=0

ifneq ($(FORCE_LTO),)
USE_LTO=1
endif

ifeq ($(COMPILE_LTO),y)
USE_LTO=1
endif

ifeq ($(USE_LTO),1)
LDFLAGS += -flto -Os -fuse-linker-plugin
CFLAGS += -fuse-linker-plugin
else
# Be explicit and disable LTO
LDFLAGS += -fno-lto
Expand All @@ -112,6 +123,11 @@ endif
# We are using newlib-nano for all the platforms
CFLAGS += --specs=nano.specs

ifneq ($(LTO_EXTRA_OPTIMIZATIONS),)
CFLAGS += -fipa-pta -fdevirtualize-at-ltrans -fdevirtualize-speculatively -flto-partition=balanced -fmerge-all-constants
LDFLAGS += -fipa-pta -fdevirtualize-at-ltrans -fdevirtualize-speculatively -flto-partition=balanced -fmerge-all-constants
endif

# Check if the compiler version is the minimum required
version_to_number=$(shell v=$1; v=($${v//./ }); echo $$((v[0] * 10000 + v[1] * 100 + v[2])))
get_major_version=$(shell v=$1; v=($${v//./ }); echo $${v[0]})
Expand Down
2 changes: 0 additions & 2 deletions hal/inc/bootloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ int bootloader_update(const void* bootloader_image, unsigned length);
// Make sure we have only one function to retrieve the bootloader version going forward.
uint16_t bootloader_get_version(void);

int bootloader_init_security_mode(void* reserved);

#ifdef __cplusplus
}
#endif
Expand Down
10 changes: 5 additions & 5 deletions hal/inc/hal_dynalib_usb.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ DYNALIB_FN(0, hal_usb, HAL_USB_USART_Init, void(HAL_USB_USART_Serial, const HAL_
DYNALIB_FN(1, hal_usb, HAL_USB_USART_Begin, void(HAL_USB_USART_Serial, uint32_t, void *))
DYNALIB_FN(2, hal_usb, HAL_USB_USART_End, void(HAL_USB_USART_Serial))
DYNALIB_FN(3, hal_usb, HAL_USB_USART_Baud_Rate, unsigned int(HAL_USB_USART_Serial))
DYNALIB_FN(4, hal_usb, HAL_USB_USART_Available_Data, int32_t(HAL_USB_USART_Serial))
DYNALIB_FN(5, hal_usb, HAL_USB_USART_Available_Data_For_Write, int32_t(HAL_USB_USART_Serial))
DYNALIB_FN(6, hal_usb, HAL_USB_USART_Receive_Data, int32_t(HAL_USB_USART_Serial, uint8_t))
DYNALIB_FN(7, hal_usb, HAL_USB_USART_Send_Data, int32_t(HAL_USB_USART_Serial, uint8_t))
DYNALIB_FN(8, hal_usb, HAL_USB_USART_Flush_Data, void(HAL_USB_USART_Serial))
DYNALIB_FN_WRAP(4, hal_usb, HAL_USB_USART_Available_Data, protected, int32_t(HAL_USB_USART_Serial))
DYNALIB_FN_WRAP(5, hal_usb, HAL_USB_USART_Available_Data_For_Write, protected, int32_t(HAL_USB_USART_Serial))
DYNALIB_FN_WRAP(6, hal_usb, HAL_USB_USART_Receive_Data, protected, int32_t(HAL_USB_USART_Serial, uint8_t))
DYNALIB_FN_WRAP(7, hal_usb, HAL_USB_USART_Send_Data, protected, int32_t(HAL_USB_USART_Serial, uint8_t))
DYNALIB_FN_WRAP(8, hal_usb, HAL_USB_USART_Flush_Data, protected, void(HAL_USB_USART_Serial))
DYNALIB_FN(9, hal_usb, HAL_USB_USART_Is_Enabled, bool(HAL_USB_USART_Serial))
DYNALIB_FN(10, hal_usb, HAL_USB_USART_Is_Connected, bool(HAL_USB_USART_Serial))
DYNALIB_FN(11, hal_usb, HAL_USB_USART_LineCoding_BitRate_Handler, int32_t(void (*handler)(uint32_t bitRate), void* reserved))
Expand Down
12 changes: 7 additions & 5 deletions hal/inc/usb_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
#include "hw_config.h"
#endif

#include "security_mode.h"

#ifdef __cplusplus
extern "C" {
#endif
Expand Down Expand Up @@ -204,11 +206,11 @@ void HAL_USB_USART_Init(HAL_USB_USART_Serial serial, const HAL_USB_USART_Config*
void HAL_USB_USART_Begin(HAL_USB_USART_Serial serial, uint32_t baud, void *reserved);
void HAL_USB_USART_End(HAL_USB_USART_Serial serial);
unsigned int HAL_USB_USART_Baud_Rate(HAL_USB_USART_Serial serial);
int32_t HAL_USB_USART_Available_Data(HAL_USB_USART_Serial serial);
int32_t HAL_USB_USART_Available_Data_For_Write(HAL_USB_USART_Serial serial);
int32_t HAL_USB_USART_Receive_Data(HAL_USB_USART_Serial serial, uint8_t peek);
int32_t HAL_USB_USART_Send_Data(HAL_USB_USART_Serial serial, uint8_t data);
void HAL_USB_USART_Flush_Data(HAL_USB_USART_Serial serial);
SECURITY_MODE_PROTECTED_FN(int32_t, HAL_USB_USART_Available_Data, (HAL_USB_USART_Serial serial));
SECURITY_MODE_PROTECTED_FN(int32_t, HAL_USB_USART_Available_Data_For_Write, (HAL_USB_USART_Serial serial));
SECURITY_MODE_PROTECTED_FN(int32_t, HAL_USB_USART_Receive_Data, (HAL_USB_USART_Serial serial, uint8_t peek));
SECURITY_MODE_PROTECTED_FN(int32_t, HAL_USB_USART_Send_Data, (HAL_USB_USART_Serial serial, uint8_t data));
SECURITY_MODE_PROTECTED_FN(void, HAL_USB_USART_Flush_Data, (HAL_USB_USART_Serial serial));
bool HAL_USB_USART_Is_Enabled(HAL_USB_USART_Serial serial);
bool HAL_USB_USART_Is_Connected(HAL_USB_USART_Serial serial);
int32_t HAL_USB_USART_LineCoding_BitRate_Handler(void (*handler)(uint32_t bitRate), void* reserved);
Expand Down
2 changes: 1 addition & 1 deletion hal/src/nRF52840/ble_hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@ int BleObject::BleGap::setDeviceAddress(const hal_ble_addr_t* address) const {

int BleObject::BleGap::getDeviceAddress(hal_ble_addr_t* address) const {
CHECK_TRUE(address, SYSTEM_ERROR_INVALID_ARGUMENT);
ble_gap_addr_t localAddr;
ble_gap_addr_t localAddr = {};
int ret = sd_ble_gap_addr_get(&localAddr);
CHECK_NRF_RETURN(ret, nrf_system_error(ret));
*address = toHalAddress(localAddr);
Expand Down
13 changes: 0 additions & 13 deletions hal/src/nRF52840/bootloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,3 @@ uint16_t bootloader_get_version(void)
}
return info.module_version;
}

int bootloader_init_security_mode(void* reserved) {
CHECK_TRUE(FLASH_VerifyCRC32(FLASH_INTERNAL, BOOTLOADER_ADDR, FLASH_ModuleLength(FLASH_INTERNAL, BOOTLOADER_ADDR)), SYSTEM_ERROR_BAD_DATA);
module_info_security_mode_ext_t ext = {};
ext.ext.length = sizeof(ext);
CHECK(security_mode_find_extension(HAL_STORAGE_ID_INTERNAL_FLASH, BOOTLOADER_ADDR, &ext));

if (ext.security_mode == MODULE_INFO_SECURITY_MODE_PROTECTED) {
security_mode_set(ext.security_mode, nullptr);
}

return 0;
}
4 changes: 2 additions & 2 deletions hal/src/nRF52840/lwip/lwipopts.h
Original file line number Diff line number Diff line change
Expand Up @@ -451,14 +451,14 @@ void sys_unlock_tcpip_core(void);
* this option does not affect outgoing packet sizes, which can be controlled
* via IP_FRAG.
*/
#define IP_REASSEMBLY (PLATFORM_ID != PLATFORM_TRACKER)
#define IP_REASSEMBLY (0)

/**
* IP_FRAG==1: Fragment outgoing IP packets if their size exceeds MTU. Note
* that this option does not affect incoming packet sizes, which can be
* controlled via IP_REASSEMBLY.
*/
#define IP_FRAG (PLATFORM_ID != PLATFORM_TRACKER)
#define IP_FRAG (0)

/**
* IP_OPTIONS_ALLOWED: Defines the behavior for IP options.
Expand Down
27 changes: 27 additions & 0 deletions hal/src/nRF52840/usb_hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,20 @@ int32_t HAL_USB_USART_Available_Data(HAL_USB_USART_Serial serial) {
return usb_uart_available_rx_data();
}

int32_t HAL_USB_USART_Available_Data_protected(HAL_USB_USART_Serial serial) {
CHECK_SECURITY_MODE_PROTECTED();
return HAL_USB_USART_Available_Data(serial);
}

int32_t HAL_USB_USART_Available_Data_For_Write(HAL_USB_USART_Serial serial) {
return usb_uart_available_tx_data();
}

int32_t HAL_USB_USART_Available_Data_For_Write_protected(HAL_USB_USART_Serial serial) {
CHECK_SECURITY_MODE_PROTECTED();
return HAL_USB_USART_Available_Data_For_Write(serial);
}

int32_t HAL_USB_USART_Receive_Data(HAL_USB_USART_Serial serial, uint8_t peek) {
if (usb_uart_available_rx_data() == 0) {
return -1;
Expand All @@ -108,14 +118,31 @@ int32_t HAL_USB_USART_Receive_Data(HAL_USB_USART_Serial serial, uint8_t peek) {
}
}

int32_t HAL_USB_USART_Receive_Data_protected(HAL_USB_USART_Serial serial, uint8_t peek) {
CHECK_SECURITY_MODE_PROTECTED();
return HAL_USB_USART_Receive_Data(serial, peek);
}

int32_t HAL_USB_USART_Send_Data(HAL_USB_USART_Serial serial, uint8_t data) {
return usb_uart_send(&data, 1);
}

int32_t HAL_USB_USART_Send_Data_protected(HAL_USB_USART_Serial serial, uint8_t data) {
CHECK_SECURITY_MODE_PROTECTED();
return HAL_USB_USART_Send_Data(serial, data);
}

void HAL_USB_USART_Flush_Data(HAL_USB_USART_Serial serial) {
usb_uart_flush_tx_data();
}

void HAL_USB_USART_Flush_Data_protected(HAL_USB_USART_Serial serial) {
if (security_mode_get(NULL) == MODULE_INFO_SECURITY_MODE_PROTECTED) {
return;
}
HAL_USB_USART_Flush_Data(serial);
}

bool HAL_USB_USART_Is_Enabled(HAL_USB_USART_Serial serial) {
return usb_hal_is_enabled();
}
Expand Down
13 changes: 0 additions & 13 deletions hal/src/rtl872x/bootloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,3 @@ uint16_t bootloader_get_version(void)
// hard code to unblock porting work for now
return 1001;
}

int bootloader_init_security_mode(void* reserved) {
CHECK_TRUE(FLASH_VerifyCRC32(FLASH_INTERNAL, BOOTLOADER_ADDR, FLASH_ModuleLength(FLASH_INTERNAL, BOOTLOADER_ADDR)), SYSTEM_ERROR_BAD_DATA);
module_info_security_mode_ext_t ext = {};
ext.ext.length = sizeof(ext);
CHECK(security_mode_find_extension(HAL_STORAGE_ID_INTERNAL_FLASH, BOOTLOADER_ADDR, &ext));

if (ext.security_mode == MODULE_INFO_SECURITY_MODE_PROTECTED) {
security_mode_set(ext.security_mode, nullptr);
}

return 0;
}
27 changes: 27 additions & 0 deletions hal/src/rtl872x/usb_hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ int32_t HAL_USB_USART_Available_Data(HAL_USB_USART_Serial serial) {
return getCdcClassDriver().available();
}

int32_t HAL_USB_USART_Available_Data_protected(HAL_USB_USART_Serial serial) {
CHECK_SECURITY_MODE_PROTECTED();
return HAL_USB_USART_Available_Data(serial);
}

int32_t HAL_USB_USART_Available_Data_For_Write(HAL_USB_USART_Serial serial) {
if (serial != HAL_USB_USART_SERIAL) {
return SYSTEM_ERROR_INVALID_ARGUMENT;
Expand All @@ -180,6 +185,11 @@ int32_t HAL_USB_USART_Available_Data_For_Write(HAL_USB_USART_Serial serial) {
return getCdcClassDriver().availableForWrite();
}

int32_t HAL_USB_USART_Available_Data_For_Write_protected(HAL_USB_USART_Serial serial) {
CHECK_SECURITY_MODE_PROTECTED();
return HAL_USB_USART_Available_Data_For_Write(serial);
}

int32_t HAL_USB_USART_Receive_Data(HAL_USB_USART_Serial serial, uint8_t peek) {
if (serial != HAL_USB_USART_SERIAL) {
return SYSTEM_ERROR_INVALID_ARGUMENT;
Expand All @@ -197,6 +207,11 @@ int32_t HAL_USB_USART_Receive_Data(HAL_USB_USART_Serial serial, uint8_t peek) {
return r;
}

int32_t HAL_USB_USART_Receive_Data_protected(HAL_USB_USART_Serial serial, uint8_t peek) {
CHECK_SECURITY_MODE_PROTECTED();
return HAL_USB_USART_Receive_Data(serial, peek);
}

int32_t HAL_USB_USART_Send_Data(HAL_USB_USART_Serial serial, uint8_t data) {
if (serial != HAL_USB_USART_SERIAL) {
return SYSTEM_ERROR_INVALID_ARGUMENT;
Expand All @@ -220,13 +235,25 @@ int32_t HAL_USB_USART_Send_Data(HAL_USB_USART_Serial serial, uint8_t data) {
return -1;
}

int32_t HAL_USB_USART_Send_Data_protected(HAL_USB_USART_Serial serial, uint8_t data) {
CHECK_SECURITY_MODE_PROTECTED();
return HAL_USB_USART_Send_Data(serial, data);
}

void HAL_USB_USART_Flush_Data(HAL_USB_USART_Serial serial) {
if (serial != HAL_USB_USART_SERIAL) {
return;
}
return getCdcClassDriver().flush();
}

void HAL_USB_USART_Flush_Data_protected(HAL_USB_USART_Serial serial) {
if (security_mode_get(NULL) == MODULE_INFO_SECURITY_MODE_PROTECTED) {
return;
}
return HAL_USB_USART_Flush_Data(serial);
}

bool HAL_USB_USART_Is_Enabled(HAL_USB_USART_Serial serial) {
if (serial != HAL_USB_USART_SERIAL) {
return false;
Expand Down
4 changes: 3 additions & 1 deletion modules/argon/system-part1/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ NCP_FIRMWARE_MODULE_VERSION=4
DEPENDENCIES = newlib_nano modules/argon/user-part modules/argon/system-part1 dynalib services hal platform system wiring communication rt-dynalib crypto proto_defs
LIB_DEPENDENCIES = services system wiring communication hal platform crypto proto_defs

export FORCE_LTO=1

# newlib_nano is special in that it's linked automatically by the system, so no need to add it to the library path here
MAKE_DEPENDENCIES = newlib_nano $(LIB_DEPENDENCIES)
include ../modular.mk
Expand All @@ -29,7 +31,7 @@ include $(PROJECT_ROOT)/build/arm-tlm.mk

# NOTE: When compiling with LTO vTaskSwitchContext is getting linked out, despite the fact that it's
# marked as used.
LDFLAGS += -flto -Os -fuse-linker-plugin -Wl,--undefined=vTaskSwitchContext
LDFLAGS += -Wl,--undefined=vTaskSwitchContext

$(call check_modular)

Expand Down
Loading