Re: [PATCH v6 5/7] fwu: meta-data: switch to management by common code

2023-03-16 Thread Sughosh Ganu
On Thu, 16 Mar 2023 at 13:56, Ilias Apalodimas
 wrote:
>
> On Mon, Mar 06, 2023 at 05:18:41PM -0600, jassisinghb...@gmail.com wrote:
> > From: Jassi Brar 
> >
> > The common code can now read, verify and fix meta-data copies
> > while exposing one consistent structure to users.
> >  Only the .read_mdata() and .write_mdata() callbacks of fwu_mdata_ops
> > are needed. Get rid of .get_mdata() .update_mdata() .get_mdata_part_num()
> > .read_mdata_partition() and .write_mdata_partition() and also the
> > corresponding wrapper functions.
> >
> > Signed-off-by: Jassi Brar 
> > Reviewed-by: Etienne Carriere 
> > ---
> >  cmd/fwu_mdata.c  |  17 +-
> >  drivers/fwu-mdata/fwu-mdata-uclass.c | 165 ---
> >  drivers/fwu-mdata/gpt_blk.c  | 124 +-
> >  include/fwu.h| 199 ---
> >  lib/fwu_updates/fwu.c| 235 ---
> >  5 files changed, 38 insertions(+), 702 deletions(-)



> >
> Etienne, Sughosh, this looks correct, but can someone
> verify it doesn't break the ST board?

I will check on the ST board by tomorrow and get back.

-sughosh


Re: [PATCH v6 5/7] fwu: meta-data: switch to management by common code

