mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* Re: [PATCH 2/2] ARM: Fix calling of arm_mem_barebox_image()
From: Trent Piepho @ 2016-09-22  0:35 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: Barebox List
In-Reply-To: <20160915071008.tbpw5d222h2chd5w@pengutronix.de>

On Thu, 2016-09-15 at 09:10 +0200, Sascha Hauer wrote:
> On Wed, Sep 14, 2016 at 06:27:04PM +0000, Trent Piepho wrote:
> > On Wed, 2016-09-14 at 10:21 +0200, Sascha Hauer wrote:
> > > arm_mem_barebox_image() is used to pick a suitable place where to
> > > put the final image to. This is called from both the PBL uncompression
> > > code and also from the final image. To make it work properly it is
> > > crucial that it's called with the same arguments both times. Currently
> > 
> > This code has changed since I was working with it, but wouldn't
> > arm_mem_barebox_image() returning a different value from when the PBL
> > code calls it versus barebox_non_pbl_start() just result in an
> > unnecessary relocation of the uncompressed barebox from the PBL's choice
> > to the main barebox choice?
> 
> That may work when both regions do not overlap.

Ah, good point.  I suppose barebox could check that it doesn't try to
relocate on top of itself while running.


> I already tried. Somehow I didn't like the result that much, see the
> patch below. The patch also still misses the single pbl handling.

Here's what I was thinking.  multi and single pbl should work, getting
the size (data+bss) from the compressed data's size word.  Non-pbl and
PBL main barebox know the data via the linker symbols.

From: Trent Piepho <tpiepho@kymetacorp.com>
Date: Sat, 17 Sep 2016 16:24:59 -0700
Subject: [PATCH] Include BSS in the size appended to compressed barebox

In a PBL config the compressed main barebox image includes the
uncompressed size as a LE 32-bit word at the end of the compressed
image.  This allows the pbl to know how much space the main barebox
will need.  But this value alone is not correct, as the image also
needs BSS space which, being all zero, is not actually stored in the
compressed image.

While the BSS space could be estimated, it is important that both the
PBL and the main barebox use the same value.

To fix this, when making the barebox.z compressed data for the PBL,
include BSS in the size word.  Now the PBL knows the size it needs.

The main boxbox image (both in PBL and non-PBL modes) already knows
the correct values as they are embedded in the binary directly by the
linker, and are used elsewhere like setup_c() and
mem_malloc_resource().
---
 arch/arm/cpu/start-pbl.c  |  7 +++++--
 arch/arm/cpu/uncompress.c |  8 ++++++--
 images/Makefile           |  4 ++++
 scripts/Makefile.lib      | 23 ++++++++++-------------
 4 files changed, 25 insertions(+), 17 deletions(-)

diff --git a/arch/arm/cpu/start-pbl.c b/arch/arm/cpu/start-pbl.c
index f723edc..1869a96 100644
--- a/arch/arm/cpu/start-pbl.c
+++ b/arch/arm/cpu/start-pbl.c
@@ -28,6 +28,7 @@
 #include <asm/sections.h>
 #include <asm/pgtable.h>
 #include <asm/cache.h>
+#include <asm/unaligned.h>
 
 #include "mmu-early.h"
 
