031-09-MIPS-BCM47XX-Don-t-try-guessing-NVRAM-size-on-MTD-pa.patch 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. From 40d12172c8a5c2f3fc39642fc564b053575cd000 Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <zajec5@gmail.com>
  3. Date: Wed, 1 Apr 2015 08:23:05 +0200
  4. Subject: [PATCH] MIPS: BCM47XX: Don't try guessing NVRAM size on MTD partition
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. When dealing with whole flash content (bcm47xx_nvram_init_from_mem) we
  9. need to find NVRAM start trying various partition sizes (nvram_sizes).
  10. This is not needed when using MTD as we have direct partition access.
  11. Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
  12. Cc: linux-mips@linux-mips.org
  13. Cc: Hauke Mehrtens <hauke@hauke-m.de>
  14. Patchwork: https://patchwork.linux-mips.org/patch/9652/
  15. Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
  16. ---
  17. arch/mips/bcm47xx/nvram.c | 36 ++++++++++++++----------------------
  18. 1 file changed, 14 insertions(+), 22 deletions(-)
  19. --- a/arch/mips/bcm47xx/nvram.c
  20. +++ b/arch/mips/bcm47xx/nvram.c
  21. @@ -139,36 +139,28 @@ static int nvram_init(void)
  22. struct mtd_info *mtd;
  23. struct nvram_header header;
  24. size_t bytes_read;
  25. - int err, i;
  26. + int err;
  27. mtd = get_mtd_device_nm("nvram");
  28. if (IS_ERR(mtd))
  29. return -ENODEV;
  30. - for (i = 0; i < ARRAY_SIZE(nvram_sizes); i++) {
  31. - loff_t from = mtd->size - nvram_sizes[i];
  32. -
  33. - if (from < 0)
  34. - continue;
  35. + err = mtd_read(mtd, 0, sizeof(header), &bytes_read, (uint8_t *)&header);
  36. + if (!err && header.magic == NVRAM_MAGIC) {
  37. + u8 *dst = (uint8_t *)nvram_buf;
  38. + size_t len = header.len;
  39. +
  40. + if (header.len > NVRAM_SPACE) {
  41. + pr_err("nvram on flash (%i bytes) is bigger than the reserved space in memory, will just copy the first %i bytes\n",
  42. + header.len, NVRAM_SPACE);
  43. + len = NVRAM_SPACE;
  44. + }
  45. - err = mtd_read(mtd, from, sizeof(header), &bytes_read,
  46. - (uint8_t *)&header);
  47. - if (!err && header.magic == NVRAM_MAGIC) {
  48. - u8 *dst = (uint8_t *)nvram_buf;
  49. - size_t len = header.len;
  50. -
  51. - if (header.len > NVRAM_SPACE) {
  52. - pr_err("nvram on flash (%i bytes) is bigger than the reserved space in memory, will just copy the first %i bytes\n",
  53. - header.len, NVRAM_SPACE);
  54. - len = NVRAM_SPACE;
  55. - }
  56. -
  57. - err = mtd_read(mtd, from, len, &bytes_read, dst);
  58. - if (err)
  59. - return err;
  60. + err = mtd_read(mtd, 0, len, &bytes_read, dst);
  61. + if (err)
  62. + return err;
  63. - return 0;
  64. - }
  65. + return 0;
  66. }
  67. #endif