This is experimental patch
Download fresh flashrom sources to payloads/flashrom dir.
try running "make payload"

currently only writting to flash is supported
writes rom image from usb flash drive to mainboard flash

if you don't have a backup chip this may brick your board
any error will halt the system

Signed-off-by: Tadas Slotkus <devtadas@gmail.com>

Index: flash.h
===================================================================
--- flash.h	(revision 1357)
+++ flash.h	(working copy)
@@ -32,7 +32,11 @@
 #undef min
 #undef max
 #endif
-
+#ifdef __LIBPAYLOAD__
+#undef __linux__
+#define fprintf(stream, ...) printf(__VA_ARGS__)
+#define vfprintf(output_type, fmt, ap) vprintf(fmt, ap)
+#endif
 #define ERROR_PTR ((void*)-1)
 
 /* Error codes */
@@ -249,6 +253,7 @@
 
 /* cli_classic.c */
 int cli_classic(int argc, char *argv[]);
+int cli_payload(int argc, char *argv[]);
 
 /* layout.c */
 int read_romlayout(char *name);
Index: cli_output.c
===================================================================
--- cli_output.c	(revision 1357)
+++ cli_output.c	(working copy)
@@ -47,6 +47,8 @@
 	va_start(ap, fmt);
 	ret = vfprintf(output_type, fmt, ap);
 	va_end(ap);
+#ifndef __LIBPAYLOAD__
 	fflush(output_type);
+#endif
 	return ret;
 }
Index: Makefile
===================================================================
--- Makefile	(revision 1357)
+++ Makefile	(working copy)
@@ -30,8 +30,9 @@
 EXPORTDIR ?= .
 AR      ?= ar
 RANLIB  ?= ranlib
+FILO_DIR = ../filo/
 
-WARNERROR ?= yes
+WARNERROR ?= no
 
 ifeq ($(WARNERROR), yes)
 CFLAGS += -Werror
@@ -85,10 +86,11 @@
 endif
 
 ifeq ($(OS_ARCH), libpayload)
-CC:=CC=i386-elf-gcc lpgcc
-AR:=i386-elf-ar
-RANLIB:=i386-elf-ranlib
+CC:=../libpayload/install/libpayload/bin/lpgcc
+AR_ARCH = --target=elf32-i386
+RANLIB_ARCH = --target=elf32-i386
 CPPFLAGS += -DSTANDALONE
+CPPFLAGS += -I$(FILO_DIR)include -I$(FILO_DIR)i386/include -I$(FILO_DIR)build
 ifeq ($(CONFIG_DUMMY), yes)
 UNSUPPORTED_FEATURES += CONFIG_DUMMY=yes
 else
@@ -126,6 +128,11 @@
 
 CLI_OBJS = flashrom.o cli_classic.o cli_output.o print.o
 
+include $(FILO_DIR).config
+TARGETS-y :=
+include $(FILO_DIR)drivers/Makefile.inc $(FILO_DIR)fs/Makefile.inc 
+FILO_OBJS = $(addprefix $(FILO_DIR), $(TARGETS-y)) $(FILO_DIR)main/strtox.o
+
 PROGRAMMER_OBJS = udelay.o programmer.o
 
 all: pciutils features $(PROGRAM)$(EXEC_SUFFIX)
@@ -361,7 +368,9 @@
 # FIXME There needs to be a better way to do this
 LIBS += ../libpci/lib/libpci.a
 else
+ifneq ($(OS_ARCH), libpayload)
 LIBS += -lpci
+endif
 ifeq ($(OS_ARCH), OpenBSD)
 # For (i386|amd64)_iopl(2).
 LIBS += -l$(shell uname -m)
@@ -381,15 +390,25 @@
 FEATURE_LIBS += $(shell LC_ALL=C grep -q "NEEDLIBZ := yes" .libdeps && printf "%s" "-lz")
 
 LIBFLASHROM_OBJS = $(CHIP_OBJS) $(PROGRAMMER_OBJS) $(LIB_OBJS)
