ofpart_linksys_ns.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2021 Rafał Miłecki <[email protected]>
  4. */
  5. #include <linux/bcm47xx_nvram.h>
  6. #include <linux/mtd/mtd.h>
  7. #include <linux/mtd/partitions.h>
  8. #include "ofpart_linksys_ns.h"
  9. #define NVRAM_BOOT_PART "bootpartition"
  10. static int ofpart_linksys_ns_bootpartition(void)
  11. {
  12. char buf[4];
  13. int bootpartition;
  14. /* Check CFE environment variable */
  15. if (bcm47xx_nvram_getenv(NVRAM_BOOT_PART, buf, sizeof(buf)) > 0) {
  16. if (!kstrtoint(buf, 0, &bootpartition))
  17. return bootpartition;
  18. pr_warn("Failed to parse %s value \"%s\"\n", NVRAM_BOOT_PART,
  19. buf);
  20. } else {
  21. pr_warn("Failed to get NVRAM \"%s\"\n", NVRAM_BOOT_PART);
  22. }
  23. return 0;
  24. }
  25. int linksys_ns_partitions_post_parse(struct mtd_info *mtd,
  26. struct mtd_partition *parts,
  27. int nr_parts)
  28. {
  29. int bootpartition = ofpart_linksys_ns_bootpartition();
  30. int trx_idx = 0;
  31. int i;
  32. for (i = 0; i < nr_parts; i++) {
  33. if (of_device_is_compatible(parts[i].of_node, "linksys,ns-firmware")) {
  34. if (trx_idx++ == bootpartition)
  35. parts[i].name = "firmware";
  36. else
  37. parts[i].name = "backup";
  38. }
  39. }
  40. return 0;
  41. }