summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Georgi <patrick.georgi@coresystems.de>2010-09-30 17:03:32 +0000
committerPatrick Georgi <pgeorgi@google.com>2010-09-30 17:03:32 +0000
commita9095a95450860e7ea96bb6c21ca4f34e406d3d6 (patch)
treef79ff036266bb09b180f27b3552dd30116a221e4
parent5cfc94a98be9fa2317220c76367fe1792c328461 (diff)
downloadast2050-flashrom-a9095a95450860e7ea96bb6c21ca4f34e406d3d6.zip
ast2050-flashrom-a9095a95450860e7ea96bb6c21ca4f34e406d3d6.tar.gz
Add support for building flashrom against libpayload
This doesn't include changes to the frontend which must be done separately, so this won't work out of the box. This code was tested on hardware. Corresponding to flashrom svn r1184. Signed-off-by: Patrick Georgi <patrick.georgi@coresystems.de> Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
-rw-r--r--flashrom.c4
-rw-r--r--hwaccess.c6
-rw-r--r--hwaccess.h12
-rw-r--r--layout.c2
-rw-r--r--physmap.c41
-rw-r--r--udelay.c14
6 files changed, 74 insertions, 5 deletions
diff --git a/flashrom.c b/flashrom.c
index f722029..0a3e4fe 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -22,9 +22,11 @@
*/
#include <stdio.h>
-#include <fcntl.h>
#include <sys/types.h>
+#ifndef __LIBPAYLOAD__
+#include <fcntl.h>
#include <sys/stat.h>
+#endif
#include <string.h>
#include <stdlib.h>
#include <getopt.h>
diff --git a/hwaccess.c b/hwaccess.c
index 3a61e60..bbb91a6 100644
--- a/hwaccess.c
+++ b/hwaccess.c
@@ -22,9 +22,11 @@
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
-#if !defined (__DJGPP__)
+#if !defined (__DJGPP__) && !defined(__LIBPAYLOAD__)
#include <unistd.h>
#include <fcntl.h>
+#endif
+#if !defined (__DJGPP__)
#include <errno.h>
#endif
#include "flash.h"
@@ -44,7 +46,7 @@ int io_fd;
void get_io_perms(void)
{
-#if defined(__DJGPP__)
+#if defined(__DJGPP__) || defined(__LIBPAYLOAD__)
/* We have full permissions by default. */
return;
#else
diff --git a/hwaccess.h b/hwaccess.h
index 2d17326..45629d2 100644
--- a/hwaccess.h
+++ b/hwaccess.h
@@ -292,7 +292,7 @@ static inline uint32_t inl(uint16_t port)
#endif
#endif
-#if !defined(__DARWIN__) && !defined(__FreeBSD__) && !defined(__DragonFly__)
+#if !defined(__DARWIN__) && !defined(__FreeBSD__) && !defined(__DragonFly__) && !defined(__LIBPAYLOAD__)
typedef struct { uint32_t hi, lo; } msr_t;
msr_t rdmsr(int addr);
int wrmsr(int addr, msr_t msr);
@@ -307,6 +307,16 @@ typedef struct { uint32_t hi, lo; } msr_t;
msr_t freebsd_rdmsr(int addr);
int freebsd_wrmsr(int addr, msr_t msr);
#endif
+#if defined(__LIBPAYLOAD__)
+#include <arch/io.h>
+#include <arch/msr.h>
+typedef struct { uint32_t hi, lo; } msr_t;
+msr_t libpayload_rdmsr(int addr);
+int libpayload_wrmsr(int addr, msr_t msr);
+#undef rdmsr
+#define rdmsr libpayload_rdmsr
+#define wrmsr libpayload_wrmsr
+#endif
#elif defined(__powerpc__) || defined(__powerpc64__) || defined(__ppc__) || defined(__ppc64__)
diff --git a/layout.c b/layout.c
index d65e370..c01e09c 100644
--- a/layout.c
+++ b/layout.c
@@ -134,6 +134,7 @@ int show_id(uint8_t *bios, int size, int force)
}
#endif
+#ifndef __LIBPAYLOAD__
int read_romlayout(char *name)
{
FILE *romlayout;
@@ -181,6 +182,7 @@ int read_romlayout(char *name)
return 0;
}
+#endif
int find_romentry(char *name)
{
diff --git a/physmap.c b/physmap.c
index 7ac8ae0..011c8d1 100644
--- a/physmap.c
+++ b/physmap.c
@@ -28,7 +28,7 @@
#include "flash.h"
/* Do we need any file access or ioctl for physmap or MSR? */
-#if !defined(__DJGPP__)
+#if !defined(__DJGPP__) && !defined(__LIBPAYLOAD__)
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
@@ -104,6 +104,31 @@ void physunmap(void *virt_addr, size_t len)
__dpmi_free_physical_address_mapping(&mi);
}
+#elif defined(__LIBPAYLOAD__)
+#include <arch/virtual.h>
+
+#define MEM_DEV ""
+
+void *sys_physmap(unsigned long phys_addr, size_t len)
+{
+ return (void*)phys_to_virt(phys_addr);
+}
+
+#define sys_physmap_rw_uncached sys_physmap
+#define sys_physmap_ro_cached sys_physmap
+
+void physunmap(void *virt_addr, size_t len)
+{
+}
+
+int setup_cpu_msr(int cpu)
+{
+ return 0;
+}
+
+void cleanup_cpu_msr(void)
+{
+}
#elif defined(__DARWIN__)
#include <DirectIO/darwinio.h>
@@ -453,6 +478,20 @@ void cleanup_cpu_msr(void)
{
// Nothing, yet.
}
+#elif defined(__LIBPAYLOAD__)
+msr_t libpayload_rdmsr(int addr)
+{
+ msr_t msr;
+ unsigned long long val = _rdmsr(addr);
+ msr.lo = val & 0xffffffff;
+ msr.hi = val >> 32;
+ return msr;
+}
+
+int libpayload_wrmsr(int addr, msr_t msr)
+{
+ _wrmsr(addr, msr.lo | ((unsigned long long)msr.hi << 32));
+}
#else
msr_t rdmsr(int addr)
{
diff --git a/udelay.c b/udelay.c
index 981b1bb..153f510 100644
--- a/udelay.c
+++ b/udelay.c
@@ -19,6 +19,8 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#ifndef __LIBPAYLOAD__
+
#include <unistd.h>
#include <sys/time.h>
#include <stdlib.h>
@@ -179,3 +181,15 @@ void internal_delay(int usecs)
}
}
+#else
+
+void myusec_calibrate_delay(void)
+{
+ get_cpu_speed();
+}
+
+void internal_delay(int usecs)
+{
+ udelay(usecs);
+}
+#endif
OpenPOWER on IntegriCloud