Skip to content

Commit

Permalink
V2.0
Browse files Browse the repository at this point in the history
- Improved build system
- Added stack debug framework
- Removed not used source files
- Added support for void __libc_init_array(void)
- Changed the layout of the config store.
    - Before upgrading the firmware it is advised to make a backup of the configuration.
    - After the upgrade, then restore the saved configuration.
  • Loading branch information
vanvught committed Oct 18, 2023
1 parent a3edb5e commit d7bb4d8
Show file tree
Hide file tree
Showing 166 changed files with 4,955 additions and 3,157 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,4 @@
*.bin
*.list
*.map
*.size
2 changes: 1 addition & 1 deletion bootloader-tftp/.settings/language.settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuildCommandParser" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser" keep-relative-paths="false" name="CDT GCC Build Output Parser" parameter="([^/\\\\]*)((g?cc)|([gc]\+\+)|(clang))" prefer-non-shared="true"/>
<provider class="org.eclipse.cdt.internal.build.crossgcc.CrossGCCBuiltinSpecsDetector" console="false" env-hash="-999154680596266402" id="org.eclipse.cdt.build.crossgcc.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<provider class="org.eclipse.cdt.internal.build.crossgcc.CrossGCCBuiltinSpecsDetector" console="false" env-hash="-998591167597546402" id="org.eclipse.cdt.build.crossgcc.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
Expand Down
17 changes: 17 additions & 0 deletions bootloader-tftp/Common.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
DEFINES+=DISABLE_JSON
DEFINES+=DISABLE_RTC
DEFINES+=DISABLE_FS
DEFINES+=DISABLE_PRINTF_FLOAT

DEFINES+=ENABLE_TFTP_SERVER

DEFINES+=UDP_MAX_PORTS_ALLOWED=2

#DEFINES+=ENET_LINK_CHECK_REG_POLL

DEFINES+=CONFIG_REMOTECONFIG_MINIMUM
DEFINES+=CONFIG_STORE_USE_SPI

SRCDIR=firmware lib

LIBS=remoteconfig flashcodeinstall configstore display flashcode flash
14 changes: 14 additions & 0 deletions bootloader-tftp/Makefile-bw-softuart.GD32
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
BOARD=BOARD_BW_OPIDMX4

DEFINES=CONFIG_USE_SOFTUART0

DEFINES+=DEBUG_STACK
DEFINES+=NDEBUG

SRCDIR=
LIBS=

include Common.mk
include ../firmware-template-gd32/Rules.mk

prerequisites:
14 changes: 14 additions & 0 deletions bootloader-tftp/Makefile-bw.GD32
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
BOARD=BOARD_BW_OPIDMX4

DEFINES=CONSOLE_NULL

DEFINES+=DEBUG_STACK
DEFINES+=NDEBUG

SRCDIR=
LIBS=

include Common.mk
include ../firmware-template-gd32/Rules.mk

prerequisites:
14 changes: 14 additions & 0 deletions bootloader-tftp/Makefile-dmx3.GD32
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
BOARD=BOARD_DMX3

DEFINES=

DEFINES+=DEBUG_STACK
DEFINES+=NDEBUG

SRCDIR=
LIBS=

include Common.mk
include ../firmware-template-gd32/Rules.mk

prerequisites:
14 changes: 14 additions & 0 deletions bootloader-tftp/Makefile-dmx4-softuart.GD32
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
BOARD=BOARD_DMX4

DEFINES=CONFIG_USE_SOFTUART0

DEFINES+=DEBUG_STACK
DEFINES+=NDEBUG

SRCDIR=
LIBS=

include Common.mk
include ../firmware-template-gd32/Rules.mk

prerequisites:
14 changes: 14 additions & 0 deletions bootloader-tftp/Makefile-dmx4.GD32
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
BOARD=BOARD_DMX4

DEFINES=CONSOLE_NULL

DEFINES+=DEBUG_STACK
DEFINES+=NDEBUG

SRCDIR=
LIBS=

include Common.mk
include ../firmware-template-gd32/Rules.mk

prerequisites:
21 changes: 6 additions & 15 deletions bootloader-tftp/Makefile.GD32
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
DEFINES =DISABLE_JSON
DEFINES+=DISABLE_RTC
DEFINES+=DISABLE_FS
DEFINES+=DISABLE_PRINTF_FLOAT
BOARD=BOARD_GD32F207RG