-OBJS = $(CLI_OBJS) $(LIBFLASHROM_OBJS) 
+OBJS = $(CLI_OBJS) $(LIBFLASHROM_OBJS)
 
+ifeq ($(OS_ARCH), libpayload)
+OBJS += $(FILO_OBJS) payload.o
+endif
+
 $(PROGRAM)$(EXEC_SUFFIX): $(OBJS)
 	$(CC) $(LDFLAGS) -o $(PROGRAM)$(EXEC_SUFFIX) $(OBJS) $(FEATURE_LIBS) $(LIBS)
 
 libflashrom.a: $(LIBFLASHROM_OBJS)
-	$(AR) rcs $@ $^
-	$(RANLIB) $@
+	$(AR) rcs $@ $^ $(AR_ARCH)
+	$(RANLIB) $@ $(AR_ARCH)
 
+payload:
+	make OS_ARCH=libpayload
+
+payload.a:
+	make OS_ARCH=libpayload libflashrom.a
+
 # TAROPTIONS reduces information leakage from the packager's system.
 # If other tar programs support command line arguments for setting uid/gid of
 # stored files, they can be handled here as well.
@@ -402,7 +421,9 @@
 # This includes all frontends and libflashrom.
 # We don't use EXEC_SUFFIX here because we want to clean everything.
 clean:
-	rm -f $(PROGRAM) $(PROGRAM).exe libflashrom.a *.o *.d
+	rm -f $(PROGRAM) $(PROGRAM).exe libflashrom.a *.o *.d .*.tmp
+	find $(FILO_DIR) -path "../*.o" -delete
+	find $(FILO_DIR) -path "../*.d" -delete
 
 distclean: clean
 	rm -f .features .libdeps
@@ -519,6 +540,6 @@
 djgpp-dos: clean
 	make CC=i586-pc-msdosdjgpp-gcc STRIP=i586-pc-msdosdjgpp-strip WARNERROR=no OS_ARCH=DOS
 
-.PHONY: all clean distclean compiler pciutils features export tarball dos featuresavailable
+.PHONY: all clean distclean compiler pciutils features export tarball dos featuresavailable payload payload.a
 
 -include $(OBJS:.o=.d)
Index: cli_classic.c
===================================================================
--- cli_classic.c	(revision 1357)
+++ cli_classic.c	(working copy)
@@ -22,8 +22,10 @@
  */
 
 #include <stdio.h>
+#ifndef __LIBPAYLOAD__
 #include <fcntl.h>
 #include <sys/stat.h>
+#endif
 #include <string.h>
 #include <stdlib.h>
 #include <getopt.h>
@@ -150,12 +152,14 @@
 	if (selfcheck())
 		exit(1);
 
+#ifndef __LIBPAYLOAD__
 	setbuf(stdout, NULL);
