0002-Revert-fw_setenv-fix-bug-when-SPI-flash-write-size-s.patch 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. From 35bbc4d8155ed86ca7200e060dad98bdfbce684d Mon Sep 17 00:00:00 2001
  2. From: Stefano Babic <sbabic@denx.de>
  3. Date: Thu, 15 Jun 2023 16:54:46 +0200
  4. Subject: [PATCH] Revert "fw_setenv: fix bug when SPI flash write size !=
  5. sector size"
  6. This reverts commit 44ecc1c216007272a6f99a104a71c9d410969d9e.
  7. mtd writesize was errouneously interpreted as maximum allowed size, but
  8. it is the minimum size. The patch raises performance issues because on
  9. NOR flashes single bytes are written.
  10. Signed-off-by: Stefano Babic <sbabic@denx.de>
  11. Upstream: https://github.com/sbabic/libubootenv/commit/9f17a00ee56dc5cfb1d9b51e6639d67b64cb3309
  12. Signed-off-by: Brandon Maier <brandon.maier@collins.com>
  13. ---
  14. src/uboot_env.c | 29 +++++++++--------------------
  15. 1 file changed, 9 insertions(+), 20 deletions(-)
  16. diff --git a/src/uboot_env.c b/src/uboot_env.c
  17. index c5eefe7..76e2619 100644
  18. --- a/src/uboot_env.c
  19. +++ b/src/uboot_env.c
  20. @@ -712,8 +712,6 @@ static int mtdwrite(struct uboot_flash_env *dev, void *data)
  21. sectors = dev->envsectors ? dev->envsectors : 1;
  22. buf = data;
  23. while (count > 0) {
  24. - int blockcount;
  25. -
  26. erase.start = start;
  27. skip = is_nand_badblock(dev, start);
  28. @@ -744,26 +742,17 @@ static int mtdwrite(struct uboot_flash_env *dev, void *data)
  29. ret =-EIO;
  30. goto devwrite_out;
  31. }
  32. -
  33. - blockcount = blocksize;
  34. -
  35. - /* writesize can be different than the sector size. */
  36. -
  37. - while (blockcount > 0) {
  38. - if (lseek(dev->fd, start, SEEK_SET) < 0) {
  39. - ret =-EIO;
  40. - goto devwrite_out;
  41. - }
  42. - if (write(dev->fd, buf, dev->mtdinfo.writesize) != dev->mtdinfo.writesize) {
  43. - ret =-EIO;
  44. - goto devwrite_out;
  45. - }
  46. -
  47. - blockcount -= dev->mtdinfo.writesize;
  48. - start += dev->mtdinfo.writesize;
  49. - buf += dev->mtdinfo.writesize;
  50. + if (lseek(dev->fd, start, SEEK_SET) < 0) {
  51. + ret =-EIO;
  52. + goto devwrite_out;
  53. + }
  54. + if (write(dev->fd, buf, blocksize) != blocksize) {
  55. + ret =-EIO;
  56. + goto devwrite_out;
  57. }
  58. MTDLOCK(dev, &erase);
  59. + start += dev->sectorsize;
  60. + buf += blocksize;
  61. count -= blocksize;
  62. ret += blocksize;
  63. }
  64. --
  65. 2.41.0