* [PATCH] ARM: rpi: add SD card environment support
@ 2013-10-15 10:50 Sascha Hauer
2013-10-15 11:36 ` Jean-Christophe PLAGNIOL-VILLARD
2013-10-15 11:54 ` Andre Heider
0 siblings, 2 replies; 6+ messages in thread
From: Sascha Hauer @ 2013-10-15 10:50 UTC (permalink / raw)
To: barebox
Similar to the OMAP boards mount the SD card to /boot and expect
the environment as /boot/barebox.env
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
arch/arm/boards/raspberry-pi/rpi.c | 33 +++++++++++++++++++++++++++++++--
1 file changed, 31 insertions(+), 2 deletions(-)
diff --git a/arch/arm/boards/raspberry-pi/rpi.c b/arch/arm/boards/raspberry-pi/rpi.c
index d4912cc..971a603 100644
--- a/arch/arm/boards/raspberry-pi/rpi.c
+++ b/arch/arm/boards/raspberry-pi/rpi.c
@@ -15,6 +15,9 @@
#include <common.h>
#include <init.h>
+#include <fs.h>
+#include <linux/stat.h>
+#include <envfs.h>
#include <asm/armlinux.h>
#include <generated/mach-types.h>
@@ -37,11 +40,37 @@ static int rpi_console_init(void)
}
console_initcall(rpi_console_init);
+static int rpi_env_init(void)
+{
+ struct stat s;
+ const char *diskdev = "/dev/disk0.0";
+ int ret;
+
+ device_detect_by_name("mci0");
+
+ ret = stat(diskdev, &s);
+ if (ret) {
+ printf("no %s. using default env\n", diskdev);
+ return 0;
+ }
+
+ mkdir("/boot", 0666);
+ ret = mount(diskdev, "fat", "/boot");
+ if (ret) {
+ printf("failed to mount %s\n", diskdev);
+ return 0;
+ }
+
+ default_environment_path = "/boot/barebox.env";
+
+ return 0;
+}
+
static int rpi_devices_init(void)
{
armlinux_set_architecture(MACH_TYPE_BCM2708);
armlinux_set_bootparams((void *)(0x00000100));
+ rpi_env_init();
return 0;
}
-
-device_initcall(rpi_devices_init);
+late_initcall(rpi_devices_init);
--
1.8.4.rc3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] ARM: rpi: add SD card environment support
2013-10-15 10:50 [PATCH] ARM: rpi: add SD card environment support Sascha Hauer
@ 2013-10-15 11:36 ` Jean-Christophe PLAGNIOL-VILLARD
2013-10-16 7:44 ` Sascha Hauer
2013-10-15 11:54 ` Andre Heider
1 sibling, 1 reply; 6+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-10-15 11:36 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
On 12:50 Tue 15 Oct , Sascha Hauer wrote:
> Similar to the OMAP boards mount the SD card to /boot and expect
> the environment as /boot/barebox.env
>
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
> arch/arm/boards/raspberry-pi/rpi.c | 33 +++++++++++++++++++++++++++++++--
> 1 file changed, 31 insertions(+), 2 deletions(-)
>
> diff --git a/arch/arm/boards/raspberry-pi/rpi.c b/arch/arm/boards/raspberry-pi/rpi.c
> index d4912cc..971a603 100644
> --- a/arch/arm/boards/raspberry-pi/rpi.c
> +++ b/arch/arm/boards/raspberry-pi/rpi.c
> @@ -15,6 +15,9 @@
>
> #include <common.h>
> #include <init.h>
> +#include <fs.h>
> +#include <linux/stat.h>
> +#include <envfs.h>
> #include <asm/armlinux.h>
> #include <generated/mach-types.h>
>
> @@ -37,11 +40,37 @@ static int rpi_console_init(void)
> }
> console_initcall(rpi_console_init);
>
> +static int rpi_env_init(void)
> +{
> + struct stat s;
> + const char *diskdev = "/dev/disk0.0";
> + int ret;
> +
> + device_detect_by_name("mci0");
> +
> + ret = stat(diskdev, &s);
> + if (ret) {
> + printf("no %s. using default env\n", diskdev);
> + return 0;
> + }
> +
> + mkdir("/boot", 0666);
> + ret = mount(diskdev, "fat", "/boot");
> + if (ret) {
> + printf("failed to mount %s\n", diskdev);
> + return 0;
> + }
> +
> + default_environment_path = "/boot/barebox.env";
> +
> + return 0;
> +}
can we drop all of this and do something like this
set_defaultenv and do not have custom code in the c duplicated everywhere?
> +
> static int rpi_devices_init(void)
> {
> armlinux_set_architecture(MACH_TYPE_BCM2708);
> armlinux_set_bootparams((void *)(0x00000100));
> + rpi_env_init();
> return 0;
> }
> -
> -device_initcall(rpi_devices_init);
> +late_initcall(rpi_devices_init);
> --
> 1.8.4.rc3
>
>
> _______________________________________________
> 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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] ARM: rpi: add SD card environment support
2013-10-15 10:50 [PATCH] ARM: rpi: add SD card environment support Sascha Hauer
2013-10-15 11:36 ` Jean-Christophe PLAGNIOL-VILLARD
@ 2013-10-15 11:54 ` Andre Heider
2013-10-15 12:53 ` Sascha Hauer
1 sibling, 1 reply; 6+ messages in thread
From: Andre Heider @ 2013-10-15 11:54 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
Hi,
On Tue, Oct 15, 2013 at 12:50:14PM +0200, Sascha Hauer wrote:
> Similar to the OMAP boards mount the SD card to /boot and expect
> the environment as /boot/barebox.env
>
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
> arch/arm/boards/raspberry-pi/rpi.c | 33 +++++++++++++++++++++++++++++++--
> 1 file changed, 31 insertions(+), 2 deletions(-)
>
> diff --git a/arch/arm/boards/raspberry-pi/rpi.c b/arch/arm/boards/raspberry-pi/rpi.c
> index d4912cc..971a603 100644
> --- a/arch/arm/boards/raspberry-pi/rpi.c
> +++ b/arch/arm/boards/raspberry-pi/rpi.c
> @@ -15,6 +15,9 @@
>
> #include <common.h>
> #include <init.h>
> +#include <fs.h>
> +#include <linux/stat.h>
> +#include <envfs.h>
> #include <asm/armlinux.h>
> #include <generated/mach-types.h>
>
> @@ -37,11 +40,37 @@ static int rpi_console_init(void)
> }
> console_initcall(rpi_console_init);
>
> +static int rpi_env_init(void)
> +{
> + struct stat s;
> + const char *diskdev = "/dev/disk0.0";
> + int ret;
> +
> + device_detect_by_name("mci0");
> +
> + ret = stat(diskdev, &s);
> + if (ret) {
> + printf("no %s. using default env\n", diskdev);
> + return 0;
> + }
> +
> + mkdir("/boot", 0666);
> + ret = mount(diskdev, "fat", "/boot");
> + if (ret) {
> + printf("failed to mount %s\n", diskdev);
> + return 0;
> + }
> +
> + default_environment_path = "/boot/barebox.env";
> +
> + return 0;
> +}
I was solving the same thing just yesterday ;)
What I did was to create a env/init/automount script, what's the advantage of this approach?
Regards,
Andre
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] ARM: rpi: add SD card environment support
2013-10-15 11:54 ` Andre Heider
@ 2013-10-15 12:53 ` Sascha Hauer
2013-10-15 16:22 ` Andre Heider
0 siblings, 1 reply; 6+ messages in thread
From: Sascha Hauer @ 2013-10-15 12:53 UTC (permalink / raw)
To: Andre Heider; +Cc: barebox
On Tue, Oct 15, 2013 at 01:54:50PM +0200, Andre Heider wrote:
> Hi,
>
> > +static int rpi_env_init(void)
> > +{
> > + struct stat s;
> > + const char *diskdev = "/dev/disk0.0";
> > + int ret;
> > +
> > + device_detect_by_name("mci0");
> > +
> > + ret = stat(diskdev, &s);
> > + if (ret) {
> > + printf("no %s. using default env\n", diskdev);
> > + return 0;
> > + }
> > +
> > + mkdir("/boot", 0666);
> > + ret = mount(diskdev, "fat", "/boot");
> > + if (ret) {
> > + printf("failed to mount %s\n", diskdev);
> > + return 0;
> > + }
> > +
> > + default_environment_path = "/boot/barebox.env";
> > +
> > + return 0;
> > +}
>
> I was solving the same thing just yesterday ;)
>
> What I did was to create a env/init/automount script, what's the advantage of this approach?
This approach also sets default_environment_path to /boot/barebox.env so
that loadenv/saveenv works and barebox comes up with the saved
environment.
You could probably do similar with scripts doing something like:
automount -d /boot "detect mci0 && mount /dev/disk0.0 /boot"
loadenv -s /boot/barebox.env /env
/env/bin/init
However, I made the experience that in scripts proper error checking is
hard to archieve and therefore often skipped. Also with C Code a single
git commitish makes the system behaviour clear. When instead scripts are
used which might have been modified by a user, or which might come from
an older barebox version the situation gets much more complex.
I generally try to reduce the usage (or better: necessity) of scripts.
They pretend a high level of flexibility but this comes at the cost of
reduced consistency across different boards (or even different instances
of the same board)
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 [flat|nested] 6+ messages in thread
* Re: [PATCH] ARM: rpi: add SD card environment support
2013-10-15 12:53 ` Sascha Hauer
@ 2013-10-15 16:22 ` Andre Heider
0 siblings, 0 replies; 6+ messages in thread
From: Andre Heider @ 2013-10-15 16:22 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
On Tue, Oct 15, 2013 at 02:53:12PM +0200, Sascha Hauer wrote:
> On Tue, Oct 15, 2013 at 01:54:50PM +0200, Andre Heider wrote:
> > Hi,
> >
> > > +static int rpi_env_init(void)
> > > +{
> > > + struct stat s;
> > > + const char *diskdev = "/dev/disk0.0";
> > > + int ret;
> > > +
> > > + device_detect_by_name("mci0");
> > > +
> > > + ret = stat(diskdev, &s);
> > > + if (ret) {
> > > + printf("no %s. using default env\n", diskdev);
> > > + return 0;
> > > + }
> > > +
> > > + mkdir("/boot", 0666);
> > > + ret = mount(diskdev, "fat", "/boot");
> > > + if (ret) {
> > > + printf("failed to mount %s\n", diskdev);
> > > + return 0;
> > > + }
> > > +
> > > + default_environment_path = "/boot/barebox.env";
> > > +
> > > + return 0;
> > > +}
> >
> > I was solving the same thing just yesterday ;)
> >
> > What I did was to create a env/init/automount script, what's the advantage of this approach?
>
> This approach also sets default_environment_path to /boot/barebox.env so
> that loadenv/saveenv works and barebox comes up with the saved
> environment.
>
> You could probably do similar with scripts doing something like:
>
> automount -d /boot "detect mci0 && mount /dev/disk0.0 /boot"
> loadenv -s /boot/barebox.env /env
> /env/bin/init
>
> However, I made the experience that in scripts proper error checking is
> hard to archieve and therefore often skipped. Also with C Code a single
> git commitish makes the system behaviour clear. When instead scripts are
> used which might have been modified by a user, or which might come from
> an older barebox version the situation gets much more complex.
>
> I generally try to reduce the usage (or better: necessity) of scripts.
> They pretend a high level of flexibility but this comes at the cost of
> reduced consistency across different boards (or even different instances
> of the same board)
>
Alright, thanks!
Regards,
Andre
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] ARM: rpi: add SD card environment support
2013-10-15 11:36 ` Jean-Christophe PLAGNIOL-VILLARD
@ 2013-10-16 7:44 ` Sascha Hauer
0 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2013-10-16 7:44 UTC (permalink / raw)
To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox
On Tue, Oct 15, 2013 at 01:36:30PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> On 12:50 Tue 15 Oct , Sascha Hauer wrote:
> > +static int rpi_env_init(void)
> > +{
> > + struct stat s;
> > + const char *diskdev = "/dev/disk0.0";
> > + int ret;
> > +
> > + device_detect_by_name("mci0");
> > +
> > + ret = stat(diskdev, &s);
> > + if (ret) {
> > + printf("no %s. using default env\n", diskdev);
> > + return 0;
> > + }
> > +
> > + mkdir("/boot", 0666);
> > + ret = mount(diskdev, "fat", "/boot");
> > + if (ret) {
> > + printf("failed to mount %s\n", diskdev);
> > + return 0;
> > + }
> > +
> > + default_environment_path = "/boot/barebox.env";
> > +
> > + return 0;
> > +}
>
> can we drop all of this and do something like this
>
> set_defaultenv and do not have custom code in the c duplicated everywhere?
That's probably a good idea. Right now it's just not clear to me how
such a code would look like. Omap does something similar to the above,
but additionally checks whether the device to mount is actually the
device the board started from.
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 [flat|nested] 6+ messages in thread
end of thread, other threads:[~2013-10-16 7:45 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-15 10:50 [PATCH] ARM: rpi: add SD card environment support Sascha Hauer
2013-10-15 11:36 ` Jean-Christophe PLAGNIOL-VILLARD
2013-10-16 7:44 ` Sascha Hauer
2013-10-15 11:54 ` Andre Heider
2013-10-15 12:53 ` Sascha Hauer
2013-10-15 16:22 ` Andre Heider
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox