Fix static analysis errors
Fix checkpatch and cppcheck findings in newly added FWU files.
Change-Id: Ie6a877e65b758399647ceda345ae22081d911f8e
Signed-off-by: Gyorgy Szing <Gyorgy.Szing@arm.com>
diff --git a/deployments/fwu/config/default-opteesp/optee_sp_user_defines.h b/deployments/fwu/config/default-opteesp/optee_sp_user_defines.h
index 66cd9f2..e5fb8c1 100644
--- a/deployments/fwu/config/default-opteesp/optee_sp_user_defines.h
+++ b/deployments/fwu/config/default-opteesp/optee_sp_user_defines.h
@@ -6,9 +6,9 @@
#ifndef OPTEE_SP_USER_DEFINES_H
#define OPTEE_SP_USER_DEFINES_H
-#define OPTEE_SP_FLAGS 0
+#define OPTEE_SP_FLAGS 0
/* Provisioned stack size */
-#define OPTEE_SP_STACK_SIZE (64 * 1024)
+#define OPTEE_SP_STACK_SIZE (64 * 1024)
#endif /* SP_HEADER_DEFINES_H */
diff --git a/deployments/fwu/env/commonsp/fwu_sp.c b/deployments/fwu/env/commonsp/fwu_sp.c
index 016ec50..bf7cbe8 100644
--- a/deployments/fwu/env/commonsp/fwu_sp.c
+++ b/deployments/fwu/env/commonsp/fwu_sp.c
@@ -4,38 +4,37 @@
*/
#include <stddef.h>
-#include <sp_api.h>
-#include <sp_discovery.h>
-#include <sp_messaging.h>
-#include <sp_rxtx.h>
-#include <trace.h>
-#include <rpc/ffarpc/endpoint/ffarpc_call_ep.h>
-#include <protocols/rpc/common/packed-c/status.h>
-#include <config/ramstore/config_ramstore.h>
-#include <config/loader/sp/sp_config_loader.h>
-#include <media/volume/factory/volume_factory.h>
-#include <service/fwu/config/fwu_configure.h>
-#include <service/discovery/provider/discovery_provider.h>
-#include <service/discovery/provider/serializer/packed-c/packedc_discovery_provider_serializer.h>
-#include <service/fwu/provider/fwu_provider.h>
-#include <service/fwu/provider/serializer/packed-c/packedc_fwu_provider_serializer.h>
-#include <service/fwu/fw_store/banked/bank_scheme.h>
-#include <service/fwu/fw_store/banked/metadata_serializer/v1/metadata_serializer_v1.h>
-#include <service/fwu/fw_store/banked/metadata_serializer/v2/metadata_serializer_v2.h>
-#include <service/fwu/inspector/direct/direct_fw_inspector.h>
-#include <service/fwu/agent/update_agent.h>
-#include <service/fwu/fw_store/banked/banked_fw_store.h>
+#include "config/loader/sp/sp_config_loader.h"
+#include "config/ramstore/config_ramstore.h"
+#include "media/volume/factory/volume_factory.h"
+#include "protocols/rpc/common/packed-c/status.h"
+#include "rpc/ffarpc/endpoint/ffarpc_call_ep.h"
+#include "service/discovery/provider/discovery_provider.h"
+#include "service/discovery/provider/serializer/packed-c/packedc_discovery_provider_serializer.h"
+#include "service/fwu/agent/update_agent.h"
+#include "service/fwu/config/fwu_configure.h"
+#include "service/fwu/fw_store/banked/bank_scheme.h"
+#include "service/fwu/fw_store/banked/banked_fw_store.h"
+#include "service/fwu/fw_store/banked/metadata_serializer/v1/metadata_serializer_v1.h"
+#include "service/fwu/fw_store/banked/metadata_serializer/v2/metadata_serializer_v2.h"
+#include "service/fwu/inspector/direct/direct_fw_inspector.h"
+#include "service/fwu/provider/fwu_provider.h"
+#include "service/fwu/provider/serializer/packed-c/packedc_fwu_provider_serializer.h"
+#include "sp_api.h"
+#include "sp_discovery.h"
+#include "sp_messaging.h"
+#include "sp_rxtx.h"
+#include "trace.h"
/* Set default limit on the number of storage devices to update */
#ifndef FWU_SP_MAX_STORAGE_DEVICES
-#define FWU_SP_MAX_STORAGE_DEVICES (1)
+#define FWU_SP_MAX_STORAGE_DEVICES (1)
#endif
/* Parameters that should be passed forward by the bootloader */
-#define HARD_CODED_BOOT_INDEX (0)
-#define HARD_CODED_METADATA_VER (2)
-
+#define HARD_CODED_BOOT_INDEX (0)
+#define HARD_CODED_METADATA_VER (2)
static bool sp_init(uint16_t *own_sp_id);
static bool configure_for_platform(void);
@@ -87,31 +86,26 @@
goto fatal_error;
}
- if (update_agent_init(&update_agent, HARD_CODED_BOOT_INDEX,
- direct_fw_inspector_inspect, &fw_store)) {
+ if (update_agent_init(&update_agent, HARD_CODED_BOOT_INDEX, direct_fw_inspector_inspect,
+ &fw_store)) {
EMSG("Failed to init update agent");
goto fatal_error;
}
/* Initialise the FWU service provider */
- service_iface = fwu_provider_init(
- &service_provider,
- &update_agent);
+ service_iface = fwu_provider_init(&service_provider, &update_agent);
if (!service_iface) {
EMSG("Failed to init service provider");
goto fatal_error;
}
- fwu_provider_register_serializer(
- &service_provider,
- TS_RPC_ENCODING_PACKED_C,
- packedc_fwu_provider_serializer_instance());
+ fwu_provider_register_serializer(&service_provider, TS_RPC_ENCODING_PACKED_C,
+ packedc_fwu_provider_serializer_instance());
- discovery_provider_register_serializer(
- &service_provider.discovery_provider,
- TS_RPC_ENCODING_PACKED_C,
- packedc_discovery_provider_serializer_instance());
+ discovery_provider_register_serializer(&service_provider.discovery_provider,
+ TS_RPC_ENCODING_PACKED_C,
+ packedc_discovery_provider_serializer_instance());
/* Associate service interface with FFA call endpoint */
ffa_call_ep_init(&ffarpc_call_ep, service_iface, own_id);
@@ -140,7 +134,8 @@
fatal_error:
/* SP is not viable */
EMSG("FWU SP error");
- while (1) {}
+ while (1) {
+ }
}
void sp_interrupt_handler(uint32_t interrupt_id)
@@ -150,11 +145,10 @@
static bool sp_init(uint16_t *own_id)
{
- sp_result sp_res = SP_RESULT_INTERNAL_ERROR;
static uint8_t tx_buffer[4096] __aligned(4096);
static uint8_t rx_buffer[4096] __aligned(4096);
- sp_res = sp_rxtx_buffer_map(tx_buffer, rx_buffer, sizeof(rx_buffer));
+ sp_result sp_res = sp_rxtx_buffer_map(tx_buffer, rx_buffer, sizeof(rx_buffer));
if (sp_res != SP_RESULT_OK) {
EMSG("Failed to map RXTX buffers: %d", sp_res);
return false;
@@ -174,11 +168,10 @@
struct uuid_octets device_uuids[FWU_SP_MAX_STORAGE_DEVICES];
size_t num_storage_devices = 0;
- int status = volume_factory_init(device_uuids,
- FWU_SP_MAX_STORAGE_DEVICES, &num_storage_devices);
+ int status =
+ volume_factory_init(device_uuids, FWU_SP_MAX_STORAGE_DEVICES, &num_storage_devices);
if (status) {
-
EMSG("Failed to init volume factory: %d", status);
return false;
}
@@ -186,7 +179,6 @@
status = fwu_configure(device_uuids, num_storage_devices);
if (status) {
-
EMSG("Failed to setup FWU configuration: %d", status);
return false;
}
diff --git a/deployments/fwu/env/posix/cmd_print_image_dir.cpp b/deployments/fwu/env/posix/cmd_print_image_dir.cpp
index 0060ebd..1e07027 100644
--- a/deployments/fwu/env/posix/cmd_print_image_dir.cpp
+++ b/deployments/fwu/env/posix/cmd_print_image_dir.cpp
@@ -4,17 +4,18 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <vector>
+#include "cmd_print_image_dir.h"
+
#include <cstdint>
#include <cstdio>
#include <cstdlib>
-#include <common/uuid/uuid.h>
-#include <protocols/service/fwu/packed-c/fwu_proto.h>
-#include "cmd_print_image_dir.h"
-#include "print_uuid.h"
+#include <vector>
-void cmd_print_image_dir(
- fwu_app &app)
+#include "common/uuid/uuid.h"
+#include "print_uuid.h"
+#include "protocols/service/fwu/packed-c/fwu_proto.h"
+
+void cmd_print_image_dir(fwu_app &app)
{
std::vector<uint8_t> fetched_object;
struct uuid_octets object_uuid;
@@ -24,13 +25,11 @@
int status = app.read_object(object_uuid, fetched_object);
if (status) {
-
printf("Error: failed to read image directory\n");
return;
}
if (fetched_object.size() < offsetof(ts_fwu_image_directory, img_info_entry)) {
-
printf("Error: invalid image directory size\n");
return;
}
@@ -38,25 +37,21 @@
const struct ts_fwu_image_directory *img_dir =
(const struct ts_fwu_image_directory *)fetched_object.data();
- printf("\nimage_directory (size %ld bytes) :\n", fetched_object.size());
+ printf("\nimage_directory (size %zu bytes) :\n", fetched_object.size());
printf("\tdirectory_version : %d\n", img_dir->directory_version);
printf("\tnum_images : %d\n", img_dir->num_images);
printf("\tcorrect_boot : %d\n", img_dir->correct_boot);
for (unsigned int i = 0; i < img_dir->num_images; i++) {
-
- printf("\timg_info_entry[%d]:\n", i);
+ printf("\timg_info_entry[%u]:\n", i);
printf("\t\timg_type_uuid : %s\n",
- print_uuid(img_dir->img_info_entry[i].img_type_uuid).c_str());
+ print_uuid(img_dir->img_info_entry[i].img_type_uuid).c_str());
printf("\t\tclient_permissions : 0x%x\n",
- img_dir->img_info_entry[i].client_permissions);
- printf("\t\timg_max_size : %d\n",
- img_dir->img_info_entry[i].img_max_size);
+ img_dir->img_info_entry[i].client_permissions);
+ printf("\t\timg_max_size : %d\n", img_dir->img_info_entry[i].img_max_size);
printf("\t\tlowest_accepted_version : %d\n",
- img_dir->img_info_entry[i].lowest_accepted_version);
- printf("\t\timg_version : %d\n",
- img_dir->img_info_entry[i].img_version);
- printf("\t\taccepted : %d\n",
- img_dir->img_info_entry[i].accepted);
+ img_dir->img_info_entry[i].lowest_accepted_version);
+ printf("\t\timg_version : %d\n", img_dir->img_info_entry[i].img_version);
+ printf("\t\taccepted : %d\n", img_dir->img_info_entry[i].accepted);
}
}
diff --git a/deployments/fwu/env/posix/cmd_print_image_dir.h b/deployments/fwu/env/posix/cmd_print_image_dir.h
index 1630734..7ae2e01 100644
--- a/deployments/fwu/env/posix/cmd_print_image_dir.h
+++ b/deployments/fwu/env/posix/cmd_print_image_dir.h
@@ -8,7 +8,7 @@
#ifndef CMD_PRINT_IMAGE_DIR_H
#define CMD_PRINT_IMAGE_DIR_H
-#include <service/fwu/app/fwu_app.h>
+#include "service/fwu/app/fwu_app.h"
void cmd_print_image_dir(fwu_app &app);
diff --git a/deployments/fwu/env/posix/cmd_print_metadata_v1.cpp b/deployments/fwu/env/posix/cmd_print_metadata_v1.cpp
index 3762745..6539e57 100644
--- a/deployments/fwu/env/posix/cmd_print_metadata_v1.cpp
+++ b/deployments/fwu/env/posix/cmd_print_metadata_v1.cpp
@@ -4,19 +4,19 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <vector>
+#include "cmd_print_metadata_v1.h"
+
#include <cstdint>
#include <cstdio>
#include <cstdlib>
-#include <common/uuid/uuid.h>
-#include <protocols/service/fwu/packed-c/fwu_proto.h>
-#include <protocols/service/fwu/packed-c/metadata_v1.h>
-#include "cmd_print_metadata_v1.h"
+#include <vector>
+
+#include "common/uuid/uuid.h"
#include "print_uuid.h"
+#include "protocols/service/fwu/packed-c/fwu_proto.h"
+#include "protocols/service/fwu/packed-c/metadata_v1.h"
-
-void cmd_print_metadata_v1(
- fwu_app &app)
+void cmd_print_metadata_v1(fwu_app &app)
{
std::vector<uint8_t> fetched_object;
struct uuid_octets object_uuid;
@@ -26,41 +26,38 @@
int status = app.read_object(object_uuid, fetched_object);
if (status) {
-
printf("Error: failed to read metadata\n");
return;
}
if (fetched_object.size() < sizeof(struct fwu_metadata)) {
-
printf("Error: invalid metadata size\n");
return;
}
- const struct fwu_metadata *metadata =
- (const struct fwu_metadata *)fetched_object.data();
+ const struct fwu_metadata *metadata = (const struct fwu_metadata *)fetched_object.data();
- printf("\nfwu_metadata (size %ld bytes) :\n", fetched_object.size());
+ printf("\nfwu_metadata (size %zu bytes) :\n", fetched_object.size());
printf("\tcrc_32 : 0x%x\n", metadata->crc_32);
printf("\tversion : %d\n", metadata->version);
printf("\tactive_index : %d\n", metadata->active_index);
printf("\tprevious_active_index : %d\n", metadata->previous_active_index);
for (unsigned int i = 0; i < FWU_METADATA_NUM_IMAGE_ENTRIES; i++) {
-
- printf("\timg_entry[%d]:\n", i);
+ printf("\timg_entry[%u]:\n", i);
printf("\t\timg_type_uuid : %s\n",
- print_uuid(metadata->img_entry[i].img_type_uuid).c_str());
+ print_uuid(metadata->img_entry[i].img_type_uuid).c_str());
printf("\t\tlocation_uuid : %s\n",
- print_uuid(metadata->img_entry[i].location_uuid).c_str());
+ print_uuid(metadata->img_entry[i].location_uuid).c_str());
- for (unsigned int bank_index = 0; bank_index < FWU_METADATA_NUM_BANKS; bank_index++) {
-
- printf("\t\timg_props[%d]:\n", bank_index);
+ for (unsigned int bank_index = 0; bank_index < FWU_METADATA_NUM_BANKS;
+ bank_index++) {
+ printf("\t\timg_props[%u]:\n", bank_index);
printf("\t\t\timg_uuid : %s\n",
- print_uuid(metadata->img_entry[i].img_props[bank_index].img_uuid).c_str());
+ print_uuid(metadata->img_entry[i].img_props[bank_index].img_uuid)
+ .c_str());
printf("\t\t\taccepted : %d\n",
- metadata->img_entry[i].img_props[bank_index].accepted);
+ metadata->img_entry[i].img_props[bank_index].accepted);
}
}
}
diff --git a/deployments/fwu/env/posix/cmd_print_metadata_v1.h b/deployments/fwu/env/posix/cmd_print_metadata_v1.h
index 0dc5eac..c31ec68 100644
--- a/deployments/fwu/env/posix/cmd_print_metadata_v1.h
+++ b/deployments/fwu/env/posix/cmd_print_metadata_v1.h
@@ -8,7 +8,7 @@
#ifndef CMD_PRINT_METADATA_V1_H
#define CMD_PRINT_METADATA_V1_H
-#include <service/fwu/app/fwu_app.h>
+#include "service/fwu/app/fwu_app.h"
void cmd_print_metadata_v1(fwu_app &app);
diff --git a/deployments/fwu/env/posix/cmd_print_metadata_v2.cpp b/deployments/fwu/env/posix/cmd_print_metadata_v2.cpp
index 5fee2d9..69e09d7 100644
--- a/deployments/fwu/env/posix/cmd_print_metadata_v2.cpp
+++ b/deployments/fwu/env/posix/cmd_print_metadata_v2.cpp
@@ -4,18 +4,19 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <vector>
+#include "cmd_print_metadata_v2.h"
+
#include <cstdint>
#include <cstdio>
#include <cstdlib>
-#include <common/uuid/uuid.h>
-#include <protocols/service/fwu/packed-c/fwu_proto.h>
-#include <protocols/service/fwu/packed-c/metadata_v2.h>
-#include "cmd_print_metadata_v2.h"
-#include "print_uuid.h"
+#include <vector>
-void cmd_print_metadata_v2(
- fwu_app &app)
+#include "common/uuid/uuid.h"
+#include "print_uuid.h"
+#include "protocols/service/fwu/packed-c/fwu_proto.h"
+#include "protocols/service/fwu/packed-c/metadata_v2.h"
+
+void cmd_print_metadata_v2(fwu_app &app)
{
std::vector<uint8_t> fetched_object;
struct uuid_octets object_uuid;
@@ -25,30 +26,26 @@
int status = app.read_object(object_uuid, fetched_object);
if (status) {
-
printf("Error: failed to read metadata\n");
return;
}
if (fetched_object.size() < sizeof(struct fwu_metadata)) {
-
printf("Error: invalid metadata size\n");
return;
}
/* Print mandatory metadata header */
- const struct fwu_metadata *metadata =
- (const struct fwu_metadata *)fetched_object.data();
+ const struct fwu_metadata *metadata = (const struct fwu_metadata *)fetched_object.data();
- printf("\nfwu_metadata (size %ld bytes) :\n", fetched_object.size());
+ printf("\nfwu_metadata (size %zu bytes) :\n", fetched_object.size());
printf("\tcrc_32 : 0x%x\n", metadata->crc_32);
printf("\tversion : %d\n", metadata->version);
printf("\tmetadata_size : %d\n", metadata->metadata_size);
printf("\theader_size : %d\n", metadata->header_size);
printf("\tactive_index : %d\n", metadata->active_index);
printf("\tprevious_active_index : %d\n", metadata->previous_active_index);
- printf("\tbank_state : 0x%x 0x%x\n",
- metadata->bank_state[0], metadata->bank_state[1]);
+ printf("\tbank_state : 0x%x 0x%x\n", metadata->bank_state[0], metadata->bank_state[1]);
if (metadata->metadata_size <= metadata->header_size)
return;
@@ -56,7 +53,6 @@
size_t fw_store_desc_size = metadata->metadata_size - metadata->header_size;
if (fw_store_desc_size < sizeof(fwu_fw_store_desc)) {
-
printf("\tInsufficient space for fw store descriptor\n");
return;
}
@@ -72,18 +68,16 @@
printf("\t\tbank_entry_size : %d\n", fw_store_desc->bank_entry_size);
for (unsigned int i = 0; i < fw_store_desc->num_images; i++) {
-
struct fwu_image_entry *img_entry = &fw_store_desc->img_entry[i];
- printf("\t\timg_entry[%d] :\n", i);
+ printf("\t\timg_entry[%u] :\n", i);
printf("\t\t\timg_type_uuid : %s\n", print_uuid(img_entry->img_type_uuid).c_str());
printf("\t\t\tlocation_uuid : %s\n", print_uuid(img_entry->location_uuid).c_str());
- for (unsigned int i = 0; i < fw_store_desc->num_banks; i++) {
+ for (unsigned int j = 0; j < fw_store_desc->num_banks; j++) {
+ struct fwu_img_bank_info *bank_info = &img_entry->img_bank_info[j];
- struct fwu_img_bank_info *bank_info = &img_entry->img_bank_info[i];
-
- printf("\t\t\timg_bank_info[%d] :\n", i);
+ printf("\t\t\timg_bank_info[%u] :\n", j);
printf("\t\t\t\timg_uuid : %s\n", print_uuid(bank_info->img_uuid).c_str());
printf("\t\t\t\taccepted : %d\n", bank_info->accepted);
}
diff --git a/deployments/fwu/env/posix/cmd_print_metadata_v2.h b/deployments/fwu/env/posix/cmd_print_metadata_v2.h
index 2943f93..5377212 100644
--- a/deployments/fwu/env/posix/cmd_print_metadata_v2.h
+++ b/deployments/fwu/env/posix/cmd_print_metadata_v2.h
@@ -8,7 +8,7 @@
#ifndef CMD_PRINT_METADATA_V2_H
#define CMD_PRINT_METADATA_V2_H
-#include <service/fwu/app/fwu_app.h>
+#include "service/fwu/app/fwu_app.h"
void cmd_print_metadata_v2(fwu_app &app);
diff --git a/deployments/fwu/env/posix/cmd_update_image.cpp b/deployments/fwu/env/posix/cmd_update_image.cpp
index 8e1014f..06c13a6 100644
--- a/deployments/fwu/env/posix/cmd_update_image.cpp
+++ b/deployments/fwu/env/posix/cmd_update_image.cpp
@@ -4,22 +4,20 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
+#include "cmd_update_image.h"
+
#include <cstdio>
#include <cstdlib>
#include <cstring>
-#include <common/uuid/uuid.h>
-#include "cmd_update_image.h"
+#include "common/uuid/uuid.h"
-int cmd_update_image(
- fwu_app &app,
- const std::string &img_type_uuid,
- const std::string &img_filename)
+int cmd_update_image(fwu_app &app, const std::string &img_type_uuid,
+ const std::string &img_filename)
{
FILE *fp = fopen(img_filename.c_str(), "rb");
if (!fp) {
-
printf("Error: failed to open image file: %s\n", img_filename.c_str());
return -1;
}
@@ -33,7 +31,6 @@
uint8_t *img_buf = (uint8_t *)malloc(img_size);
if (!img_buf) {
-
fclose(fp);
printf("Error: failed to allocate image buffer\n");
return -1;
@@ -41,8 +38,8 @@
/* Read file contents into buffer */
if (fread(img_buf, 1, img_size, fp)) {
-
fclose(fp);
+ free(img_buf);
printf("Error: failed to read image file\n");
return -1;
}
diff --git a/deployments/fwu/env/posix/cmd_update_image.h b/deployments/fwu/env/posix/cmd_update_image.h
index b0fe6ae..7091bd2 100644
--- a/deployments/fwu/env/posix/cmd_update_image.h
+++ b/deployments/fwu/env/posix/cmd_update_image.h
@@ -9,11 +9,10 @@
#define CMD_UPDATE_IMAGE_H
#include <string>
-#include <service/fwu/app/fwu_app.h>
-int cmd_update_image(
- fwu_app &app,
- const std::string &img_type_uuid,
- const std::string &img_filename);
+#include "service/fwu/app/fwu_app.h"
+
+int cmd_update_image(fwu_app &app, const std::string &img_type_uuid,
+ const std::string &img_filename);
#endif /* CMD_UPDATE_IMAGE_H */
diff --git a/deployments/fwu/env/posix/fwu_main.cpp b/deployments/fwu/env/posix/fwu_main.cpp
index e01640a..88bac76 100644
--- a/deployments/fwu/env/posix/fwu_main.cpp
+++ b/deployments/fwu/env/posix/fwu_main.cpp
@@ -7,37 +7,29 @@
#include <cstdio>
#include <cstdlib>
#include <cstring>
-#include <string>
#include <sstream>
+#include <string>
#include <sys/stat.h>
-#include <common/uuid/uuid.h>
-#include <service/fwu/app/fwu_app.h>
-#include "cmd_update_image.h"
+
#include "cmd_print_image_dir.h"
#include "cmd_print_metadata_v1.h"
#include "cmd_print_metadata_v2.h"
+#include "cmd_update_image.h"
+#include "common/uuid/uuid.h"
+#include "service/fwu/app/fwu_app.h"
-static bool option_selected(
- const char *option_switch,
- int argc, char *argv[]);
+static bool option_selected(const char *option_switch, int argc, char *argv[]);
-static std::string parse_string_option(
- const char *option_switch,
- int argc, char *argv[],
- const char *default_val);
+static std::string parse_string_option(const char *option_switch, int argc, char *argv[],
+ const char *default_val);
-static int parse_numeric_option(
- const char *option_switch,
- int argc, char *argv[],
- int default_val);
+static int parse_numeric_option(const char *option_switch, int argc, char *argv[], int default_val);
-static bool file_exists(
- const std::string &filename);
+static bool file_exists(const std::string &filename);
static void print_usage(void);
static void print_help(void);
-
int main(int argc, char *argv[])
{
fwu_app app;
@@ -46,10 +38,8 @@
std::string img_type_uuid;
/* Check for help */
- if (option_selected("-h", argc, argv) ||
- option_selected("-help", argc, argv) ||
- option_selected("--help", argc, argv)) {
-
+ if (option_selected("-h", argc, argv) || option_selected("-help", argc, argv) ||
+ option_selected("--help", argc, argv)) {
print_help();
return 0;
}
@@ -58,7 +48,6 @@
if (argc > 1)
disk_img_filename = std::string(argv[1]);
else {
-
printf("Error: missing disk-filename argument\n");
print_usage();
return -1;
@@ -66,7 +55,6 @@
/* Check if disk image file exists */
if (!file_exists(disk_img_filename)) {
-
printf("Error: %s does not exist\n", disk_img_filename.c_str());
return -1;
}
@@ -75,7 +63,6 @@
int status = app.configure(disk_img_filename.c_str());
if (status) {
-
printf("Error: failed to configure with status: %d\n", status);
return -1;
}
@@ -89,7 +76,6 @@
status = app.get_boot_info(boot_index, metadata_version);
if (status) {
-
printf("No recognised metadata, assume default boot index and version\n");
boot_index = 0;
@@ -110,14 +96,12 @@
/* Check if image file exists (if one was specified) */
if (!update_img_filename.empty() && !file_exists(update_img_filename)) {
-
printf("Error: %s does not exist\n", update_img_filename.c_str());
return -1;
}
/* Check if img type canonical uuid is well formed */
if (!img_type_uuid.empty() && !uuid_is_valid(img_type_uuid.c_str())) {
-
printf("Error: image type uuid invalid\n");
return -1;
}
@@ -127,30 +111,25 @@
status = app.init_update_agent(boot_index, metadata_version);
if (!status) {
-
- printf("Update agent started: boot index: %d metadata ver: %d\n",
- boot_index, metadata_version);
+ printf("Update agent started: boot index: %u metadata ver: %u\n", boot_index,
+ metadata_version);
if (is_print_img_dir)
cmd_print_image_dir(app);
if (is_print_metadata) {
-
if (metadata_version == 1)
cmd_print_metadata_v1(app);
else if (metadata_version == 2)
cmd_print_metadata_v2(app);
else
printf("Unsupported metadata version\n");
-
}
if (!update_img_filename.empty() && !img_type_uuid.empty()) {
-
status = cmd_update_image(app, img_type_uuid, update_img_filename);
} else if (!update_img_filename.empty() || !img_type_uuid.empty()) {
-
printf("Error: both image filename and uuid arguments are needed\n");
return -1;
}
@@ -164,31 +143,24 @@
return status;
}
-static bool option_selected(
- const char *option_switch,
- int argc, char *argv[])
+static bool option_selected(const char *option_switch, int argc, char *argv[])
{
bool is_selected = false;
for (int i = 1; (i < argc) && !is_selected; ++i) {
-
is_selected = (strcmp(argv[i], option_switch) == 0);
}
return is_selected;
}
-static std::string parse_string_option(
- const char *option_switch,
- int argc, char *argv[],
- const char *default_val)
+static std::string parse_string_option(const char *option_switch, int argc, char *argv[],
+ const char *default_val)
{
std::string option = std::string(default_val);
for (int i = 1; i + 1 < argc; ++i) {
-
if (strcmp(argv[i], option_switch) == 0) {
-
option = std::string(argv[i + 1]);
break;
}
@@ -197,17 +169,12 @@
return option;
}
-static int parse_numeric_option(
- const char *option_switch,
- int argc, char *argv[],
- int default_val)
+static int parse_numeric_option(const char *option_switch, int argc, char *argv[], int default_val)
{
int option = default_val;
for (int i = 1; i + 1 < argc; ++i) {
-
if (strcmp(argv[i], option_switch) == 0) {
-
std::istringstream iss(argv[i + 1]);
int val;
@@ -233,7 +200,7 @@
static void print_usage(void)
{
printf("Usage: fwu disk-filename [-dir -meta] [-boot-index number -meta-ver number] "
- "[-img filename -img-type uuid]\n");
+ "[-img filename -img-type uuid]\n");
}
static void print_help(void)
@@ -249,4 +216,3 @@
printf("\t-img\t\tFile containing image update\n");
printf("\t-img-type\tCanonical UUID of image to update\n");
}
-
diff --git a/deployments/fwu/env/posix/print_uuid.cpp b/deployments/fwu/env/posix/print_uuid.cpp
index 6cfbdcd..a65bac1 100644
--- a/deployments/fwu/env/posix/print_uuid.cpp
+++ b/deployments/fwu/env/posix/print_uuid.cpp
@@ -4,9 +4,10 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <common/uuid/uuid.h>
#include "print_uuid.h"
+#include "common/uuid/uuid.h"
+
std::string print_uuid(const uint8_t *uuid_octets)
{
struct uuid_canonical canonical_uuid;