@@ -49,7 +50,7 @@ __noreturn void barebox_single_pbl_start(unsigned long membase,
 		unsigned long memsize, void *boarddata)
 {
 	uint32_t offset;
-	uint32_t pg_start, pg_end, pg_len;
+	uint32_t pg_start, pg_end, pg_len, barebox_mem_len;
 	void __noreturn (*barebox)(unsigned long, unsigned long, void *);
 	uint32_t endmem = membase + memsize;
 	unsigned long barebox_base;
@@ -63,9 +64,11 @@ __noreturn void barebox_single_pbl_start(unsigned long membase,
 	pg_start = (uint32_t)&input_data - offset;
 	pg_end = (uint32_t)&input_data_end - offset;
 	pg_len = pg_end - pg_start;
+	/* Size word at end of image includes space for BSS */
+	barebox_mem_len = get_unaligned((const u32 *)(pg_start + pg_len - 4));
 
 	if (IS_ENABLED(CONFIG_RELOCATABLE))
-		barebox_base = arm_mem_barebox_image(membase, endmem, pg_len);
+		barebox_base = arm_mem_barebox_image(membase, endmem, barebox_mem_len);
 	else
 		barebox_base = TEXT_BASE;
 
diff --git a/arch/arm/cpu/uncompress.c b/arch/arm/cpu/uncompress.c
index b8e2e9f..9bec77f 100644
--- a/arch/arm/cpu/uncompress.c
+++ b/arch/arm/cpu/uncompress.c
@@ -29,6 +29,7 @@
 #include <asm/sections.h>
 #include <asm/pgtable.h>
 #include <asm/cache.h>
+#include <asm/unaligned.h>
 
 #include <debug_ll.h>
 
@@ -44,7 +45,7 @@ static int __attribute__((__used__))
 void __noreturn barebox_multi_pbl_start(unsigned long membase,
 		unsigned long memsize, void *boarddata)
 {
-	uint32_t pg_len;
+	uint32_t pg_len, barebox_mem_len;
 	void __noreturn (*barebox)(unsigned long, unsigned long, void *);
 	uint32_t endmem = membase + memsize;
 	unsigned long barebox_base;
@@ -69,13 +70,16 @@ void __noreturn barebox_multi_pbl_start(unsigned long membase,
 	/*
 	 * image_end is the first location after the executable. It contains
 	 * the size of the appended compressed binary followed by the binary.
+	 * The final word of the compressed binary is the space (uncompressed
+	 * image plus bss room) needed by barebox.
 	 */
 	pg_start = image_end + 1;
 	pg_len = *(image_end);
+	barebox_mem_len = get_unaligned((const u32 *)(pg_start + pg_len - 4));
 
 	if (IS_ENABLED(CONFIG_RELOCATABLE))
 		barebox_base = arm_mem_barebox_image(membase, endmem,
-						     pg_len);
+						     barebox_mem_len);
 	else
 		barebox_base = TEXT_BASE;
 
diff --git a/images/Makefile b/images/Makefile
index da9cc8d..cc76958 100644
--- a/images/Makefile
+++ b/images/Makefile
@@ -89,8 +89,12 @@ suffix_$(CONFIG_IMAGE_COMPRESSION_NONE) = shipped
 
 # barebox.z - compressed barebox binary
 # ----------------------------------------------------------------
+quiet_cmd_sizebss = SIZEBSS $@
+cmd_sizebss = $(call size_append, $<, $(obj)/../barebox) >> $@
+
 $(obj)/barebox.z: $(obj)/../barebox.bin FORCE
 	$(call if_changed,$(suffix_y))
+	$(call if_changed,sizebss)
 
 # %.img - create a copy from another file
 # ----------------------------------------------------------------
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index e55bc27..5b9d172 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -299,20 +299,17 @@ cmd_env=$(srctree)/scripts/genenv $(srctree) $(objtree) $@ $<
 
 # Bzip2 and LZMA do not include size in file... so we have to fake that;
 # append the size as a 32-bit littleendian number as gzip does.
-size_append = printf $(shell						\
-dec_size=0;								\
-for F in $1; do								\
-	fsize=$$(stat -c "%s" $$F);					\
-	dec_size=$$(expr $$dec_size + $$fsize);				\
+# If a second argument is supplied, include the BSS space it uses, as
+# this gives the memory needs to load a compressed binary.
+size_append = size=0;							\
+[ -n "$2" ] && size=`size -A $2 | awk '$$1==".bss"{print $$2}'`;	\
+for F in $1; do 							\
+	fsize=`stat -c %s $$F`;						\
+	size=$$((size + fsize));					\
 done;									\
-printf "%08x\n" $$dec_size |						\
-	sed 's/\(..\)/\1 /g' | {					\
-		read ch0 ch1 ch2 ch3;					\
-		for ch in $$ch3 $$ch2 $$ch1 $$ch0; do			\
-			printf '%s%03o' '\\' $$((0x$$ch)); 		\
-		done;							\
-	}								\
-)
+printf `printf '\\\\%03o\\\\%03o\\\\%03o\\\\%03o' 			\
+	$$((size&0xff)) $$((size>>8&0xff)) 				\
+	$$((size>>16&0xff)) $$((size>>24&0xff))`
 
 quiet_cmd_bzip2 = BZIP2   $@
 cmd_bzip2 = (cat $(filter-out FORCE,$^) | \
-- 
2.7.0.25.gfc10eb5.dirty


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

^ permalink raw reply related

* Re: How to port brcmnand Linux driver?
From: Eric Le Bihan @ 2016-09-21 15:09 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox
In-Reply-To: <20160921090500.bkrkohjxpye2gkc6@pengutronix.de>

> On Wed, Sep 21, 2016 at 10:40:43AM +0200, Eric Le Bihan wrote:
> >
> > I'm trying to port the brcmnand driver for Broadcom NAND controller
> > from Linux.
> > This driver requires an update of the MTD headers in barebox, as
> > they lack
> > definitions for functions such as mtd_set_ooblayout().
> > 
> > What is the recommended strategy for this? Should I update the
> > whole set of
> > headers and report the barebox specific changes (use of device_d,
> > etc) or only
> > add the missing functions?
> 
> For the mtd headers we usually only port the functions we need which
> worked good enough in the past.

OK. I've noticed that the use of mtd_set_ooblayout() was introduced in 
Linux 4.7. So I'll port brcmnand from 4.6, thus avoiding quite a few 
changes in the OOB/ECC management.

Thanks for your advices.

Best regards,

--
ELB

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

^ permalink raw reply

* Re: How to port brcmnand Linux driver?
From: Sascha Hauer @ 2016-09-21  9:05 UTC (permalink / raw)
  To: Eric Le Bihan; +Cc: barebox
In-Reply-To: <220039379.350137727.1474447243380.JavaMail.root@zimbra32-e6.priv.proxad.net>

On Wed, Sep 21, 2016 at 10:40:43AM +0200, Eric Le Bihan wrote:
> Hi!
> 
> I'm trying to port the brcmnand driver for Broadcom NAND controller from Linux.
> This driver requires an update of the MTD headers in barebox, as they lack 
> definitions for functions such as mtd_set_ooblayout().
> 
> What is the recommended strategy for this? Should I update the whole set of
> headers and report the barebox specific changes (use of device_d, etc) or only
> add the missing functions?

For the mtd headers we usually only port the functions we need which
worked good enough in the past.

> 
> In general, when adding such driver, should the functions unsupported by barebox
> (irq handling, memory barriers, etc) be stubbed or removed?

It's a matter of taste. I usually remove spin_locks and other things
that are not relevant for barebox, but we actually do have stubs for some
stuff. I recommend removing such functions, but in the end it's up to
you.

irq handling is normally an area which must be changed heavily anyway when
porting from Linux to barebox, so I wouldn't try to make it look like in
the Linux driver, just to make potential updates from a newer Linux driver
easier.

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-5555 |

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

^ permalink raw reply

* How to port brcmnand Linux driver?
From: Eric Le Bihan @ 2016-09-21  8:40 UTC (permalink / raw)
  To: barebox
In-Reply-To: <122759075.350079920.1474446203319.JavaMail.root@zimbra32-e6.priv.proxad.net>

Hi!

I'm trying to port the brcmnand driver for Broadcom NAND controller from Linux.
This driver requires an update of the MTD headers in barebox, as they lack 
definitions for functions such as mtd_set_ooblayout().

What is the recommended strategy for this? Should I update the whole set of
headers and report the barebox specific changes (use of device_d, etc) or only
add the missing functions?

In general, when adding such driver, should the functions unsupported by barebox
(irq handling, memory barriers, etc) be stubbed or removed?

Best regards,

--
ELB

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

^ permalink raw reply

* Re: [PATCH 1/2] net: add linux.bootarg parameter from ifup call
From: Sascha Hauer @ 2016-09-21  8:33 UTC (permalink / raw)
  To: Enrico Jorns; +Cc: barebox, Michael Olbrich, Gavin Schenk, u.kleine-koenig
In-Reply-To: <1474301029-22877-2-git-send-email-ejo@pengutronix.de>

On Mon, Sep 19, 2016 at 06:03:48PM +0200, Enrico Jorns wrote:
> This sets a `ip=dhcp` or
> `ip=<clientip>:<serverip>:<gatewayip>:<netmaskip>::<iface>:` bootarg for
> the network device upon execution of 'ifup'. This is the only point
> where we can distinguish between a static ip and a dhcp-based network
> setup and thus set a valid bootarg options as it will be required for
> nfs boot, for example.
> 
> Signed-off-by: Enrico Jorns <ejo@pengutronix.de>

Applied both with two little adjustments

> --- a/net/eth.c
> +++ b/net/eth.c
> @@ -384,6 +384,7 @@ int eth_register(struct eth_device *edev)
>  	dev_add_param_ip(dev, "netmask", NULL, NULL, &edev->netmask, edev);
>  	dev_add_param_mac(dev, "ethaddr", eth_param_set_ethaddr, NULL,
>  			edev->ethaddr, edev);
> +	dev_add_param_string(dev, "linux.bootargs", NULL, NULL, &edev->bootarg, NULL);

Added a edev->bootarg = xstrdup(""); here to not have a <NULL> string in
the variable when not initialized.

>  
>  	if (edev->init)
>  		edev->init(edev);
> diff --git a/net/ifup.c b/net/ifup.c
> index 30ac3f5..618eb8a 100644
> --- a/net/ifup.c
> +++ b/net/ifup.c
> @@ -106,12 +106,22 @@ int ifup(const char *name, unsigned flags)
>  		ret = eth_set_param(dev, "serverip");
>  		if (ret)
>  			goto out;
> +		dev_set_param(dev, "linux.bootargs", "ip=dhcp");
>  	} else if (!strcmp(ip, "static")) {
> +		char *bootarg;
>  		for (i = 0; i < ARRAY_SIZE(vars); i++) {
>  			ret = eth_set_param(dev, vars[i]);
>  			if (ret)
>  				goto out;
>  		}
> +		bootarg = basprintf("ip=%pI4:%pI4:%pI4:%pI4::%s:",
> +				&edev->ipaddr,
> +				&edev->serverip,
> +				&edev->gateway,
> +				&edev->netmask,
> +				edev->devname);

I dropped setting the devname here since we do not know if it's the same
under Linux. If there are multiple interfaces in Linux we can only hope
that the right one is used anyway.

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-5555 |

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

^ permalink raw reply

* Re: [PATCH] Documentation: imd: fix sphinx warning
From: Sascha Hauer @ 2016-09-21  8:12 UTC (permalink / raw)
  To: Antony Pavlov; +Cc: barebox
In-Reply-To: <20160920141301.10187-1-antonynpavlov@gmail.com>

On Tue, Sep 20, 2016 at 05:13:01PM +0300, Antony Pavlov wrote:
> The patch fixes this sphinx warnings:
> 
>     barebox/Documentation/user/imd.rst:27: WARNING: Could not lex literal_block as "c". Highlighting skipped.
> 
> Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
> Cc: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>  Documentation/user/imd.rst | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/Documentation/user/imd.rst b/Documentation/user/imd.rst
> index e0251d6..ce1b90c 100644
> --- a/Documentation/user/imd.rst
> +++ b/Documentation/user/imd.rst
> @@ -22,7 +22,9 @@ The informations can be extracted with the ``bareboximd`` tool which lives under
>  ``scripts/`` in the barebox sourcecode. If enabled it is compiled for the compile
>  host and also for the target architecture. barebox itself has the :ref:`command_imd`
>  command to extract the informations. Here is an example output of the tool called
> -without additional options::
> +without additional options:
> +
> +.. code-block:: none
>  
>    # imd barebox-phytec-pbab01dl-1gib.img
>    build: #890 Wed Jul 30 16:15:24 CEST 2014
> @@ -31,7 +33,9 @@ without additional options::
>    of_compatible: phytec,imx6x-pbab01 phytec,imx6dl-pfla02 fsl,imx6dl
>    model: Phytec phyFLEX-i.MX6 Duallite Carrier-Board
>  
> -Single informations can be extracted with the ``-t <type>`` option::
> +Single informations can be extracted with the ``-t <type>`` option:
> +
> +.. code-block:: none
>  
>    # imd barebox-phytec-pbab01dl-1gib.img -t release
>    2014.07.0-00167-ge6632a9-dirty
> -- 
> 2.9.3
> 
> 

-- 
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-5555 |

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

^ permalink raw reply

* Re: [PATCH 1/3] ARM: i.MX6: remove duplicate clock initialization
From: Sascha Hauer @ 2016-09-21  8:12 UTC (permalink / raw)
  To: Jan Luebbe; +Cc: barebox
In-Reply-To: <1474359462-32142-1-git-send-email-jlu@pengutronix.de>

On Tue, Sep 20, 2016 at 10:17:40AM +0200, Jan Luebbe wrote:
> These registers are already set by imx6_ccm_probe (in clk-imx6.c) during
> core_initcall, while imx6_init_lowlevel is only called during
> postcore_initcall via imx_init in imx.c.
> 
> Signed-off-by: Jan Luebbe <jlu@pengutronix.de>
> ---
>  arch/arm/mach-imx/imx6.c | 9 ---------
>  1 file changed, 9 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/arch/arm/mach-imx/imx6.c b/arch/arm/mach-imx/imx6.c
> index ba8fb8964ac8..dfd9a70200ec 100644
> --- a/arch/arm/mach-imx/imx6.c
> +++ b/arch/arm/mach-imx/imx6.c
> @@ -56,15 +56,6 @@ void imx6_init_lowlevel(void)
>  	writel(0, aips2 + 0x4c);
>  	writel(0, aips2 + 0x50);
>  
> -	/* enable all clocks */
> -	writel(0xffffffff, 0x020c4068);
> -	writel(0xffffffff, 0x020c406c);
> -	writel(0xffffffff, 0x020c4070);
> -	writel(0xffffffff, 0x020c4074);
> -	writel(0xffffffff, 0x020c4078);
> -	writel(0xffffffff, 0x020c407c);
> -	writel(0xffffffff, 0x020c4080);
> -
>  	/* Due to hardware limitation, on MX6Q we need to gate/ungate all PFDs
>  	 * to make sure PFD is working right, otherwise, PFDs may
>  	 * not output clock after reset, MX6DL and MX6SL have added 396M pfd
> -- 
> 2.1.4
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
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-5555 |

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

^ permalink raw reply

* Re: [PATCH] strings: new command
From: Sascha Hauer @ 2016-09-21  8:09 UTC (permalink / raw)
  To: Sam Ravnborg; +Cc: Barebox List
In-Reply-To: <20160917170731.GA30325@ravnborg.org>

On Sat, Sep 17, 2016 at 07:07:31PM +0200, Sam Ravnborg wrote:
> From 724382cf9aa173b6ced9fd213bbb369d9a5e3739 Mon Sep 17 00:00:00 2001
> From: Sam Ravnborg <sam@ravnborg.org>
> Date: Sat, 17 Sep 2016 19:01:15 +0200
> Subject: [PATCH 1/1] strings: new command
> 
> Implement a simple version of strings that will print
> printable strings from one or more files.
> Strings shall be at least 4 chars before thay are printed
> 
> Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
> ---
> 
> I was in a situation where I missed "strings".
> So here it is....
> I started out with cat.c - but ended up re-writing everything.
> 
> It has seen light testing on my x86 box.
> Ran it through checkpatch for good measure - fixed a few things.
> 
> The location in Makefile seems random, so I just put it next to cat.
> 
> Before applying please consider if strings is really
> general useful in barebox.

The first thing I tried is "strings /dev/ram0" Which gave me quite a
long list, especially when Linux was bootet before ;)

I first thought this command might be useful for debugging, but probably
it isn't because usually one wants to pipe the result through grep to
limit the output. Also the next interesting thing to know is the
position of a string which this command does not tell us.

I won't apply it, but it's on the list for reference if someone wants to
use it. Maybe he/she can then tell us a good reason why this command should
be merged.

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-5555 |

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

^ permalink raw reply

* [PATCH 2/2] commands: ubi: added the new command 'ubirename' to rename ubi volumes.
From: Giorgio Dal Molin @ 2016-09-21  8:04 UTC (permalink / raw)
  To: barebox; +Cc: Giorgio Dal Molin, Giorgio Dal Molin
In-Reply-To: <20160921080443.21522-1-iw3gtf@arcor.de>

From: Giorgio Dal Molin <giorgio.dal.molin@mobotix.com>

The syntax was taken from the corresponding command of the 'mts-utils'
userland package:

# ubirename UBIDEV OLD_NAME NEW_NAME [OLD_NAME NEW_NAME ...]

Signed-off-by: Giorgio Dal Molin <iw3gtf@arcor.de>
---
 commands/ubi.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 87 insertions(+)

diff --git a/commands/ubi.c b/commands/ubi.c
index 26b521f..3479340 100644
--- a/commands/ubi.c
+++ b/commands/ubi.c
@@ -6,6 +6,8 @@
 #include <errno.h>
 #include <getopt.h>
 #include <linux/mtd/mtd.h>
+#include <linux/mtd/ubi.h>
+#include <libgen.h>
 #include <linux/kernel.h>
 #include <linux/stat.h>
 #include <linux/mtd/mtd-abi.h>
@@ -306,3 +308,88 @@ BAREBOX_CMD_START(ubirmvol)
 	BAREBOX_CMD_GROUP(CMD_GRP_PART)
 	BAREBOX_CMD_HELP(cmd_ubirmvol_help)
 BAREBOX_CMD_END
+
+
+static int get_vol_id(const char *vol_name)
+{
+	struct ubi_volume_desc *desc;
+	struct cdev *vol_cdev;
+	struct ubi_volume_info vi;
+
+	vol_cdev = cdev_by_name(vol_name);
+	if(!vol_cdev) {
+		perror("cdev_by_name");
+		return -1;
+	}
+	desc = ubi_open_volume_cdev(vol_cdev, UBI_READONLY);
+	if(IS_ERR(desc)) {
+		perror("ubi_open_volume_cdev");
+		return -1;
+	}
+	ubi_get_volume_info(desc, &vi);
+	ubi_close_volume(desc);
+
+	return vi.vol_id;
+};
+
+static int do_ubirename(int argc, char *argv[])
+{
+	struct ubi_rnvol_req req;
+	struct cdev *ubi_cd;
+	int i, j, fd, ret;
+
+	if ((argc < 4) || (argc % 2))
+		return COMMAND_ERROR_USAGE;
+
+	req.count = (argc / 2) - 1;
+	if (req.count > UBI_MAX_RNVOL) {
+		printf("too many volume renames. (max: %u)\n", UBI_MAX_RNVOL);
+		return COMMAND_ERROR_USAGE;
+	}
+
+	ubi_cd = cdev_by_name(basename(argv[1]));
+	if(!ubi_cd || !ubi_cd->name || (strlen(ubi_cd->name)>127)) {
+		printf("arg 1 (%s) is not an ubi device.\n", argv[1]);
+		return COMMAND_ERROR_USAGE;
+	}
+
+	for(i=2, j=0; i<argc; ++j, i+=2) {
+		char vol_name[128 + UBI_MAX_VOLUME_NAME];
+
+		snprintf(vol_name, sizeof(vol_name), "%s.%s", ubi_cd->name, argv[i]);
+		req.ents[j].vol_id = get_vol_id(vol_name);
+		if(req.ents[j].vol_id < 0) {
+			printf("'%s' is not a volume name.\n", vol_name);
+			return COMMAND_ERROR_USAGE;
+		}
+		strncpy(req.ents[j].name, argv[i+1], UBI_MAX_VOLUME_NAME);
+		req.ents[j].name_len = strlen(req.ents[j].name);
+	}
+
+	fd = open(argv[1], O_WRONLY);
+	if (fd < 0) {
+		perror("open");
+		return 1;
+	}
+
+	ret = ioctl(fd, UBI_IOCRNVOL, &req);
+	if (ret)
+		printf("failed to rename: %s\n", strerror(-ret));
+
+	close(fd);
+
+	return ret ? 1 : 0;
+
+}
+
+BAREBOX_CMD_HELP_START(ubirename)
+BAREBOX_CMD_HELP_TEXT("Rename UBI volume(s) from UBIDEV")
+BAREBOX_CMD_HELP_END
+
+BAREBOX_CMD_START(ubirename)
+	.cmd		= do_ubirename,
+	BAREBOX_CMD_DESC("rename UBI volume(s)")
+	BAREBOX_CMD_OPTS("UBIDEV OLD_NAME NEW_NAME [OLD_NAME NEW_NAME ...]")
+	BAREBOX_CMD_GROUP(CMD_GRP_PART)
+	BAREBOX_CMD_HELP(cmd_ubirename_help)
+BAREBOX_CMD_END
-- 
2.10.0


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

^ permalink raw reply related

* [PATCH 1/2] mtd: UBI: add support (ioctl) for renaming ubi volumes.
From: Giorgio Dal Molin @ 2016-09-21  8:04 UTC (permalink / raw)
  To: barebox; +Cc: Giorgio Dal Molin, Giorgio Dal Molin
In-Reply-To: <20160921080443.21522-1-iw3gtf@arcor.de>

From: Giorgio Dal Molin <giorgio.dal.molin@mobotix.com>

The actual implementation was taken from the current linux kernel v4.7.4.

Signed-off-by: Giorgio Dal Molin <iw3gtf@arcor.de>
---
 drivers/mtd/ubi/barebox.c | 182 ++++++++++++++++++++++++++++++++++++++++++++--
 drivers/mtd/ubi/vmt.c     |   3 +
 2 files changed, 180 insertions(+), 5 deletions(-)

diff --git a/drivers/mtd/ubi/barebox.c b/drivers/mtd/ubi/barebox.c
index fc60aae..6d3bdaf 100644
--- a/drivers/mtd/ubi/barebox.c
+++ b/drivers/mtd/ubi/barebox.c
@@ -203,6 +203,168 @@ static int ubi_volume_cdev_ioctl(struct cdev *cdev, int cmd, void *buf)
 	return err;
 }
 
+/**
+ * rename_volumes - rename UBI volumes.
+ * @ubi: UBI device description object
+ * @req: volumes re-name request
+ *
+ * This is a helper function for the volume re-name IOCTL which validates the
+ * the request, opens the volume and calls corresponding volumes management
+ * function. Returns zero in case of success and a negative error code in case
+ * of failure.
+ */
+static int rename_volumes(struct ubi_device *ubi,
+			  struct ubi_rnvol_req *req)
+{
+	int i, n, err;
+	struct list_head rename_list;
+	struct ubi_rename_entry *re, *re1;
+
+	if (req->count < 0 || req->count > UBI_MAX_RNVOL)
+		return -EINVAL;
+
+	if (req->count == 0)
+		return 0;
+
+	/* Validate volume IDs and names in the request */
+	for (i = 0; i < req->count; i++) {
+		if (req->ents[i].vol_id < 0 ||
+		    req->ents[i].vol_id >= ubi->vtbl_slots)
+			return -EINVAL;
+		if (req->ents[i].name_len < 0)
+			return -EINVAL;
+		if (req->ents[i].name_len > UBI_VOL_NAME_MAX)
+			return -ENAMETOOLONG;
+		req->ents[i].name[req->ents[i].name_len] = '\0';
+		n = strlen(req->ents[i].name);
+		if (n != req->ents[i].name_len)
+			return -EINVAL;
+	}
+
+	/* Make sure volume IDs and names are unique */
+	for (i = 0; i < req->count - 1; i++) {
+		for (n = i + 1; n < req->count; n++) {
+			if (req->ents[i].vol_id == req->ents[n].vol_id) {
+				ubi_err(ubi, "duplicated volume id %d",
+					req->ents[i].vol_id);
+				return -EINVAL;
+			}
+			if (!strcmp(req->ents[i].name, req->ents[n].name)) {
+				ubi_err(ubi, "duplicated volume name \"%s\"",
+					req->ents[i].name);
+				return -EINVAL;
+			}
+		}
+	}
+
+	/* Create the re-name list */
+	INIT_LIST_HEAD(&rename_list);
+	for (i = 0; i < req->count; i++) {
+		int vol_id = req->ents[i].vol_id;
+		int name_len = req->ents[i].name_len;
+		const char *name = req->ents[i].name;
+
+		re = kzalloc(sizeof(struct ubi_rename_entry), GFP_KERNEL);
+		if (!re) {
+			err = -ENOMEM;
+			goto out_free;
+		}
+
+		re->desc = ubi_open_volume(ubi->ubi_num, vol_id, UBI_READONLY);
+		if (IS_ERR(re->desc)) {
+			err = PTR_ERR(re->desc);
+			ubi_err(ubi, "cannot open volume %d, error %d",
+				vol_id, err);
+			kfree(re);
+			goto out_free;
+		}
+
+		/* Skip this re-naming if the name does not really change */
+		if (re->desc->vol->name_len == name_len &&
+		    !memcmp(re->desc->vol->name, name, name_len)) {
+			ubi_close_volume(re->desc);
+			kfree(re);
+			continue;
+		}
+
+		re->new_name_len = name_len;
+		memcpy(re->new_name, name, name_len);
+		list_add_tail(&re->list, &rename_list);
+		dbg_gen("will rename volume %d from \"%s\" to \"%s\"",
+			vol_id, re->desc->vol->name, name);
+	}
+
+	if (list_empty(&rename_list))
+		return 0;
+
+	/* Find out the volumes which have to be removed */
+	list_for_each_entry(re, &rename_list, list) {
+		struct ubi_volume_desc *desc;
+		int no_remove_needed = 0;
+
+		/*
+		 * Volume @re->vol_id is going to be re-named to
+		 * @re->new_name, while its current name is @name. If a volume
+		 * with name @re->new_name currently exists, it has to be
+		 * removed, unless it is also re-named in the request (@req).
+		 */
+		list_for_each_entry(re1, &rename_list, list) {
+			if (re->new_name_len == re1->desc->vol->name_len &&
+			    !memcmp(re->new_name, re1->desc->vol->name,
+				    re1->desc->vol->name_len)) {
+				no_remove_needed = 1;
+				break;
+			}
+		}
+
+		if (no_remove_needed)
+			continue;
+
+		/*
+		 * It seems we need to remove volume with name @re->new_name,
+		 * if it exists.
+		 */
+		desc = ubi_open_volume_nm(ubi->ubi_num, re->new_name,
+					  UBI_EXCLUSIVE);
+		if (IS_ERR(desc)) {
+			err = PTR_ERR(desc);
+			if (err == -ENODEV)
+				/* Re-naming into a non-existing volume name */
+				continue;
+
+			/* The volume exists but busy, or an error occurred */
+			ubi_err(ubi, "cannot open volume \"%s\", error %d",
+				re->new_name, err);
+			goto out_free;
+		}
+
+		re1 = kzalloc(sizeof(struct ubi_rename_entry), GFP_KERNEL);
+		if (!re1) {
+			err = -ENOMEM;
+			ubi_close_volume(desc);
+			goto out_free;
+		}
+
+		re1->remove = 1;
+		re1->desc = desc;
+		list_add(&re1->list, &rename_list);
+		dbg_gen("will remove volume %d, name \"%s\"",
+			re1->desc->vol->vol_id, re1->desc->vol->name);
+	}
+
+	mutex_lock(&ubi->device_mutex);
+	err = ubi_rename_volumes(ubi, &rename_list);
+	mutex_unlock(&ubi->device_mutex);
+
+out_free:
+	list_for_each_entry_safe(re, re1, &rename_list, list) {
+		ubi_close_volume(re->desc);
+		list_del(&re->list);
+		kfree(re);
+	}
+	return err;
+}
+
 static struct file_operations ubi_volume_fops = {
 	.open	= ubi_volume_cdev_open,
 	.close	= ubi_volume_cdev_close,
@@ -261,10 +423,11 @@ static int ubi_cdev_ioctl(struct cdev *cdev, int cmd, void *buf)
 {
 	struct ubi_volume_desc *desc;
 	struct ubi_device *ubi = cdev->priv;
-	struct ubi_mkvol_req *req = buf;
 
 	switch (cmd) {
-	case UBI_IOCRMVOL:
+	case UBI_IOCRMVOL: {
+		struct ubi_mkvol_req *req = buf;
+
 		desc = ubi_open_volume_nm(ubi->ubi_num, req->name,
                                            UBI_EXCLUSIVE);
 		if (IS_ERR(desc))
@@ -272,13 +435,22 @@ static int ubi_cdev_ioctl(struct cdev *cdev, int cmd, void *buf)
 		ubi_remove_volume(desc, 0);
 		ubi_close_volume(desc);
 		break;
-	case UBI_IOCMKVOL:
+	}
+	case UBI_IOCMKVOL: {
+		struct ubi_mkvol_req *req = buf;
+
 		if (!req->bytes)
 			req->bytes = (__s64)ubi->avail_pebs * ubi->leb_size;
 		return ubi_create_volume(ubi, req);
-	};
+	}
+	case UBI_IOCRNVOL: {
+		struct ubi_rnvol_req *req = buf;
 
-	return 0;
+		return rename_volumes(ubi, req);
+	}
+	default:
+		return -ENOTTY;
+	};
 }
 
 static struct file_operations ubi_fops = {
diff --git a/drivers/mtd/ubi/vmt.c b/drivers/mtd/ubi/vmt.c
index 41b814c..ed04364 100644
--- a/drivers/mtd/ubi/vmt.c
+++ b/drivers/mtd/ubi/vmt.c
@@ -411,6 +411,9 @@ int ubi_rename_volumes(struct ubi_device *ubi, struct list_head *rename_list)
 
 			vol->name_len = re->new_name_len;
 			memcpy(vol->name, re->new_name, re->new_name_len + 1);
+			free(vol->cdev.name);
+			vol->cdev.name = basprintf("%s.%s", ubi->cdev.name, vol->name);
+			vol->cdev.size = vol->used_bytes;
 			ubi_volume_notify(ubi, vol, UBI_VOLUME_RENAMED);
 		}
 	}
-- 
2.10.0


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

^ permalink raw reply related

* [PATCH 0/2] added support for renaming UBI volumes.
From: Giorgio Dal Molin @ 2016-09-21  8:04 UTC (permalink / raw)
  To: barebox; +Cc: Giorgio Dal Molin

These two patches implement the ioctl UBI_IOCRNVOL for UBI devices and a new
command, 'ubirename' that calls the ioctl from the shell to rename UBI volumes.

The ioctl implementation was ported from the linux kernel v4.7.4, with minimal
changes; a further change was needed for the function 'ubi_rename_volumes()' in
drivers/mtd/ubi/vmt.c to also change the name(s) of the file(s) corresponding to
the renamed UBI volumes under /dev/...

Expecially this last change needs to be reviewed and validated by a barebox
developer more experienced than me.

	
Giorgio Dal Molin (2):
  mtd: UBI: add support (ioctl) for renaming ubi volumes.
  commands: ubi: added the new command 'ubirename' to rename ubi
    volumes.

 commands/ubi.c            |  87 ++++++++++++++++++++++
 drivers/mtd/ubi/barebox.c | 182 ++++++++++++++++++++++++++++++++++++++++++++--
 drivers/mtd/ubi/vmt.c     |   3 +
 3 files changed, 267 insertions(+), 5 deletions(-)

-- 
2.10.0


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

^ permalink raw reply

* Re: [PATCH v2 1/3] state: copy backend of_path string
From: Sascha Hauer @ 2016-09-21  7:52 UTC (permalink / raw)
  To: Antony Pavlov; +Cc: barebox, Michael Olbrich
In-Reply-To: <20160916111243.1dc2a3f16421fb33831817a0@gmail.com>

On Fri, Sep 16, 2016 at 11:12:43AM +0300, Antony Pavlov wrote:
> On Fri, 16 Sep 2016 08:43:38 +0200
> Michael Olbrich <m.olbrich@pengutronix.de> wrote:
> 
> > Caching pointers to device tree nodes or names is not save. The barebox
>                                                         ^^^^ safe?

Fixed, thanks

Sascha

> > internal device tree may be changed by loading a new device tree or through
> > fixup handlers. As a result, the string may be deleted.
> > Use local copies of the full path instead.
> > 
> > Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
> 
> -- 
> Best regards,
>   Antony Pavlov
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
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-5555 |

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

^ permalink raw reply

* [PATCH 1/2] globalvar: Move static inline functions to common/
From: Sascha Hauer @ 2016-09-20 14:26 UTC (permalink / raw)
  To: Barebox List

These functions will get bigger in the next patch which disqualifies
them as static inline functions.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/globalvar.c  | 67 ++++++++++++++++++++++++++++++++++++++++++++++
 include/globalvar.h | 76 +++++------------------------------------------------
 2 files changed, 74 insertions(+), 69 deletions(-)

diff --git a/common/globalvar.c b/common/globalvar.c
index 44e6528..49f7f7d 100644
--- a/common/globalvar.c
+++ b/common/globalvar.c
@@ -437,6 +437,73 @@ int globalvar_add_simple(const char *name, const char *value)
 	return dev_set_param(&global_device, name, value);
 }
 
+int globalvar_add_simple_string(const char *name, char **value)
+{
+	struct param_d *p;
+
+	p = dev_add_param_string(&global_device, name, NULL, NULL,
+		value, NULL);
+
+	if (IS_ERR(p))
+		return PTR_ERR(p);
+
+	return 0;
+}
+
+int globalvar_add_simple_int(const char *name, int *value,
+			     const char *format)
+{
+	struct param_d *p;
+
+	p = dev_add_param_int(&global_device, name, NULL, NULL,
+		value, format, NULL);
+
+	if (IS_ERR(p))
+		return PTR_ERR(p);
+
+	return 0;
+}
+
+int globalvar_add_simple_bool(const char *name, int *value)
+{
+	struct param_d *p;
+
+	p = dev_add_param_bool(&global_device, name, NULL, NULL,
+		value, NULL);
+
+	if (IS_ERR(p))
+		return PTR_ERR(p);
+
+	return 0;
+}
+
+int globalvar_add_simple_enum(const char *name,	int *value,
+			      const char * const *names, int max)
+{
+	struct param_d *p;
+
+	p = dev_add_param_enum(&global_device, name, NULL, NULL,
+		value, names, max, NULL);
+
+	if (IS_ERR(p))
+		return PTR_ERR(p);
+
+	return 0;
+}
+
+int globalvar_add_simple_ip(const char *name, IPaddr_t *ip)
+{
+	struct param_d *p;
+
+	p = dev_add_param_ip(&global_device, name, NULL, NULL,
+		ip, NULL);
+
+	if (IS_ERR(p))
+		return PTR_ERR(p);
+
+	return 0;
+}
+
 static int globalvar_init(void)
 {
 	register_device(&global_device);
diff --git a/include/globalvar.h b/include/globalvar.h
index 1cd8d21..2322efb 100644
--- a/include/globalvar.h
+++ b/include/globalvar.h
@@ -18,75 +18,13 @@ void globalvar_remove(const char *name);
 char *globalvar_get_match(const char *match, const char *separator);
 void globalvar_set_match(const char *match, const char *val);
 
-static inline int globalvar_add_simple_string(const char *name,
-		char **value)
-{
-	struct param_d *p;
-
-	p = dev_add_param_string(&global_device, name, NULL, NULL,
-		value, NULL);
-
-	if (IS_ERR(p))
-		return PTR_ERR(p);
-
-	return 0;
-}
-
-static inline int globalvar_add_simple_int(const char *name,
-		int *value, const char *format)
-{
-	struct param_d *p;
-
-	p = dev_add_param_int(&global_device, name, NULL, NULL,
-		value, format, NULL);
-
-	if (IS_ERR(p))
-		return PTR_ERR(p);
-
-	return 0;
-}
-
-static inline int globalvar_add_simple_bool(const char *name,
-		int *value)
-{
-	struct param_d *p;
-
-	p = dev_add_param_bool(&global_device, name, NULL, NULL,
-		value, NULL);
-
-	if (IS_ERR(p))
-		return PTR_ERR(p);
-
-	return 0;
-}
-
-static inline int globalvar_add_simple_enum(const char *name,
-		int *value, const char * const *names, int max)
-{
-	struct param_d *p;
-
-	p = dev_add_param_enum(&global_device, name, NULL, NULL,
-		value, names, max, NULL);
-
-	if (IS_ERR(p))
-		return PTR_ERR(p);
-
-	return 0;
-}
-
-static inline int globalvar_add_simple_ip(const char *name,
-		IPaddr_t *ip)
-{
-	struct param_d *p;
-
-	p = dev_add_param_ip(&global_device, name, NULL, NULL,
-		ip, NULL);
-
-	if (IS_ERR(p))
-		return PTR_ERR(p);
-
-	return 0;
-}
+int globalvar_add_simple_string(const char *name, char **value);
+int globalvar_add_simple_int(const char *name, int *value,
+			     const char *format);
+int globalvar_add_simple_bool(const char *name, int *value);
+int globalvar_add_simple_enum(const char *name,	int *value,
+			      const char * const *names, int max);
+int globalvar_add_simple_ip(const char *name, IPaddr_t *ip);
 
 int nvvar_load(void);
 void nvvar_print(void);
-- 
2.8.1


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

^ permalink raw reply related

* [PATCH 2/2] globalvar: sync with nvvars
From: Sascha Hauer @ 2016-09-20 14:26 UTC (permalink / raw)
  To: Barebox List
In-Reply-To: <1474381562-4330-1-git-send-email-s.hauer@pengutronix.de>

This patch fixes the behaviour when a driver creates a globalvar using
globalvar_add_simple_[string|int|bool|enum|ip]) *after* nvvars are
initialized and this globalvar is overwritten with a nvvar. Currently
this fix is not needed because all globalvars are registered before the
nvvars are initialized.

We have two different typed of globalvars. The first type, here referred
to as qualified globalvars, has a backend variable storage (the ones
created with globalvar_add_simple_[string|int|bool|enum|ip]), the other
created with globalvar_add_simple only has a dynamically allocted string
as backend.

Normally during startup of barebox the qualified globalvars are
registered and during load of nvvars are synced with the values from the
nvvars. Everything works fine in this case. However, when during nvvar
initialisation a globalvar for a nvvar does not exist, then it is
registered as unqualified globalvar. When then later some driver wants
to register a qualified globalvar for which a unqualified globalvar
already exists, it will get a -EEXIST. This is not the expected
behaviour. Instead, the current unqualified globalvar should be removed,
recreated as qualified globalvar and then afterwards synced with the
corresponding nvvar. This behaviour is fixed with this patch.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/globalvar.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++---
 include/param.h    |  1 +
 2 files changed, 68 insertions(+), 4 deletions(-)

diff --git a/common/globalvar.c b/common/globalvar.c
index 49f7f7d..3fd8221 100644
--- a/common/globalvar.c
+++ b/common/globalvar.c
@@ -425,11 +425,14 @@ void globalvar_set_match(const char *match, const char *val)
  */
 int globalvar_add_simple(const char *name, const char *value)
 {
-	int ret;
+	struct param_d *param;
 
-	ret = globalvar_add(name, NULL, NULL, 0);
-	if (ret && ret != -EEXIST)
-		return ret;
+	param = dev_add_param(&global_device, name, NULL, NULL,
+			      PARAM_GLOBALVAR_UNQUALIFIED);
+	if (IS_ERR(param)) {
+		if (PTR_ERR(param) != -EEXIST)
+			return PTR_ERR(param);
+	}
 
 	if (!value)
 		return 0;
@@ -437,9 +440,39 @@ int globalvar_add_simple(const char *name, const char *value)
 	return dev_set_param(&global_device, name, value);
 }
 
+static int globalvar_remove_unqualified(const char *name)
+{
+	struct param_d *p;
+
+	p = get_param_by_name(&global_device, name);
+	if (!p)
+		return 0;
+
+	if (!(p->flags & PARAM_GLOBALVAR_UNQUALIFIED))
+		return -EEXIST;
+
+	dev_remove_param(p);
+
+	return 0;
+}
+
+static void globalvar_nv_sync(const char *name)
+{
+	const char *val;
+
+	val = dev_get_param(&nv_device, name);
+	if (val)
+		dev_set_param(&global_device, name, val);
+}
+
 int globalvar_add_simple_string(const char *name, char **value)
 {
 	struct param_d *p;
+	int ret;
+
+	ret = globalvar_remove_unqualified(name);
+	if (ret)
+		return ret;
 
 	p = dev_add_param_string(&global_device, name, NULL, NULL,
 		value, NULL);
@@ -447,6 +480,8 @@ int globalvar_add_simple_string(const char *name, char **value)
 	if (IS_ERR(p))
 		return PTR_ERR(p);
 
+	globalvar_nv_sync(name);
+
 	return 0;
 }
 
@@ -454,6 +489,11 @@ int globalvar_add_simple_int(const char *name, int *value,
 			     const char *format)
 {
 	struct param_d *p;
+	int ret;
+
+	ret = globalvar_remove_unqualified(name);
+	if (ret)
+		return ret;
 
 	p = dev_add_param_int(&global_device, name, NULL, NULL,
 		value, format, NULL);
@@ -461,12 +501,19 @@ int globalvar_add_simple_int(const char *name, int *value,
 	if (IS_ERR(p))
 		return PTR_ERR(p);
 
+	globalvar_nv_sync(name);
+
 	return 0;
 }
 
 int globalvar_add_simple_bool(const char *name, int *value)
 {
 	struct param_d *p;
+	int ret;
+
+	ret = globalvar_remove_unqualified(name);
+	if (ret)
+		return ret;
 
 	p = dev_add_param_bool(&global_device, name, NULL, NULL,
 		value, NULL);
@@ -474,6 +521,8 @@ int globalvar_add_simple_bool(const char *name, int *value)
 	if (IS_ERR(p))
 		return PTR_ERR(p);
 
+	globalvar_nv_sync(name);
+
 	return 0;
 }
 
@@ -481,6 +530,11 @@ int globalvar_add_simple_enum(const char *name,	int *value,
 			      const char * const *names, int max)
 {
 	struct param_d *p;
+	int ret;
+
+	ret = globalvar_remove_unqualified(name);
+	if (ret)
+		return ret;
 
 	p = dev_add_param_enum(&global_device, name, NULL, NULL,
 		value, names, max, NULL);
@@ -488,12 +542,19 @@ int globalvar_add_simple_enum(const char *name,	int *value,
 	if (IS_ERR(p))
 		return PTR_ERR(p);
 
+	globalvar_nv_sync(name);
+
 	return 0;
 }
 
 int globalvar_add_simple_ip(const char *name, IPaddr_t *ip)
 {
 	struct param_d *p;
+	int ret;
+
+	ret = globalvar_remove_unqualified(name);
+	if (ret)
+		return ret;
 
 	p = dev_add_param_ip(&global_device, name, NULL, NULL,
 		ip, NULL);
@@ -501,6 +562,8 @@ int globalvar_add_simple_ip(const char *name, IPaddr_t *ip)
 	if (IS_ERR(p))
 		return PTR_ERR(p);
 
+	globalvar_nv_sync(name);
+
 	return 0;
 }
 
diff --git a/include/param.h b/include/param.h
index 3fb4740..68e08a2 100644
--- a/include/param.h
+++ b/include/param.h
@@ -6,6 +6,7 @@
 #include <linux/list.h>
 
 #define PARAM_FLAG_RO	(1 << 0)
+#define PARAM_GLOBALVAR_UNQUALIFIED	(1 << 1)
 
 struct device_d;
 typedef uint32_t          IPaddr_t;
-- 
2.8.1


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

^ permalink raw reply related

* [PATCH] Documentation: imd: fix sphinx warning
From: Antony Pavlov @ 2016-09-20 14:13 UTC (permalink / raw)
  To: barebox

The patch fixes this sphinx warnings:

    barebox/Documentation/user/imd.rst:27: WARNING: Could not lex literal_block as "c". Highlighting skipped.

Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
---
 Documentation/user/imd.rst | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/Documentation/user/imd.rst b/Documentation/user/imd.rst
index e0251d6..ce1b90c 100644
--- a/Documentation/user/imd.rst
+++ b/Documentation/user/imd.rst
@@ -22,7 +22,9 @@ The informations can be extracted with the ``bareboximd`` tool which lives under
 ``scripts/`` in the barebox sourcecode. If enabled it is compiled for the compile
 host and also for the target architecture. barebox itself has the :ref:`command_imd`
 command to extract the informations. Here is an example output of the tool called
-without additional options::
+without additional options:
+
+.. code-block:: none
 
   # imd barebox-phytec-pbab01dl-1gib.img
   build: #890 Wed Jul 30 16:15:24 CEST 2014
@@ -31,7 +33,9 @@ without additional options::
   of_compatible: phytec,imx6x-pbab01 phytec,imx6dl-pfla02 fsl,imx6dl
   model: Phytec phyFLEX-i.MX6 Duallite Carrier-Board
 
-Single informations can be extracted with the ``-t <type>`` option::
+Single informations can be extracted with the ``-t <type>`` option:
+
+.. code-block:: none
 
   # imd barebox-phytec-pbab01dl-1gib.img -t release
   2014.07.0-00167-ge6632a9-dirty
-- 
2.9.3


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

^ permalink raw reply related

* [PATCH 2/3] state: make locally used function static
From: Sascha Hauer @ 2016-09-20  8:30 UTC (permalink / raw)
  To: Barebox List
In-Reply-To: <1474360242-3512-1-git-send-email-s.hauer@pengutronix.de>

state_set_dirty() is only used in one file, make it static.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/state/state.h           | 1 -
 common/state/state_variables.c | 2 +-
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/common/state/state.h b/common/state/state.h
index 855ba9d..bc6917d 100644
--- a/common/state/state.h
+++ b/common/state/state.h
@@ -190,7 +190,6 @@ struct state_string {
 	char raw[];
 };
 
-int state_set_dirty(struct param_d *p, void *priv);
 int state_from_node(struct state *state, struct device_node *node, bool create);
 struct device_node *state_to_node(struct state *state,
 				  struct device_node *parent,
diff --git a/common/state/state_variables.c b/common/state/state_variables.c
index 4f82462..6f2b1ae 100644
--- a/common/state/state_variables.c
+++ b/common/state/state_variables.c
@@ -34,7 +34,7 @@
  * @param priv
  * @return
  */
-int state_set_dirty(struct param_d *p, void *priv)
+static int state_set_dirty(struct param_d *p, void *priv)
 {
 	struct state *state = priv;
 
-- 
2.8.1


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

^ permalink raw reply related

* [PATCH 3/3] state: consistently pass one type as private data to dev_add_param_*
From: Sascha Hauer @ 2016-09-20  8:30 UTC (permalink / raw)
  To: Barebox List
In-Reply-To: <1474360242-3512-1-git-send-email-s.hauer@pengutronix.de>

The different dev_add_param_* calls all use different types as private
data. This is unnecessary, use struct state_variable * for all of them.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/state/state_variables.c | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)

diff --git a/common/state/state_variables.c b/common/state/state_variables.c
index 6f2b1ae..efc2456 100644
--- a/common/state/state_variables.c
+++ b/common/state/state_variables.c
@@ -36,9 +36,9 @@
  */
 static int state_set_dirty(struct param_d *p, void *priv)
 {
-	struct state *state = priv;
+	struct state_variable *sv = priv;
 
-	state->dirty = 1;
+	sv->state->dirty = 1;
 
 	return 0;
 }
@@ -90,13 +90,13 @@ static int state_uint32_import(struct state_variable *sv,
 
 static int state_uint8_set(struct param_d *p, void *priv)
 {
-	struct state_uint32 *su32 = priv;
-	struct state *state = su32->var.state;
+	struct state_variable *sv = priv;
+	struct state_uint32 *su32 = to_state_uint32(sv);
 
 	if (su32->value > 255)
 		return -ERANGE;
 
-	return state_set_dirty(p, state);
+	return state_set_dirty(p, sv);
 }
 
 static struct state_variable *state_uint8_create(struct state *state,
@@ -109,7 +109,7 @@ static struct state_variable *state_uint8_create(struct state *state,
 	su32 = xzalloc(sizeof(*su32));
 
 	param = dev_add_param_int(&state->dev, name, state_uint8_set,
-				  NULL, &su32->value, "%u", su32);
+				  NULL, &su32->value, "%u", &su32->var);
 	if (IS_ERR(param)) {
 		free(su32);
 		return ERR_CAST(param);
@@ -137,7 +137,7 @@ static struct state_variable *state_uint32_create(struct state *state,
 	su32 = xzalloc(sizeof(*su32));
 
 	param = dev_add_param_int(&state->dev, name, state_set_dirty,
-				  NULL, &su32->value, "%u", state);
+				  NULL, &su32->value, "%u", &su32->var);
 	if (IS_ERR(param)) {
 		free(su32);
 		return ERR_CAST(param);
@@ -249,7 +249,7 @@ static struct state_variable *state_enum32_create(struct state *state,
 
 	enum32->param = dev_add_param_enum(&state->dev, name, state_set_dirty,
 					   NULL, &enum32->value, enum32->names,
-					   num_names, state);
+					   num_names, &enum32->var);
 	if (IS_ERR(enum32->param)) {
 		ret = PTR_ERR(enum32->param);
 		goto out;
@@ -312,7 +312,7 @@ static struct state_variable *state_mac_create(struct state *state,
 	mac->var.state = state;
 
 	mac->param = dev_add_param_mac(&state->dev, name, state_set_dirty,
-				       NULL, mac->value, state);
+				       NULL, mac->value, &mac->var);
 	if (IS_ERR(mac->param)) {
 		ret = PTR_ERR(mac->param);
 		goto out;
@@ -375,20 +375,21 @@ static int state_string_import(struct state_variable *sv,
 
 static int state_string_set(struct param_d *p, void *priv)
 {
-	struct state_string *string = priv;
-	struct state *state = string->var.state;
+	struct state_variable *sv = priv;
+	struct state_string *string = to_state_string(sv);
 	int ret;
 
 	ret = state_string_copy_to_raw(string, string->value);
 	if (ret)
 		return ret;
 
-	return state_set_dirty(p, state);
+	return state_set_dirty(p, sv->state);
 }
 
 static int state_string_get(struct param_d *p, void *priv)
 {
-	struct state_string *string = priv;
+	struct state_variable *sv = priv;
+	struct state_string *string = to_state_string(sv);
 
 	free(string->value);
 	if (string->raw[0])
@@ -425,7 +426,7 @@ static struct state_variable *state_string_create(struct state *state,
 
 	string->param = dev_add_param_string(&state->dev, name,
 					     state_string_set, state_string_get,
-					     &string->value, string);
+					     &string->value, &string->var);
 	if (IS_ERR(string->param)) {
 		ret = PTR_ERR(string->param);
 		goto out;
-- 
2.8.1


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

^ permalink raw reply related

* [PATCH 1/3] state: Add state to state_variable
From: Sascha Hauer @ 2016-09-20  8:30 UTC (permalink / raw)
  To: Barebox List

A state variable should know which state it belongs to. Add field
for it to struct state_variable.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/state/state.h           |  3 +--
 common/state/state_variables.c | 11 +++++++----
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/common/state/state.h b/common/state/state.h
index 7b3e495..855ba9d 100644
--- a/common/state/state.h
+++ b/common/state/state.h
@@ -138,6 +138,7 @@ struct variable_type {
 
 /* instance of a single variable */
 struct state_variable {
+	struct state *state;
 	enum state_variable_type type;
 	struct list_head list;
 	const char *name;
@@ -152,7 +153,6 @@ struct state_variable {
 struct state_uint32 {
 	struct state_variable var;
 	struct param_d *param;
-	struct state *state;
 	uint32_t value;
 	uint32_t value_default;
 };
@@ -185,7 +185,6 @@ struct state_mac {
 struct state_string {
 	struct state_variable var;
 	struct param_d *param;
-	struct state *state;
 	char *value;
 	const char *value_default;
 	char raw[];
diff --git a/common/state/state_variables.c b/common/state/state_variables.c
index 0d2a626..4f82462 100644
--- a/common/state/state_variables.c
+++ b/common/state/state_variables.c
@@ -91,7 +91,7 @@ static int state_uint32_import(struct state_variable *sv,
 static int state_uint8_set(struct param_d *p, void *priv)
 {
 	struct state_uint32 *su32 = priv;
-	struct state *state = su32->state;
+	struct state *state = su32->var.state;
 
 	if (su32->value > 255)
 		return -ERANGE;
@@ -122,7 +122,7 @@ static struct state_variable *state_uint8_create(struct state *state,
 #else
 	su32->var.raw = &su32->value + 3;
 #endif
-	su32->state = state;
+	su32->var.state = state;
 
 	return &su32->var;
 }
@@ -146,6 +146,7 @@ static struct state_variable *state_uint32_create(struct state *state,
 	su32->param = param;
 	su32->var.size = sizeof(uint32_t);
 	su32->var.raw = &su32->value;
+	su32->var.state = state;
 
 	return &su32->var;
 }
@@ -235,6 +236,7 @@ static struct state_variable *state_enum32_create(struct state *state,
 	enum32->num_names = num_names;
 	enum32->var.size = sizeof(uint32_t);
 	enum32->var.raw = &enum32->value;
+	enum32->var.state = state;
 
 	for (i = 0; i < num_names; i++) {
 		const char *name;
@@ -307,6 +309,7 @@ static struct state_variable *state_mac_create(struct state *state,
 
 	mac->var.size = ARRAY_SIZE(mac->value);
 	mac->var.raw = mac->value;
+	mac->var.state = state;
 
 	mac->param = dev_add_param_mac(&state->dev, name, state_set_dirty,
 				       NULL, mac->value, state);
@@ -373,7 +376,7 @@ static int state_string_import(struct state_variable *sv,
 static int state_string_set(struct param_d *p, void *priv)
 {
 	struct state_string *string = priv;
-	struct state *state = string->state;
+	struct state *state = string->var.state;
 	int ret;
 
 	ret = state_string_copy_to_raw(string, string->value);
@@ -418,7 +421,7 @@ static struct state_variable *state_string_create(struct state *state,
 	string = xzalloc(sizeof(*string) + start_size[1]);
 	string->var.size = start_size[1];
 	string->var.raw = &string->raw;
-	string->state = state;
+	string->var.state = state;
 
 	string->param = dev_add_param_string(&state->dev, name,
 					     state_string_set, state_string_get,
-- 
2.8.1


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

^ permalink raw reply related

* [PATCH 2/3] ARM: i.MX6: fix clock gating
From: Jan Luebbe @ 2016-09-20  8:17 UTC (permalink / raw)
  To: barebox
In-Reply-To: <1474359462-32142-1-git-send-email-jlu@pengutronix.de>

Since ce6755ca1c41b8dd3b40cf3c9d6f3a1237a92720, both IPU and OpenVG are
enabled if CONFIG_DRIVER_VIDEO_IMX_IPUV3 is true, but in the other case,
only OpenVG was disabled.

Signed-off-by: Jan Luebbe <jlu@pengutronix.de>
---
 arch/arm/mach-imx/clk-imx6.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-imx/clk-imx6.c b/arch/arm/mach-imx/clk-imx6.c
index a634580c86d5..26dfd1a7e16b 100644
--- a/arch/arm/mach-imx/clk-imx6.c
+++ b/arch/arm/mach-imx/clk-imx6.c
@@ -495,9 +495,9 @@ static int imx6_ccm_probe(struct device_d *dev)
 	writel(0xf0ffffff, ccm_base + CCGR1); /* gate GPU3D, GPU2D */
 	writel(0xffffffff, ccm_base + CCGR2);
 	if (IS_ENABLED(CONFIG_DRIVER_VIDEO_IMX_IPUV3))
-		writel(0xffffffff, ccm_base + CCGR3); /* gate OpenVG */
+		writel(0x3fffffff, ccm_base + CCGR3); /* gate OpenVG */
 	else
-		writel(0x3fffffff, ccm_base + CCGR3); /* gate OpenVG, LDB, IPU1, IPU2 */
+		writel(0x3fff0000, ccm_base + CCGR3); /* gate OpenVG, LDB, IPU1, IPU2 */
 	writel(0xffffffff, ccm_base + CCGR4);
 	writel(0xffffffff, ccm_base + CCGR5);
 	writel(0xffff3fff, ccm_base + CCGR6); /* gate VPU */
-- 
2.1.4


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

^ permalink raw reply related

* [PATCH 1/3] ARM: i.MX6: remove duplicate clock initialization
From: Jan Luebbe @ 2016-09-20  8:17 UTC (permalink / raw)
  To: barebox

These registers are already set by imx6_ccm_probe (in clk-imx6.c) during
core_initcall, while imx6_init_lowlevel is only called during
postcore_initcall via imx_init in imx.c.

Signed-off-by: Jan Luebbe <jlu@pengutronix.de>
---
 arch/arm/mach-imx/imx6.c | 9 ---------
 1 file changed, 9 deletions(-)

diff --git a/arch/arm/mach-imx/imx6.c b/arch/arm/mach-imx/imx6.c
index ba8fb8964ac8..dfd9a70200ec 100644
--- a/arch/arm/mach-imx/imx6.c
+++ b/arch/arm/mach-imx/imx6.c
@@ -56,15 +56,6 @@ void imx6_init_lowlevel(void)
 	writel(0, aips2 + 0x4c);
 	writel(0, aips2 + 0x50);
 
-	/* enable all clocks */
-	writel(0xffffffff, 0x020c4068);
-	writel(0xffffffff, 0x020c406c);
-	writel(0xffffffff, 0x020c4070);
-	writel(0xffffffff, 0x020c4074);
-	writel(0xffffffff, 0x020c4078);
-	writel(0xffffffff, 0x020c407c);
-	writel(0xffffffff, 0x020c4080);
-
 	/* Due to hardware limitation, on MX6Q we need to gate/ungate all PFDs
 	 * to make sure PFD is working right, otherwise, PFDs may
 	 * not output clock after reset, MX6DL and MX6SL have added 396M pfd
-- 
2.1.4


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

^ permalink raw reply related

* [PATCH 3/3] ARM: i.MX6: gate PCIe when unused
From: Jan Luebbe @ 2016-09-20  8:17 UTC (permalink / raw)
  To: barebox
In-Reply-To: <1474359462-32142-1-git-send-email-jlu@pengutronix.de>

Signed-off-by: Jan Luebbe <jlu@pengutronix.de>
---
 arch/arm/mach-imx/clk-imx6.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/arch/arm/mach-imx/clk-imx6.c b/arch/arm/mach-imx/clk-imx6.c
index 26dfd1a7e16b..8ac43bebb075 100644
--- a/arch/arm/mach-imx/clk-imx6.c
+++ b/arch/arm/mach-imx/clk-imx6.c
@@ -498,7 +498,10 @@ static int imx6_ccm_probe(struct device_d *dev)
 		writel(0x3fffffff, ccm_base + CCGR3); /* gate OpenVG */
 	else
 		writel(0x3fff0000, ccm_base + CCGR3); /* gate OpenVG, LDB, IPU1, IPU2 */
-	writel(0xffffffff, ccm_base + CCGR4);
+	if (IS_ENABLED(CONFIG_PCI_IMX6))
+		writel(0xffffffff, ccm_base + CCGR4);
+	else
+		writel(0xfffffffc, ccm_base + CCGR4); /* gate PCIe */
 	writel(0xffffffff, ccm_base + CCGR5);
 	writel(0xffff3fff, ccm_base + CCGR6); /* gate VPU */
 	writel(0xffffffff, ccm_base + CCGR7);
-- 
2.1.4


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

^ permalink raw reply related

* Re: [PATCH 2/2] fs: nfs: pick up network interface bootargs parameter
From: Uwe Kleine-König @ 2016-09-19 16:19 UTC (permalink / raw)
  To: Enrico Jorns; +Cc: barebox, Michael Olbrich, Gavin Schenk
In-Reply-To: <1474301029-22877-3-git-send-email-ejo@pengutronix.de>

On Mon, Sep 19, 2016 at 06:03:49PM +0200, Enrico Jorns wrote:
> This adds the linux.bootarg device parameter from the network device of
s/bootarg/bootargs/

> the current nfs connection and adds it to the nfs bootargs line.

s/and adds it//

> This allows booting from nfs without manually setting a ip=dhcp or
> ip=<ipaddr> option.

Otherwise: \o/
(i.e.: Acked-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> for
both patches)

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

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

^ permalink raw reply

* [PATCH 2/2] fs: nfs: pick up network interface bootargs parameter
From: Enrico Jorns @ 2016-09-19 16:03 UTC (permalink / raw)
  To: barebox; +Cc: Michael Olbrich, Gavin Schenk, Enrico Jorns, u.kleine-koenig
In-Reply-To: <1474301029-22877-1-git-send-email-ejo@pengutronix.de>

This adds the linux.bootarg device parameter from the network device of
the current nfs connection and adds it to the nfs bootargs line.

This allows booting from nfs without manually setting a ip=dhcp or
ip=<ipaddr> option.

Signed-off-by: Enrico Jorns <ejo@pengutronix.de>
---
 fs/nfs.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/fs/nfs.c b/fs/nfs.c
index a0a9dfc..97f01cf 100644
--- a/fs/nfs.c
+++ b/fs/nfs.c
@@ -1314,6 +1314,7 @@ static char *rootnfsopts;
 static void nfs_set_rootarg(struct nfs_priv *npriv, struct fs_device_d *fsdev)
 {
 	char *str, *tmp;
+	const char *bootargs;
 
 	str = basprintf("root=/dev/nfs nfsroot=%pI4:%s%s%s", &npriv->server, npriv->path,
 			  rootnfsopts[0] ? "," : "", rootnfsopts);
@@ -1331,6 +1332,13 @@ static void nfs_set_rootarg(struct nfs_priv *npriv, struct fs_device_d *fsdev)
 		str = tmp;
 	}
 
+	bootargs = dev_get_param(&npriv->con->edev->dev, "linux.bootargs");
+	if (bootargs) {
+		tmp = basprintf("%s %s", str, bootargs);
+		free(str);
+		str = tmp;
+	}
+
 	fsdev_set_linux_rootarg(fsdev, str);
 
 	free(str);
-- 
2.8.1


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

^ permalink raw reply related

* [PATCH 1/2] net: add linux.bootarg parameter from ifup call
From: Enrico Jorns @ 2016-09-19 16:03 UTC (permalink / raw)
  To: barebox; +Cc: Michael Olbrich, Gavin Schenk, Enrico Jorns, u.kleine-koenig
In-Reply-To: <1474301029-22877-1-git-send-email-ejo@pengutronix.de>

This sets a `ip=dhcp` or
`ip=<clientip>:<serverip>:<gatewayip>:<netmaskip>::<iface>:` bootarg for
the network device upon execution of 'ifup'. This is the only point
where we can distinguish between a static ip and a dhcp-based network
setup and thus set a valid bootarg options as it will be required for
nfs boot, for example.

Signed-off-by: Enrico Jorns <ejo@pengutronix.de>
---
 include/net.h |  1 +
 net/eth.c     |  1 +
 net/ifup.c    | 10 ++++++++++
 3 files changed, 12 insertions(+)

diff --git a/include/net.h b/include/net.h
index fd1c412..632b6d5 100644
--- a/include/net.h
+++ b/include/net.h
@@ -62,6 +62,7 @@ struct eth_device {
 	IPaddr_t netmask;
 	IPaddr_t gateway;
 	char ethaddr[6];
+	char *bootarg;
 };
 
 #define dev_to_edev(d) container_of(d, struct eth_device, dev)
diff --git a/net/eth.c b/net/eth.c
index 6f8e78d..e056826 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -384,6 +384,7 @@ int eth_register(struct eth_device *edev)
 	dev_add_param_ip(dev, "netmask", NULL, NULL, &edev->netmask, edev);
 	dev_add_param_mac(dev, "ethaddr", eth_param_set_ethaddr, NULL,
 			edev->ethaddr, edev);
+	dev_add_param_string(dev, "linux.bootargs", NULL, NULL, &edev->bootarg, NULL);
 
 	if (edev->init)
 		edev->init(edev);
diff --git a/net/ifup.c b/net/ifup.c
index 30ac3f5..618eb8a 100644
--- a/net/ifup.c
+++ b/net/ifup.c
@@ -106,12 +106,22 @@ int ifup(const char *name, unsigned flags)
 		ret = eth_set_param(dev, "serverip");
 		if (ret)
 			goto out;
+		dev_set_param(dev, "linux.bootargs", "ip=dhcp");
 	} else if (!strcmp(ip, "static")) {
+		char *bootarg;
 		for (i = 0; i < ARRAY_SIZE(vars); i++) {
 			ret = eth_set_param(dev, vars[i]);
 			if (ret)
 				goto out;
 		}
+		bootarg = basprintf("ip=%pI4:%pI4:%pI4:%pI4::%s:",
+				&edev->ipaddr,
+				&edev->serverip,
+				&edev->gateway,
+				&edev->netmask,
+				edev->devname);
+		dev_set_param(dev, "linux.bootargs", bootarg);
+		free(bootarg);
 	} else {
 		pr_err("unknown ip type: %s\n", ip);
 		ret = -EINVAL;
-- 
2.8.1


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

^ permalink raw reply related

* [PATCH 0/2] Auto-append ip= option for NFS boot with appendrot
From: Enrico Jorns @ 2016-09-19 16:03 UTC (permalink / raw)
  To: barebox; +Cc: Michael Olbrich, Gavin Schenk, Enrico Jorns, u.kleine-koenig

This patches allow booting from nfs without the need to additionally provide an
extra ip= option, such as ip=dhcp to the kernel commandline.

This is solved by adding a bootargs property to the network device of the
connection used for the NFS boot and appending this to the nfs bootarg string.

Note that these patches are based on the 'vsprintf: Add support for printing
ipv4 addresses with %pI4' series posted by Sascha.

Enrico Jorns (2):
  net: add linux.bootarg parameter from ifup call
  fs: nfs: pick up network interface bootargs parameter

 fs/nfs.c      |  8 ++++++++
 include/net.h |  1 +
 net/eth.c     |  1 +
 net/ifup.c    | 10 ++++++++++
 4 files changed, 20 insertions(+)

-- 
2.8.1


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

^ permalink raw reply


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox