Skip to content

Commit 1f1378e

Browse files
committed
Compile image with bootloader and two images for dual-boot
1 parent cb54b3a commit 1f1378e

File tree

4 files changed

+174
-25
lines changed

4 files changed

+174
-25
lines changed

firmware/Makefile

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,47 @@
33
# it under the terms of the GNU General Public License version 3.
44

55
BOOT_NAME=bootloader_fw.hex
6-
PROG_NAME=app_fw.hex
6+
APP1_NAME=app_fw_1.hex
7+
APP2_NAME=app_fw_2.hex
78
GEN_NAME=nando_fw
89

910
BOOT_DIR=bootloader/
10-
PROG_DIR=programmer/
11+
APP_DIR=programmer/
1112

1213
BOOT_OBJ_DIR=$(BOOT_DIR)obj/
13-
PROG_OBJ_DIR=$(PROG_DIR)obj/
14+
APP_OBJ_DIR=$(APP_DIR)obj/
1415

1516
BOOT_PATH=$(BOOT_OBJ_DIR)$(BOOT_NAME)
16-
PROG_PATH=$(PROG_OBJ_DIR)$(PROG_NAME)
17+
APP1_PATH=$(APP_OBJ_DIR)$(APP1_NAME)
18+
APP2_PATH=$(APP_OBJ_DIR)$(APP2_NAME)
1719

1820
OBJ_DIR=obj/
1921

20-
TOOLCHAIN=../../../compiler/gcc-arm-none-eabi-4_9-2015q1/bin/arm-none-eabi-
22+
TOOLCHAIN=../../compiler/gcc-arm-none-eabi-4_9-2015q1/bin/arm-none-eabi-
2123
OBJCOPY=$(TOOLCHAIN)objcopy
2224

2325
all:
2426
$(MAKE) -C $(BOOT_DIR)
25-
$(MAKE) -C $(PROG_DIR)
27+
$(MAKE) -C $(APP_DIR)
2628
mkdir -p $(OBJ_DIR)
2729
cp $(BOOT_PATH) $(OBJ_DIR)
28-
cp $(PROG_PATH) $(OBJ_DIR)
29-
cd $(OBJ_DIR) && sed -i '$$d' $(BOOT_NAME) && \
30-
cat $(BOOT_NAME) $(PROG_NAME) > $(GEN_NAME).hex && \
31-
$(OBJCOPY) --input-target=ihex --output-target=binary $(GEN_NAME).hex \
32-
$(GEN_NAME).bin
30+
cp $(APP1_PATH) $(OBJ_DIR)
31+
cp $(APP2_PATH) $(OBJ_DIR)
32+
sed -i '$$d' $(OBJ_DIR)$(BOOT_NAME)
33+
sed -i '$$d' $(OBJ_DIR)$(APP1_NAME)
34+
cat $(OBJ_DIR)$(BOOT_NAME) $(OBJ_DIR)$(APP1_NAME) \
35+
$(OBJ_DIR)$(APP2_NAME) > $(OBJ_DIR)$(GEN_NAME).hex
36+
$(OBJCOPY) --input-target=ihex --output-target=binary \
37+
$(OBJ_DIR)$(GEN_NAME).hex $(OBJ_DIR)$(GEN_NAME).bin
3338

3439
clean:
3540
$(MAKE) -C $(BOOT_DIR) clean
36-
$(MAKE) -C $(PROG_DIR) clean
41+
$(MAKE) -C $(APP_DIR) clean
3742
rm -rf obj/
3843

3944
distclean:
4045
$(MAKE) -C $(BOOT_DIR) distclean
41-
$(MAKE) -C $(PROG_DIR) distclean
46+
$(MAKE) -C $(APP_DIR) distclean
4247
rm -rf obj/
4348

4449
erase:

firmware/programmer/Makefile

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
# This program is free software; you can redistribute it and/or modify
33
# it under the terms of the GNU General Public License version 3.
44

5-
PROG_NAME=app_fw
5+
APP_NAME=app_fw
66

