Skip to content

Commit 2ebf5ae

Browse files
committed
updated flash_device verify, struct to make it work with the latest J-Link software
1 parent ae1e0d9 commit 2ebf5ae

File tree

2 files changed

+74
-46
lines changed

2 files changed

+74
-46
lines changed

CMakeLists.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,16 @@ target_compile_options(flash_loader PUBLIC $<$<COMPILE_LANGUAGE:CXX>:-fno-rtti>)
6868
target_compile_options(flash_loader PUBLIC $<$<COMPILE_LANGUAGE:CXX>:-fconcepts>)
6969
target_compile_options(flash_loader PUBLIC $<$<COMPILE_LANGUAGE:CXX>:-fno-use-cxa-get-exception-ptr>)
7070
target_compile_options(flash_loader PUBLIC $<$<COMPILE_LANGUAGE:CXX>:-fno-use-cxa-atexit>)
71+
target_compile_options(flash_loader PUBLIC $<$<COMPILE_LANGUAGE:CXX>:-Wno-volatile>)
7172

7273
# set the cpu options for the linker
7374
target_link_options(flash_loader PRIVATE "-march=armv7e-m")
7475
target_link_options(flash_loader PRIVATE "-mcpu=cortex-m4")
7576
target_link_options(flash_loader PRIVATE "-mthumb")
7677

7778
# other linker options
78-
target_link_options(flash_loader PRIVATE "-ffunction-sections")
79-
target_link_options(flash_loader PRIVATE "-fdata-sections")
79+
target_link_options(flash_loader PUBLIC "-ffunction-sections")
80+
target_link_options(flash_loader PUBLIC "-fdata-sections")
8081
target_link_options(flash_loader PUBLIC "-nostdlib")
8182
target_link_options(flash_loader PUBLIC "-nodefaultlibs")
8283
target_link_options(flash_loader PUBLIC "-nostartfiles")
@@ -91,5 +92,5 @@ target_link_options(flash_loader PUBLIC "-T${CMAKE_SOURCE_DIR}/linkerscript.ld")
9192
# Custom commands for processing the build binary and show some statistics and debug info
9293
add_custom_command(TARGET flash_loader DEPENDS ${CMAKE_BINARY_DIR}/flash_loader.elf POST_BUILD COMMAND arm-none-eabi-objcopy ARGS -O binary -R .bss -R .stack flash_loader.elf flash_loader.bin)
9394
add_custom_command(TARGET flash_loader DEPENDS ${CMAKE_BINARY_DIR}/flash_loader.elf POST_BUILD COMMAND arm-none-eabi-objdump ARGS -C -S flash_loader.elf > flash_loader.lss)
94-
add_custom_command(TARGET flash_loader DEPENDS ${CMAKE_BINARY_DIR}/flash_loader.elf POST_BUILD COMMAND arm-none-eabi-objdump ARGS -C -sj .flash_device -sj .bss -sj .data -sj .rodata -S flash_loader.elf > flash_loader.memory)
95+
add_custom_command(TARGET flash_loader DEPENDS ${CMAKE_BINARY_DIR}/flash_loader.elf POST_BUILD COMMAND arm-none-eabi-objdump ARGS -C -sj PrgCode -sj DevDscr -sj .bss -sj .data -sj .rodata -S flash_loader.elf > flash_loader.memory)
9596
add_custom_command(TARGET flash_loader DEPENDS ${CMAKE_BINARY_DIR}/flash_loader.elf POST_BUILD COMMAND arm-none-eabi-size ARGS -A flash_loader.elf -x)

flash/flash_device.cpp

Lines changed: 70 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* <PageSize> = 2 ^ Shift. Shift = 3 => <PageSize> = 2^3 = 8 bytes
88
*
99
*/
10-
#define PAGE_SIZE_SHIFT (2)
10+
#define PAGE_SIZE_SHIFT (8)
1111

1212
/**
1313
* @brief If value is false the device does not support native read. This
@@ -37,44 +37,64 @@
3737
* <SectorSize> = 2 ^ Shift. Shift = 12 => <SectorSize> = 2 ^ 12 = 4096 bytes
3838
*
3939
*/
40-
#define SECTOR_SIZE_SHIFT (2)
40+
#define SECTOR_SIZE_SHIFT (12)
41+
42+
/**
43+
* @brief Use a custom verify. Is optional. Speeds up verifying
44+
*
45+
*/
46+
#define CUSTOM_VERIFY (false)
4147

4248
/**
4349
* @brief Device specific infomation
4450
*
4551
*/
4652
extern "C" {
47-
const __attribute__ ((section("DevDscr"), __used__)) flash_device FlashDevice = {
48-
flash_drv_version, // driver version
49-
"test device", // device name
50-
device_type::on_chip, // device type
51-
0xA0000000, // base address
52-
0x00000400, // flash size
53-
4, // page size
54-
0, // reserved
55-
0xff, // blank value
56-
100, // page program timeout
57-
3000, // sector erase timeout
58-
59-
// flash sectors
60-
{
61-
{0x00000400, 0x00000000},
62-
end_of_sectors
63-
}
64-
};
53+
// declaration for the flash device. If we initialize it here we get
54+
// a wrong name in the symbol table
55+
extern const struct flash_device FlashDevice;
56+
57+
// Mark start of <PrgData> segment. Non-static to make sure linker can keep this
58+
// symbol. Dummy needed to make sure that <PrgData> section in resulting ELF file
59+
// is present. Needed by open flash loader logic on PC side
60+
volatile int PRGDATA_StartMarker __attribute__ ((section ("PrgData"), __used__));
6561
}
6662

