003-raw-mode.patch 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. The downstream Freescale vendor kernel has a patch that allows determining
  2. if raw NAND flash mode is provided via a debugfs file. This is not present
  3. in upstream kernels, but the raw access support was added in the 3.19
  4. kernel, so we will check the kernel version if we can't find the file.
  5. --- a/src/mtd.c
  6. +++ b/src/mtd.c
  7. @@ -34,6 +34,7 @@
  8. #include <errno.h>
  9. #include <sys/types.h>
  10. #include <sys/ioctl.h>
  11. +#include <sys/utsname.h>
  12. #include "mtd.h"
  13. #include "rand.h"
  14. @@ -808,15 +809,27 @@ struct mtd_data *mtd_open(const struct m
  15. md->cfg = *cfg;
  16. /* check if use new raw access mode */
  17. + /* by looking for debugfs from fsl patch */
  18. + md->raw_mode_flag = 0;
  19. fp = fopen("/sys/kernel/debug/gpmi-nand/raw_mode", "r");
  20. if (!fp) {
  21. - md->raw_mode_flag = 0;
  22. - vp(md, "mtd: use legacy raw access mode\n");
  23. + /* fallback to kernel version: raw access added in 3.19 */
  24. + struct utsname uts;
  25. + if (!uname(&uts)) {
  26. + int major = 0, minor = 0;
  27. + sscanf(uts.release, "%d.%d", &major, &minor);
  28. + vp(md, "mtd: Linux %d.%d\n", major, minor);
  29. + if ((major << 8 | minor) > (3 << 8 | 18))
  30. + md->raw_mode_flag = 1;
  31. + }
  32. } else {
  33. fclose(fp);
  34. md->raw_mode_flag = 1;
  35. - vp(md, "mtd: use new bch layout raw access mode\n");
  36. }
  37. + if (md->raw_mode_flag)
  38. + vp(md, "mtd: use new bch layout raw access mode\n");
  39. + else
  40. + vp(md, "mtd: use legacy raw access mode\n");
  41. if (plat_config_data->m_u32UseMultiBootArea) {