All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] lib: sparse: Make CHUNK_TYPE_RAW buffer aligned
@ 2021-11-15  5:43 qianfanguijin
  2021-11-15 15:07 ` Sean Anderson
  0 siblings, 1 reply; 6+ messages in thread
From: qianfanguijin @ 2021-11-15  5:43 UTC (permalink / raw)
  To: u-boot; +Cc: sean.anderson, hs, qianfan Zhao

From: qianfan Zhao <qianfanguijin@163.com>

CHUNK_TYPE_RAW buffer is not aligned, and flash sparse images by
fastboot will report "Misaligned operation" if DCACHE is enabled.

Flashing Sparse Image
CACHE: Misaligned operation at range [84000028, 84001028]
CACHE: Misaligned operation at range [84001034, 84002034]
CACHE: Misaligned operation at range [8401104c, 8401304c]

Fix it

Signed-off-by: qianfan Zhao <qianfanguijin@163.com>
---
 lib/image-sparse.c | 54 +++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 46 insertions(+), 8 deletions(-)

diff --git a/lib/image-sparse.c b/lib/image-sparse.c
index d80fdbbf58..1143c88a79 100644
--- a/lib/image-sparse.c
+++ b/lib/image-sparse.c
@@ -49,6 +49,48 @@
 
 static void default_log(const char *ignored, char *response) {}
 
+static lbaint_t write_sparse_chunk_raw(struct sparse_storage *info,
+				       lbaint_t blk, lbaint_t blkcnt,
+				       void *data,
+				       char *response)
+{
+	lbaint_t n, write_blks, blks = 0, aligned_buf_blks = 100;
+	uint32_t *aligned_buf = NULL;
+
+	if (CONFIG_IS_ENABLED(SYS_DCACHE_OFF))
+		return info->write(info, blk, blkcnt, data);
+
+	aligned_buf = memalign(ARCH_DMA_MINALIGN, info->blksz * aligned_buf_blks);
+	if (!aligned_buf) {
+		info->mssg("Malloc failed for: CHUNK_TYPE_RAW", response);
+		return -ENOMEM;
+	}
+
+	while (blkcnt > 0) {
+		n = min(aligned_buf_blks, blkcnt);
+		memcpy(aligned_buf, data, n * info->blksz);
+
+		/* write_blks might be > n due to NAND bad-blocks */
+		write_blks = info->write(info, blk + blks, n, aligned_buf);
+		if (write_blks < 0 || write_blks < n) {
+			printf("%s: %s" LBAFU " [" LBAFU "]\n",
+				__func__, "Write failed, block #",
+				blk + blks, n);
+			info->mssg("flash write failure", response);
+			free(aligned_buf);
+
+			return min(write_blks, (lbaint_t)-1);
+		}
+
+		blks += write_blks;
+		data += n * info->blksz;
+		blkcnt -= n;
+	}
+
+	free(aligned_buf);
+	return blks;
+}
+
 int write_sparse_image(struct sparse_storage *info,
 		       const char *part_name, void *data, char *response)
 {
@@ -152,15 +194,11 @@ int write_sparse_image(struct sparse_storage *info,
 				return -1;
 			}
 
-			blks = info->write(info, blk, blkcnt, data);
-			/* blks might be > blkcnt (eg. NAND bad-blocks) */
-			if (blks < blkcnt) {
-				printf("%s: %s" LBAFU " [" LBAFU "]\n",
-				       __func__, "Write failed, block #",
-				       blk, blks);
-				info->mssg("flash write failure", response);
+			blks = write_sparse_chunk_raw(info, blk, blkcnt,
+						      data, response);
+			if (blks < 0)
 				return -1;
-			}
+
 			blk += blks;
 			bytes_written += ((u64)blkcnt) * info->blksz;
 			total_blocks += chunk_header->chunk_sz;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] lib: sparse: Make CHUNK_TYPE_RAW buffer aligned
  2021-11-15  5:43 [PATCH] lib: sparse: Make CHUNK_TYPE_RAW buffer aligned qianfanguijin
@ 2021-11-15 15:07 ` Sean Anderson
  0 siblings, 0 replies; 6+ messages in thread
From: Sean Anderson @ 2021-11-15 15:07 UTC (permalink / raw)
  To: qianfanguijin, u-boot; +Cc: hs, qianfan Zhao

