All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH 0/5 v2] sandbox: spi/sf emulation
@ 2012-01-31 19:53 Mike Frysinger
  2012-01-31 19:53 ` [U-Boot] [PATCH 1/5 v2] sandbox: add lseek helper Mike Frysinger
                   ` (4 more replies)
  0 siblings, 5 replies; 11+ messages in thread
From: Mike Frysinger @ 2012-01-31 19:53 UTC (permalink / raw)
  To: u-boot

Should address the feedback posted by Simon.

Mike Frysinger (5):
  sandbox: add lseek helper
  sandbox: add getopt support
  sandbox: SPI emulation bus
  sandbox: new SPI flash driver
  sandbox: enable new spi/sf layers

 arch/sandbox/cpu/os.c          |   26 +++
 arch/sandbox/cpu/start.c       |   24 +++
 arch/sandbox/include/asm/spi.h |   48 +++++
 drivers/mtd/spi/Makefile       |    1 +
 drivers/mtd/spi/sandbox.c      |  386 ++++++++++++++++++++++++++++++++++++++++
 drivers/spi/Makefile           |    1 +
 drivers/spi/sandbox_spi.c      |  203 +++++++++++++++++++++
 include/configs/sandbox.h      |    7 +
 include/os.h                   |   17 ++
 9 files changed, 713 insertions(+), 0 deletions(-)
 create mode 100644 arch/sandbox/include/asm/spi.h
 create mode 100644 drivers/mtd/spi/sandbox.c
 create mode 100644 drivers/spi/sandbox_spi.c

-- 
1.7.8.4

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [U-Boot] [PATCH 1/5 v2] sandbox: add lseek helper
  2012-01-31 19:53 [U-Boot] [PATCH 0/5 v2] sandbox: spi/sf emulation Mike Frysinger
@ 2012-01-31 19:53 ` Mike Frysinger
  2012-02-01 23:37   ` Simon Glass
  2012-02-03 11:26   ` [U-Boot] [PATCH 1/5 v2.1] " Mike Frysinger
  2012-01-31 19:53 ` [U-Boot] [PATCH 2/5 v2] sandbox: add getopt support Mike Frysinger
                   ` (3 subsequent siblings)
  4 siblings, 2 replies; 11+ messages in thread
From: Mike Frysinger @ 2012-01-31 19:53 UTC (permalink / raw)
  To: u-boot

Follow up patches want to be able to seek fd's.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
 arch/sandbox/cpu/os.c |   13 +++++++++++++
 include/os.h          |   15 +++++++++++++++
 2 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c
index 093e7dc..13331d2 100644
--- a/arch/sandbox/cpu/os.c
+++ b/arch/sandbox/cpu/os.c
@@ -45,6 +45,19 @@ ssize_t os_write(int fd, const void *buf, size_t count)
 	return write(fd, buf, count);
 }
 
+off_t os_lseek(int fd, off_t offset, int whence)
+{
+	if (whence == OS_SEEK_SET)
+		whence = SEEK_SET;
+	else if (whence == OS_SEEK_CUR)
+		whence = SEEK_CUR;
+	else if (whence == OS_SEEK_END)
+		whence = SEEK_END;
+	else
+		printf("%s: invalid whence value %i\n", __func__, whence);
+	return lseek(fd, offset, whence);
+}
+
 int os_open(const char *pathname, int flags)
 {
 	return open(pathname, flags);
diff --git a/include/os.h b/include/os.h
index c17a8a5..11017b7 100644
--- a/include/os.h
+++ b/include/os.h
@@ -49,6 +49,21 @@ ssize_t os_read(int fd, void *buf, size_t count);
 ssize_t os_write(int fd, const void *buf, size_t count);
 
 /**
+ * Access to the OS lseek() system call
+ *
+ * \param fd	File descriptor as returned by os_open()
+ * \param offset	File offset (based on whence)
+ * \param whence	Position offset is relative to (see below)
+ * \return new file offset
+ */
+off_t os_lseek(int fd, off_t offset, int whence);
+
+/* Defines for "whence" in os_lseek() */
+#define OS_SEEK_SET	0
+#define OS_SEEK_CUR	0
+#define OS_SEEK_END	0
+
+/**
  * Access to the OS open() system call
  *
  * \param pathname	Pathname of file to open
-- 
1.7.8.4

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [U-Boot] [PATCH 2/5 v2] sandbox: add getopt support
  2012-01-31 19:53 [U-Boot] [PATCH 0/5 v2] sandbox: spi/sf emulation Mike Frysinger
  2012-01-31 19:53 ` [U-Boot] [PATCH 1/5 v2] sandbox: add lseek helper Mike Frysinger
@ 2012-01-31 19:53 ` Mike Frysinger
  2012-01-31 19:53 ` [U-Boot] [PATCH 3/5 v2] sandbox: SPI emulation bus Mike Frysinger
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 11+ messages in thread
From: Mike Frysinger @ 2012-01-31 19:53 UTC (permalink / raw)
  To: u-boot

Note: just a PoC that the current SPI flash code is based on.
Not meant to reject the getopt code Simon posted.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
 arch/sandbox/cpu/os.c    |   13 +++++++++++++
 arch/sandbox/cpu/start.c |   24 ++++++++++++++++++++++++
 include/os.h             |    2 ++
 3 files changed, 39 insertions(+), 0 deletions(-)

diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c
index 13331d2..f7ba1fa 100644
--- a/arch/sandbox/cpu/os.c
+++ b/arch/sandbox/cpu/os.c
@@ -22,6 +22,7 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <stdlib.h>
+#include <string.h>
 #include <termios.h>
 #include <time.h>
 #include <unistd.h>
@@ -135,3 +136,15 @@ u64 os_get_nsec(void)
 	return tv.tv_sec * 1000000000ULL + tv.tv_usec * 1000;
 #endif
 }
+
+extern char **sb_argv;
+const char *os_getopt(const char *name, int has_arg)
+{
+	size_t i;
+
+	for (i = 0; sb_argv[i]; ++i)
+		if (!strcmp(sb_argv[i], name))
+			return sb_argv[i + !!has_arg];
+
+	return NULL;
+}
diff --git a/arch/sandbox/cpu/start.c b/arch/sandbox/cpu/start.c
index a429e29..3508a35 100644
--- a/arch/sandbox/cpu/start.c
+++ b/arch/sandbox/cpu/start.c
@@ -20,9 +20,33 @@
  */
 
 #include <common.h>
