Julian Hall | 0471f74 | 2023-01-11 17:28:31 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2023, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
Julian Hall | 0471f74 | 2023-01-11 17:28:31 +0000 | [diff] [blame] | 8 | #include "fwu_configure.h" |
| 9 | |
Gyorgy Szing | 3c44624 | 2023-03-31 01:53:15 +0200 | [diff] [blame] | 10 | #include <service/fwu/config/gpt/gpt_fwu_configure.h> |
| 11 | |
| 12 | #include "media/volume/factory/volume_factory.h" |
| 13 | #include "media/volume/index/volume_index.h" |
| 14 | #include "service/fwu/installer/factory/installer_factory.h" |
| 15 | #include "service/fwu/installer/installer_index.h" |
| 16 | |
Julian Hall | 0471f74 | 2023-01-11 17:28:31 +0000 | [diff] [blame] | 17 | int fwu_configure(const struct uuid_octets *device_uuids, size_t num_device_uuids) |
| 18 | { |
| 19 | unsigned int location_id = 0; |
| 20 | |
| 21 | volume_index_init(); |
| 22 | installer_index_init(); |
| 23 | |
| 24 | for (size_t i = 0; i < num_device_uuids; i++) { |
Julian Hall | 0471f74 | 2023-01-11 17:28:31 +0000 | [diff] [blame] | 25 | unsigned int new_location_count = 0; |
| 26 | |
Gyorgy Szing | 3c44624 | 2023-03-31 01:53:15 +0200 | [diff] [blame] | 27 | int status = gpt_fwu_configure(&device_uuids[i], location_id, &new_location_count); |
Julian Hall | 0471f74 | 2023-01-11 17:28:31 +0000 | [diff] [blame] | 28 | |
| 29 | if (status) |
| 30 | return status; |
| 31 | |
| 32 | location_id += new_location_count; |
| 33 | } |
| 34 | |
| 35 | return 0; |
| 36 | } |
| 37 | |
| 38 | void fwu_deconfigure(void) |
| 39 | { |
| 40 | unsigned int index = 0; |
| 41 | |
| 42 | /* Destroy installers */ |
| 43 | while (1) { |
| 44 | struct installer *installer = installer_index_get(index); |
| 45 | |
| 46 | if (installer) |
| 47 | installer_factory_destroy_installer(installer); |
| 48 | else |
| 49 | break; |
| 50 | |
| 51 | ++index; |
| 52 | } |
| 53 | |
| 54 | /* Destroy volumes */ |
| 55 | index = 0; |
| 56 | |
| 57 | while (1) { |
| 58 | struct volume *volume = volume_index_get(index); |
| 59 | |
| 60 | if (volume) |
| 61 | volume_factory_destroy_volume(volume); |
| 62 | else |
| 63 | break; |
| 64 | |
| 65 | ++index; |
| 66 | } |
| 67 | |
| 68 | installer_index_clear(); |
| 69 | volume_index_clear(); |
| 70 | } |