diff mbox series

[09/10] dfu: add error callback

Message ID 20210518151206.9.I36ae186249a121969b9ab6d3a7f62752091cf472@changeid
State Accepted
Commit d4710326c814ffbf84eab87dce8f8fd789b0da18
Delegated to: Patrice Chotard
Headers show
Series stm32mp: stm32prog: several features and fixes | expand

Commit Message

Patrick Delaunay May 18, 2021, 1:12 p.m. UTC
Add error callback in dfu stack to manage some board specific
behavior on DFU targets.

Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
---

 drivers/dfu/dfu.c | 12 ++++++++++++
 include/dfu.h     | 11 +++++++++++
 2 files changed, 23 insertions(+)

Comments

Patrice CHOTARD May 28, 2021, 12:54 p.m. UTC | #1
Hi Patrick

On 5/18/21 3:12 PM, Patrick Delaunay wrote:
> Add error callback in dfu stack to manage some board specific
> behavior on DFU targets.
> 
> Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
> ---
> 
>  drivers/dfu/dfu.c | 12 ++++++++++++
>  include/dfu.h     | 11 +++++++++++
>  2 files changed, 23 insertions(+)
> 
> diff --git a/drivers/dfu/dfu.c b/drivers/dfu/dfu.c
> index 213a20e7bc..ff1859d946 100644
> --- a/drivers/dfu/dfu.c
> +++ b/drivers/dfu/dfu.c
> @@ -44,6 +44,14 @@ __weak void dfu_initiated_callback(struct dfu_entity *dfu)
>  {
>  }
>  
> +/*
> + * The purpose of the dfu_error_callback() function is to
> + * provide callback for dfu user
> + */
> +__weak void dfu_error_callback(struct dfu_entity *dfu, const char *msg)
> +{
> +}
> +
>  /*
>   * The purpose of the dfu_usb_get_reset() function is to
>   * provide information if after USB_DETACH request
> @@ -342,6 +350,7 @@ int dfu_write(struct dfu_entity *dfu, void *buf, int size, int blk_seq_num)
>  		printf("%s: Wrong sequence number! [%d] [%d]\n",
>  		       __func__, dfu->i_blk_seq_num, blk_seq_num);
>  		dfu_transaction_cleanup(dfu);
> +		dfu_error_callback(dfu, "Wrong sequence number");
>  		return -1;
>  	}
>  
> @@ -366,6 +375,7 @@ int dfu_write(struct dfu_entity *dfu, void *buf, int size, int blk_seq_num)
>  		ret = dfu_write_buffer_drain(dfu);
>  		if (ret) {
>  			dfu_transaction_cleanup(dfu);
> +			dfu_error_callback(dfu, "DFU write error");
>  			return ret;
>  		}
>  	}
> @@ -375,6 +385,7 @@ int dfu_write(struct dfu_entity *dfu, void *buf, int size, int blk_seq_num)
>  		pr_err("Buffer overflow! (0x%p + 0x%x > 0x%p)\n", dfu->i_buf,
>  		      size, dfu->i_buf_end);
>  		dfu_transaction_cleanup(dfu);
> +		dfu_error_callback(dfu, "Buffer overflow");
>  		return -1;
>  	}
>  
> @@ -386,6 +397,7 @@ int dfu_write(struct dfu_entity *dfu, void *buf, int size, int blk_seq_num)
>  		ret = dfu_write_buffer_drain(dfu);
>  		if (ret) {
>  			dfu_transaction_cleanup(dfu);
> +			dfu_error_callback(dfu, "DFU write error");
>  			return ret;
>  		}
>  	}
> diff --git a/include/dfu.h b/include/dfu.h
> index d18b701728..1963e9ffb9 100644
> --- a/include/dfu.h
> +++ b/include/dfu.h
> @@ -383,6 +383,17 @@ void dfu_initiated_callback(struct dfu_entity *dfu);
>   */
>  void dfu_flush_callback(struct dfu_entity *dfu);
>  
> +/**
> + * dfu_error_callback() - weak callback called at the DFU write error
> + *
> + * It is a callback function called by DFU stack after DFU write error.
> + * This function allows to manage some board specific behavior on DFU targets
> + *
> + * @dfu:	pointer to the dfu_entity which cause the error
> + * @msg:	the message of the error
> + */
> +void dfu_error_callback(struct dfu_entity *dfu, const char *msg);
> +
>  int dfu_transaction_initiate(struct dfu_entity *dfu, bool read);
>  void dfu_transaction_cleanup(struct dfu_entity *dfu);
>  
> 

Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>

