Julian Hall | 56387ba | 2022-11-18 11:47:44 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2022-2023, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
Gyorgy Szing | 3c44624 | 2023-03-31 01:53:15 +0200 | [diff] [blame] | 8 | #include "installer.h" |
| 9 | |
Julian Hall | 56387ba | 2022-11-18 11:47:44 +0000 | [diff] [blame] | 10 | #include <assert.h> |
| 11 | #include <stdbool.h> |
| 12 | #include <stddef.h> |
Julian Hall | 56387ba | 2022-11-18 11:47:44 +0000 | [diff] [blame] | 13 | |
Imre Kis | 7554c47 | 2024-07-04 10:09:31 +0200 | [diff] [blame] | 14 | #include "protocols/service/fwu/status.h" |
Gyorgy Szing | 3c44624 | 2023-03-31 01:53:15 +0200 | [diff] [blame] | 15 | |
| 16 | void installer_init(struct installer *installer, enum install_type install_type, |
| 17 | uint32_t location_id, const struct uuid_octets *location_uuid, void *context, |
| 18 | const struct installer_interface *interface) |
Julian Hall | 56387ba | 2022-11-18 11:47:44 +0000 | [diff] [blame] | 19 | { |
| 20 | assert(installer); |
| 21 | assert(location_uuid); |
| 22 | assert(context); |
| 23 | assert(interface); |
| 24 | |
| 25 | installer->install_type = install_type; |
| 26 | installer->location_id = location_id; |
| 27 | installer->location_uuid = *location_uuid; |
| 28 | installer->context = context; |
| 29 | installer->interface = interface; |
| 30 | |
| 31 | installer->install_status = FWU_STATUS_SUCCESS; |
| 32 | installer->is_active = false; |
| 33 | installer->next = NULL; |
| 34 | } |
| 35 | |
Gyorgy Szing | 3c44624 | 2023-03-31 01:53:15 +0200 | [diff] [blame] | 36 | int installer_begin(struct installer *installer, uint32_t current_volume_id, |
| 37 | uint32_t update_volume_id) |
Julian Hall | 56387ba | 2022-11-18 11:47:44 +0000 | [diff] [blame] | 38 | { |
| 39 | assert(installer); |
| 40 | assert(installer->interface); |
| 41 | assert(installer->interface->begin); |
| 42 | |
| 43 | installer->install_status = FWU_STATUS_SUCCESS; |
| 44 | installer->is_active = true; |
| 45 | |
Gyorgy Szing | 3c44624 | 2023-03-31 01:53:15 +0200 | [diff] [blame] | 46 | return installer->interface->begin(installer->context, current_volume_id, update_volume_id); |
Julian Hall | 56387ba | 2022-11-18 11:47:44 +0000 | [diff] [blame] | 47 | } |
| 48 | |
Gyorgy Szing | 3c44624 | 2023-03-31 01:53:15 +0200 | [diff] [blame] | 49 | int installer_finalize(struct installer *installer) |
Julian Hall | 56387ba | 2022-11-18 11:47:44 +0000 | [diff] [blame] | 50 | { |
| 51 | assert(installer); |
| 52 | assert(installer->interface); |
| 53 | assert(installer->interface->finalize); |
| 54 | |
| 55 | installer->is_active = false; |
| 56 | |
Gyorgy Szing | 3c44624 | 2023-03-31 01:53:15 +0200 | [diff] [blame] | 57 | return installer->interface->finalize(installer->context); |
Julian Hall | 56387ba | 2022-11-18 11:47:44 +0000 | [diff] [blame] | 58 | } |
| 59 | |
Gyorgy Szing | 3c44624 | 2023-03-31 01:53:15 +0200 | [diff] [blame] | 60 | void installer_abort(struct installer *installer) |
Julian Hall | 56387ba | 2022-11-18 11:47:44 +0000 | [diff] [blame] | 61 | { |
| 62 | assert(installer); |
| 63 | assert(installer->interface); |
| 64 | assert(installer->interface->abort); |
| 65 | |
| 66 | installer->is_active = false; |
| 67 | |
Gyorgy Szing | 3c44624 | 2023-03-31 01:53:15 +0200 | [diff] [blame] | 68 | installer->interface->abort(installer->context); |
Julian Hall | 56387ba | 2022-11-18 11:47:44 +0000 | [diff] [blame] | 69 | } |
| 70 | |
Gyorgy Szing | 3c44624 | 2023-03-31 01:53:15 +0200 | [diff] [blame] | 71 | int installer_open(struct installer *installer, const struct image_info *image_info) |
Julian Hall | 56387ba | 2022-11-18 11:47:44 +0000 | [diff] [blame] | 72 | { |
| 73 | assert(installer); |
| 74 | assert(installer->interface); |
| 75 | assert(installer->interface->open); |
| 76 | |
Gyorgy Szing | 3c44624 | 2023-03-31 01:53:15 +0200 | [diff] [blame] | 77 | int status = installer->interface->open(installer->context, image_info); |
Julian Hall | 56387ba | 2022-11-18 11:47:44 +0000 | [diff] [blame] | 78 | |
| 79 | if (status && !installer->install_status) |
| 80 | installer->install_status = status; |
| 81 | |
| 82 | return status; |
| 83 | } |
| 84 | |
Gyorgy Szing | 3c44624 | 2023-03-31 01:53:15 +0200 | [diff] [blame] | 85 | int installer_commit(struct installer *installer) |
Julian Hall | 56387ba | 2022-11-18 11:47:44 +0000 | [diff] [blame] | 86 | { |
| 87 | assert(installer); |
| 88 | assert(installer->interface); |
| 89 | assert(installer->interface->commit); |
| 90 | |
Gyorgy Szing | 3c44624 | 2023-03-31 01:53:15 +0200 | [diff] [blame] | 91 | int status = installer->interface->commit(installer->context); |
Julian Hall | 56387ba | 2022-11-18 11:47:44 +0000 | [diff] [blame] | 92 | |
| 93 | if (status && !installer->install_status) |
| 94 | installer->install_status = status; |
| 95 | |
| 96 | return status; |
| 97 | } |
| 98 | |
Gyorgy Szing | 3c44624 | 2023-03-31 01:53:15 +0200 | [diff] [blame] | 99 | int installer_write(struct installer *installer, const uint8_t *data, size_t data_len) |
Julian Hall | 56387ba | 2022-11-18 11:47:44 +0000 | [diff] [blame] | 100 | { |
| 101 | assert(installer); |
| 102 | assert(installer->interface); |
| 103 | assert(installer->interface->write); |
| 104 | |
Gyorgy Szing | 3c44624 | 2023-03-31 01:53:15 +0200 | [diff] [blame] | 105 | int status = installer->interface->write(installer->context, data, data_len); |
Julian Hall | 56387ba | 2022-11-18 11:47:44 +0000 | [diff] [blame] | 106 | |
| 107 | if (status && !installer->install_status) |
| 108 | installer->install_status = status; |
| 109 | |
| 110 | return status; |
| 111 | } |
| 112 | |
Gyorgy Szing | 3c44624 | 2023-03-31 01:53:15 +0200 | [diff] [blame] | 113 | int installer_enumerate(struct installer *installer, uint32_t volume_id, |
| 114 | struct fw_directory *fw_directory) |
Julian Hall | 56387ba | 2022-11-18 11:47:44 +0000 | [diff] [blame] | 115 | { |
| 116 | assert(installer); |
| 117 | assert(installer->interface); |
| 118 | assert(installer->interface->enumerate); |
| 119 | |
Gyorgy Szing | 3c44624 | 2023-03-31 01:53:15 +0200 | [diff] [blame] | 120 | return installer->interface->enumerate(installer->context, volume_id, fw_directory); |
Julian Hall | 56387ba | 2022-11-18 11:47:44 +0000 | [diff] [blame] | 121 | } |