+#endif
 	/* FIXME: Delay all operation_specified checks until after command
 	 * line parsing to allow --help overriding everything else.
 	 */
 	while ((opt = getopt_long(argc, argv, optstring,
-				  long_options, &option_index)) != EOF) {
+				  long_options, &option_index)) != -1) {
 		switch (opt) {
 		case 'r':
 			if (++operation_specified > 1) {
Index: layout.c
===================================================================
--- layout.c	(revision 1357)
+++ layout.c	(working copy)
@@ -136,9 +136,9 @@
 }
 #endif
 
-#ifndef __LIBPAYLOAD__
 int read_romlayout(char *name)
 {
+#ifndef __LIBPAYLOAD__
 	FILE *romlayout;
 	char tempstr[256];
 	int i;
@@ -191,8 +191,10 @@
 	fclose(romlayout);
 
 	return 0;
+#else
+	return -1;
+#endif
 }
-#endif
 
 int find_romentry(char *name)
 {
Index: payload.c
===================================================================
--- payload.c	(revision 0)
+++ payload.c	(revision 0)
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2011 Tadas Slotkus
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ */
+
+#include "fs.h"
+#define LINE_SIZE	40
+
+int cli_classic(int argc, char *argv[]);
+
+int cli_payload(int argc, char *argv[])
+{
+	usb_initialize();
+	while (havechar())
+		getchar();
+
+	char *argt[8], line[LINE_SIZE], lineb[LINE_SIZE];
+	memset(line, 0, LINE_SIZE);
+	//set a predefined line
+	strcpy(line + 1, "-w uda1:/coreboot.rom\0");
+
+	while (1) {
+		argc = 0;
+		printf("\nEnter cmd line args like: -w uda1:/coreboot.rom\n");
+		strcpy(line + getline(line + 1, LINE_SIZE - 1) + 1, "\0\0");
+		memcpy(lineb, line, LINE_SIZE);
+		argt[argc++] = strtok(line, " ");
+		while (((argt[argc] = strtok(NULL, " ")) < (line + LINE_SIZE)) \
+				&& (strlen(argt[argc]) > 0))
+			argc++;
+
+#if 0	//debug fishing args from line
+		int i;
+		printf("\ngot args:\n");
+		for (i = 0; i < argc; i++)
+			printf("%d:%s|\n", i, argt[i]);
+		printf("\n");
+#endif
+		if (!file_open(argt[2]))// TODO: this needs checking which argt is actually filename
+			printf("\nfile not found\n");
+		else
+			cli_classic(argc, argt);
+		memcpy(line, lineb, LINE_SIZE);
+	}
+	return 0;
+}
+
+int read_buf_from_file(unsigned char *buf, unsigned long size, char *fname)
+{
+	if (!file_open(fname)){
+		perror(fname);
+		return 1;
+	}
+	file_seek(0);
+	printf("\nread %d bytes\n", file_read(buf, size));
+	file_close();
+	return 0;
+}
+
+void print_a_completion (char *name)
+{
+	// Nothing yet.
+}
+
Index: nicintel.c
===================================================================
--- nicintel.c	(revision 1357)
+++ nicintel.c	(working copy)
@@ -23,12 +23,14 @@
 #include "flash.h"
 #include "programmer.h"
 
+#define PCI_VENDOR_ID_INTEL 0x8086
+
 uint8_t *nicintel_bar;
 uint8_t *nicintel_control_bar;
 
 const struct pcidev_status nics_intel[] = {
-	{PCI_VENDOR_ID_INTEL, 0x1209, NT, "Intel", "8255xER/82551IT Fast Ethernet Controller"},
-	{PCI_VENDOR_ID_INTEL, 0x1229, NT, "Intel", "82557/8/9/0/1 Ethernet Pro 100"},
+	{0x8086, 0x1209, NT, "Intel", "8255xER/82551IT Fast Ethernet Controller"},
+	{0x8086, 0x1229, NT, "Intel", "82557/8/9/0/1 Ethernet Pro 100"},
 
 	{},
 };
Index: flashrom.c
===================================================================
--- flashrom.c	(revision 1357)
+++ flashrom.c	(working copy)
@@ -1218,6 +1218,7 @@
 	return ret;
 }
 
+#ifndef __LIBPAYLOAD__
 int read_buf_from_file(unsigned char *buf, unsigned long size, const char *filename)
 {
 	unsigned long numbytes;
@@ -1250,9 +1251,11 @@
 	}
 	return 0;
 }
+#endif
 
 int write_buf_to_file(unsigned char *buf, unsigned long size, const char *filename)
 {
+#ifndef __LIBPAYLOAD__
 	unsigned long numbytes;
 	FILE *image;
 
@@ -1272,6 +1275,7 @@
 			 filename);
 		return 1;
 	}
+#endif
 	return 0;
 }
 
@@ -1784,7 +1788,11 @@
 
 int main(int argc, char *argv[])
 {
+#ifdef __LIBPAYLOAD__
+	return cli_payload(argc, argv);
+#else
 	return cli_classic(argc, argv);
+#endif
 }
 
 /* FIXME: This function signature needs to be improved once doit() has a better
