Skip to content

Commit e04de4b

Browse files
committed
Add GD32 EMAC bootloader and flash installer
Introduces a new `gd32_emac_bootloader` firmware target with board-specific makefiles, startup flow, and a dedicated 32KB bootloader linker script. Adds the new `lib-flashcodeinstall` library for firmware image handling, erase/write chunk support, and U-Boot header/firmware metadata handling. Build rules were updated to better support minimal remote-config bootloader builds: conditional network defines for `CONFIG_REMOTECONFIG_MINIMUM`, deterministic sorting of define flags, conditional inclusion of remoteconfig TFTP sources, and removal of `.ram*` sections from generated binaries.
1 parent afd229f commit e04de4b

37 files changed

Lines changed: 1848 additions & 8 deletions

firmware-template-gd32/Rules.mk

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,16 @@ LDLIBS:=$(addprefix -l,$(LIBS))
5252
# The variables for the dependency check
5353
LIBDEP=$(addprefix ../lib-,$(LIBS))
5454

55-
DEFINES+=-DHTTPD_CONTENT_SIZE=2048
56-
DEFINES+=-DTCP_MAX_TCBS_ALLOWED=8
57-
DEFINES+=-DCONFIG_NETWORK_MEMORY_BLOCKS=16
55+
ifeq ($(findstring CONFIG_REMOTECONFIG_MINIMUM,$(DEFINES)),CONFIG_REMOTECONFIG_MINIMUM)
56+
else
57+
DEFINES+=-DHTTPD_CONTENT_SIZE=2048
58+
DEFINES+=-DTCP_MAX_TCBS_ALLOWED=8
59+
DEFINES+=-DCONFIG_NETWORK_MEMORY_BLOCKS=16
60+
endif
5861

5962
COPS=-DGD32 -D$(FAMILY_UCA) -D$(LINE_UC) -D$(MCU) -D$(BOARD) -DPHY_TYPE=$(ENET_PHY)
60-
COPS+=$(strip $(DEFINES) $(MAKE_FLAGS) $(INCLUDES) $(LIBINCDIRS))
63+
COPS+=$(sort $(DEFINES) $(MAKE_FLAGS))
64+
COPS+=$(strip $(INCLUDES) $(LIBINCDIRS))
6165
COPS+=$(strip $(ARMOPS) $(CMSISOPS))
6266
COPS+=-Os -nostartfiles -ffreestanding -nostdlib
6367
COPS+=-fstack-usage
@@ -176,6 +180,7 @@ $(TARGET): $(BUILD)main.elf
176180
-O binary \
177181
$@ \
178182
--remove-section=.tcmsram* \
183+
--remove-section=.ram* \
179184
--remove-section=.sram1* \
180185
--remove-section=.sram2* \
181186
--remove-section=.ramadd* \
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
MEMORY
2+
{
3+
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 32K
4+
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 256K
5+
}
6+
7+
ENTRY(Reset_Handler)
8+
9+
SECTIONS
10+
{
11+
__heap_size = DEFINED(__heap_size) ? __heap_size : 1K;
12+
__stack_size = DEFINED(__stack_size) ? __stack_size : 2K;
13+
14+
.vectors :
15+
{
16+
. = ALIGN(4);
17+
KEEP(*(.vectors))
18+
. = ALIGN(4);
19+
__Vectors_End = .;
20+
__Vectors_Size = __Vectors_End - __gVectors;
21+
} >FLASH
22+
23+
.text :
24+
{
25+
. = ALIGN(4);
26+
*(.text.unlikely*)
27+
*(.text.hot*)
28+
*(.text)
29+
*(.text*)
30+
*(.glue_7)
31+
*(.glue_7t)
32+
*(.eh_frame)
33+
KEEP (*(.init))
34+
KEEP (*(.fini))
35+
. = ALIGN(4);
36+
_etext = .;
37+
} >FLASH
38+
39+
.rodata :
40+
{
41+
. = ALIGN(4);
42+
*(.rodata)
43+
*(.rodata*)
44+
. = ALIGN(4);
45+
} >FLASH
46+
47+
.preinit_array :
48+
{
49+
PROVIDE_HIDDEN (__preinit_array_start = .);
50+
KEEP (*(.preinit_array*))
51+
PROVIDE_HIDDEN (__preinit_array_end = .);
52+
} >FLASH
53+
54+
.init_array :
55+
{
56+
PROVIDE_HIDDEN (__init_array_start = .);
57+
KEEP (*(SORT(.init_array.*)))
58+
KEEP (*(.init_array*))
59+
PROVIDE_HIDDEN (__init_array_end = .);
60+
} >FLASH
61+
62+
.fini_array :
63+
{
64+
PROVIDE_HIDDEN (__fini_array_start = .);
65+
KEEP (*(.fini_array*))
66+
KEEP (*(SORT(.fini_array.*)))
67+
PROVIDE_HIDDEN (__fini_array_end = .);
68+
} >FLASH
69+
70+
.stack :
71+
{
72+
. = ALIGN(4);
73+
PROVIDE( stack_low = . );
74+
. = __stack_size;
75+
PROVIDE( _sp = . );
76+
. = ALIGN(4);
77+
} >RAM
78+
79+
.ram :
80+
{
81+
. = ALIGN(4);
82+
_snetwork = .;
83+
*(.network*)
84+
. = ALIGN(4);
85+
_enetwork = .;
86+
. = ALIGN(4);
87+
} >RAM
88+
89+
_sidata = LOADADDR(.data);
90+
.data :
91+
{
92+
. = ALIGN(4);
93+
_sdata = .;
94+
*(.data)
95+
*(.data*)
96+
. = ALIGN(4);
97+
_edata = .;
98+
} >RAM AT> FLASH
99+
100+
. = ALIGN(4);
101+
.bss :
102+
{
103+
_sbss = .;
104+
__bss_start__ = _sbss;
105+
*(.bss)
106+
*(.bss*)
107+
*(COMMON)
108+
. = ALIGN(4);
109+
_ebss = .;
110+
__bss_end__ = _ebss;
111+
} >RAM
112+
113+
. = ALIGN(8);
114+
PROVIDE ( end = _ebss );
115+
PROVIDE ( _end = _ebss );
116+
117+
.heap :
118+
{
119+
. = ALIGN(4);
120+
heap_low = .;
121+
. = . + __heap_size;
122+
heap_top = .;
123+
. = ALIGN(4);
124+
} >RAM
125+
126+
/DISCARD/ :
127+
{
128+
*(*.ARM.*)
129+
*(*.comment)
130+
*(*.debug*)
131+
}
132+
}
133+
134+
GROUP(libgcc.a)

