Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Miosix Kernel
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Avionics
Software Development
Miosix Kernel
Commits
c2a41db2
Commit
c2a41db2
authored
6 years ago
by
Alvise de'Faveri
Browse files
Options
Downloads
Patches
Plain Diff
[aderaan] Added flash check in stage1boot
parent
8331edc2
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
miosix/arch/cortexM3_stm32/stm32f103c8_skyward_alderaan/core/stage_1_boot.cpp
+37
-0
37 additions, 0 deletions
..._stm32/stm32f103c8_skyward_alderaan/core/stage_1_boot.cpp
with
37 additions
and
0 deletions
miosix/arch/cortexM3_stm32/stm32f103c8_skyward_alderaan/core/stage_1_boot.cpp
+
37
−
0
View file @
c2a41db2
...
@@ -16,6 +16,39 @@
...
@@ -16,6 +16,39 @@
//stage_2_boot.cpp
//stage_2_boot.cpp
extern
"C"
void
_init
();
extern
"C"
void
_init
();
#define _FLASH_BASE 0x08000000
#define _FLASH_END 0x0801FFFF
/**
* Calculate the CRC of the whole flash and enter an infinite loop if is not 0.
*
* NOTE: During compilation, the program binary has been padded to reach 128k and
* then the CRC has been calculated and placed in the last 4 bytes of the flash.
* Since CRC(foo + CRC(foo)) = 0, we expect the CRC calculated here to be 0.
*/
void
checkFlash
()
{
// Enable CRC clock
RCC
->
AHBENR
|=
RCC_AHBENR_CRCEN
;
CRC
->
CR
=
1
;
// reset initial value
// Calculate CRC of whole flash (32 bits at a time)
// NOTE: writing DR causes the new CRC to be calculated and then loaded back
// in DR for the next iteration
for
(
uint32_t
i
=
_FLASH_BASE
;
i
<
_FLASH_END
;
i
+=
4
)
{
CRC
->
DR
=
*
((
uint32_t
*
)
i
);
}
// Disable CRC clock
RCC
->
AHBENR
&=
~
RCC_AHBENR_CRCEN
;
// CRC->DR now contains the CRC value of the whole flash (bin + loaded crc).
// If it's not 0, the flash is broken -> enter in an infinite loop.
if
(
CRC
->
DR
!=
0
)
for
(;;);
}
/**
/**
* Called by Reset_Handler, performs initialization and calls main.
* Called by Reset_Handler, performs initialization and calls main.
* Never returns.
* Never returns.
...
@@ -26,6 +59,10 @@ void program_startup()
...
@@ -26,6 +59,10 @@ void program_startup()
//Cortex M3 core appears to get out of reset with interrupts already enabled
//Cortex M3 core appears to get out of reset with interrupts already enabled
__disable_irq
();
__disable_irq
();
// checkFlash() blocks if the flash CRC is not correct: this prevents the
// microcontroller from doing something nasty if the flash is corrupted.
checkFlash
();
//SystemInit() is called *before* initializing .data and zeroing .bss
//SystemInit() is called *before* initializing .data and zeroing .bss
//Despite all startup files provided by ST do the opposite, there are three
//Despite all startup files provided by ST do the opposite, there are three
//good reasons to do so:
//good reasons to do so:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment