8000 mimxrt/mboot: Fixes code review findings. · micropython/micropython@8d8c7de · GitHub
[go: up one dir, main page]

Skip to content

Commit 8d8c7de

Browse files
committed
mimxrt/mboot: Fixes code review findings.
Fixes code formatting with curly brackets on `for` loops and adds `void` argument to empty function declarations and definitions. Signed-off-by: Philipp Ebensberger
1 parent c665595 commit 8d8c7de

File tree

6 files changed

+23
-28
lines changed

6 files changed

+23
-28
lines changed

ports/mimxrt/mboot.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ CFLAGS_BL += \
105105
-nostdlib \
106106
-std=c99 \
107107
-Wall \
108+
-Werror \
108109
-Wdouble-promotion \
109110
-Werror \
110111
-Wfloat-conversion \

ports/mimxrt/mboot/main.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ extern uint32_t __firmware_start; // Linker symbol
6767
// --------------------------------------------------------------------+
6868
// External Function Declarations
6969
// --------------------------------------------------------------------+
70-
extern void SystemInit();
70+
extern void SystemInit(void);
7171

7272
// --------------------------------------------------------------------+
7373
// Local Function Declarations
@@ -94,8 +94,7 @@ int main(void) {
9494
}
9595

9696
// Fatal error occured - wait for power cycle
97-
for (;;)
98-
{
97+
for (;;) {
9998
__asm__ ("nop");
10099
}
101100

@@ -105,7 +104,7 @@ int main(void) {
105104
// --------------------------------------------------------------------+
106105
// Local Function Definitions
107106
// --------------------------------------------------------------------+
108-
static bool reprog_request() {
107+
static bool reprog_request(void) {
109108
bool reprogramming_requested = false;
110109

111110
if ((bl_command.magic == BOOT_COMMAND_MAGIC) && (bl_command.command == BOOT_COMMAND_RESET_DFU)) {
@@ -121,7 +120,7 @@ static bool reprog_request() {
121120
return reprogramming_requested;
122121
}
123122

124-
static bool valid_fw_available() {
123+
static bool valid_fw_available(void) {
125124
fw_header_t *fw_header = (fw_header_t *)MEM_GET_SYMBOL_VALUE(__firmware_start);
126125
uintptr_t start_addr = ((uintptr_t)MEM_GET_SYMBOL_VALUE(__firmware_start)) + sizeof(fw_header_t);
127126
mboot_validate_status_t fw_status = mboot_validate_firmware(fw_header, start_addr);
@@ -135,18 +134,17 @@ static inline firmware_entry_func get_entry_func() {
135134
return entry_func;
136135
}
137136

138-
static inline void fw_start() {
137+
static inline void fw_start(void) {
139138
firmware_entry_func entry_func = get_entry_func();
140139

141140
entry_func();
142141

143-
for (;;)
144-
{
142 E30A +
for (;;) {
145143
__asm__ ("nop");
146144
}
147145
}
148146

149-
static void board_init() {
147+
static void board_init(void) {
150148
// Init clock
151149
BOARD_BootClockRUN();
152150
SystemCoreClockUpdate();

ports/mimxrt/mboot/mboot_buffer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
// --------------------------------------------------------------------+
4242
// Global Function Declarations
4343
// --------------------------------------------------------------------+
44-
void mboot_buffer_init();
44+
void mboot_buffer_init(void);
4545
size_t mboot_buffer_append(const uint8_t *data, size_t length);
4646
void mboot_buffer_pad(void);
4747
void mboot_buffer_reset(void);

ports/mimxrt/mboot/mboot_upgrade.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,16 @@ extern uintptr_t __flash_start;
7474
// --------------------------------------------------------------------+
7575
// Local Function Declarations
7676
// --------------------------------------------------------------------+
77-
static mboot_upgrade_status_t write_initial_block_handler();
78-
static mboot_upgrade_status_t write_block_handler();
77+
static mboot_upgrade_status_t write_initial_block_handler(void);
78+
static mboot_upgrade_status_t write_block_handler(void);
7979
static mboot_upgrade_status_t write_block(uint8_t *data, uint32_t length, uintptr_t *eaddr, uintptr_t *waddr);
8080

8181
// --------------------------------------------------------------------+
8282
// Global Function Definitions
8383
// --------------------------------------------------------------------+
8484

8585
// Todo: Add configuration structure
86-
mboot_upgrade_status_t mboot_upgrade_init() {
86+
mboot_upgrade_status_t mboot_upgrade_init(void) {
8787
flash_init();
8888

8989
// Initialize firmware upgrade session
@@ -109,7 +109,7 @@ mboot_upgrade_status_t mboot_upgrade_init() {
109109
return BU_STATUS_OK;
110110
}
111111

112-
mboot_upgrade_status_t mboot_upgrade_deinit() {
112+
mboot_upgrade_status_t mboot_upgrade_deinit(void) {
113113
// De-initialize firmware upgrade session
114114
session.n_blocks = 0UL;
115115
session.n_bytes_written = 0UL;
@@ -213,7 +213,7 @@ mboot_upgrade_status_t mboot_upgrade_validate() {
213213
// --------------------------------------------------------------------+
214214
// Local Function Definitions
215215
// --------------------------------------------------------------------+
216-
static mboot_upgrade_status_t write_initial_block_handler() {
216+
static mboot_upgrade_status_t write_initial_block_handler(void) {
217217
mboot_upgrade_status_t ret_status = BU_STATUS_UNKNOWN_ERROR;
218218
uint8_t *data = mboot_buffer_data_ptr();
219219
uint32_t length = mboot_buffer_len();
@@ -253,7 +253,7 @@ static mboot_upgrade_status_t write_initial_block_handler() {
253253
return ret_status;
254254
}
255255

256-
static mboot_upgrade_status_t write_block_handler() {
256+
static mboot_upgrade_status_t write_block_handler(void) {
257257
mboot_upgrade_status_t ret_status = BU_STATUS_UNKNOWN_ERROR;
258258
uint8_t *data = mboot_buffer_data_ptr();
259259
uint32_t length = mboot_buffer_len();

ports/mimxrt/mboot/mboot_upgrade.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ typedef enum _mboot_upgrade_status_t {
4545
/**
4646
* Initializes firmware upgrade session base don selected configuration.
4747
*/
48-
mboot_upgrade_status_t mboot_upgrade_init();
48+
mboot_upgrade_status_t mboot_upgrade_init(void);
4949

5050
/**
5151
* De-initializes firmware upgrade session.
5252
*/
53-
mboot_upgrade_status_t mboot_upgrade_deinit();
53+
mboot_upgrade_status_t mboot_upgrade_deinit(void);
5454

5555
/**
5656
* Write block of data to memory.
@@ -63,13 +63,13 @@ mboot_upgrade_status_t mboot_upgrade_write_data(uint16_t block_num, const uint8_
6363
* Finalize firmware upgrade by:
6464
* - flushing remaining data from buffer and write to memory
6565
**/
66-
mboot_upgrade_status_t mboot_upgrade_finalize();
66+
mboot_upgrade_status_t mboot_upgrade_finalize(void);
6767

6868
/**
6969
* Check and validate firmware upgrade:
7070
* - check written data
7171
* - valdiate firmware image if check ok
7272
**/
73-
mboot_upgrade_status_t mboot_upgrade_validate();
73+
mboot_upgrade_status_t mboot_upgrade_validate(void);
7474

7575
#endif // MICROPY_INCLUDED_MIMXRT_MBOOT_UPGRADE_H

ports/mimxrt/mboot/mboot_validate.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ mboot_validate_status_t mboot_validate_header(fw_header_t *img_header) {
8484
static uint8_t reflect8(uint8_t val) {
8585
uint8_t resVal = 0;
8686

87-
for (int i = 0; i < 8; i++)
88-
{
87+
for (int i = 0; i < 8; i++) {
8988
if ((val & (1 << i)) != 0) {
9089
resVal |= (uint8_t)(1 << (7 - i));
9190
}
@@ -97,8 +96,7 @@ static uint8_t reflect8(uint8_t val) {
9796
static uint32_t reflect32(uint32_t val) {
9897
uint32_t resVal = 0;
9998

100-
for (int i = 0; i < 32; i++)
101-
{
99+
for (int i = 0; i < 32; i++) {
102100
if ((val & (1 << i)) != 0) {
103101
resVal |= (uint32_t)(1 << (31 - i));
104102
}
@@ -110,14 +108,12 @@ static uint32_t reflect32(uint32_t val) {
110108
uint32_t crc32(const uint8_t *data, size_t len) {
111109
uint32_t crc = crc_initial;
112110

113-
for (int i = 0; i < len; ++i)
114-
{
111+
for (int i = 0; i < len; ++i) {
115112
uint8_t curByte = reflect8(data[i]);
116113

117114
crc ^= (uint32_t)(curByte << 24); /* move byte into MSB of 32bit CRC */
118115

119-
for (int i = 0; i < 8; i++)
120-
{
116+
for (int i = 0; i < 8; i++) {
121117
if ((crc & 0x80000000) != 0) { /* test for MSB = bit 31 */
122118
crc = (uint32_t)((crc << 1) ^ crc_polynomial);
123119
} else {

0 commit comments

Comments
 (0)
0