imx: parse-container: Use malloc for container processing
If the container has image which conflicts with spl_get_load_buffer address, there are processing failures. Use malloc instead of spl_get_load_buffer. Reviewed-by: Ye Li <ye.li@nxp.com> Signed-off-by: Nitin Garg <nitin.garg@nxp.com> Signed-off-by: Peng Fan <peng.fan@nxp.com>
This commit is contained in:

committed by
Stefano Babic

parent
dc2d49209e
commit
6e81ca220e
@@ -4,6 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <common.h>
|
#include <common.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <log.h>
|
#include <log.h>
|
||||||
#include <spl.h>
|
#include <spl.h>
|
||||||
@@ -134,21 +135,27 @@ static int read_auth_container(struct spl_image_info *spl_image,
|
|||||||
* It will not override the ATF code, so safe to use it here,
|
* It will not override the ATF code, so safe to use it here,
|
||||||
* no need malloc
|
* no need malloc
|
||||||
*/
|
*/
|
||||||
container = (struct container_hdr *)spl_get_load_buffer(-size, size);
|
container = malloc(size);
|
||||||
|
if (!container)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
debug("%s: container: %p sector: %lu sectors: %u\n", __func__,
|
debug("%s: container: %p sector: %lu sectors: %u\n", __func__,
|
||||||
container, sector, sectors);
|
container, sector, sectors);
|
||||||
if (info->read(info, sector, sectors, container) != sectors)
|
if (info->read(info, sector, sectors, container) != sectors) {
|
||||||
return -EIO;
|
ret = -EIO;
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
if (container->tag != 0x87 && container->version != 0x0) {
|
if (container->tag != 0x87 && container->version != 0x0) {
|
||||||
printf("Wrong container header\n");
|
printf("Wrong container header");
|
||||||
return -ENOENT;
|
ret = -ENOENT;
|
||||||
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!container->num_images) {
|
if (!container->num_images) {
|
||||||
printf("Wrong container, no image found\n");
|
printf("Wrong container, no image found");
|
||||||
return -ENOENT;
|
ret = -ENOENT;
|
||||||
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
length = container->length_lsb + (container->length_msb << 8);
|
length = container->length_lsb + (container->length_msb << 8);
|
||||||
@@ -158,13 +165,18 @@ static int read_auth_container(struct spl_image_info *spl_image,
|
|||||||
size = roundup(length, info->bl_len);
|
size = roundup(length, info->bl_len);
|
||||||
sectors = size / info->bl_len;
|
sectors = size / info->bl_len;
|
||||||
|
|
||||||
container = (struct container_hdr *)spl_get_load_buffer(-size, size);
|
free(container);
|
||||||
|
container = malloc(size);
|
||||||
|
if (!container)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
debug("%s: container: %p sector: %lu sectors: %u\n",
|
debug("%s: container: %p sector: %lu sectors: %u\n",
|
||||||
__func__, container, sector, sectors);
|
__func__, container, sector, sectors);
|
||||||
if (info->read(info, sector, sectors, container) !=
|
if (info->read(info, sector, sectors, container) !=
|
||||||
sectors)
|
sectors) {
|
||||||
return -EIO;
|
ret = -EIO;
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_AHAB_BOOT
|
#ifdef CONFIG_AHAB_BOOT
|
||||||
@@ -175,7 +187,7 @@ static int read_auth_container(struct spl_image_info *spl_image,
|
|||||||
SECO_LOCAL_SEC_SEC_SECURE_RAM_BASE);
|
SECO_LOCAL_SEC_SEC_SECURE_RAM_BASE);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
printf("authenticate container hdr failed, return %d\n", ret);
|
printf("authenticate container hdr failed, return %d\n", ret);
|
||||||
return ret;
|
goto end_auth;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -200,6 +212,10 @@ end_auth:
|
|||||||
if (sc_seco_authenticate(-1, SC_SECO_REL_CONTAINER, 0))
|
if (sc_seco_authenticate(-1, SC_SECO_REL_CONTAINER, 0))
|
||||||
printf("Error: release container failed!\n");
|
printf("Error: release container failed!\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
end:
|
||||||
|
free(container);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user