blob: 7c27ccde0018d9c30554410cf6e20765792089df [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.
Carl-Daniel Hailfingerb5b161b2010-06-04 19:05:39 +000014 */
15
16/*
17 * Contains the processor specific flash enables and system settings.
18 */
19
20#include "flash.h"
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +000021#include "programmer.h"
Carl-Daniel Hailfingerb5b161b2010-06-04 19:05:39 +000022
Vladimir 'phcoder' Serbinenko5cfc94a2010-09-29 23:37:24 +000023#if defined (__MIPSEL__) && defined (__linux)
24#include <stdio.h>
25#include <string.h>
26#include <ctype.h>
27
28static 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 Hailfinger9e3a6c42010-10-08 12:40:09 +000039 while (*ptr && isspace((unsigned char)*ptr))
Vladimir 'phcoder' Serbinenko5cfc94a2010-09-29 23:37:24 +000040 ptr++;
41 /* "cpu" part appears only with some Linux versions. */
Carl-Daniel Hailfingerbfa021d2011-06-26 11:50:10 +000042 if (strncmp(ptr, "cpu", strlen("cpu")) == 0)
43 ptr += strlen("cpu");
Carl-Daniel Hailfinger9e3a6c42010-10-08 12:40:09 +000044 while (*ptr && isspace((unsigned char)*ptr))
Vladimir 'phcoder' Serbinenko5cfc94a2010-09-29 23:37:24 +000045 ptr++;
Carl-Daniel Hailfingerbfa021d2011-06-26 11:50:10 +000046 if (strncmp(ptr, "model", strlen("model")) != 0)
Vladimir 'phcoder' Serbinenko5cfc94a2010-09-29 23:37:24 +000047 continue;
Carl-Daniel Hailfingerbfa021d2011-06-26 11:50:10 +000048 ptr += strlen("model");
Carl-Daniel Hailfinger9e3a6c42010-10-08 12:40:09 +000049 while (*ptr && isspace((unsigned char)*ptr))
Vladimir 'phcoder' Serbinenko5cfc94a2010-09-29 23:37:24 +000050 ptr++;
51 if (*ptr != ':')
52 continue;
53 ptr++;
Carl-Daniel Hailfinger9e3a6c42010-10-08 12:40:09 +000054 while (*ptr && isspace((unsigned char)*ptr))
Vladimir 'phcoder' Serbinenko5cfc94a2010-09-29 23:37:24 +000055 ptr++;
Stefan Tauner16687702015-12-25 21:59:45 +000056 (void)fclose(cpuinfo);
Peter Lemenkov975b7062012-08-09 21:09:51 +000057 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' Serbinenko5cfc94a2010-09-29 23:37:24 +000059 }
Stefan Tauner16687702015-12-25 21:59:45 +000060 (void)fclose(cpuinfo);
Vladimir 'phcoder' Serbinenko5cfc94a2010-09-29 23:37:24 +000061 return 0;
62}
63#endif
64
Carl-Daniel Hailfingerb5b161b2010-06-04 19:05:39 +000065int processor_flash_enable(void)
66{
Peter Lemenkov975b7062012-08-09 21:09:51 +000067 /* Default to 1 to catch not implemented architectures. */
68 int ret = 1;
69
Vladimir 'phcoder' Serbinenko5cfc94a2010-09-29 23:37:24 +000070 /* FIXME: detect loongson on FreeBSD and OpenBSD as well. */
71#if defined (__MIPSEL__) && defined (__linux)
72 if (is_loongson()) {
73 flashbase = 0x1fc00000;
Peter Lemenkov975b7062012-08-09 21:09:51 +000074 ret = 0;
Vladimir 'phcoder' Serbinenko5cfc94a2010-09-29 23:37:24 +000075 }
Peter Lemenkov975b7062012-08-09 21:09:51 +000076#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' Serbinenko5cfc94a2010-09-29 23:37:24 +000082#endif
Peter Lemenkov975b7062012-08-09 21:09:51 +000083 return ret;
Carl-Daniel Hailfingerb5b161b2010-06-04 19:05:39 +000084}