1 /*
2  * Copyright (c) 2021-2022, Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #include "image.h"
9 
10 #include "Driver_Flash.h"
11 #include "flash_layout.h"
12 #include "region_defs.h"
13 #include "fih.h"
14 
15 extern ARM_DRIVER_FLASH FLASH_DEV_NAME;
16 
bl1_image_get_flash_offset(uint32_t image_id)17 int32_t __WEAK bl1_image_get_flash_offset(uint32_t image_id)
18 {
19     switch (image_id) {
20     case 0:
21         return FLASH_AREA_0_OFFSET;
22     case 1:
23         return FLASH_AREA_1_OFFSET;
24     default:
25         FIH_PANIC;
26     }
27 }
28 
bl1_image_copy_to_sram(uint32_t image_id,uint8_t * out)29 fih_int bl1_image_copy_to_sram(uint32_t image_id, uint8_t *out)
30 {
31     uint32_t flash_offset;
32     fih_int fih_rc;
33 
34     flash_offset = bl1_image_get_flash_offset(image_id);
35     fih_rc = fih_int_encode(FLASH_DEV_NAME.ReadData(flash_offset, out,
36                                                     sizeof(struct bl1_2_image_t)));
37 
38     FIH_RET(fih_rc);
39 }
40