Thanks
Patrice
Patrice CHOTARD June 18, 2021, 7:56 a.m. UTC | #2
On 5/28/21 2:54 PM, Patrice CHOTARD wrote:
> Hi Patrick
> 
> On 5/18/21 3:12 PM, Patrick Delaunay wrote:
>> Add error callback in dfu stack to manage some board specific
>> behavior on DFU targets.
>>
>> Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
>> ---
>>
>>  drivers/dfu/dfu.c | 12 ++++++++++++
>>  include/dfu.h     | 11 +++++++++++
>>  2 files changed, 23 insertions(+)
>>
>> diff --git a/drivers/dfu/dfu.c b/drivers/dfu/dfu.c
>> index 213a20e7bc..ff1859d946 100644
>> --- a/drivers/dfu/dfu.c
>> +++ b/drivers/dfu/dfu.c
>> @@ -44,6 +44,14 @@ __weak void dfu_initiated_callback(struct dfu_entity *dfu)
>>  {
>>  }
>>  
>> +/*
>> + * The purpose of the dfu_error_callback() function is to
>> + * provide callback for dfu user
>> + */
>> +__weak void dfu_error_callback(struct dfu_entity *dfu, const char *msg)
>> +{
>> +}
>> +
>>  /*
>>   * The purpose of the dfu_usb_get_reset() function is to
>>   * provide information if after USB_DETACH request
>> @@ -342,6 +350,7 @@ int dfu_write(struct dfu_entity *dfu, void *buf, int size, int blk_seq_num)
>>  		printf("%s: Wrong sequence number! [%d] [%d]\n",
>>  		       __func__, dfu->i_blk_seq_num, blk_seq_num);
>>  		dfu_transaction_cleanup(dfu);
>> +		dfu_error_callback(dfu, "Wrong sequence number");
>>  		return -1;
>>  	}
>>  
>> @@ -366,6 +375,7 @@ int dfu_write(struct dfu_entity *dfu, void *buf, int size, int blk_seq_num)
>>  		ret = dfu_write_buffer_drain(dfu);
>>  		if (ret) {
>>  			dfu_transaction_cleanup(dfu);
>> +			dfu_error_callback(dfu, "DFU write error");
>>  			return ret;
>>  		}
>>  	}
>> @@ -375,6 +385,7 @@ int dfu_write(struct dfu_entity *dfu, void *buf, int size, int blk_seq_num)
>>  		pr_err("Buffer overflow! (0x%p + 0x%x > 0x%p)\n", dfu->i_buf,
>>  		      size, dfu->i_buf_end);
>>  		dfu_transaction_cleanup(dfu);
>> +		dfu_error_callback(dfu, "Buffer overflow");
>>  		return -1;
>>  	}
>>  
>> @@ -386,6 +397,7 @@ int dfu_write(struct dfu_entity *dfu, void *buf, int size, int blk_seq_num)
>>  		ret = dfu_write_buffer_drain(dfu);
>>  		if (ret) {
>>  			dfu_transaction_cleanup(dfu);
>> +			dfu_error_callback(dfu, "DFU write error");
>>  			return ret;
>>  		}
>>  	}
>> diff --git a/include/dfu.h b/include/dfu.h
>> index d18b701728..1963e9ffb9 100644
>> --- a/include/dfu.h
>> +++ b/include/dfu.h
>> @@ -383,6 +383,17 @@ void dfu_initiated_callback(struct dfu_entity *dfu);
>>   */
>>  void dfu_flush_callback(struct dfu_entity *dfu);
>>  
>> +/**
>> + * dfu_error_callback() - weak callback called at the DFU write error
>> + *
>> + * It is a callback function called by DFU stack after DFU write error.
>> + * This function allows to manage some board specific behavior on DFU targets
>> + *
>> + * @dfu:	pointer to the dfu_entity which cause the error
>> + * @msg:	the message of the error
>> + */
>> +void dfu_error_callback(struct dfu_entity *dfu, const char *msg);
>> +
>>  int dfu_transaction_initiate(struct dfu_entity *dfu, bool read);
>>  void dfu_transaction_cleanup(struct dfu_entity *dfu);
>>  
>>
> 
> Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
> 
> Thanks
> Patrice
> _______________________________________________
> Uboot-stm32 mailing list
> Uboot-stm32@st-md-mailman.stormreply.com
> https://st-md-mailman.stormreply.com/mailman/listinfo/uboot-stm32
> 
Applied on u-boot-stm32/next

