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