Skip to contentSkip to conversation

remoteproc: support ELF loading without resource table

RFC In review Stefan Agner 2 participants 2 messages Apr 7, 2016 – Apr 8, 2016 Remote processor (remoteproc)

lore
Share & tools
lore
#0 lore raw

RFC 1/1 remoteproc: support ELF loading without resource table

Start remote processor even if the ELF does not provide a resource table.

---
Hi Bjorn,

Nice meeting you at ELC! I had this patch carrying in one of my tree which basically enables to boot a bare ELF file... Altough my goal is it to use firmwares with some kind of resource table, I think we should not enforce having a resource table...

--
Stefan

 drivers/remoteproc/remoteproc_core.c | 44 +++++++++++++++++-------------------
 1 file changed, 21 insertions(+), 23 deletions(-)
drivers/remoteproc/remoteproc_core.c +21 -23
index 3d7d58a..5e16910 100644
@@ -799,9 +799,6 @@ static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw)
 	struct resource_table *table, *loaded_table;
 	int ret, tablesz;
 
-	if (!rproc->table_ptr)
-		return -ENOMEM;
-
 	ret = rproc_fw_sanity_check(rproc, fw);
 	if (ret)
 		return ret;
@@ -824,21 +821,20 @@ static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw)
 	/* look for the resource table */
 	table = rproc_find_rsc_table(rproc, fw, &tablesz);
 	if (!table) {
-		dev_err(dev, "Failed to find resource table\n");
-		goto clean_up;
-	}
-
-	/* Verify that resource table in loaded fw is unchanged */
-	if (rproc->table_csum != crc32(0, table, tablesz)) {
-		dev_err(dev, "resource checksum failed, fw changed?\n");
-		goto clean_up;
-	}
+		dev_info(dev, "No resource table found, continuing...\n");
+	} else {
+		/* Verify that resource table in loaded fw is unchanged */
+		if (rproc->table_csum != crc32(0, table, tablesz)) {
+			dev_err(dev, "resource checksum failed, fw changed?\n");
+			goto clean_up;
+		}
 
-	/* handle fw resources which are required to boot rproc */
-	ret = rproc_handle_resources(rproc, tablesz, rproc_loading_handlers);
-	if (ret) {
-		dev_err(dev, "Failed to process resources: %d\n", ret);
-		goto clean_up;
+		/* handle fw resources which are required to boot rproc */
+		ret = rproc_handle_resources(rproc, tablesz, rproc_loading_handlers);
+		if (ret) {
+			dev_err(dev, "Failed to process resources: %d\n", ret);
+			goto clean_up;
+		}
 	}
 
 	/* load the ELF segments to memory */
@@ -855,13 +851,15 @@ static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw)
 	 * In order to pass this information to the remote device we must
 	 * copy this information to device memory.
 	 */
-	loaded_table = rproc_find_loaded_rsc_table(rproc, fw);
-	if (!loaded_table) {
-		ret = -EINVAL;
-		goto clean_up;
-	}
+	if (table) {
+		loaded_table = rproc_find_loaded_rsc_table(rproc, fw);
+		if (!loaded_table) {
+			ret = -EINVAL;
+			goto clean_up;
+		}
 
-	memcpy(loaded_table, rproc->cached_table, tablesz);
+		memcpy(loaded_table, rproc->cached_table, tablesz);
+	}
 
 	/* power up the remote processor */
 	ret = rproc->ops->start(rproc);
Signature · 1 line
2.7.4
#1 lore raw
Quoted 8 lines · Stefan Agner

Start remote processor even if the ELF does not provide a resource table.

---
Hi Bjorn,

Nice meeting you at ELC!

You too, thanks for the good chat.

Quoted 5 lines

I had this patch carrying in one of my tree
which basically enables to boot a bare ELF file... Altough my goal is it to use firmwares with some kind of resource table, I think we should not enforce having a resource table...

I agree, we should support platforms without resource tables; and the variants of no resource-table in the ELF and no loaded resource table (transfered to the remote).

Quoted 21 lines

--
Stefan

 drivers/remoteproc/remoteproc_core.c | 44 +++++++++++++++++-------------------
 1 file changed, 21 insertions(+), 23 deletions(-)
