Re: [PATCH v3 1/2] mfd: add stmpe-i2c driver

2012-09-04 Thread Sascha Hauer
On Tue, Sep 04, 2012 at 11:58:45AM +0200, Steffen Trumtrar wrote:
> The stmpe mfds can be connected via i2c and spi. This driver provides the 
> basic
> infrastructure for the i2c kind. It can be added as a normal i2c-device in the
> board code. To enable functions a platform_data struct has to be provided, 
> that
> describes what parts of the chip are to be used.
> 
> Signed-off-by: Steffen Trumtrar 
> ---
> +static struct stmpe_client_info i2c_ci = {
> + .read_reg = stmpe_reg_read,
> + .write_reg = stmpe_reg_write,
> +};
> +
> +static int stmpe_probe(struct device_d *dev)
> +{
> + struct stmpe_platform_data *pdata = dev->platform_data;
> + struct stmpe *stmpe_dev;
> +
> + if (!pdata) {
> + dev_dbg(dev, "no platform data\n");
> + return -ENODEV;
> + }
> +
> + stmpe_dev = xzalloc(sizeof(struct stmpe));
> + stmpe_dev->cdev.name = DRIVERNAME;
> + stmpe_dev->client = to_i2c_client(dev);
> + stmpe_dev->cdev.size = 191; /* 191 known registers */
> + stmpe_dev->cdev.dev = dev;
> + stmpe_dev->cdev.ops = &stmpe_fops;
> + stmpe_dev->pdata = pdata;
> + dev->priv = stmpe_dev;
> + i2c_ci.stmpe = stmpe_dev;

This breaks for multiple instances of a stmpe device. You have to
allocate a static struct stmpe_client_info dynamically.

> +
> + if (pdata->blocks &= STMPE_BLOCK_GPIO)
> + add_generic_device("stmpe-gpio", 0, NULL, pdata->base, 0x10, 
> IORESOURCE_MEM, &i2c_ci);

This issues:

drivers/mfd/stmpe-i2c.c: In function 'stmpe_probe':
drivers/mfd/stmpe-i2c.c:135:3: warning: passing argument 4 of 
'add_generic_device' makes integer from pointer without a cast [enabled by 
default]
include/driver.h:197:18: note: expected 'resource_size_t' but argument is of 
type 'void *'

The base and size refer to the iomem space. As an i2c device we do not
have iomem here, so this is wrong.

Looking further at it it seems to be unused by the gpio driver anyway,
so you can just pass 0, 0 as iomem and size.


> +struct stmpe_platform_data {
> + enumstmpe_revision  revision;
> + enumstmpe_blocksblocks;
> + void__iomem *base;

This is unused, please remove.

> + int gpio_base;
> +};
> +
> +
> +extern int stmpe_reg_read(struct stmpe *priv, u32 reg, u8 *val);
> +extern int stmpe_reg_write(struct stmpe *priv, u32 reg, u8 val);
> +extern int stmpe_set_bits(struct stmpe *priv, u32 reg, u8 mask, u8 val);

no 'extern' for function prototypes please.

Sascha

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: MLO doesn't work, rest is ok

2012-09-04 Thread Jan Weitzel
Am Dienstag, den 04.09.2012, 18:31 +0200 schrieb Norbert Roos:
> Hello,
> 
> I just wanted to try the freshly generated MLO and barebox.bin on my 
> Phytec PCM049 board (OMAP4 based). Copied both files to the FAT 
> partition on the SD card.
> 
> Unfortunately it doesn't boot, after trying to boot from SD card the ROM 
> boot loader oviously skips to booting from UART.
> 
> When i replace the MLO with a different one (downloaded a compiled one), 
> my generated barebox.bin gets loaded and everything's fine.
> 
> Is there a simple way for debugging it? It seems like the MLO does not 
> get executed, as the ROM boot skips to UART boot...
> 
> bye
> Norbert

Hi,
which barebox version? Is the board with OMAP4460?
Jan

> ___
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox



___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: barebox on imx23-olinuxino

2012-09-04 Thread Fadil Berisha
Sascha

On Tue, Sep 4, 2012 at 4:47 PM, Sascha Hauer  wrote:

> The problem is the 5th parameter. It is the size of the memory resource.
> When speicified as 0 you will not be able to request it. It seems we
> still have not catched all of these. We should probably add a warning
> if someone tries to register a device with a valid resource but size =
> 0.
Thank you for your help. I will clean-up my workaround and define size
as needed. Barebox booting good in olinuxino. At this stage, I am
doing testing and adjusting env parameters.

Regards,
Fadil Berisha

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: barebox on imx23-olinuxino

2012-09-04 Thread Sascha Hauer
On Sun, Sep 02, 2012 at 01:25:01AM -0400, Fadil Berisha wrote:
> Juergen,
> 
> Sorry, for replying so late, but took me time to identify problem.
>  I am using function:
> 
> add_generic_device("mxs_mci", DEVICE_ID_DYNAMIC, NULL, IMX_SSP1_BASE, 0,
>  IORESOURCE_MEM, &mci_pdata);
>

The problem is the 5th parameter. It is the size of the memory resource.
When speicified as 0 you will not be able to request it. It seems we
still have not catched all of these. We should probably add a warning
if someone tries to register a device with a valid resource but size =
0.

Sascha
 
-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 2/6] memory: fix regions calculation

2012-09-04 Thread Sascha Hauer
On Tue, Sep 04, 2012 at 10:05:43AM +0200, Alexander Aring wrote:
> Fix calculation of regions.
> 
> Previous end address and next start address of two chained regions are
> the same in a linkerscript.
> We need the same behaviour for mem_malloc_init.
> 
> When we add the region to the regions tree we calculate -1 to the end
> address.
> 

Most of this patch is wrong. The following is always true:

end = start + size - 1

The problem we have is that in the linker scripts we have

_text = .;
*(.text*)
_etext = .;

Here _etext is *not* the end but the next free address.

So we have to calculate text size for the above example as:

text_size = _etext - _text;


> index 80b62e9..c85aae1 100644
> --- a/arch/arm/lib/arm.c
> +++ b/arch/arm/lib/arm.c
> @@ -7,7 +7,7 @@
>  static int arm_mem_malloc_init(void)
>  {
>   mem_malloc_init((void *)MALLOC_BASE,
> - (void *)(MALLOC_BASE + MALLOC_SIZE - 1));
> + (void *)(MALLOC_BASE + MALLOC_SIZE));

So this patch is wrong.

>   request_sdram_region("malloc space",
>   malloc_start,
> - malloc_end - malloc_start + 1);
> + malloc_end - malloc_start);

This is also wrong (and also all changes above this)

>   request_sdram_region("barebox",
>   (unsigned long)&_stext,
>   (unsigned long)&_etext -
> - (unsigned long)&_stext + 1);
> + (unsigned long)&_stext);

This change is correct.

>   request_sdram_region("bss",
>   (unsigned long)&__bss_start,
>   (unsigned long)&__bss_stop -
> - (unsigned long)&__bss_start + 1);
> + (unsigned long)&__bss_start);

This change is also correct.

>  #ifdef STACK_BASE
>   request_sdram_region("stack", STACK_BASE, STACK_SIZE);
>  #endif
> diff --git a/common/startup.c b/common/startup.c
> index abd1b77..0fa2dab 100644
> --- a/common/startup.c
> +++ b/common/startup.c
> @@ -47,8 +47,8 @@ extern initcall_t __barebox_initcalls_start[], 
> __barebox_early_initcalls_end[],
>  static void display_meminfo(void)
>  {
>   ulong mstart = mem_malloc_start();
> - ulong mend   = mem_malloc_end();
> - ulong msize  = mend - mstart + 1;
> + ulong mend   = mem_malloc_end() - 1;
> + ulong msize  = mend - mstart;

This change is wrong.

>  
>   debug("barebox code: 0x%p -> 0x%p\n", _stext, _etext);
>   debug("bss segment:  0x%p -> 0x%p\n", __bss_start, __bss_stop);
> @@ -56,7 +56,7 @@ static void display_meminfo(void)
>   mstart, mend, size_human_readable(msize));
>  #ifdef CONFIG_ARM
>   printf("Stack space : 0x%08x -> 0x%08x (size %s)\n",
> - STACK_BASE, STACK_BASE + STACK_SIZE,
> + STACK_BASE, STACK_BASE + STACK_SIZE - 1,

This change is correct.

Sascha

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 17/19] envfs: add support of variable inode size

2012-09-04 Thread Jean-Christophe PLAGNIOL-VILLARD
Introduce a struct envfs_inode_end with more data.
Today this will just containt the file mode to be able to add the symlink
support.

But this is compatible with the previous envfs version as they will do not
care about the extra as the previous version is just reading the filename and
then consume the extra data without using them.

Increase the envfs version to 1.0

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD 
---
 common/environment.c |   53 ++
 include/envfs.h  |   12 +---
 2 files changed, 50 insertions(+), 15 deletions(-)

diff --git a/common/environment.c b/common/environment.c
index 8efed97..fc5c57e 100644
--- a/common/environment.c
+++ b/common/environment.c
@@ -53,6 +53,7 @@ int file_size_action(const char *filename, struct stat 
*statbuf,
 
data->writep += sizeof(struct envfs_inode);
data->writep += PAD4(strlen(filename) + 1 - strlen(data->base));
+   data->writep += sizeof(struct envfs_inode_end);
data->writep += PAD4(statbuf->st_size);
return 1;
 }