77
SRC_DIR=./
88
USB_DIR=../usb_cdc/
99
OBJ_DIR=obj/
1010
LIB_DIR=../libs/
1111
INCLUDE_DIR=../
1212
TOOLCHAIN=../../../compiler/gcc-arm-none-eabi-4_9-2015q1/bin/arm-none-eabi-
13-
PROG=$(OBJ_DIR)$(PROG_NAME)
13+
APP_1=$(OBJ_DIR)$(APP_NAME)_1
14+
APP_2=$(OBJ_DIR)$(APP_NAME)_2
1415

1516
SPL_PATH=$(LIB_DIR)spl/
1617
SPL_DEVICE_SUPPORT_PATH=$(SPL_PATH)CMSIS/CM3/DeviceSupport/ST/STM32F10x/
@@ -42,7 +43,8 @@ CFLAGS+=-ffunction-sections -fdata-sections
4243
CFLAGS+=-mcpu=cortex-m3 -mthumb
4344
CFLAGS+=$(SPL_FLAGS)
4445

45-
LDFLAGS=-mcpu=cortex-m3 -mthumb -Wl,--gc-sections -Wl,-Map=$(PROG).map
46+
LDFLAGS_1=-mcpu=cortex-m3 -mthumb -Wl,--gc-sections -Wl,-Map=$(APP_1).map
47+
LDFLAGS_2=-mcpu=cortex-m3 -mthumb -Wl,--gc-sections -Wl,-Map=$(APP_2).map
4648

4749
vpath %.c $(SRC_DIR) $(SPL_DEVICE_SUPPORT_PATH) $(SRC_BSP_DIR) $(USB_DIR)
4850
vpath %.s $(SRC_DIR)
@@ -58,22 +60,32 @@ OBJS=$(addprefix $(OBJ_DIR),$(SRCS:.c=.o)) \
5860
$(addprefix $(OBJ_DIR),$(STARTUP:.s=.o))
5961
DEPS=$(OBJS:%.o=%.d)
6062

61-
LINKER_SCRIPT=$(SRC_DIR)stm32_flash.ld
63+
LINKER_SCRIPT_1=$(SRC_DIR)stm32_flash_1.ld
64+
LINKER_SCRIPT_2=$(SRC_DIR)stm32_flash_2.ld
6265

63-
all: lib dirs $(PROG).elf
66+
all: lib dirs $(APP_1).elf $(APP_2).elf
6467

6568
lib:
6669
$(MAKE) -C $(SPL_PATH)
6770

6871
dirs:
6972
mkdir -p $(OBJ_DIR)
7073

71-
$(PROG).elf: $(OBJS)
72-
$(CC) $(LDFLAGS) -o $@ $^ -L$(SPL_PATH) -l$(SPL_LIB) -T$(LINKER_SCRIPT)
73-
$(OBJCOPY) -O ihex $(PROG).elf $(PROG).hex
74-
$(OBJCOPY) -O binary $(PROG).elf $(PROG).bin
75-
$(OBJDUMP) -St $(PROG).elf > $(PROG).lst
76-
$(SIZE) $(PROG).elf
74+
$(APP_1).elf: $(OBJS)
75+
$(CC) $(LDFLAGS_1) -o $@ $^ -L$(SPL_PATH) -l$(SPL_LIB) \
76+
-T$(LINKER_SCRIPT_1)
77+
$(OBJCOPY) -O ihex $(APP_1).elf $(APP_1).hex
78+
$(OBJCOPY) -O binary $(APP_1).elf $(APP_1).bin
79+
$(OBJDUMP) -St $(APP_1).elf > $(APP_1).lst
80+
$(SIZE) $(APP_1).elf
81+
82+
$(APP_2).elf: $(OBJS)
83+
$(CC) $(LDFLAGS_2) -o $@ $^ -L$(SPL_PATH) -l$(SPL_LIB) \
84+
-T$(LINKER_SCRIPT_2)
85+
$(OBJCOPY) -O ihex $(APP_2).elf $(APP_2).hex
86+
$(OBJCOPY) -O binary $(APP_2).elf $(APP_2).bin
87+
$(OBJDUMP) -St $(APP_2).elf > $(APP_2).lst
88+
$(SIZE) $(APP_2).elf
7789

7890
$(OBJ_DIR)%.o: %.c
7991
$(CC) -c $(CFLAGS) $< -o $@
@@ -90,4 +102,4 @@ distclean: clean
90102
$(MAKE) -C $(SPL_PATH) clean
91103

