Carl-Daniel Hailfinger | b5b161b | 2010-06-04 19:05:39 +0000 | [diff] [blame] | 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. |
Carl-Daniel Hailfinger | b5b161b | 2010-06-04 19:05:39 +0000 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | /* |
| 17 | * Contains the processor specific flash enables and system settings. |
| 18 | */ |
| 19 | |
| 20 | #include "flash.h" |
Carl-Daniel Hailfinger | 5b997c3 | 2010-07-27 22:41:39 +0000 | [diff] [blame] | 21 | #include "programmer.h" |
Carl-Daniel Hailfinger | b5b161b | 2010-06-04 19:05:39 +0000 | [diff] [blame] | 22 | |
Vladimir 'phcoder' Serbinenko | 5cfc94a | 2010-09-29 23:37:24 +0000 | [diff] [blame] | 23 | #if defined (__MIPSEL__) && defined (__linux) |
| 24 | #include <stdio.h> |
| 25 | #include <string.h> |
| 26 | #include <ctype.h> |
| 27 | |
| 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; |
Carl-Daniel Hailfinger | 9e3a6c4 | 2010-10-08 12:40:09 +0000 | [diff] [blame] | 39 | while (*ptr && isspace((unsigned char)*ptr)) |
Vladimir 'phcoder' Serbinenko | 5cfc94a | 2010-09-29 23:37:24 +0000 | [diff] [blame] | 40 | ptr++; |
| 41 | /* "cpu" part appears only with some Linux versions. */ |
Carl-Daniel Hailfinger | bfa021d | 2011-06-26 11:50:10 +0000 | [diff] [blame] | 42 | if (strncmp(ptr, "cpu", strlen("cpu")) == 0) |
| 43 | ptr += strlen("cpu"); |
Carl-Daniel Hailfinger | 9e3a6c4 | 2010-10-08 12:40:09 +0000 | [diff] [blame] | 44 | while (*ptr && isspace((unsigned char)*ptr)) |
Vladimir 'phcoder' Serbinenko | 5cfc94a | 2010-09-29 23:37:24 +0000 | [diff] [blame] | 45 | ptr++; |
Carl-Daniel Hailfinger | bfa021d | 2011-06-26 11:50:10 +0000 | [diff] [blame] | 46 | if (strncmp(ptr, "model", strlen("model")) != 0) |
Vladimir 'phcoder' Serbinenko | 5cfc94a | 2010-09-29 23:37:24 +0000 | [diff] [blame] | 47 | continue; |
Carl-Daniel Hailfinger | bfa021d | 2011-06-26 11:50:10 +0000 | [diff] [blame] | 48 | ptr += strlen("model"); |
Carl-Daniel Hailfinger | 9e3a6c4 | 2010-10-08 12:40:09 +0000 | [diff] [blame] | 49 | while (*ptr && isspace((unsigned char)*ptr)) |
Vladimir 'phcoder' Serbinenko | 5cfc94a | 2010-09-29 23:37:24 +0000 | [diff] [blame] | 50 | ptr++; |
| 51 | if (*ptr != ':') |
| 52 | continue; |
| 53 | ptr++; |
Carl-Daniel Hailfinger | 9e3a6c4 | 2010-10-08 12:40:09 +0000 | [diff] [blame] | 54 | while (*ptr && isspace((unsigned char)*ptr)) |
Vladimir 'phcoder' Serbinenko | 5cfc94a | 2010-09-29 23:37:24 +0000 | [diff] [blame] | 55 | ptr++; |
Stefan Tauner | 1668770 | 2015-12-25 21:59:45 +0000 | [diff] [blame] | 56 | (void)fclose(cpuinfo); |
Peter Lemenkov | 975b706 | 2012-08-09 21:09:51 +0000 | [diff] [blame] | 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); |
Vladimir 'phcoder' Serbinenko | 5cfc94a | 2010-09-29 23:37:24 +0000 | [diff] [blame] | 59 | } |
Stefan Tauner | 1668770 | 2015-12-25 21:59:45 +0000 | [diff] [blame] | 60 | (void)fclose(cpuinfo); |
Vladimir 'phcoder' Serbinenko | 5cfc94a | 2010-09-29 23:37:24 +0000 | [diff] [blame] | 61 | return 0; |
| 62 | } |
| 63 | #endif |
| 64 | |
Carl-Daniel Hailfinger | b5b161b | 2010-06-04 19:05:39 +0000 | [diff] [blame] | 65 | int processor_flash_enable(void) |
| 66 | { |
Peter Lemenkov | 975b706 | 2012-08-09 21:09:51 +0000 | [diff] [blame] | 67 | /* Default to 1 to catch not implemented architectures. */ |
| 68 | int ret = 1; |
| 69 | |
Vladimir 'phcoder' Serbinenko | 5cfc94a | 2010-09-29 23:37:24 +0000 | [diff] [blame] | 70 | /* FIXME: detect loongson on FreeBSD and OpenBSD as well. */ |
| 71 | #if defined (__MIPSEL__) && defined (__linux) |
| 72 | if (is_loongson()) { |
| 73 | flashbase = 0x1fc00000; |
Peter Lemenkov | 975b706 | 2012-08-09 21:09:51 +0000 | [diff] [blame] | 74 | ret = 0; |
Vladimir 'phcoder' Serbinenko | 5cfc94a | 2010-09-29 23:37:24 +0000 | [diff] [blame] | 75 | } |
Peter Lemenkov | 975b706 | 2012-08-09 21:09:51 +0000 | [diff] [blame] | 76 | #elif defined(__i386__) || defined(__x86_64__) |
| 77 | /* On x86, flash access is not processor specific except on |
| 78 | * AMD Elan SC520, AMD Geode and maybe other SoC-style CPUs. |
| 79 | * FIXME: Move enable_flash_cs5536 and get_flashbase_sc520 here. |
| 80 | */ |
| 81 | ret = 0; |
Vladimir 'phcoder' Serbinenko | 5cfc94a | 2010-09-29 23:37:24 +0000 | [diff] [blame] | 82 | #endif |
Peter Lemenkov | 975b706 | 2012-08-09 21:09:51 +0000 | [diff] [blame] | 83 | return ret; |
Carl-Daniel Hailfinger | b5b161b | 2010-06-04 19:05:39 +0000 | [diff] [blame] | 84 | } |