1 /*
2 * Arm SCP/MCP Software
3 * Copyright (c) 2020-2022, Arm Limited and Contributors. All rights reserved.
4 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 */
7
8 #include <mod_bootloader.h>
9
10 #include <fwk_core.h>
11 #include <fwk_event.h>
12 #include <fwk_id.h>
13 #include <fwk_log.h>
14 #include <fwk_module.h>
15 #include <fwk_module_idx.h>
16 #include <fwk_status.h>
17
18 struct mod_isys_rom_ctx {
19 const struct mod_bootloader_api *bootloader_api;
20 } ctx;
21
22 enum mod_isys_rom_event {
23 MOD_ISYS_ROM_EVENT_RUN,
24 MOD_ISYS_ROM_EVENT_COUNT,
25 };
26
mod_isys_init(fwk_id_t id,unsigned int element_count,const void * data)27 static int mod_isys_init(
28 fwk_id_t id,
29 unsigned int element_count,
30 const void *data)
31 {
32 return FWK_SUCCESS;
33 }
34
mod_isys_rom_bind(fwk_id_t id,unsigned int round)35 static int mod_isys_rom_bind(fwk_id_t id, unsigned int round)
36 {
37 int status = FWK_SUCCESS;
38
39 if (round > 0)
40 goto exit;
41
42 status = fwk_module_bind(
43 FWK_ID_MODULE(FWK_MODULE_IDX_BOOTLOADER),
44 FWK_ID_API(FWK_MODULE_IDX_BOOTLOADER, 0),
45 &ctx.bootloader_api);
46 if (status != FWK_SUCCESS)
47 status = FWK_E_PANIC;
48
49 exit:
50 return status;
51 }
52
mod_isys_rom_start(fwk_id_t id)53 static int mod_isys_rom_start(fwk_id_t id)
54 {
55 struct fwk_event event = {
56 .source_id = FWK_ID_MODULE(FWK_MODULE_IDX_ISYS_ROM),
57 .target_id = FWK_ID_MODULE(FWK_MODULE_IDX_ISYS_ROM),
58 .id = FWK_ID_EVENT(FWK_MODULE_IDX_ISYS_ROM, MOD_ISYS_ROM_EVENT_RUN),
59 };
60
61 return fwk_put_event(&event);
62 }
63
mod_isys_rom_process_event(const struct fwk_event * event,struct fwk_event * resp)64 static int mod_isys_rom_process_event(
65 const struct fwk_event *event,
66 struct fwk_event *resp)
67 {
68 int status;
69
70 status = ctx.bootloader_api->load_image();
71
72 FWK_LOG_CRIT(
73 "[ISYS-ROM] Failed to load RAM firmware image: %s",
74 fwk_status_str(status));
75
76 fwk_trap();
77
78 return FWK_E_PANIC;
79 }
80
81 const struct fwk_module module_isys_rom = {
82 .type = FWK_MODULE_TYPE_SERVICE,
83
84 .init = mod_isys_init,
85 .bind = mod_isys_rom_bind,
86 .start = mod_isys_rom_start,
87
88 .process_event = mod_isys_rom_process_event,
89 .event_count = MOD_ISYS_ROM_EVENT_COUNT,
90 };
91
92 const struct fwk_module_config config_isys_rom = { 0 };
93