DEFINES+=ENABLE_TFTP_SERVER
DEFINES+=CONFIG_REMOTECONFIG_MINIMUM

DEFINES+=UDP_MAX_PORTS_ALLOWED=2

#DEFINES+=ENET_LINK_CHECK_REG_POLL

DEFINES+=CONFIG_STORE_USE_SPI
DEFINES=

DEFINES+=DEBUG_STACK
DEFINES+=NDEBUG

SRCDIR=firmware lib

LIBS=remoteconfig flashcodeinstall configstore display flashcode flash
SRCDIR=
LIBS=

include Common.mk
include ../firmware-template-gd32/Rules.mk

prerequisites:
16 changes: 7 additions & 9 deletions bootloader-tftp/firmware/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ int main(void) {
const auto isNotRemote = (bkp_data_read(BKP_DATA_1) != 0xA5A5);
const auto isNotKey = (gpio_input_bit_get(KEY_BOOTLOADER_TFTP_GPIOx, KEY_BOOTLOADER_TFTP_GPIO_PINx));

if (isNotRemote && isNotKey) { // https://developer.arm.com/documentation/ka001423/1-0
if (isNotRemote && isNotKey) {
// https://developer.arm.com/documentation/ka001423/1-0
//1. Disable interrupt response.
__disable_irq();
//2. Disable all enabled interrupts in NVIC.
Expand Down Expand Up @@ -96,19 +97,15 @@ int main(void) {
}

Hardware hw;
Network nw;
Display display(4);
ConfigStore configStore;
StoreNetwork storeNetwork;
Network nw(&storeNetwork);
FirmwareVersion fw(SOFTWARE_VERSION, __DATE__, __TIME__);
FlashCodeInstall flashCodeInstall;

printf("Remote=%c, Key=%c\n", isNotRemote ? 'N' : 'Y', isNotKey ? 'N' : 'Y');
fw.Print("Bootloader TFTP Server");

FlashCodeInstall flashCodeInstall;
ConfigStore configStore;

StoreNetwork storeNetwork;
nw.SetNetworkStore(&storeNetwork);
nw.Init(&storeNetwork);
nw.Print();

hw.SetMode(hardware::ledblink::Mode::OFF_ON);
Expand All @@ -124,6 +121,7 @@ int main(void) {

remoteConfig.SetEnableReboot(true);

network::display_ip();
display.Printf(3, "Bootloader TFTP Srvr");

hw.SetMode(hardware::ledblink::Mode::FAST);
Expand Down
2 changes: 1 addition & 1 deletion bootloader-tftp/include/software_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
#ifndef SOFTWARE_VERSION_H_
#define SOFTWARE_VERSION_H_

constexpr char SOFTWARE_VERSION[] = "1.4";
constexpr char SOFTWARE_VERSION[] = "2.0";

#endif /* SOFTWARE_VERSION_H_ */
20 changes: 15 additions & 5 deletions bootloader-tftp/lib/networkdisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @file networkdisplay.cpp
*
*/
/* Copyright (C) 2022 by Arjan van Vught mailto:[email protected]
/* Copyright (C) 2022-2023 by Arjan van Vught mailto:[email protected]
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -33,13 +33,23 @@
namespace network {
static constexpr auto LINE_IP = 2U;

void display_emac_config() {
Display::Get()->ClearEndOfLine();
Display::Get()->Printf(LINE_IP, "Ethernet config");
}

void display_emac_start() {
Display::Get()->ClearLine(LINE_IP);
Display::Get()->PutString("Ethernet start");
Display::Get()->ClearEndOfLine();
Display::Get()->Printf(LINE_IP, "Ethernet start");
}

void display_emac_status(const bool isLinkUp) {
Display::Get()->ClearEndOfLine();
Display::Get()->Printf(LINE_IP, "Ethernet Link %s", isLinkUp ? "UP" : "DOWN");
}

void display_ip() {
Display::Get()->ClearLine(LINE_IP);
Display::Get()->ClearEndOfLine();
Display::Get()->Printf(LINE_IP, "" IPSTR "/%d %c", IP2STR(Network::Get()->GetIp()), Network::Get()->GetNetmaskCIDR(), Network::Get()->GetAddressingMode());
}

Expand All @@ -54,7 +64,7 @@ void display_hostname() {
}

void display_emac_shutdown() {
Display::Get()->ClearLine(LINE_IP);
Display::Get()->ClearEndOfLine();
Display::Get()->PutString("Ethernet shutdown");
}

Expand Down
17 changes: 13 additions & 4 deletions firmware-template-gd32/Rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ AR = $(PREFIX)ar
BOARD?=BOARD_GD32F207RG
ENET_PHY?=DP83848
FAMILY?=gd32f20x
MCU?=gd32f207

FAMILY:=$(shell echo $(FAMILY) | tr A-Z a-z)
FAMILY_UC=$(shell echo $(FAMILY) | tr a-w A-W)
Expand All @@ -17,7 +18,7 @@ $(info $$FAMILY [${FAMILY}])
$(info $$FAMILY_UC [${FAMILY_UC}])

# Output
TARGET=gd32f207.bin
TARGET=$(MCU).bin
LIST=$(FAMILY).list
MAP=$(FAMILY).map
BUILD=build_gd32/
Expand Down Expand Up @@ -117,7 +118,9 @@ lisdep: $(LIBDEP)
$(LIBDEP):
$(MAKE) -f Makefile.GD32 $(MAKECMDGOALS) 'FAMILY=${FAMILY}' 'BOARD=${BOARD}' 'PHY_TYPE=${ENET_PHY}' 'MAKE_FLAGS=$(DEFINES)' -C $@

# Build uImage
#
# Build bin
#

$(BUILD_DIRS) :
mkdir -p $(BUILD_DIRS)
Expand All @@ -128,9 +131,15 @@ $(BUILD)startup_$(FAMILY)_cl.o : $(FIRMWARE_DIR)/startup_$(FAMILY)_cl.S
$(BUILD)main.elf: Makefile.GD32 $(LINKER) $(BUILD)startup_$(FAMILY)_cl.o $(OBJECTS) $(LIBDEP)
$(LD) $(BUILD)startup_$(FAMILY)_cl.o $(OBJECTS) -Map $(MAP) -T $(LINKER) $(LDOPS) -o $(BUILD)main.elf $(LIBGD32) $(LDLIBS) $(PLATFORM_LIBGCC) -lgcc
$(PREFIX)objdump -D $(BUILD)main.elf | $(PREFIX)c++filt > $(LIST)
$(PREFIX)size -A -x $(BUILD)main.elf
$(PREFIX)size -A -x $(BUILD)main.elf > $(FAMILY).size
$(MAKE) -f Makefile.GD32 calculate_unused_ram SIZE_FILE=$(FAMILY).size LINKER_SCRIPT=$(LINKER)

$(TARGET) : $(BUILD)main.elf
$(PREFIX)objcopy $(BUILD)main.elf -O binary $(TARGET)

$(foreach bdir,$(SRCDIR),$(eval $(call compile-objects,$(bdir))))
$(foreach bdir,$(SRCDIR),$(eval $(call compile-objects,$(bdir))))

.PHONY: calculate_unused_ram
calculate_unused_ram: $(FAMILY).size $(LINKER)
@$(FIRMWARE_DIR)/calculate_unused_ram.sh $(FAMILY).size $(LINKER)

21 changes: 21 additions & 0 deletions firmware-template-gd32/calculate_unused_ram.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

if [ $# -lt 2 ]; then
echo "Usage: $0 <size_file> <linker_script>"
exit 1
fi

size_file="$1"
linker_script="$2"

used_stack=$(grep ".stack" "$size_file" | awk '{print $2}')
used_heap=$(grep ".heap" "$size_file" | awk '{print $2}')
used_data=$(grep '.data' "$size_file" | tail -n 1 | awk '{print $2}')
used_bss=$(grep ".bss" "$size_file" | awk '{print $2}')

total_ram=$(grep "RAM (xrw)" "$linker_script" | awk '{print $NF}' | sed 's/K$//' | awk '{printf "%d", $0 * 1024}')
unused_ram=$(( $(echo $total_ram) - $(echo $used_stack) - $(echo $used_heap) - $(echo $used_data) - $(echo $used_bss) ))

cat $1
echo "RAM $total_ram bytes, Unused: $unused_ram bytes"
echo
Loading

0 comments on commit d7bb4d8

Please sign in to comment.