Skip to content

Commit

Permalink
port: zephyr: run clang-format on files
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
szczys committed Aug 23, 2024
1 parent 29e5463 commit f7e5ee1
Show file tree
Hide file tree
Showing 3 changed files with 175 additions and 107 deletions.
124 changes: 80 additions & 44 deletions port/zephyr/golioth_fw_zephyr.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ LOG_MODULE_REGISTER(golioth_fw_zephyr);

struct flash_img_context _flash_img_context;

bool fw_update_is_pending_verify(void) {
if (!IS_ENABLED(CONFIG_BOOTLOADER_MCUBOOT)) {
bool fw_update_is_pending_verify(void)
{
if (!IS_ENABLED(CONFIG_BOOTLOADER_MCUBOOT))
{
return false;
}

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

void fw_update_rollback(void) {}

void fw_update_reboot(void) {
if (!IS_ENABLED(CONFIG_BOOTLOADER_MCUBOOT)) {
void fw_update_reboot(void)
{
if (!IS_ENABLED(CONFIG_BOOTLOADER_MCUBOOT))
{
return;
}

Expand All @@ -43,7 +47,8 @@ void fw_update_reboot(void) {
*
* @note This is a copy of zephyr_img_mgmt_flash_check_empty() from mcumgr.
*/
static int flash_area_check_empty(const struct flash_area* fa, bool* out_empty) {
static int flash_area_check_empty(const struct flash_area *fa, bool *out_empty)
{
uint32_t data[16];
off_t addr;
off_t end;
Expand All @@ -59,21 +64,28 @@ static int flash_area_check_empty(const struct flash_area* fa, bool* out_empty)
erased_val_32 = ERASED_VAL_32(erased_val);

end = fa->fa_size;
for (addr = 0; addr < end; addr += sizeof(data)) {
if (end - addr < sizeof(data)) {
for (addr = 0; addr < end; addr += sizeof(data))
{
if (end - addr < sizeof(data))
{
bytes_to_read = end - addr;
} else {
}
else
{
bytes_to_read = sizeof(data);
}

rc = flash_area_read(fa, addr, data, bytes_to_read);
if (rc != 0) {
if (rc != 0)
{
flash_area_close(fa);
return rc;
}

for (i = 0; i < bytes_to_read / 4; i++) {
if (data[i] != erased_val_32) {
for (i = 0; i < bytes_to_read / 4; i++)
{
if (data[i] != erased_val_32)
{
*out_empty = false;
flash_area_close(fa);
return 0;
Expand All @@ -86,33 +98,40 @@ static int flash_area_check_empty(const struct flash_area* fa, bool* out_empty)
return 0;
}

static int flash_img_erase_if_needed(struct flash_img_context* ctx) {
static int flash_img_erase_if_needed(struct flash_img_context *ctx)
{
bool empty;
int err;

if (IS_ENABLED(CONFIG_IMG_ERASE_PROGRESSIVELY)) {
if (IS_ENABLED(CONFIG_IMG_ERASE_PROGRESSIVELY))
{
return 0;
}

err = flash_area_check_empty(ctx->flash_area, &empty);
if (err) {
if (err)
{
return err;
}

if (empty) {
if (empty)
{
return 0;
}

err = flash_area_erase(ctx->flash_area, 0, ctx->flash_area->fa_size);
if (err) {
if (err)
{
return err;
}

return 0;
}

static const char* swap_type_str(int swap_type) {
switch (swap_type) {
static const char *swap_type_str(int swap_type)
{
switch (swap_type)
{
case BOOT_SWAP_TYPE_NONE:
return "none";
case BOOT_SWAP_TYPE_TEST:
Expand All @@ -128,12 +147,14 @@ static const char* swap_type_str(int swap_type) {
return "unknown";
}

static int flash_img_prepare(struct flash_img_context* flash) {
static int flash_img_prepare(struct flash_img_context *flash)
{
int swap_type;
int err;

swap_type = mcuboot_swap_type();
switch (swap_type) {
switch (swap_type)
{
case BOOT_SWAP_TYPE_REVERT:
LOG_WRN("'revert' swap type detected, it is not safe to continue");
return -EBUSY;
Expand All @@ -143,81 +164,96 @@ static int flash_img_prepare(struct flash_img_context* flash) {
}

err = flash_img_init(flash);
if (err) {
if (err)
{
LOG_ERR("failed to init: %d", err);
return err;
}

err = flash_img_erase_if_needed(flash);
if (err) {
if (err)
{
LOG_ERR("failed to erase: %d", err);
return err;
}

return 0;
}

void fw_update_cancel_rollback(void) {
if (!IS_ENABLED(CONFIG_BOOTLOADER_MCUBOOT)) {
void fw_update_cancel_rollback(void)
{
if (!IS_ENABLED(CONFIG_BOOTLOADER_MCUBOOT))
{
return;
}

boot_write_img_confirmed();
}

enum golioth_status fw_update_handle_block(
const uint8_t* block,
size_t block_size,
size_t offset,
size_t total_size) {
enum golioth_status fw_update_handle_block(const uint8_t *block,
size_t block_size,
size_t offset,
size_t total_size)
{
int err;

if (!IS_ENABLED(CONFIG_BOOTLOADER_MCUBOOT)) {
if (!IS_ENABLED(CONFIG_BOOTLOADER_MCUBOOT))
{
return GOLIOTH_OK;
}

if (offset == 0) {
if (offset == 0)
{
err = flash_img_prepare(&_flash_img_context);
if (err) {
if (err)
{
return GOLIOTH_ERR_FAIL;
}
}

err = flash_img_buffered_write(&_flash_img_context, block, block_size, false);
if (err) {
if (err)
{
LOG_ERR("Failed to write to flash: %d", err);
return GOLIOTH_ERR_FAIL;
}

return GOLIOTH_OK;
}

void fw_update_post_download(void) {
void fw_update_post_download(void)
{
int err;

if (!_flash_img_context.stream.buf_bytes) {
if (!_flash_img_context.stream.buf_bytes)
{
return;
}

err = flash_img_buffered_write(&_flash_img_context, NULL, 0, true);
if (err) {
if (err)
{
LOG_ERR("Failed to write to flash: %d", err);
}
}

enum golioth_status fw_update_validate(void) {
enum golioth_status fw_update_validate(void)
{
return GOLIOTH_OK;
}

enum golioth_status fw_update_change_boot_image(void) {
enum golioth_status fw_update_change_boot_image(void)
{
int err;

if (!IS_ENABLED(CONFIG_BOOTLOADER_MCUBOOT)) {
if (!IS_ENABLED(CONFIG_BOOTLOADER_MCUBOOT))
{
return GOLIOTH_ERR_NOT_IMPLEMENTED;
}

err = boot_request_upgrade(BOOT_UPGRADE_TEST);
if (err) {
if (err)
{
return GOLIOTH_ERR_FAIL;
}

Expand All @@ -226,9 +262,9 @@ enum golioth_status fw_update_change_boot_image(void) {

void fw_update_end(void) {}

enum golioth_status fw_update_read_current_image_at_offset(
uint8_t* buf,
size_t bufsize,
size_t offset) {
enum golioth_status fw_update_read_current_image_at_offset(uint8_t *buf,
size_t bufsize,
size_t offset)
{
return GOLIOTH_ERR_NOT_IMPLEMENTED;
}
4 changes: 2 additions & 2 deletions port/zephyr/golioth_log_zephyr.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
* SPDX-License-Identifier: Apache-2.0
*/

int log_backend_golioth_enable(void* client);
int log_backend_golioth_disable(void* client);
int log_backend_golioth_enable(void *client);
int log_backend_golioth_disable(void *client);
Loading

0 comments on commit f7e5ee1

Please sign in to comment.