Re: [PATCH 1/2] cfa-10036: Use the second MMC partition to store the environment

2013-02-14 Thread Juergen Beisert
Maxime Ripard wrote:
 Since the only storage medium on the cfa-10036 is the MMC card, we need
 to have a registered environment partition on it if we want to be able
 to modify at runtime.

 Signed-off-by: Maxime Ripard maxime.rip...@free-electrons.com
 ---
  arch/arm/boards/crystalfontz-cfa10036/cfa10036.c |   44
 +- 1 file changed, 43 insertions(+), 1 deletion(-)

 diff --git a/arch/arm/boards/crystalfontz-cfa10036/cfa10036.c 
 b/arch/arm/boards/crystalfontz-cfa10036/cfa10036.c
 index b59dbab..1821b10 100644 
 --- a/arch/arm/boards/crystalfontz-cfa10036/cfa10036.c
 +++ b/arch/arm/boards/crystalfontz-cfa10036/cfa10036.c
 @@ -97,9 +97,46 @@ static int cfa10036_mem_init(void)
  }
  mem_initcall(cfa10036_mem_init);

 +/**
 + * Try to register an environment storage on the attached MCI card
 + * @return 0 on success
 + *
 + * We rely on the existence of a usable SD card, already attached to
 + * our system, to get something like a persistent memory for our environment.
 + * If this SD card is also the boot media, we can use the second partition
 + * for our environment purpose (if present!). 
 + */
 +static int register_persistant_environment(void)

register_persist*e*nt_environment

Seems a copy from my typo in the falconwing. I really should fix it :))

 [...]

jbe

-- 
Pengutronix e.K.  | Juergen Beisert |
Linux Solutions for Science and Industry  | http://www.pengutronix.de/  |

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


[PATCH] arm/i.M23/chumbyfalconwing: just fix a typo

2013-02-14 Thread Juergen Beisert
diff --git a/arch/arm/boards/chumby_falconwing/falconwing.c 
b/arch/arm/boards/chumby_falconwing/falconwing.c
index 0818666..a8fe00c 100644
--- a/arch/arm/boards/chumby_falconwing/falconwing.c
+++ b/arch/arm/boards/chumby_falconwing/falconwing.c
@@ -274,7 +274,7 @@ mem_initcall(falconwing_mem_init);
  * If this SD card is also the boot media, we can use the second partition
  * for our environment purpose (if present!).
  */
