]>
git.ipfire.org Git - thirdparty/u-boot.git/blob - common/spl/spl_imx_container.c
1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2018-2021 NXP
6 #define LOG_CATEGORY LOGC_ARCH
10 #include <imx_container.h>
13 #ifdef CONFIG_AHAB_BOOT
14 #include <asm/mach-imx/ahab.h>
17 static struct boot_img_t
*read_auth_image(struct spl_image_info
*spl_image
,
18 struct spl_load_info
*info
,
19 struct container_hdr
*container
,
23 struct boot_img_t
*images
;
27 if (image_index
> container
->num_images
) {
28 debug("Invalid image number\n");
32 images
= (struct boot_img_t
*)((u8
*)container
+
33 sizeof(struct container_hdr
));
35 if (images
[image_index
].offset
% info
->bl_len
) {
36 printf("%s: image%d offset not aligned to %u\n",
37 __func__
, image_index
, info
->bl_len
);
41 sectors
= roundup(images
[image_index
].size
, info
->bl_len
) /
43 sector
= images
[image_index
].offset
/ info
->bl_len
+
46 debug("%s: container: %p sector: %lu sectors: %u\n", __func__
,
47 container
, sector
, sectors
);
48 if (info
->read(info
, sector
, sectors
,
49 (void *)images
[image_index
].dst
) != sectors
) {
50 printf("%s wrong\n", __func__
);
54 #ifdef CONFIG_AHAB_BOOT
55 if (ahab_verify_cntr_image(&images
[image_index
], image_index
))
59 return &images
[image_index
];
62 static int read_auth_container(struct spl_image_info
*spl_image
,
63 struct spl_load_info
*info
, ulong sector
)
65 struct container_hdr
*container
= NULL
;
70 size
= roundup(CONTAINER_HDR_ALIGNMENT
, info
->bl_len
);
71 sectors
= size
/ info
->bl_len
;
74 * It will not override the ATF code, so safe to use it here,
77 container
= malloc(size
);
81 debug("%s: container: %p sector: %lu sectors: %u\n", __func__
,
82 container
, sector
, sectors
);
83 if (info
->read(info
, sector
, sectors
, container
) != sectors
) {
88 if (!valid_container_hdr(container
)) {
89 log_err("Wrong container header\n");
94 if (!container
->num_images
) {
95 log_err("Wrong container, no image found\n");
100 length
= container
->length_lsb
+ (container
->length_msb
<< 8);
101 debug("Container length %u\n", length
);
103 if (length
> CONTAINER_HDR_ALIGNMENT
) {
104 size
= roundup(length
, info
->bl_len
);
105 sectors
= size
/ info
->bl_len
;
108 container
= malloc(size
);
112 debug("%s: container: %p sector: %lu sectors: %u\n",
113 __func__
, container
, sector
, sectors
);
114 if (info
->read(info
, sector
, sectors
, container
) !=
121 #ifdef CONFIG_AHAB_BOOT
122 ret
= ahab_auth_cntr_hdr(container
, length
);
127 for (i
= 0; i
< container
->num_images
; i
++) {
128 struct boot_img_t
*image
= read_auth_image(spl_image
, info
,
138 spl_image
->load_addr
= image
->dst
;
139 spl_image
->entry_point
= image
->entry
;
144 #ifdef CONFIG_AHAB_BOOT
154 int spl_load_imx_container(struct spl_image_info
*spl_image
,
155 struct spl_load_info
*info
, ulong sector
)
157 return read_auth_container(spl_image
, info
, sector
);