drivers/remoteproc/remoteproc_core.c +0 -3
index 3d7d58a..5e16910 100644
@@ -799,9 +799,6 @@ static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw)
 	struct resource_table *table, *loaded_table;
 	int ret, tablesz;
 
-	if (!rproc->table_ptr)
-		return -ENOMEM;
-
 	ret = rproc_fw_sanity_check(rproc, fw);
 	if (ret)
 		return ret;

drivers/remoteproc/remoteproc_core.c static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw) · line 823

Quoted 3 lines
drivers/remoteproc/remoteproc_core.c +0 -0
@@ -824,21 +821,20 @@ static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw)
 	/* look for the resource table */
 	table = rproc_find_rsc_table(rproc, fw, &tablesz);
 	if (!table) {

We're fetching the resource table here just to verify that the firmware was not changed since we set up the vrings and whatnot.

So I think it would be more consistent to check for rproc->table_ptr being set here.

drivers/remoteproc/remoteproc_core.c static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw) · line 824

Quoted 10 lines
drivers/remoteproc/remoteproc_core.c +1 -9
-		dev_err(dev, "Failed to find resource table\n");
-		goto clean_up;
-	}
-
-	/* Verify that resource table in loaded fw is unchanged */
-	if (rproc->table_csum != crc32(0, table, tablesz)) {
-		dev_err(dev, "resource checksum failed, fw changed?\n");
-		goto clean_up;
-	}
+		dev_info(dev, "No resource table found, continuing...\n");

I think rather than just informing the user (if there even is someone looking at the dmesg) we should push an "assert" down to the drivers that require a resource table. But we can make that an incremental patch (and just be silent for now).

Quoted 8 lines
drivers/remoteproc/remoteproc_core.c +6 -1
+	} else {
+		/* Verify that resource table in loaded fw is unchanged */
+		if (rproc->table_csum != crc32(0, table, tablesz)) {
+			dev_err(dev, "resource checksum failed, fw changed?\n");
+			goto clean_up;
+		}
 
-	/* handle fw resources which are required to boot rproc */

drivers/remoteproc/remoteproc_core.c static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw) · line 837

Quoted 10 lines
drivers/remoteproc/remoteproc_core.c +6 -4
-	ret = rproc_handle_resources(rproc, tablesz, rproc_loading_handlers);
-	if (ret) {
-		dev_err(dev, "Failed to process resources: %d\n", ret);
-		goto clean_up;
+		/* handle fw resources which are required to boot rproc */
+		ret = rproc_handle_resources(rproc, tablesz, rproc_loading_handlers);
+		if (ret) {
+			dev_err(dev, "Failed to process resources: %d\n", ret);
+			goto clean_up;
+		}

For the Qualcomm case I worked around this by returning a dummy resource table, see qcom_mdt_find_rsc_table() in
https://patchwork.kernel.org/patch/8681951/

Please update this part and resend a patch and I'll give it some test. I think we can merge this.

Quoted 12 lines
drivers/remoteproc/remoteproc_core.c +0 -5
 	}
 
 	/* load the ELF segments to memory */
@@ -855,13 +851,15 @@ static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw)
 	 * In order to pass this information to the remote device we must
 	 * copy this information to device memory.
 	 */
-	loaded_table = rproc_find_loaded_rsc_table(rproc, fw);
-	if (!loaded_table) {
-		ret = -EINVAL;
-		goto clean_up;
-	}

drivers/remoteproc/remoteproc_core.c static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw) · line 862

Quoted 10 lines
drivers/remoteproc/remoteproc_core.c +8 -1
+	if (table) {
+		loaded_table = rproc_find_loaded_rsc_table(rproc, fw);
+		if (!loaded_table) {
+			ret = -EINVAL;
+			goto clean_up;
+		}
 
-	memcpy(loaded_table, rproc->cached_table, tablesz);
+		memcpy(loaded_table, rproc->cached_table, tablesz);
+	}

I have a patch available for making the loadable table optional, please have a look at:
https://patchwork.kernel.org/patch/8681971/

Comments/acks/tested-by appreciated.

Looking at it again I see that I should not assign the table_ptr if we don't have a loaded table. The table_ptr will be set back to cached_table upon shutdown, but this is not consistent so I will fix that in a v3.

Regards,
Bjorn