Skip to contentSkip to conversation

armv8: sec_firmware: Add support for multiple loadables

PATCH New Sumit Garg 2 participants 5 messages Jan 15, 2018 Arm (32-bit)

lore
Share & tools
lore

Sumit Garg

author
#0 lore raw

PATCH 1/1 armv8: sec_firmware: Add support for multiple loadables

Enable support for multiple loadable images in SEC firmware FIT image.

---
 arch/arm/cpu/armv8/sec_firmware.c | 51 +++++++++++++++++++++++++++++++--------
 1 file changed, 41 insertions(+), 10 deletions(-)
arch/arm/cpu/armv8/sec_firmware.c +41 -10
index 927eae4..28de81c 100644
@@ -116,11 +116,13 @@ static int sec_firmware_check_copy_loadable(const void *sec_firmware_img,
 					    u32 *loadable_l, u32 *loadable_h)
 {
 	phys_addr_t sec_firmware_loadable_addr = 0;
-	int conf_node_off, ld_node_off;
+	int conf_node_off, ld_node_off, images;
 	char *conf_node_name = NULL;
 	const void *data;
 	size_t size;
 	ulong load;
+	const char *name, *str, *type;
+	int len;
 
 	conf_node_name = SEC_FIRMEWARE_FIT_CNF_NAME;
 
@@ -130,11 +132,32 @@ static int sec_firmware_check_copy_loadable(const void *sec_firmware_img,
 	return -ENOENT;
 	}
 
-	ld_node_off = fit_conf_get_prop_node(sec_firmware_img, conf_node_off,
-					     FIT_LOADABLE_PROP);
-	if (ld_node_off >= 0) {
-		printf("SEC Firmware: '%s' present in config\n",
-		       FIT_LOADABLE_PROP);
+	/* find the node holding the images information */
+	images = fdt_path_offset(sec_firmware_img, FIT_IMAGES_PATH);
+	if (images < 0) {
+		debug("%s: Cannot find /images node: %d\n", __func__, images);
+		return -1;
+	}
+
+	type = FIT_LOADABLE_PROP;
+
+	name = fdt_getprop(sec_firmware_img, conf_node_off, type, &len);
+	if (!name) {
+		/* Loadables not present */
+		return 0;
+	}
+
+	printf("SEC Firmware: '%s' present in config\n", type);
+
+	for (str = name; str && ((str - name) < len);
+	     str = strchr(str, '\0') + 1) {
+		printf("%s: '%s'\n", type, str);
+		ld_node_off = fdt_subnode_offset(sec_firmware_img, images, str);
+		if (ld_node_off < 0) {
+			printf("cannot find image node '%s': %d\n", str,
+			       ld_node_off);
+			return -EINVAL;
+		}
 
 		/* Verify secure firmware image */
 		if (!(fit_image_verify(sec_firmware_img, ld_node_off))) {
@@ -164,11 +187,19 @@ static int sec_firmware_check_copy_loadable(const void *sec_firmware_img,
 		memcpy((void *)sec_firmware_loadable_addr, data, size);
 		flush_dcache_range(sec_firmware_loadable_addr,
 				   sec_firmware_loadable_addr + size);
-	}
 
-	/* Populate address ptrs for loadable image with loadbale addr */
-	out_le32(loadable_l, (sec_firmware_loadable_addr & WORD_MASK));
-	out_le32(loadable_h, (sec_firmware_loadable_addr >> WORD_SHIFT));
+		/* Populate loadable address only for Trusted OS */
+		if (!strcmp(str, "trustedOS at 1")) {
+			/*
+			 * Populate address ptrs for loadable image with
+			 * loadbale addr
+			 */
+			out_le32(loadable_l, (sec_firmware_loadable_addr &
+					      WORD_MASK));
+			out_le32(loadable_h, (sec_firmware_loadable_addr >>
+					      WORD_SHIFT));
+		}
+	}
 
 	return 0;
 }
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/1 armv8: sec_firmware: Add support for multiple loadables

Quoted 29 lines · Sumit Garg

Enable support for multiple loadable images in SEC firmware FIT image.

---
 arch/arm/cpu/armv8/sec_firmware.c | 51 +++++++++++++++++++++++++++++++--------
 1 file changed, 41 insertions(+), 10 deletions(-)
arch/arm/cpu/armv8/sec_firmware.c +3 -1
index 927eae4..28de81c 100644
@@ -116,11 +116,13 @@ static int sec_firmware_check_copy_loadable(const void *sec_firmware_img,
 					    u32 *loadable_l, u32 *loadable_h)
 {
 	phys_addr_t sec_firmware_loadable_addr = 0;
-	int conf_node_off, ld_node_off;
+	int conf_node_off, ld_node_off, images;
 	char *conf_node_name = NULL;
 	const void *data;
 	size_t size;
 	ulong load;
+	const char *name, *str, *type;
+	int len;
 
 	conf_node_name = SEC_FIRMEWARE_FIT_CNF_NAME;
 
@@ -130,11 +132,32 @@ static int sec_firmware_check_copy_loadable(const void *sec_firmware_img,
 	return -ENOENT;
 	}

arch/arm/cpu/armv8/sec_firmware.c static int sec_firmware_check_copy_loadable(const void *sec_firmware_img, · line 138

Quoted 10 lines
arch/arm/cpu/armv8/sec_firmware.c +4 -5
 
-	ld_node_off = fit_conf_get_prop_node(sec_firmware_img, conf_node_off,
-					     FIT_LOADABLE_PROP);
-	if (ld_node_off >= 0) {
-		printf("SEC Firmware: '%s' present in config\n",
-		       FIT_LOADABLE_PROP);
+	/* find the node holding the images information */
+	images = fdt_path_offset(sec_firmware_img, FIT_IMAGES_PATH);
+	if (images < 0) {
+		debug("%s: Cannot find /images node: %d\n", __func__, images);

Do you expect this often? If it should happen, change debug to printf.

arch/arm/cpu/armv8/sec_firmware.c static int sec_firmware_check_copy_loadable(const void *sec_firmware_img, · line 150

Quoted 12 lines
arch/arm/cpu/armv8/sec_firmware.c +12 -0
+		return -1;
+	}
+
+	type = FIT_LOADABLE_PROP;
+
+	name = fdt_getprop(sec_firmware_img, conf_node_off, type, &len);
+	if (!name) {
+		/* Loadables not present */
+		return 0;
+	}
+
+	printf("SEC Firmware: '%s' present in config\n", type);

How about replace printf() with debug()?

Quoted 28 lines
arch/arm/cpu/armv8/sec_firmware.c +15 -4
+
+	for (str = name; str && ((str - name) < len);
+	     str = strchr(str, '\0') + 1) {
+		printf("%s: '%s'\n", type, str);
+		ld_node_off = fdt_subnode_offset(sec_firmware_img, images, str);
+		if (ld_node_off < 0) {
+			printf("cannot find image node '%s': %d\n", str,
+			       ld_node_off);
+			return -EINVAL;
+		}
 
 		/* Verify secure firmware image */
 		if (!(fit_image_verify(sec_firmware_img, ld_node_off))) {
@@ -164,11 +187,19 @@ static int sec_firmware_check_copy_loadable(const void *sec_firmware_img,
 		memcpy((void *)sec_firmware_loadable_addr, data, size);
 		flush_dcache_range(sec_firmware_loadable_addr,
 				   sec_firmware_loadable_addr + size);
-	}
 
-	/* Populate address ptrs for loadable image with loadbale addr */
-	out_le32(loadable_l, (sec_firmware_loadable_addr & WORD_MASK));
-	out_le32(loadable_h, (sec_firmware_loadable_addr >> WORD_SHIFT));
+		/* Populate loadable address only for Trusted OS */
+		if (!strcmp(str, "trustedOS at 1")) {
+			/*
+			 * Populate address ptrs for loadable image with
+			 * loadbale addr

arch/arm/cpu/armv8/sec_firmware.c static int sec_firmware_check_copy_loadable(const void *sec_firmware_img, · line 205

Quoted 10 lines
arch/arm/cpu/armv8/sec_firmware.c +7 -0
+			 */
+			out_le32(loadable_l, (sec_firmware_loadable_addr &
+					      WORD_MASK));
+			out_le32(loadable_h, (sec_firmware_loadable_addr >>
+					      WORD_SHIFT));
+		}
+	}
 
 	return 0;
 }

It is unclear that you are looking for "trustedOS at 1" to set the address. Please add some document to describe the FIT image you are expecting.

York

author
#2 lore raw

PATCH 1/1 armv8: sec_firmware: Add support for multiple loadables

Quoted 49 lines

From: York Sun
Sent: Monday, January 15, 2018 10:16 PM

arch/arm/cpu/armv8/sec_firmware.c static int sec_firmware_check_copy_loadable(const

Quoted 14 lines · Sumit Garg

Enable support for multiple loadable images in SEC firmware FIT image.

---
 arch/arm/cpu/armv8/sec_firmware.c | 51
+++++++++++++++++++++++++++++++--------
 1 file changed, 41 insertions(+), 10 deletions(-)
arch/arm/cpu/armv8/sec_firmware.c +0 -0
index 927eae4..28de81c 100644
@@ -116,11 +116,13 @@ static int sec_firmware_check_copy_loadable(const

void *sec_firmware_img,

arch/arm/cpu/armv8/sec_firmware.c static int sec_firmware_check_copy_loadable(const

Quoted 14 lines
arch/arm/cpu/armv8/sec_firmware.c +3 -1
 					    u32 *loadable_l, u32 *loadable_h)  {
 	phys_addr_t sec_firmware_loadable_addr = 0;
-	int conf_node_off, ld_node_off;
+	int conf_node_off, ld_node_off, images;
 	char *conf_node_name = NULL;
 	const void *data;
 	size_t size;
 	ulong load;
+	const char *name, *str, *type;
+	int len;
 
 	conf_node_name = SEC_FIRMEWARE_FIT_CNF_NAME;
 
@@ -130,11 +132,32 @@ static int sec_firmware_check_copy_loadable(const

void *sec_firmware_img,

arch/arm/cpu/armv8/sec_firmware.c static int sec_firmware_check_copy_loadable(const void *sec_firmware_img,

Quoted 4 lines
arch/arm/cpu/armv8/sec_firmware.c +0 -1
 	return -ENOENT;
 	}
 
-	ld_node_off = fit_conf_get_prop_node(sec_firmware_img,

conf_node_off,

arch/arm/cpu/armv8/sec_firmware.c static int sec_firmware_check_copy_loadable(const void *sec_firmware_img,

Quoted 8 lines
arch/arm/cpu/armv8/sec_firmware.c +4 -4
-					     FIT_LOADABLE_PROP);
-	if (ld_node_off >= 0) {
-		printf("SEC Firmware: '%s' present in config\n",
-		       FIT_LOADABLE_PROP);
+	/* find the node holding the images information */
+	images = fdt_path_offset(sec_firmware_img, FIT_IMAGES_PATH);
+	if (images < 0) {
+		debug("%s: Cannot find /images node: %d\n", __func__,

images);

Quoted 1 line

Do you expect this often? If it should happen, change debug to printf.

No this isn't expected as fit image should at least have ppa monitor image.

Quoted 15 lines

arch/arm/cpu/armv8/sec_firmware.c static int sec_firmware_check_copy_loadable(const void *sec_firmware_img, · line 150

Quoted 13 lines
arch/arm/cpu/armv8/sec_firmware.c +12 -0
+		return -1;
+	}
+
+	type = FIT_LOADABLE_PROP;
+
+	name = fdt_getprop(sec_firmware_img, conf_node_off, type, &len);
+	if (!name) {
+		/* Loadables not present */
+		return 0;
+	}
+
+	printf("SEC Firmware: '%s' present in config\n", type);

How about replace printf() with debug()?

Actually I wanted to differentiate from u-boot logs whether there were any "loadables" in ppa fit image or not.

Quoted 39 lines

arch/arm/cpu/armv8/sec_firmware.c static int sec_firmware_check_copy_loadable(const void *sec_firmware_img,

Quoted 6 lines
arch/arm/cpu/armv8/sec_firmware.c +5 -0
+
+	for (str = name; str && ((str - name) < len);
+	     str = strchr(str, '\0') + 1) {
+		printf("%s: '%s'\n", type, str);
+		ld_node_off = fdt_subnode_offset(sec_firmware_img,

images, str);

arch/arm/cpu/armv8/sec_firmware.c static int sec_firmware_check_copy_loadable(const void *sec_firmware_img,

Quoted 9 lines
arch/arm/cpu/armv8/sec_firmware.c +5 -1
+		if (ld_node_off < 0) {
+			printf("cannot find image node '%s': %d\n", str,
+			       ld_node_off);
+			return -EINVAL;
+		}
 
 		/* Verify secure firmware image */
 		if (!(fit_image_verify(sec_firmware_img, ld_node_off))) { @@
-164,11 +187,19 @@ static int sec_firmware_check_copy_loadable(const void

*sec_firmware_img,

arch/arm/cpu/armv8/sec_firmware.c static int sec_firmware_check_copy_loadable(const void *sec_firmware_img,

Quoted 8 lines
arch/arm/cpu/armv8/sec_firmware.c +0 -4
 		memcpy((void *)sec_firmware_loadable_addr, data, size);
 		flush_dcache_range(sec_firmware_loadable_addr,
 				   sec_firmware_loadable_addr + size);
-	}
 
-	/* Populate address ptrs for loadable image with loadbale addr */
-	out_le32(loadable_l, (sec_firmware_loadable_addr & WORD_MASK));
-	out_le32(loadable_h, (sec_firmware_loadable_addr >>

WORD_SHIFT));

Quoted 13 lines
arch/arm/cpu/armv8/sec_firmware.c +12 -0
+		/* Populate loadable address only for Trusted OS */
+		if (!strcmp(str, "trustedOS at 1")) {
+			/*
+			 * Populate address ptrs for loadable image with
+			 * loadbale addr
+			 */
+			out_le32(loadable_l, (sec_firmware_loadable_addr &
+					      WORD_MASK));
+			out_le32(loadable_h, (sec_firmware_loadable_addr >>
+					      WORD_SHIFT));
+		}
+	}
Quoted 5 lines
Quoted 3 lines

return 0;
}

It is unclear that you are looking for "trustedOS at 1" to set the address.

Actually this patch is meant to load "fuse provisioning script" used by PPA to provision fuses on our SoC's in PPA DDR space (2MB). And this allocation of PPA DDR space for this script will be fixed and hardcoded in PPA.

But in case of trusted OS with own DDR space (64MB), we have to communicate load address of trusted OS to PPA to initialize it.

Quoted 1 line

Please add some document to describe the FIT image you are expecting.

Sure I will add a document to describe the FIT image.

-Sumit

#3 lore raw

PATCH 1/1 armv8: sec_firmware: Add support for multiple loadables

Quoted 49 lines · Sumit Garg
Quoted 49 lines

From: York Sun
Sent: Monday, January 15, 2018 10:16 PM

arch/arm/cpu/armv8/sec_firmware.c static int sec_firmware_check_copy_loadable(const

Quoted 14 lines · Sumit Garg

Enable support for multiple loadable images in SEC firmware FIT image.

---
 arch/arm/cpu/armv8/sec_firmware.c | 51
+++++++++++++++++++++++++++++++--------
 1 file changed, 41 insertions(+), 10 deletions(-)
arch/arm/cpu/armv8/sec_firmware.c +0 -0
index 927eae4..28de81c 100644
@@ -116,11 +116,13 @@ static int sec_firmware_check_copy_loadable(const

void *sec_firmware_img,

arch/arm/cpu/armv8/sec_firmware.c static int sec_firmware_check_copy_loadable(const

Quoted 14 lines
arch/arm/cpu/armv8/sec_firmware.c +3 -1
 					    u32 *loadable_l, u32 *loadable_h)  {
 	phys_addr_t sec_firmware_loadable_addr = 0;
-	int conf_node_off, ld_node_off;
+	int conf_node_off, ld_node_off, images;
 	char *conf_node_name = NULL;
 	const void *data;
 	size_t size;
 	ulong load;
+	const char *name, *str, *type;
+	int len;
 
 	conf_node_name = SEC_FIRMEWARE_FIT_CNF_NAME;
 
@@ -130,11 +132,32 @@ static int sec_firmware_check_copy_loadable(const

void *sec_firmware_img,

arch/arm/cpu/armv8/sec_firmware.c static int sec_firmware_check_copy_loadable(const void *sec_firmware_img,

Quoted 4 lines
arch/arm/cpu/armv8/sec_firmware.c +0 -1
 	return -ENOENT;
 	}
 
-	ld_node_off = fit_conf_get_prop_node(sec_firmware_img,

conf_node_off,

arch/arm/cpu/armv8/sec_firmware.c static int sec_firmware_check_copy_loadable(const void *sec_firmware_img,

Quoted 8 lines
arch/arm/cpu/armv8/sec_firmware.c +4 -4
-					     FIT_LOADABLE_PROP);
-	if (ld_node_off >= 0) {
-		printf("SEC Firmware: '%s' present in config\n",
-		       FIT_LOADABLE_PROP);
+	/* find the node holding the images information */
+	images = fdt_path_offset(sec_firmware_img, FIT_IMAGES_PATH);
+	if (images < 0) {
+		debug("%s: Cannot find /images node: %d\n", __func__,

images);

Quoted 3 lines
Quoted 1 line

Do you expect this often? If it should happen, change debug to printf.

No this isn't expected as fit image should at least have ppa monitor image.

The idea is to reduce unnecessary messages and make sure the error is raised. In this case, if the image is not found, you cannot proceed with secure booting. So a visible error is needed.

York

author
#4 lore raw

PATCH 1/1 armv8: sec_firmware: Add support for multiple loadables

Quoted 58 lines

-----Original Message-----
From: York Sun
Sent: Monday, January 15, 2018 10:43 PM

Quoted 53 lines · Sumit Garg
Quoted 52 lines

From: York Sun
Sent: Monday, January 15, 2018 10:16 PM

Quoted 14 lines · Sumit Garg

Enable support for multiple loadable images in SEC firmware FIT image.

---
 arch/arm/cpu/armv8/sec_firmware.c | 51
+++++++++++++++++++++++++++++++--------
 1 file changed, 41 insertions(+), 10 deletions(-)
arch/arm/cpu/armv8/sec_firmware.c +0 -0
index 927eae4..28de81c 100644
@@ -116,11 +116,13 @@ static int
Quoted 1 line

sec_firmware_check_copy_loadable(const

void *sec_firmware_img,

Quoted 14 lines
arch/arm/cpu/armv8/sec_firmware.c +3 -1
 					    u32 *loadable_l, u32 *loadable_h)  {
 	phys_addr_t sec_firmware_loadable_addr = 0;
-	int conf_node_off, ld_node_off;
+	int conf_node_off, ld_node_off, images;
 	char *conf_node_name = NULL;
 	const void *data;
 	size_t size;
 	ulong load;
+	const char *name, *str, *type;
+	int len;
 
 	conf_node_name = SEC_FIRMEWARE_FIT_CNF_NAME;
@@ -130,11 +132,32 @@ static int
Quoted 1 line

sec_firmware_check_copy_loadable(const

void *sec_firmware_img,

arch/arm/cpu/armv8/sec_firmware.c static int sec_firmware_check_copy_loadable(const void *sec_firmware_img,

Quoted 4 lines
arch/arm/cpu/armv8/sec_firmware.c +0 -1
 	return -ENOENT;
 	}
 
-	ld_node_off = fit_conf_get_prop_node(sec_firmware_img,

conf_node_off,

arch/arm/cpu/armv8/sec_firmware.c static int sec_firmware_check_copy_loadable(const void *sec_firmware_img,

Quoted 8 lines
arch/arm/cpu/armv8/sec_firmware.c +4 -4
-					     FIT_LOADABLE_PROP);
-	if (ld_node_off >= 0) {
-		printf("SEC Firmware: '%s' present in config\n",
-		       FIT_LOADABLE_PROP);
+	/* find the node holding the images information */
+	images = fdt_path_offset(sec_firmware_img, FIT_IMAGES_PATH);
+	if (images < 0) {
+		debug("%s: Cannot find /images node: %d\n", __func__,

images);

Do you expect this often? If it should happen, change debug to printf.

Quoted 7 lines
Quoted 1 line

No this isn't expected as fit image should at least have ppa monitor image.

The idea is to reduce unnecessary messages and make sure the error is raised. In this case, if the image is not found, you cannot proceed with secure booting. So a visible error is needed.

York

Sure I will put up a printf instead of debug here.

-Sumit