@@ -62,6 +63,7 @@ int file_save_action(const char *filename, struct stat 
*statbuf,
 {
struct action_data *data = userdata;
struct envfs_inode *inode;
+   struct envfs_inode_end *inode_end;
int fd;
int namelen = strlen(filename) + 1 - strlen(data->base);
 
@@ -70,12 +72,16 @@ int file_save_action(const char *filename, struct stat 
*statbuf,
 
inode = (struct envfs_inode*)data->writep;
inode->magic = ENVFS_32(ENVFS_INODE_MAGIC);
-   inode->namelen = ENVFS_32(namelen);
+   inode->headerlen = ENVFS_32(PAD4(namelen + sizeof(struct 
envfs_inode_end)));
inode->size = ENVFS_32(statbuf->st_size);
data->writep += sizeof(struct envfs_inode);
 
strcpy(data->writep, filename + strlen(data->base));
data->writep += PAD4(namelen);
+   inode_end = (struct envfs_inode_end*)data->writep;
+   data->writep += sizeof(struct envfs_inode_end);
+   inode_end->magic = ENVFS_32(ENVFS_INODE_END_MAGIC);
+   inode_end->mode = ENVFS_32(S_IRWXU | S_IRWXG | S_IRWXO);
 
fd = open(filename, O_RDONLY);
if (fd < 0) {
@@ -176,8 +182,13 @@ int envfs_load(char *filename, char *dir)
int envfd;
int fd, ret = 0;
char *str, *tmp;
-   int namelen_full;
+   int headerlen_full;
unsigned long size;
+   /* for envfs < 1.0 */
+   struct envfs_inode_end inode_end_dummy;
+
+   inode_end_dummy.mode = ENVFS_32(S_IRWXU | S_IRWXG | S_IRWXO);
+   inode_end_dummy.magic = ENVFS_32(ENVFS_INODE_END_MAGIC);
 
envfd = open(filename, O_RDONLY);
if (envfd < 0) {
@@ -223,11 +234,18 @@ int envfs_load(char *filename, char *dir)
goto out;
}
 
+   if (super.major < ENVFS_MAJOR)
+   printf("envfs version %d.%d loaded into %d.%d\n",
+   super.major, super.minor,
+   ENVFS_MAJOR, ENVFS_MINOR);
+
while (size) {
struct envfs_inode *inode;
-   uint32_t inode_size, inode_namelen;
+   struct envfs_inode_end *inode_end;
+   uint32_t inode_size, inode_headerlen, namelen;
 
inode = (struct envfs_inode *)buf;
+   buf += sizeof(struct envfs_inode);
 
if (ENVFS_32(inode->magic) != ENVFS_INODE_MAGIC) {
printf("envfs: wrong magic on %s\n", filename);
@@ -235,16 +253,30 @@ int envfs_load(char *filename, char *dir)
goto out;
}
inode_size = ENVFS_32(inode->size);
-   inode_namelen = ENVFS_32(inode->namelen);
+   inode_headerlen = ENVFS_32(inode->headerlen);
+   namelen = strlen(inode->data) + 1;
+   if (super.major < 1)
+   inode_end = &inode_end_dummy;
+   else
+   inode_end = (struct envfs_inode_end *)(buf + 
PAD4(namelen));
 
-   debug("loading %s size %d namelen %d\n", inode->data,
-   inode_size, inode_namelen);
+   debug("loading %s size %d namelen %d headerlen %d\n", 
inode->data,
+   inode_size, namelen, inode_headerlen);
 
str = concat_path_file(dir, inode->data);
tmp = strdup(str);
make_directory(dirname(tmp));
free(tmp);
 
+   headerlen_full = PAD4(inode_headerlen);
+   buf += headerlen_full;
+
+   if (ENVFS_32(inode_end->magic) != ENVFS_INODE_END_MAGIC) {
+   printf("envfs: wrong inode_end_magic on %s\n", 
filename);
+   ret = -EIO;
+   goto out;
+   }
+
fd = open(str, O_WRONLY | O_CREAT | O_TRUNC, 0644);
free(str);
if (fd < 0) {
@@ -253,9 +285,7 @@ int envfs_load(char *filename, char *dir)
  

[PATCH 18/19] envfs: add support of symlink

2012-09-04 Thread Jean-Christophe PLAGNIOL-VILLARD
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD 
---
 common/environment.c |  103 +++---
 1 file changed, 73 insertions(+), 30 deletions(-)

diff --git a/common/environment.c b/common/environment.c
index fc5c57e..ce46f4a 100644
--- a/common/environment.c
+++ b/common/environment.c
@@ -54,7 +54,20 @@ int file_size_action(const char *filename, struct stat 
*statbuf,
data->writep += sizeof(struct envfs_inode);
data->writep += PAD4(strlen(filename) + 1 - strlen(data->base));
data->writep += sizeof(struct envfs_inode_end);
-   data->writep += PAD4(statbuf->st_size);
+   if (S_ISLNK(statbuf->st_mode)) {
+   char path[PATH_MAX];
+
+   memset(path, 0, PATH_MAX);
+
+   if (readlink(filename, path, PATH_MAX - 1) < 0) {
+   perror("read");
+   return 0;
+   }
+   data->writep += PAD4(strlen(path) + 1);
+   } else {
+   data->writep += PAD4(statbuf->st_size);
+   }
+
return 1;
 }
 
@@ -67,13 +80,9 @@ int file_save_action(const char *filename, struct stat 
*statbuf,
int fd;
int namelen = strlen(filename) + 1 - strlen(data->base);
 
-   debug("handling file %s size %ld namelen %d\n", filename + 
strlen(data->base),
-   statbuf->st_size, namelen);
-
inode = (struct envfs_inode*)data->writep;
inode->magic = ENVFS_32(ENVFS_INODE_MAGIC);
inode->headerlen = ENVFS_32(PAD4(namelen + sizeof(struct 
envfs_inode_end)));
-   inode->size = ENVFS_32(statbuf->st_size);
data->writep += sizeof(struct envfs_inode);
 
strcpy(data->writep, filename + strlen(data->base));
@@ -83,19 +92,44 @@ int file_save_action(const char *filename, struct stat 
*statbuf,
inode_end->magic = ENVFS_32(ENVFS_INODE_END_MAGIC);
inode_end->mode = ENVFS_32(S_IRWXU | S_IRWXG | S_IRWXO);
 
-   fd = open(filename, O_RDONLY);
-   if (fd < 0) {
-   printf("Open %s %s\n", filename, errno_str());
-   goto out;
-   }
+   if (S_ISLNK(statbuf->st_mode)) {
+   char path[PATH_MAX];
+   int len;
 
-   if (read(fd, data->writep, statbuf->st_size) < statbuf->st_size) {
-   perror("read");
-   goto out;
-   }
-   close(fd);
+   memset(path, 0, PATH_MAX);
+
+   if (readlink(filename, path, PATH_MAX - 1) < 0) {
+   perror("read");
+   goto out;
+   }
+   len = strlen(path) + 1;
+
+   inode_end->mode |= ENVFS_32(S_IFLNK);
 
-   data->writep += PAD4(statbuf->st_size);
+   memcpy(data->writep, path, len);
+   inode->size = ENVFS_32(len);
+   data->writep += PAD4(len);
+   debug("handling symlink %s size %ld namelen %d headerlen %d\n", 
filename + strlen(data->base),
+   len, namelen, ENVFS_32(inode->headerlen));
+   } else {
+   debug("handling file %s size %ld namelen %d headerlen %d\n", 
filename + strlen(data->base),
+   statbuf->st_size, namelen, ENVFS_32(inode->headerlen));
+
+   inode->size = ENVFS_32(statbuf->st_size);
+   fd = open(filename, O_RDONLY);
+   if (fd < 0) {
+   printf("Open %s %s\n", filename, errno_str());
+   goto out;
+   }
+
+   if (read(fd, data->writep, statbuf->st_size) < 
statbuf->st_size) {
+   perror("read");
+   goto out;
+   }
+   close(fd);
+
+   data->writep += PAD4(statbuf->st_size);
+   }
 
 out:
return 1;
@@ -277,22 +311,31 @@ int envfs_load(char *filename, char *dir)
goto out;
}
 
-   fd = open(str, O_WRONLY | O_CREAT | O_TRUNC, 0644);
-   free(str);
-   if (fd < 0) {
-   printf("Open %s\n", errno_str());
-   ret = fd;
-   goto out;
-   }
-
-   ret = write(fd, buf, inode_size);
-   if (ret < inode_size) {
-   perror("write");
-   ret = -errno;
+   if (S_ISLNK(ENVFS_32(inode_end->mode))) {
+   debug("symlink: %s -> %s\n", str, (char*)buf);
+   if (symlink((char*)buf, str) < 0) {
+   printf("symlink: %s -> %s :", str, (char*)buf);
+   perror("");
+   }
+   free(str);
+   } else {
+   fd = open(str, O_WRONLY | O_CREAT | O_TRUNC, 0644);
+   free(str);
+   if (fd < 0) {
+   printf("Open %s\n", errno_str());
+ 

[PATCH 19/19] defautenv: add support of symlink

2012-09-04 Thread Jean-Christophe PLAGNIOL-VILLARD
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD 
---
 common/Makefile |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/Makefile b/common/Makefile
index d74dffb..df9f301 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -58,7 +58,7 @@ ifneq ($(CONFIG_DEFAULT_ENVIRONMENT_PATH),"")
 DEFAULT_ENVIRONMENT_PATH += $(CONFIG_DEFAULT_ENVIRONMENT_PATH)
 endif
 
-ENV_FILES := $(shell cd $(srctree); for i in $(DEFAULT_ENVIRONMENT_PATH); do 
find $${i} -type f -exec readlink -f '{}' \;; done)
+ENV_FILES := $(shell cd $(srctree); for i in $(DEFAULT_ENVIRONMENT_PATH); do 
find $${i} -type f ; done)
 
 endif # ifdef CONFIG_DEFAULT_ENVIRONMENT
 
-- 
1.7.10.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 11/19] command: add readlink support

2012-09-04 Thread Jean-Christophe PLAGNIOL-VILLARD
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD 
---
 commands/Kconfig|6 
 commands/Makefile   |1 +
 commands/readlink.c |   80 +++
 3 files changed, 87 insertions(+)
 create mode 100644 commands/readlink.c

diff --git a/commands/Kconfig b/commands/Kconfig
index 92a8152..876f2f8 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -220,6 +220,12 @@ config CMD_DIRNAME
  Strip last component of file name and store the result in a
  environment variable
 
+config CMD_READLINK
+   tristate
+   prompt "readlink"
+   help
+ read value of a symbolic link
+
 endmenu
 
 menu "console   "
diff --git a/commands/Makefile b/commands/Makefile
index e9157bf..ab6c7ea 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -72,3 +72,4 @@ obj-$(CONFIG_CMD_AUTOMOUNT)   += automount.o
 obj-$(CONFIG_CMD_GLOBAL)   += global.o
 obj-$(CONFIG_CMD_BASENAME) += basename.o
 obj-$(CONFIG_CMD_DIRNAME)  += dirname.o
+obj-$(CONFIG_CMD_READLINK) += readlink.o
diff --git a/commands/readlink.c b/commands/readlink.c
new file mode 100644
index 000..d2671e0
--- /dev/null
+++ b/commands/readlink.c
@@ -0,0 +1,80 @@
+/*
+ * readlink.c - read value of a symbolic link
+ *
+ * Copyright (c) 2012 Jean-Christophe PLAGNIOL-VILLARD 
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static int do_readlink(int argc, char *argv[])
+{
+   char realname[PATH_MAX];
+   int canonicalize = 0;
+   int opt;
+
+   memset(realname, 0, PATH_MAX);
+
+   while ((opt = getopt(argc, argv, "f")) > 0) {
+   switch (opt) {
+   case 'f':
+   canonicalize = 1;
+   break;
+   }
+   }
+
+   if (argc < optind + 2)
+   return COMMAND_ERROR_USAGE;
+
+   if (readlink(argv[optind], realname, PATH_MAX - 1) < 0)
+   goto err;
+
+   if (canonicalize) {
+   char *buf = normalise_link(argv[optind], realname);
+
+   if (!buf)
+   goto err;
+   setenv(argv[optind + 1], buf);
+   free(buf);
+   } else {
+   setenv(argv[optind + 1], realname);
+   }
+
+   return 0;
+err:
+   setenv(argv[optind + 1], "");
+   return 1;
+}
+
+BAREBOX_CMD_HELP_START(readlink)
+BAREBOX_CMD_HELP_USAGE("readlink [-f] FILE REALNAME\n")
+BAREBOX_CMD_HELP_SHORT("read value of a symbolic link and store into 
$REALNAME\n")
+BAREBOX_CMD_HELP_SHORT("-f canonicalize by following first symlink");
+BAREBOX_CMD_HELP_END
+
+BAREBOX_CMD_START(readlink)
+   .cmd= do_readlink,
+   .usage  = "read value of a symbolic link",
+   BAREBOX_CMD_HELP(cmd_readlink_help)
+BAREBOX_CMD_END
-- 
1.7.10.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 13/19] ls: add symlink support to -l

2012-09-04 Thread Jean-Christophe PLAGNIOL-VILLARD
barebox:/ ls -l /env/init.d/
drwxrwxrwx  0 .
drwxrwxrwx  0 ..
lrwxrwxrwx 11 net -> ../boot/net

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD 
---
 commands/ls.c |   31 +--
 1 file changed, 21 insertions(+), 10 deletions(-)

diff --git a/commands/ls.c b/commands/ls.c
index fbcbadc..d36ef57 100644
--- a/commands/ls.c
+++ b/commands/ls.c
@@ -29,13 +29,24 @@
 #include 
 #include 
 
-static void ls_one(const char *path, struct stat *s)
+static void ls_one(const char *path, const char* fullname, struct stat *s)
 {
char modestr[11];
unsigned int namelen = strlen(path);
 
mkmodestr(s->st_mode, modestr);
-   printf("%s %10llu %*.*s\n", modestr, s->st_size, namelen, namelen, 
path);
+   printf("%s %10llu %*.*s", modestr, s->st_size, namelen, namelen, path);
+
+   if (S_ISLNK(s->st_mode)) {
+   char realname[PATH_MAX];
+
+   memset(realname, 0, PATH_MAX);
+
+   if (readlink(fullname, realname, PATH_MAX - 1) >= 0)
+   printf(" -> %s", realname);
+   }
+
+   puts("\n");
 }
 
 int ls(const char *path, ulong flags)
@@ -48,14 +59,14 @@ int ls(const char *path, ulong flags)
 
string_list_init(&sl);
 
-   if (stat(path, &s))
+   if (lstat(path, &s))
return -errno;
 
if (flags & LS_SHOWARG && s.st_mode & S_IFDIR)
printf("%s:\n", path);
 
if (!(s.st_mode & S_IFDIR)) {
-   ls_one(path, &s);
+   ls_one(path, path, &s);
return 0;
}
 
@@ -65,12 +76,12 @@ int ls(const char *path, ulong flags)
 
while ((d = readdir(dir))) {
sprintf(tmp, "%s/%s", path, d->d_name);
-   if (stat(tmp, &s))
+   if (lstat(tmp, &s))
goto out;
if (flags & LS_COLUMN)
string_list_add_sorted(&sl, d->d_name);
else
-   ls_one(d->d_name, &s);
+   ls_one(d->d_name, tmp, &s);
}
 
closedir(dir);
@@ -97,7 +108,7 @@ int ls(const char *path, ulong flags)
continue;
sprintf(tmp, "%s/%s", path, d->d_name);
 
-   if (stat(tmp, &s))
+   if (lstat(tmp, &s))
goto out;
if (s.st_mode & S_IFDIR) {
char *norm = normalise_path(tmp);
@@ -146,7 +157,7 @@ static int do_ls(int argc, char *argv[])
 
/* first pass: all files */
while (o < argc) {
-   ret = stat(argv[o], &s);
+   ret = lstat(argv[o], &s);
if (ret) {
printf("%s: %s: %s\n", argv[0],
argv[o], errno_str());
@@ -158,7 +169,7 @@ static int do_ls(int argc, char *argv[])
if (flags & LS_COLUMN)
string_list_add_sorted(&sl, argv[o]);
else
-   ls_one(argv[o], &s);
+   ls_one(argv[o], argv[o], &s);
}
 
o++;
@@ -173,7 +184,7 @@ static int do_ls(int argc, char *argv[])
 
/* second pass: directories */
while (o < argc) {
-   ret = stat(argv[o], &s);
+   ret = lstat(argv[o], &s);
if (ret) {
o++;
continue;
-- 
1.7.10.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 12/19] command: add ln support

2012-09-04 Thread Jean-Christophe PLAGNIOL-VILLARD
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD 
---
 commands/Kconfig  |4 
 commands/Makefile |1 +
 commands/ln.c |   51 +++
 3 files changed, 56 insertions(+)
 create mode 100644 commands/ln.c

diff --git a/commands/Kconfig b/commands/Kconfig
index 876f2f8..337f545 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -57,6 +57,10 @@ config CMD_READLINE
tristate
prompt "readline"
 
+config CMD_LN
+   tristate
+   prompt "ln"
+
 config CMD_TRUE
tristate
default y
diff --git a/commands/Makefile b/commands/Makefile
index ab6c7ea..ccebd7f 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -73,3 +73,4 @@ obj-$(CONFIG_CMD_GLOBAL)  += global.o
 obj-$(CONFIG_CMD_BASENAME) += basename.o
 obj-$(CONFIG_CMD_DIRNAME)  += dirname.o
 obj-$(CONFIG_CMD_READLINK) += readlink.o
+obj-$(CONFIG_CMD_LN)   += ln.o
diff --git a/commands/ln.c b/commands/ln.c
new file mode 100644
index 000..0237447
--- /dev/null
+++ b/commands/ln.c
@@ -0,0 +1,51 @@
+/*
+ * ln.c - make links between files
+ *
+ * Copyright (c) 2012 Jean-Christophe PLAGNIOL-VILLARD 
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static int do_ln(int argc, char *argv[])
+{
+   if (argc != 3)
+   return COMMAND_ERROR_USAGE;
+
+   if (symlink(argv[1], argv[2]) < 0) {
+   perror("ln");
+   return 1;
+   }
+   return 0;
+}
+
+BAREBOX_CMD_HELP_START(ln)
+BAREBOX_CMD_HELP_USAGE("ln SRC DEST\n")
+BAREBOX_CMD_HELP_SHORT("symlink - make a new name for a file\n")
+BAREBOX_CMD_HELP_END
+
+BAREBOX_CMD_START(ln)
+   .cmd= do_ln,
+   .usage  = "symlink - make a new name for a file",
+   BAREBOX_CMD_HELP(cmd_ln_help)
+BAREBOX_CMD_END
-- 
1.7.10.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 16/19] envfs: introduce version major and minor

2012-09-04 Thread Jean-Christophe PLAGNIOL-VILLARD
they are store in the super block at byte 16th and 17th.

set the verison at 0.1

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD 
---
 common/environment.c |2 ++
 include/envfs.h  |7 ++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/common/environment.c b/common/environment.c
index 52ce0de..8efed97 100644
--- a/common/environment.c
+++ b/common/environment.c
@@ -125,6 +125,8 @@ int envfs_save(char *filename, char *dirname)
 
super = (struct envfs_super *)buf;
super->magic = ENVFS_32(ENVFS_MAGIC);
+   super->major = ENVFS_MAJOR;
+   super->minor = ENVFS_MINOR;
super->size = ENVFS_32(size);
 
/* second pass: copy files to buffer */
diff --git a/include/envfs.h b/include/envfs.h
index ba976d6..c6df8c5 100644
--- a/include/envfs.h
+++ b/include/envfs.h
@@ -5,6 +5,9 @@
 #include 
 #endif
 
+#define ENVFS_MAJOR0
+#define ENVFS_MINOR1
+
 #define ENVFS_MAGIC0x798fba79  /* some random number */
 #define ENVFS_INODE_MAGIC  0x67a8c78d
 #define ENVFS_END_MAGIC0x6a87d6cd
@@ -29,8 +32,10 @@ struct envfs_super {
uint32_t priority;
uint32_t crc;   /* crc for the data */
uint32_t size;  /* size of data */
+   uint8_t major;  /* major */
+   uint8_t minor;  /* minor */
+   uint16_t future;/* reserved for future use */
uint32_t flags; /* feature flags */
-   uint32_t future;/* reserved for future use */
uint32_t sb_crc;/* crc for the superblock */
 };
 
-- 
1.7.10.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 09/19] nfs: add readlink support

2012-09-04 Thread Jean-Christophe PLAGNIOL-VILLARD
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD 
---
 MAKEALL  |1 +
 fs/nfs.c |   86 ++
 2 files changed, 59 insertions(+), 28 deletions(-)

diff --git a/MAKEALL b/MAKEALL
index 1ba4710..056a4d0 100755
--- a/MAKEALL
+++ b/MAKEALL
@@ -264,3 +264,4 @@ then
 else
do_build_target ${ARCH} $1
 fi
+exit $nb_errors
diff --git a/fs/nfs.c b/fs/nfs.c
index 79e667f..4a880cd 100644
--- a/fs/nfs.c
+++ b/fs/nfs.c
@@ -605,34 +605,6 @@ static int nfs_read_req(struct file_priv *priv, int 
offset, int readlen)
return 0;
 }
 
-#if 0
-static int nfs_readlink_reply(unsigned char *pkt, unsigned len)
-{
-   uint32_t *data;
-   char *path;
-   int rlen;
-// int ret;
-
-   data = (uint32_t *)(pkt + sizeof(struct rpc_reply));
-
-   data++;
-
-   rlen = ntohl(net_read_uint32(data)); /* new path length */
-
-   data++;
-   path = (char *)data;
-
-   if (*path != '/') {
-   strcat(nfs_path, "/");
-   strncat(nfs_path, path, rlen);
-   } else {
-   memcpy(nfs_path, path, rlen);
-   nfs_path[rlen] = 0;
-   }
-   return 0;
-}
-#endif
-
 static void nfs_handler(void *ctx, char *packet, unsigned len)
 {
char *pkt = net_eth_to_udp_payload(packet);
@@ -742,6 +714,63 @@ static struct file_priv *nfs_do_stat(struct device_d *dev, 
const char *filename,
return priv;
 }
 
+static int nfs_readlink_req(struct file_priv *priv, char* buf, size_t size)
+{
+   uint32_t data[1024];
+   uint32_t *p;
+   int len;
+   int ret;
+   char *path;
+   uint32_t *filedata;
+
+   p = &(data[0]);
+   p = rpc_add_credentials(p);
+
+   memcpy(p, priv->filefh, NFS_FHSIZE);
+   p += (NFS_FHSIZE / 4);
+
+   len = p - &(data[0]);
+
+   ret = rpc_req(priv->npriv, PROG_NFS, NFS_READLINK, data, len);
+   if (ret)
+   return ret;
+
+   filedata = nfs_packet + sizeof(struct rpc_reply);
+   filedata++;
+
+   len = ntohl(net_read_uint32(filedata)); /* new path length */
+   filedata++;
+
+   path = (char *)filedata;
+
+   if (len > size)
+   len = size;
+
+   memcpy(buf, path, len);
+
+   return 0;
+}
+
+static int nfs_readlink(struct device_d *dev, const char *filename,
+   char *realname, size_t size)
+{
+   struct file_priv *priv;
+   int ret;
+   struct stat s;
+
+   priv = nfs_do_stat(dev, filename, &s);
+   if (IS_ERR(priv))
+   return PTR_ERR(priv);
+
+   ret = nfs_readlink_req(priv, realname, size);
+   if (ret) {
+   nfs_do_close(priv);
+   return ret;
+   }
+
+   return 0;
+}
+
 static int nfs_open(struct device_d *dev, FILE *file, const char *filename)
 {
struct file_priv *priv;
@@ -1039,6 +1068,7 @@ static struct fs_driver_d nfs_driver = {
.rmdir = nfs_rmdir,
.write = nfs_write,
.truncate  = nfs_truncate,
+   .readlink  = nfs_readlink,
.flags = 0,
.drv = {
.probe  = nfs_probe,
-- 
1.7.10.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 08/19] ramfs: add symlink and readlink support

2012-09-04 Thread Jean-Christophe PLAGNIOL-VILLARD
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD 
---
 fs/ramfs.c |   61 ++--
 1 file changed, 55 insertions(+), 6 deletions(-)

diff --git a/fs/ramfs.c b/fs/ramfs.c
index 91d06b8..8f3b936 100644
--- a/fs/ramfs.c
+++ b/fs/ramfs.c
@@ -42,6 +42,7 @@ struct ramfs_inode {
struct ramfs_inode *parent;
struct ramfs_inode *next;
struct ramfs_inode *child;
+   char *symlink;
ulong mode;
 
struct handle_d *handle;
@@ -176,6 +177,7 @@ static void ramfs_put_inode(struct ramfs_inode *node)
data = tmp;
}
 
+   free(node->symlink);
free(node->name);
free(node);
 }
@@ -212,18 +214,38 @@ static struct ramfs_inode* node_insert(struct ramfs_inode 
*parent_node, const ch
 
 /* ---*/
 
-static int ramfs_create(struct device_d *dev, const char *pathname, mode_t 
mode)
+static int __ramfs_create(struct device_d *dev, const char *pathname,
+ mode_t mode, const char *symlink)
 {
struct ramfs_priv *priv = dev->priv;
struct ramfs_inode *node;
char *file;
+   char *__symlink = NULL;
 
node = rlookup_parent(priv, pathname, &file);
-   if (node) {
-   node_insert(node, file, mode);
-   return 0;
+   if (!node)
+   return -ENOENT;
+
+   if (symlink) {
+   __symlink = strdup(symlink);
+   if (!__symlink)
+   return -ENOMEM;
}
-   return -ENOENT;
+
+   node = node_insert(node, file, mode);
+   if (!node) {
+   free(__symlink);
+   return -ENOMEM;
+   }
+
+   node->symlink = __symlink;
+
+   return 0;
+}
+
+static int ramfs_create(struct device_d *dev, const char *pathname, mode_t 
mode)
+{
+   return __ramfs_create(dev, pathname, mode, NULL);
 }
 
 static int ramfs_unlink(struct device_d *dev, const char *pathname)
@@ -532,12 +554,37 @@ static int ramfs_stat(struct device_d *dev, const char 
*filename, struct stat *s
if (!node)
return -ENOENT;
 
-   s->st_size = node->size;
+   s->st_size = node->symlink ? strlen(node->symlink) : node->size;
s->st_mode = node->mode;
 
return 0;
 }
 
+static int ramfs_symlink(struct device_d *dev, const char *pathname,
+  const char *newpath)
+{
+   mode_t mode = S_IFLNK | S_IRWXU | S_IRWXG | S_IRWXO;
+
+   return __ramfs_create(dev, newpath, mode, pathname);
+}
+
+static int ramfs_readlink(struct device_d *dev, const char *pathname,
+   char *buf, size_t bufsiz)
+{
+   struct ramfs_priv *priv = dev->priv;
+   struct ramfs_inode *node = rlookup(priv, pathname);
+   int len;
+
+   if (!node || !node->symlink)
+   return -ENOENT;
+
+   len = min(bufsiz, strlen(node->symlink));
+
+   memcpy(buf, node->symlink, len);
+
+   return 0;
+}
+
 static int ramfs_probe(struct device_d *dev)
 {
struct ramfs_inode *n;
@@ -584,6 +631,8 @@ static struct fs_driver_d ramfs_driver = {
.readdir   = ramfs_readdir,
.closedir  = ramfs_closedir,
.stat  = ramfs_stat,
+   .symlink   = ramfs_symlink,
+   .readlink  = ramfs_readlink,
.flags = FS_DRIVER_NO_DEV,
.drv = {
.probe  = ramfs_probe,
-- 
1.7.10.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 15/19] recursive_action: add ACTION_FOLLOWLINKS support

2012-09-04 Thread Jean-Christophe PLAGNIOL-VILLARD
this is need to support symlink in envfs

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD 
---
 include/libbb.h|2 +-
 lib/recursive_action.c |7 ++-
 scripts/bareboxenv.c   |2 +-
 3 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/include/libbb.h b/include/libbb.h
index 110e8ec..47b2e08 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -14,7 +14,7 @@ char* last_char_is(const char *s, int c);
 
 enum {
ACTION_RECURSE = (1 << 0),
-   /* ACTION_FOLLOWLINKS = (1 << 1), - unused */
+   ACTION_FOLLOWLINKS= (1 << 1),
ACTION_DEPTHFIRST  = (1 << 2),
/*ACTION_REVERSE   = (1 << 3), - unused */
 };
diff --git a/lib/recursive_action.c b/lib/recursive_action.c
index 1ef758d..5bc2595 100644
--- a/lib/recursive_action.c
+++ b/lib/recursive_action.c
@@ -54,14 +54,19 @@ int recursive_action(const char *fileName,
const unsigned depth)
 {
struct stat statbuf;
+   unsigned follow;
int status;
DIR *dir;
struct dirent *next;
 
if (!fileAction) fileAction = true_action;
if (!dirAction) dirAction = true_action;
-   status = stat(fileName, &statbuf);
 
+   follow = ACTION_FOLLOWLINKS;
+   if (depth == 0)
+   follow = ACTION_FOLLOWLINKS;
+   follow &= flags;
+   status = (follow ? stat : lstat)(fileName, &statbuf);
if (status < 0) {
 #ifdef DEBUG_RECURS_ACTION
bb_error_msg("status=%d followLinks=%d TRUE=%d",
diff --git a/scripts/bareboxenv.c b/scripts/bareboxenv.c
index 866e345..f7f5351 100644
--- a/scripts/bareboxenv.c
+++ b/scripts/bareboxenv.c
@@ -73,7 +73,7 @@ char* last_char_is(const char *s, int c)
 
 enum {
ACTION_RECURSE = (1 << 0),
-   /* ACTION_FOLLOWLINKS = (1 << 1), - unused */
+   ACTION_FOLLOWLINKS = (1 << 1),
ACTION_DEPTHFIRST  = (1 << 2),
/*ACTION_REVERSE   = (1 << 3), - unused */
 };
-- 
1.7.10.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 14/19] dirname: add -V option to return only path related to the mountpoint

2012-09-04 Thread Jean-Christophe PLAGNIOL-VILLARD
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD 
---
 commands/dirname.c |   24 +---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/commands/dirname.c b/commands/dirname.c
index cf1d0a0..f34d88d 100644
--- a/commands/dirname.c
+++ b/commands/dirname.c
@@ -24,20 +24,38 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 
 static int do_dirname(int argc, char *argv[])
 {
-   if (argc != 3)
+   int opt;
+   int path_fs = 0;
+   int len = 0;
+
+   while ((opt = getopt(argc, argv, "V")) > 0) {
+   switch (opt) {
+   case 'V':
+   path_fs = 1;
+   break;
+   }
+   }
+
+   if (argc < optind + 2)
return COMMAND_ERROR_USAGE;
 
-   setenv(argv[2], dirname(argv[1]));
+   if (path_fs)
+   len = strlen(get_mounted_path(argv[optind]));
+
+   setenv(argv[optind + 1], dirname(argv[optind]) + len);
 
return 0;
 }
 
 BAREBOX_CMD_HELP_START(dirname)
-BAREBOX_CMD_HELP_USAGE("dirname NAME DIRNAME\n")
+BAREBOX_CMD_HELP_USAGE("dirname [-V] NAME DIRNAME\n")
 BAREBOX_CMD_HELP_SHORT("strip last componext of NAME and store into 
$DIRNAME\n")
+BAREBOX_CMD_HELP_SHORT("-V return the path relative to the mountpoint.\n")
 BAREBOX_CMD_HELP_END
 
 BAREBOX_CMD_START(dirname)
-- 
1.7.10.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 10/19] test: add -L support to test if it's a symbolic link

2012-09-04 Thread Jean-Christophe PLAGNIOL-VILLARD
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD 
---
 commands/test.c |   11 +--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/commands/test.c b/commands/test.c
index 9ffa892..18eeaab 100644
--- a/commands/test.c
+++ b/commands/test.c
@@ -43,6 +43,7 @@ typedef enum {
OPT_DIRECTORY,
OPT_FILE,
OPT_EXISTS,
+   OPT_SYMBOLIC_LINK,
OPT_MAX,
 } test_opts;
 
@@ -62,6 +63,7 @@ static char *test_options[] = {
[OPT_FILE]  = "-f",
[OPT_DIRECTORY] = "-d",
[OPT_EXISTS]= "-e",
+   [OPT_SYMBOLIC_LINK] = "-L",
 };
 
 static int parse_opt(const char *opt)
@@ -140,9 +142,10 @@ static int do_test(int argc, char *argv[])
case OPT_FILE:
case OPT_DIRECTORY:
case OPT_EXISTS:
+   case OPT_SYMBOLIC_LINK:
adv = 2;
if (ap[1] && *ap[1] != ']' && strlen(ap[1])) {
-   expr = stat(ap[1], &statbuf);
+   expr = (opt == OPT_SYMBOLIC_LINK ? lstat : 
stat)(ap[1], &statbuf);
if (expr < 0) {
expr = 0;
break;
@@ -160,6 +163,10 @@ static int do_test(int argc, char *argv[])
expr = 1;
break;
}
+   if (opt == OPT_SYMBOLIC_LINK && 
S_ISLNK(statbuf.st_mode)) {
+   expr = 1;
+   break;
+   }
}
break;
 
@@ -224,7 +231,7 @@ static const char *test_aliases[] = { "[", NULL};
 
 static const __maybe_unused char cmd_test_help[] =
 "Usage: test [OPTIONS]\n"
-"options: !, =, !=, -eq, -ne, -ge, -gt, -le, -lt, -o, -a, -z, -n, -d, -e, -f\n"
+"options: !, =, !=, -eq, -ne, -ge, -gt, -le, -lt, -o, -a, -z, -n, -d, -e, -f, 
-L\n"
 "see 'man test' on your PC for more information.\n";
 
 static const __maybe_unused char cmd_test_usage[] = "minimal test like 
/bin/sh";
-- 
1.7.10.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 05/19] fs: implement stat

2012-09-04 Thread Jean-Christophe PLAGNIOL-VILLARD
stat() stats the file pointed to by path and fills in buf.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD 
---
 fs/fs.c  |  105 ++
 include/fs.h |6 ++--
 2 files changed, 107 insertions(+), 4 deletions(-)

diff --git a/fs/fs.c b/fs/fs.c
index f46c606..dfe571a 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -26,6 +26,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -111,6 +112,61 @@ static int init_cwd(void)
 
 postcore_initcall(init_cwd);
 
+char *normalise_link(const char *pathname, const char *symlink)
+{
+   const char *buf = symlink;
+   char *path_free, *path;
+   char *absolute_path;
+   int point = 0;
+   int dir = 1;
+   int len;
+
+   if (symlink[0] == '/')
+   return strdup(symlink);
+
+   while (*buf == '.' || *buf == '/') {
+   if (*buf == '.') {
+   point++;
+   } else if (*buf == '/') {
+   point = 0;
+   dir++;
+   }
+   if (point > 2) {
+   buf -= 2;
+   break;
+   }
+   buf++;
+   }
+
+   path = path_free = strdup(pathname);
+   if (!path)
+   return NULL;
+
+   while(dir) {
+   path = dirname(path);
+   dir--;
+   }
+
+   len = strlen(buf) + strlen(path) + 1;
+   if (buf[0] != '/')
+   len++;
+
+   absolute_path = calloc(sizeof(char), len);
+
+   if (!absolute_path)
+   goto out;
+
+   strcat(absolute_path, path);
+   if (buf[0] != '/')
+   strcat(absolute_path, "/");
+   strcat(absolute_path, buf);
+
+out:
+   free(path_free);
+
+   return absolute_path;
+}
+
 char *normalise_path(const char *pathname)
 {
char *path = xzalloc(strlen(pathname) + strlen(cwd) + 2);
@@ -512,6 +568,42 @@ out:
 }
 EXPORT_SYMBOL(unlink);
 
+static char *realfile(const char *pathname, struct stat *s)
+{
+   char *path = normalise_path(pathname);
+   int ret;
+
+   ret = lstat(path, s);
+   if (ret)
+   goto out;
+
+   if (S_ISLNK(s->st_mode)) {
+   char tmp[PATH_MAX];
+   char *new_path;
+
+   memset(tmp, 0, PATH_MAX);
+
+   ret = readlink(path, tmp, PATH_MAX - 1);
+   if (ret < 0)
+   goto out;
+
+   new_path = normalise_link(path, tmp);
+   free(path);
+   if (!new_path)
+   return ERR_PTR(-ENOMEM);
+   path = new_path;
+
+   ret = lstat(path, s);
+   }
+
+   if (!ret)
+   return path;
+
+out:
+   free(path);
+   return ERR_PTR(ret);
+}
+
 int open(const char *pathname, int flags, ...)
 {
struct fs_device_d *fsdev;
@@ -1218,6 +1310,19 @@ int closedir(DIR *dir)
 }
 EXPORT_SYMBOL(closedir);
 
+int stat(const char *filename, struct stat *s)
+{
+   char *f;
+
+   f = realfile(filename, s);
+   if (IS_ERR(f))
+   return PTR_ERR(f);
+
+   free(f);
+   return 0;
+}
+EXPORT_SYMBOL(stat);
+
 int lstat(const char *filename, struct stat *s)
 {
struct device_d *dev;
diff --git a/include/fs.h b/include/fs.h
index d96de0e..07976d2 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -107,10 +107,7 @@ int unlink(const char *pathname);
 int close(int fd);
 int flush(int fd);
 int lstat(const char *filename, struct stat *s);
-static inline int stat(const char *filename, struct stat *s)
-{
-   return lstat(filename, s);
-}
+int stat(const char *filename, struct stat *s);
 int read(int fd, void *buf, size_t count);
 int ioctl(int fd, int request, void *buf);
 ssize_t write(int fd, const void *buf, size_t count);
@@ -169,6 +166,7 @@ void *read_file(const char *filename, size_t *size);
  * of "..", "." and double slashes. The returned string must be freed wit 
free().
  */
 char *normalise_path(const char *path);
+char *normalise_link(const char *pathname, const char* symlink);
 
 /* Register a new filesystem driver */
 int register_fs_driver(struct fs_driver_d *fsdrv);
-- 
1.7.10.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 07/19] fs: introduce get_mounted_path to get the path where a file is mounted

2012-09-04 Thread Jean-Christophe PLAGNIOL-VILLARD
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD 
---
 fs/fs.c  |9 +
 include/fs.h |2 ++
 2 files changed, 11 insertions(+)

diff --git a/fs/fs.c b/fs/fs.c
index 5bfd713..7e670ec 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -243,6 +243,15 @@ static struct fs_device_d *get_fsdevice_by_path(const char 
*path)
return fs_dev_root;
 }
 
+char *get_mounted_path(const char *path)
+{
+   struct fs_device_d *fdev;
+
+   fdev = get_fsdevice_by_path(path);
+
+   return fdev->path;
+}
+
 static FILE files[MAX_FILES];
 
 static FILE *get_file(void)
diff --git a/include/fs.h b/include/fs.h
index 07976d2..2c8b13b 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -168,6 +168,8 @@ void *read_file(const char *filename, size_t *size);
 char *normalise_path(const char *path);
 char *normalise_link(const char *pathname, const char* symlink);
 
+char *get_mounted_path(const char *path);
+
 /* Register a new filesystem driver */
 int register_fs_driver(struct fs_driver_d *fsdrv);
 
-- 
1.7.10.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 06/19] fs: open: add symlink support

2012-09-04 Thread Jean-Christophe PLAGNIOL-VILLARD
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD 
---
 fs/fs.c |   15 +++
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/fs/fs.c b/fs/fs.c
index dfe571a..5bfd713 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -609,13 +609,20 @@ int open(const char *pathname, int flags, ...)
struct fs_device_d *fsdev;
struct fs_driver_d *fsdrv;
FILE *f;
-   int exist_err;
+   int exist_err = 0;
struct stat s;
-   char *path = normalise_path(pathname);
-   char *freep = path;
+   char *path;
+   char *freep;
int ret;
 
-   exist_err = lstat(path, &s);
+   path = realfile(pathname, &s);
+
+   if (IS_ERR(path)) {
+   exist_err = PTR_ERR(path);
+   path = normalise_path(pathname);
+   }
+
+   freep = path;
 
if (!exist_err && S_ISDIR(s.st_mode)) {
ret = -EISDIR;
-- 
1.7.10.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 04/19] fs: add symlink support

2012-09-04 Thread Jean-Christophe PLAGNIOL-VILLARD
Limit it's support to existing file only

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD 
---
 fs/fs.c  |   51 +++
 include/fs.h |3 +++
 2 files changed, 54 insertions(+)

diff --git a/fs/fs.c b/fs/fs.c
index 323b6c2..f46c606 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -927,6 +927,57 @@ out:
 }
 EXPORT_SYMBOL(readlink);
 
+int symlink(const char *pathname, const char *newpath)
+{
+   struct fs_driver_d *fsdrv;
+   struct fs_device_d *fsdev;
+   char *p;
+   char *freep = normalise_path(pathname);
+   int ret;
+   struct stat s;
+
+   if (!freep)
+   return -ENOMEM;
+
+   if (!stat(freep, &s) && S_ISDIR(s.st_mode)) {
+   ret = -ENOSYS;
+   goto out;
+   }
+
+   free(freep);
+   freep = p = normalise_path(newpath);
+
+   if (!p)
+   return -ENOMEM;
+
+   ret = lstat(p, &s);
+   if (!ret) {
+   ret = -EEXIST;
+   goto out;
+   }
+
+   fsdev = get_fs_device_and_root_path(&p);
+   if (!fsdev) {
+   ret = -ENODEV;
+   goto out;
+   }
+   fsdrv = fsdev->driver;
+
+   if (fsdrv->symlink) {
+   ret = fsdrv->symlink(&fsdev->dev, pathname, p);
+   } else {
+   ret = -EPERM;
+   }
+
+out:
+   free(freep);
+   if (ret)
+   errno = -ret;
+
+   return ret;
+}
+EXPORT_SYMBOL(symlink);
+
 static int fs_match(struct device_d *dev, struct driver_d *drv)
 {
return strcmp(dev->name, drv->name) ? -1 : 0;
diff --git a/include/fs.h b/include/fs.h
index 98210cf..d96de0e 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -50,6 +50,8 @@ struct fs_driver_d {
/* Truncate a file to given size */
int (*truncate)(struct device_d *dev, FILE *f, ulong size);
 
+   int (*symlink)(struct device_d *dev, const char *pathname,
+  const char *newpath);
int (*readlink)(struct device_d *dev, const char *pathname, char *name,
size_t size);
 
@@ -131,6 +133,7 @@ DIR *opendir(const char *pathname);
 struct dirent *readdir(DIR *dir);
 int closedir(DIR *dir);
 
+int symlink(const char *pathname, const char *newpath);
 int readlink(const char *path, char *buf, size_t bufsiz);
 
 int mount (const char *device, const char *fsname, const char *path);
-- 
1.7.10.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 02/19] fs: fix rmdir with symlink

2012-09-04 Thread Jean-Christophe PLAGNIOL-VILLARD
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD 
---
 fs/fs.c |6 ++
 1 file changed, 6 insertions(+)

diff --git a/fs/fs.c b/fs/fs.c
index 6a85513..914df5a 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -1253,6 +1253,12 @@ int rmdir (const char *pathname)
char *freep = p;
int ret;
 
+   ret = path_check_prereq(pathname, S_IFLNK);
+   if (!ret) {
+   ret = -ENOTDIR;
+   goto out;
+   }
+
ret = path_check_prereq(pathname, S_IFDIR | S_UB_IS_EMPTY);
if (ret)
goto out;
-- 
1.7.10.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 03/19] fs: rename stat to lstat as we implement lstat

2012-09-04 Thread Jean-Christophe PLAGNIOL-VILLARD
For compatibility put a inline on lstat for stat until we have the symlink
support.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD 
---
 fs/fs.c  |   10 +-
 include/fs.h |6 +-
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/fs/fs.c b/fs/fs.c
index 914df5a..323b6c2 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -392,7 +392,7 @@ static int path_check_prereq(const char *path, unsigned int 
flags)
unsigned int m;
int ret = 0;
 
-   if (stat(path, &s)) {
+   if (lstat(path, &s)) {
if (flags & S_UB_DOES_NOT_EXIST)
goto out;
ret = -ENOENT;
@@ -434,7 +434,7 @@ static int parent_check_directory(const char *path)
int ret;
char *dir = dirname(xstrdup(path));
 
-   ret = stat(dir, &s);
+   ret = lstat(dir, &s);
 
free(dir);
 
@@ -523,7 +523,7 @@ int open(const char *pathname, int flags, ...)
char *freep = path;
int ret;
 
-   exist_err = stat(path, &s);
+   exist_err = lstat(path, &s);
 
if (!exist_err && S_ISDIR(s.st_mode)) {
ret = -EISDIR;
@@ -1167,7 +1167,7 @@ int closedir(DIR *dir)
 }
 EXPORT_SYMBOL(closedir);
 
-int stat(const char *filename, struct stat *s)
+int lstat(const char *filename, struct stat *s)
 {
struct device_d *dev;
struct fs_driver_d *fsdrv;
@@ -1206,7 +1206,7 @@ out:
 
return ret;
 }
-EXPORT_SYMBOL(stat);
+EXPORT_SYMBOL(lstat);
 
 int mkdir (const char *pathname, mode_t mode)
 {
diff --git a/include/fs.h b/include/fs.h
index 906d192..98210cf 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -104,7 +104,11 @@ int creat(const char *pathname, mode_t mode);
 int unlink(const char *pathname);
 int close(int fd);
 int flush(int fd);
-int stat(const char *filename, struct stat *s);
+int lstat(const char *filename, struct stat *s);
+static inline int stat(const char *filename, struct stat *s)
+{
+   return lstat(filename, s);
+}
 int read(int fd, void *buf, size_t count);
 int ioctl(int fd, int request, void *buf);
 ssize_t write(int fd, const void *buf, size_t count);
-- 
1.7.10.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 01/19] fs: add readlink support

2012-09-04 Thread Jean-Christophe PLAGNIOL-VILLARD
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD 
---
 fs/fs.c  |   37 +
 include/fs.h |5 +
 2 files changed, 42 insertions(+)

diff --git a/fs/fs.c b/fs/fs.c
index 0b376a5..6a85513 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -890,6 +890,43 @@ int close(int fd)
 }
 EXPORT_SYMBOL(close);
 
+int readlink(const char *pathname, char *buf, size_t bufsiz)
+{
+   struct fs_driver_d *fsdrv;
+   struct fs_device_d *fsdev;
+   char *p = normalise_path(pathname);
+   char *freep = p;
+   int ret;
+
+   ret = path_check_prereq(pathname, S_IFLNK);
+   if (ret)
+   goto out;
+
+   fsdev = get_fs_device_and_root_path(&p);
+   if (!fsdev) {
+   ret = -ENODEV;
+   goto out;
+   }
+   fsdrv = fsdev->driver;
+
+   if (fsdrv->readlink)
+   ret = fsdrv->readlink(&fsdev->dev, p, buf, bufsiz);
+   else
+   ret = -ENOSYS;
+
+   if (ret)
+   goto out;
+
+out:
+   free(freep);
+
+   if (ret)
+   errno = -ret;
+
+   return ret;
+}
+EXPORT_SYMBOL(readlink);
+
 static int fs_match(struct device_d *dev, struct driver_d *drv)
 {
return strcmp(dev->name, drv->name) ? -1 : 0;
diff --git a/include/fs.h b/include/fs.h
index c0b9f71..906d192 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -50,6 +50,9 @@ struct fs_driver_d {
/* Truncate a file to given size */
int (*truncate)(struct device_d *dev, FILE *f, ulong size);
 
+   int (*readlink)(struct device_d *dev, const char *pathname, char *name,
+   size_t size);
+
int (*open)(struct device_d *dev, FILE *f, const char *pathname);
int (*close)(struct device_d *dev, FILE *f);
int (*read)(struct device_d *dev, FILE *f, void *buf, size_t size);
@@ -124,6 +127,8 @@ DIR *opendir(const char *pathname);
 struct dirent *readdir(DIR *dir);
 int closedir(DIR *dir);
 
+int readlink(const char *path, char *buf, size_t bufsiz);
+
 int mount (const char *device, const char *fsname, const char *path);
 int umount(const char *pathname);
 
-- 
1.7.10.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 00/18 v5] fs: add symlink and readlink support

2012-09-04 Thread Jean-Christophe PLAGNIOL-VILLARD
HI,

v5:
fix rmdir
fix test -L

v4:
 drop the mounted path added to absolute symlink

v3:
 - fix support
   mkdir mymount
   mount -t ramfs none mymount/
   ln /env/boot/net /mymount/link

 - addres comments

v2:
 addres comments

please pull
The following changes since commit 5b1583d994c0e63b4588a75b631011e2bf41bab8:

  nhk8815: fix nand IO_DATA end resource (2012-09-03 11:06:49 +0200)

are available in the git repository at:

  git://git.jcrosoft.org/barebox.git tags/fs-symlink

for you to fetch changes up to b65e60792376bb209adfa128e1783cf67af9f13b:

  defautenv: add support of symlink (2012-09-05 03:22:14 +0800)


fs: add symlink and readlink support

This patch series introduce the support of symlink and readlink at

1) vfs level

2) libc API
 - symlink
 - readlink

3) commands
 - ln
 - readlink

3) filesystem
 - ramfs
 - nfs
 - envfs

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD 


Jean-Christophe PLAGNIOL-VILLARD (19):
  fs: add readlink support
  fs: fix rmdir with symlink
  fs: rename stat to lstat as we implement lstat
  fs: add symlink support
  fs: implement stat
  fs: open: add symlink support
  fs: introduce get_mounted_path to get the path where a file is mounted
  ramfs: add symlink and readlink support
  nfs: add readlink support
  test: add -L support to test if it's a symbolic link
  command: add readlink support
  command: add ln support
  ls: add symlink support to -l
  dirname: add -V option to return only path related to the mountpoint
  recursive_action: add ACTION_FOLLOWLINKS support
  envfs: introduce version major and minor
  envfs: add support of variable inode size
  envfs: add support of symlink
  defautenv: add support of symlink

 MAKEALL|1 +
 commands/Kconfig   |   10 
 commands/Makefile  |2 ++
 commands/dirname.c |   24 +++---
 commands/ln.c  |   51 ++
 commands/ls.c  |   31 +++
 commands/readlink.c|   80 
+++
 commands/test.c|   11 +++--
 common/Makefile|2 +-
 common/environment.c   |  150 
++
 fs/fs.c|  229 
++--
 fs/nfs.c   |   86 
++-
 fs/ramfs.c |   61 -
 include/envfs.h|   15 +--
 include/fs.h   |   12 +
 include/libbb.h|2 +-
 lib/recursive_action.c |7 +-
 scripts/bareboxenv.c   |2 +-
 18 files changed, 676 insertions(+), 100 deletions(-)
 create mode 100644 commands/ln.c
 create mode 100644 commands/readlink.c

Best Regards,
J.

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


MLO doesn't work, rest is ok

2012-09-04 Thread Norbert Roos

Hello,

I just wanted to try the freshly generated MLO and barebox.bin on my 
Phytec PCM049 board (OMAP4 based). Copied both files to the FAT 
partition on the SD card.


Unfortunately it doesn't boot, after trying to boot from SD card the ROM 
boot loader oviously skips to booting from UART.


When i replace the MLO with a different one (downloaded a compiled one), 
my generated barebox.bin gets loaded and everything's fine.


Is there a simple way for debugging it? It seems like the MLO does not 
get executed, as the ROM boot skips to UART boot...


bye
Norbert

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH v3] xload: get barebox size from barebox_arm_head

2012-09-04 Thread Jean-Christophe PLAGNIOL-VILLARD
On 14:27 Tue 04 Sep , Jan Weitzel wrote:
> Am Dienstag, den 04.09.2012, 11:28 +0200 schrieb Sascha Hauer:
> > On Tue, Sep 04, 2012 at 09:34:22AM +0200, Jan Weitzel wrote:
> > > Am Mittwoch, den 29.08.2012, 14:21 +0200 schrieb Jean-Christophe
> > > > > +unsigned int get_image_size(void *head)
> > > > > +{
> > > > > + unsigned int ret = 0;
> > > > > + unsigned int *psize = head + HEAD_SIZE_OFFSET;
> > > > > + const char *pmagic = head + HEAD_MAGICWORD_OFFSET;
> > > > > +
> > > > > + if (!strcmp(pmagic, "barebox"))
> > > > > + ret = *psize;
> > > > > + debug("Detected barebox image size %u\n", ret);
> > > > factorise the code with filetype
> > > What exactly do you mean? I could factorise it by boot source (mmc / 
> > > nand) with complete omap_xload_boot_nand.
> > 
> > He means that you should use file_detect_type() To detect whether it's a
> > barebox image.
> > I'm unsure I share this opinion. After detecting that it's a barebox
> > file you have to look into the header anyway to get the actual size.
> I wasn't aware of this function. I would like to avoid adding
> CONFIG_FILETYPE to MLO config.

so factorize the detection of the barebox-arm in a header share by both

duplication of the code NACK

Best Regards,
J.

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH v3] xload: get barebox size from barebox_arm_head

2012-09-04 Thread Jan Weitzel
Am Dienstag, den 04.09.2012, 11:28 +0200 schrieb Sascha Hauer:
> On Tue, Sep 04, 2012 at 09:34:22AM +0200, Jan Weitzel wrote:
> > Am Mittwoch, den 29.08.2012, 14:21 +0200 schrieb Jean-Christophe
> > > > +unsigned int get_image_size(void *head)
> > > > +{
> > > > +   unsigned int ret = 0;
> > > > +   unsigned int *psize = head + HEAD_SIZE_OFFSET;
> > > > +   const char *pmagic = head + HEAD_MAGICWORD_OFFSET;
> > > > +
> > > > +   if (!strcmp(pmagic, "barebox"))
> > > > +   ret = *psize;
> > > > +   debug("Detected barebox image size %u\n", ret);
> > > factorise the code with filetype
> > What exactly do you mean? I could factorise it by boot source (mmc / nand) 
> > with complete omap_xload_boot_nand.
> 
> He means that you should use file_detect_type() To detect whether it's a
> barebox image.
> I'm unsure I share this opinion. After detecting that it's a barebox
> file you have to look into the header anyway to get the actual size.
I wasn't aware of this function. I would like to avoid adding
CONFIG_FILETYPE to MLO config.
Jan
> Sascha
> 



___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH v3 1/2] mfd: add stmpe-i2c driver

2012-09-04 Thread Marc Kleine-Budde
On 09/04/2012 11:58 AM, Steffen Trumtrar wrote:
> The stmpe mfds can be connected via i2c and spi. This driver provides the 
> basic
> infrastructure for the i2c kind. It can be added as a normal i2c-device in the
> board code. To enable functions a platform_data struct has to be provided, 
> that
> describes what parts of the chip are to be used.
> 
> Signed-off-by: Steffen Trumtrar 
> ---
>  drivers/mfd/Kconfig |4 ++
>  drivers/mfd/Makefile|1 +
>  drivers/mfd/stmpe-i2c.c |  153 
> +++
>  include/mfd/stmpe-i2c.h |   56 +
>  4 files changed, 214 insertions(+)
>  create mode 100644 drivers/mfd/stmpe-i2c.c
>  create mode 100644 include/mfd/stmpe-i2c.h
> 
> diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
> index af67935..20eef86 100644
> --- a/drivers/mfd/Kconfig
> +++ b/drivers/mfd/Kconfig
> @@ -33,4 +33,8 @@ config I2C_TWL6030
>   select I2C_TWLCORE
>   bool "TWL6030 driver"
>  
> +config I2C_STMPE
> + depends on I2C
> + bool "STMPE-i2c driver"
> +
>  endmenu
> diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
> index e11223b..792ae2d 100644
> --- a/drivers/mfd/Makefile
> +++ b/drivers/mfd/Makefile
> @@ -6,3 +6,4 @@ obj-$(CONFIG_I2C_LP3972) += lp3972.o
>  obj-$(CONFIG_I2C_TWLCORE) += twl-core.o
>  obj-$(CONFIG_I2C_TWL4030) += twl4030.o
>  obj-$(CONFIG_I2C_TWL6030) += twl6030.o
> +obj-$(CONFIG_I2C_STMPE) += stmpe-i2c.o
> diff --git a/drivers/mfd/stmpe-i2c.c b/drivers/mfd/stmpe-i2c.c
> new file mode 100644
> index 000..53b3d06
> --- /dev/null
> +++ b/drivers/mfd/stmpe-i2c.c
> @@ -0,0 +1,153 @@
> +/*
> + * Copyright (C) 2012 Pengutronix
> + * Steffen Trumtrar 
> + *
> + * 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.
> + *
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +#include 
> +
> +#define DRIVERNAME   "stmpe-i2c"
> +
> +#define to_stmpe(a)  container_of(a, struct stmpe, cdev)
> +
> +int stmpe_reg_read(struct stmpe *stmpe, u32 reg, u8 *val)
> +{
> + int ret;
> +
> + ret = i2c_read_reg(stmpe->client, reg, val, 1);
> +
> + return ret == 1 ? 0 : ret;
> +}
> +EXPORT_SYMBOL(stmpe_reg_read)
> +
> +int stmpe_reg_write(struct stmpe *stmpe, u32 reg, u8 val)
> +{
> + int ret;
> +
> + ret = i2c_write_reg(stmpe->client, reg, &val, 1);
> +
> + return ret == 1 ? 0 : ret;
> +}
> +EXPORT_SYMBOL(stmpe_reg_write)
> +
> +int stmpe_set_bits(struct stmpe *stmpe, u32 reg, u8 mask, u8 val)
> +{
> + u8 tmp;
> + int err;
> +
> + err = stmpe_reg_read(stmpe, reg, &tmp);
> + tmp = (tmp & ~mask) | val;
> +
> + if (!err)
> + err = stmpe_reg_write(stmpe, reg, tmp);
> +
> + return err;
> +}
> +EXPORT_SYMBOL(stmpe_set_bits);
> +
> +static ssize_t stmpe_read(struct cdev *cdev, void *_buf, size_t count, 
> loff_t offset, ulong flags)
> +{
> + struct stmpe *stmpe = to_stmpe(cdev);
> + u8 *buf = _buf;
> + size_t i = count;
> + int err;
> +
> + while (i) {
> + err = stmpe_reg_read(stmpe, offset, buf);
> + if (err)
> + return (ssize_t)err;
> + buf++;
> + i--;
> + offset++;
> + }
> +
> + return count;
> +}
> +
> +static ssize_t stmpe_write(struct cdev *cdev, const void *_buf, size_t 
> count, loff_t offset, ulong flags)
> +{
> + struct stmpe *stmpe = to_stmpe(cdev);
> + const u8 *buf = _buf;
> + size_t i = count;
> + int err;
> +
> + while (i) {
> + err = stmpe_reg_write(stmpe, offset, *buf);
> + if (err)
> + return (ssize_t)err;
> + buf++;
> + i--;
> + offset++;
> + }
> +
> + return count;
> +}
> +
> +static struct file_operations stmpe_fops = {
> + .lseek  = dev_lseek_default,
> + .read   = stmpe_read,
> + .write  = stmpe_write,
> +};
> +
> +static struct stmpe_client_info i2c_ci = {
> + .read_reg = stmpe_reg_read,
> + .write_reg = stmpe_reg_write,
> +};
> +
> +static int stmpe_probe(struct device_d *dev)
> +{
> + struct stmpe_platform_data *pdata = dev->platform_data;
> + struct stmpe *stmpe_dev;
> +
> + if (!pdata) {
> + dev_dbg(dev, "no platform data\n");
> + return -ENODEV;
> + }
> +
> + stmpe_dev = xzalloc(sizeof(struct stmpe));
> + stmpe_dev->cdev.name = DRIVERNAME;
> + stmpe_dev->client = to_i2c_client(dev);
> + stmpe_dev->cdev.size = 191; /

[PATCH v3 0/2] Add stmpe mfd

2012-09-04 Thread Steffen Trumtrar
Hi,

this fixes some issues with the v2 patches:
- remove unused variables
- allow multiple instances of stmpe-i2c
- remove unnecessary castings

Thanks to Sascha and Mark for reviewing.

Steffen Trumtrar (2):
  mfd: add stmpe-i2c driver
  gpio: add driver for stmpe io-expander

 drivers/Kconfig   |1 +
 drivers/gpio/Kconfig  |9 +++
 drivers/gpio/Makefile |2 +
 drivers/gpio/gpio-stmpe.c |  162 +
 drivers/mfd/Kconfig   |4 ++
 drivers/mfd/Makefile  |1 +
 drivers/mfd/stmpe-i2c.c   |  153 ++
 include/mfd/stmpe-i2c.h   |   56 
 8 files changed, 388 insertions(+)
 create mode 100644 drivers/gpio/Kconfig
 create mode 100644 drivers/gpio/Makefile
 create mode 100644 drivers/gpio/gpio-stmpe.c
 create mode 100644 drivers/mfd/stmpe-i2c.c
 create mode 100644 include/mfd/stmpe-i2c.h

-- 
1.7.10.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v3 2/2] gpio: add driver for stmpe io-expander

2012-09-04 Thread Steffen Trumtrar
Signed-off-by: Steffen Trumtrar 
---
 drivers/Kconfig   |1 +
 drivers/gpio/Kconfig  |9 +++
 drivers/gpio/Makefile |2 +
 drivers/gpio/gpio-stmpe.c |  162 +
 4 files changed, 174 insertions(+)
 create mode 100644 drivers/gpio/Kconfig
 create mode 100644 drivers/gpio/Makefile
 create mode 100644 drivers/gpio/gpio-stmpe.c

diff --git a/drivers/Kconfig b/drivers/Kconfig
index 883b0e7..adf8fcd 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -18,5 +18,6 @@ source "drivers/input/Kconfig"
 source "drivers/watchdog/Kconfig"
 source "drivers/pwm/Kconfig"
 source "drivers/dma/Kconfig"
+source "drivers/gpio/Kconfig"
 
 endmenu
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
new file mode 100644
index 000..acfd4ef
--- /dev/null
+++ b/drivers/gpio/Kconfig
@@ -0,0 +1,9 @@
+menu "GPIO  "
+
+config STMPE_GPIO
+   depends on I2C
+   depends on GPIOLIB
+   select I2C_STMPE
+   bool "STMPE GPIO Expander"
+
+endmenu
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
new file mode 100644
index 000..da1bc21
--- /dev/null
+++ b/drivers/gpio/Makefile
@@ -0,0 +1,2 @@
+obj-y += gpio.o
+obj-$(CONFIG_STMPE_GPIO) += gpio-stmpe.o
diff --git a/drivers/gpio/gpio-stmpe.c b/drivers/gpio/gpio-stmpe.c
new file mode 100644
index 000..0746458
--- /dev/null
+++ b/drivers/gpio/gpio-stmpe.c
@@ -0,0 +1,162 @@
+/*
+ * Copyright (C) 2012 Pengutronix
+ * Steffen Trumtrar 
+ *
+ * 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.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define GPIO_BASE  0x80
+#define GPIO_SET   (GPIO_BASE + 0x02)
+#define GPIO_CLR   (GPIO_BASE + 0x04)
+#define GPIO_MP(GPIO_BASE + 0x06)
+#define GPIO_SET_DIR   (GPIO_BASE + 0x08)
+#define GPIO_ED(GPIO_BASE + 0x0a)
+#define GPIO_RE(GPIO_BASE + 0x0c)
+#define GPIO_FE(GPIO_BASE + 0x0e)
+#define GPIO_PULL_UP   (GPIO_BASE + 0x10)
+#define GPIO_AF(GPIO_BASE + 0x12)
+#define GPIO_LT(GPIO_BASE + 0x16)
+
+#define OFFSET(gpio)   (0xff & (1 << (gpio)) ? 1 : 0)
+
+struct stmpe_gpio_chip {
+   struct gpio_chip chip;
+   struct stmpe_client_info *ci;
+};
+
+static void stmpe_gpio_set_value(struct gpio_chip *chip, unsigned gpio, int 
value)
+{
+   struct stmpe_gpio_chip *stmpegpio = container_of(chip, struct 
stmpe_gpio_chip, chip);
+   struct stmpe_client_info *ci = (struct stmpe_client_info 
*)stmpegpio->ci;
+   int ret;
+   u8 val;
+
+   ci->read_reg(ci->stmpe, GPIO_MP + OFFSET(gpio), &val);
+
+   val |= 1 << (gpio % 8);
+
+   if (value)
+   ret = ci->write_reg(ci->stmpe, GPIO_SET + OFFSET(gpio), val);
+   else
+   ret = ci->write_reg(ci->stmpe, GPIO_CLR + OFFSET(gpio), val);
+
+   if (ret)
+   dev_err(chip->dev, "write failed!\n");
+}
+
+static int stmpe_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
+{
+   struct stmpe_gpio_chip *stmpegpio = container_of(chip, struct 
stmpe_gpio_chip, chip);
+   struct stmpe_client_info *ci = (struct stmpe_client_info 
*)stmpegpio->ci;
+   int ret;
+   u8 val;
+
+   ci->read_reg(ci->stmpe, GPIO_SET_DIR + OFFSET(gpio), &val);
+   val &= ~(1 << (gpio % 8));
+   ret = ci->write_reg(ci->stmpe, GPIO_SET_DIR + OFFSET(gpio), val);
+
+   if (ret)
+   dev_err(chip->dev, "couldn't change direction. Write 
failed!\n");
+
+   return ret;
+}
+
+static int stmpe_gpio_direction_output(struct gpio_chip *chip, unsigned gpio, 
int value)
+{
+   struct stmpe_gpio_chip *stmpegpio = container_of(chip, struct 
stmpe_gpio_chip, chip);
+   struct stmpe_client_info *ci = (struct stmpe_client_info 
*)stmpegpio->ci;
+   int ret;
+   u8 val;
+
+   ci->read_reg(ci->stmpe, GPIO_SET_DIR + OFFSET(gpio), &val);
+   val |= 1 << (gpio % 8);
+   ret = ci->write_reg(ci->stmpe, GPIO_SET_DIR + OFFSET(gpio), val);
+
+   stmpe_gpio_set_value(chip, gpio, value);
+
+   if (ret)
+   dev_err(chip->dev, "couldn't change direction. Write 
failed!\n");
+
+   return ret;
+}
+
+static int stmpe_gpio_get_value(struct gpio_chip *chip, unsigned gpio)
+{
+   struct stmpe_gpio_chip *stmpegpio = container_of(chip, struct 
stmpe_gpio_chip, chip);
+   struct stmpe_client_info *ci = (struct stmpe_client_info 
*)stmpegpio->ci;
+   u8 val;
+   int ret;
+
+   ret = ci->read_reg(c

[PATCH v3 1/2] mfd: add stmpe-i2c driver

2012-09-04 Thread Steffen Trumtrar
The stmpe mfds can be connected via i2c and spi. This driver provides the basic
infrastructure for the i2c kind. It can be added as a normal i2c-device in the
board code. To enable functions a platform_data struct has to be provided, that
describes what parts of the chip are to be used.

Signed-off-by: Steffen Trumtrar 
---
 drivers/mfd/Kconfig |4 ++
 drivers/mfd/Makefile|1 +
 drivers/mfd/stmpe-i2c.c |  153 +++
 include/mfd/stmpe-i2c.h |   56 +
 4 files changed, 214 insertions(+)
 create mode 100644 drivers/mfd/stmpe-i2c.c
 create mode 100644 include/mfd/stmpe-i2c.h

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index af67935..20eef86 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -33,4 +33,8 @@ config I2C_TWL6030
select I2C_TWLCORE
bool "TWL6030 driver"
 
+config I2C_STMPE
+   depends on I2C
+   bool "STMPE-i2c driver"
+
 endmenu
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index e11223b..792ae2d 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -6,3 +6,4 @@ obj-$(CONFIG_I2C_LP3972) += lp3972.o
 obj-$(CONFIG_I2C_TWLCORE) += twl-core.o
 obj-$(CONFIG_I2C_TWL4030) += twl4030.o
 obj-$(CONFIG_I2C_TWL6030) += twl6030.o
+obj-$(CONFIG_I2C_STMPE) += stmpe-i2c.o
diff --git a/drivers/mfd/stmpe-i2c.c b/drivers/mfd/stmpe-i2c.c
new file mode 100644
index 000..53b3d06
--- /dev/null
+++ b/drivers/mfd/stmpe-i2c.c
@@ -0,0 +1,153 @@
+/*
+ * Copyright (C) 2012 Pengutronix
+ * Steffen Trumtrar 
+ *
+ * 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.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+#define DRIVERNAME "stmpe-i2c"
+
+#define to_stmpe(a)container_of(a, struct stmpe, cdev)
+
+int stmpe_reg_read(struct stmpe *stmpe, u32 reg, u8 *val)
+{
+   int ret;
+
+   ret = i2c_read_reg(stmpe->client, reg, val, 1);
+
+   return ret == 1 ? 0 : ret;
+}
+EXPORT_SYMBOL(stmpe_reg_read)
+
+int stmpe_reg_write(struct stmpe *stmpe, u32 reg, u8 val)
+{
+   int ret;
+
+   ret = i2c_write_reg(stmpe->client, reg, &val, 1);
+
+   return ret == 1 ? 0 : ret;
+}
+EXPORT_SYMBOL(stmpe_reg_write)
+
+int stmpe_set_bits(struct stmpe *stmpe, u32 reg, u8 mask, u8 val)
+{
+   u8 tmp;
+   int err;
+
+   err = stmpe_reg_read(stmpe, reg, &tmp);
+   tmp = (tmp & ~mask) | val;
+
+   if (!err)
+   err = stmpe_reg_write(stmpe, reg, tmp);
+
+   return err;
+}
+EXPORT_SYMBOL(stmpe_set_bits);
+
+static ssize_t stmpe_read(struct cdev *cdev, void *_buf, size_t count, loff_t 
offset, ulong flags)
+{
+   struct stmpe *stmpe = to_stmpe(cdev);
+   u8 *buf = _buf;
+   size_t i = count;
+   int err;
+
+   while (i) {
+   err = stmpe_reg_read(stmpe, offset, buf);
+   if (err)
+   return (ssize_t)err;
+   buf++;
+   i--;
+   offset++;
+   }
+
+   return count;
+}
+
+static ssize_t stmpe_write(struct cdev *cdev, const void *_buf, size_t count, 
loff_t offset, ulong flags)
+{
+   struct stmpe *stmpe = to_stmpe(cdev);
+   const u8 *buf = _buf;
+   size_t i = count;
+   int err;
+
+   while (i) {
+   err = stmpe_reg_write(stmpe, offset, *buf);
+   if (err)
+   return (ssize_t)err;
+   buf++;
+   i--;
+   offset++;
+   }
+
+   return count;
+}
+
+static struct file_operations stmpe_fops = {
+   .lseek  = dev_lseek_default,
+   .read   = stmpe_read,
+   .write  = stmpe_write,
+};
+
+static struct stmpe_client_info i2c_ci = {
+   .read_reg = stmpe_reg_read,
+   .write_reg = stmpe_reg_write,
+};
+
+static int stmpe_probe(struct device_d *dev)
+{
+   struct stmpe_platform_data *pdata = dev->platform_data;
+   struct stmpe *stmpe_dev;
+
+   if (!pdata) {
+   dev_dbg(dev, "no platform data\n");
+   return -ENODEV;
+   }
+
+   stmpe_dev = xzalloc(sizeof(struct stmpe));
+   stmpe_dev->cdev.name = DRIVERNAME;
+   stmpe_dev->client = to_i2c_client(dev);
+   stmpe_dev->cdev.size = 191; /* 191 known registers */
+   stmpe_dev->cdev.dev = dev;
+   stmpe_dev->cdev.ops = &stmpe_fops;
+   stmpe_dev->pdata = pdata;
+   dev->priv = stmpe_dev;
+   i2c_ci.stmpe = stmpe_dev;
+
+   if (pdata->blocks &= STMPE_BLOCK_GPIO)
+   add_generic_de

Re: [PATCH v3] xload: get barebox size from barebox_arm_head

2012-09-04 Thread Sascha Hauer
On Tue, Sep 04, 2012 at 09:34:22AM +0200, Jan Weitzel wrote:
> Am Mittwoch, den 29.08.2012, 14:21 +0200 schrieb Jean-Christophe
> > > +unsigned int get_image_size(void *head)
> > > +{
> > > + unsigned int ret = 0;
> > > + unsigned int *psize = head + HEAD_SIZE_OFFSET;
> > > + const char *pmagic = head + HEAD_MAGICWORD_OFFSET;
> > > +
> > > + if (!strcmp(pmagic, "barebox"))
> > > + ret = *psize;
> > > + debug("Detected barebox image size %u\n", ret);
> > factorise the code with filetype
> What exactly do you mean? I could factorise it by boot source (mmc / nand) 
> with complete omap_xload_boot_nand.

He means that you should use file_detect_type() To detect whether it's a
barebox image.
I'm unsure I share this opinion. After detecting that it's a barebox
file you have to look into the header anyway to get the actual size.

Sascha

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 10/10] drivers/spi: add driver for the Multichannel SPI controller found in TI SoCs

2012-09-04 Thread Sascha Hauer
On Mon, Sep 03, 2012 at 01:46:05PM +0200, Jan Luebbe wrote:
> Also create devices for OMAP3.
> 
> Signed-off-by: Jan Luebbe 
> ---
> +
> +#define WORD_LEN 8
> +#define SPI_WAIT_TIMEOUT 3000
> +
> +#define SPI_XFER_BEGIN  0x01/* Assert CS before transfer 
> */
> +#define SPI_XFER_END0x02/* Deassert CS after 
> transfer */
> +
> +static void spi_reset(struct spi_master *master)
> +{
> + struct omap3_spi_master *omap3_master = container_of(master, struct 
> omap3_spi_master, master);
> + struct mcspi __iomem *regs = omap3_master->regs;
> + unsigned int tmp;
> +
> + writel(OMAP3_MCSPI_SYSCONFIG_SOFTRESET, ®s->sysconfig);
> + do {
> + tmp = readl(®s->sysstatus);
> + } while (!(tmp & OMAP3_MCSPI_SYSSTATUS_RESETDONE));
> +
> + writel(OMAP3_MCSPI_SYSCONFIG_AUTOIDLE |
> +  OMAP3_MCSPI_SYSCONFIG_ENAWAKEUP |
> +  OMAP3_MCSPI_SYSCONFIG_SMARTIDLE,
> +  ®s->sysconfig);
> +
> + writel(OMAP3_MCSPI_WAKEUPENABLE_WKEN, ®s->wakeupenable);
> +}
> +
> +int spi_claim_bus(struct spi_device *spi)
> +{
> + struct spi_master *master = spi->master;
> + struct omap3_spi_master *omap3_master = container_of(master, struct 
> omap3_spi_master, master);
> + struct mcspi __iomem *regs = omap3_master->regs;
> + unsigned int conf, div = 0;
> +
> + /* McSPI global module configuration */
> +
> + /*
> +  * setup when switching from (reset default) slave mode
> +  * to single-channel master mode
> +  */
> + conf = readl(®s->modulctrl);
> + conf &= ~(OMAP3_MCSPI_MODULCTRL_STEST | OMAP3_MCSPI_MODULCTRL_MS);
> + conf |= OMAP3_MCSPI_MODULCTRL_SINGLE;
> + writel(conf, ®s->modulctrl);
> +
> + /* McSPI individual channel configuration */
> +
> + /* Calculate clock divisor. Valid range: 0x0 - 0xC ( /1 - /4096 ) */
> + if (spi->max_speed_hz) {
> + while (div <= 0xC && (OMAP3_MCSPI_MAX_FREQ / (1 << div))
> +  > spi->max_speed_hz)
> + div++;
> + } else
> + div = 0xC;

if an 'if' has braces then add them to the 'else' path aswell.

> +
> + conf = readl(®s->channel[spi->chip_select].chconf);
> +
> + /* standard 4-wire master mode: SCK, MOSI/out, MISO/in, nCS
> +  * REVISIT: this controller could support SPI_3WIRE mode.
> +  */
> + conf &= ~(OMAP3_MCSPI_CHCONF_IS|OMAP3_MCSPI_CHCONF_DPE1);
> + conf |= OMAP3_MCSPI_CHCONF_DPE0;
> +
> + /* wordlength */
> + conf &= ~OMAP3_MCSPI_CHCONF_WL_MASK;
> + conf |= (WORD_LEN - 1) << 7;
> +
> + /* set chipselect polarity; manage with FORCE */
> + if (!(spi->mode & SPI_CS_HIGH))
> + conf |= OMAP3_MCSPI_CHCONF_EPOL; /* active-low; normal */
> + else
> + conf &= ~OMAP3_MCSPI_CHCONF_EPOL;
> +
> + /* set clock divisor */
> + conf &= ~OMAP3_MCSPI_CHCONF_CLKD_MASK;
> + conf |= div << 2;
> +
> + /* set SPI mode 0..3 */
> + if (spi->mode & SPI_CPOL)
> + conf |= OMAP3_MCSPI_CHCONF_POL;
> + else
> + conf &= ~OMAP3_MCSPI_CHCONF_POL;
> + if (spi->mode & SPI_CPHA)
> + conf |= OMAP3_MCSPI_CHCONF_PHA;
> + else
> + conf &= ~OMAP3_MCSPI_CHCONF_PHA;
> +
> + /* Transmit & receive mode */
> + conf &= ~OMAP3_MCSPI_CHCONF_TRM_MASK;
> +
> + writel(conf, ®s->channel[spi->chip_select].chconf);
> + readl(®s->channel[spi->chip_select].chconf);
> +
> + return 0;
> +}
> +
> +int omap3_spi_write(struct spi_device *spi, unsigned int len, const u8 *txp,
> + unsigned long flags)
> +{
> + struct spi_master *master = spi->master;
> + struct omap3_spi_master *omap3_master = container_of(master, struct 
> omap3_spi_master, master);
> + struct mcspi __iomem *regs = omap3_master->regs;
> + int i;
> + int timeout = SPI_WAIT_TIMEOUT;
> + int chconf = readl(®s->channel[spi->chip_select].chconf);
> +
> + if (flags & SPI_XFER_BEGIN)
> + writel(OMAP3_MCSPI_CHCTRL_EN,
> +®s->channel[spi->chip_select].chctrl);
> +
> + chconf &= ~OMAP3_MCSPI_CHCONF_TRM_MASK;
> + chconf |= OMAP3_MCSPI_CHCONF_TRM_TX_ONLY;
> + chconf |= OMAP3_MCSPI_CHCONF_FORCE;
> + writel(chconf, ®s->channel[spi->chip_select].chconf);
> + readl(®s->channel[spi->chip_select].chconf);
> +
> + for (i = 0; i < len; i++) {
> + /* wait till TX register is empty (TXS == 1) */
> + while (!(readl(®s->channel[spi->chip_select].chstat) &
> +  OMAP3_MCSPI_CHSTAT_TXS)) {
> + if (--timeout <= 0) {
> + printf("SPI TXS timed out, status=0x%08x\n",
> +
> readl(®s->channel[spi->chip_select].chstat));
> + return -1;
> + }
> + }

Please use a well defin

Re: [PATCH 09/10] omap3: allow enabling clocks for UART3, MMC1 and SPI

2012-09-04 Thread Sascha Hauer
On Mon, Sep 03, 2012 at 01:46:04PM +0200, Jan Luebbe wrote:
> Signed-off-by: Jan Luebbe 
> ---
>  arch/arm/mach-omap/Kconfig   |4 
>  arch/arm/mach-omap/omap3_clock.c |   35 +--
>  2 files changed, 29 insertions(+), 10 deletions(-)
> 
> diff --git a/arch/arm/mach-omap/Kconfig b/arch/arm/mach-omap/Kconfig
> index a781287..82fa46b 100644
> --- a/arch/arm/mach-omap/Kconfig
> +++ b/arch/arm/mach-omap/Kconfig
> @@ -61,6 +61,10 @@ config OMAP_CLOCK_UART3
>   bool
>  config OMAP_CLOCK_I2C
>   bool
> +config OMAP_CLOCK_MMC1
> + bool
> +config OMAP_CLOCK_SPI
> + bool

A Kconfig entry for enabling a clock is overkill. Please do not continue
this.

Right now we have:

config OMAP_CLOCK_UART
bool
config OMAP_CLOCK_UART2
bool
config OMAP_CLOCK_UART3
bool
config OMAP_CLOCK_I2C
bool

And it's completely unused, so can be simply removed.

Sascha


-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 08/10] drivers/net: add driver for the EMAC device found in some TI SoCs

2012-09-04 Thread Sascha Hauer
On Mon, Sep 03, 2012 at 01:46:03PM +0200, Jan Luebbe wrote:
> Signed-off-by: Jan Luebbe 
> ---
>  arch/arm/mach-omap/include/mach/emac_defs.h |   53 +++
>  drivers/net/Kconfig |5 +
>  drivers/net/Makefile|1 +
>  drivers/net/davinci_emac.c  |  619 
> +++
>  drivers/net/davinci_emac.h  |  331 ++
>  5 files changed, 1009 insertions(+)
>  create mode 100644 arch/arm/mach-omap/include/mach/emac_defs.h
>  create mode 100644 drivers/net/davinci_emac.c
>  create mode 100644 drivers/net/davinci_emac.h
> 
> diff --git a/arch/arm/mach-omap/include/mach/emac_defs.h 
> b/arch/arm/mach-omap/include/mach/emac_defs.h
> new file mode 100644
> index 000..ef930fc
> --- /dev/null
> +++ b/arch/arm/mach-omap/include/mach/emac_defs.h
> +struct davinci_emac_priv {
> + struct device_d *dev;
> + struct eth_device edev;
> + struct mii_device miidev;
> + void __iomem *regs;

This seems to be filled in in probe(), but otherwise unused.

> +
> + /* EMAC Addresses */
> + emac_regs   *adap_emac; /* = (emac_regs *)EMAC_BASE_ADDR; */
> + ewrap_regs  *adap_ewrap; /* = (ewrap_regs *)EMAC_WRAPPER_BASE_ADDR; 
> */
> + mdio_regs   *adap_mdio; /* = (mdio_regs *)EMAC_MDIO_BASE_ADDR; */

These should be filled in by resources, not hardcoded addresses.

> +};
> +
> +/* davinci_eth_mac_addr[0] goes out on the wire first */
> +
> +static u_int8_t davinci_eth_mac_addr[] = { 0x00, 0xff, 0xff, 0xff, 0xff, 
> 0x00 };

Add this to struct davinci_emac_priv

> +
> +/*
> + * This function must be called before emac_open() if you want to override
> + * the default mac address.
> + */
> +void davinci_eth_set_mac_addr(const u_int8_t *addr)

static please. If you intend to call this from somewhere else than this
file there is something wrong.

> +}
> +
> +/* Read a PHY register via MDIO inteface. Returns 1 on success, 0 otherwise 
> */
> +int davinci_eth_phy_read(struct davinci_emac_priv *priv, u_int8_t phy_addr, 
> u_int8_t reg_num, u_int16_t *data)

static

> +{
> + int tmp;
> +
> + while (readl(&priv->adap_mdio->USERACCESS0) & MDIO_USERACCESS0_GO);
> +
> + writel(MDIO_USERACCESS0_GO |
> + MDIO_USERACCESS0_WRITE_READ |
> + ((reg_num & 0x1f) << 21) |
> + ((phy_addr & 0x1f) << 16),
> + &priv->adap_mdio->USERACCESS0);
> +
> + /* Wait for command to complete */
> + while ((tmp = readl(&priv->adap_mdio->USERACCESS0)) & 
> MDIO_USERACCESS0_GO);
> +
> + if (tmp & MDIO_USERACCESS0_ACK) {
> + *data = tmp & 0x;
> + dev_dbg(priv->dev, "emac_phy_read: addr=0x%02x reg=0x%02x 
> data=0x%04x\n",
> +phy_addr, reg_num, *data);
> + return 1;
> + }
> +
> + *data = -1;
> + return 0;
> +}
> +
> +/* Write to a PHY register via MDIO inteface. Blocks until operation is 
> complete. */
> +int davinci_eth_phy_write(struct davinci_emac_priv *priv, u_int8_t phy_addr, 
> u_int8_t reg_num, u_int16_t data)

static

> +{
> +
> + while (readl(&priv->adap_mdio->USERACCESS0) & MDIO_USERACCESS0_GO);
> +
> + dev_dbg(priv->dev, "emac_phy_write: addr=0x%02x reg=0x%02x 
> data=0x%04x\n",
> +phy_addr, reg_num, data);
> + writel(MDIO_USERACCESS0_GO |
> + MDIO_USERACCESS0_WRITE_WRITE |
> + ((reg_num & 0x1f) << 21) |
> + ((phy_addr & 0x1f) << 16) |
> + (data & 0x),
> + &priv->adap_mdio->USERACCESS0);
> +
> + /* Wait for command to complete */
> + while (readl(&priv->adap_mdio->USERACCESS0) & MDIO_USERACCESS0_GO);
> +
> + return 1;
> +}
> +
> +static int davinci_miidev_read(struct mii_device *dev, int addr, int reg)
> +{
> + struct davinci_emac_priv *priv = (struct davinci_emac_priv 
> *)dev->edev->priv;
> + uint16_t value = 0;
> + return davinci_eth_phy_read(priv, addr, reg, &value) ? value : -1;
> +}
> +
> +static int davinci_miidev_write(struct mii_device *dev, int addr, int reg, 
> int value)
> +{
> + struct davinci_emac_priv *priv = (struct davinci_emac_priv 
> *)dev->edev->priv;
> + return davinci_eth_phy_write(priv, addr, reg, value) ? 0 : -1;
> +}
> +
> +static int davinci_emac_get_ethaddr(struct eth_device *edev, unsigned char 
> *adr)
> +{
> + return -1;
> +}
> +
> +static int davinci_emac_set_ethaddr(struct eth_device *edev, unsigned char 
> *adr)
> +{
> + davinci_eth_set_mac_addr(adr);
> + return 0;
> +}
> +
> +static int davinci_emac_init(struct eth_device *edev)
> +{
> + dev_dbg(&edev->dev, "* emac_init\n");
> + return 0;
> +}
> +
> +static int davinci_emac_open(struct eth_device *edev)
> +{
> + struct davinci_emac_priv *priv = (struct davinci_emac_priv *)edev->priv;
> +
> + dv_reg_paddr;
> + u_int32_t   clkdiv, cnt;
> + emac_desc   *rx_

Re: [PATCH v2 2/2] gpio: add driver for stmpe io-expander

2012-09-04 Thread Marc Kleine-Budde
On 09/03/2012 01:03 PM, Steffen Trumtrar wrote:
> Signed-off-by: Steffen Trumtrar 
> ---
>  drivers/Kconfig   |1 +
>  drivers/gpio/Kconfig  |9 +++
>  drivers/gpio/Makefile |2 +
>  drivers/gpio/gpio-stmpe.c |  162 
> +
>  4 files changed, 174 insertions(+)
>  create mode 100644 drivers/gpio/Kconfig
>  create mode 100644 drivers/gpio/Makefile
>  create mode 100644 drivers/gpio/gpio-stmpe.c
> 
> diff --git a/drivers/Kconfig b/drivers/Kconfig
> index 883b0e7..adf8fcd 100644
> --- a/drivers/Kconfig
> +++ b/drivers/Kconfig
> @@ -18,5 +18,6 @@ source "drivers/input/Kconfig"
>  source "drivers/watchdog/Kconfig"
>  source "drivers/pwm/Kconfig"
>  source "drivers/dma/Kconfig"
> +source "drivers/gpio/Kconfig"
>  
>  endmenu
> diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
> new file mode 100644
> index 000..acfd4ef
> --- /dev/null
> +++ b/drivers/gpio/Kconfig
> @@ -0,0 +1,9 @@
> +menu "GPIO  "
> +
> +config STMPE_GPIO
> + depends on I2C
> + depends on GPIOLIB
> + select I2C_STMPE
> + bool "STMPE GPIO Expander"
> +
> +endmenu
> diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
> new file mode 100644
> index 000..da1bc21
> --- /dev/null
> +++ b/drivers/gpio/Makefile
> @@ -0,0 +1,2 @@
> +obj-y += gpio.o
> +obj-$(CONFIG_STMPE_GPIO) += gpio-stmpe.o
> diff --git a/drivers/gpio/gpio-stmpe.c b/drivers/gpio/gpio-stmpe.c
> new file mode 100644
> index 000..74547d9
> --- /dev/null
> +++ b/drivers/gpio/gpio-stmpe.c
> @@ -0,0 +1,162 @@
> +/*
> + * Copyright (C) 2012 Pengutronix
> + * Steffen Trumtrar 
> + *
> + * 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.
> + *
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define GPIO_BASE0x80
> +#define GPIO_SET (GPIO_BASE + 0x02)
> +#define GPIO_CLR (GPIO_BASE + 0x04)
> +#define GPIO_MP  (GPIO_BASE + 0x06)
> +#define GPIO_SET_DIR (GPIO_BASE + 0x08)
> +#define GPIO_ED  (GPIO_BASE + 0x0a)
> +#define GPIO_RE  (GPIO_BASE + 0x0c)
> +#define GPIO_FE  (GPIO_BASE + 0x0e)
> +#define GPIO_PULL_UP (GPIO_BASE + 0x10)
> +#define GPIO_AF  (GPIO_BASE + 0x12)
> +#define GPIO_LT  (GPIO_BASE + 0x16)
> +
> +#define OFFSET(gpio) (0xff & (1 << (gpio)) ? 1 : 0)
> +
> +extern void __iomem *stmpe_gpio_base[];
> +extern int stmpe_gpio_count;

Are these two used?

> +
> +struct stmpe_gpio_chip {
> + void __iomem *base;
^^

Where is it used? An i2c device doesn't have iomem?

> + struct gpio_chip chip;
> + void *ci;

why is this a void, not struct stmpe_client_info *

> +};
> +
> +static void stmpe_gpio_set_value(struct gpio_chip *chip, unsigned gpio, int 
> value)
> +{
> + struct stmpe_gpio_chip *stmpegpio = container_of(chip, struct 
> stmpe_gpio_chip, chip);
> + struct stmpe_client_info *ci = (struct stmpe_client_info 
> *)stmpegpio->ci;
> + int ret;
> + u8 val;
> +
> + ci->read_reg(ci->stmpe, GPIO_MP + OFFSET(gpio), &val);
> +
> + val |= 1 << (gpio % 8);
> +
> + if (value)
> + ret = ci->write_reg(ci->stmpe, GPIO_SET + OFFSET(gpio), val);
> + else
> + ret = ci->write_reg(ci->stmpe, GPIO_CLR + OFFSET(gpio), val);
> +
> + if (ret)
> + dev_err(chip->dev, "write failed!\n");
> +}
> +
> +static int stmpe_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
> +{
> + struct stmpe_gpio_chip *stmpegpio = container_of(chip, struct 
> stmpe_gpio_chip, chip);
> + struct stmpe_client_info *ci = (struct stmpe_client_info 
> *)stmpegpio->ci;
> + int ret;
> + u8 val;
> +
> + ci->read_reg(ci->stmpe, GPIO_SET_DIR + OFFSET(gpio), &val);
> + val &= ~(1 << (gpio % 8));
> + ret = ci->write_reg(ci->stmpe, GPIO_SET_DIR + OFFSET(gpio), val);
> +
> + if (ret)
> + dev_err(chip->dev, "couldn't change direction. Write 
> failed!\n");
> +
> + return 0;
> +}
> +
> +static int stmpe_gpio_direction_output(struct gpio_chip *chip, unsigned 
> gpio, int value)
> +{
> + struct stmpe_gpio_chip *stmpegpio = container_of(chip, struct 
> stmpe_gpio_chip, chip);
> + struct stmpe_client_info *ci = (struct stmpe_client_info 
> *)stmpegpio->ci;
> + int ret;
> + u8 val;
> +
> + ci->read_reg(ci->stmpe, GPIO_SET_DIR + OFFSET(gpio), &val);
> + val |= 1 << (gpio % 8);
> + ret = ci->write_reg(ci->stmpe, GPIO_SET_DIR + OFFSET(gpio), val);

Re: [PATCH 04/10] scripts: add tool to create image for SPI boot on AM35xx

2012-09-04 Thread Sascha Hauer
On Mon, Sep 03, 2012 at 01:45:59PM +0200, Jan Luebbe wrote:
> Booting from SPI on an AM35xx (and possibly other TI SOCs) requires
> a special format:
> 
> - 32 bit image size in big-endian
> - 32 bit load address in big-endian
> - binary image converted from little- to big-endian
> 
> The mk-am35xx-spi-image tool converts barebox.bin to
> this format.
> 
> Signed-off-by: Jan Luebbe 
> ---
>  arch/arm/Makefile |8 +++
>  arch/arm/mach-omap/Kconfig|7 +++
>  scripts/.gitignore|1 +
>  scripts/Makefile  |2 +-
>  scripts/mk-am35xx-spi-image.c |  126 
> +
>  5 files changed, 143 insertions(+), 1 deletion(-)
>  create mode 100644 scripts/mk-am35xx-spi-image.c
> 
> diff --git a/arch/arm/Makefile b/arch/arm/Makefile
> index 1b60261..ff96299 100644
> --- a/arch/arm/Makefile
> +++ b/arch/arm/Makefile
> @@ -199,6 +199,14 @@ endif
>  
>  all: $(KBUILD_IMAGE)
>  
> +barebox.spi: barebox.bin
> + @echo "  SPI" $@
> + $(Q)scripts/mk-am35xx-spi-image barebox.bin > barebox.spi
> +
> +ifeq ($(CONFIG_OMAP_BUILD_SPI),y)
> +all: barebox.spi
> +endif
> +
>  archprepare: maketools
>  maketools:
>   $(Q)$(MAKE) $(build)=arch/arm/tools include/generated/mach-types.h
> diff --git a/arch/arm/mach-omap/Kconfig b/arch/arm/mach-omap/Kconfig
> index d735284..a781287 100644
> --- a/arch/arm/mach-omap/Kconfig
> +++ b/arch/arm/mach-omap/Kconfig
> @@ -91,6 +91,13 @@ config OMAP_BUILD_IFT
>   prompt "build ift binary"
>   bool
>  
> +config OMAP_BUILD_SPI
> + prompt "build SPI binary"
> + bool
> + help
> +   Say Y here if you want to build an barebox.spi image as used
> +   on the AM35xx chips when booting form SPI NOR flash.
> +
>  config ARCH_TEXT_BASE
>   hex
>   default 0x80e8 if MACH_OMAP343xSDP
> diff --git a/scripts/.gitignore b/scripts/.gitignore
> index 6e63f85..3f1cbdb 100644
> --- a/scripts/.gitignore
> +++ b/scripts/.gitignore
> @@ -2,6 +2,7 @@ bareboxenv
>  bin2c
>  gen_netx_image
>  kallsyms
> +mk-am35xx-spi-image
>  mkimage
>  mkublheader
>  omap_signGP
> diff --git a/scripts/Makefile b/scripts/Makefile
> index 7ca5e29..55ccdac 100644
> --- a/scripts/Makefile
> +++ b/scripts/Makefile
> @@ -9,7 +9,7 @@ hostprogs-y  += bin2c
>  hostprogs-y  += mkimage
>  hostprogs-y  += bareboxenv
>  hostprogs-$(CONFIG_ARCH_NETX)+= gen_netx_image
> -hostprogs-$(CONFIG_ARCH_OMAP)+= omap_signGP
> +hostprogs-$(CONFIG_ARCH_OMAP)+= omap_signGP mk-am35xx-spi-image
>  hostprogs-$(CONFIG_ARCH_S5PCxx)  += s5p_cksum
>  hostprogs-$(CONFIG_ARCH_DAVINCI) += mkublheader
>  
> diff --git a/scripts/mk-am35xx-spi-image.c b/scripts/mk-am35xx-spi-image.c
> new file mode 100644
> index 000..133f2b7
> --- /dev/null
> +++ b/scripts/mk-am35xx-spi-image.c
> @@ -0,0 +1,126 @@
> +/*
> + * mkublheader.c - produce the header needed to load barebox on OMAP-L138

We already have scripts/mkublheader.c:

/*
 * mkublheader.c - produce the header needed to load barebox on OMAP-L138
 */

This indeed seems to be a different tool. Can we clarify this a bit,
maybe by adding the purpose of the different tools to the header?

Sascha

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 02/10] drivers/nor/m25p80: add MEMGETINFO ioctl

2012-09-04 Thread Sascha Hauer
On Mon, Sep 03, 2012 at 01:45:57PM +0200, Jan Luebbe wrote:
> Signed-off-by: Jan Luebbe 
> ---
>  drivers/nor/m25p80.c |   26 ++
>  1 file changed, 26 insertions(+)
> 
> diff --git a/drivers/nor/m25p80.c b/drivers/nor/m25p80.c
> index 61f2195..1722e0a 100644
> --- a/drivers/nor/m25p80.c
> +++ b/drivers/nor/m25p80.c
> @@ -20,6 +20,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -690,9 +691,34 @@ static const struct spi_device_id *jedec_probe(struct 
> spi_device *spi)
>   return NULL;
>  }
>  
> +static int m25p80_ioctl(struct cdev *cdev, int request, void *buf)
> +{
> + struct m25p *flash = cdev->priv;
> + struct flash_info *info = flash->info;
> + struct mtd_info_user *user = buf;
> +
> + switch (request) {
> + case MEMGETINFO:
> + memset(user, 0, sizeof(*user));
> + user->type = MTD_NORFLASH;
> + user->flags = MTD_CAP_NORFLASH;
> + user->size = flash->size;
> + user->erasesize = info->sector_size;
> + user->writesize = 1;
> + user->oobsize = 0;
> + /* The below fields are obsolete */
> + user->ecctype = -1;
> + user->eccsize = 0;
> + return 0;
> + }
> +
> + return -EINVAL;
> +}
> +
>  static struct file_operations m25p80_ops = {
>   .read   = m25p80_read,
>   .write  = m25p80_write,
> + .ioctl  = m25p80_ioctl,

Rather than doing this you should simply fill in cdev->mtd. See how the
cfi flash driver does this. Then it will also work for partitions on a
m25p80.

Sascha


-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH v2 1/2] mfd: add stmpe-i2c driver

2012-09-04 Thread Marc Kleine-Budde
On 09/03/2012 01:03 PM, Steffen Trumtrar wrote:
> The stmpe mfds can be connected via i2c and spi. This driver provides the 
> basic
> infrastructure for the i2c kind. It can be added as a normal i2c-device in the
> board code. To enable functions a platform_data struct has to be provided, 
> that
> describes what parts of the chip are to be used.
> 
> Signed-off-by: Steffen Trumtrar 
> ---
>  drivers/mfd/Kconfig |4 ++
>  drivers/mfd/Makefile|1 +
>  drivers/mfd/stmpe-i2c.c |  166 
> +++
>  include/mfd/stmpe-i2c.h |   56 
>  4 files changed, 227 insertions(+)
>  create mode 100644 drivers/mfd/stmpe-i2c.c
>  create mode 100644 include/mfd/stmpe-i2c.h
> 
> diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
> index af67935..20eef86 100644
> --- a/drivers/mfd/Kconfig
> +++ b/drivers/mfd/Kconfig
> @@ -33,4 +33,8 @@ config I2C_TWL6030
>   select I2C_TWLCORE
>   bool "TWL6030 driver"
>  
> +config I2C_STMPE
> + depends on I2C
> + bool "STMPE-i2c driver"
> +
>  endmenu
> diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
> index e11223b..792ae2d 100644
> --- a/drivers/mfd/Makefile
> +++ b/drivers/mfd/Makefile
> @@ -6,3 +6,4 @@ obj-$(CONFIG_I2C_LP3972) += lp3972.o
>  obj-$(CONFIG_I2C_TWLCORE) += twl-core.o
>  obj-$(CONFIG_I2C_TWL4030) += twl4030.o
>  obj-$(CONFIG_I2C_TWL6030) += twl6030.o
> +obj-$(CONFIG_I2C_STMPE) += stmpe-i2c.o
> diff --git a/drivers/mfd/stmpe-i2c.c b/drivers/mfd/stmpe-i2c.c
> new file mode 100644
> index 000..a0cfa75
> --- /dev/null
> +++ b/drivers/mfd/stmpe-i2c.c
> @@ -0,0 +1,166 @@
> +/*
> + * Copyright (C) 2012 Pengutronix
> + * Steffen Trumtrar 
> + *
> + * 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.
> + *
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +#include 
> +
> +#define DRIVERNAME   "stmpe-i2c"
> +
> +#define to_stmpe(a)  container_of(a, struct stmpe, cdev)
> +
> +static struct stmpe *stmpe_dev;
> +
> +struct stmpe *stmpe_get(void)
> +{
> + if (!stmpe_dev)
> + return NULL;

nitpick, you can remove the above return :)
> +
> + return stmpe_dev;
> +}
> +EXPORT_SYMBOL(stmpe_get);
> +
> +int stmpe_reg_read(struct stmpe *stmpe, u32 reg, u8 *val)
> +{
> + int ret;
> +
> + ret = i2c_read_reg(stmpe->client, reg, val, 1);
> +
> + return ret == 1 ? 0 : ret;
> +}
> +EXPORT_SYMBOL(stmpe_reg_read)
> +
> +int stmpe_reg_write(struct stmpe *stmpe, u32 reg, u8 val)
> +{
> + int ret;
> +
> + ret = i2c_write_reg(stmpe->client, reg, &val, 1);
> +
> + return ret == 1 ? 0 : ret;
> +}
> +EXPORT_SYMBOL(stmpe_reg_write)
> +
> +int stmpe_set_bits(struct stmpe *stmpe, u32 reg, u8 mask, u8 val)
> +{
> + u8 tmp;
> + int err;
> +
> + err = stmpe_reg_read(stmpe, reg, &tmp);
> + tmp = (tmp & ~mask) | val;
> +
> + if (!err)
> + err = stmpe_reg_write(stmpe, reg, tmp);
> +
> + return err;
> +}
> +EXPORT_SYMBOL(stmpe_set_bits);
> +
> +static ssize_t stmpe_read(struct cdev *cdev, void *_buf, size_t count, 
> loff_t offset, ulong flags)
> +{
> + struct stmpe *stmpe = to_stmpe(cdev);
> + u8 *buf = _buf;
> + size_t i = count;
> + int err;
> +
> + while (i) {
> + err = stmpe_reg_read(stmpe, offset, buf);
> + if (err)
> + return (ssize_t)err;
> + buf++;
> + i--;
> + offset++;
> + }
> +
> + return count;
> +}
> +
> +static ssize_t stmpe_write(struct cdev *cdev, const void *_buf, size_t 
> count, loff_t offset, ulong flags)
> +{
> + struct stmpe *stmpe = to_stmpe(cdev);
> + const u8 *buf = _buf;
> + size_t i = count;
> + int err;
> +
> + while (i) {
> + err = stmpe_reg_write(stmpe, offset, *buf);
> + if (err)
> + return (ssize_t)err;
> + buf++;
> + i--;
> + offset++;
> + }
> +
> + return count;
> +}
> +
> +static struct file_operations stmpe_fops = {
> + .lseek  = dev_lseek_default,
> + .read   = stmpe_read,
> + .write  = stmpe_write,
> +};
> +
> +static struct stmpe_client_info i2c_ci = {
> + .read_reg = stmpe_reg_read,
> + .write_reg = stmpe_reg_write,
> +};
> +
> +static int stmpe_probe(struct device_d *dev)
> +{
> + struct stmpe_platform_data *pdata = dev->platform_data;
> +
> + if (!pdata) {
> + dev_dbg(dev, "no platform data\n");
> + return -ENOD

Re: [PATCH v2 2/2] gpio: add driver for stmpe io-expander

2012-09-04 Thread Sascha Hauer
On Mon, Sep 03, 2012 at 01:03:47PM +0200, Steffen Trumtrar wrote:
> Signed-off-by: Steffen Trumtrar 
> ---
> +static int stmpe_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
> +{
> + struct stmpe_gpio_chip *stmpegpio = container_of(chip, struct 
> stmpe_gpio_chip, chip);
> + struct stmpe_client_info *ci = (struct stmpe_client_info 
> *)stmpegpio->ci;
> + int ret;
> + u8 val;
> +
> + ci->read_reg(ci->stmpe, GPIO_SET_DIR + OFFSET(gpio), &val);
> + val &= ~(1 << (gpio % 8));
> + ret = ci->write_reg(ci->stmpe, GPIO_SET_DIR + OFFSET(gpio), val);
> +
> + if (ret)
> + dev_err(chip->dev, "couldn't change direction. Write 
> failed!\n");
> +
> + return 0;

Please propagate the error value.

> +}
> +
> +static int stmpe_gpio_direction_output(struct gpio_chip *chip, unsigned 
> gpio, int value)
> +{
> + struct stmpe_gpio_chip *stmpegpio = container_of(chip, struct 
> stmpe_gpio_chip, chip);
> + struct stmpe_client_info *ci = (struct stmpe_client_info 
> *)stmpegpio->ci;
> + int ret;
> + u8 val;
> +
> + ci->read_reg(ci->stmpe, GPIO_SET_DIR + OFFSET(gpio), &val);
> + val |= 1 << (gpio % 8);
> + ret = ci->write_reg(ci->stmpe, GPIO_SET_DIR + OFFSET(gpio), val);
> +
> + stmpe_gpio_set_value(chip, gpio, value);
> +
> + if (ret)
> + dev_err(chip->dev, "couldn't change direction. Write 
> failed!\n");
> +
> + return 0;

ditto

> +
> +static int stmpe_gpio_probe(struct device_d *dev)
> +{
> + struct stmpe_gpio_chip *stmpegpio;
> + struct stmpe_client_info *ci;
> +
> + stmpegpio = xzalloc(sizeof(*stmpegpio));
> +
> + stmpegpio->base = dev_request_mem_region(dev, 0);
> + stmpegpio->chip.ops = &stmpe_gpio_ops;
> + stmpegpio->ci = dev->platform_data;
> +
> + ci = (struct stmpe_client_info *)stmpegpio->ci;
> +
> + if (ci->stmpe->pdata->gpio_base)
> + stmpegpio->chip.base = ci->stmpe->pdata->gpio_base;
> + else
> + stmpegpio->chip.base = -1;
> +
> + stmpegpio->chip.ngpio = 16;
> + stmpegpio->chip.dev = dev;
> +
> + gpiochip_add(&stmpegpio->chip);

It's worth checking the return value of gpiochip_add. It could indicate
that the selected chip.base is busy.

Sascha

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH v2 1/2] mfd: add stmpe-i2c driver

2012-09-04 Thread Sascha Hauer
On Mon, Sep 03, 2012 at 01:03:46PM +0200, Steffen Trumtrar wrote:
> The stmpe mfds can be connected via i2c and spi. This driver provides the 
> basic
> infrastructure for the i2c kind. It can be added as a normal i2c-device in the
> board code. To enable functions a platform_data struct has to be provided, 
> that
> describes what parts of the chip are to be used.
> 
> Signed-off-by: Steffen Trumtrar 
> +
> +struct stmpe *stmpe_get(void)
> +{
> + if (!stmpe_dev)
> + return NULL;
> +
> + return stmpe_dev;
> +}
> +EXPORT_SYMBOL(stmpe_get);

For the pmic devices the assumption that there is only one in the system
is not nice, but reasonable. For this driver it is an unnecessary
limitation.

How about this:

add a 'static struct stmpe stmpe_dev' just like you did, but instead
of returning -EBUSY for the second one, do

if (!stmpe_dev)
stmpe_dev = newdev;

This way the at least the gpio support works for multiple instances.

Sascha

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


iMX27 board : Barebox & linux 2.6.24.6 => reboot the board randomly ...

2012-09-04 Thread Aurelien Bouin
Hello,

I am currently porting Barebox instead of UBoot to an old kernel linux 2.6.24.6 
on an iMX27 board.
Speaking of Barebox everything is going well and seems to work correctly : USB, 
I2C, Network, etc ...
The problem is that the processor halt and sometime reboot ... but it can occur 
at anytime randomly ... 
I was looking on the Chip Errata of this processor, apparently there is a 
problem of improper duty cycle that have to be handled ... 
I am following some Barebox implementation of mx27 that handle this chip errata 
(arch/arm/boards/eukrea_cpuimx27;guf-neso;phycard-iMX27)It do not happen with 
UBoot with the kernel 2.6.24.6, neither with barebox and the kernel 3.2.0 ...
I am using the master branch of the git repository. I cannot upgrade my old 
linux 2.6.24 because of video support not handle.

If you have any idea of what could be the problem ...
Thank you for your time and your support,
Best regards,

Aurelien BOUIN___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 0/4 v2] fs/mount: add autodetection support

2012-09-04 Thread Sascha Hauer
On Sun, Aug 12, 2012 at 08:05:35PM +0200, Jean-Christophe PLAGNIOL-VILLARD 
wrote:
> HI,
> 
> v2:
>   fix typo
>   move convert to fs_driver after check
> 
> please pull
> The following changes since commit 58713d32746d49ad39ba17658fe82f1b98b80b2e:
> 
>   commands: memset: fix help message (2012-08-09 08:44:38 +0200)
> 
> are available in the git repository at:
> 
>   git://git.jcrosoft.org/barebox.git tags/fs
> 
> for you to fetch changes up to 7565f1e0f6877357c3e38f40d73f5773957f94b6:
> 
>   command/mount: add autodetection support (2012-08-12 21:46:15 +0800)

This series breaks compilation on several architectures due to missing
asm/unaligned.h header:

- openrisc
- blackfin
- ppc

For ppc Renaud Barbier already sent a fix. I fixed the remaining myself.

Sascha


-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 00/18 v3] fs: add symlink and readlink support

2012-09-04 Thread Sascha Hauer
On Mon, Sep 03, 2012 at 04:50:42PM +0200, Jean-Christophe PLAGNIOL-VILLARD 
wrote:
> HI,
> 
>   v4:
>drop the mounted path added to absolute symlink
> 
>   v3:
>- fix support
>  mkdir mymount
>  mount -t ramfs none mymount/
>  ln /env/boot/net /mymount/link
> 
>- addres comments
> 
>   v2:
>addres comments
> 
> please pull
> The following changes since commit b77300ac6c6bbbc7eac774ff0076c7c05d39735f:
> 
>   command/mount: add autodetection support (2012-08-21 18:53:00 +0800)
> 
> are available in the git repository at:
> 
>   git://git.jcrosoft.org/barebox.git tags/fs-symlink

It gets better. Now we still have:

# ln bla link
# ln bla link
# ls -l
lrwxrwxrwx  3 link -> bla
lrwxrwxrwx  3 link -> bla

# ln a b
# rmdir b
unable to handle NULL pointer dereference at address 0x0008
pc : []lr : []
sp : a6eff948  ip : 0003  fp : 
r10: a6ffbddc  r9 :   r8 : 0002
r7 :   r6 :   r5 : a6fe0e98  r4 : a6ffbb44
r3 :   r2 :   r1 : a6ffbdc7  r0 : 
Flags: nZCv  IRQs off  FIQs off  Mode SVC_32
[] (ramfs_rmdir+0x48/0x78) from [] (rmdir+0x5c/0x88)
[] (rmdir+0x5c/0x88) from [] (do_rmdir+0x28/0x6c)
[] (do_rmdir+0x28/0x6c) from [] (execute_command+0x38/0x7c)
[] (execute_command+0x38/0x7c) from [] 
(run_list_real+0x8dc/0x9dc)
[] (run_list_real+0x8dc/0x9dc) from [] 
(parse_stream_outer+0x148/0x238)
[] (parse_stream_outer+0x148/0x238) from [] 
(run_shell+0x3c/0x7c)
[] (run_shell+0x3c/0x7c) from [] (execute_command+0x38/0x7c)
[] (execute_command+0x38/0x7c) from [] 
(run_list_real+0x8dc/0x9dc)
[] (run_list_real+0x8dc/0x9dc) from [] 
(run_list_real+0x438/0x9dc)

[] (unwind_backtrace+0x0/0x9c) from [] (panic+0x28/0x3c)
[] (panic+0x28/0x3c) from [] (do_exception+0x10/0x14)
[] (do_exception+0x10/0x14) from [] 
(do_data_abort+0x2c/0x38)
[] (do_data_abort+0x2c/0x38) from [] (data_abort+0x50/0x60)

While you are at it, the 'ln' command should be under "file commands",
not under "scripting commands".

For links to directories I agree, this is nontrivial and can be added
later. I don't see though why links to links shouldn't be supported from
the start. All it takes is the following, right?

8<

diff --git a/fs/fs.c b/fs/fs.c
index 7c59126..447b56f 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -580,13 +580,13 @@ EXPORT_SYMBOL(unlink);
 static char *realfile(const char *pathname, struct stat *s)
 {
char *path = normalise_path(pathname);
-   int ret;
+   int ret, recursive = 16;
 
ret = lstat(path, s);
if (ret)
goto out;
 
-   if (S_ISLNK(s->st_mode)) {
+   while (S_ISLNK(s->st_mode)) {
char tmp[PATH_MAX];
char *new_path;
 
@@ -603,10 +603,16 @@ static char *realfile(const char *pathname, struct stat 
*s)
path = new_path;
 
ret = lstat(path, s);
+   if (ret)
+   goto out;
+
+   if (!recursive--) {
+   ret = -ELOOP;
+   goto out;
+   }
}
 
-   if (!ret)
-   return path;
+   return path;
 
 out:
free(path);

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 06/10] omap: add SPI as a boot mode for xload

2012-09-04 Thread Jan Weitzel
Am Montag, den 03.09.2012, 18:24 +0200 schrieb Jean-Christophe
PLAGNIOL-VILLARD:
> On 13:46 Mon 03 Sep , Jan Luebbe wrote:
> > Signed-off-by: Jan Luebbe 
> you need to sync with 
> 
> 257 Aug27 Jan Weitzel [RFC] xload: get barebox size from 
> barebox_arm_head

read_image_head reads the size from partition. Could you try it?.
[PATCH v3] xload: get barebox size from barebox_arm_head

Jan



> Best Regards,
> J.
> 
> ___
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox



___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH v3] xload: get barebox size from barebox_arm_head

2012-09-04 Thread Jan Weitzel
Am Mittwoch, den 29.08.2012, 14:21 +0200 schrieb Jean-Christophe
PLAGNIOL-VILLARD:
> On 11:10 Wed 29 Aug , Jan Weitzel wrote:
> > Add functions to read the barebox_arm_head, check barebox magicword
> > and read out the barebox image size.
> > Create a inital partion of 1Mb to access the barebox image on nand.
> > 
> > Signed-off-by: Jan Weitzel 
> > ---
> > v2: remove fall back if header read fail 
> > v3: fix header check, rebase master 
> > 
> >  arch/arm/include/asm/barebox-arm-head.h |4 ++
> >  arch/arm/mach-omap/include/mach/xload.h |2 +-
> >  arch/arm/mach-omap/xload.c  |   58 
> > --
> >  3 files changed, 59 insertions(+), 5 deletions(-)
> > 
> > diff --git a/arch/arm/include/asm/barebox-arm-head.h 
> > b/arch/arm/include/asm/barebox-arm-head.h
> > index 2c250e9..1ddfc0f 100644
> > --- a/arch/arm/include/asm/barebox-arm-head.h
> > +++ b/arch/arm/include/asm/barebox-arm-head.h
> > @@ -1,6 +1,10 @@
> >  #ifndef __ASM_ARM_HEAD_H
> >  #define __ASM_ARM_HEAD_H
> >  
> > +#define ARM_HEAD_SIZE  0x30
> > +#define HEAD_MAGICWORD_OFFSET  0x20
> > +#define HEAD_SIZE_OFFSET   0x2C
> > +
> >  static inline void barebox_arm_head(void)
> >  {
> > __asm__ __volatile__ (
> > diff --git a/arch/arm/mach-omap/include/mach/xload.h 
> > b/arch/arm/mach-omap/include/mach/xload.h
> > index 844b57f..26f1b68 100644
> > --- a/arch/arm/mach-omap/include/mach/xload.h
> > +++ b/arch/arm/mach-omap/include/mach/xload.h
> > @@ -1,7 +1,7 @@
> >  #ifndef _MACH_XLOAD_H
> >  #define _MACH_XLOAD_H
> >  
> > -void *omap_xload_boot_nand(int offset, int size);
> > +void *omap_xload_boot_nand(int offset);
> >  void *omap_xload_boot_mmc(void);
> >  
> >  enum omap_boot_src {
> > diff --git a/arch/arm/mach-omap/xload.c b/arch/arm/mach-omap/xload.c
> > index 13024ab..d9765b7 100644
> > --- a/arch/arm/mach-omap/xload.c
> > +++ b/arch/arm/mach-omap/xload.c
> > @@ -7,16 +7,66 @@
> >  #include 
> >  #include 
> >  #include 
> > +#include 
> >  
> > -void *omap_xload_boot_nand(int offset, int size)
> > +void *read_image_head(const char *name)
> >  {
> > +   void *header = xmalloc(ARM_HEAD_SIZE);
> > +   struct cdev *cdev;
> > int ret;
> > -   void *to = xmalloc(size);
> > +
> > +   cdev = cdev_open(name, O_RDONLY);
> > +   if (!cdev) {
> > +   printf("failed to open partition\n");
> > +   return NULL;
> > +   }
> > +
> > +   ret = cdev_read(cdev, header, ARM_HEAD_SIZE, 0, 0);
> > +   cdev_close(cdev);
> > +
> > +   if (ret != ARM_HEAD_SIZE) {
> > +   printf("failed to read from partition\n");
> > +   return NULL;
> > +   }
> > +
> > +   return header;
> > +}
> > +
> > +unsigned int get_image_size(void *head)
> > +{
> > +   unsigned int ret = 0;
> > +   unsigned int *psize = head + HEAD_SIZE_OFFSET;
> > +   const char *pmagic = head + HEAD_MAGICWORD_OFFSET;
> > +
> > +   if (!strcmp(pmagic, "barebox"))
> > +   ret = *psize;
> > +   debug("Detected barebox image size %u\n", ret);
> factorise the code with filetype
What exactly do you mean? I could factorise it by boot source (mmc / nand) with 
complete omap_xload_boot_nand.
Jan

> Best Regards,
> J.



___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox