blob: 1361dd5a3c2f2ec5d85981e1f1cc8c425b3eac53 [file] [log] [blame]
Carl-Daniel Hailfingerb5b161b2010-06-04 19:05:39 +00001/*
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 Hailfinger5b997c32010-07-27 22:41:39 +000025#include "programmer.h"
Carl-Daniel Hailfingerb5b161b2010-06-04 19:05:39 +000026
Vladimir 'phcoder' Serbinenko5cfc94a2010-09-29 23:37:24 +000027#if defined (__MIPSEL__) && defined (__linux)
28#include <stdio.h>
29#include <string.h>
30#include <ctype.h>
31
32static 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 Hailfinger9e3a6c42010-10-08 12:40:09 +000043 while (*ptr && isspace((unsigned char)*ptr))
Vladimir 'phcoder' Serbinenko5cfc94a2010-09-29 23:37:24 +000044 ptr++;
45 /* "cpu" part appears only with some Linux versions. */
Carl-Daniel Hailfingerbfa021d2011-06-26 11:50:10 +000046 if (strncmp(ptr, "cpu", strlen("cpu")) == 0)
47 ptr += strlen("cpu");
Carl-Daniel Hailfinger9e3a6c42010-10-08 12:40:09 +000048 while (*ptr && isspace((unsigned char)*ptr))
Vladimir 'phcoder' Serbinenko5cfc94a2010-09-29 23:37:24 +000049 ptr++;
Carl-Daniel Hailfingerbfa021d2011-06-26 11:50:10 +000050 if (strncmp(ptr, "model", strlen("model")) != 0)
Vladimir 'phcoder' Serbinenko5cfc94a2010-09-29 23:37:24 +000051 continue;
Carl-Daniel Hailfingerbfa021d2011-06-26 11:50:10 +000052 ptr += strlen("model");
Carl-Daniel Hailfinger9e3a6c42010-10-08 12:40:09 +000053 while (*ptr && isspace((unsigned char)*ptr))
Vladimir 'phcoder' Serbinenko5cfc94a2010-09-29 23:37:24 +000054 ptr++;
55 if (*ptr != ':')
56 continue;
57 ptr++;
Carl-Daniel Hailfinger9e3a6c42010-10-08 12:40:09 +000058 while (*ptr && isspace((unsigned char)*ptr))
Vladimir 'phcoder' Serbinenko5cfc94a2010-09-29 23:37:24 +000059 ptr++;
60 fclose(cpuinfo);
Peter Lemenkov975b7062012-08-09 21:09:51 +000061 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' Serbinenko5cfc94a2010-09-29 23:37:24 +000063 }
64 fclose(cpuinfo);
65 return 0;
66}
67#endif
68
Carl-Daniel Hailfingerb5b161b2010-06-04 19:05:39 +000069int processor_flash_enable(void)
70{
Peter Lemenkov975b7062012-08-09 21:09:51 +000071 /* Default to 1 to catch not implemented architectures. */
72 int ret = 1;
73
Vladimir 'phcoder' Serbinenko5cfc94a2010-09-29 23:37:24 +000074 /* FIXME: detect loongson on FreeBSD and OpenBSD as well. */
75#if defined (__MIPSEL__) && defined (__linux)
76 if (is_loongson()) {
77 flashbase = 0x1fc00000;
Peter Lemenkov975b7062012-08-09 21:09:51 +000078 ret = 0;
Vladimir 'phcoder' Serbinenko5cfc94a2010-09-29 23:37:24 +000079 }
Peter Lemenkov975b7062012-08-09 21:09:51 +000080#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' Serbinenko5cfc94a2010-09-29 23:37:24 +000086#endif
Peter Lemenkov975b7062012-08-09 21:09:51 +000087 return ret;
Carl-Daniel Hailfingerb5b161b2010-06-04 19:05:39 +000088}