(This should be [PATCH v3] for those following along at home)

On 11/15/21 12:43 AM, qianfanguijin@qq.com wrote:
> From: qianfan Zhao <qianfanguijin@163.com>
> 
> CHUNK_TYPE_RAW buffer is not aligned, and flash sparse images by
> fastboot will report "Misaligned operation" if DCACHE is enabled.
> 
> Flashing Sparse Image
> CACHE: Misaligned operation at range [84000028, 84001028]
> CACHE: Misaligned operation at range [84001034, 84002034]
> CACHE: Misaligned operation at range [8401104c, 8401304c]
> 
> Fix it
> 
> Signed-off-by: qianfan Zhao <qianfanguijin@163.com>
> ---
>   lib/image-sparse.c | 54 +++++++++++++++++++++++++++++++++++++++-------
>   1 file changed, 46 insertions(+), 8 deletions(-)
> 
> diff --git a/lib/image-sparse.c b/lib/image-sparse.c
> index d80fdbbf58..1143c88a79 100644
> --- a/lib/image-sparse.c
> +++ b/lib/image-sparse.c
> @@ -49,6 +49,48 @@
>   
>   static void default_log(const char *ignored, char *response) {}
>   
> +static lbaint_t write_sparse_chunk_raw(struct sparse_storage *info,
> +				       lbaint_t blk, lbaint_t blkcnt,
> +				       void *data,
> +				       char *response)
> +{
> +	lbaint_t n, write_blks, blks = 0, aligned_buf_blks = 100;
> +	uint32_t *aligned_buf = NULL;
> +
> +	if (CONFIG_IS_ENABLED(SYS_DCACHE_OFF))
> +		return info->write(info, blk, blkcnt, data);

No error message for regular write?

> +
> +	aligned_buf = memalign(ARCH_DMA_MINALIGN, info->blksz * aligned_buf_blks);
> +	if (!aligned_buf) {
> +		info->mssg("Malloc failed for: CHUNK_TYPE_RAW", response);
> +		return -ENOMEM;
> +	}
> +
> +	while (blkcnt > 0) {
> +		n = min(aligned_buf_blks, blkcnt);
> +		memcpy(aligned_buf, data, n * info->blksz);
> +
> +		/* write_blks might be > n due to NAND bad-blocks */
> +		write_blks = info->write(info, blk + blks, n, aligned_buf);
> +		if (write_blks < 0 || write_blks < n) {

n will always be >= 0, so the first condition here does nothing

> +			printf("%s: %s" LBAFU " [" LBAFU "]\n",
> +				__func__, "Write failed, block #",
> +				blk + blks, n);
> +			info->mssg("flash write failure", response);
> +			free(aligned_buf);
> +
> +			return min(write_blks, (lbaint_t)-1);
> +		}
> +
> +		blks += write_blks;
> +		data += n * info->blksz;
> +		blkcnt -= n;
> +	}
> +
> +	free(aligned_buf);
> +	return blks;
> +}
> +
>   int write_sparse_image(struct sparse_storage *info,
>   		       const char *part_name, void *data, char *response)
>   {
> @@ -152,15 +194,11 @@ int write_sparse_image(struct sparse_storage *info,
>   				return -1;
>   			}
>   
> -			blks = info->write(info, blk, blkcnt, data);
> -			/* blks might be > blkcnt (eg. NAND bad-blocks) */
> -			if (blks < blkcnt) {
> -				printf("%s: %s" LBAFU " [" LBAFU "]\n",
> -				       __func__, "Write failed, block #",
> -				       blk, blks);
> -				info->mssg("flash write failure", response);
> +			blks = write_sparse_chunk_raw(info, blk, blkcnt,
> +						      data, response);
> +			if (blks < 0)

This will not catch errors for a short write not using the wrapper above.

--Sean

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] lib: sparse: Make CHUNK_TYPE_RAW buffer aligned
  2021-11-08  2:12   ` qianfan
@ 2021-11-08 14:45     ` Sean Anderson
  0 siblings, 0 replies; 6+ messages in thread
From: Sean Anderson @ 2021-11-08 14:45 UTC (permalink / raw)
  To: qianfan, u-boot; +Cc: hs, qianfan Zhao



On 11/7/21 9:12 PM, qianfan wrote:
> 
> 在 2021/11/5 23:06, Sean Anderson 写道:
>> Hi quanfan,
>>
>> Thanks for the patch. I had something similar in mind.
>>
>> On 11/5/21 1:46 AM, qianfanguijin@qq.com wrote:
>>> From: qianfan Zhao <qianfanguijin@163.com>
>>>
>>> CHUNK_TYPE_RAW buffer is not aligned, and flash sparse images by
>>> fastboot will report "Misaligned operation" if DCACHE is enabled.
>>>
>>> Flashing Sparse Image
>>> CACHE: Misaligned operation at range [84000028, 84001028]
>>> CACHE: Misaligned operation at range [84001034, 84002034]
>>> CACHE: Misaligned operation at range [8401104c, 8401304c]
>>>
>>> Fix it
>>>
>>> Signed-off-by: qianfan Zhao <qianfanguijin@163.com>
>>> ---
>>>   lib/image-sparse.c | 46 +++++++++++++++++++++++++++++++++++++++++++++-
>>>   1 file changed, 45 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/lib/image-sparse.c b/lib/image-sparse.c
>>> index d80fdbbf58..1c621cd685 100644
>>> --- a/lib/image-sparse.c
>>> +++ b/lib/image-sparse.c
>>> @@ -49,6 +49,48 @@
>>>
>>>   static void default_log(const char *ignored, char *response) {}
>>>
>>> +static lbaint_t write_sparse_chunk_raw(struct sparse_storage *info,
>>> +                       lbaint_t blk, lbaint_t blkcnt,
>>> +                       void *data,
>>> +                       char *response)
>>> +{
>>> +#if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
>>
>> Please rewrite this like
>>
>>     if (CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
>>         return info->write(info, blk, blkcnt, data);
>>
>>> +    lbaint_t n, blks = 0, aligned_buf_blks = 100;
>>
>> Can we try allocating info->blksz * blkcnt up front?
>>
>>> +    uint32_t *aligned_buf = NULL;
>>> +
>>> +    while (blkcnt > 0) {
>>> +        aligned_buf = (uint32_t *)
>>> +                   memalign(ARCH_DMA_MINALIGN,
>>> +                        ROUNDUP(
>>> +                        info->blksz * aligned_buf_blks,
>>> +                        ARCH_DMA_MINALIGN));
>>
>> I don't think we need this ROUNDUP. info->blksz is the block size of the
>> underlying storage, which is at least 512. And void pointers don't need
>> to be casted.
>>
>>> +        if (!aligned_buf) {
>>> +            info->mssg("Malloc failed for: CHUNK_TYPE_RAW",
>>> +                   response);
>>> +            return -1;
>>
>> return -ENOMEM;
>>
>> Yes, the rest of the function returns -1, but there is no reason to
>> perpetuate that.
>>
>>> +        }
>>> +
>>> +        n = min(aligned_buf_blks, blkcnt);
>>> +        memcpy(aligned_buf, data, n * info->blksz);
>>> +
>>> +        if (info->write(info, blk + blks, n, aligned_buf) != n) {
>>> +            free(aligned_buf);
>>
>> Can we reuse the buffer instead of allocating/freeing it every loop?
>>
>>> +            return n + blks;
>>> +        }
>>> +
>>> +        free(aligned_buf);
>>> +
>>> +        data += n * info->blksz;
>>> +        blkcnt -= n;
>>> +        blks += n;
>>> +    }
>>> +
>>> +    return blks;
>>> +#else
>>> +    return info->write(info, blk, blkcnt, data);
>>> +#endif
>>> +}
>>> +
>>>   int write_sparse_image(struct sparse_storage *info,
>>>                  const char *part_name, void *data, char *response)
>>>   {
>>> @@ -152,7 +194,9 @@ int write_sparse_image(struct sparse_storage *info,
>>>                   return -1;
>>>               }
>>>
>>> -            blks = info->write(info, blk, blkcnt, data);
>>> +            blks = write_sparse_chunk_raw(info, blk, blkcnt,
>>> +                              data, response);
>>> +
>>>               /* blks might be > blkcnt (eg. NAND bad-blocks) */
>>>               if (blks < blkcnt) {
>>>                   printf("%s: %s" LBAFU " [" LBAFU "]\n",
>>
>> You also need to fix the error handling here. Otherwise you will get
>> tuings like "Write failed, block #4294967295" on out of memory.
> 
> thanks for your's review. I had changed based on yours guide and has a question about this error message.
> 
> What is your's test platform, nand flash? I had tested on emmc platform and no such messages.

write_sparse_chunk_raw has two error conditions: blks < blkcnt, and blks < 0. The latter case will be handled incorrectly.

--Sean

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] lib: sparse: Make CHUNK_TYPE_RAW buffer aligned
  2021-11-05 15:06 ` Sean Anderson
@ 2021-11-08  2:12   ` qianfan
  2021-11-08 14:45     ` Sean Anderson
  0 siblings, 1 reply; 6+ messages in thread
From: qianfan @ 2021-11-08  2:12 UTC (permalink / raw)
  To: Sean Anderson, u-boot; +Cc: hs, qianfan Zhao


在 2021/11/5 23:06, Sean Anderson 写道:
> Hi quanfan,
>
> Thanks for the patch. I had something similar in mind.
>
> On 11/5/21 1:46 AM, qianfanguijin@qq.com wrote:
>> From: qianfan Zhao <qianfanguijin@163.com>
>>
>> CHUNK_TYPE_RAW buffer is not aligned, and flash sparse images by
>> fastboot will report "Misaligned operation" if DCACHE is enabled.
>>
>> Flashing Sparse Image
>> CACHE: Misaligned operation at range [84000028, 84001028]
>> CACHE: Misaligned operation at range [84001034, 84002034]
>> CACHE: Misaligned operation at range [8401104c, 8401304c]
>>
>> Fix it
>>
>> Signed-off-by: qianfan Zhao <qianfanguijin@163.com>
>> ---
>>   lib/image-sparse.c | 46 +++++++++++++++++++++++++++++++++++++++++++++-
>>   1 file changed, 45 insertions(+), 1 deletion(-)
>>
>> diff --git a/lib/image-sparse.c b/lib/image-sparse.c
>> index d80fdbbf58..1c621cd685 100644
>> --- a/lib/image-sparse.c
>> +++ b/lib/image-sparse.c
>> @@ -49,6 +49,48 @@
>>
>>   static void default_log(const char *ignored, char *response) {}
>>
>> +static lbaint_t write_sparse_chunk_raw(struct sparse_storage *info,
>> +                       lbaint_t blk, lbaint_t blkcnt,
>> +                       void *data,
>> +                       char *response)
>> +{
>> +#if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
>
> Please rewrite this like
>
>     if (CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
>         return info->write(info, blk, blkcnt, data);
>
>> +    lbaint_t n, blks = 0, aligned_buf_blks = 100;
>
> Can we try allocating info->blksz * blkcnt up front?
>
>> +    uint32_t *aligned_buf = NULL;
>> +
>> +    while (blkcnt > 0) {
>> +        aligned_buf = (uint32_t *)
>> +                   memalign(ARCH_DMA_MINALIGN,
>> +                        ROUNDUP(
>> +                        info->blksz * aligned_buf_blks,
>> +                        ARCH_DMA_MINALIGN));
>
> I don't think we need this ROUNDUP. info->blksz is the block size of the
> underlying storage, which is at least 512. And void pointers don't need
> to be casted.
>
>> +        if (!aligned_buf) {
>> +            info->mssg("Malloc failed for: CHUNK_TYPE_RAW",
>> +                   response);
>> +            return -1;
>
> return -ENOMEM;
>
> Yes, the rest of the function returns -1, but there is no reason to
> perpetuate that.
>
>> +        }
>> +
>> +        n = min(aligned_buf_blks, blkcnt);
>> +        memcpy(aligned_buf, data, n * info->blksz);
>> +
>> +        if (info->write(info, blk + blks, n, aligned_buf) != n) {
>> +            free(aligned_buf);
>
> Can we reuse the buffer instead of allocating/freeing it every loop?
>
>> +            return n + blks;
>> +        }
>> +
>> +        free(aligned_buf);
>> +
>> +        data += n * info->blksz;
>> +        blkcnt -= n;
>> +        blks += n;
>> +    }
>> +
>> +    return blks;
>> +#else
>> +    return info->write(info, blk, blkcnt, data);
>> +#endif
>> +}
>> +
>>   int write_sparse_image(struct sparse_storage *info,
>>                  const char *part_name, void *data, char *response)
>>   {
>> @@ -152,7 +194,9 @@ int write_sparse_image(struct sparse_storage *info,
>>                   return -1;
>>               }
>>
>> -            blks = info->write(info, blk, blkcnt, data);
>> +            blks = write_sparse_chunk_raw(info, blk, blkcnt,
>> +                              data, response);
>> +
>>               /* blks might be > blkcnt (eg. NAND bad-blocks) */
>>               if (blks < blkcnt) {
>>                   printf("%s: %s" LBAFU " [" LBAFU "]\n",
>
> You also need to fix the error handling here. Otherwise you will get
> tuings like "Write failed, block #4294967295" on out of memory.

thanks for your's review. I had changed based on yours guide and has a 
question about this error message.

What is your's test platform, nand flash? I had tested on emmc platform 
and no such messages.

>
> --Sean


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] lib: sparse: Make CHUNK_TYPE_RAW buffer aligned
  2021-11-05  5:46 qianfanguijin
@ 2021-11-05 15:06 ` Sean Anderson
  2021-11-08  2:12   ` qianfan
  0 siblings, 1 reply; 6+ messages in thread
From: Sean Anderson @ 2021-11-05 15:06 UTC (permalink / raw)
  To: qianfanguijin, u-boot; +Cc: hs, qianfan Zhao

Hi quanfan,

Thanks for the patch. I had something similar in mind.

On 11/5/21 1:46 AM, qianfanguijin@qq.com wrote:
> From: qianfan Zhao <qianfanguijin@163.com>
>
> CHUNK_TYPE_RAW buffer is not aligned, and flash sparse images by
> fastboot will report "Misaligned operation" if DCACHE is enabled.
>
> Flashing Sparse Image
> CACHE: Misaligned operation at range [84000028, 84001028]
> CACHE: Misaligned operation at range [84001034, 84002034]
> CACHE: Misaligned operation at range [8401104c, 8401304c]
>
> Fix it
>
> Signed-off-by: qianfan Zhao <qianfanguijin@163.com>
> ---
>   lib/image-sparse.c | 46 +++++++++++++++++++++++++++++++++++++++++++++-
>   1 file changed, 45 insertions(+), 1 deletion(-)
>
> diff --git a/lib/image-sparse.c b/lib/image-sparse.c
> index d80fdbbf58..1c621cd685 100644
> --- a/lib/image-sparse.c
> +++ b/lib/image-sparse.c
> @@ -49,6 +49,48 @@
>
>   static void default_log(const char *ignored, char *response) {}
>
> +static lbaint_t write_sparse_chunk_raw(struct sparse_storage *info,
> +				       lbaint_t blk, lbaint_t blkcnt,
> +				       void *data,
> +				       char *response)
> +{
> +#if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)

Please rewrite this like

	if (CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
		return info->write(info, blk, blkcnt, data);

> +	lbaint_t n, blks = 0, aligned_buf_blks = 100;

Can we try allocating info->blksz * blkcnt up front?

> +	uint32_t *aligned_buf = NULL;
> +
> +	while (blkcnt > 0) {
> +		aligned_buf = (uint32_t *)
> +				   memalign(ARCH_DMA_MINALIGN,
> +					    ROUNDUP(
> +						info->blksz * aligned_buf_blks,
> +						ARCH_DMA_MINALIGN));

I don't think we need this ROUNDUP. info->blksz is the block size of the
underlying storage, which is at least 512. And void pointers don't need
to be casted.

> +		if (!aligned_buf) {
> +			info->mssg("Malloc failed for: CHUNK_TYPE_RAW",
> +				   response);
> +			return -1;

return -ENOMEM;

Yes, the rest of the function returns -1, but there is no reason to
perpetuate that.

> +		}
> +
> +		n = min(aligned_buf_blks, blkcnt);
> +		memcpy(aligned_buf, data, n * info->blksz);
> +
> +		if (info->write(info, blk + blks, n, aligned_buf) != n) {
> +			free(aligned_buf);

Can we reuse the buffer instead of allocating/freeing it every loop?

> +			return n + blks;
> +		}
> +
> +		free(aligned_buf);
> +
> +		data += n * info->blksz;
> +		blkcnt -= n;
> +		blks += n;
> +	}
> +
> +	return blks;
> +#else
> +	return info->write(info, blk, blkcnt, data);
> +#endif
> +}
> +
>   int write_sparse_image(struct sparse_storage *info,
>   		       const char *part_name, void *data, char *response)
>   {
> @@ -152,7 +194,9 @@ int write_sparse_image(struct sparse_storage *info,
>   				return -1;
>   			}
>
> -			blks = info->write(info, blk, blkcnt, data);
> +			blks = write_sparse_chunk_raw(info, blk, blkcnt,
> +						      data, response);
> +
>   			/* blks might be > blkcnt (eg. NAND bad-blocks) */
>   			if (blks < blkcnt) {
>   				printf("%s: %s" LBAFU " [" LBAFU "]\n",

You also need to fix the error handling here. Otherwise you will get
tuings like "Write failed, block #4294967295" on out of memory.

--Sean

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] lib: sparse: Make CHUNK_TYPE_RAW buffer aligned
@ 2021-11-05  5:46 qianfanguijin
  2021-11-05 15:06 ` Sean Anderson
  0 siblings, 1 reply; 6+ messages in thread
From: qianfanguijin @ 2021-11-05  5:46 UTC (permalink / raw)
  To: u-boot; +Cc: sean.anderson, hs, qianfan Zhao

From: qianfan Zhao <qianfanguijin@163.com>

CHUNK_TYPE_RAW buffer is not aligned, and flash sparse images by
fastboot will report "Misaligned operation" if DCACHE is enabled.

Flashing Sparse Image
CACHE: Misaligned operation at range [84000028, 84001028]
CACHE: Misaligned operation at range [84001034, 84002034]
CACHE: Misaligned operation at range [8401104c, 8401304c]

Fix it

Signed-off-by: qianfan Zhao <qianfanguijin@163.com>
---
 lib/image-sparse.c | 46 +++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 45 insertions(+), 1 deletion(-)

diff --git a/lib/image-sparse.c b/lib/image-sparse.c
index d80fdbbf58..1c621cd685 100644
--- a/lib/image-sparse.c
+++ b/lib/image-sparse.c
@@ -49,6 +49,48 @@
 
 static void default_log(const char *ignored, char *response) {}
 
+static lbaint_t write_sparse_chunk_raw(struct sparse_storage *info,
+				       lbaint_t blk, lbaint_t blkcnt,
+				       void *data,
+				       char *response)
+{
+#if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
+	lbaint_t n, blks = 0, aligned_buf_blks = 100;
+	uint32_t *aligned_buf = NULL;
+
+	while (blkcnt > 0) {
+		aligned_buf = (uint32_t *)
+				   memalign(ARCH_DMA_MINALIGN,
+					    ROUNDUP(
+						info->blksz * aligned_buf_blks,
+						ARCH_DMA_MINALIGN));
+		if (!aligned_buf) {
+			info->mssg("Malloc failed for: CHUNK_TYPE_RAW",
+				   response);
+			return -1;
+		}
+
+		n = min(aligned_buf_blks, blkcnt);
+		memcpy(aligned_buf, data, n * info->blksz);
+
+		if (info->write(info, blk + blks, n, aligned_buf) != n) {
+			free(aligned_buf);
+			return n + blks;
+		}
+
+		free(aligned_buf);
+
+		data += n * info->blksz;
+		blkcnt -= n;
+		blks += n;
+	}
+
+	return blks;
+#else
+	return info->write(info, blk, blkcnt, data);
+#endif
+}
+
 int write_sparse_image(struct sparse_storage *info,
 		       const char *part_name, void *data, char *response)
 {
@@ -152,7 +194,9 @@ int write_sparse_image(struct sparse_storage *info,
 				return -1;
 			}
 
-			blks = info->write(info, blk, blkcnt, data);
+			blks = write_sparse_chunk_raw(info, blk, blkcnt,
+						      data, response);
+
 			/* blks might be > blkcnt (eg. NAND bad-blocks) */
 			if (blks < blkcnt) {
 				printf("%s: %s" LBAFU " [" LBAFU "]\n",
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-11-15 15:08 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-15  5:43 [PATCH] lib: sparse: Make CHUNK_TYPE_RAW buffer aligned qianfanguijin
2021-11-15 15:07 ` Sean Anderson
  -- strict thread matches above, loose matches on Subject: below --
2021-11-05  5:46 qianfanguijin
2021-11-05 15:06 ` Sean Anderson
2021-11-08  2:12   ` qianfan
2021-11-08 14:45     ` Sean Anderson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.