+#include <os.h>
+
+char **sb_argv;
+
+static const char usage[] =
+	"Usage: u-boot [options]\n"
+	"\n"
+	"Options: (note: not all options may be available)\n"
+	" -h, --help               this message (imagine that)\n"
+#ifdef CONFIG_SANDBOX_SPI
+	" --spi-<bus>-<cs> <spec>  connect client to spi <bus> on <cs>\n"
+# ifdef CONFIG_SPI_FLASH
+	"   spec: sf:<file>        treat <file> as spi flash\n"
+# endif
+#endif
+;
 
 int main(int argc, char *argv[])
 {
+	/* Save the argv for people to access */
+	sb_argv = argv;
+
+	if (os_getopt("-h", 0) || os_getopt("--help", 0)) {
+		serial_puts(usage);
+		return 0;
+	}
+
 	/*
 	 * Do pre- and post-relocation init, then start up U-Boot. This will
 	 * never return.
diff --git a/include/os.h b/include/os.h
index 11017b7..565b936 100644
--- a/include/os.h
+++ b/include/os.h
@@ -117,4 +117,6 @@ void os_usleep(unsigned long usec);
  */
 u64 os_get_nsec(void);
 
+const char *os_getopt(const char *name, int has_arg);
+
 #endif
-- 
1.7.8.4

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [U-Boot] [PATCH 3/5 v2] sandbox: SPI emulation bus
  2012-01-31 19:53 [U-Boot] [PATCH 0/5 v2] sandbox: spi/sf emulation Mike Frysinger
  2012-01-31 19:53 ` [U-Boot] [PATCH 1/5 v2] sandbox: add lseek helper Mike Frysinger
  2012-01-31 19:53 ` [U-Boot] [PATCH 2/5 v2] sandbox: add getopt support Mike Frysinger
@ 2012-01-31 19:53 ` Mike Frysinger
  2012-01-31 19:53 ` [U-Boot] [PATCH 4/5 v2] sandbox: new SPI flash driver Mike Frysinger
  2012-01-31 19:53 ` [U-Boot] [PATCH 5/5 v2] sandbox: enable new spi/sf layers Mike Frysinger
  4 siblings, 0 replies; 11+ messages in thread
From: Mike Frysinger @ 2012-01-31 19:53 UTC (permalink / raw)
  To: u-boot

This adds a SPI framework for people to hook up simulated SPI clients.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
 arch/sandbox/include/asm/spi.h |   48 ++++++++++
 drivers/spi/Makefile           |    1 +
 drivers/spi/sandbox_spi.c      |  198 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 247 insertions(+), 0 deletions(-)
 create mode 100644 arch/sandbox/include/asm/spi.h
 create mode 100644 drivers/spi/sandbox_spi.c

diff --git a/arch/sandbox/include/asm/spi.h b/arch/sandbox/include/asm/spi.h
new file mode 100644
index 0000000..8de19c4
--- /dev/null
+++ b/arch/sandbox/include/asm/spi.h
@@ -0,0 +1,48 @@
+/*
+ * Simulate a SPI port and clients
+ *
+ * Copyright (c) 2011-2012 The Chromium OS Authors.
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * Licensed under the GPL-2 or later.
+ */
+
+#ifndef __ASM_SPI_H__
+#define __ASM_SPI_H__
+
+#include <linux/types.h>
+
+/*
+ * The interface between the SPI bus and the SPI client.  The bus will
+ * instantiate a client, and that then call into it via these entry
+ * points.  These should be enough for the client to emulate the SPI
+ * device just like the real hardware.
+ */
+struct sb_spi_emu_ops {
+	/* The bus wants to instantiate a new client, so setup everything */
+	int (*setup)(void **priv, const char *spec);
+	/* The bus is done with us, so break things down */
+	void (*free)(void *priv);
+	/* The CS has been "activated" -- we won't worry about low/high */
+	void (*cs_activate)(void *priv);
+	/* The CS has been "deactivated" -- we won't worry about low/high */
+	void (*cs_deactivate)(void *priv);
+	/* The client is rx-ing bytes from the bus, so it should tx some */
+	int (*xfer)(void *priv, const u8 *rx, u8 *tx, uint bytes);
+};
+
+/*
+ * There are times when the data lines are allowed to tristate.  What
+ * is actually sensed on the line depends on the hardware.  It could
+ * always be 0xFF/0x00 (if there are pull ups/downs), or things could
+ * float and so we'd get garbage back.  This func encapsulates that
+ * scenario so we can worry about the details here.
+ */
+static inline void sb_spi_tristate(u8 *buf, uint len)
+{
+	/* XXX: make this into a user config option ? */
+	memset(buf, 0xff, len);
+}
+
+#endif
diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile
index c967d87..d80ff8b 100644
--- a/drivers/spi/Makefile
+++ b/drivers/spi/Makefile
@@ -40,6 +40,7 @@ COBJS-$(CONFIG_MXC_SPI) += mxc_spi.o
 COBJS-$(CONFIG_MXS_SPI) += mxs_spi.o
 COBJS-$(CONFIG_OC_TINY_SPI) += oc_tiny_spi.o
 COBJS-$(CONFIG_OMAP3_SPI) += omap3_spi.o
+COBJS-$(CONFIG_SANDBOX_SPI) += sandbox_spi.o
 COBJS-$(CONFIG_SOFT_SPI) += soft_spi.o
 COBJS-$(CONFIG_SH_SPI) += sh_spi.o
 COBJS-$(CONFIG_FSL_ESPI) += fsl_espi.o
diff --git a/drivers/spi/sandbox_spi.c b/drivers/spi/sandbox_spi.c
new file mode 100644
index 0000000..d0cba76
--- /dev/null
+++ b/drivers/spi/sandbox_spi.c
@@ -0,0 +1,198 @@
+/*
+ * Simulate a SPI port
+ *
+ * Copyright (c) 2011-2012 The Chromium OS Authors.
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * Licensed under the GPL-2 or later.
+ */
+
+#include <common.h>
+#include <malloc.h>
+#include <spi.h>
+#include <os.h>
+
+#include <asm/spi.h>
+
+#ifndef CONFIG_SPI_IDLE_VAL
+# define CONFIG_SPI_IDLE_VAL 0xFF
+#endif
+
+struct sb_spi_slave {
+	struct spi_slave slave;
+	const char *spec;
+	const struct sb_spi_emu_ops *ops;
+	void *priv;
+};
+
+#define to_sb_spi_slave(s) container_of(s, struct sb_spi_slave, slave)
+
+static const char *sb_lookup_arg(unsigned int bus, unsigned int cs)
+{
+	char sf_arg[20];
+	sprintf(sf_arg, "--spi-%u-%u", bus, cs);
+	return os_getopt(sf_arg, 1);
+}
+
+static const struct {
+	const char *spec;
+	const struct sb_spi_emu_ops *ops;
+} sb_emu_map[] = {
+};
+
+static int sb_parse_type(struct sb_spi_slave *sss)
+{
+	size_t i;
+
+	for (i = 0; i < ARRAY_SIZE(sb_emu_map); ++i) {
+		size_t len = strlen(sb_emu_map[i].spec);
+		const char *sub_spec = sss->spec + len;
+
+		sss->ops = sb_emu_map[i].ops;
+		if (!memcmp(sss->spec, sb_emu_map[i].spec, len) &&
+		    sss->spec[len] == ':')
+			return sss->ops->setup(&sss->priv, sub_spec + 1);
+	}
+
+	return 1;
+}
+
+int spi_cs_is_valid(unsigned int bus, unsigned int cs)
+{
+	return sb_lookup_arg(bus, cs) ? 1 : 0;
+}
+
+void spi_cs_activate(struct spi_slave *slave)
+{
+	struct sb_spi_slave *sss = to_sb_spi_slave(slave);
+
+	debug("sb_spi: activating CS\n");
+	if (sss->ops->cs_activate)
+		sss->ops->cs_activate(sss->priv);
+}
+
+void spi_cs_deactivate(struct spi_slave *slave)
+{
+	struct sb_spi_slave *sss = to_sb_spi_slave(slave);
+
+	debug("sb_spi: deactivating CS\n");
+	if (sss->ops->cs_deactivate)
+		sss->ops->cs_deactivate(sss->priv);
+}
+
+void spi_init(void)
+{
+}
+
+void spi_set_speed(struct spi_slave *slave, uint hz)
+{
+}
+
+struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
+		unsigned int max_hz, unsigned int mode)
+{
+	struct sb_spi_slave *sss;
+
+	if (!spi_cs_is_valid(bus, cs))
+		return NULL;
+
+	sss = malloc(sizeof(*sss));
+	if (!sss)
+		return NULL;
+
+	sss->spec = sb_lookup_arg(bus, cs);
+	if (sb_parse_type(sss)) {
+		free(sss);
+		printf("sb_spi: unable to locate a slave client\n");
+		return NULL;
+	}
+
+	return &sss->slave;
+}
+
+void spi_free_slave(struct spi_slave *slave)
+{
+	struct sb_spi_slave *sss = to_sb_spi_slave(slave);
+
+	debug("sb_spi: releasing slave\n");
+
+	if (sss->ops->free)
+		sss->ops->free(sss->priv);
+
+	free(sss);
+}
+
+static int spi_bus_claim_cnt;
+
+int spi_claim_bus(struct spi_slave *slave)
+{
+	if (spi_bus_claim_cnt++)
+		printf("sb_spi: error: bus already claimed!\n");
+	return 0;
+}
+
+void spi_release_bus(struct spi_slave *slave)
+{
+	if (--spi_bus_claim_cnt)
+		printf("sb_spi: error: bus freed too often!\n");
+}
+
+int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,
+		void *din, unsigned long flags)
+{
+	struct sb_spi_slave *sss = to_sb_spi_slave(slave);
+	uint bytes = bitlen / 8, i;
+	int ret = 0;
+	u8 *tx = (void *)dout, *rx = din;
+
+	if (bitlen == 0)
+		goto done;
+
+	/* we can only do 8 bit transfers */
+	if (bitlen % 8) {
+		printf("sb_spi: xfer: invalid bitlen size %u; needs to be 8bit\n",
+			bitlen);
+		flags |= SPI_XFER_END;
+		goto done;
+	}
+
+	if (flags & SPI_XFER_BEGIN)
+		spi_cs_activate(slave);
+
+	/* make sure rx/tx buffers are full so clients can assume */
+	if (!tx) {
+		debug("sb_spi: xfer: auto-allocating tx scratch buffer\n");
+		tx = malloc(bytes);
+		if (tx)
+			memset(tx, CONFIG_SPI_IDLE_VAL, bytes);
+	}
+	if (!rx) {
+		debug("sb_spi: xfer: auto-allocating rx scratch buffer\n");
+		rx = malloc(bytes);
+	}
+	if (tx && rx) {
+		debug("sb_spi: xfer: bytes = %u\n tx:", bytes);
+		for (i = 0; i < bytes; ++i)
+			debug(" %u:%02x", i, tx[i]);
+		debug("\n");
+
+		ret = sss->ops->xfer(sss->priv, tx, rx, bytes);
+
+		debug("sb_spi: xfer: got back %i (that's %s)\n rx:",
+			ret, ret ? "bad" : "good");
+		for (i = 0; i < bytes; ++i)
+			debug(" %u:%02x", i, rx[i]);
+		debug("\n");
+	}
+	if (tx != dout)
+		free(tx);
+	if (rx != din)
+		free(rx);
+
+ done:
+	if (flags & SPI_XFER_END)
+		spi_cs_deactivate(slave);
+
+	return ret;
+}
-- 
1.7.8.4

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [U-Boot] [PATCH 4/5 v2] sandbox: new SPI flash driver
  2012-01-31 19:53 [U-Boot] [PATCH 0/5 v2] sandbox: spi/sf emulation Mike Frysinger
                   ` (2 preceding siblings ...)
  2012-01-31 19:53 ` [U-Boot] [PATCH 3/5 v2] sandbox: SPI emulation bus Mike Frysinger
@ 2012-01-31 19:53 ` Mike Frysinger
  2012-01-31 19:53 ` [U-Boot] [PATCH 5/5 v2] sandbox: enable new spi/sf layers Mike Frysinger
  4 siblings, 0 replies; 11+ messages in thread
From: Mike Frysinger @ 2012-01-31 19:53 UTC (permalink / raw)
  To: u-boot

This adds a SPI flash driver which simulates SPI flash clients.
Currently supports the bare min that U-Boot requires: you can
probe, read, erase, and write.  Should be easy to extend to make
it behave more exactly like a real SPI flash, but this is good
enough to merge now.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
 drivers/mtd/spi/Makefile  |    1 +
 drivers/mtd/spi/sandbox.c |  386 +++++++++++++++++++++++++++++++++++++++++++++
 drivers/spi/sandbox_spi.c |    5 +
 3 files changed, 392 insertions(+), 0 deletions(-)
 create mode 100644 drivers/mtd/spi/sandbox.c

diff --git a/drivers/mtd/spi/Makefile b/drivers/mtd/spi/Makefile
index 90f8392..fb37807 100644
--- a/drivers/mtd/spi/Makefile
+++ b/drivers/mtd/spi/Makefile
@@ -33,6 +33,7 @@ COBJS-$(CONFIG_SPI_FLASH)	+= spi_flash.o
 COBJS-$(CONFIG_SPI_FLASH_ATMEL)	+= atmel.o
 COBJS-$(CONFIG_SPI_FLASH_EON)	+= eon.o
 COBJS-$(CONFIG_SPI_FLASH_MACRONIX)	+= macronix.o
+COBJS-$(CONFIG_SPI_FLASH_SANDBOX)	+= sandbox.o
 COBJS-$(CONFIG_SPI_FLASH_SPANSION)	+= spansion.o
 COBJS-$(CONFIG_SPI_FLASH_SST)	+= sst.o
 COBJS-$(CONFIG_SPI_FLASH_STMICRO)	+= stmicro.o
diff --git a/drivers/mtd/spi/sandbox.c b/drivers/mtd/spi/sandbox.c
new file mode 100644
index 0000000..4b8e384
--- /dev/null
+++ b/drivers/mtd/spi/sandbox.c
@@ -0,0 +1,386 @@
+/*
+ * Simulate a SPI flash
+ *
+ * Copyright (c) 2011-2012 The Chromium OS Authors.
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * Licensed under the GPL-2 or later.
+ */
+
+#include <common.h>
+#include <malloc.h>
+#include <spi.h>
+#include <os.h>
+
+#include <spi_flash.h>
+#include "spi_flash_internal.h"
+
+#include <asm/spi.h>
+
+/*
+ * The different states that our SPI flash transitions between.
+ * We need to keep track of this across multiple xfer calls since
+ * the SPI bus could possibly call down into us multiple times.
+ */
+typedef enum {
+	SF_CMD,   /* default state -- we're awaiting a command */
+	SF_ID,    /* read the flash's (jedec) ID code */
+	SF_ADDR,  /* processing the offset in the flash to read/etc... */
+	SF_READ,  /* reading data from the flash */
+	SF_WRITE, /* writing data to the flash, i.e. page programming */
+	SF_ERASE, /* erase the flash */
+	SF_READ_STATUS, /* read the flash's status register */
+} sb_sf_state;
+
+static const char *sb_sf_state_name(sb_sf_state state)
+{
+	static const char * const states[] = {
+		"CMD", "ID", "ADDR", "READ", "WRITE", "ERASE", "READ_STATUS",
+	};
+	return states[state];
+}
+
+/* Bits for the status register */
+#define STAT_WIP	(1 << 0)
+#define STAT_WEL	(1 << 1)
+
+/* Assume all SPI flashes have 3 byte addresses since they do atm */
+#define SF_ADDR_LEN	3
+
+struct sb_spi_flash_erase_commands {
+	u8 cmd;
+	u32 size;
+};
+#define IDCODE_LEN 5
+#define MAX_ERASE_CMDS 2
+struct sb_spi_flash_data {
+	const char *name;
+	u8 idcode[IDCODE_LEN];
+	u32 size;
+	const struct sb_spi_flash_erase_commands erase_cmds[MAX_ERASE_CMDS];
+};
+
+/* Structure describing all the flashes we know how to emulate */
+static const struct sb_spi_flash_data sb_sf_flashes[] = {
+	{
+		"M25P16", { 0x20, 0x20, 0x15 }, (2 * 1024 * 1024),
+		{	/* erase commands */
+			{ 0xd8, (64 * 1024), }, /* sector */
+			{ 0xc7, (2 * 1024 * 1024), }, /* bulk */
+		},
+	},
+};
+
+/* Used to quickly bulk erase backing store */
+static u8 sb_sf_0xff[0x10000];
+
+/* Internal state data for each SPI flash */
+struct sb_spi_flash {
+	/*
+	 * As we receive data over the SPI bus, our flash transitions
+	 * between states.  For example, we start off in the SF_CMD
+	 * state where the first byte tells us what operation to perform
+	 * (such as read or write the flash).  But the operation itself
+	 * can go through a few states such as first reading in the
+	 * offset in the flash to perform the requested operation.
+	 * Thus "state" stores the exact state that our machine is in
+	 * while "cmd" stores the overall command we're processing.
+	 */
+	sb_sf_state state;
+	uint cmd;
+	const void *cmd_data;
+	/* Current position in the flash; used when reading/writing/etc... */
+	uint off;
+	/* How many address bytes we've consumed */
+	uint addr_bytes, pad_addr_bytes;
+	/* The current flash status (see STAT_XXX defines above) */
+	u8 status;
+	/* Data describing the flash we're emulating */
+	const struct sb_spi_flash_data *data;
+	/* The file on disk to serv up data from */
+	int fd;
+};
+
+static int sb_sf_setup(void **priv, const char *spec)
+{
+	/* spec = idcode:file */
+	struct sb_spi_flash *sbsf;
+	const char *file;
+	size_t i, len, idname_len;
+	const struct sb_spi_flash_data *data;
+
+	file = strchr(spec, ':');
+	if (!file)
+		goto error;
+	idname_len = file - spec;
+	++file;
+
+	for (i = 0; i < ARRAY_SIZE(sb_sf_flashes); ++i) {
+		data = &sb_sf_flashes[i];
+		len = strlen(data->name);
+		if (idname_len != len)
+			continue;
+		if (!memcmp(spec, data->name, len))
+			break;
+	}
+	if (i == ARRAY_SIZE(sb_sf_flashes)) {
+		printf("sb_sf: unknown flash '%*s'\n",
+			(int)idname_len, file);
+		goto error;
+	}
+
+	if (sb_sf_0xff[0] == 0x00)
+		memset(sb_sf_0xff, 0xff, sizeof(sb_sf_0xff));
+
+	sbsf = malloc(sizeof(*sbsf));
+	if (!sbsf)
+		goto error;
+
+	sbsf->fd = os_open(file, 02);
+	if (sbsf->fd == -1) {
+		free(sbsf);
+		goto error;
+	}
+
+	sbsf->data = data;
+
+	*priv = sbsf;
+	return 0;
+
+ error:
+	printf("sb_sf: unable to parse client spec\n");
+	return 1;
+}
+
+static void sb_sf_free(void *priv)
+{
+	struct sb_spi_flash *sbsf = priv;
+
+	os_close(sbsf->fd);
+	free(sbsf);
+}
+
+static void sb_sf_cs_activate(void *priv)
+{
+	struct sb_spi_flash *sbsf = priv;
+
+	debug("sb_sf: CS activated; state is fresh!\n");
+
+	/* CS is asserted, so reset state */
+	sbsf->off = 0;
+	sbsf->addr_bytes = 0;
+	sbsf->pad_addr_bytes = 0;
+	sbsf->state = sbsf->cmd = SF_CMD;
+}
+
+static void sb_sf_cs_deactivate(void *priv)
+{
+	debug("sb_sf: CS deactivated; cmd done processing!\n");
+}
+
+/* Figure out what command this stream is telling us to do */
+static int sb_sf_process_cmd(struct sb_spi_flash *sbsf, const u8 *rx, u8 *tx)
+{
+	sb_sf_state oldstate = sbsf->state;
+
+	/* We need to output a byte for the cmd byte we just ate */
+	sb_spi_tristate(tx, 1);
+
+	sbsf->cmd = rx[0];
+	switch (sbsf->cmd) {
+	case CMD_READ_ID:
+		sbsf->state = sbsf->cmd = SF_ID;
+		break;
+	case CMD_READ_ARRAY_FAST:
+		sbsf->pad_addr_bytes = 1;
+	case CMD_READ_ARRAY_SLOW:
+	case CMD_PAGE_PROGRAM:
+ state_addr:
+		sbsf->state = SF_ADDR;
+		break;
+	case CMD_WRITE_DISABLE:
+		debug(" write disabled\n");
+		sbsf->status &= ~STAT_WEL;
+		break;
+	case CMD_READ_STATUS:
+		sbsf->state = SF_READ_STATUS;
+		break;
+	case CMD_WRITE_ENABLE:
+		debug(" write enabled\n");
+		sbsf->status |= STAT_WEL;
+		break;
+	default: {
+		size_t i;
+
+		/* handle erase commands first */
+		for (i = 0; i < MAX_ERASE_CMDS; ++i) {
+			const struct sb_spi_flash_erase_commands *erase_cmd =
+				&sbsf->data->erase_cmds[i];
+
+			if (erase_cmd->cmd == 0x00)
+				continue;
+			if (sbsf->cmd != erase_cmd->cmd)
+				continue;
+
+			sbsf->cmd_data = erase_cmd;
+			goto state_addr;
+		}
+
+		debug(" cmd unknown: %#x\n", sbsf->cmd);
+		return 1;
+	}
+	}
+
+	if (oldstate != sbsf->state)
+		debug(" cmd: transition to %s state\n",
+			sb_sf_state_name(sbsf->state));
+
+	return 0;
+}
+
+static int sb_sf_xfer(void *priv, const u8 *rx, u8 *tx,
+		uint bytes)
+{
+	struct sb_spi_flash *sbsf = priv;
+	uint cnt, pos = 0;
+
+	debug("sb_sf: state:%x(%s) bytes:%u\n", sbsf->state,
+		sb_sf_state_name(sbsf->state), bytes);
+
+	if (sbsf->state == SF_CMD) {
+		/* Figure out the initial state */
+		if (sb_sf_process_cmd(sbsf, rx, tx))
+			return 1;
+		++pos;
+	}
+
+	/* Process the remaining data */
+	while (pos < bytes) {
+		switch (sbsf->state) {
+		case SF_ID: {
+			u8 id;
+
+			debug(" id: off:%u tx:", sbsf->off);
+			if (sbsf->off < IDCODE_LEN)
+				id = sbsf->data->idcode[sbsf->off];
+			else
+				id = 0;
+			debug("%02x\n", id);
+			tx[pos++] = id;
+			++sbsf->off;
+			break;
+		}
+		case SF_ADDR:
+			debug(" addr: bytes:%u rx:%02x ",
+				sbsf->addr_bytes, rx[pos]);
+
+			if (sbsf->addr_bytes++ < SF_ADDR_LEN)
+				sbsf->off = (sbsf->off << 8) | rx[pos];
+			debug("addr:%06x\n", sbsf->off);
+
+			sb_spi_tristate(&tx[pos++], 1);
+
+			/* See if we're done processing */
+			if (sbsf->addr_bytes < SF_ADDR_LEN + sbsf->pad_addr_bytes)
+				break;
+
+			/* Next state! */
+			os_lseek(sbsf->fd, sbsf->off, OS_SEEK_SET);
+			switch (sbsf->cmd) {
+			case CMD_READ_ARRAY_FAST:
+			case CMD_READ_ARRAY_SLOW:
+				sbsf->state = SF_READ;
+				break;
+			case CMD_PAGE_PROGRAM:
+				sbsf->state = SF_WRITE;
+				break;
+			default:
+				/* assume erase state ... */
+				sbsf->state = SF_ERASE;
+				goto case_SF_ERASE;
+			}
+			debug(" cmd: transition to %s state\n",
+				sb_sf_state_name(sbsf->state));
+			break;
+		case SF_READ:
+			/*
+			 * XXX: need to handle exotic behavior:
+			 *      - reading past end of device
+			 */
+
+			cnt = bytes - pos;
+			debug(" tx: read(%u)\n", cnt);
+			pos += os_read(sbsf->fd, tx + pos, cnt);
+			break;
+		case SF_READ_STATUS:
+			debug(" read status: %#x\n", sbsf->status);
+			cnt = bytes - pos;
+			memset(tx + pos, sbsf->status, cnt);
+			pos += cnt;
+			break;
+		case SF_WRITE:
+			/*
+			 * XXX: need to handle exotic behavior:
+			 *      - unaligned addresses
+			 *      - more than a page (256) worth of data
+			 *      - reading past end of device
+			 */
+
+			if (!(sbsf->status & STAT_WEL)) {
+				puts("sb_sf: write enable not set before erase\n");
+				goto done;
+			}
+
+			cnt = bytes - pos;
+			debug(" rx: write(%u)\n", cnt);
+			sb_spi_tristate(&tx[pos], cnt);
+			pos += os_write(sbsf->fd, rx + pos, cnt);
+			sbsf->status &= ~STAT_WEL;
+			break;
+		case SF_ERASE:
+		case_SF_ERASE: {
+			const struct sb_spi_flash_erase_commands *erase_cmd =
+				sbsf->cmd_data;
+
+			if (!(sbsf->status & STAT_WEL)) {
+				puts("sb_sf: write enable not set before erase\n");
+				goto done;
+			}
+
+			/* verify address is aligned */
+			if (sbsf->off & ~(erase_cmd->size - 1)) {
+				debug(" sector erase: cmd:%#x needs align:%#x, but we got %#x\n",
+					erase_cmd->cmd, erase_cmd->size, sbsf->off);
+				sbsf->status &= ~STAT_WEL;
+				goto done;
+			}
+
+			debug(" sector erase addr: %u\n", sbsf->off);
+
+			cnt = bytes - pos;
+			sb_spi_tristate(&tx[pos], cnt);
+			pos += cnt;
+
+			/* XXX: latch WIP in status, and delay before clearing it ? */
+			os_write(sbsf->fd, sb_sf_0xff, erase_cmd->size);
+			sbsf->status &= ~STAT_WEL;
+			goto done;
+		}
+		default:
+			debug(" ??? no idea what to do ???\n");
+			goto done;
+		}
+	}
+
+ done:
+	return pos == bytes ? 0 : 1;
+}
+
+const struct sb_spi_emu_ops sb_sf_ops = {
+	.setup         = sb_sf_setup,
+	.free          = sb_sf_free,
+	.cs_activate   = sb_sf_cs_activate,
+	.cs_deactivate = sb_sf_cs_deactivate,
+	.xfer          = sb_sf_xfer,
+};
diff --git a/drivers/spi/sandbox_spi.c b/drivers/spi/sandbox_spi.c
index d0cba76..88b51ab 100644
--- a/drivers/spi/sandbox_spi.c
+++ b/drivers/spi/sandbox_spi.c
@@ -35,10 +35,15 @@ static const char *sb_lookup_arg(unsigned int bus, unsigned int cs)
 	return os_getopt(sf_arg, 1);
 }
 
+extern const struct sb_spi_emu_ops sb_sf_ops;
+
 static const struct {
 	const char *spec;
 	const struct sb_spi_emu_ops *ops;
 } sb_emu_map[] = {
+#ifdef CONFIG_SPI_FLASH_SANDBOX
+	{ "sf", &sb_sf_ops, },
+#endif
 };
 
 static int sb_parse_type(struct sb_spi_slave *sss)
-- 
1.7.8.4

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [U-Boot] [PATCH 5/5 v2] sandbox: enable new spi/sf layers
  2012-01-31 19:53 [U-Boot] [PATCH 0/5 v2] sandbox: spi/sf emulation Mike Frysinger
                   ` (3 preceding siblings ...)
  2012-01-31 19:53 ` [U-Boot] [PATCH 4/5 v2] sandbox: new SPI flash driver Mike Frysinger
@ 2012-01-31 19:53 ` Mike Frysinger
  4 siblings, 0 replies; 11+ messages in thread
From: Mike Frysinger @ 2012-01-31 19:53 UTC (permalink / raw)
  To: u-boot

We want to test SPI flash code in the sandbox, so enable the new drivers.

Acked-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
 include/configs/sandbox.h |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/include/configs/sandbox.h b/include/configs/sandbox.h
index 10565e6..c1962cd 100644
--- a/include/configs/sandbox.h
+++ b/include/configs/sandbox.h
@@ -51,6 +51,13 @@
 #define CONFIG_ENV_SIZE		8192
 #define CONFIG_ENV_IS_NOWHERE
 
+/* SPI */
+#define CONFIG_SANDBOX_SPI
+#define CONFIG_CMD_SF
+#define CONFIG_SPI_FLASH
+#define CONFIG_SPI_FLASH_SANDBOX
+#define CONFIG_SPI_FLASH_STMICRO
+
 #define CONFIG_SYS_HZ			1000
 
 /* Memory things - we don't really want a memory test */
-- 
1.7.8.4

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [U-Boot] [PATCH 1/5 v2] sandbox: add lseek helper
  2012-01-31 19:53 ` [U-Boot] [PATCH 1/5 v2] sandbox: add lseek helper Mike Frysinger
@ 2012-02-01 23:37   ` Simon Glass
  2012-02-03 11:25     ` Mike Frysinger
  2012-02-03 11:26   ` [U-Boot] [PATCH 1/5 v2.1] " Mike Frysinger
  1 sibling, 1 reply; 11+ messages in thread
From: Simon Glass @ 2012-02-01 23:37 UTC (permalink / raw)
  To: u-boot

Hi Mike,

On Tue, Jan 31, 2012 at 11:53 AM, Mike Frysinger <vapier@gentoo.org> wrote:
> Follow up patches want to be able to seek fd's.
>
> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
> ---
> ?arch/sandbox/cpu/os.c | ? 13 +++++++++++++
> ?include/os.h ? ? ? ? ?| ? 15 +++++++++++++++
> ?2 files changed, 28 insertions(+), 0 deletions(-)
>
> diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c
> index 093e7dc..13331d2 100644
> --- a/arch/sandbox/cpu/os.c
> +++ b/arch/sandbox/cpu/os.c
> @@ -45,6 +45,19 @@ ssize_t os_write(int fd, const void *buf, size_t count)
> ? ? ? ?return write(fd, buf, count);
> ?}
>
> +off_t os_lseek(int fd, off_t offset, int whence)
> +{
> + ? ? ? if (whence == OS_SEEK_SET)
> + ? ? ? ? ? ? ? whence = SEEK_SET;
> + ? ? ? else if (whence == OS_SEEK_CUR)
> + ? ? ? ? ? ? ? whence = SEEK_CUR;
> + ? ? ? else if (whence == OS_SEEK_END)
> + ? ? ? ? ? ? ? whence = SEEK_END;

I suppose this is safest.

> + ? ? ? else
> + ? ? ? ? ? ? ? printf("%s: invalid whence value %i\n", __func__, whence);
> + ? ? ? return lseek(fd, offset, whence);
> +}
> +
> ?int os_open(const char *pathname, int flags)
> ?{
> ? ? ? ?return open(pathname, flags);
> diff --git a/include/os.h b/include/os.h
> index c17a8a5..11017b7 100644
> --- a/include/os.h
> +++ b/include/os.h
> @@ -49,6 +49,21 @@ ssize_t os_read(int fd, void *buf, size_t count);
> ?ssize_t os_write(int fd, const void *buf, size_t count);
>
> ?/**
> + * Access to the OS lseek() system call
> + *
> + * \param fd ? File descriptor as returned by os_open()
> + * \param offset ? ? ? File offset (based on whence)
> + * \param whence ? ? ? Position offset is relative to (see below)
> + * \return new file offset
> + */
> +off_t os_lseek(int fd, off_t offset, int whence);
> +
> +/* Defines for "whence" in os_lseek() */
> +#define OS_SEEK_SET ? ?0
> +#define OS_SEEK_CUR ? ?0
> +#define OS_SEEK_END ? ?0

0, 1, 2?

> +
> +/**
> ?* Access to the OS open() system call
> ?*
> ?* \param pathname ? ? Pathname of file to open
> --
> 1.7.8.4
>
> _______________________________________________
> U-Boot mailing list
> U-Boot at lists.denx.de
> http://lists.denx.de/mailman/listinfo/u-boot

Regards,
Simon

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [U-Boot] [PATCH 1/5 v2] sandbox: add lseek helper
  2012-02-01 23:37   ` Simon Glass
@ 2012-02-03 11:25     ` Mike Frysinger
  0 siblings, 0 replies; 11+ messages in thread
From: Mike Frysinger @ 2012-02-03 11:25 UTC (permalink / raw)
  To: u-boot

On Wednesday 01 February 2012 18:37:27 Simon Glass wrote:
> On Tue, Jan 31, 2012 at 11:53 AM, Mike Frysinger wrote:
> > --- a/include/os.h
> > +++ b/include/os.h
> >
> > +#define OS_SEEK_SET    0
> > +#define OS_SEEK_CUR    0
> > +#define OS_SEEK_END    0
> 
> 0, 1, 2?

see if you can guess what 1 mode i tested ;)
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120203/ecc46b47/attachment.pgp>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [U-Boot] [PATCH 1/5 v2.1] sandbox: add lseek helper
  2012-01-31 19:53 ` [U-Boot] [PATCH 1/5 v2] sandbox: add lseek helper Mike Frysinger
  2012-02-01 23:37   ` Simon Glass
@ 2012-02-03 11:26   ` Mike Frysinger
  2012-02-15  6:30     ` Simon Glass
  2012-02-21  5:24     ` [U-Boot] [PATCH 1/5 v2.2] " Mike Frysinger
  1 sibling, 2 replies; 11+ messages in thread
From: Mike Frysinger @ 2012-02-03 11:26 UTC (permalink / raw)
  To: u-boot

Follow up patches want to be able to seek fd's.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
v2.1
	- fix thinko in os_seek_xxx defines

 arch/sandbox/cpu/os.c |   13 +++++++++++++
 include/os.h          |   15 +++++++++++++++
 2 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c
index 093e7dc..13331d2 100644
--- a/arch/sandbox/cpu/os.c
+++ b/arch/sandbox/cpu/os.c
@@ -45,6 +45,19 @@ ssize_t os_write(int fd, const void *buf, size_t count)
 	return write(fd, buf, count);
 }
 
+off_t os_lseek(int fd, off_t offset, int whence)
+{
+	if (whence == OS_SEEK_SET)
+		whence = SEEK_SET;
+	else if (whence == OS_SEEK_CUR)
+		whence = SEEK_CUR;
+	else if (whence == OS_SEEK_END)
+		whence = SEEK_END;
+	else
+		printf("%s: invalid whence value %i\n", __func__, whence);
+	return lseek(fd, offset, whence);
+}
+
 int os_open(const char *pathname, int flags)
 {
 	return open(pathname, flags);
diff --git a/include/os.h b/include/os.h
index c17a8a5..f74766d 100644
--- a/include/os.h
+++ b/include/os.h
@@ -49,6 +49,21 @@ ssize_t os_read(int fd, void *buf, size_t count);
 ssize_t os_write(int fd, const void *buf, size_t count);
 
 /**
+ * Access to the OS lseek() system call
+ *
+ * \param fd	File descriptor as returned by os_open()
+ * \param offset	File offset (based on whence)
+ * \param whence	Position offset is relative to (see below)
+ * \return new file offset
+ */
+off_t os_lseek(int fd, off_t offset, int whence);
+
+/* Defines for "whence" in os_lseek() */
+#define OS_SEEK_SET	0
+#define OS_SEEK_CUR	1
+#define OS_SEEK_END	2
+
+/**
  * Access to the OS open() system call
  *
  * \param pathname	Pathname of file to open
-- 
1.7.8.4

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [U-Boot] [PATCH 1/5 v2.1] sandbox: add lseek helper
  2012-02-03 11:26   ` [U-Boot] [PATCH 1/5 v2.1] " Mike Frysinger
@ 2012-02-15  6:30     ` Simon Glass
  2012-02-21  5:24     ` [U-Boot] [PATCH 1/5 v2.2] " Mike Frysinger
  1 sibling, 0 replies; 11+ messages in thread
From: Simon Glass @ 2012-02-15  6:30 UTC (permalink / raw)
  To: u-boot

On Fri, Feb 3, 2012 at 3:26 AM, Mike Frysinger <vapier@gentoo.org> wrote:

> Follow up patches want to be able to seek fd's.
>
> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
>

Acked-by: Simon Glass <sjg@chromium.org>


> ---
> v2.1
>        - fix thinko in os_seek_xxx defines
>
>  arch/sandbox/cpu/os.c |   13 +++++++++++++
>  include/os.h          |   15 +++++++++++++++
>  2 files changed, 28 insertions(+), 0 deletions(-)
>
> diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c
> index 093e7dc..13331d2 100644
> --- a/arch/sandbox/cpu/os.c
> +++ b/arch/sandbox/cpu/os.c
> @@ -45,6 +45,19 @@ ssize_t os_write(int fd, const void *buf, size_t count)
>        return write(fd, buf, count);
>  }
>
> +off_t os_lseek(int fd, off_t offset, int whence)
> +{
> +       if (whence == OS_SEEK_SET)
> +               whence = SEEK_SET;
> +       else if (whence == OS_SEEK_CUR)
> +               whence = SEEK_CUR;
> +       else if (whence == OS_SEEK_END)
> +               whence = SEEK_END;
> +       else
> +               printf("%s: invalid whence value %i\n", __func__, whence);
> +       return lseek(fd, offset, whence);
> +}
> +
>  int os_open(const char *pathname, int flags)
>  {
>        return open(pathname, flags);
> diff --git a/include/os.h b/include/os.h
> index c17a8a5..f74766d 100644
> --- a/include/os.h
> +++ b/include/os.h
> @@ -49,6 +49,21 @@ ssize_t os_read(int fd, void *buf, size_t count);
>  ssize_t os_write(int fd, const void *buf, size_t count);
>
>  /**
> + * Access to the OS lseek() system call
> + *
> + * \param fd   File descriptor as returned by os_open()
> + * \param offset       File offset (based on whence)
> + * \param whence       Position offset is relative to (see below)
> + * \return new file offset
>

We mostly use @param and @return I think, but I suppose it doesn't matter
much.


> + */
> +off_t os_lseek(int fd, off_t offset, int whence);
> +
> +/* Defines for "whence" in os_lseek() */
> +#define OS_SEEK_SET    0
> +#define OS_SEEK_CUR    1
> +#define OS_SEEK_END    2
> +
> +/**
>  * Access to the OS open() system call
>  *
>  * \param pathname     Pathname of file to open
> --
> 1.7.8.4
>
>
> Regards,
Simon

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [U-Boot] [PATCH 1/5 v2.2] sandbox: add lseek helper
  2012-02-03 11:26   ` [U-Boot] [PATCH 1/5 v2.1] " Mike Frysinger
  2012-02-15  6:30     ` Simon Glass
@ 2012-02-21  5:24     ` Mike Frysinger
  1 sibling, 0 replies; 11+ messages in thread
From: Mike Frysinger @ 2012-02-21  5:24 UTC (permalink / raw)
  To: u-boot

Follow up patches want to be able to seek fd's.

Acked-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
v2.2
	- added stdio.h include for printf() prototype

 arch/sandbox/cpu/os.c |   14 ++++++++++++++
 include/os.h          |   15 +++++++++++++++
 2 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c
index 093e7dc..15f1f67 100644
--- a/arch/sandbox/cpu/os.c
+++ b/arch/sandbox/cpu/os.c
@@ -21,6 +21,7 @@
 
 #include <errno.h>
 #include <fcntl.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <termios.h>
 #include <time.h>
@@ -45,6 +46,19 @@ ssize_t os_write(int fd, const void *buf, size_t count)
 	return write(fd, buf, count);
 }
 
+off_t os_lseek(int fd, off_t offset, int whence)
+{
+	if (whence == OS_SEEK_SET)
+		whence = SEEK_SET;
+	else if (whence == OS_SEEK_CUR)
+		whence = SEEK_CUR;
+	else if (whence == OS_SEEK_END)
+		whence = SEEK_END;
+	else
+		printf("%s: invalid whence value %i\n", __func__, whence);
+	return lseek(fd, offset, whence);
+}
+
 int os_open(const char *pathname, int flags)
 {
 	return open(pathname, flags);
diff --git a/include/os.h b/include/os.h
index c17a8a5..f74766d 100644
--- a/include/os.h
+++ b/include/os.h
@@ -49,6 +49,21 @@ ssize_t os_read(int fd, void *buf, size_t count);
 ssize_t os_write(int fd, const void *buf, size_t count);
 
 /**
+ * Access to the OS lseek() system call
+ *
+ * \param fd	File descriptor as returned by os_open()
+ * \param offset	File offset (based on whence)
+ * \param whence	Position offset is relative to (see below)
+ * \return new file offset
+ */
+off_t os_lseek(int fd, off_t offset, int whence);
+
+/* Defines for "whence" in os_lseek() */
+#define OS_SEEK_SET	0
+#define OS_SEEK_CUR	1
+#define OS_SEEK_END	2
+
+/**
  * Access to the OS open() system call
  *
  * \param pathname	Pathname of file to open
-- 
1.7.8.4

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2012-02-21  5:24 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-31 19:53 [U-Boot] [PATCH 0/5 v2] sandbox: spi/sf emulation Mike Frysinger
2012-01-31 19:53 ` [U-Boot] [PATCH 1/5 v2] sandbox: add lseek helper Mike Frysinger
2012-02-01 23:37   ` Simon Glass
2012-02-03 11:25     ` Mike Frysinger
2012-02-03 11:26   ` [U-Boot] [PATCH 1/5 v2.1] " Mike Frysinger
2012-02-15  6:30     ` Simon Glass
2012-02-21  5:24     ` [U-Boot] [PATCH 1/5 v2.2] " Mike Frysinger
2012-01-31 19:53 ` [U-Boot] [PATCH 2/5 v2] sandbox: add getopt support Mike Frysinger
2012-01-31 19:53 ` [U-Boot] [PATCH 3/5 v2] sandbox: SPI emulation bus Mike Frysinger
2012-01-31 19:53 ` [U-Boot] [PATCH 4/5 v2] sandbox: new SPI flash driver Mike Frysinger
2012-01-31 19:53 ` [U-Boot] [PATCH 5/5 v2] sandbox: enable new spi/sf layers Mike Frysinger

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.