From: Wendy Liang <[email protected]>

In rproc_is_running_fw() function, set the firmware checksum in resource
in the resource table and compared it with the one in the loaded resource
table.

If the firmware checksum in the loaded resource table matches the one
calculated with the firmware, the remote is running with the expected
firmware.

Signed-off-by: Wendy Liang <[email protected]>
Signed-off-by: Michal Simek <[email protected]>
---
 drivers/remoteproc/remoteproc_core.c | 29 ++++++++++++++++++++++++++---
 1 file changed, 26 insertions(+), 3 deletions(-)

diff --git a/drivers/remoteproc/remoteproc_core.c 
b/drivers/remoteproc/remoteproc_core.c
index 447c28b..e4fb289 100644
--- a/drivers/remoteproc/remoteproc_core.c
+++ b/drivers/remoteproc/remoteproc_core.c
@@ -956,10 +956,33 @@ struct fw_rsc_fw_chksum *rproc_handle_fw_chksum(struct 
rproc *rproc,
  */
 static bool rproc_is_running_fw(struct rproc *rproc, const struct firmware *fw)
 {
-       (void)rproc;
-       (void) fw;
+       struct resource_table *loaded_table;
+       struct fw_rsc_fw_chksum *rsc, *loaded_rsc;
+       int rsc_fw_chksum_offset;
 
-       return false;
+       rsc = rproc_handle_fw_chksum(rproc, fw, &rsc_fw_chksum_offset);
+       if (!rsc)
+               return false;
+
+       if (!rproc_is_running(rproc))
+               return false;
+
+       /* look for the loaded resource table */
+       loaded_table = rproc_find_loaded_rsc_table(rproc, fw);
+       if (!loaded_table)
+               return false;
+
+       loaded_rsc = (void *)loaded_table + rsc_fw_chksum_offset;
+       if (!loaded_rsc->algo || !loaded_rsc->chksum)
+               return false;
+
+       if (strncmp(rsc->algo, loaded_rsc->algo, strlen(rsc->algo)))
+               return false;
+
+       if (memcmp(rsc->chksum, loaded_rsc->chksum, sizeof(rsc->chksum)))
+               return false;
+
+       return true;
 }
 
 /*
-- 
1.9.1

Reply via email to