Skip to content

Commit a5819e4

Browse files
committed
Harden bootloader startup and build flags
Prevent the bootloader from jumping into an empty application image by checking the reset vector before branching, and surface that state in startup logging. Centralize RTL8201F/link-check and minimum remote-config build defines in `Validate.mk`, removing duplicated per-target defines. Also add an optional label to `debug::PrintBits`, apply small style cleanups, and remove the obsolete `pixeltype.json` content file.
1 parent 82edf05 commit a5819e4

11 files changed

Lines changed: 33 additions & 130 deletions

File tree

common/include/common/utils/utils_string.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ inline float Atof(const char* buffer, uint32_t size) {
8181
}
8282

8383
while (size > 0 && *p >= '0' && *p <= '9') {
84-
result = result * 10.0F + static_cast<float>(*p - '0');
84+
result = (result * 10.0F) + static_cast<float>(*p - '0');
8585
++p;
8686
--size;
8787
}

common/include/firmware/debug/debug_printbits.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
namespace debug {
3636
template <typename T>
3737
requires std::unsigned_integral<T>
38-
inline void PrintBits(T value) {
38+
inline void PrintBits(T value, const char* string = nullptr) {
3939
if constexpr (!config::kDumpEnabled) {
4040
return;
4141
}
@@ -46,7 +46,10 @@ inline void PrintBits(T value) {
4646

4747
static_assert(sizeof(T) <= sizeof(unsigned));
4848

49-
printf("%.*x ", kHexDigits, static_cast<unsigned>(value));
49+
if (string != nullptr) {
50+
printf("%s :", string);
51+
}
52+
printf("0x%.*x ", kHexDigits, static_cast<unsigned>(value));
5053

5154
for (int bit_number = kMaxBitIndex; bit_number >= 0; --bit_number) {
5255
const auto kMask = static_cast<T>(1) << bit_number;

common/make/gd32/Validate.mk

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ endif
2424

2525
ifeq ($(findstring CONFIG_REMOTECONFIG_MINIMUM,$(FLAGS)),CONFIG_REMOTECONFIG_MINIMUM)
2626
DEFINES+=-DCONFIG_NET_APPS_NO_MDNS
27+
DEFINES+=-DCONFIG_UDP_NO_OPTIMIZE
28+
DEFINES+=-DDISABLE_RTC
2729
else
2830
ifeq ($(findstring NO_EMAC,$(FLAGS)),NO_EMAC)
2931
else
@@ -56,8 +58,23 @@ ifdef FATFS_MKFS
5658
DEFINES+=-DCONFIG_FATFS_MKFS
5759
endif
5860

61+
# Hardware Scenario Flag Condition Resulting Compiler Definitions (DEFINES)
62+
# Using RTL8201F ENET_LINK_CHECK is missing -DRTL8201F_LED1_LINK_ALL -DENET_LINK_CHECK_USE_INT (Uses Interrupts)
63+
# Using RTL8201F ENET_LINK_CHECK is present -DRTL8201F_LED1_LINK_ALL
64+
# Other Hardware Any -DENET_LINK_CHECK_REG_POLL (Uses Polling)
65+
66+
ifneq ($(findstring RTL8201F,$(FLAGS)),)
67+
DEFINES+=-DRTL8201F_LED1_LINK_ALL
68+
ifeq ($(findstring ENET_LINK_CHECK,$(FLAGS)),)
69+
DEFINES+=-DENET_LINK_CHECK_USE_INT
70+
endif
71+
else
72+
DEFINES+=-DENET_LINK_CHECK_REG_POLL
73+
endif
74+
5975
$(info $$DEFINES [${DEFINES}])
6076

6177
DEFINES:= $(sort $(DEFINES))
6278

6379
$(info $$DEFINES [${DEFINES}])
80+

gd32_emac_artnet_dmx_multi/Common.mk

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ DEFINES+=RDM_CONTROLLER
1111

1212
DEFINES+=CONFIG_STORE_USE_SPI
1313

14-
DEFINES+=RTL8201F_LED1_LINK_ALL
15-
1614
DEFINES+=DISPLAY_UDF
1715

1816
DEFINES+=ENABLE_HTTPD

gd32_emac_bootloader/Common.mk

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ DEFINES+=CONFIG_NETWORK_MEMORY_BLOCKS=1
1010
DEFINES+=UDP_MAX_PORTS_ALLOWED=3
1111
DEFINES+=ENET_RXBUF_NUM=2 ENET_TXBUF_NUM=2
1212

13-
DEFINES+=RTL8201F_LED1_LINK_ALL
14-
1513
SRCDIR=firmware lib
1614

1715
LIBS=remoteconfig flashcodeinstall configstore display flashcode flash

gd32_emac_bootloader/firmware/main.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,10 @@ int main() {
6666

6767
const auto kIsNotRemote = (bkp_data_read(BKP_DATA_1) != 0xA5A5);
6868
const auto kIsNotKey = (gpio_input_bit_get(KEY_BOOTLOADER_TFTP_GPIOx, KEY_BOOTLOADER_TFTP_GPIO_PINx));
69+
const uint32_t* reset_p = reinterpret_cast<uint32_t*>(FLASH_BASE + OFFSET_UIMAGE + 4);
70+
const auto kIsEmpty = (*reset_p == UINT32_MAX);
6971

70-
if (kIsNotRemote && kIsNotKey) {
72+
if (kIsNotRemote && kIsNotKey && !kIsEmpty) {
7173
// https://developer.arm.com/documentation/ka001423/1-0
7274
// 1. Disable interrupt response.
7375
__disable_irq();
@@ -97,7 +99,6 @@ int main() {
9799
// 7. Enable interrupts.
98100
__enable_irq();
99101
// 8. Call the reset handler
100-
const uint32_t* reset_p = reinterpret_cast<uint32_t*>(FLASH_BASE + OFFSET_UIMAGE + 4);
101102
asm volatile("bx %0;" : : "r"(*reset_p));
102103
}
103104

@@ -108,7 +109,7 @@ int main() {
108109
FirmwareVersion fw(kSoftwareVersion, __DATE__, __TIME__);
109110
FlashCodeInstall flashcode_install;
110111

111-
printf("Remote=%c, Key=%c\n", kIsNotRemote ? 'N' : 'Y', kIsNotKey ? 'N' : 'Y');
112+
printf("Remote=%c, Key=%c, Empty=%c\n", kIsNotRemote ? 'N' : 'Y', kIsNotKey ? 'N' : 'Y', kIsEmpty ? 'Y' : 'N');
112113
fw.Print("Bootloader TFTP Server");
113114

114115
RemoteConfig remote_config(remoteconfig::Output::CONFIG);

lib-clib/src/asctime.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ static const char kWdayName[][4] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "S
3535
static char s_buffer[kMaxAscTime + 1];
3636

3737
extern "C" char* asctime(const struct tm* p_tm) {
38-
if (!p_tm) return nullptr;
38+
if (p_tm == nullptr) {
39+
return nullptr;
40+
}
3941

4042
const char* const kWday = (p_tm->tm_wday >= 0 && p_tm->tm_wday <= 6) ? kWdayName[p_tm->tm_wday] : "???";
4143
const char* const kMon = (p_tm->tm_mon >= 0 && p_tm->tm_mon <= 11) ? kMonName[p_tm->tm_mon] : "???";

lib-pixel/.settings/language.settings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<project>
33
<configuration id="ilg.gnuarmeclipse.managedbuild.cross.toolchain.base.309283989.303033930.1702909156.1968016134.307371463" name="H3">
44
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
5-
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="true" env-hash="205609204473843936" id="org.eclipse.embedcdt.managedbuild.cross.arm.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Arm Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
5+
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="true" env-hash="471349836864574239" id="org.eclipse.embedcdt.managedbuild.cross.arm.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Arm Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
66
<language-scope id="org.eclipse.cdt.core.gcc"/>
77
<language-scope id="org.eclipse.cdt.core.g++"/>
88
</provider>

lib-pixeldmx/.settings/language.settings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<project>
33
<configuration id="ilg.gnuarmeclipse.managedbuild.cross.toolchain.base.309283989.303033930.1702909156.1968016134.1348187898.727602372" name="H3">
44
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
5-
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="true" env-hash="415158614607112017" id="org.eclipse.embedcdt.managedbuild.cross.arm.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Arm Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
5+
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="true" env-hash="415161100161396711" id="org.eclipse.embedcdt.managedbuild.cross.arm.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Arm Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
66
<language-scope id="org.eclipse.cdt.core.gcc"/>
77
<language-scope id="org.eclipse.cdt.core.g++"/>
88
</provider>

lib-remoteconfig/http/content/pixeltype.json

Lines changed: 0 additions & 116 deletions
This file was deleted.

0 commit comments

Comments
 (0)