firmware-template-gd32/lib/Rules.mk

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ include ../common/make/gd32/Validate.mk
3232
INCLUDES+=-I../lib-configstore/include -I../lib-device/include -I../lib-display/include -I../lib-flash/include -I../lib-flashcode/include -I../lib-board/include -I../lib-lightset/include -I../lib-network/include
3333

3434
COPS=-DGD32 -D$(FAMILY_UCA) -D$(LINE_UC) -D$(MCU) -D$(BOARD) -DPHY_TYPE=$(ENET_PHY)
35-
COPS+=$(strip $(DEFINES) $(MAKE_FLAGS) $(VALIDATE_FLAGS) $(INCLUDES))
35+
COPS+=$(sort $(DEFINES) $(MAKE_FLAGS) $(VALIDATE_FLAGS))
36+
COPS+=$(strip $(INCLUDES))
3637
COPS+=$(strip $(ARMOPS) $(CMSISOPS))
3738
COPS+=-Os -nostartfiles -ffreestanding -nostdlib
3839
COPS+=-fstack-usage

gd32_emac_bootloader/.clangd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CompileFlags: {CompilationDatabase: }

gd32_emac_bootloader/.cproject

Lines changed: 153 additions & 0 deletions
Large diffs are not rendered by default.

gd32_emac_bootloader/.project

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>gd32_emac_bootloader</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
10+
<triggers>clean,full,incremental,</triggers>
11+
<arguments>
12+
</arguments>
13+
</buildCommand>
14+
<buildCommand>
15+
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
16+
<triggers>full,incremental,</triggers>
17+
<arguments>
18+
</arguments>
19+
</buildCommand>
20+
</buildSpec>
21+
<natures>
22+
<nature>org.eclipse.cdt.core.cnature</nature>
23+
<nature>org.eclipse.cdt.core.ccnature</nature>
24+
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
25+
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
26+
</natures>
27+
</projectDescription>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<project>
3+
<configuration id="ilg.gnuarmeclipse.managedbuild.cross.toolchain.base.1450088188" name="Default">
4+
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
5+
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
6+
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
7+
<provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
8+
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="424298382668343167" 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">
9+
<language-scope id="org.eclipse.cdt.core.gcc"/>
10+
<language-scope id="org.eclipse.cdt.core.g++"/>
11+
</provider>
12+
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
13+
</extension>
14+
</configuration>
15+
</project>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
eclipse.preferences.version=1
2+
encoding/<project>=UTF-8

gd32_emac_bootloader/Common.mk

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
DEFINES+=DISABLE_RTC
2+
DEFINES+=DISABLE_FS
3+
DEFINES+=DISABLE_PRINTF_FLOAT
4+
5+
DEFINES+=ENABLE_TFTP_SERVER
6+
DEFINES+=CONFIG_REMOTECONFIG_MINIMUM
7+
8+
DEFINES+=CONFIG_NETWORK_MEMORY_BLOCKS=1
9+
10+
DEFINES+=UDP_MAX_PORTS_ALLOWED=3
11+
DEFINES+=ENET_RXBUF_NUM=2 ENET_TXBUF_NUM=2
12+
13+
DEFINES+=RTL8201F_LED1_LINK_ALL
14+
15+
SRCDIR=firmware lib
16+
17+
LIBS=remoteconfig flashcodeinstall configstore display flashcode flash

gd32_emac_bootloader/Makefile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
BOARD=BOARD_GD32F207RG
2+
3+
DEFINES=
4+
5+
DEFINES+=CONFIG_CLIB_USE_UART0
6+
7+
DEFINES+=CONFIG_DEBUG_I2C
8+
DEFINES+=CONFIG_DEBUG_STACK
9+
10+
DEFINES+=CONFIG_DEBUG_TRACE
11+
DEFINES+=DEBUG_BOARD
12+
DEFINES+=DEBUG_GD32_TIMERS
13+
DEFINES+=DEBUG_FMC
14+
15+
DEFINES+=NDEBUG
16+
17+
SRCDIR=
18+
LIBS=
19+
20+
include Common.mk
21+
include ../firmware-template-gd32/Rules.mk
22+
23+
prerequisites:

0 commit comments

Comments
 (0)