63+
// definition for the flash device
64+
const __attribute__ ((section("DevDscr"), __used__)) flash_device FlashDevice = {
65+
flash_drv_version, // driver version
66+
"test device", // device name
67+
device_type::on_chip, // device type
68+
0xA0000000, // base address
69+
0x00000400, // flash size
70+
4, // page size
71+
0, // reserved
72+
0xff, // blank value
73+
100, // page program timeout
74+
3000, // sector erase timeout
75+
76+
// flash sectors
77+
{
78+
{0x00000400, 0x00000000},
79+
end_of_sectors
80+
}
81+
};
82+
6783
// function overrides when parts are not in use
6884
#if NATIVE_READ
69-
#define VERIFY_FUNC nullptr
7085
#define BLANK_CHECK_FUNC nullptr
7186
#define OPEN_READ_FUNC nullptr
7287
#else
73-
#define VERIFY_FUNC Verify
7488
#define BLANK_CHECK_FUNC BlankCheck
7589
#define OPEN_READ_FUNC SEGGER_OPEN_Read
7690
#endif
7791

92+
#if CUSTOM_VERIFY
93+
#define VERIFY_FUNC Verify
94+
#else
95+
#define VERIFY_FUNC nullptr
96+
#endif
97+
7898
#if CHIP_ERASE
7999
#define CHIP_ERASE_FUNC EraseChip
80100
#else
@@ -92,23 +112,28 @@ extern "C" {
92112
*
93113
*/
94114
extern "C" {
95-
const uint32_t SEGGER_OFL_Api[13] __attribute__ ((section ("PrgCode"), __used__)) = {
96-
reinterpret_cast<uint32_t>(FeedWatchdog),
97-
reinterpret_cast<uint32_t>(Init),
98-
reinterpret_cast<uint32_t>(UnInit),
99-
reinterpret_cast<uint32_t>(EraseSector),
100-
reinterpret_cast<uint32_t>(ProgramPage),
101-
reinterpret_cast<uint32_t>(BLANK_CHECK_FUNC),
102-
reinterpret_cast<uint32_t>(CHIP_ERASE_FUNC),
103-
reinterpret_cast<uint32_t>(VERIFY_FUNC),
104-
reinterpret_cast<uint32_t>(nullptr), // SEGGER_OPEN_CalcCRC
105-
reinterpret_cast<uint32_t>(OPEN_READ_FUNC),
106-
reinterpret_cast<uint32_t>(SEGGER_OPEN_Program),
107-
reinterpret_cast<uint32_t>(UNIFORM_ERASE_FUNC),
108-
reinterpret_cast<uint32_t>(nullptr), // SEGGER_OPEN_Start for turbo mode
109-
};
115+
// declaration for the OFL Api. If we initialize it here we get
116+
// a wrong name in the symbol table
117+
extern const uint32_t SEGGER_OFL_Api[13];
110118
}
111119

120+
// definition of OFL Api
121+
const uint32_t SEGGER_OFL_Api[13] __attribute__ ((section ("PrgCode"), __used__)) = {
122+
reinterpret_cast<uint32_t>(FeedWatchdog),
123+
reinterpret_cast<uint32_t>(Init),
124+
reinterpret_cast<uint32_t>(UnInit),
125+
reinterpret_cast<uint32_t>(EraseSector),
126+
reinterpret_cast<uint32_t>(ProgramPage),
127+
reinterpret_cast<uint32_t>(BLANK_CHECK_FUNC),
128+
reinterpret_cast<uint32_t>(CHIP_ERASE_FUNC),
129+
reinterpret_cast<uint32_t>(VERIFY_FUNC),
130+
reinterpret_cast<uint32_t>(nullptr), // SEGGER_OPEN_CalcCRC
131+
reinterpret_cast<uint32_t>(OPEN_READ_FUNC),
132+
reinterpret_cast<uint32_t>(SEGGER_OPEN_Program),
133+
reinterpret_cast<uint32_t>(UNIFORM_ERASE_FUNC),
134+
reinterpret_cast<uint32_t>(nullptr), // SEGGER_OPEN_Start for turbo mode
135+
};
136+
112137
void __attribute__ ((noinline)) FeedWatchdog(void) {
113138
// TODO: implement something to keep the watchdog happy
114139
return;
@@ -185,20 +210,22 @@ int __attribute__ ((noinline)) SEGGER_OPEN_Program(uint32_t address, uint32_t si
185210
}
186211
#endif
187212

188-
#if !NATIVE_READ
189-
uint32_t __attribute__ ((noinline)) Verify(uint32_t Addr, uint32_t NumBytes, uint8_t *pBuff) {
213+
#if CUSTOM_VERIFY
214+
uint32_t __attribute__ ((noinline, __used__)) Verify(uint32_t Addr, uint32_t NumBytes, uint8_t *pBuff) {
190215
// TODO: implement verify
191216

192-
return 0;
217+
return (Addr + NumBytes);
193218
}
219+
#endif
194220

195-
int __attribute__ ((noinline)) BlankCheck(const uint32_t address, const uint32_t size, const uint8_t blank_value) {
196-
// TODO: implement blankcheck
221+
#if !NATIVE_READ
222+
int __attribute__ ((noinline, __used__)) BlankCheck(const uint32_t address, const uint32_t size, const uint8_t blank_value) {
223+
// TODO: implement verify
197224

198225
return 0;
199226
}
200227

201-
int __attribute__ ((noinline)) SEGGER_OPEN_Read(const uint32_t address, const uint32_t size, uint8_t *const data) {
228+
int __attribute__ ((noinline, __used__)) SEGGER_OPEN_Read(const uint32_t address, const uint32_t size, uint8_t *const data) {
202229
// TODO: add read implementation
203230

204231
return size;

0 commit comments

Comments
 (0)