Thanks
diff mbox series

Patch

diff --git a/drivers/dfu/dfu.c b/drivers/dfu/dfu.c
index 213a20e7bc..ff1859d946 100644
--- a/drivers/dfu/dfu.c
+++ b/drivers/dfu/dfu.c
@@ -44,6 +44,14 @@  __weak void dfu_initiated_callback(struct dfu_entity *dfu)
 {
 }
 
+/*
+ * The purpose of the dfu_error_callback() function is to
+ * provide callback for dfu user
+ */
+__weak void dfu_error_callback(struct dfu_entity *dfu, const char *msg)
+{
+}
+
 /*
  * The purpose of the dfu_usb_get_reset() function is to
  * provide information if after USB_DETACH request
@@ -342,6 +350,7 @@  int dfu_write(struct dfu_entity *dfu, void *buf, int size, int blk_seq_num)
 		printf("%s: Wrong sequence number! [%d] [%d]\n",
 		       __func__, dfu->i_blk_seq_num, blk_seq_num);
 		dfu_transaction_cleanup(dfu);
+		dfu_error_callback(dfu, "Wrong sequence number");
 		return -1;
 	}
 
@@ -366,6 +375,7 @@  int dfu_write(struct dfu_entity *dfu, void *buf, int size, int blk_seq_num)
 		ret = dfu_write_buffer_drain(dfu);
 		if (ret) {
 			dfu_transaction_cleanup(dfu);
+			dfu_error_callback(dfu, "DFU write error");
 			return ret;
 		}
 	}
@@ -375,6 +385,7 @@  int dfu_write(struct dfu_entity *dfu, void *buf, int size, int blk_seq_num)
 		pr_err("Buffer overflow! (0x%p + 0x%x > 0x%p)\n", dfu->i_buf,
 		      size, dfu->i_buf_end);
 		dfu_transaction_cleanup(dfu);
+		dfu_error_callback(dfu, "Buffer overflow");
 		return -1;
 	}
 
@@ -386,6 +397,7 @@  int dfu_write(struct dfu_entity *dfu, void *buf, int size, int blk_seq_num)
 		ret = dfu_write_buffer_drain(dfu);
 		if (ret) {
 			dfu_transaction_cleanup(dfu);
+			dfu_error_callback(dfu, "DFU write error");
 			return ret;
 		}
 	}
diff --git a/include/dfu.h b/include/dfu.h
index d18b701728..1963e9ffb9 100644
--- a/include/dfu.h
+++ b/include/dfu.h
@@ -383,6 +383,17 @@  void dfu_initiated_callback(struct dfu_entity *dfu);
  */
 void dfu_flush_callback(struct dfu_entity *dfu);
 
+/**
+ * dfu_error_callback() - weak callback called at the DFU write error
+ *
+ * It is a callback function called by DFU stack after DFU write error.
+ * This function allows to manage some board specific behavior on DFU targets
+ *
+ * @dfu:	pointer to the dfu_entity which cause the error
+ * @msg:	the message of the error
+ */
+void dfu_error_callback(struct dfu_entity *dfu, const char *msg);
+
 int dfu_transaction_initiate(struct dfu_entity *dfu, bool read);
 void dfu_transaction_cleanup(struct dfu_entity *dfu);