-static int register_persistant_environment(void)
+static int register_persistent_environment(void)
 {
struct cdev *cdev;
 
@@ -338,7 +338,7 @@ static int falconwing_devices_init(void)
armlinux_set_bootparams((void *)IMX_MEMORY_BASE + 0x100);
armlinux_set_architecture(MACH_TYPE_CHUMBY);
 
-   rc = register_persistant_environment();
+   rc = register_persistent_environment();
if (rc != 0)
printf(Cannot create the 'env0' persistant environment storage 
(%d)\n, rc);
 

-- 
Pengutronix e.K.  | Juergen Beisert |
Linux Solutions for Science and Industry  | Phone: +49-5121-206917-5128 |
Peiner Str. 6-8, 31137 Hildesheim, Germany| Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de/  |

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


Re: [PATCH v2 1/2] Introduce device_platform_driver() macro

2013-02-14 Thread Sascha Hauer
On Tue, Feb 12, 2013 at 10:08:56PM +0400, Alexander Shiyan wrote:
 device_platform_driver() - Helper macro for drivers that don't do
 anything special in module registration. This eliminates a lot of
 boilerplate. Driver registration will called on device_initcall.
 
 Signed-off-by: Alexander Shiyan shc_w...@mail.ru

Applied, thanks.

Sascha

 ---
  include/driver.h | 12 
  1 file changed, 12 insertions(+)
 
 diff --git a/include/driver.h b/include/driver.h
 index 31f5d69..151829e 100644
 --- a/include/driver.h
 +++ b/include/driver.h
 @@ -390,6 +390,18 @@ extern struct list_head bus_list;
  extern struct bus_type platform_bus;
  
  int platform_driver_register(struct driver_d *drv);
 +
 +/* device_platform_driver() - Helper macro for drivers that don't do
 + * anything special in module registration. This eliminates a lot of
 + * boilerplate. Each module may only use this macro once.
 + */
 +#define device_platform_driver(drv)  \
 + static int __init drv ## _register(void)\
 + {   \
 + return platform_driver_register(drv);  \
 + }   \
 + device_initcall(drv ## _register)
 +
  int platform_device_register(struct device_d *new_device);
  
  struct file_operations {
 -- 
 1.7.12.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- |

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


[PATCH v2] arm/i.M23/chumbyfalconwing: just fix a typo

2013-02-14 Thread Juergen Beisert
Juergen Beisert wrote:
 [...]
   if (rc != 0)
   printf(Cannot create the 'env0' persistant environment storage 
 (%d)\n, rc);
 ___^
Arrghh, still two 'a' left. :(

diff --git a/arch/arm/boards/chumby_falconwing/falconwing.c 
b/arch/arm/boards/chumby_falconwing/falconwing.c
index 0818666..a9e1c00 100644
--- a/arch/arm/boards/chumby_falconwing/falconwing.c
+++ b/arch/arm/boards/chumby_falconwing/falconwing.c
@@ -274,7 +274,7 @@ mem_initcall(falconwing_mem_init);
  * If this SD card is also the boot media, we can use the second partition
  * for our environment purpose (if present!).
  */
-static int register_persistant_environment(void)
+static int register_persistent_environment(void)
 {
struct cdev *cdev;
 
@@ -338,9 +338,9 @@ static int falconwing_devices_init(void)
armlinux_set_bootparams((void *)IMX_MEMORY_BASE + 0x100);
armlinux_set_architecture(MACH_TYPE_CHUMBY);
 
-   rc = register_persistant_environment();
+   rc = register_persistent_environment();
if (rc != 0)
-   printf(Cannot create the 'env0' persistant environment storage 
(%d)\n, rc);
+   printf(Cannot create the 'env0' persistent environment storage 
(%d)\n, rc);
 
return 0;
 }
@@ -393,7 +393,7 @@ make ARCH=arm CROSS_COMPILE=armv5compiler
 
 - Create four primary partitions on the MCI card
  - the first one for the bootlets (about 256 kiB)
- - the second one for the persistant environment (size is up to you, at least 
256k)
+ - the second one for the persistent environment (size is up to you, at least 
256k)
  - the third one for the kernel (2 MiB ... 4 MiB in size)
  - the 4th one for the root filesystem which can fill the rest of the 
available space
 


jbe

-- 
Pengutronix e.K.  | Juergen Beisert |
Linux Solutions for Science and Industry  | http://www.pengutronix.de/  |

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


[PATCH] USB i.MX: Add i.MX6 HSIC support

2013-02-14 Thread Sascha Hauer
The following adds USB HSIC support for i.MX6.

The special thing about HSIC on i.MX is that we have to configure
a pullup on the Strobe line *after* the USB port is initialized, so
the bulk of this series deals with adding post init hooks to the
imx-usb-misc and ehci driver.

Sascha


Sascha Hauer (5):
  ARM i.MX6: Fix HSIC pad definitions
  USB chipidea i.MX: Fix PTS mask for HSIC
  USB ehci: Add platform specific init calls
  USB i.MX chipidea: implement post init support
  USB i.MX6: Add HSIC support

 arch/arm/mach-imx/include/mach/iomux-mx6.h |   19 +++--
 drivers/usb/host/ehci-hcd.c|   14 
 drivers/usb/imx/chipidea-imx.c |   45 --
 drivers/usb/imx/imx-usb-misc.c |  123 +---
 include/usb/chipidea-imx.h |3 +
 include/usb/ehci.h |5 ++
 6 files changed, 181 insertions(+), 28 deletions(-)

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


[PATCH 2/5] USB chipidea i.MX: Fix PTS mask for HSIC

2013-02-14 Thread Sascha Hauer
bit25 is part of the PTS bits, so mask it out before rewriting it.

Signed-off-by: Sascha Hauer s.ha...@pengutronix.de
---
 drivers/usb/imx/chipidea-imx.c |2 +-
 include/usb/chipidea-imx.h |1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/imx/chipidea-imx.c b/drivers/usb/imx/chipidea-imx.c
index 5b4c081..64bb866 100644
--- a/drivers/usb/imx/chipidea-imx.c
+++ b/drivers/usb/imx/chipidea-imx.c
@@ -20,7 +20,7 @@
 #include usb/chipidea-imx.h
 #include usb/ulpi.h
 
-#define MXC_EHCI_PORTSC_MASK (0xf  28)
+#define MXC_EHCI_PORTSC_MASK ((0xf  28) | (1  25))
 
 static int imx_chipidea_probe(struct device_d *dev)
 {
diff --git a/include/usb/chipidea-imx.h b/include/usb/chipidea-imx.h
index e98cc89..252d488 100644
--- a/include/usb/chipidea-imx.h
+++ b/include/usb/chipidea-imx.h
@@ -9,6 +9,7 @@
 #define MXC_EHCI_MODE_UTMI_16_BIT  ((0  30) | (1  28))
 #define MXC_EHCI_MODE_PHILIPS  (1  30)
 #define MXC_EHCI_MODE_ULPI (2  30)
+#define MXC_EHCI_MODE_HSIC (1  25)
 #define MXC_EHCI_MODE_SERIAL   (3  30)
 
 /*
-- 
1.7.10.4


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


[PATCH 1/5] ARM i.MX6: Fix HSIC pad definitions

2013-02-14 Thread Sascha Hauer
Signed-off-by: Sascha Hauer s.ha...@pengutronix.de
---
 arch/arm/mach-imx/include/mach/iomux-mx6.h |   19 +++
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/arch/arm/mach-imx/include/mach/iomux-mx6.h 
b/arch/arm/mach-imx/include/mach/iomux-mx6.h
index f50fd8a..57d1a3b 100644
--- a/arch/arm/mach-imx/include/mach/iomux-mx6.h
+++ b/arch/arm/mach-imx/include/mach/iomux-mx6.h
@@ -83,6 +83,9 @@
MX6_PAD_CTL_DSE_40ohm | MX6_PAD_CTL_HYS | \
MX6_PAD_CTL_ODE | MX6_PAD_CTL_SRE_FAST)
 
+#define MX6Q_USB_HSIC_PAD_CTRL (MX6_PAD_CTL_HYS | MX6_PAD_CTL_PKE | 
MX6_PAD_CTL_PUE |  \
+   MX6_PAD_CTL_DSE_40ohm)
+
 #define MX6Q_HIGH_DRV (MX6_PAD_CTL_DSE_120ohm)
 
 #define _MX6Q_PAD_SD2_DAT1__USDHC2_DAT1
\
@@ -135,7 +138,7 @@
IOMUX_PAD(0x0368, 0x0054, 7, 0x, 0, 0)
 
 #define _MX6Q_PAD_RGMII_TXC__USBOH3_H2_DATA
\
-   IOMUX_PAD(0x036C, 0x0058, 0, 0x, 0, 0)
+   IOMUX_PAD(0x036C, 0x0058, IOMUX_CONFIG_SION, 0x, 0, 0)
 #define _MX6Q_PAD_RGMII_TXC__ENET_RGMII_TXC
\
IOMUX_PAD(0x036C, 0x0058, 1, 0x, 0, 0)
 #define _MX6Q_PAD_RGMII_TXC__SPDIF_SPDIF_EXTCLK
\
@@ -188,7 +191,7 @@
IOMUX_PAD(0x037C, 0x0068, 6, 0x, 0, 0)
 
 #define _MX6Q_PAD_RGMII_RX_CTL__USBOH3_H3_DATA 
\
-   IOMUX_PAD(0x0380, 0x006C, 0, 0x, 0, 0)
+   IOMUX_PAD(0x0380, 0x006C, IOMUX_CONFIG_SION, 0x, 0, 0)
 #define _MX6Q_PAD_RGMII_RX_CTL__ENET_RGMII_RX_CTL  
\
IOMUX_PAD(0x0380, 0x006C, 1, 0x0858, 0, 0)
 #define _MX6Q_PAD_RGMII_RX_CTL__GPIO_6_24  
\
@@ -206,7 +209,7 @@
IOMUX_PAD(0x0384, 0x0070, 6, 0x, 0, 0)
 
 #define _MX6Q_PAD_RGMII_TX_CTL__USBOH3_H2_STROBE   
\
-   IOMUX_PAD(0x0388, 0x0074, 0, 0x, 0, 0)
+   IOMUX_PAD(0x0388, 0x0074, IOMUX_CONFIG_SION, 0x, 0, 0)
 #define _MX6Q_PAD_RGMII_TX_CTL__ENET_RGMII_TX_CTL  
\
IOMUX_PAD(0x0388, 0x0074, 1, 0x, 0, 0)
 #define _MX6Q_PAD_RGMII_TX_CTL__GPIO_6_26  
\
@@ -246,7 +249,7 @@
IOMUX_PAD(0x0394, 0x0080, 6, 0x, 0, 0)
 
 #define _MX6Q_PAD_RGMII_RXC__USBOH3_H3_STROBE  
\
-   IOMUX_PAD(0x0398, 0x0084, 0, 0x, 0, 0)
+   IOMUX_PAD(0x0398, 0x0084, IOMUX_CONFIG_SION, 0x, 0, 0)
 #define _MX6Q_PAD_RGMII_RXC__ENET_RGMII_RXC
\
IOMUX_PAD(0x0398, 0x0084, 1, 0x0844, 0, 0)
 #define _MX6Q_PAD_RGMII_RXC__GPIO_6_30 
\
@@ -3695,7 +3698,7 @@
 #define  MX6Q_PAD_SD2_DAT0__DCIC2_DCIC_OUT   
(_MX6Q_PAD_SD2_DAT0__DCIC2_DCIC_OUT | MUX_PAD_CTRL(NO_PAD_CTRL))
 #define  MX6Q_PAD_SD2_DAT0__ANATOP_ANATOP_TESTO_2
(_MX6Q_PAD_SD2_DAT0__ANATOP_ANATOP_TESTO_2 | MUX_PAD_CTRL(NO_PAD_CTRL))
 
-#define  MX6Q_PAD_RGMII_TXC__USBOH3_H2_DATA  
(_MX6Q_PAD_RGMII_TXC__USBOH3_H2_DATA | MUX_PAD_CTRL(NO_PAD_CTRL))
+#define  MX6Q_PAD_RGMII_TXC__USBOH3_H2_DATA  
(_MX6Q_PAD_RGMII_TXC__USBOH3_H2_DATA | MUX_PAD_CTRL(MX6Q_USB_HSIC_PAD_CTRL))
 #define  MX6Q_PAD_RGMII_TXC__ENET_RGMII_TXC  
(_MX6Q_PAD_RGMII_TXC__ENET_RGMII_TXC | MUX_PAD_CTRL(MX6Q_ENET_PAD_CTRL))
 #define  MX6Q_PAD_RGMII_TXC__SPDIF_SPDIF_EXTCLK  
(_MX6Q_PAD_RGMII_TXC__SPDIF_SPDIF_EXTCLK | MUX_PAD_CTRL(NO_PAD_CTRL))
 #define  MX6Q_PAD_RGMII_TXC__GPIO_6_19   
(_MX6Q_PAD_RGMII_TXC__GPIO_6_19 | MUX_PAD_CTRL(NO_PAD_CTRL))
@@ -3724,7 +3727,7 @@
 #define  MX6Q_PAD_RGMII_TD3__GPIO_6_23   
(_MX6Q_PAD_RGMII_TD3__GPIO_6_23 | MUX_PAD_CTRL(NO_PAD_CTRL))
 #define  MX6Q_PAD_RGMII_TD3__MIPI_CORE_DPHY_TEST_IN_4
(_MX6Q_PAD_RGMII_TD3__MIPI_CORE_DPHY_TEST_IN_4 | MUX_PAD_CTRL(NO_PAD_CTRL))
 
-#define  MX6Q_PAD_RGMII_RX_CTL__USBOH3_H3_DATA   
(_MX6Q_PAD_RGMII_RX_CTL__USBOH3_H3_DATA | MUX_PAD_CTRL(NO_PAD_CTRL))
+#define  MX6Q_PAD_RGMII_RX_CTL__USBOH3_H3_DATA   
(_MX6Q_PAD_RGMII_RX_CTL__USBOH3_H3_DATA | MUX_PAD_CTRL(MX6Q_USB_HSIC_PAD_CTRL))
 #define  MX6Q_PAD_RGMII_RX_CTL__ENET_RGMII_RX_CTL
(_MX6Q_PAD_RGMII_RX_CTL__ENET_RGMII_RX_CTL | MUX_PAD_CTRL(MX6Q_ENET_PAD_CTRL))
 #define  MX6Q_PAD_RGMII_RX_CTL__GPIO_6_24
(_MX6Q_PAD_RGMII_RX_CTL__GPIO_6_24 | MUX_PAD_CTRL(NO_PAD_CTRL))
 #define  MX6Q_PAD_RGMII_RX_CTL__MIPI_CORE_DPHY_TEST_IN_5 
(_MX6Q_PAD_RGMII_RX_CTL__MIPI_CORE_DPHY_TEST_IN_5 | MUX_PAD_CTRL(NO_PAD_CTRL))
@@ -3734,7 +3737,7 @@
 #define  MX6Q_PAD_RGMII_RD0__GPIO_6_25   

[PATCH 5/5] USB i.MX6: Add HSIC support

2013-02-14 Thread Sascha Hauer
HSIC needs some special setup for i.MX6. Most ugly detail is that
the HSIC needs help of the IOMUX to configure a pullup on the strobe
line. This has to be done after the ehci controller has started.
Fortunately there is only one muxing possibility for the HSIC ports
on i.MX6, so we can simply control the iomux from the usbmisc driver.

Signed-off-by: Sascha Hauer s.ha...@pengutronix.de
---
 drivers/usb/imx/imx-usb-misc.c |   60 
 1 file changed, 60 insertions(+)

diff --git a/drivers/usb/imx/imx-usb-misc.c b/drivers/usb/imx/imx-usb-misc.c
index d42f4c0..901ced4 100644
--- a/drivers/usb/imx/imx-usb-misc.c
+++ b/drivers/usb/imx/imx-usb-misc.c
@@ -17,6 +17,8 @@
 #include init.h
 #include io.h
 #include usb/chipidea-imx.h
+#include mach/imx6-regs.h
+#include mach/iomux-mx6.h
 
 #define MX25_OTG_SIC_SHIFT 29
 #define MX25_OTG_SIC_MASK  (0x3  MX25_OTG_SIC_SHIFT)
@@ -345,14 +347,72 @@ static __maybe_unused struct imx_usb_misc_data mx5_data = 
{
.init = mx5_initialize_usb_hw,
 };
 
+static void mx6_hsic_pullup(unsigned long reg, int on)
+{
+   u32 val;
+
+   val = readl(MX6_IOMUXC_BASE_ADDR + reg);
+
+   if (on)
+   val |= MX6_PAD_CTL_PUS_47K_UP;
+   else
+   val = ~MX6_PAD_CTL_PUS_47K_UP;
+
+   writel(val, MX6_IOMUXC_BASE_ADDR + reg);
+}
+
 static __maybe_unused int mx6_initialize_usb_hw(void __iomem *base, int port,
unsigned int flags)
 {
+   switch (port) {
+   case 0:
+   break;
+   case 1:
+   break;
+   case 2: /* HSIC port */
+   mx6_hsic_pullup(0x388, 0);
+
+   writel(0x3000, base + 0x8);
+   writel(0x80001842, base + 0x10);
+
+   break;
+   case 3: /* HSIC port */
+   writel(0x3000, base + 0xc);
+   writel(0x80001842, base + 0x14);
+
+   mx6_hsic_pullup(0x398, 0);
+   break;
+   default:
+   return -EINVAL;
+   }
+
+   return 0;
+}
+
+static __maybe_unused int mx6_post_init(void __iomem *base, int port,
+   unsigned int flags)
+{
+   switch (port) {
+   case 0:
+   break;
+   case 1:
+   break;
+   case 2: /* HSIC port */
+   mx6_hsic_pullup(0x388, 1);
+   break;
+   case 3: /* HSIC port */
+   mx6_hsic_pullup(0x398, 1);
+   break;
+   default:
+   return -EINVAL;
+   }
+
return 0;
 }
 
 static __maybe_unused struct imx_usb_misc_data mx6_data = {
.init = mx6_initialize_usb_hw,
+   .post_init = mx6_post_init,
 };
 
 static struct platform_device_id imx_usbmisc_ids[] = {
-- 
1.7.10.4


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


[PATCH 4/5] USB i.MX chipidea: implement post init support

2013-02-14 Thread Sascha Hauer
Some controllers need an init hook after the USB controller is
started, so implement the post init hook for i.MX.

Signed-off-by: Sascha Hauer s.ha...@pengutronix.de
---
 drivers/usb/imx/chipidea-imx.c |   43 ++-
 drivers/usb/imx/imx-usb-misc.c |   63 
 include/usb/chipidea-imx.h |2 ++
 3 files changed, 89 insertions(+), 19 deletions(-)

diff --git a/drivers/usb/imx/chipidea-imx.c b/drivers/usb/imx/chipidea-imx.c
index 64bb866..de80c36 100644
--- a/drivers/usb/imx/chipidea-imx.c
+++ b/drivers/usb/imx/chipidea-imx.c
@@ -22,12 +22,41 @@
 
 #define MXC_EHCI_PORTSC_MASK ((0xf  28) | (1  25))
 
+static int imx_chipidea_port_init(void *drvdata)
+{
+   struct device_d *dev = drvdata;
+   struct imxusb_platformdata *pdata = dev-platform_data;
+   int ret;
+
+   ret = imx_usbmisc_port_init(dev-id, pdata-flags);
+   if (ret)
+   dev_err(dev, misc init failed: %s\n, strerror(-ret));
+
+   if (pdata-init)
+   pdata-init(dev-id);
+
+   return ret;
+}
+
+static int imx_chipidea_port_post_init(void *drvdata)
+{
+   struct device_d *dev = drvdata;
+   struct imxusb_platformdata *pdata = dev-platform_data;
+   int ret;
+
+   ret = imx_usbmisc_port_post_init(dev-id, pdata-flags);
+   if (ret)
+   dev_err(dev, post misc init failed: %s\n, strerror(-ret));
+
+   return ret;
+}
+
 static int imx_chipidea_probe(struct device_d *dev)
 {
struct imxusb_platformdata *pdata = dev-platform_data;
int ret;
void __iomem *base;
-   struct ehci_data data;
+   struct ehci_data data = {};
uint32_t portsc;
 
if (!pdata) {
@@ -39,17 +68,17 @@ static int imx_chipidea_probe(struct device_d *dev)
if (!base)
return -ENODEV;
 
+   data.init = imx_chipidea_port_init;
+   data.post_init = imx_chipidea_port_post_init;
+   data.drvdata = dev;
+
+   imx_chipidea_port_init(dev);
+
portsc = readl(base + 0x184);
portsc = ~MXC_EHCI_PORTSC_MASK;
portsc |= pdata-flags  MXC_EHCI_PORTSC_MASK;
writel(portsc, base + 0x184);
 
-   ret = imx_usbmisc_port_init(dev-id, pdata-flags);
-   if (ret) {
-   dev_err(dev, failed to init misc regs: %s\n, strerror(-ret));
-   return ret;
-   }
-
if ((pdata-flags  MXC_EHCI_PORTSC_MASK) == MXC_EHCI_MODE_ULPI) {
dev_dbg(dev, using ULPI phy\n);
if (IS_ENABLED(CONFIG_USB_ULPI)) {
diff --git a/drivers/usb/imx/imx-usb-misc.c b/drivers/usb/imx/imx-usb-misc.c
index 4cdf5ab..d42f4c0 100644
--- a/drivers/usb/imx/imx-usb-misc.c
+++ b/drivers/usb/imx/imx-usb-misc.c
@@ -34,6 +34,11 @@
 #define MX25_H1_USBTE_BIT  (1  4)
 #define MX25_H1_OCPOL_BIT  (1  2)
 
+struct imx_usb_misc_data {
+   int (*init)(void __iomem *base, int port, unsigned int flags);
+   int (*post_init)(void __iomem *base, int port, unsigned int flags);
+};
+
 static __maybe_unused int mx25_initialize_usb_hw(void __iomem *base, int port, 
unsigned int flags)
 {
unsigned int v;
@@ -93,6 +98,10 @@ static __maybe_unused int mx25_initialize_usb_hw(void 
__iomem *base, int port, u
return 0;
 }
 
+static __maybe_unused struct imx_usb_misc_data mx25_data = {
+   .init = mx25_initialize_usb_hw,
+};
+
 #define MX27_OTG_SIC_SHIFT 29
 #define MX27_OTG_SIC_MASK  (0x3  MX27_OTG_SIC_SHIFT)
 #define MX27_OTG_PM_BIT(1  24)
@@ -152,6 +161,10 @@ static __maybe_unused int mx27_mx31_initialize_usb_hw(void 
__iomem *base, int po
return 0;
 }
 
+static __maybe_unused struct imx_usb_misc_data mx27_mx31_data = {
+   .init = mx27_mx31_initialize_usb_hw,
+};
+
 #define USBCTRL_OTGBASE_OFFSET 0x600
 
 #define MX35_OTG_SIC_SHIFT 29
@@ -229,6 +242,10 @@ static __maybe_unused int mx35_initialize_usb_hw(void 
__iomem *base, int port, u
return 0;
 }
 
+static __maybe_unused struct imx_usb_misc_data mx35_data = {
+   .init = mx35_initialize_usb_hw,
+};
+
 /* USB_CTRL */
 #define MX5_OTG_UCTRL_OWIE_BIT (1  27)   /* OTG wakeup intr 
enable */
 #define MX5_OTG_UCTRL_OPM_BIT  (1  24)   /* OTG power mask */
@@ -324,53 +341,61 @@ static __maybe_unused int mx5_initialize_usb_hw(void 
__iomem *base, int port,
return 0;
 }
 
+static __maybe_unused struct imx_usb_misc_data mx5_data = {
+   .init = mx5_initialize_usb_hw,
+};
+
 static __maybe_unused int mx6_initialize_usb_hw(void __iomem *base, int port,
unsigned int flags)
 {
return 0;
 }
 
+static __maybe_unused struct imx_usb_misc_data mx6_data = {
+   .init = mx6_initialize_usb_hw,
+};
+
 static struct platform_device_id imx_usbmisc_ids[] = {
 #ifdef CONFIG_ARCH_IMX25
{
.name = imx25-usb-misc,
-   .driver_data = (unsigned long)mx25_initialize_usb_hw,
+   .driver_data = (unsigned long)mx25_data,
},
 #endif
 

[PATCH 3/5] USB ehci: Add platform specific init calls

2013-02-14 Thread Sascha Hauer
Some USB cores need a platform specific init hook, add it to
the ehci driver.

Signed-off-by: Sascha Hauer s.ha...@pengutronix.de
---
 drivers/usb/host/ehci-hcd.c |   14 ++
 include/usb/ehci.h  |5 +
 2 files changed, 19 insertions(+)

diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index d0d6ae4..d6dc1de 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -42,6 +42,10 @@ struct ehci_priv {
struct qTD *td;
int portreset;
unsigned long flags;
+
+   int (*init)(void *drvdata);
+   int (*post_init)(void *drvdata);
+   void *drvdata;
 };
 
 #define to_ehci(ptr) container_of(ptr, struct ehci_priv, host)
@@ -748,6 +752,9 @@ static int ehci_init(struct usb_host *host)
if (ehci_reset(ehci) != 0)
return -1;
 
+   if (ehci-init)
+   ehci-init(ehci-drvdata);
+
ehci-qh_list-qh_link = cpu_to_hc32((uint32_t)ehci-qh_list | 
QH_LINK_TYPE_QH);
ehci-qh_list-qh_endpt1 = cpu_to_hc32((1  15) | (USB_SPEED_HIGH  
12));
ehci-qh_list-qh_curtd = cpu_to_hc32(QT_NEXT_TERMINATE);
@@ -788,6 +795,9 @@ static int ehci_init(struct usb_host *host)
 
ehci-rootdev = 0;
 
+   if (ehci-post_init)
+   ehci-post_init(ehci-drvdata);
+
return 0;
 }
 
@@ -856,6 +866,10 @@ int ehci_register(struct device_d *dev, struct ehci_data 
*data)
ehci-hcor = (void __iomem *)ehci-hccr +
HC_LENGTH(ehci_readl(ehci-hccr-cr_capbase));
 
+   ehci-drvdata = data-drvdata;
+   ehci-init = data-init;
+   ehci-post_init = data-post_init;
+
ehci-qh_list = dma_alloc_coherent(sizeof(struct QH) * NUM_TD);
ehci-td = dma_alloc_coherent(sizeof(struct qTD) * NUM_TD);
 
diff --git a/include/usb/ehci.h b/include/usb/ehci.h
index 4377116..93f980d 100644
--- a/include/usb/ehci.h
+++ b/include/usb/ehci.h
@@ -11,6 +11,11 @@ struct ehci_data {
void __iomem *hccr;
void __iomem *hcor;
unsigned long flags;
+
+   /* platform specific init functions */
+   int (*init)(void *drvdata);
+   int (*post_init)(void *drvdata);
+   void *drvdata;
 };
 
 #ifdef CONFIG_USB_EHCI
-- 
1.7.10.4


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


[PATCH] USB i.MX: Add chipidea gadget support

2013-02-14 Thread Sascha Hauer
This adds USB gadget support to the i.MX chipidea driver. Basically
we have to add a register function to the fsl udc driver and call
this from the chipidea driver if device mode is selected.

Signed-off-by: Sascha Hauer s.ha...@pengutronix.de
---
 drivers/usb/gadget/fsl_udc.c   |   11 +--
 drivers/usb/imx/chipidea-imx.c |6 ++
 include/usb/fsl_usb2.h |6 ++
 3 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/gadget/fsl_udc.c b/drivers/usb/gadget/fsl_udc.c
index 0a7c3ae..968c58f 100644
--- a/drivers/usb/gadget/fsl_udc.c
+++ b/drivers/usb/gadget/fsl_udc.c
@@ -2257,7 +2257,7 @@ static struct poller_struct poller = {
.func   = fsl_udc_poller
 };
 
-static int fsl_udc_probe(struct device_d *dev)
+int ci_udc_register(struct device_d *dev, void __iomem *regs)
 {
int ret, i;
u32 dccparams;
@@ -2265,7 +2265,7 @@ static int fsl_udc_probe(struct device_d *dev)
udc_controller = xzalloc(sizeof(*udc_controller));
udc_controller-stopped = 1;
 
-   dr_regs = dev_request_mem_region(dev, 0);
+   dr_regs = regs;
 
/* Read Device Controller Capability Parameters register */
dccparams = readl(dr_regs-dccparams);
@@ -2326,6 +2326,13 @@ err_out:
return ret;
 }
 
+static int fsl_udc_probe(struct device_d *dev)
+{
+   void __iomem *regs = dev_request_mem_region(dev, 0);
+
+   return ci_udc_register(dev, regs);
+}
+
 static struct driver_d fsl_udc_driver = {
 .name   = fsl-udc,
 .probe  = fsl_udc_probe,
diff --git a/drivers/usb/imx/chipidea-imx.c b/drivers/usb/imx/chipidea-imx.c
index de80c36..ec4db27 100644
--- a/drivers/usb/imx/chipidea-imx.c
+++ b/drivers/usb/imx/chipidea-imx.c
@@ -19,6 +19,7 @@
 #include usb/ehci.h
 #include usb/chipidea-imx.h
 #include usb/ulpi.h
+#include usb/fsl_usb2.h
 
 #define MXC_EHCI_PORTSC_MASK ((0xf  28) | (1  25))
 
@@ -99,10 +100,7 @@ static int imx_chipidea_probe(struct device_d *dev)
if (pdata-mode == IMX_USB_MODE_HOST) {
ret = ehci_register(dev, data);
} else {
-   /*
-* Not yet implemented. Register USB gadget driver here.
-*/
-   ret = -ENOSYS;
+   ret = ci_udc_register(dev, base);
}
 
return ret;
diff --git a/include/usb/fsl_usb2.h b/include/usb/fsl_usb2.h
index fd37ade..dec3933 100644
--- a/include/usb/fsl_usb2.h
+++ b/include/usb/fsl_usb2.h
@@ -1,3 +1,6 @@
+#ifndef __USB_FSL_USB2_H
+#define __USB_FSL_USB2_H
+
 enum fsl_usb2_operating_modes {
FSL_USB2_MPH_HOST,
FSL_USB2_DR_HOST,
@@ -20,3 +23,6 @@ struct fsl_usb2_platform_data {
unsigned intport_enables;
 };
 
+int ci_udc_register(struct device_d *dev, void __iomem *regs);
+
+#endif /* __USB_FSL_USB2_H */
-- 
1.7.10.4


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


[PATCH] ARM pbl: move piggydata before bss

2013-02-14 Thread Sascha Hauer
This decreases the pbl image size by the size of the bss segment.

Signed-off-by: Sascha Hauer s.ha...@pengutronix.de
---
 arch/arm/pbl/zbarebox.lds.S |   12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/arch/arm/pbl/zbarebox.lds.S b/arch/arm/pbl/zbarebox.lds.S
index 564b3c6..2914fdd 100644
--- a/arch/arm/pbl/zbarebox.lds.S
+++ b/arch/arm/pbl/zbarebox.lds.S
@@ -59,18 +59,18 @@ SECTIONS
.data : { *(.data*) }
 
. = ALIGN(4);
-   __bss_start = .;
-   .bss : { *(.bss*) }
-   __bss_stop = .;
-   _end = .;
-
-   . = ALIGN(4);
__piggydata_start = .;
.piggydata : {
*(.piggydata)
}
__piggydata_end = .;
 
+   . = ALIGN(4);
+   __bss_start = .;
+   .bss : { *(.bss*) }
+   __bss_stop = .;
+   _end = .;
+
_barebox_image_size = __piggydata_end - (TEXT_BASE - SZ_2M);
_barebox_pbl_size = __bss_start - (TEXT_BASE - SZ_2M);
 }
-- 
1.7.10.4


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


Re: [PATCH] Add warning above get_ram_size

2013-02-14 Thread Maxime Ripard
Hi Sascha,

Le 13/02/2013 18:16, Sascha Hauer a écrit :
 Signed-off-by: Sascha Hauer s.ha...@pengutronix.de
 ---
  common/memsize.c |3 +++
  1 file changed, 3 insertions(+)
 
 diff --git a/common/memsize.c b/common/memsize.c
 index d149e41..ef6381b 100644
 --- a/common/memsize.c
 +++ b/common/memsize.c
 @@ -33,6 +33,9 @@
   * Check memory range for valid RAM. A simple memory test determines
   * the actually available RAM size between addresses `base' and
   * `base + maxsize'.
 + *
 + * This function modifies the RAM. Do not use it if you're running from
 + * the RAM you are going to detect!
   */

Actually, I don't see how it modifies the RAM, at least permanently. The
values it erase are backed up, and there's no concurrency at barebox
level, so we are sure that the value saved will still be the one that
would need to be backed up at the end of the function, right?

Maxime

-- 
Maxime Ripard, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com

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


Re: [PATCH] cfa10036: Retrieve the RAM size at runtime

2013-02-14 Thread Maxime Ripard
Hi Jean-Christophe,

Le 13/02/2013 18:09, Jean-Christophe PLAGNIOL-VILLARD a écrit :
 On 17:50 Wed 13 Feb , Maxime Ripard wrote:
 The cfa-10036 comes in two flavours, with either 128MB or 256MB of RAM
 on it.

 Since it's not stored anywhere, we need to runtime detect it, thanks to
 the get_ram_size function.

 Signed-off-by: Maxime Ripard maxime.rip...@free-electrons.com
 ---
  arch/arm/boards/crystalfontz-cfa10036/cfa10036.c |3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)

 diff --git a/arch/arm/boards/crystalfontz-cfa10036/cfa10036.c 
 b/arch/arm/boards/crystalfontz-cfa10036/cfa10036.c
 index 1821b10..47a9520 100644
 --- a/arch/arm/boards/crystalfontz-cfa10036/cfa10036.c
 +++ b/arch/arm/boards/crystalfontz-cfa10036/cfa10036.c
 @@ -91,7 +91,8 @@ static struct i2c_gpio_platform_data i2c_gpio_pdata = {
  
  static int cfa10036_mem_init(void)
  {
 -arm_add_mem_device(ram0, IMX_MEMORY_BASE, 128 * 1024 * 1024);
 +arm_add_mem_device(ram0, IMX_MEMORY_BASE,
 +get_ram_size(IMX_MEMORY_BASE, 256 * SZ_1M));
 check the sdram control register instead so you do not need to get_ram_size
 and specify a Max

This is not possible, the first stage bootloader sets up the cs, lines
and rows for 256MB, in every case, so we will always end up with 256MB here.

Maxime

-- 
Maxime Ripard, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com

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


[PATCH] Add missing SZ_xx defines

2013-02-14 Thread Alexander Shiyan

Signed-off-by: Alexander Shiyan shc_w...@mail.ru
---
 include/sizes.h |   12 
 1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/include/sizes.h b/include/sizes.h
index c47f906..321d40c 100644
--- a/include/sizes.h
+++ b/include/sizes.h
@@ -17,7 +17,19 @@
 #define __sizes_h  1
 
 /* handy sizes */
+#define SZ_1   0x0001
+#define SZ_2   0x0002
+#define SZ_4   0x0004
+#define SZ_8   0x0008
+#define SZ_16  0x0010
+#define SZ_32  0x8020
+#define SZ_64  0x0040
+#define SZ_128 0x0080
+#define SZ_256 0x0100
+#define SZ_512 0x0200
+
 #define SZ_1K  0x0400
+#define SZ_2K  0x0800
 #define SZ_4K  0x1000
 #define SZ_8K  0x2000
 #define SZ_16K 0x4000
-- 
1.7.3.4


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


Re: [PATCH 1/2] cfa-10036: Use the second MMC partition to store the environment

2013-02-14 Thread Eric Bénard
Le Thu, 14 Feb 2013 11:10:54 +0100,
Maxime Ripard maxime.rip...@free-electrons.com a écrit :

 Hi Juergen,
 
 Le 14/02/2013 09:16, Juergen Beisert a écrit :
  Maxime Ripard wrote:
  Since the only storage medium on the cfa-10036 is the MMC card, we need
  to have a registered environment partition on it if we want to be able
  to modify at runtime.
 
  Signed-off-by: Maxime Ripard maxime.rip...@free-electrons.com
  ---
   arch/arm/boards/crystalfontz-cfa10036/cfa10036.c |   44
  +- 1 file changed, 43 insertions(+), 1 deletion(-)
 
  diff --git a/arch/arm/boards/crystalfontz-cfa10036/cfa10036.c 
  b/arch/arm/boards/crystalfontz-cfa10036/cfa10036.c
  index b59dbab..1821b10 100644 
  --- a/arch/arm/boards/crystalfontz-cfa10036/cfa10036.c
  +++ b/arch/arm/boards/crystalfontz-cfa10036/cfa10036.c
  @@ -97,9 +97,46 @@ static int cfa10036_mem_init(void)
   }
   mem_initcall(cfa10036_mem_init);
 
  +/**
  + * Try to register an environment storage on the attached MCI card
  + * @return 0 on success
  + *
  + * We rely on the existence of a usable SD card, already attached to
  + * our system, to get something like a persistent memory for our 
  environment.
  + * If this SD card is also the boot media, we can use the second partition
  + * for our environment purpose (if present!). 
  + */
  +static int register_persistant_environment(void)
  
  register_persist*e*nt_environment
  
  Seems a copy from my typo in the falconwing. I really should fix it :))
 
 Oops :)
 I will fix it, it will probably end up in a common function anyway.
 
FWIW : I have cooked a patch for this common function, I will be
able to send it tonight.

Eric

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


Re: [PATCH] ARM pbl: move piggydata before bss

2013-02-14 Thread Sascha Hauer
On Thu, Feb 14, 2013 at 11:06:13AM +0100, Alexander Aring wrote:
 Hi Sascha,
 
 i am a little bit confused. I add in commit
 
 43afe67390697041d1d16d4e5c934d2bfa831399
 
 the data section, but I forgot to change this linker script file.
 Does it work now?

Yes, it works.

 It seems that pbl doesn't uses pointers from
 asm-generic/sections.h or never includes this file.

The linker generated pointers to the data sections are only used to
request the corresponding sdram regions. The pbl does not request
regions.

 
 Should I write a patch to add data section to this linker script file?

Not necessary.

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] Add warning above get_ram_size

2013-02-14 Thread Sascha Hauer
On Thu, Feb 14, 2013 at 10:40:38AM +0100, Maxime Ripard wrote:
 Hi Sascha,
 
 Le 13/02/2013 18:16, Sascha Hauer a écrit :
  Signed-off-by: Sascha Hauer s.ha...@pengutronix.de
  ---
   common/memsize.c |3 +++
   1 file changed, 3 insertions(+)
  
  diff --git a/common/memsize.c b/common/memsize.c
  index d149e41..ef6381b 100644
  --- a/common/memsize.c
  +++ b/common/memsize.c
  @@ -33,6 +33,9 @@
* Check memory range for valid RAM. A simple memory test determines
* the actually available RAM size between addresses `base' and
* `base + maxsize'.
  + *
  + * This function modifies the RAM. Do not use it if you're running from
  + * the RAM you are going to detect!
*/
 
 Actually, I don't see how it modifies the RAM, at least permanently. The
 values it erase are backed up, and there's no concurrency at barebox
 level, so we are sure that the value saved will still be the one that
 would need to be backed up at the end of the function, right?

Yes, it restores the values, but how do you make sure the function does
not modify the instructions you are currently executing? You need bad
luck to hit this, but sooner or later this will happen.

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 3/3] falconwing: switch to generic peristent env

2013-02-14 Thread Eric Bénard
Signed-off-by: Eric Bénard e...@eukrea.com
---
 arch/arm/boards/chumby_falconwing/falconwing.c | 38 +-
 1 file changed, 1 insertion(+), 37 deletions(-)

diff --git a/arch/arm/boards/chumby_falconwing/falconwing.c 
b/arch/arm/boards/chumby_falconwing/falconwing.c
index 0818666..3a7b830 100644
--- a/arch/arm/boards/chumby_falconwing/falconwing.c
+++ b/arch/arm/boards/chumby_falconwing/falconwing.c
@@ -265,42 +265,6 @@ static int falconwing_mem_init(void)
 }
 mem_initcall(falconwing_mem_init);
 
-/**
- * Try to register an environment storage on the attached MCI card
- * @return 0 on success
- *
- * We rely on the existence of a usable SD card, already attached to
- * our system, to get something like a persistent memory for our environment.
- * If this SD card is also the boot media, we can use the second partition
- * for our environment purpose (if present!).
- */
-static int register_persistant_environment(void)
-{
-   struct cdev *cdev;
-
-   /*
-* The chumby one only has one MCI card socket.
-* So, we expect its name as disk0.
-*/
-   cdev = cdev_by_name(disk0);
-   if (cdev == NULL) {
-   pr_err(No MCI card preset\n);
-   return -ENODEV;
-   }
-
-   /* MCI card is present, also a useable partition on it? */
-   cdev = cdev_by_name(disk0.1);
-   if (cdev == NULL) {
-   pr_err(No second partition available\n);
-   pr_info(Please create at least a second partition with
-256 kiB...512 kiB in size (your choice)\n);
-   return -ENODEV;
-   }
-
-   /* use the full partition as our persistent environment storage */
-   return devfs_add_partition(disk0.1, 0, cdev-size, 
DEVFS_PARTITION_FIXED, env0);
-}
-
 #define GPIO_USB_HUB_RESET 29
 #define GPIO_USB_HUB_POWER 26
 
@@ -338,7 +302,7 @@ static int falconwing_devices_init(void)
armlinux_set_bootparams((void *)IMX_MEMORY_BASE + 0x100);
armlinux_set_architecture(MACH_TYPE_CHUMBY);
 
-   rc = register_persistant_environment();
+   rc = register_persistant_environment(disk0, 1);
if (rc != 0)
printf(Cannot create the 'env0' persistant environment storage 
(%d)\n, rc);
 
-- 
1.7.11.7


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


[PATCH 1/3] env: add register_persistent_environment

2013-02-14 Thread Eric Bénard
- heavily copied from register_persistant_environment which was
Signed-off-by: Juergen Beisert j...@pengutronix.de

Signed-off-by: Eric Bénard e...@eukrea.com
---
 common/environment.c  | 40 
 include/environment.h |  1 +
 2 files changed, 41 insertions(+)

diff --git a/common/environment.c b/common/environment.c
index e8d623f..55befd9 100644
--- a/common/environment.c
+++ b/common/environment.c
@@ -363,3 +363,43 @@ out:
free(buf_free);
return ret;
 }
+
+#ifdef __BAREBOX__
+/**
+ * Try to register an environment storage on a device's partition
+ * @return 0 on success
+ *
+ * We rely on the existence of a usable storage device, already attached to
+ * our system, to get something like a persistent memory for our environment.
+ * We need to specify the partition number to use on this device.
+ * @param[in] devname Name of the device
+ * @param[in] partnr Partition number
+ * @return 0 on success, anything else in case of failure
+ */
+
+int register_persistent_environment(const char *devname, unsigned int partnr)
+{
+   struct cdev *cdev;
+   char *partname;
+
+   if (!devname)
+   return -EINVAL;
+
+   cdev = cdev_by_name(devname);
+   if (cdev == NULL) {
+   pr_err(No %s present\n, devname);
+   return -ENODEV;
+   }
+   partname = asprintf(%s.%d, devname, partnr);
+   cdev = cdev_by_name(partname);
+   if (cdev == NULL) {
+   pr_err(No %s partition available\n, partname);
+   pr_info(Please create the partition %s to store the env\n, 
partname);
+   return -ENODEV;
+   }
+
+   return devfs_add_partition(partname, 0, cdev-size,
+   DEVFS_PARTITION_FIXED, env0);
+}
+EXPORT_SYMBOL(register_persistent_environment);
+#endif
diff --git a/include/environment.h b/include/environment.h
index 7bdd213..d172f8f 100644
--- a/include/environment.h
+++ b/include/environment.h
@@ -71,6 +71,7 @@ int env_pop_context(void);
 int env_push_context(void);
 
 int export(const char *);
+int register_persistent_environment(const char *devname, unsigned int partnr);
 
 #endif /* _ENVIRONMENT_H_ */
 
-- 
1.7.11.7


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


[PATCH 2/3] imx23-olinuxino: swith to generic peristent env

2013-02-14 Thread Eric Bénard
Signed-off-by: Eric Bénard e...@eukrea.com
---
 arch/arm/boards/imx233-olinuxino/imx23-olinuxino.c | 44 +-
 1 file changed, 2 insertions(+), 42 deletions(-)

diff --git a/arch/arm/boards/imx233-olinuxino/imx23-olinuxino.c 
b/arch/arm/boards/imx233-olinuxino/imx23-olinuxino.c
index 0482638..068436f 100644
--- a/arch/arm/boards/imx233-olinuxino/imx23-olinuxino.c
+++ b/arch/arm/boards/imx233-olinuxino/imx23-olinuxino.c
@@ -111,46 +111,6 @@ static void olinuxino_init_usb(void)
add_generic_usb_ehci_device(DEVICE_ID_DYNAMIC, IMX_USB_BASE, NULL);
 }
 
-/**
- * Try to register an environment storage on the attached MCI card
- * @return 0 on success
- *
- * We rely on the existence of a usable SD card, already attached to
- * our system, to get something like a persistent memory for our environment.
- * If this SD card is also the boot media, we can use the second partition
- * for our environment purpose (if present!).
- */
-static int register_persistant_environment(void)
-{
-   struct cdev *cdev;
-
-   /*
-* The imx23-olinuxino only has one MCI card socket.
-* So, we expect its name as disk0.
-*/
-   cdev = cdev_by_name(disk0);
-   if (cdev == NULL) {
-   pr_err(No MCI card preset\n);
-   return -ENODEV;
-   }
-
-
-
-   /* MCI card is present, also a useable partition on it? */
-   cdev = cdev_by_name(disk0.1);
-   if (cdev == NULL) {
-   pr_err(No second partition available\n);
-   pr_info(Please create at least a second partition with
-256 kiB...512 kiB in size (your choice)\n);
-   return -ENODEV;
-   }
-
-   /* use the full partition as our persistent environment storage */
-   return devfs_add_partition(disk0.1, 0, cdev-size,
-   DEVFS_PARTITION_FIXED, env0);
-}
-
-
 static int imx23_olinuxino_devices_init(void)
 {
int i, rc;
@@ -174,9 +134,9 @@ static int imx23_olinuxino_devices_init(void)
 
olinuxino_init_usb();
 
-   rc = register_persistant_environment();
+   rc = register_persistent_environment(disk0, 1);
if (rc != 0)
-   printf(Cannot create the 'env0' persistant 
+   printf(Cannot create the 'env0' persistent 
 environment storage (%d)\n, rc);
 
return 0;
-- 
1.7.11.7


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


Re: [PATCH 0/2] Summary of last patches submitted

2013-02-14 Thread Sascha Hauer
On Tue, Feb 12, 2013 at 12:04:57AM +0100, Vicente Bergas wrote:
 Here are the last two patches I've submitted.
 The first is a straightforward solution to a regression.
 The second was first intended to provide devicetree support for booting an
 omap4 based tablet. I've achieved booting it successfully, but after several
 tries at bringing the mmc controller working I've realised that the Linux
 kernel still has no support for devicetree on omap4 (it's almost there, but it
 lacks dma configuration).
 For more information see:
 http://omappedia.org/wiki/Device_Tree#Drivers_.2F_Features_migration_status
 So the second patch has been stripped and only provides generic support,
 nothing related to the tablet.
 
 The patches also include the changes reflecting the received feedback, thanks!
 
 Vicente Bergas (2):
   ArchosG9: solve regression in second stage lowlevel init
   DeviceTree: add support for initrd in the DT

Applied, thanks

Sascha

 
  arch/arm/boards/archosg9/lowlevel.c |  7 ++--
  arch/arm/lib/armlinux.c |  2 ++
  common/oftree.c | 66 
 +
  include/of.h|  8 +
  4 files changed, 81 insertions(+), 2 deletions(-)
 
 -- 
 1.8.1.3
 
 
 ___
 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- |

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


[PATCH 1/4] fs: fix return type of read

2013-02-14 Thread Alexander Aring
Use ssize_t instead of int. Similar write function
which uses ssize_t as return type, too.

Signed-off-by: Alexander Aring alex.ar...@gmail.com
---
 fs/fs.c  | 2 +-
 include/fs.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/fs.c b/fs/fs.c
index f840516..48d1c89 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -754,7 +754,7 @@ int ioctl(int fd, int request, void *buf)
return ret;
 }
 
-int read(int fd, void *buf, size_t count)
+ssize_t read(int fd, void *buf, size_t count)
 {
struct device_d *dev;
struct fs_driver_d *fsdrv;
diff --git a/include/fs.h b/include/fs.h
index 919daab..d6b22f7 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -113,7 +113,7 @@ int close(int fd);
 int flush(int fd);
 int lstat(const char *filename, struct stat *s);
 int stat(const char *filename, struct stat *s);
-int read(int fd, void *buf, size_t count);
+ssize_t 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.8.1.3


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


[PATCH 2/4] fs: add pread and pwrite functions

2013-02-14 Thread Alexander Aring
Add pread and pwrite functions.

These functions setting file pointer to a given
offset with lseek and call read or write afterwards.

Signed-off-by: Alexander Aring alex.ar...@gmail.com
---
 fs/fs.c  | 28 
 include/fs.h |  2 ++
 2 files changed, 30 insertions(+)

diff --git a/fs/fs.c b/fs/fs.c
index 48d1c89..fea7e02 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -785,6 +785,20 @@ ssize_t read(int fd, void *buf, size_t count)
 }
 EXPORT_SYMBOL(read);
 
+ssize_t pread(int fd, void *buf, size_t count, loff_t offset)
+{
+   int ret;
+
+   ret = lseek(fd, offset, SEEK_SET);
+   if (ret  0)
+   goto out;
+
+   ret = read(fd, buf, count);
+out:
+   return ret;
+}
+EXPORT_SYMBOL(pread);
+
 ssize_t write(int fd, const void *buf, size_t count)
 {
struct device_d *dev;
@@ -821,6 +835,20 @@ out:
 }
 EXPORT_SYMBOL(write);
 
+ssize_t pwrite(int fd, const void *buf, size_t count, loff_t offset)
+{
+   int ret;
+
+   ret = lseek(fd, offset, SEEK_SET);
+   if (ret  0)
+   goto out;
+
+   ret = write(fd, buf, count);
+out:
+   return ret;
+}
+EXPORT_SYMBOL(pwrite);
+
 int flush(int fd)
 {
struct device_d *dev;
diff --git a/include/fs.h b/include/fs.h
index d6b22f7..7c4e461 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -114,8 +114,10 @@ int flush(int fd);
 int lstat(const char *filename, struct stat *s);
 int stat(const char *filename, struct stat *s);
 ssize_t read(int fd, void *buf, size_t count);
+ssize_t pread(int fd, void *buf, size_t count, loff_t offset);
 int ioctl(int fd, int request, void *buf);
 ssize_t write(int fd, const void *buf, size_t count);
+ssize_t pwrite(int fd, const void *buf, size_t count, loff_t offset);
 
 #define SEEK_SET   1
 #define SEEK_CUR   2
-- 
1.8.1.3


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


[PATCH 3/4] nandtest: use new pread and pwrite functions

2013-02-14 Thread Alexander Aring
Signed-off-by: Alexander Aring alex.ar...@gmail.com
---
 commands/nandtest.c | 36 ++--
 1 file changed, 6 insertions(+), 30 deletions(-)

diff --git a/commands/nandtest.c b/commands/nandtest.c
index f08f8eb..4e6024b 100644
--- a/commands/nandtest.c
+++ b/commands/nandtest.c
@@ -43,41 +43,17 @@ static unsigned int ecc_stats_over;
 static unsigned int ecc_failed_cnt;
 
 /*
- * Implementation of pread with lseek and read.
- */
-static ssize_t pread(int fd, void *buf, size_t count, loff_t offset)
-{
-   int ret;
-
-   /* Seek to offset */
-   ret = lseek(fd, offset, SEEK_SET);
-   if (ret  0)
-   perror(lseek);
-
-   /* Read from flash and put it into buf  */
-   ret = read(fd, buf, count);
-   if (ret  0)
-   perror(read);
-
-   return 0;
-}
-
-/*
  * Implementation of pwrite with lseek and write.
  */
-static ssize_t pwrite(int fd, const void *buf,
+static ssize_t __pwrite(int fd, const void *buf,
size_t count, loff_t offset, loff_t length)
 {
-   int ret;
-
-   ret = lseek(fd, offset, SEEK_SET);
-   if (ret  0)
-   perror(lseek);
+   ssize_t ret;
 
/* Write buf to flash */
-   ret = write(fd, buf, count);
+   ret = pwrite(fd, buf, count, offset);
if (ret  0) {
-   perror(write);
+   perror(pwrite);
if (markbad) {
printf(\nMark block bad at 0x%08llx\n,
offset + memregion.offset);
@@ -88,7 +64,7 @@ static ssize_t pwrite(int fd, const void *buf,
}
 
flush(fd);
-   return 0;
+   return ret;
 }
 
 /*
@@ -119,7 +95,7 @@ static int erase_and_write(loff_t ofs, unsigned char *data,
for (i = 0; i  meminfo.erasesize;
i += meminfo.writesize) {
/* Write data to given offset */
-   pwrite(fd, data + i, meminfo.writesize,
+   __pwrite(fd, data + i, meminfo.writesize,
ofs + i, length);
 
/* Read data from offset */
-- 
1.8.1.3


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


[PATCH v2] falconwing: switch to generic peristent env

2013-02-14 Thread Eric Bénard
Signed-off-by: Eric Bénard e...@eukrea.com
---
v2: fix typo on persistent

 arch/arm/boards/chumby_falconwing/falconwing.c | 38 +-
 1 file changed, 1 insertion(+), 37 deletions(-)

diff --git a/arch/arm/boards/chumby_falconwing/falconwing.c 
b/arch/arm/boards/chumby_falconwing/falconwing.c
index 0818666..3e82596 100644
--- a/arch/arm/boards/chumby_falconwing/falconwing.c
+++ b/arch/arm/boards/chumby_falconwing/falconwing.c
@@ -265,42 +265,6 @@ static int falconwing_mem_init(void)
 }
 mem_initcall(falconwing_mem_init);
 
-/**
- * Try to register an environment storage on the attached MCI card
- * @return 0 on success
- *
- * We rely on the existence of a usable SD card, already attached to
- * our system, to get something like a persistent memory for our environment.
- * If this SD card is also the boot media, we can use the second partition
- * for our environment purpose (if present!).
- */
-static int register_persistant_environment(void)
-{
-   struct cdev *cdev;
-
-   /*
-* The chumby one only has one MCI card socket.
-* So, we expect its name as disk0.
-*/
-   cdev = cdev_by_name(disk0);
-   if (cdev == NULL) {
-   pr_err(No MCI card preset\n);
-   return -ENODEV;
-   }
-
-   /* MCI card is present, also a useable partition on it? */
-   cdev = cdev_by_name(disk0.1);
-   if (cdev == NULL) {
-   pr_err(No second partition available\n);
-   pr_info(Please create at least a second partition with
-256 kiB...512 kiB in size (your choice)\n);
-   return -ENODEV;
-   }
-
-   /* use the full partition as our persistent environment storage */
-   return devfs_add_partition(disk0.1, 0, cdev-size, 
DEVFS_PARTITION_FIXED, env0);
-}
-
 #define GPIO_USB_HUB_RESET 29
 #define GPIO_USB_HUB_POWER 26
 
@@ -338,7 +302,7 @@ static int falconwing_devices_init(void)
armlinux_set_bootparams((void *)IMX_MEMORY_BASE + 0x100);
armlinux_set_architecture(MACH_TYPE_CHUMBY);
 
-   rc = register_persistant_environment();
+   rc = register_persistent_environment(disk0, 1);
if (rc != 0)
printf(Cannot create the 'env0' persistant environment storage 
(%d)\n, rc);
 
-- 
1.7.11.7


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


Re: [PATCH] ARM pbl: move piggydata before bss

2013-02-14 Thread Jean-Christophe PLAGNIOL-VILLARD
On 10:12 Thu 14 Feb , Sascha Hauer wrote:
 This decreases the pbl image size by the size of the bss segment.
 
 Signed-off-by: Sascha Hauer s.ha...@pengutronix.de
 ---
  arch/arm/pbl/zbarebox.lds.S |   12 ++--
  1 file changed, 6 insertions(+), 6 deletions(-)
 
 diff --git a/arch/arm/pbl/zbarebox.lds.S b/arch/arm/pbl/zbarebox.lds.S
 index 564b3c6..2914fdd 100644
 --- a/arch/arm/pbl/zbarebox.lds.S
 +++ b/arch/arm/pbl/zbarebox.lds.S
 @@ -59,18 +59,18 @@ SECTIONS
   .data : { *(.data*) }
  
   . = ALIGN(4);
 - __bss_start = .;
 - .bss : { *(.bss*) }
 - __bss_stop = .;
 - _end = .;
 -
 - . = ALIGN(4);
   __piggydata_start = .;
   .piggydata : {
   *(.piggydata)
   }
   __piggydata_end = .;
  
 + . = ALIGN(4);
 + __bss_start = .;
 + .bss : { *(.bss*) }
 + __bss_stop = .;
 + _end = .;

I did this on purpose

so we can load the pbl in sram without the piggydata

so do not change it

Best Regards,
J.
 +
   _barebox_image_size = __piggydata_end - (TEXT_BASE - SZ_2M);
   _barebox_pbl_size = __bss_start - (TEXT_BASE - SZ_2M);
  }
 -- 
 1.7.10.4
 
 
 ___
 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 0/6 v3] arm: add Calxeda Highbank support

2013-02-14 Thread Sascha Hauer
On Wed, Feb 13, 2013 at 11:02:49AM +0100, Jean-Christophe PLAGNIOL-VILLARD 
wrote:
 Hi,
 
   v3:
reset: add missing wfi
gpio: move probe to board
add oftree probe support
 
   v2:
fix cc tag so Rob can receive the patch
add oftree support to xgmac
 
   The following patch serie add the support of the Quad Core Cortex-A9
   Highbank from Calxeda
 
   As I do not have the real hardware this is only tested on qemu
 
   Rob could confirm if this work on real hw
 
   This patch serie depends on the amba sp804 patch and the ahci patch 
 serie
 
 The following changes since commit ddec6455ac75cad442be1247ae265b539c54ebfe:
 
   amba: add oftree probe support (2013-02-13 02:35:56 +0800)
 
 are available in the git repository at:
 
   git://git.jcrosoft.org/barebox.git delivery/highbank

Applied, thanks

Sascha

 
 for you to fetch changes up to 1d6b912a9a89b0bdf7915026d938f40aba13b581:
 
   highbank: use the provided dtb by the firmware to probe barebox device and 
 mem size (2013-02-13 02:35:56 +0800)
 
 
 Jean-Christophe PLAGNIOL-VILLARD (6):
   ahci-generic: add oftree support
   of: make of_add_memory available for other board
   highbank: add xgmac support
   arm: add highbank support
   highbank: add l2x0 support
   highbank: use the provided dtb by the firmware to probe barebox device 
 and mem size
 
  arch/arm/Kconfig   |   12 
  arch/arm/Makefile  |2 +
  arch/arm/boards/highbank/Makefile  |4 ++
  arch/arm/boards/highbank/config.h  |5 ++
  arch/arm/boards/highbank/env/bin/init_board|7 +++
  arch/arm/boards/highbank/env/config|   34 +++
  arch/arm/boards/highbank/init.c|   86 
 ++
  arch/arm/boards/highbank/lowlevel.c|   17 ++
  arch/arm/configs/highbank_defconfig|   61 +++
  arch/arm/mach-highbank/Kconfig |   18 ++
  arch/arm/mach-highbank/Makefile|4 ++
  arch/arm/mach-highbank/cache-l2x0.c|   45 ++
  arch/arm/mach-highbank/core.c  |   49 +++
  arch/arm/mach-highbank/core.h  |2 +
  arch/arm/mach-highbank/devices.c   |   74 +++
  arch/arm/mach-highbank/include/mach/clkdev.h   |7 +++
  arch/arm/mach-highbank/include/mach/debug_ll.h |   26 
  arch/arm/mach-highbank/include/mach/devices.h  |   17 ++
  arch/arm/mach-highbank/include/mach/gpio.h |1 +
  arch/arm/mach-highbank/reset.c |   21 +++
  arch/arm/mach-highbank/smc.S   |   27 +
  arch/arm/mach-highbank/sysregs.h   |   52 
  drivers/ata/ahci.c |9 +++
  drivers/net/Kconfig|3 +
  drivers/net/Makefile   |1 +
  drivers/net/xgmac.c|  740 
 +
  drivers/of/base.c  |   20 --
  include/of.h   |6 ++
  28 files changed, 1344 insertions(+), 6 deletions(-)
  create mode 100644 arch/arm/boards/highbank/Makefile
  create mode 100644 arch/arm/boards/highbank/config.h
  create mode 100644 arch/arm/boards/highbank/env/bin/init_board
  create mode 100644 arch/arm/boards/highbank/env/config
  create mode 100644 arch/arm/boards/highbank/init.c
  create mode 100644 arch/arm/boards/highbank/lowlevel.c
  create mode 100644 arch/arm/configs/highbank_defconfig
  create mode 100644 arch/arm/mach-highbank/Kconfig
  create mode 100644 arch/arm/mach-highbank/Makefile
  create mode 100644 arch/arm/mach-highbank/cache-l2x0.c
  create mode 100644 arch/arm/mach-highbank/core.c
  create mode 100644 arch/arm/mach-highbank/core.h
  create mode 100644 arch/arm/mach-highbank/devices.c
  create mode 100644 arch/arm/mach-highbank/include/mach/clkdev.h
  create mode 100644 arch/arm/mach-highbank/include/mach/debug_ll.h
  create mode 100644 arch/arm/mach-highbank/include/mach/devices.h
  create mode 100644 arch/arm/mach-highbank/include/mach/gpio.h
  create mode 100644 arch/arm/mach-highbank/reset.c
  create mode 100644 arch/arm/mach-highbank/smc.S
  create mode 100644 arch/arm/mach-highbank/sysregs.h
  create mode 100644 drivers/net/xgmac.c
 
 Best Regards,
 J.
 
 ___
 barebox mailing list
 barebox@lists.infradead.org
 http://lists.infradead.org/mailman/listinfo/barebox
 

-- 
Pengutronix e.K.   | |
Industrial 

[PATCH v3] falconwing: switch to generic peristent env

2013-02-14 Thread Eric Bénard
Signed-off-by: Eric Bénard e...@eukrea.com
---
v3: also fix the typo in the printf
v2: fix typo in persistent

 arch/arm/boards/chumby_falconwing/falconwing.c | 40 ++
 1 file changed, 2 insertions(+), 38 deletions(-)

diff --git a/arch/arm/boards/chumby_falconwing/falconwing.c 
b/arch/arm/boards/chumby_falconwing/falconwing.c
index 0818666..80eebba 100644
--- a/arch/arm/boards/chumby_falconwing/falconwing.c
+++ b/arch/arm/boards/chumby_falconwing/falconwing.c
@@ -265,42 +265,6 @@ static int falconwing_mem_init(void)
 }
 mem_initcall(falconwing_mem_init);
 
-/**
- * Try to register an environment storage on the attached MCI card
- * @return 0 on success
- *
- * We rely on the existence of a usable SD card, already attached to
- * our system, to get something like a persistent memory for our environment.
- * If this SD card is also the boot media, we can use the second partition
- * for our environment purpose (if present!).
- */
-static int register_persistant_environment(void)
-{
-   struct cdev *cdev;
-
-   /*
-* The chumby one only has one MCI card socket.
-* So, we expect its name as disk0.
-*/
-   cdev = cdev_by_name(disk0);
-   if (cdev == NULL) {
-   pr_err(No MCI card preset\n);
-   return -ENODEV;
-   }
-
-   /* MCI card is present, also a useable partition on it? */
-   cdev = cdev_by_name(disk0.1);
-   if (cdev == NULL) {
-   pr_err(No second partition available\n);
-   pr_info(Please create at least a second partition with
-256 kiB...512 kiB in size (your choice)\n);
-   return -ENODEV;
-   }
-
-   /* use the full partition as our persistent environment storage */
-   return devfs_add_partition(disk0.1, 0, cdev-size, 
DEVFS_PARTITION_FIXED, env0);
-}
-
 #define GPIO_USB_HUB_RESET 29
 #define GPIO_USB_HUB_POWER 26
 
@@ -338,9 +302,9 @@ static int falconwing_devices_init(void)
armlinux_set_bootparams((void *)IMX_MEMORY_BASE + 0x100);
armlinux_set_architecture(MACH_TYPE_CHUMBY);
 
-   rc = register_persistant_environment();
+   rc = register_persistent_environment(disk0, 1);
if (rc != 0)
-   printf(Cannot create the 'env0' persistant environment storage 
(%d)\n, rc);
+   printf(Cannot create the 'env0' persistent environment storage 
(%d)\n, rc);
 
return 0;
 }
-- 
1.7.11.7


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


Re: [PATCH] Add warning above get_ram_size

2013-02-14 Thread Maxime Ripard
Hi Sascha,

Le 14/02/2013 12:35, Sascha Hauer a écrit :
 On Thu, Feb 14, 2013 at 10:40:38AM +0100, Maxime Ripard wrote:
 Hi Sascha,

 Le 13/02/2013 18:16, Sascha Hauer a écrit :
 Signed-off-by: Sascha Hauer s.ha...@pengutronix.de
 ---
  common/memsize.c |3 +++
  1 file changed, 3 insertions(+)

 diff --git a/common/memsize.c b/common/memsize.c
 index d149e41..ef6381b 100644
 --- a/common/memsize.c
 +++ b/common/memsize.c
 @@ -33,6 +33,9 @@
   * Check memory range for valid RAM. A simple memory test determines
   * the actually available RAM size between addresses `base' and
   * `base + maxsize'.
 + *
 + * This function modifies the RAM. Do not use it if you're running from
 + * the RAM you are going to detect!
   */

 Actually, I don't see how it modifies the RAM, at least permanently. The
 values it erase are backed up, and there's no concurrency at barebox
 level, so we are sure that the value saved will still be the one that
 would need to be backed up at the end of the function, right?
 
 Yes, it restores the values, but how do you make sure the function does
 not modify the instructions you are currently executing? You need bad
 luck to hit this, but sooner or later this will happen.

Ah, yes, this would be nasty indeed. Is there a way to know the end
address of barebox into RAM ? or the address it has been loaded to and
the size of its binary, so that we can just check the part that doesn't
hold barebox?

Maxime

-- 
Maxime Ripard, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com

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


[PATCH 0/5] add EFI GUID Partition Table support

2013-02-14 Thread Jean-Christophe PLAGNIOL-VILLARD
HI,

this add the support of the EFI GPT and named partition

The following changes since commit a40e76cebcbe8b025bafdefdc6e27b7553209ed7:

  Add warning above get_ram_size (2013-02-13 18:14:38 +0100)

are available in the git repository at:

  git://git.jcrosoft.org/barebox.git delivery/efi_gpt

for you to fetch changes up to af822258f8dd08f8d8aab9e5e70e84033028b26d:

  disk: partitions: add EFI GUID Partition Table (2013-02-13 22:49:30 +0800)


Jean-Christophe PLAGNIOL-VILLARD (5):
  linux/types: import __aligned_x64 from the kernel
  filetype: add GPT support
  partitons: add framework
  disk: introduce partition name
  disk: partitions: add EFI GUID Partition Table

 common/Kconfig |   14 +--
 common/Makefile|2 +-
 common/filetype.c  |4 ++
 common/partitions.c|  181 
++--
 common/partitions/Makefile |2 +
 common/partitions/dos.c|   87 +++
 common/partitions/efi.c|  508 
+++
 common/partitions/efi.h|  123 
++
 common/partitions/parser.h |   37 +
 include/filetype.h |1 +
 include/linux/efi.h|  547 
+
 include/linux/types.h  |   13 ++
 12 files changed, 1409 insertions(+), 110 deletions(-)
 create mode 100644 common/partitions/Makefile
 create mode 100644 common/partitions/dos.c
 create mode 100644 common/partitions/efi.c
 create mode 100644 common/partitions/efi.h
 create mode 100644 common/partitions/parser.h
 create mode 100644 include/linux/efi.h

Best Regards,
J.

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


[PATCH 1/5] linux/types: import __aligned_x64 from the kernel

2013-02-14 Thread Jean-Christophe PLAGNIOL-VILLARD
need it by upcoming EFI GPT support

Cc: Rob Herring rob.herr...@calxeda.com
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD plagn...@jcrosoft.com
---
 include/linux/types.h |   13 +
 1 file changed, 13 insertions(+)

diff --git a/include/linux/types.h b/include/linux/types.h
index 76c6b67..14f8315 100644
--- a/include/linux/types.h
+++ b/include/linux/types.h
@@ -142,6 +142,19 @@ typedef __u64 __bitwise __be64;
 typedef __u16 __bitwise __sum16;
 typedef __u32 __bitwise __wsum;
 
+/*
+ * aligned_u64 should be used in defining kernel-userspace ABIs to avoid
+ * common 32/64-bit compat problems.
+ * 64-bit values align to 4-byte boundaries on x86_32 (and possibly other
+ * architectures) and to 8-byte boundaries on 64-bit architectures.  The new
+ * aligned_64 type enforces 8-byte alignment so that structs containing
+ * aligned_64 values have the same alignment on 32-bit and 64-bit 
architectures.
+ * No conversions are necessary between 32-bit user-space and a 64-bit kernel.
+ */
+#define __aligned_u64 __u64 __attribute__((aligned(8)))
+#define __aligned_be64 __be64 __attribute__((aligned(8)))
+#define __aligned_le64 __le64 __attribute__((aligned(8)))
+
 #ifdef CONFIG_PHYS_ADDR_T_64BIT
 typedef u64 phys_addr_t;
 typedef u64 phys_size_t;
-- 
1.7.10.4


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


[PATCH 2/5] filetype: add GPT support

2013-02-14 Thread Jean-Christophe PLAGNIOL-VILLARD
GPT need to be check before MBR

Cc: Rob Herring rob.herr...@calxeda.com
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD plagn...@jcrosoft.com
---
 common/filetype.c  |4 
 include/filetype.h |1 +
 2 files changed, 5 insertions(+)

diff --git a/common/filetype.c b/common/filetype.c
index 22fc621..6563ecc 100644
--- a/common/filetype.c
+++ b/common/filetype.c
@@ -48,6 +48,7 @@ static const struct filetype_str filetype_str[] = {
[filetype_bmp] = { BMP image, bmp },
[filetype_png] = { PNG image, png },
[filetype_ext] = { ext filesystem, ext },
+   [filetype_gpt] = { GUID Partition Table, gpt },
 };
 
 const char *file_type_to_string(enum filetype f)
@@ -159,6 +160,9 @@ enum filetype file_detect_type(const void *_buf, size_t 
bufsize)
if (bufsize  512)
return filetype_unknown;
 
+   if (bufsize = 520  strncmp(buf8[512], EFI PART, 8) == 0)
+   return filetype_gpt;
+
type = is_fat_or_mbr(buf8, NULL);
if (type != filetype_unknown)
return type;
diff --git a/include/filetype.h b/include/filetype.h
index 4d43757..78ca5d2 100644
--- a/include/filetype.h
+++ b/include/filetype.h
@@ -23,6 +23,7 @@ enum filetype {
filetype_bmp,
filetype_png,
filetype_ext,
+   filetype_gpt,
filetype_max,
 };
 
-- 
1.7.10.4


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


[PATCH 3/5] partitons: add framework

2013-02-14 Thread Jean-Christophe PLAGNIOL-VILLARD
so we can support multiple format

use filetpye to detect the parser to use

Cc: Rob Herring rob.herr...@calxeda.com
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD plagn...@jcrosoft.com
---
 common/Kconfig |   14 +
 common/Makefile|2 +-
 common/partitions.c|  132 +++-
 common/partitions/Makefile |1 +
 common/partitions/dos.c|   87 +
 common/partitions/parser.h |   35 
 6 files changed, 171 insertions(+), 100 deletions(-)
 create mode 100644 common/partitions/Makefile
 create mode 100644 common/partitions/dos.c
 create mode 100644 common/partitions/parser.h

diff --git a/common/Kconfig b/common/Kconfig
index 3f6c11e..3a55e01 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -478,19 +478,7 @@ config PARTITION
bool
prompt Enable Partitions
 
-config PARTITION_DISK
-   depends on PARTITION
-   bool DISK partition support
-   help
- Add support for handling common partition tables on all kind of disk
- like devices (harddisks, CF cards, SD cards and so on)
-
-config PARTITION_DISK_DOS
-   depends on PARTITION_DISK
-   default y
-   bool DOS partition support
-   help
- Add support to handle partitions in DOS style.
+source common/partitions/Kconfig
 
 config DEFAULT_ENVIRONMENT
bool
diff --git a/common/Makefile b/common/Makefile
index 7206eed..b264cb8 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -7,7 +7,7 @@ obj-$(CONFIG_ENV_HANDLING)  += environment.o
 obj-$(CONFIG_AUTO_COMPLETE)+= complete.o
 obj-$(CONFIG_POLLER)   += poller.o
 obj-$(CONFIG_BLOCK)+= block.o
-obj-$(CONFIG_PARTITION_DISK)   += partitions.o
+obj-$(CONFIG_PARTITION_DISK)   += partitions.o partitions/
 
 obj-$(CONFIG_CMD_LOADS)+= s_record.o
 obj-$(CONFIG_OFTREE)   += oftree.o
diff --git a/common/partitions.c b/common/partitions.c
index 24310a3..7cb8399 100644
--- a/common/partitions.c
+++ b/common/partitions.c
@@ -27,92 +27,12 @@
 #include block.h
 #include asm/unaligned.h
 #include disks.h
-#include dma.h
 #include filetype.h
+#include dma.h
 
-struct partition {
-   uint64_t first_sec;
-   uint64_t size;
-};
-
-struct partition_desc {
-   int used_entries;
-   struct partition parts[8];
-};
-
-/**
- * Guess the size of the disk, based on the partition table entries
- * @param dev device to create partitions for
- * @param table partition table
- * @return sector count
- */
-static int disk_guess_size(struct device_d *dev, struct partition_entry *table)
-{
-   uint64_t size = 0;
-   int i;
-
-   for (i = 0; i  4; i++) {
-   if (table[i].partition_start != 0) {
-   size += get_unaligned_le32(table[i].partition_start) - 
size;
-   size += get_unaligned_le32(table[i].partition_size);
-   }
-   }
-
-   return (int)size;
-}
-
-/**
- * Check if a DOS like partition describes this block device
- * @param blk Block device to register to
- * @param pd Where to store the partition information
- *
- * It seems at least on ARM this routine canot use temp. stack space for the
- * sector. So, keep the malloc/free.
- */
-static void __maybe_unused try_dos_partition(struct block_device *blk,
-   struct partition_desc *pd)
-{
-   uint8_t *buffer;
-   struct partition_entry *table;
-   struct partition pentry;
-   int i, rc;
-
-   buffer = dma_alloc(SECTOR_SIZE);
-
-   /* read in the MBR to get the partition table */
-   rc = blk-ops-read(blk, buffer, 0, 1);
-   if (rc != 0) {
-   dev_err(blk-dev, Cannot read MBR/partition table\n);
-   goto on_error;
-   }
-
-   if (is_fat_or_mbr(buffer, NULL) != filetype_mbr) {
-   dev_info(blk-dev, No partition table found\n);
-   goto on_error;
-   }
-
-   table = (struct partition_entry *)buffer[446];
-
-   /* valid for x86 BIOS based disks only */
-   if (IS_ENABLED(CONFIG_DISK_BIOS)  blk-num_blocks == 0)
-   blk-num_blocks = disk_guess_size(blk-dev, table);
-
-   for (i = 0; i  4; i++) {
-   pentry.first_sec = 
get_unaligned_le32(table[i].partition_start);
-   pentry.size = get_unaligned_le32(table[i].partition_size);
+#include partitions/parser.h
 
-   if (pentry.first_sec != 0) {
-   pd-parts[pd-used_entries].first_sec = 
pentry.first_sec;
-   pd-parts[pd-used_entries].size = pentry.size;
-   pd-used_entries++;
-   } else {
-   dev_dbg(blk-dev, Skipping empty partition %d\n, i);
-   }
-   }
-
-on_error:
-   dma_free(buffer);
-}
+LIST_HEAD(partition_parser_list);
 
 /**
  * Register one partition on the given block device
@@ -135,6 +55,21 @@ static int 

[PATCH 4/5] disk: introduce partition name

2013-02-14 Thread Jean-Christophe PLAGNIOL-VILLARD
so we can register partion with name as present in EFI GPT

Cc: Rob Herring rob.herr...@calxeda.com
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD plagn...@jcrosoft.com
---
 common/partitions.c|   51 ++--
 common/partitions/parser.h |2 ++
 2 files changed, 42 insertions(+), 11 deletions(-)

diff --git a/common/partitions.c b/common/partitions.c
index 7cb8399..51a0fc2 100644
--- a/common/partitions.c
+++ b/common/partitions.c
@@ -44,15 +44,42 @@ LIST_HEAD(partition_parser_list);
 static int register_one_partition(struct block_device *blk,
struct partition *part, int no)
 {
-   char partition_name[19];
+   char *partition_name;
+   int ret;
+   uint64_t start = part-first_sec * SECTOR_SIZE;
+   uint64_t size = part-size * SECTOR_SIZE;
+
+   partition_name = asprintf(%s.%d, blk-cdev.name, no);
+   if (!partition_name)
+   return -ENOMEM;
+   dev_dbg(blk-dev, Registering partition %s on drive %s\n,
+   partition_name, blk-cdev.name);
+   ret = devfs_add_partition(blk-cdev.name,
+   start, size, 0, partition_name);
+   if (ret)
+   goto out;
+
+   free(partition_name);
+   partition_name = asprintf(%s.%s, blk-cdev.name, part-name);
+   if (!partition_name) {
+   dev_warn(blk-dev, Registering partition %s on drive %s 
failled\n,
+   part-name, blk-cdev.name);
+   return 0;
+   }
 
-   sprintf(partition_name, %s.%d, blk-cdev.name, no);
dev_dbg(blk-dev, Registering partition %s on drive %s\n,
partition_name, blk-cdev.name);
-   return devfs_add_partition(blk-cdev.name,
-   part-first_sec * SECTOR_SIZE,
-   part-size * SECTOR_SIZE,
-   0, partition_name);
+   ret = devfs_add_partition(blk-cdev.name,
+   start, size, 0, partition_name);
+
+   if (ret)
+   dev_warn(blk-dev, Registering partition %s on drive %s 
failled\n,
+   partition_name, blk-cdev.name);
+
+   ret = 0;
+out:
+   free(partition_name);
+   return 0;
 }
 
 static struct partition_parser *partition_parser_get_by_filetype(uint8_t *buf)
@@ -79,12 +106,13 @@ static struct partition_parser 
*partition_parser_get_by_filetype(uint8_t *buf)
  */
 int parse_partition_table(struct block_device *blk)
 {
-   struct partition_desc pdesc = { .used_entries = 0, };
+   struct partition_desc *pdesc;
int i;
int rc = 0;
struct partition_parser *parser;
uint8_t *buf;
 
+   pdesc = xzalloc(sizeof(*pdesc));
buf = dma_alloc(SECTOR_SIZE * 2);
 
rc = blk-ops-read(blk, buf, 0, 2);
@@ -97,14 +125,14 @@ int parse_partition_table(struct block_device *blk)
if (!parser)
goto on_error;
 
-   parser-parse(buf, blk, pdesc);
+   parser-parse(buf, blk, pdesc);
 
-   if (!pdesc.used_entries)
+   if (!pdesc-used_entries)
return 0;
 
/* at least one partition description found */
-   for (i = 0; i  pdesc.used_entries; i++) {
-   rc = register_one_partition(blk, pdesc.parts[i], i);
+   for (i = 0; i  pdesc-used_entries; i++) {
+   rc = register_one_partition(blk, pdesc-parts[i], i);
if (rc != 0)
dev_err(blk-dev,
Failed to register partition %d on %s (%d)\n,
@@ -115,6 +143,7 @@ int parse_partition_table(struct block_device *blk)
 
 on_error:
dma_free(buf);
+   free(pdesc);
return rc;
 }
 
diff --git a/common/partitions/parser.h b/common/partitions/parser.h
index 61b1cf5..083c143 100644
--- a/common/partitions/parser.h
+++ b/common/partitions/parser.h
@@ -12,8 +12,10 @@
 #include linux/list.h
 
 #define MAX_PARTITION  8
+#define MAX_PARTITION_NAME 38
 
 struct partition {
+   char name[MAX_PARTITION_NAME];
uint64_t first_sec;
uint64_t size;
 };
-- 
1.7.10.4


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


Re: [PATCH 1/1] commands/ubi.c: Add support for VID header offset in ubiattach

2013-02-14 Thread Jan Lübbe
On Mon, 2013-02-11 at 16:21 +0100, Sascha Hauer wrote:
 I'm interested in this patch once it's clear that this option is needed.
 Right now I think that the work is better invested in making this option
 unneeded. Jan, do you have insights why this is needed?

Linux with current mainline + pending GPMC/ELM patches thinks it
supports sub-page reads/writes on 2k page NAND with BCH8. This is simply
wrong. By using root=ubi0:root ubi.mtd=nand0.root,2048
rootfstype=ubifs in the kernel cmdline, you will get this override in
the kernel.

The GMPC NAND driver in barebox correctly does not use sub-page-access
and works fine without overriding the VID header offset.

When building the UBIFS/UBI the offset must obviously be set correctly.

Which kernel  barebox are you using?

Regards,
Jan
-- 
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/5] filetype: add GPT support

2013-02-14 Thread Sascha Hauer
On Thu, Feb 14, 2013 at 04:52:24PM +0100, Jean-Christophe PLAGNIOL-VILLARD 
wrote:
 GPT need to be check before MBR
 
 Cc: Rob Herring rob.herr...@calxeda.com
 Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD plagn...@jcrosoft.com
 ---
  common/filetype.c  |4 
  include/filetype.h |1 +
  2 files changed, 5 insertions(+)
 
 diff --git a/common/filetype.c b/common/filetype.c
 index 22fc621..6563ecc 100644
 --- a/common/filetype.c
 +++ b/common/filetype.c
 @@ -48,6 +48,7 @@ static const struct filetype_str filetype_str[] = {
   [filetype_bmp] = { BMP image, bmp },
   [filetype_png] = { PNG image, png },
   [filetype_ext] = { ext filesystem, ext },
 + [filetype_gpt] = { GUID Partition Table, gpt },
  };
  
  const char *file_type_to_string(enum filetype f)
 @@ -159,6 +160,9 @@ enum filetype file_detect_type(const void *_buf, size_t 
 bufsize)
   if (bufsize  512)
   return filetype_unknown;
  
 + if (bufsize = 520  strncmp(buf8[512], EFI PART, 8) == 0)
 + return filetype_gpt;
 +

The list is sorted by size, so please move this below:

if (bufsize  1536)
return filetype_unknown;

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/5] filetype: add GPT support

2013-02-14 Thread Jean-Christophe PLAGNIOL-VILLARD
On 17:36 Thu 14 Feb , Sascha Hauer wrote:
 On Thu, Feb 14, 2013 at 04:52:24PM +0100, Jean-Christophe PLAGNIOL-VILLARD 
 wrote:
  GPT need to be check before MBR
  
  Cc: Rob Herring rob.herr...@calxeda.com
  Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD plagn...@jcrosoft.com
  ---
   common/filetype.c  |4 
   include/filetype.h |1 +
   2 files changed, 5 insertions(+)
  
  diff --git a/common/filetype.c b/common/filetype.c
  index 22fc621..6563ecc 100644
  --- a/common/filetype.c
  +++ b/common/filetype.c
  @@ -48,6 +48,7 @@ static const struct filetype_str filetype_str[] = {
  [filetype_bmp] = { BMP image, bmp },
  [filetype_png] = { PNG image, png },
  [filetype_ext] = { ext filesystem, ext },
  +   [filetype_gpt] = { GUID Partition Table, gpt },
   };
   
   const char *file_type_to_string(enum filetype f)
  @@ -159,6 +160,9 @@ enum filetype file_detect_type(const void *_buf, size_t 
  bufsize)
  if (bufsize  512)
  return filetype_unknown;
   
  +   if (bufsize = 520  strncmp(buf8[512], EFI PART, 8) == 0)
  +   return filetype_gpt;
  +
 
 The list is sorted by size, so please move this below:
on purpose

EFI need to be detect before mbr

Best Regards,
J.
 
   if (bufsize  1536)
   return filetype_unknown;
 
 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/5] filetype: add GPT support

2013-02-14 Thread Johannes Stezenbach
On Thu, Feb 14, 2013 at 05:53:23PM +0100, Jean-Christophe PLAGNIOL-VILLARD 
wrote:
 On 17:36 Thu 14 Feb , Sascha Hauer wrote:
  On Thu, Feb 14, 2013 at 04:52:24PM +0100, Jean-Christophe PLAGNIOL-VILLARD 
  wrote:
   GPT need to be check before MBR
   
   Cc: Rob Herring rob.herr...@calxeda.com
   Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD plagn...@jcrosoft.com
   ---
common/filetype.c  |4 
include/filetype.h |1 +
2 files changed, 5 insertions(+)
   
   diff --git a/common/filetype.c b/common/filetype.c
   index 22fc621..6563ecc 100644
   --- a/common/filetype.c
   +++ b/common/filetype.c
   @@ -48,6 +48,7 @@ static const struct filetype_str filetype_str[] = {
 [filetype_bmp] = { BMP image, bmp },
 [filetype_png] = { PNG image, png },
 [filetype_ext] = { ext filesystem, ext },
   + [filetype_gpt] = { GUID Partition Table, gpt },
};

const char *file_type_to_string(enum filetype f)
   @@ -159,6 +160,9 @@ enum filetype file_detect_type(const void *_buf, 
   size_t bufsize)
 if (bufsize  512)
 return filetype_unknown;

   + if (bufsize = 520  strncmp(buf8[512], EFI PART, 8) == 0)
   + return filetype_gpt;
   +
  
  The list is sorted by size, so please move this below:
 on purpose
 
 EFI need to be detect before mbr

IMHO the check is too simple, it will give false positive if
GPT is replaced by DOS MBR and not zeroed out.  Need to check
for protective MBR.

Johannes

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


Environment changes lead to weird boot behaviour

2013-02-14 Thread Christian Kapeller
Hi,

I try to investigate a situation where barebox (v2013.02.0 + board patches)
fails to boot the linux kernel on my karo-tx53 based board. The problem may
well be introduced by myself, but after a few days of investigation is still
fail to grasp the problem's root.

Depending on whether files are present in the boot environment the kernel may
start in some cases, in some it won't.

The file contents seems not to be relevant, since I've managed to get a
broken boot situation, by simply adding a ash script doing one 'echo blah'.

In all cases barebox shuts down in orderly fashion, and jumps to the kernel
image. The kernel in question is a zImage (3.4) + Initramfs + concatenated
devicetree. Also another zImage + concatenated devicetree is affected.


Background: I am implementing a 'foolproof' field update scheme. The
control flow looks like:

(Good Case)  boot0 -(A)- bootA/bootB -(B)- kernel
(Bad Case 1) boot0 -(A)- bootA/bootB -(C)- rescue-kernel
(Bad Case 2) boot0 -(D)- rescue-kernel

boot0   .. 1st stage barebox in 256k NAND partition
bootA/B .. 2nd stage barebox in 256k NAND partition
kernel  .. production kernel + ubiroot in NAND
rescue-kernel  .. selfcontained rescue kernel + initramfs in NAND
bootenv   .. stores just state variables. (256k NAND partition)
scriptenv .. stores just scripts and static config (bundled with 2ndstage)


(A) boot0 checks one of 2 partitions with 2nd stage barebox in a uimage,
and boots the newer one.
(B) 2nd stage bb starts production system
(C) 2nd stage bb starts rescue kernel bc button/bootenv says so.
(D) 1st stage bb starts rescue system bc no 2nd stage is valid

I want to be able to exchange 2nd stage without hassle. To do this,
I've introduced a split of the bootenvironment: boot scripts stay with
the barebox image, non-volatile data is saved in a barebox environment.

The following patch accomplishes this:

diff --git a/common/startup.c b/common/startup.c
index 14409a2..59e76ac 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -108,15 +108,17 @@ void start_barebox (void)
debug(initcalls done\n);
 
 #ifdef CONFIG_ENV_HANDLING
-   if (envfs_load(default_environment_path, /env, 0)) {
+   envfs_load(/dev/defaultenv, /env, 0);
 #ifdef CONFIG_DEFAULT_ENVIRONMENT
+   mkdir(/var, 0);
+   if (envfs_load(default_environment_path, /var, 0)) {
printf(no valid environment found on %s. 
Using default environment\n,
default_environment_path);
-   envfs_load(/dev/defaultenv, /env, 0);
-#endif
+   envfs_save(/dev/env0, /var);
}
 #endif
+#endif
 #ifdef CONFIG_COMMAND_SUPPORT
printf(running /env/bin/init...\n);
 

Everything looks peachy, until I add a file in the boot environment
using the bareboxenv tool. Say, I add a 'update-in-progress' flag. If
the 2nd stage loader sees this, it knows, that something went wrong, 
and can act accordingly.

The problem is, although I can read the state variable out of the 
environment, the kernel boot fails with no messages from the kernel.
No earlyprintk output, nothing.


There the search started:

removing the new file, by just using 'rm /var/update-in-progress'
made the kernel boot again. ... most of the time.

The removing some scripts (not relevant to this bootpath) from
the image bundled scriptenv helped,.. sometimes.

I removed the 'common/bareboxenv' file before every recompile.

I've investigated size issues: I use defaultenv-2 + custom scripts
together ~ 225k worth of ash scripts giving a 15k
common/barebox_default_env. I found no correlation between size
and failure.

I've tried to boil down the scripting stuff, to get a clean
failure case, but no success here, hence I don't post the code
in this mail.

I can compile bb images that render the kernel unbootable.
So I ruled out issues when writing the environment from linux.

The rescue kernel is bootable without any additional kernel
parameters. So I should get at least something from there.
just 'bootm /dev/rescue' works right away.

I've ruled out partition overlaps. The partitions (8 of them)
are registered with mtdparts-add by means of a quite bulky
environment variable.

I've tried to add a big binary blob to the scriptenv, 
making the bb image nearly 256k big. No reproducible
failure,

I've tried to add 30 shell scripts echoing some line.
I source those from /env/bin/init, to see whether ash
couqhs up on them, also no reproducible failure.


So my questions are:

Do you know of any side effects the above patch may introduce?

Do you know of a way to cause a kernel to fail to boot, by just
adding a irrelevant shell script to the boot environment?

What else can I look for?

Best regards,
Christian


-- 
Christian Kapeller
cmotion GmbH
Kriehubergasse 16
1050 Wien / Austria
http://www.cmotion.eu

christian.kapel...@cmotion.eu
Phone: +43 1 789 1096 38

___
barebox mailing list
barebox@lists.infradead.org

Re: [PATCH] Add warning above get_ram_size

2013-02-14 Thread Sascha Hauer
On Thu, Feb 14, 2013 at 02:59:48PM +0100, Maxime Ripard wrote:
 Hi Sascha,
 
 Le 14/02/2013 12:35, Sascha Hauer a écrit :
  On Thu, Feb 14, 2013 at 10:40:38AM +0100, Maxime Ripard wrote:
  Hi Sascha,
 
  Le 13/02/2013 18:16, Sascha Hauer a écrit :
  Signed-off-by: Sascha Hauer s.ha...@pengutronix.de
  ---
   common/memsize.c |3 +++
   1 file changed, 3 insertions(+)
 
  diff --git a/common/memsize.c b/common/memsize.c
  index d149e41..ef6381b 100644
  --- a/common/memsize.c
  +++ b/common/memsize.c
  @@ -33,6 +33,9 @@
* Check memory range for valid RAM. A simple memory test determines
* the actually available RAM size between addresses `base' and
* `base + maxsize'.
  + *
  + * This function modifies the RAM. Do not use it if you're running from
  + * the RAM you are going to detect!
*/
 
  Actually, I don't see how it modifies the RAM, at least permanently. The
  values it erase are backed up, and there's no concurrency at barebox
  level, so we are sure that the value saved will still be the one that
  would need to be backed up at the end of the function, right?
  
  Yes, it restores the values, but how do you make sure the function does
  not modify the instructions you are currently executing? You need bad
  luck to hit this, but sooner or later this will happen.
 
 Ah, yes, this would be nasty indeed. Is there a way to know the end
 address of barebox into RAM ? or the address it has been loaded to and
 the size of its binary, so that we can just check the part that doesn't
 hold barebox?

See include/asm-generic/sections.h. You have to avoid modifying
everything between _text and __bss_stop. I haven't looked how exactly
get_dram_size works. Normally this function would have to test every
location at a power of 2, that would be:

1 2 4 ... 64MiB 128MiB

It seems you have to make sure that your binary does not cross a power
of 2 boundary, then you should be safe.

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/5] filetype: add GPT support

2013-02-14 Thread Sascha Hauer
On Thu, Feb 14, 2013 at 06:05:07PM +0100, Johannes Stezenbach wrote:
 On Thu, Feb 14, 2013 at 05:53:23PM +0100, Jean-Christophe PLAGNIOL-VILLARD 
 wrote:
  On 17:36 Thu 14 Feb , Sascha Hauer wrote:
   On Thu, Feb 14, 2013 at 04:52:24PM +0100, Jean-Christophe 
   PLAGNIOL-VILLARD wrote:
GPT need to be check before MBR

Cc: Rob Herring rob.herr...@calxeda.com
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD plagn...@jcrosoft.com
---
 common/filetype.c  |4 
 include/filetype.h |1 +
 2 files changed, 5 insertions(+)

diff --git a/common/filetype.c b/common/filetype.c
index 22fc621..6563ecc 100644
--- a/common/filetype.c
+++ b/common/filetype.c
@@ -48,6 +48,7 @@ static const struct filetype_str filetype_str[] = {
[filetype_bmp] = { BMP image, bmp },
[filetype_png] = { PNG image, png },
[filetype_ext] = { ext filesystem, ext },
+   [filetype_gpt] = { GUID Partition Table, gpt },
 };
 
 const char *file_type_to_string(enum filetype f)
@@ -159,6 +160,9 @@ enum filetype file_detect_type(const void *_buf, 
size_t bufsize)
if (bufsize  512)
return filetype_unknown;
 
+   if (bufsize = 520  strncmp(buf8[512], EFI PART, 8) == 0)
+   return filetype_gpt;
+
   
   The list is sorted by size, so please move this below:
  on purpose
  
  EFI need to be detect before mbr
 
 IMHO the check is too simple, it will give false positive if
 GPT is replaced by DOS MBR and not zeroed out.  Need to check
 for protective MBR.

So is_fat_or_mbr() should test if the MBR is a protective MBR and return
false in this case?

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 1/3] env: add register_persistent_environment

2013-02-14 Thread Sascha Hauer
On Thu, Feb 14, 2013 at 12:56:49PM +0100, Eric Bénard wrote:
 - heavily copied from register_persistant_environment which was
 Signed-off-by: Juergen Beisert j...@pengutronix.de
 
 Signed-off-by: Eric Bénard e...@eukrea.com
 ---
  common/environment.c  | 40 
  include/environment.h |  1 +

Please move the prototype to include/envfs.h. include/environment.h has
stuff for shell environment variables only.

  2 files changed, 41 insertions(+)
 
 diff --git a/common/environment.c b/common/environment.c
 index e8d623f..55befd9 100644
 --- a/common/environment.c
 +++ b/common/environment.c
 @@ -363,3 +363,43 @@ out:
   free(buf_free);
   return ret;
  }
 +
 +#ifdef __BAREBOX__
 +/**
 + * Try to register an environment storage on a device's partition
 + * @return 0 on success
 + *
 + * We rely on the existence of a usable storage device, already attached to
 + * our system, to get something like a persistent memory for our environment.
 + * We need to specify the partition number to use on this device.
 + * @param[in] devname Name of the device
 + * @param[in] partnr Partition number
 + * @return 0 on success, anything else in case of failure
 + */
 +
 +int register_persistent_environment(const char *devname, unsigned int partnr)

I think envfs_register_partition would be a better name.

 +{
 + struct cdev *cdev;
 + char *partname;
 +
 + if (!devname)
 + return -EINVAL;
 +
 + cdev = cdev_by_name(devname);
 + if (cdev == NULL) {
 + pr_err(No %s present\n, devname);
 + return -ENODEV;
 + }
 + partname = asprintf(%s.%d, devname, partnr);

free partname?

Sascha

 + cdev = cdev_by_name(partname);
 + if (cdev == NULL) {
 + pr_err(No %s partition available\n, partname);
 + pr_info(Please create the partition %s to store the env\n, 
 partname);
 + return -ENODEV;
 + }
 +
 + return devfs_add_partition(partname, 0, cdev-size,
 + DEVFS_PARTITION_FIXED, env0);
 +}
 +EXPORT_SYMBOL(register_persistent_environment);
 +#endif
 diff --git a/include/environment.h b/include/environment.h
 index 7bdd213..d172f8f 100644
 --- a/include/environment.h
 +++ b/include/environment.h
 @@ -71,6 +71,7 @@ int env_pop_context(void);
  int env_push_context(void);
  
  int export(const char *);
 +int register_persistent_environment(const char *devname, unsigned int 
 partnr);
  
  #endif   /* _ENVIRONMENT_H_ */
  
 -- 
 1.7.11.7
 
 
 ___
 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- |

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


Re: [PATCH 3/5] partitons: add framework

2013-02-14 Thread Sascha Hauer
On Thu, Feb 14, 2013 at 04:52:25PM +0100, Jean-Christophe PLAGNIOL-VILLARD 
wrote:
 so we can support multiple format
 
 use filetpye to detect the parser to use
 
 Cc: Rob Herring rob.herr...@calxeda.com
 Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD plagn...@jcrosoft.com
 ---
  common/Kconfig |   14 +
  common/Makefile|2 +-
  common/partitions.c|  132 
 +++-
  common/partitions/Makefile |1 +
  common/partitions/dos.c|   87 +
  common/partitions/parser.h |   35 

common/partitions/Kconfig is missing in this patch.

 +int partition_parser_register(struct partition_parser *p)
 +{
 + if (!p || !p-parse)
 + return -EINVAL;

Please drop these stupid checks. Everyone calling this with a NULL
pointer really deserves a stack dump.

 +
 +#ifndef __PARTITIONS_PARSER_H__
 +#define __PARTITIONS_PARSER_H__
 +
 +#include block.h
 +#include filetype.h
 +#include linux/list.h
 +
 +#define MAX_PARTITION8
 +
 +struct partition {
 + uint64_t first_sec;
 + uint64_t size;
 +};
 +
 +struct partition_desc {
 + int used_entries;
 + struct partition parts[MAX_PARTITION];
 +};
 +
 +struct partition_parser {
 + void (*parse)(uint8_t *buf, struct block_device *blk, struct 
 partition_desc *pd);

use void * for passing buffers 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: [PATCH 2/4] fs: add pread and pwrite functions

2013-02-14 Thread Sascha Hauer
On Thu, Feb 14, 2013 at 02:08:29PM +0100, Alexander Aring wrote:
 Add pread and pwrite functions.
 
 These functions setting file pointer to a given
 offset with lseek and call read or write afterwards.
 
 Signed-off-by: Alexander Aring alex.ar...@gmail.com
 ---
  fs/fs.c  | 28 
  include/fs.h |  2 ++
  2 files changed, 30 insertions(+)
 
 diff --git a/fs/fs.c b/fs/fs.c
 index 48d1c89..fea7e02 100644
 --- a/fs/fs.c
 +++ b/fs/fs.c
 @@ -785,6 +785,20 @@ ssize_t read(int fd, void *buf, size_t count)
  }
  EXPORT_SYMBOL(read);
  
 +ssize_t pread(int fd, void *buf, size_t count, loff_t offset)
 +{
 + int ret;
 +
 + ret = lseek(fd, offset, SEEK_SET);
 + if (ret  0)
 + goto out;
 +
 + ret = read(fd, buf, count);
 +out:
 + return ret;
 +}

The man page says that the file offset is not modified by pread/pwrite.
If we add a standard function with a standard prototype I think it
should have the same behaviour.
Maybe this can be implemented similar to the current read() function
is implemented. read() could then call pread() internally and advances
the file offset afterwards.

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 4/5] disk: introduce partition name

2013-02-14 Thread Jean-Christophe PLAGNIOL-VILLARD
On 21:51 Thu 14 Feb , Sascha Hauer wrote:
 On Thu, Feb 14, 2013 at 04:52:26PM +0100, Jean-Christophe PLAGNIOL-VILLARD 
 wrote:
  so we can register partion with name as present in EFI GPT
  
  Cc: Rob Herring rob.herr...@calxeda.com
  Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD plagn...@jcrosoft.com
  ---
   common/partitions.c|   51 
  ++--
   common/partitions/parser.h |2 ++
   2 files changed, 42 insertions(+), 11 deletions(-)
  
  diff --git a/common/partitions.c b/common/partitions.c
  index 7cb8399..51a0fc2 100644
  --- a/common/partitions.c
  +++ b/common/partitions.c
  @@ -44,15 +44,42 @@ LIST_HEAD(partition_parser_list);
   static int register_one_partition(struct block_device *blk,
  struct partition *part, int no)
   {
  -   char partition_name[19];
  +   char *partition_name;
  +   int ret;
  +   uint64_t start = part-first_sec * SECTOR_SIZE;
  +   uint64_t size = part-size * SECTOR_SIZE;
  +
  +   partition_name = asprintf(%s.%d, blk-cdev.name, no);
  +   if (!partition_name)
  +   return -ENOMEM;
  +   dev_dbg(blk-dev, Registering partition %s on drive %s\n,
  +   partition_name, blk-cdev.name);
  +   ret = devfs_add_partition(blk-cdev.name,
  +   start, size, 0, partition_name);
  +   if (ret)
  +   goto out;
  +
  +   free(partition_name);
  +   partition_name = asprintf(%s.%s, blk-cdev.name, part-name);
  +   if (!partition_name) {
  +   dev_warn(blk-dev, Registering partition %s on drive %s 
  failled\n,
  +   part-name, blk-cdev.name);
 
 You are in -ENOMEM here, not in partitiion register fai*l*ed.
 
  +   return 0;
  +   }
   
  -   sprintf(partition_name, %s.%d, blk-cdev.name, no);
  dev_dbg(blk-dev, Registering partition %s on drive %s\n,
  partition_name, blk-cdev.name);
  -   return devfs_add_partition(blk-cdev.name,
  -   part-first_sec * SECTOR_SIZE,
  -   part-size * SECTOR_SIZE,
  -   0, partition_name);
  +   ret = devfs_add_partition(blk-cdev.name,
  +   start, size, 0, partition_name);
  +
  +   if (ret)
  +   dev_warn(blk-dev, Registering partition %s on drive %s 
  failled\n,
  +   partition_name, blk-cdev.name);
  +
  +   ret = 0;
  +out:
  +   free(partition_name);
  +   return 0;
   }
   
   static struct partition_parser *partition_parser_get_by_filetype(uint8_t 
  *buf)
  @@ -79,12 +106,13 @@ static struct partition_parser 
  *partition_parser_get_by_filetype(uint8_t *buf)
*/
   int parse_partition_table(struct block_device *blk)
 
 The changes to this function seem unrelated to the topic of this patch.
 
   {
  -   struct partition_desc pdesc = { .used_entries = 0, };
  +   struct partition_desc *pdesc;
  int i;
  int rc = 0;
  struct partition_parser *parser;
  uint8_t *buf;
   
  +   pdesc = xzalloc(sizeof(*pdesc));
  buf = dma_alloc(SECTOR_SIZE * 2);
   
  rc = blk-ops-read(blk, buf, 0, 2);
  @@ -97,14 +125,14 @@ int parse_partition_table(struct block_device *blk)
  if (!parser)
  goto on_error;
   
  -   parser-parse(buf, blk, pdesc);
  +   parser-parse(buf, blk, pdesc);
   
  -   if (!pdesc.used_entries)
  +   if (!pdesc-used_entries)
  return 0;
 
 You lose memory here.
 
   
  /* at least one partition description found */
  -   for (i = 0; i  pdesc.used_entries; i++) {
  -   rc = register_one_partition(blk, pdesc.parts[i], i);
  +   for (i = 0; i  pdesc-used_entries; i++) {
  +   rc = register_one_partition(blk, pdesc-parts[i], i);
  if (rc != 0)
  dev_err(blk-dev,
  Failed to register partition %d on %s (%d)\n,
  @@ -115,6 +143,7 @@ int parse_partition_table(struct block_device *blk)
   
   on_error:
  dma_free(buf);
  +   free(pdesc);
  return rc;
   }
   
  diff --git a/common/partitions/parser.h b/common/partitions/parser.h
  index 61b1cf5..083c143 100644
  --- a/common/partitions/parser.h
  +++ b/common/partitions/parser.h
  @@ -12,8 +12,10 @@
   #include linux/list.h
   
   #define MAX_PARTITION  8
  +#define MAX_PARTITION_NAME 38
   
   struct partition {
  +   char name[MAX_PARTITION_NAME];
 
 is this used?
yes by efi

in GPT you have a partname so you will have this

 ` ffe08000.sata
  ` 0x-0x3fff: /dev/ata0
  ` 0x0010-0x063f: /dev/ata0.0
  ` 0x0010-0x063f: /dev/ata0.boot
  ` 0x0640-0x3fef: /dev/ata0.1
  ` 0x0640-0x3fef: /dev/ata0.root

so you do not care where is the boot partition just that the partition exist

and just mount root as rootfs

Best Regards,
J.
 
 Sascha
 
 -- 
 Pengutronix e.K.   | 

[PATCH 0/5] add EFI GUID Partition Table support

2013-02-14 Thread Jean-Christophe PLAGNIOL-VILLARD
HI,

v2:
 fix memory leak
 filetype: full check
 part name: comment
 efi: make gpt primary and alternate check optional

this add the support of the EFI GPT and named partition

The following changes since commit a40e76cebcbe8b025bafdefdc6e27b7553209ed7:

  Add warning above get_ram_size (2013-02-13 18:14:38 +0100)

are available in the git repository at:

  git://git.jcrosoft.org/barebox.git delivery/efi_gpt

for you to fetch changes up to 7825a076660b34dd08e4041f820fcbeb6a301e67:

  disk: partitions: add EFI GUID Partition Table (2013-02-14 05:59:31 +0800)


Jean-Christophe PLAGNIOL-VILLARD (5):
  linux/types: import __aligned_x64 from the kernel
  filetype: add GPT support
  partitons: add framework
  disk: introduce partition name
  disk: partitions: add EFI GUID Partition Table

 common/Kconfig |   14 +--
 common/Makefile|2 +-
 common/filetype.c  |   47 +
 common/partitions.c|  179 
+--
 common/partitions/Kconfig  |   32 +++
 common/partitions/Makefile |2 +
 common/partitions/dos.c|   88 +++
 common/partitions/efi.c|  477 
++
 common/partitions/efi.h|  123 
++
 common/partitions/parser.h |   37 +
 include/filetype.h |1 +
 include/linux/efi.h|  547 
+
 include/linux/types.h  |   13 ++
 13 files changed, 1452 insertions(+), 110 deletions(-)
 create mode 100644 common/partitions/Kconfig
 create mode 100644 common/partitions/Makefile
 create mode 100644 common/partitions/dos.c
 create mode 100644 common/partitions/efi.c
 create mode 100644 common/partitions/efi.h
 create mode 100644 common/partitions/parser.h
 create mode 100644 include/linux/efi.h

Best Regards,
J.

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


[PATCH 4/5] disk: introduce partition name

2013-02-14 Thread Jean-Christophe PLAGNIOL-VILLARD
so we can register partion with name as present in EFI GPT

Cc: Rob Herring rob.herr...@calxeda.com
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD plagn...@jcrosoft.com
---
 common/partitions.c|   54 ++--
 common/partitions/parser.h |2 ++
 2 files changed, 44 insertions(+), 12 deletions(-)

diff --git a/common/partitions.c b/common/partitions.c
index 9ab06d3..86b0f66 100644
--- a/common/partitions.c
+++ b/common/partitions.c
@@ -44,15 +44,43 @@ LIST_HEAD(partition_parser_list);
 static int register_one_partition(struct block_device *blk,
struct partition *part, int no)
 {
-   char partition_name[19];
+   char *partition_name;
+   int ret;
+   uint64_t start = part-first_sec * SECTOR_SIZE;
+   uint64_t size = part-size * SECTOR_SIZE;
+
+   partition_name = asprintf(%s.%d, blk-cdev.name, no);
+   if (!partition_name)
+   return -ENOMEM;
+   dev_dbg(blk-dev, Registering partition %s on drive %s\n,
+   partition_name, blk-cdev.name);
+   ret = devfs_add_partition(blk-cdev.name,
+   start, size, 0, partition_name);
+   if (ret)
+   goto out;
+
+   free(partition_name);
+
+   if (!part-name[0])
+   return 0;
+
+   partition_name = asprintf(%s.%s, blk-cdev.name, part-name);
+   if (!partition_name)
+   return -ENOMEM;
 
-   sprintf(partition_name, %s.%d, blk-cdev.name, no);
dev_dbg(blk-dev, Registering partition %s on drive %s\n,
partition_name, blk-cdev.name);
-   return devfs_add_partition(blk-cdev.name,
-   part-first_sec * SECTOR_SIZE,
-   part-size * SECTOR_SIZE,
-   0, partition_name);
+   ret = devfs_add_partition(blk-cdev.name,
+   start, size, 0, partition_name);
+
+   if (ret)
+   dev_warn(blk-dev, Registering partition %s on drive %s 
failled\n,
+   partition_name, blk-cdev.name);
+
+   ret = 0;
+out:
+   free(partition_name);
+   return 0;
 }
 
 static struct partition_parser *partition_parser_get_by_filetype(uint8_t *buf)
@@ -79,12 +107,13 @@ static struct partition_parser 
*partition_parser_get_by_filetype(uint8_t *buf)
  */
 int parse_partition_table(struct block_device *blk)
 {
-   struct partition_desc pdesc = { .used_entries = 0, };
+   struct partition_desc *pdesc;
int i;
int rc = 0;
struct partition_parser *parser;
uint8_t *buf;
 
+   pdesc = xzalloc(sizeof(*pdesc));
buf = dma_alloc(SECTOR_SIZE * 2);
 
rc = blk-ops-read(blk, buf, 0, 2);
@@ -97,14 +126,14 @@ int parse_partition_table(struct block_device *blk)
if (!parser)
goto on_error;
 
-   parser-parse(buf, blk, pdesc);
+   parser-parse(buf, blk, pdesc);
 
-   if (!pdesc.used_entries)
-   return 0;
+   if (!pdesc-used_entries)
+   goto on_error;
 
/* at least one partition description found */
-   for (i = 0; i  pdesc.used_entries; i++) {
-   rc = register_one_partition(blk, pdesc.parts[i], i);
+   for (i = 0; i  pdesc-used_entries; i++) {
+   rc = register_one_partition(blk, pdesc-parts[i], i);
if (rc != 0)
dev_err(blk-dev,
Failed to register partition %d on %s (%d)\n,
@@ -115,6 +144,7 @@ int parse_partition_table(struct block_device *blk)
 
 on_error:
dma_free(buf);
+   free(pdesc);
return rc;
 }
 
diff --git a/common/partitions/parser.h b/common/partitions/parser.h
index 13506c0..f5bdbd1 100644
--- a/common/partitions/parser.h
+++ b/common/partitions/parser.h
@@ -12,8 +12,10 @@
 #include linux/list.h
 
 #define MAX_PARTITION  8
+#define MAX_PARTITION_NAME 38
 
 struct partition {
+   char name[MAX_PARTITION_NAME];
uint64_t first_sec;
uint64_t size;
 };
-- 
1.7.10.4


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


[PATCH 2/5] filetype: add GPT support

2013-02-14 Thread Jean-Christophe PLAGNIOL-VILLARD
GPT need to be check before MBR

Cc: Rob Herring rob.herr...@calxeda.com
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD plagn...@jcrosoft.com
---
 common/filetype.c  |   47 +++
 include/filetype.h |1 +
 2 files changed, 48 insertions(+)

diff --git a/common/filetype.c b/common/filetype.c
index 22fc621..a685ea5 100644
--- a/common/filetype.c
+++ b/common/filetype.c
@@ -48,6 +48,7 @@ static const struct filetype_str filetype_str[] = {
[filetype_bmp] = { BMP image, bmp },
[filetype_png] = { PNG image, png },
[filetype_ext] = { ext filesystem, ext },
+   [filetype_gpt] = { GUID Partition Table, gpt },
 };
 
 const char *file_type_to_string(enum filetype f)
@@ -69,9 +70,52 @@ const char *file_type_to_short_string(enum filetype f)
 #define MBR_StartSector8   /* MBR: Offset of Starting 
Sector in Partition Table Entry */
 #define BS_55AA510 /* Boot sector signature (2) */
 #define MBR_Table  446 /* MBR: Partition table offset (2) */
+#define MBR_partition_size 16  /* MBR: Partition table offset (2) */
 #define BS_FilSysType3282  /* File system type (1) */
 #define BS_FilSysType  54  /* File system type (1) */
 
+#define MBR_PART_sys_ind   4
+#define MBR_PART_start_sect8
+#define MBR_OSTYPE_EFI_GPT 0xee
+
+static inline int pmbr_part_valid(const uint8_t *buf)
+{
+   if (buf[MBR_PART_sys_ind] == MBR_OSTYPE_EFI_GPT 
+   get_unaligned_le32(buf[MBR_PART_start_sect]) == 1UL) {
+   return 1;
+   }
+
+   return 0;
+}
+
+/**
+ * is_pmbr_valid(): test Protective MBR for validity
+ * @mbr: pointer to a legacy mbr structure
+ *
+ * Description: Returns 1 if PMBR is valid, 0 otherwise.
+ * Validity depends on two things:
+ *  1) MSDOS signature is in the last two bytes of the MBR
+ *  2) One partition of type 0xEE is found
+ */
+static int is_gpt_valid(const uint8_t *buf)
+{
+   int i;
+
+   if (get_unaligned_le16(buf[BS_55AA]) != 0xAA55)
+   return 0;
+
+   if (strncmp(buf[512], EFI PART, 8))
+   return 0;
+
+   buf += MBR_Table;
+
+   for (i = 0; i  4; i++, buf += MBR_partition_size) {
+   if (pmbr_part_valid(buf))
+   return 1;
+   }
+   return 0;
+}
+
 enum filetype is_fat_or_mbr(const unsigned char *sector, unsigned long 
*bootsec)
 {
/*
@@ -159,6 +203,9 @@ enum filetype file_detect_type(const void *_buf, size_t 
bufsize)
if (bufsize  512)
return filetype_unknown;
 
+   if (bufsize = 520  is_gpt_valid(buf8))
+   return filetype_gpt;
+
type = is_fat_or_mbr(buf8, NULL);
if (type != filetype_unknown)
return type;
diff --git a/include/filetype.h b/include/filetype.h
index 4d43757..78ca5d2 100644
--- a/include/filetype.h
+++ b/include/filetype.h
@@ -23,6 +23,7 @@ enum filetype {
filetype_bmp,
filetype_png,
filetype_ext,
+   filetype_gpt,
filetype_max,
 };
 
-- 
1.7.10.4


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


[PATCH 1/5] linux/types: import __aligned_x64 from the kernel

2013-02-14 Thread Jean-Christophe PLAGNIOL-VILLARD
need it by upcoming EFI GPT support

Cc: Rob Herring rob.herr...@calxeda.com
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD plagn...@jcrosoft.com
---
 include/linux/types.h |   13 +
 1 file changed, 13 insertions(+)

diff --git a/include/linux/types.h b/include/linux/types.h
index 76c6b67..14f8315 100644
--- a/include/linux/types.h
+++ b/include/linux/types.h
@@ -142,6 +142,19 @@ typedef __u64 __bitwise __be64;
 typedef __u16 __bitwise __sum16;
 typedef __u32 __bitwise __wsum;
 
+/*
+ * aligned_u64 should be used in defining kernel-userspace ABIs to avoid
+ * common 32/64-bit compat problems.
+ * 64-bit values align to 4-byte boundaries on x86_32 (and possibly other
+ * architectures) and to 8-byte boundaries on 64-bit architectures.  The new
+ * aligned_64 type enforces 8-byte alignment so that structs containing
+ * aligned_64 values have the same alignment on 32-bit and 64-bit 
architectures.
+ * No conversions are necessary between 32-bit user-space and a 64-bit kernel.
+ */
+#define __aligned_u64 __u64 __attribute__((aligned(8)))
+#define __aligned_be64 __be64 __attribute__((aligned(8)))
+#define __aligned_le64 __le64 __attribute__((aligned(8)))
+
 #ifdef CONFIG_PHYS_ADDR_T_64BIT
 typedef u64 phys_addr_t;
 typedef u64 phys_size_t;
-- 
1.7.10.4


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


Re: [PATCH 2/5] filetype: add GPT support

2013-02-14 Thread Johannes Stezenbach
On Thu, Feb 14, 2013 at 11:08:55PM +0100, Jean-Christophe PLAGNIOL-VILLARD 
wrote:
 On 20:17 Thu 14 Feb , Sascha Hauer wrote:
  On Thu, Feb 14, 2013 at 06:05:07PM +0100, Johannes Stezenbach wrote:
   On Thu, Feb 14, 2013 at 05:53:23PM +0100, Jean-Christophe 
   PLAGNIOL-VILLARD wrote:
On 17:36 Thu 14 Feb , Sascha Hauer wrote:
 On Thu, Feb 14, 2013 at 04:52:24PM +0100, Jean-Christophe 
 PLAGNIOL-VILLARD wrote:
  GPT need to be check before MBR
...
  +   if (bufsize = 520  strncmp(buf8[512], EFI PART, 8) == 0)
  +   return filetype_gpt;
  +
 
 The list is sorted by size, so please move this below:
on purpose

EFI need to be detect before mbr
   
   IMHO the check is too simple, it will give false positive if
   GPT is replaced by DOS MBR and not zeroed out.  Need to check
   for protective MBR.
  
  So is_fat_or_mbr() should test if the MBR is a protective MBR and return
  false in this case?
 
 no as the efi is more I do the check in efi.c protective bit and right type
 
 I move the code to filetype
 
 but efi need to be before MBR as you could have both for retro compatibility

Yes, Wikipedia says Apple Bootcamp creates hybrid MBR.
But if you run fdisk to create DOS MBR it will only
replace the first sector and leave the GPT alone.
Thus I think for usability it is important to check MBR
(for 0xAA55 marker and one of the part types must be 0xee).

Johannes

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


Re: [PATCH 2/5] filetype: add GPT support

2013-02-14 Thread Johannes Stezenbach
On Thu, Feb 14, 2013 at 11:44:30PM +0100, Jean-Christophe PLAGNIOL-VILLARD 
wrote:
 +#define MBR_OSTYPE_EFI_GPT   0xee
 +
 +static inline int pmbr_part_valid(const uint8_t *buf)
 +{
 + if (buf[MBR_PART_sys_ind] == MBR_OSTYPE_EFI_GPT 
 + get_unaligned_le32(buf[MBR_PART_start_sect]) == 1UL) {
 + return 1;
 + }
 +
 + return 0;
 +}
 +
 +/**
 + * is_pmbr_valid(): test Protective MBR for validity
 + * @mbr: pointer to a legacy mbr structure
 + *
 + * Description: Returns 1 if PMBR is valid, 0 otherwise.
 + * Validity depends on two things:
 + *  1) MSDOS signature is in the last two bytes of the MBR
 + *  2) One partition of type 0xEE is found
 + */
 +static int is_gpt_valid(const uint8_t *buf)
 +{
 + int i;
 +
 + if (get_unaligned_le16(buf[BS_55AA]) != 0xAA55)
 + return 0;
 +
 + if (strncmp(buf[512], EFI PART, 8))
 + return 0;
 +
 + buf += MBR_Table;
 +
 + for (i = 0; i  4; i++, buf += MBR_partition_size) {
 + if (pmbr_part_valid(buf))
 + return 1;
 + }
 + return 0;
 +}


ACK, this is what I meant.

Thanks,
Johannes

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