92104
program:
93-
st-flash write $(PROG).bin 0x8004000
105+
st-flash write $(APP_1).bin 0x8004000

firmware/programmer/stm32_flash_2.ld

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/* Copyright (C) 2017 Bogdan Bogush <[email protected]>
2+
* This program is free software; you can redistribute it and/or modify
3+
* it under the terms of the GNU General Public License version 3.
4+
*/
5+
6+
/* Device: STM32F103
7+
* Flash: 256KByte
8+
* RAM: 48KByte
9+
*/
10+
11+
ENTRY(Reset_Handler)
12+
13+
/* End of stack = start of RAM 0x20000000 + 48K */
14+
_estack = 0x2000c000;
15+
16+
MEMORY
17+
{
18+
FLASH(rx) : ORIGIN = 0x08022000, LENGTH = 120K
19+
RAM(xrw) : ORIGIN = 0x20000000, LENGTH = 48K
20+
}
21+
22+
SECTIONS
23+
{
24+
/* Startup code */
25+
.isr_vector :
26+
{
27+
. = ALIGN(4);
28+
KEEP(*(.isr_vector))
29+
. = ALIGN(4);
30+
} > FLASH
31+
32+
/* Code and constant data */
33+
.text :
34+
{
35+
. = ALIGN(4);
36+
*(.text)
37+
*(.text*)
38+
*(.rodata)
39+
*(.rodata*)
40+
41+
KEEP (*(.init))
42+
KEEP (*(.fini))
43+
44+
. = ALIGN(4);
45+
_etext = .;
46+
} > FLASH
47+
48+
/* Exception unwinding sections */
49+
.ARM.extab :
50+
{
51+
*(.ARM.extab* .gnu.linkonce.armextab.*)
52+
} > FLASH
53+
54+
.ARM :
55+
{
56+
__exidx_start = .;
57+
*(.ARM.exidx*)
58+
__exidx_end = .;
59+
} > FLASH
60+
61+
/* ARM specific attributes */
62+
.ARM.attributes :
63+
{
64+
*(.ARM.attributes)
65+
} > FLASH
66+
67+
/* Initialization sections */
68+
.preinit_array :
69+
{
70+
PROVIDE_HIDDEN(__preinit_array_start = .);
71+
KEEP(*(.preinit_array*))
72+
PROVIDE_HIDDEN(__preinit_array_end = .);
73+
} > FLASH
74+
75+
.init_array :
76+
{
77+
PROVIDE_HIDDEN(__init_array_start = .);
78+
KEEP(*(SORT(.init_array.*)))
79+
KEEP(*(.init_array*))
80+
PROVIDE_HIDDEN(__init_array_end = .);
81+
} > FLASH
82+
83+
/* Termination sections */
84+
.fini_array :
85+
{
86+
PROVIDE_HIDDEN(__fini_array_start = .);
87+
KEEP(*(.fini_array*))
88+
KEEP(*(SORT(.fini_array.*)))
89+
PROVIDE_HIDDEN(__fini_array_end = .);
90+
} > FLASH
91+
92+
/* Used by startup code to initialize data */
93+
_sidata = .;
94+
95+
/* Initialized data sections */
96+
.data : AT(_sidata)
97+
{
98+
. = ALIGN(4);
99+
_sdata = .;
100+
*(.data)
101+
*(.data*)
102+
103+
. = ALIGN(4);
104+
_edata = .;
105+
} > RAM
106+
107+
/* Uninitialized data section */
108+
. = ALIGN(4);
109+
.bss :
110+
{
111+
_sbss = .;
112+
__bss_start__ = _sbss;
113+
*(.bss)
114+
*(.bss*)
115+
*(COMMON)
116+
117+
. = ALIGN(4);
118+
_ebss = .;
119+
__bss_end__ = _ebss;
120+
} > RAM
121+
122+
PROVIDE(end = _ebss);
123+
PROVIDE(_end = _ebss);
124+
125+
/* Discard unused sections */
126+
/DISCARD/ :
127+
{
128+
libc.a (*)
129+
libm.a (*)
130+
libgcc.a (*)
131+
}
132+
}

0 commit comments

Comments
 (0)