mirror of
				https://xff.cz/git/u-boot/
				synced 2025-10-31 02:15:45 +01:00 
			
		
		
		
	imx: hab: extend hab_auth_img to calculate ivt_offset
Current implementation of hab_auth_img command needs ivt_offset to authenticate the image. But ivt header is placed at the end of image date after padding. This leaves the usage of hab_auth_img command to fixed size or static offset for ivt header. New function "get_image_ivt_offset" is introduced to find the ivt offset during runtime. The case conditional check in this function is same as boot_get_kernel in common/bootm.c With this variable length image e.g. FIT image with any random size can have IVT at the end and ivt_offset option can be left optional Can be used as "hab_auth_img $loadaddr $filesize" from u-boot script Signed-off-by: Parthiban Nallathambi <pn@denx.de> Reviewed-by: Breno Lima <breno.lima@nxp.com>
This commit is contained in:
		
				
					committed by
					
						 Stefano Babic
						Stefano Babic
					
				
			
			
				
	
			
			
			
						parent
						
							c54564474f
						
					
				
				
					commit
					ea91031b22
				
			| @@ -6,6 +6,8 @@ | |||||||
| #include <common.h> | #include <common.h> | ||||||
| #include <config.h> | #include <config.h> | ||||||
| #include <fuse.h> | #include <fuse.h> | ||||||
|  | #include <mapmem.h> | ||||||
|  | #include <image.h> | ||||||
| #include <asm/io.h> | #include <asm/io.h> | ||||||
| #include <asm/system.h> | #include <asm/system.h> | ||||||
| #include <asm/arch/clock.h> | #include <asm/arch/clock.h> | ||||||
| @@ -302,17 +304,40 @@ static int do_hab_status(cmd_tbl_t *cmdtp, int flag, int argc, | |||||||
| 	return 0; | 	return 0; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | static ulong get_image_ivt_offset(ulong img_addr) | ||||||
|  | { | ||||||
|  | 	const void *buf; | ||||||
|  |  | ||||||
|  | 	buf = map_sysmem(img_addr, 0); | ||||||
|  | 	switch (genimg_get_format(buf)) { | ||||||
|  | #if defined(CONFIG_IMAGE_FORMAT_LEGACY) | ||||||
|  | 	case IMAGE_FORMAT_LEGACY: | ||||||
|  | 		return (image_get_image_size((image_header_t *)img_addr) | ||||||
|  | 			+ 0x1000 - 1)  & ~(0x1000 - 1); | ||||||
|  | #endif | ||||||
|  | #if IMAGE_ENABLE_FIT | ||||||
|  | 	case IMAGE_FORMAT_FIT: | ||||||
|  | 		return (fit_get_size(buf) + 0x1000 - 1)  & ~(0x1000 - 1); | ||||||
|  | #endif | ||||||
|  | 	default: | ||||||
|  | 		return 0; | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  |  | ||||||
| static int do_authenticate_image(cmd_tbl_t *cmdtp, int flag, int argc, | static int do_authenticate_image(cmd_tbl_t *cmdtp, int flag, int argc, | ||||||
| 				 char * const argv[]) | 				 char * const argv[]) | ||||||
| { | { | ||||||
| 	ulong	addr, length, ivt_offset; | 	ulong	addr, length, ivt_offset; | ||||||
| 	int	rcode = 0; | 	int	rcode = 0; | ||||||
|  |  | ||||||
| 	if (argc < 4) | 	if (argc < 3) | ||||||
| 		return CMD_RET_USAGE; | 		return CMD_RET_USAGE; | ||||||
|  |  | ||||||
| 	addr = simple_strtoul(argv[1], NULL, 16); | 	addr = simple_strtoul(argv[1], NULL, 16); | ||||||
| 	length = simple_strtoul(argv[2], NULL, 16); | 	length = simple_strtoul(argv[2], NULL, 16); | ||||||
|  | 	if (argc == 3) | ||||||
|  | 		ivt_offset = get_image_ivt_offset(addr); | ||||||
|  | 	else | ||||||
| 		ivt_offset = simple_strtoul(argv[3], NULL, 16); | 		ivt_offset = simple_strtoul(argv[3], NULL, 16); | ||||||
|  |  | ||||||
| 	rcode = imx_hab_authenticate_image(addr, length, ivt_offset); | 	rcode = imx_hab_authenticate_image(addr, length, ivt_offset); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user