Added firmware validation step

This commit is contained in:
Vivek Kumar Dutta 2023-10-13 18:12:49 +05:30
parent c550b59832
commit 140334292c
No known key found for this signature in database
GPG key ID: 65C818099F37097D
2 changed files with 23 additions and 3 deletions

View file

@ -425,7 +425,7 @@ int bbf_fw_image_download(const char *url, const char *auto_activate, const char
{
char fw_image_path[256] = "/tmp/firmware-XXXXXX";
json_object *json_obj = NULL;
bool activate = false;
bool activate = false, valid = false;
int res = 0;
// Check the file system size if there is sufficient space for downloading the firmware image
@ -461,14 +461,30 @@ int bbf_fw_image_download(const char *url, const char *auto_activate, const char
string_to_bool((char *)auto_activate, &activate);
char *act = (activate) ? "1" : "0";
// Apply Firmware Image
dmubus_call_blocking("fwbank", "upgrade", UBUS_ARGS{{"path", fw_image_path, String}, {"auto_activate", act, Boolean}, {"bank", bank_id, Integer}}, 3, &json_obj);
dmubus_call_blocking("system", "validate_firmware_image", UBUS_ARGS{{"path", fw_image_path, String}}, 1, &json_obj);
if (json_obj == NULL) {
res = -1;
goto end;
}
char *val = dmjson_get_value(json_obj, 1, "valid");
string_to_bool(val, &valid);
json_object_put(json_obj);
json_obj = NULL;
if (valid == false) {
send_transfer_complete_event(command, obj_path, url, res_code, start_time, complete_time, commandKey, "Download");
res = -1;
goto end;
}
// Apply Firmware Image
dmubus_call_blocking("fwbank", "upgrade", UBUS_ARGS{{"path", fw_image_path, String}, {"auto_activate", act, Boolean}, {"bank", bank_id, Integer}}, 3, &json_obj);
if (json_obj == NULL) {
res = 1;
goto end;
}
sleep(30); // Wait for the image to become available
// Send the transfer complete after image applied

View file

@ -1337,6 +1337,10 @@ static int operate_DeviceInfoFirmwareImage_Download(char *refparam, struct dmctx
int res = bbf_fw_image_download(url, auto_activate, username, password, file_size, checksum_algorithm, checksum, bank_id, command, obj_path, commandKey);
if (res == 1) {
bbfdm_set_fault_message(ctx, "Firmware validation failed");
}
return res ? USP_FAULT_COMMAND_FAILURE : 0;
}