2023-03-16 Thread Ilias Apalodimas
On Mon, Mar 06, 2023 at 05:18:41PM -0600, jassisinghb...@gmail.com wrote:
> From: Jassi Brar 
>
> The common code can now read, verify and fix meta-data copies
> while exposing one consistent structure to users.
>  Only the .read_mdata() and .write_mdata() callbacks of fwu_mdata_ops
> are needed. Get rid of .get_mdata() .update_mdata() .get_mdata_part_num()
> .read_mdata_partition() and .write_mdata_partition() and also the
> corresponding wrapper functions.
>
> Signed-off-by: Jassi Brar 
> Reviewed-by: Etienne Carriere 
> ---
>  cmd/fwu_mdata.c  |  17 +-
>  drivers/fwu-mdata/fwu-mdata-uclass.c | 165 ---
>  drivers/fwu-mdata/gpt_blk.c  | 124 +-
>  include/fwu.h| 199 ---
>  lib/fwu_updates/fwu.c| 235 ---
>  5 files changed, 38 insertions(+), 702 deletions(-)
>
> diff --git a/cmd/fwu_mdata.c b/cmd/fwu_mdata.c
> index f04af27de6..9b70340368 100644
> --- a/cmd/fwu_mdata.c
> +++ b/cmd/fwu_mdata.c
> @@ -43,23 +43,10 @@ static void print_mdata(struct fwu_mdata *mdata)
>  int do_fwu_mdata_read(struct cmd_tbl *cmdtp, int flag,
>int argc, char * const argv[])
>  {
> - struct udevice *dev;
>   int ret = CMD_RET_SUCCESS, res;
> - struct fwu_mdata mdata = { 0 };
> + struct fwu_mdata mdata;
>
> - if (uclass_get_device(UCLASS_FWU_MDATA, 0, ) || !dev) {
> - log_err("Unable to get FWU metadata device\n");
> - return CMD_RET_FAILURE;
> - }
> -
> - res = fwu_check_mdata_validity();
> - if (res < 0) {
> - log_err("FWU Metadata check failed\n");
> - ret = CMD_RET_FAILURE;
> - goto out;
> - }
> -
> - res = fwu_get_mdata(dev, );
> + res = fwu_get_verified_mdata();
>   if (res < 0) {
>   log_err("Unable to get valid FWU metadata\n");
>   ret = CMD_RET_FAILURE;
> diff --git a/drivers/fwu-mdata/fwu-mdata-uclass.c 
> b/drivers/fwu-mdata/fwu-mdata-uclass.c
> index e03773c584..0a8edaaa41 100644
> --- a/drivers/fwu-mdata/fwu-mdata-uclass.c
> +++ b/drivers/fwu-mdata/fwu-mdata-uclass.c
> @@ -14,7 +14,6 @@
>
>  #include 
>  #include 
> -#include 
>
>  /**
>   * fwu_read_mdata() - Wrapper around fwu_mdata_ops.read_mdata()
> @@ -50,170 +49,6 @@ int fwu_write_mdata(struct udevice *dev, struct fwu_mdata 
> *mdata, bool primary)
>   return ops->write_mdata(dev, mdata, primary);
>  }
>
> -/**
> - * fwu_get_mdata_part_num() - Get the FWU metadata partition numbers
> - * @dev: FWU metadata device
> - * @mdata_parts: array for storing the metadata partition numbers
> - *
> - * Get the partition numbers on the storage device on which the
> - * FWU metadata is stored. Two partition numbers will be returned.
> - *
> - * Return: 0 if OK, -ve on error
> - *
> - */
> -int fwu_get_mdata_part_num(struct udevice *dev, uint *mdata_parts)
> -{
> - const struct fwu_mdata_ops *ops = device_get_ops(dev);
> -
> - if (!ops->get_mdata_part_num) {
> - log_debug("get_mdata_part_num() method not defined\n");
> - return -ENOSYS;
> - }
> -
> - return ops->get_mdata_part_num(dev, mdata_parts);
> -}
> -
> -/**
> - * fwu_read_mdata_partition() - Read the FWU metadata from a partition
> - * @dev: FWU metadata device
> - * @mdata: Copy of the FWU metadata
> - * @part_num: Partition number from which FWU metadata is to be read
> - *
> - * Read the FWU metadata from the specified partition number
> - *
> - * Return: 0 if OK, -ve on error
> - *
> - */
> -int fwu_read_mdata_partition(struct udevice *dev, struct fwu_mdata *mdata,
> -  uint part_num)
> -{
> - const struct fwu_mdata_ops *ops = device_get_ops(dev);
> -
> - if (!ops->read_mdata_partition) {
> - log_debug("read_mdata_partition() method not defined\n");
> - return -ENOSYS;
> - }
> -
> - return ops->read_mdata_partition(dev, mdata, part_num);
> -}
> -
> -/**
> - * fwu_write_mdata_partition() - Write the FWU metadata to a partition
> - * @dev: FWU metadata device
> - * @mdata: Copy of the FWU metadata
> - * @part_num: Partition number to which FWU metadata is to be written
> - *
> - * Write the FWU metadata to the specified partition number
> - *
> - * Return: 0 if OK, -ve on error
> - *
> - */
> -int fwu_write_mdata_partition(struct udevice *dev, struct fwu_mdata *mdata,
> -   uint part_num)
> -{
> - const struct fwu_mdata_ops *ops = device_get_ops(dev);
> -
> - if (!ops->write_mdata_partition) {
> - log_debug("write_mdata_partition() method not defined\n");
> - return -ENOSYS;
> - }
> -
> - return ops->write_mdata_partition(dev, mdata, part_num);
> -}
> -
> -/**
> - * fwu_mdata_check() - Check if the FWU metadata is valid
> - * @dev: FWU metadata device
> - *
> - * Validate both copies of the FWU metadata. If one of the copies
> - * has gone bad, restore it from 

[PATCH v6 5/7] fwu: meta-data: switch to management by common code

2023-03-06 Thread jassisinghbrar
From: Jassi Brar 

The common code can now read, verify and fix meta-data copies
while exposing one consistent structure to users.
 Only the .read_mdata() and .write_mdata() callbacks of fwu_mdata_ops
are needed. Get rid of .get_mdata() .update_mdata() .get_mdata_part_num()
.read_mdata_partition() and .write_mdata_partition() and also the
corresponding wrapper functions.

Signed-off-by: Jassi Brar 
Reviewed-by: Etienne Carriere 
---
 cmd/fwu_mdata.c  |  17 +-
 drivers/fwu-mdata/fwu-mdata-uclass.c | 165 ---
 drivers/fwu-mdata/gpt_blk.c  | 124 +-
 include/fwu.h| 199 ---
 lib/fwu_updates/fwu.c| 235 ---
 5 files changed, 38 insertions(+), 702 deletions(-)

diff --git a/cmd/fwu_mdata.c b/cmd/fwu_mdata.c
index f04af27de6..9b70340368 100644
--- a/cmd/fwu_mdata.c
+++ b/cmd/fwu_mdata.c
@@ -43,23 +43,10 @@ static void print_mdata(struct fwu_mdata *mdata)
 int do_fwu_mdata_read(struct cmd_tbl *cmdtp, int flag,
 int argc, char * const argv[])
 {
-   struct udevice *dev;
int ret = CMD_RET_SUCCESS, res;
-   struct fwu_mdata mdata = { 0 };
+   struct fwu_mdata mdata;
 
-   if (uclass_get_device(UCLASS_FWU_MDATA, 0, ) || !dev) {
-   log_err("Unable to get FWU metadata device\n");
-   return CMD_RET_FAILURE;
-   }
-
-   res = fwu_check_mdata_validity();
-   if (res < 0) {
-   log_err("FWU Metadata check failed\n");
-   ret = CMD_RET_FAILURE;
-   goto out;
-   }
-
-   res = fwu_get_mdata(dev, );
+   res = fwu_get_verified_mdata();
if (res < 0) {
log_err("Unable to get valid FWU metadata\n");
ret = CMD_RET_FAILURE;
diff --git a/drivers/fwu-mdata/fwu-mdata-uclass.c 
b/drivers/fwu-mdata/fwu-mdata-uclass.c
index e03773c584..0a8edaaa41 100644
--- a/drivers/fwu-mdata/fwu-mdata-uclass.c
+++ b/drivers/fwu-mdata/fwu-mdata-uclass.c
@@ -14,7 +14,6 @@
 
 #include 
 #include 
-#include 
 
 /**
  * fwu_read_mdata() - Wrapper around fwu_mdata_ops.read_mdata()
@@ -50,170 +49,6 @@ int fwu_write_mdata(struct udevice *dev, struct fwu_mdata 
*mdata, bool primary)
return ops->write_mdata(dev, mdata, primary);
 }
 
-/**
- * fwu_get_mdata_part_num() - Get the FWU metadata partition numbers
- * @dev: FWU metadata device
- * @mdata_parts: array for storing the metadata partition numbers
- *
- * Get the partition numbers on the storage device on which the
- * FWU metadata is stored. Two partition numbers will be returned.
- *
- * Return: 0 if OK, -ve on error
- *
- */
-int fwu_get_mdata_part_num(struct udevice *dev, uint *mdata_parts)
-{
-   const struct fwu_mdata_ops *ops = device_get_ops(dev);
-
-   if (!ops->get_mdata_part_num) {
-   log_debug("get_mdata_part_num() method not defined\n");
-   return -ENOSYS;
-   }
-
-   return ops->get_mdata_part_num(dev, mdata_parts);
-}
-
-/**
- * fwu_read_mdata_partition() - Read the FWU metadata from a partition
- * @dev: FWU metadata device
- * @mdata: Copy of the FWU metadata
- * @part_num: Partition number from which FWU metadata is to be read
- *
- * Read the FWU metadata from the specified partition number
- *
- * Return: 0 if OK, -ve on error
- *
- */
-int fwu_read_mdata_partition(struct udevice *dev, struct fwu_mdata *mdata,
-uint part_num)
-{
-   const struct fwu_mdata_ops *ops = device_get_ops(dev);
-
-   if (!ops->read_mdata_partition) {
-   log_debug("read_mdata_partition() method not defined\n");
-   return -ENOSYS;
-   }
-
-   return ops->read_mdata_partition(dev, mdata, part_num);
-}
-
-/**
- * fwu_write_mdata_partition() - Write the FWU metadata to a partition
- * @dev: FWU metadata device
- * @mdata: Copy of the FWU metadata
- * @part_num: Partition number to which FWU metadata is to be written
- *
- * Write the FWU metadata to the specified partition number
- *
- * Return: 0 if OK, -ve on error
- *
- */
-int fwu_write_mdata_partition(struct udevice *dev, struct fwu_mdata *mdata,
- uint part_num)
-{
-   const struct fwu_mdata_ops *ops = device_get_ops(dev);
-
-   if (!ops->write_mdata_partition) {
-   log_debug("write_mdata_partition() method not defined\n");
-   return -ENOSYS;
-   }
-
-   return ops->write_mdata_partition(dev, mdata, part_num);
-}
-
-/**
- * fwu_mdata_check() - Check if the FWU metadata is valid
- * @dev: FWU metadata device
- *
- * Validate both copies of the FWU metadata. If one of the copies
- * has gone bad, restore it from the other copy.
- *
- * Return: 0 if OK, -ve on error
- *
- */
-int fwu_mdata_check(struct udevice *dev)
-{
-   const struct fwu_mdata_ops *ops = device_get_ops(dev);
-
-   if (!ops->check_mdata) {
-   log_debug("check_mdata() method not