processor_enable.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * This file is part of the flashrom project.
  3. *
  4. * Copyright (C) 2010 Carl-Daniel Hailfinger
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; version 2 of the License.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  18. */
  19. /*
  20. * Contains the processor specific flash enables and system settings.
  21. */
  22. #include "flash.h"
  23. #include "programmer.h"
  24. #if defined (__MIPSEL__) && defined (__linux)
  25. #include <stdio.h>
  26. #include <string.h>
  27. #include <ctype.h>
  28. static int is_loongson(void)
  29. {
  30. FILE *cpuinfo;
  31. cpuinfo = fopen("/proc/cpuinfo", "rb");
  32. if (!cpuinfo)
  33. return 0;
  34. while (!feof(cpuinfo)) {
  35. char line[512], *ptr;
  36. if (fgets(line, sizeof(line), cpuinfo) == NULL)
  37. break;
  38. ptr = line;
  39. while (*ptr && isspace((unsigned char)*ptr))
  40. ptr++;
  41. /* "cpu" part appears only with some Linux versions. */
  42. if (strncmp(ptr, "cpu", strlen("cpu")) == 0)
  43. ptr += strlen("cpu");
  44. while (*ptr && isspace((unsigned char)*ptr))
  45. ptr++;
  46. if (strncmp(ptr, "model", strlen("model")) != 0)
  47. continue;
  48. ptr += strlen("model");
  49. while (*ptr && isspace((unsigned char)*ptr))
  50. ptr++;
  51. if (*ptr != ':')
  52. continue;
  53. ptr++;
  54. while (*ptr && isspace((unsigned char)*ptr))
  55. ptr++;
  56. (void)fclose(cpuinfo);
  57. return (strncmp(ptr, "ICT Loongson-2 V0.3", strlen("ICT Loongson-2 V0.3")) == 0) ||
  58. (strncmp(ptr, "Godson2 V0.3 FPU V0.1", strlen("Godson2 V0.3 FPU V0.1")) == 0);
  59. }
  60. (void)fclose(cpuinfo);
  61. return 0;
  62. }
  63. #endif
  64. int processor_flash_enable(void)
  65. {
  66. /* Default to 1 to catch not implemented architectures. */
  67. int ret = 1;
  68. /* FIXME: detect loongson on FreeBSD and OpenBSD as well. */
  69. #if defined (__MIPSEL__) && defined (__linux)
  70. if (is_loongson()) {
  71. flashbase = 0x1fc00000;
  72. ret = 0;
  73. }
  74. #elif defined(__i386__) || defined(__x86_64__)
  75. /* On x86, flash access is not processor specific except on
  76. * AMD Elan SC520, AMD Geode and maybe other SoC-style CPUs.
  77. * FIXME: Move enable_flash_cs5536 and get_flashbase_sc520 here.
  78. */
  79. ret = 0;
  80. #endif
  81. return ret;
  82. }