Skip to content

Commit 47dfdac

Browse files
committed
port: zephyr: run clang-format on files
No substantive changes were made in this commit. It merely applies the clang-format rules to these files. Signed-off-by: Mike Szczys <[email protected]>
1 parent eed44de commit 47dfdac

File tree

3 files changed

+171
-103
lines changed

3 files changed

+171
-103
lines changed

port/zephyr/golioth_fw_zephyr.c

Lines changed: 76 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ LOG_MODULE_REGISTER(golioth_fw_zephyr);
1515

1616
struct flash_img_context _flash_img_context;
1717

18-
bool fw_update_is_pending_verify(void) {
19-
if (!IS_ENABLED(CONFIG_BOOTLOADER_MCUBOOT)) {
18+
bool fw_update_is_pending_verify(void)
19+
{
20+
if (!IS_ENABLED(CONFIG_BOOTLOADER_MCUBOOT))
21+
{
2022
return false;
2123
}
2224

@@ -25,8 +27,10 @@ bool fw_update_is_pending_verify(void) {
2527

2628
void fw_update_rollback(void) {}
2729

28-
void fw_update_reboot(void) {
29-
if (!IS_ENABLED(CONFIG_BOOTLOADER_MCUBOOT)) {
30+
void fw_update_reboot(void)
31+
{
32+
if (!IS_ENABLED(CONFIG_BOOTLOADER_MCUBOOT))
33+
{
3034
return;
3135
}
3236

@@ -43,7 +47,8 @@ void fw_update_reboot(void) {
4347
*
4448
* @note This is a copy of zephyr_img_mgmt_flash_check_empty() from mcumgr.
4549
*/
46-
static int flash_area_check_empty(const struct flash_area* fa, bool* out_empty) {
50+
static int flash_area_check_empty(const struct flash_area *fa, bool *out_empty)
51+
{
4752
uint32_t data[16];
4853
off_t addr;
4954
off_t end;
@@ -59,21 +64,28 @@ static int flash_area_check_empty(const struct flash_area* fa, bool* out_empty)
5964
erased_val_32 = ERASED_VAL_32(erased_val);
6065

6166
end = fa->fa_size;
62-
for (addr = 0; addr < end; addr += sizeof(data)) {
63-
if (end - addr < sizeof(data)) {
67+
for (addr = 0; addr < end; addr += sizeof(data))
68+
{
69+
if (end - addr < sizeof(data))
70+
{
6471
bytes_to_read = end - addr;
65-
} else {
72+
}
73+
else
74+
{
6675
bytes_to_read = sizeof(data);
6776
}
6877

6978
rc = flash_area_read(fa, addr, data, bytes_to_read);
70-
if (rc != 0) {
79+
if (rc != 0)
80+
{
7181
flash_area_close(fa);
7282
return rc;
7383
}
7484

75-
for (i = 0; i < bytes_to_read / 4; i++) {
76-
if (data[i] != erased_val_32) {
85+
for (i = 0; i < bytes_to_read / 4; i++)
86+
{
87+
if (data[i] != erased_val_32)
88+
{
7789
*out_empty = false;
7890
flash_area_close(fa);
7991
return 0;
@@ -86,33 +98,40 @@ static int flash_area_check_empty(const struct flash_area* fa, bool* out_empty)
8698
return 0;
8799
}
88100

89-
static int flash_img_erase_if_needed(struct flash_img_context* ctx) {
101+
static int flash_img_erase_if_needed(struct flash_img_context *ctx)
102+
{
90103
bool empty;
91104
int err;
92105

93-
if (IS_ENABLED(CONFIG_IMG_ERASE_PROGRESSIVELY)) {
106+
if (IS_ENABLED(CONFIG_IMG_ERASE_PROGRESSIVELY))
107+
{
94108
return 0;
95109
}
96110

97111
err = flash_area_check_empty(ctx->flash_area, &empty);
98-
if (err) {
112+
if (err)
113+
{
99114
return err;
100115
}
101116

102-
if (empty) {
117+
if (empty)
118+
{
103119
return 0;
104120
}
105121

106122
err = flash_area_erase(ctx->flash_area, 0, ctx->flash_area->fa_size);
107-
if (err) {
123+
if (err)
124+
{
108125
return err;
109126
}
110127

111128
return 0;
112129
}
113130

114-
static const char* swap_type_str(int swap_type) {
115-
switch (swap_type) {
131+
static const char *swap_type_str(int swap_type)
132+
{
133+
switch (swap_type)
134+
{
116135
case BOOT_SWAP_TYPE_NONE:
117136
return "none";
118137
case BOOT_SWAP_TYPE_TEST:
@@ -128,12 +147,14 @@ static const char* swap_type_str(int swap_type) {
128147
return "unknown";
129148
}
130149

131-
static int flash_img_prepare(struct flash_img_context* flash) {
150+
static int flash_img_prepare(struct flash_img_context *flash)
151+
{
132152
int swap_type;
133153
int err;
134154

135155
swap_type = mcuboot_swap_type();
136-
switch (swap_type) {
156+
switch (swap_type)
157+
{
137158
case BOOT_SWAP_TYPE_REVERT:
138159
LOG_WRN("'revert' swap type detected, it is not safe to continue");
139160
return -EBUSY;
@@ -143,81 +164,96 @@ static int flash_img_prepare(struct flash_img_context* flash) {
143164
}
144165

145166
err = flash_img_init(flash);
146-
if (err) {
167+
if (err)
168+
{
147169
LOG_ERR("failed to init: %d", err);
148170
return err;
149171
}
150172

151173
err = flash_img_erase_if_needed(flash);
152-
if (err) {
174+
if (err)
175+
{
153176
LOG_ERR("failed to erase: %d", err);
154177
return err;
155178
}
156179

157180
return 0;
158181
}
159182

160-
void fw_update_cancel_rollback(void) {
161-
if (!IS_ENABLED(CONFIG_BOOTLOADER_MCUBOOT)) {
183+
void fw_update_cancel_rollback(void)
184+
{
185+
if (!IS_ENABLED(CONFIG_BOOTLOADER_MCUBOOT))
186+
{
162187
return;
163188
}
164189

165190
boot_write_img_confirmed();
166191
}
167192

168-
enum golioth_status fw_update_handle_block(
169-
const uint8_t* block,
170-
size_t block_size,
171-
size_t offset,
172-
size_t total_size) {
193+
enum golioth_status fw_update_handle_block(const uint8_t *block,
194+
size_t block_size,
195+
size_t offset,
196+
size_t total_size)
197+
{
173198
int err;
174199

175-
if (!IS_ENABLED(CONFIG_BOOTLOADER_MCUBOOT)) {
200+
if (!IS_ENABLED(CONFIG_BOOTLOADER_MCUBOOT))
201+
{
176202
return GOLIOTH_OK;
177203
}
178204

179-
if (offset == 0) {
205+
if (offset == 0)
206+
{
180207
err = flash_img_prepare(&_flash_img_context);
181-
if (err) {
208+
if (err)
209+
{
182210
return GOLIOTH_ERR_FAIL;
183211
}
184212
}
185213

186214
err = flash_img_buffered_write(&_flash_img_context, block, block_size, false);
187-
if (err) {
215+
if (err)
216+
{
188217
LOG_ERR("Failed to write to flash: %d", err);
189218
return GOLIOTH_ERR_FAIL;
190219
}
191220

192221
return GOLIOTH_OK;
193222
}
194223

195-
void fw_update_post_download(void) {
224+
void fw_update_post_download(void)
225+
{
196226
int err;
197227

198-
if (!_flash_img_context.stream.buf_bytes) {
228+
if (!_flash_img_context.stream.buf_bytes)
229+
{
199230
return;
200231
}
201232

202233
err = flash_img_buffered_write(&_flash_img_context, NULL, 0, true);
203-
if (err) {
234+
if (err)
235+
{
204236
LOG_ERR("Failed to write to flash: %d", err);
205237
}
206238
}
207239

208-
enum golioth_status fw_update_validate(void) {
240+
enum golioth_status fw_update_validate(void)
241+
{
209242
return GOLIOTH_OK;
210243
}
211244

212-
enum golioth_status fw_update_change_boot_image(void) {
245+
enum golioth_status fw_update_change_boot_image(void)
246+
{
213247
int err;
214248

215-
if (!IS_ENABLED(CONFIG_BOOTLOADER_MCUBOOT)) {
249+
if (!IS_ENABLED(CONFIG_BOOTLOADER_MCUBOOT))
250+
{
216251
return GOLIOTH_ERR_NOT_IMPLEMENTED;
217252
}
218253

219254
err = boot_request_upgrade(BOOT_UPGRADE_TEST);
220-
if (err) {
255+
if (err)
256+
{
221257
return GOLIOTH_ERR_FAIL;
222258
}
223259

port/zephyr/golioth_log_zephyr.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
int log_backend_golioth_enable(void* client);
8-
int log_backend_golioth_disable(void* client);
7+
int log_backend_golioth_enable(void *client);
8+
int log_backend_golioth_disable(void *client);

0 commit comments

Comments
 (0)