[U-Boot] [PATCH] ARM64: zynqmp: Wire up both USBs available on ZynqMP

2016-08-14 Thread Michal Simek
The second USB wasn't enabled. This patch fixes it.

Signed-off-by: Michal Simek 
---

 board/xilinx/zynqmp/zynqmp.c| 20 ++--
 include/configs/xilinx_zynqmp.h |  2 +-
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/board/xilinx/zynqmp/zynqmp.c b/board/xilinx/zynqmp/zynqmp.c
index 0c5d9979316f..7b4b5ffd89f4 100644
--- a/board/xilinx/zynqmp/zynqmp.c
+++ b/board/xilinx/zynqmp/zynqmp.c
@@ -283,13 +283,20 @@ int checkboard(void)
 }
 
 #ifdef CONFIG_USB_DWC3
-static struct dwc3_device dwc3_device_data = {
+static struct dwc3_device dwc3_device_data0 = {
.maximum_speed = USB_SPEED_HIGH,
.base = ZYNQMP_USB0_XHCI_BASEADDR,
.dr_mode = USB_DR_MODE_PERIPHERAL,
.index = 0,
 };
 
+static struct dwc3_device dwc3_device_data1 = {
+   .maximum_speed = USB_SPEED_HIGH,
+   .base = ZYNQMP_USB1_XHCI_BASEADDR,
+   .dr_mode = USB_DR_MODE_PERIPHERAL,
+   .index = 1,
+};
+
 int usb_gadget_handle_interrupts(void)
 {
dwc3_uboot_handle_interrupt(0);
@@ -298,7 +305,16 @@ int usb_gadget_handle_interrupts(void)
 
 int board_usb_init(int index, enum usb_init_type init)
 {
-   return dwc3_uboot_init(&dwc3_device_data);
+   debug("%s: index %x\n", __func__, index);
+
+   switch (index) {
+   case 0:
+   return dwc3_uboot_init(&dwc3_device_data0);
+   case 1:
+   return dwc3_uboot_init(&dwc3_device_data1);
+   };
+
+   return -1;
 }
 
 int board_usb_cleanup(int index, enum usb_init_type init)
diff --git a/include/configs/xilinx_zynqmp.h b/include/configs/xilinx_zynqmp.h
index 78d8bf476872..96b6da8bed4b 100644
--- a/include/configs/xilinx_zynqmp.h
+++ b/include/configs/xilinx_zynqmp.h
@@ -115,7 +115,7 @@
 #define CONFIG_SYS_LOAD_ADDR   0x800
 
 #if defined(CONFIG_ZYNQMP_USB)
-#define CONFIG_USB_MAX_CONTROLLER_COUNT 1
+#define CONFIG_USB_MAX_CONTROLLER_COUNT 2
 #define CONFIG_SYS_USB_XHCI_MAX_ROOT_PORTS  2
 #define CONFIG_USB_XHCI_ZYNQMP
 
-- 
1.9.1

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH] image-fit: fix fit_image_load() OS check

2016-08-14 Thread Michal Simek
On 14.8.2016 20:31, Andreas Bießmann wrote:
> Commit 62afc601883e788f3f22291202d5b2a23c1a8b06 introduced fpga image load via
> bootm but broke the OS check in fit_image_load().
> 
> This commit removes following compiler warning:
> 
> ---8<---
> In file included from tools/common/image-fit.c:1:
> /Volumes/devel/u-boot/tools/../common/image-fit.c:1715:39: warning: use of 
> logical '||' with constant operand [-Wconstant-logical-operand]
> os_ok = image_type == IH_TYPE_FLATDT || IH_TYPE_FPGA ||
>  ^  
> /Volumes/devel/u-boot/tools/../common/image-fit.c:1715:39: note: use '|' for 
> a bitwise operation
> os_ok = image_type == IH_TYPE_FLATDT || IH_TYPE_FPGA ||
>  ^~
>  |
> 1 warning generated.
> --->8---
> 
> Signed-off-by: Andreas Bießmann 
> Cc: Michal Simek 
> ---
>  common/image-fit.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/common/image-fit.c b/common/image-fit.c
> index d8d4e95..f833fe3 100644
> --- a/common/image-fit.c
> +++ b/common/image-fit.c
> @@ -1712,7 +1712,8 @@ int fit_image_load(bootm_headers_t *images, ulong addr,
> (image_type == IH_TYPE_KERNEL &&
>  fit_image_check_type(fit, noffset, IH_TYPE_KERNEL_NOLOAD));
>  
> - os_ok = image_type == IH_TYPE_FLATDT || IH_TYPE_FPGA ||
> + os_ok = image_type == IH_TYPE_FLATDT ||
> + image_type == IH_TYPE_FPGA ||
>   fit_image_check_os(fit, noffset, IH_OS_LINUX) ||
>   fit_image_check_os(fit, noffset, IH_OS_U_BOOT) ||
>   fit_image_check_os(fit, noffset, IH_OS_OPENRTOS);
> 


hm. Interesting. I didn't see that compilation warning.

Acked-by: Michal Simek 

Thanks,
Michal
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] cmd: net: flush cache cacheline aligned

2016-08-14 Thread Stefan Agner
On 2016-08-14 13:06, Tom Rini wrote:
> On Tue, Aug 02, 2016 at 12:20:28AM -0700, Stefan Agner wrote:
> 
>> From: Stefan Agner 
>>
>> Flush loaded data cacheline aligned. This avoids warnings such as
>> CACHE: Misaligned operation at range [8100, 816d0fa8]
>>
>> Signed-off-by: Stefan Agner 
>> Tested-by: Fabio Estevam 
>> Reviewed-by: Simon Glass 
>> ---
>> Why do we actually have to flush caches after load? It seems to
>> have worked so far despite the caches did not get flushed (due to
>> missalignment).
> 
> Joe, would you prefer to just drop this flush, given the rest of the
> thread?  Thanks!


Just found Diana Craciuns (added to CC) commit
99ffccbd3e5b7bc715e2eed6ea6d36f4020b56d8 ("Flush cache after the OS
image is loaded into the memory.") which adds a flush_cache in
cmd_bootm.c:

>--snip
Flush cache after the OS image is loaded into the memory.

Since we are loading an executable image into memory we need flush it
out of the cache to possible maintain coherence on CPUs with split
instruction and data caches.  We do this for other executable image
loading command.

On PowerPC once we do this we no longer need to explicitly flush the
dcache on multi-core systems in the BOOTM_STATE_OS_PREP phase.  We now
treat the BOOTM_STATE_OS_PREP as a no-op to maintain backwards
compatibility with the bootm subcommand.
<--snip

That might be actually the case in this situation too, although I feel
this should be taken care of before kernel entry. At least on ARM,
caches get flushed before jumping to the kernel. Is PowerPC different in
that matter?

--
Stefan
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH v5 1/2] arm: cache: add support for LPAE for region D$ behavior

2016-08-14 Thread Stefan Agner
From: Stefan Agner 

Add LPAE support for mmu_set_region_dcache_behaviour. The function
is in use in some LPAE capable board such TI DRA7xx or NXP i.MX 7.

Signed-off-by: Stefan Agner 

---

Changes in v5:
- Add this LPAE enablement patch

Changes in v4: None
Changes in v3: None
Changes in v2: None

 arch/arm/lib/cache-cp15.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/arch/arm/lib/cache-cp15.c b/arch/arm/lib/cache-cp15.c
index 1121dc3..3aabda1 100644
--- a/arch/arm/lib/cache-cp15.c
+++ b/arch/arm/lib/cache-cp15.c
@@ -61,7 +61,11 @@ __weak void mmu_page_table_flush(unsigned long start, 
unsigned long stop)
 void mmu_set_region_dcache_behaviour(phys_addr_t start, size_t size,
 enum dcache_option option)
 {
+#ifdef CONFIG_ARMV7_LPAE
+   u64 *page_table = (u64 *)gd->arch.tlb_addr;
+#else
u32 *page_table = (u32 *)gd->arch.tlb_addr;
+#endif
unsigned long upto, end;
 
end = ALIGN(start + size, MMU_SECTION_SIZE) >> MMU_SECTION_SHIFT;
-- 
2.9.0

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH v5 2/2] arm: cache: always flush cache line size for page table

2016-08-14 Thread Stefan Agner
From: Stefan Agner 

The page table is maintained by the CPU, hence it is safe to always
align cache flush to a whole cache line size. This allows to use
mmu_page_table_flush for a single page table, e.g. when configure
only small regions through mmu_set_region_dcache_behaviour.

Signed-off-by: Stefan Agner 
Tested-by: Fabio Estevam 
Reviewed-by: Simon Glass 
Reviewed-by: Heiko Schocher 
---

Changes in v5:
- Convert to a type the size of a CPU pointer (unsigned long)
- Rebase on LPAE enablement patch

Changes in v4:
- Fixed spelling misstake for real

Changes in v3:
- Fixed spelling misstake

Changes in v2:
- Move cache line alignment from mmu_page_table_flush to
  mmu_set_region_dcache_behaviour

 arch/arm/lib/cache-cp15.c | 14 +-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/arch/arm/lib/cache-cp15.c b/arch/arm/lib/cache-cp15.c
index 3aabda1..70e94f0 100644
--- a/arch/arm/lib/cache-cp15.c
+++ b/arch/arm/lib/cache-cp15.c
@@ -66,6 +66,7 @@ void mmu_set_region_dcache_behaviour(phys_addr_t start, 
size_t size,
 #else
u32 *page_table = (u32 *)gd->arch.tlb_addr;
 #endif
+   unsigned long startpt, stoppt;
unsigned long upto, end;
 
end = ALIGN(start + size, MMU_SECTION_SIZE) >> MMU_SECTION_SHIFT;
@@ -74,7 +75,18 @@ void mmu_set_region_dcache_behaviour(phys_addr_t start, 
size_t size,
  option);
for (upto = start; upto < end; upto++)
set_section_dcache(upto, option);
-   mmu_page_table_flush((u32)&page_table[start], (u32)&page_table[end]);
+
+   /*
+* Make sure range is cache line aligned
+* Only CPU maintains page tables, hence it is safe to always
+* flush complete cache lines...
+*/
+
+   startpt = (unsigned long)&page_table[start];
+   startpt &= ~(CONFIG_SYS_CACHELINE_SIZE - 1);
+   stoppt = (unsigned long)&page_table[end];
+   stoppt = ALIGN(stoppt, CONFIG_SYS_CACHELINE_SIZE);
+   mmu_page_table_flush(startpt, stoppt);
 }
 
 __weak void dram_bank_mmu_setup(int bank)
-- 
2.9.0

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH v4] arm: cache: always flush cache line size for page table

2016-08-14 Thread Stefan Agner
On 2016-08-14 13:01, Tom Rini wrote:
> On Mon, Aug 08, 2016 at 12:43:03AM -0700, Stefan Agner wrote:
>> On 2016-08-07 23:10, Lokesh Vutla wrote:
>> > Hi,
>> >
>> > On Sunday 07 August 2016 11:13 PM, Stefan Agner wrote:
>> >> From: Stefan Agner 
>> >>
>> >> The page table is maintained by the CPU, hence it is safe to always
>> >> align cache flush to a whole cache line size. This allows to use
>> >> mmu_page_table_flush for a single page table, e.g. when configure
>> >> only small regions through mmu_set_region_dcache_behaviour.
>> >>
>> >> Signed-off-by: Stefan Agner 
>> >> Tested-by: Fabio Estevam 
>> >> Reviewed-by: Simon Glass 
>> >> ---
>> >
>> > I get the following warning when CONFIG_PHYS_64BIT is enabled on arm
>> > platforms(dra7xx_evm_defconfig):
>>
>> Hm, do I see things right, this is otherwise a 32-bit architecture? Does
>> that work without LPAE? What is the page table size in this case?
> 
> It's a 32bit architecture with LPAE, iirc, yes.

Hm, when looking at other functions such as set_section_dcache,
page_table is casted to a u64* type, hence I guess this is wrong in
mmu_set_region_dcache_behaviour. In fact, that makes it seem unsafe to
use this function as is...

--
Stefan
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] A64 fastboot, faster way to compile/test

2016-08-14 Thread Sergey Kubushyn

On Sun, 14 Aug 2016, jonsm...@gmail.com wrote:


I'm trying out various versions of the A64 u-boot -- Allwinner lichee,
longsleep, apritzel, etc on the Pine64. I can get all of them up to
the prompt, but fastboot doesn't work in an of them. There is code
from Allwinner in there for implementing fastboot, but so far I've had
no luck getting it to do anything. I added a bunch of debug and the
USB controller does not appear to be generating interrupts.

Has anyone worked with A64 fastboot? Any tips on what might be wrong?

I want a faster was to update the SD Card without physically moving it
between machines.


Use ums. Works like a charm. As of fastboot it is Android weirdo and its
support in U-Boot is rudimentary. Dunno why it is in the source tree at
all -- if it was me I would've removed it altogether...

---
**
*  KSI@homeKOI8 Net  < >  The impossible we do immediately.  *
*  Las Vegas   NV, USA   < >  Miracles require 24-hour notice.   *
**
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] A64 fastboot, faster way to compile/test

2016-08-14 Thread jonsm...@gmail.com
I'm trying out various versions of the A64 u-boot -- Allwinner lichee,
longsleep, apritzel, etc on the Pine64. I can get all of them up to
the prompt, but fastboot doesn't work in an of them. There is code
from Allwinner in there for implementing fastboot, but so far I've had
no luck getting it to do anything. I added a bunch of debug and the
USB controller does not appear to be generating interrupts.

Has anyone worked with A64 fastboot? Any tips on what might be wrong?

I want a faster was to update the SD Card without physically moving it
between machines.

-- 
Jon Smirl
jonsm...@gmail.com
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH 2/3] net: davinci_emac: Round up top buffer boundaries for dcache ops

2016-08-14 Thread Tom Rini
On Sun, Aug 14, 2016 at 07:43:56PM +, Karl Beldan wrote:
> On Sun, Aug 14, 2016 at 11:47:25AM -0400, Tom Rini wrote:
> > On Sun, Aug 14, 2016 at 03:03:16PM +, Karl Beldan wrote:
> > 
> > > check_cache_range() warns that the top boundaries are not properly
> > > aligned while flushing and invalidating the buffers and make these
> > > operations to fail.
> > > ATM the RX bottom boundaries are aligned by design with EMAC_RXBUF_SIZE,
> > > properly aligned with ARCH_DMA_MINALIGN, however the top ones are not.
> > > 
> > > This gets rid of the warnings:
> > > CACHE: Misaligned operation at range
> > > 
> > > Signed-off-by: Karl Beldan 
> > > ---
> > >  drivers/net/davinci_emac.c | 6 --
> > >  1 file changed, 4 insertions(+), 2 deletions(-)
> > > 
> > > diff --git a/drivers/net/davinci_emac.c b/drivers/net/davinci_emac.c
> > > index 947bfab..55461b0 100644
> > > --- a/drivers/net/davinci_emac.c
> > > +++ b/drivers/net/davinci_emac.c
> > > @@ -632,7 +632,8 @@ static int davinci_eth_send_packet (struct eth_device 
> > > *dev,
> > > EMAC_CPPI_EOP_BIT);
> > >  
> > >   flush_dcache_range((unsigned long)packet,
> > > - (unsigned long)packet + length);
> > > +round_up((unsigned long)packet + length,
> > > + ARCH_DMA_MINALIGN));
> > 
> > It's preferred to use:
> > (unsigned long)packet + ALIGN(length, PKTALIGN)); 
> > here instead of ARCH_DMA_MINALIGN.
> > 
> 
> Hmm, I think your suggestion is buggy.
> The cache primitives act on [laddr, haddr[, i.e. haddr is excluded, IOW
> you are missing the tail of the packet (that's why I rounded up).

Joe, we've got some instances using ALIGN(length, PKTALIGN) and others
using roundup.  And I can't imagine that we shouldn't be using the same
thing everywhere here.  So, what do you say to Karl's comment?  Thanks!

> Conceptually I still prefer ARCH_DMA_MINALIGN, also all other code in
> the base does so.

Being network code, we should use PKTALIGN here and elsewhere.

-- 
Tom


signature.asc
Description: Digital signature
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] cmd: net: flush cache cacheline aligned

2016-08-14 Thread Tom Rini
On Tue, Aug 02, 2016 at 12:20:28AM -0700, Stefan Agner wrote:

> From: Stefan Agner 
> 
> Flush loaded data cacheline aligned. This avoids warnings such as
> CACHE: Misaligned operation at range [8100, 816d0fa8]
> 
> Signed-off-by: Stefan Agner 
> Tested-by: Fabio Estevam 
> Reviewed-by: Simon Glass 
> ---
> Why do we actually have to flush caches after load? It seems to
> have worked so far despite the caches did not get flushed (due to
> missalignment).

Joe, would you prefer to just drop this flush, given the rest of the
thread?  Thanks!

-- 
Tom


signature.asc
Description: Digital signature
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [U-Boot, RFC] vexpress: Check TC2 firmware support before defaulting to nonsec booting

2016-08-14 Thread Tom Rini
On Thu, Jun 23, 2016 at 01:37:32PM +0100, Jon Medhurst (Tixy) wrote:

> The firmware on TC2 needs to be configured appropriately before booting
> in nonsec mode will work as expected, so test for this and fall back to
> sec mode if required.
> 
> Signed-off-by: Jon Medhurst 
> Reviewed-by: Ryan Harkin 
> Tested-by: Ryan Harkin 
> ---
> 
> This is an implementation of Andre's suggestion in
> http://lists.denx.de/pipermail/u-boot/2016-June/258873.html
> 
> Possibly the change to bootm.c should be in a separate patch?
> 
>  arch/arm/lib/bootm.c | 15 ++-
>  board/armltd/vexpress/Makefile   |  1 +
>  board/armltd/vexpress/vexpress_tc2.c | 33 +
>  3 files changed, 44 insertions(+), 5 deletions(-)
>  create mode 100644 board/armltd/vexpress/vexpress_tc2.c

So, this supersedes https://patchwork.ozlabs.org/patch/639232/ right?
Thanks!

-- 
Tom


signature.asc
Description: Digital signature
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH v4] arm: cache: always flush cache line size for page table

2016-08-14 Thread Tom Rini
On Mon, Aug 08, 2016 at 12:43:03AM -0700, Stefan Agner wrote:
> On 2016-08-07 23:10, Lokesh Vutla wrote:
> > Hi,
> > 
> > On Sunday 07 August 2016 11:13 PM, Stefan Agner wrote:
> >> From: Stefan Agner 
> >>
> >> The page table is maintained by the CPU, hence it is safe to always
> >> align cache flush to a whole cache line size. This allows to use
> >> mmu_page_table_flush for a single page table, e.g. when configure
> >> only small regions through mmu_set_region_dcache_behaviour.
> >>
> >> Signed-off-by: Stefan Agner 
> >> Tested-by: Fabio Estevam 
> >> Reviewed-by: Simon Glass 
> >> ---
> > 
> > I get the following warning when CONFIG_PHYS_64BIT is enabled on arm
> > platforms(dra7xx_evm_defconfig):
> 
> Hm, do I see things right, this is otherwise a 32-bit architecture? Does
> that work without LPAE? What is the page table size in this case?

It's a 32bit architecture with LPAE, iirc, yes.

-- 
Tom


signature.asc
Description: Digital signature
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH 2/3] net: davinci_emac: Round up top buffer boundaries for dcache ops

2016-08-14 Thread Karl Beldan
On Sun, Aug 14, 2016 at 11:47:25AM -0400, Tom Rini wrote:
> On Sun, Aug 14, 2016 at 03:03:16PM +, Karl Beldan wrote:
> 
> > check_cache_range() warns that the top boundaries are not properly
> > aligned while flushing and invalidating the buffers and make these
> > operations to fail.
> > ATM the RX bottom boundaries are aligned by design with EMAC_RXBUF_SIZE,
> > properly aligned with ARCH_DMA_MINALIGN, however the top ones are not.
> > 
> > This gets rid of the warnings:
> > CACHE: Misaligned operation at range
> > 
> > Signed-off-by: Karl Beldan 
> > ---
> >  drivers/net/davinci_emac.c | 6 --
> >  1 file changed, 4 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/net/davinci_emac.c b/drivers/net/davinci_emac.c
> > index 947bfab..55461b0 100644
> > --- a/drivers/net/davinci_emac.c
> > +++ b/drivers/net/davinci_emac.c
> > @@ -632,7 +632,8 @@ static int davinci_eth_send_packet (struct eth_device 
> > *dev,
> >   EMAC_CPPI_EOP_BIT);
> >  
> > flush_dcache_range((unsigned long)packet,
> > -   (unsigned long)packet + length);
> > +  round_up((unsigned long)packet + length,
> > +   ARCH_DMA_MINALIGN));
> 
> It's preferred to use:
> (unsigned long)packet + ALIGN(length, PKTALIGN)); 
> here instead of ARCH_DMA_MINALIGN.
> 

Hmm, I think your suggestion is buggy.
The cache primitives act on [laddr, haddr[, i.e. haddr is excluded, IOW
you are missing the tail of the packet (that's why I rounded up).

Conceptually I still prefer ARCH_DMA_MINALIGN, also all other code in
the base does so.

Rgds, 
Karl
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH] tpm: atmel_twi: Make compatible with DM I2C busses

2016-08-14 Thread Andreas Bießmann
On 18.07.16 13:47, Mario Six wrote:
> Commit 302c5db ("dm: tpm: Add Driver Model support for tpm_atmel_twi
> driver") converted the Atmel TWI TPM driver itself to driver model, but
> kept the legacy-style i2c_write/i2c_read calls.
> 
> Commit 3e7d940 ("dm: tpm: Every TPM drivers should depends on DM_TPM")
> then made DM_I2C a dependency of the driver, effectively forcing users
> to turn on CONFIG_DM_I2C_COMPAT to get it to work.
> 
> This patch adds the necessary dm_i2c_write/dm_i2c_read calls to make the
> driver compatible with DM, but also keeps the legacy calls in ifdefs, so
> that the driver is now compatible with both DM and non-DM setups.
> 
> Signed-off-by: Mario Six 

Reviewed-by: Andreas Bießmann 
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH] image-fit: fix fit_image_load() OS check

2016-08-14 Thread Andreas Bießmann
Commit 62afc601883e788f3f22291202d5b2a23c1a8b06 introduced fpga image load via
bootm but broke the OS check in fit_image_load().

This commit removes following compiler warning:

---8<---
In file included from tools/common/image-fit.c:1:
/Volumes/devel/u-boot/tools/../common/image-fit.c:1715:39: warning: use of 
logical '||' with constant operand [-Wconstant-logical-operand]
os_ok = image_type == IH_TYPE_FLATDT || IH_TYPE_FPGA ||
 ^  
/Volumes/devel/u-boot/tools/../common/image-fit.c:1715:39: note: use '|' for a 
bitwise operation
os_ok = image_type == IH_TYPE_FLATDT || IH_TYPE_FPGA ||
 ^~
 |
1 warning generated.
--->8---

Signed-off-by: Andreas Bießmann 
Cc: Michal Simek 
---
 common/image-fit.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/common/image-fit.c b/common/image-fit.c
index d8d4e95..f833fe3 100644
--- a/common/image-fit.c
+++ b/common/image-fit.c
@@ -1712,7 +1712,8 @@ int fit_image_load(bootm_headers_t *images, ulong addr,
  (image_type == IH_TYPE_KERNEL &&
   fit_image_check_type(fit, noffset, IH_TYPE_KERNEL_NOLOAD));
 
-   os_ok = image_type == IH_TYPE_FLATDT || IH_TYPE_FPGA ||
+   os_ok = image_type == IH_TYPE_FLATDT ||
+   image_type == IH_TYPE_FPGA ||
fit_image_check_os(fit, noffset, IH_OS_LINUX) ||
fit_image_check_os(fit, noffset, IH_OS_U_BOOT) ||
fit_image_check_os(fit, noffset, IH_OS_OPENRTOS);
-- 
2.7.4 (Apple Git-66)

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH 1/3 v2] ext4: fix possible crash on directory traversal, ignore deleted entries

2016-08-14 Thread Stefan Brüns
The following command triggers a segfault in search_dir:
./sandbox/u-boot -c 'host bind 0 ./sandbox/test/fs/3GB.ext4.img ;
ext4write host 0 0 /./foo 0x10'

The following command triggers a segfault in check_filename:
./sandbox/u-boot -c 'host bind 0 ./sandbox/test/fs/3GB.ext4.img ;
ext4write host 0 0 /. 0x10'

"." is the first entry in the directory, thus previous_dir is NULL. The
whole previous_dir block in search_dir seems to be a bad copy from
check_filename(...). As the changed data is not written to disk, the
statement is mostly harmless, save the possible NULL-ptr reference.

Typically a file is unlinked by extending the direntlen of the previous
entry. If the entry is the first entry in the directory block, it is
invalidated by setting inode=0.

The inode==0 case is hard to trigger without crafted filesystems. It only
hits if the first entry in a directory block is deleted and later a lookup
for the entry (by name) is done.

Signed-off-by: Stefan Brüns 
---
v2: Fix bad filename compare on delete, used substring only

 fs/ext4/ext4_common.c | 58 +++
 fs/ext4/ext4_write.c  |  2 +-
 include/ext4fs.h  |  2 +-
 3 files changed, 23 insertions(+), 39 deletions(-)

diff --git a/fs/ext4/ext4_common.c b/fs/ext4/ext4_common.c
index b00b84f..3ecd9a8 100644
--- a/fs/ext4/ext4_common.c
+++ b/fs/ext4/ext4_common.c
@@ -511,16 +511,14 @@ fail:
 static int search_dir(struct ext2_inode *parent_inode, char *dirname)
 {
int status;
-   int inodeno;
+   int inodeno = 0;
int totalbytes;
int templength;
int direct_blk_idx;
long int blknr;
-   int found = 0;
char *ptr = NULL;
unsigned char *block_buffer = NULL;
struct ext2_dirent *dir = NULL;
-   struct ext2_dirent *previous_dir = NULL;
struct ext_filesystem *fs = get_fs();
 
/* read the block no allocated to a file */
@@ -530,7 +528,7 @@ static int search_dir(struct ext2_inode *parent_inode, char 
*dirname)
if (blknr == 0)
goto fail;
 
-   /* read the blocks of parenet inode */
+   /* read the blocks of parent inode */
block_buffer = zalloc(fs->blksz);
if (!block_buffer)
goto fail;
@@ -550,15 +548,9 @@ static int search_dir(struct ext2_inode *parent_inode, 
char *dirname)
 * space in the block that means
 * it is a last entry of directory entry
 */
-   if (strlen(dirname) == dir->namelen) {
+   if (dir->inode && (strlen(dirname) == dir->namelen)) {
if (strncmp(dirname, ptr + sizeof(struct 
ext2_dirent), dir->namelen) == 0) {
-   uint16_t new_len;
-   new_len = 
le16_to_cpu(previous_dir->direntlen);
-   new_len += le16_to_cpu(dir->direntlen);
-   previous_dir->direntlen = 
cpu_to_le16(new_len);
inodeno = le32_to_cpu(dir->inode);
-   dir->inode = 0;
-   found = 1;
break;
}
}
@@ -569,19 +561,15 @@ static int search_dir(struct ext2_inode *parent_inode, 
char *dirname)
/* traversing the each directory entry */
templength = le16_to_cpu(dir->direntlen);
totalbytes = totalbytes + templength;
-   previous_dir = dir;
dir = (struct ext2_dirent *)((char *)dir + templength);
ptr = (char *)dir;
}
 
-   if (found == 1) {
-   free(block_buffer);
-   block_buffer = NULL;
-   return inodeno;
-   }
-
free(block_buffer);
block_buffer = NULL;
+
+   if (inodeno > 0)
+   return inodeno;
}
 
 fail:
@@ -757,15 +745,13 @@ fail:
return result_inode_no;
 }
 
-static int check_filename(char *filename, unsigned int blknr)
+static int unlink_filename(char *filename, unsigned int blknr)
 {
-   unsigned int first_block_no_of_root;
int totalbytes = 0;
int templength = 0;
int status, inodeno;
int found = 0;
char *root_first_block_buffer = NULL;
-   char *root_first_block_addr = NULL;
struct ext2_dirent *dir = NULL;
struct ext2_dirent *previous_dir = NULL;
char *ptr = NULL;
@@ -773,18 +759,15 @@ static int check_filename(char *filename, unsigned int 
blknr)
int ret = -1;
 
/* get the first block of root */
-   first_block_no_of_root = blknr;
 

[U-Boot] [PATCH 3/3] ext4: Do not crash when trying to grow a directory using extents

2016-08-14 Thread Stefan Brüns
The following command crashes u-boot:
./sandbox/u-boot -c 'i=0; host bind 0 ./sandbox/test/fs/3GB.ext4.img ;
  while test $i -lt 200 ; do echo $i; setexpr i $i + 1;
  ext4write host 0 0 /foobar${i} 0; done'

Previously, the code updated the direct_block even for extents, and
fortunately crashed before pushing garbage to the disk.

Signed-off-by: Stefan Brüns 
---
 fs/ext4/ext4_common.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/fs/ext4/ext4_common.c b/fs/ext4/ext4_common.c
index b8c37cf..6432104 100644
--- a/fs/ext4/ext4_common.c
+++ b/fs/ext4/ext4_common.c
@@ -431,8 +431,13 @@ restart:
sizeof(struct ext2_dirent) + padding_factor;
if ((fs->blksz - totalbytes - last_entry_dirlen) <
new_entry_byte_reqd) {
-   printf("1st Block Full:Allocate new block\n");
+   printf("Last Block Full:Allocate new block\n");
 
+   if (le32_to_cpu(g_parent_inode->flags) &
+   EXT4_EXTENTS_FL) {
+   printf("Directory uses extents\n");
+   goto fail;
+   }
if (direct_blk_idx == INDIRECT_BLOCKS - 1) {
printf("Directory exceeds limit\n");
goto fail;
-- 
2.9.2

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH 2/3] ext4: propagate error if creation of directory entry fails

2016-08-14 Thread Stefan Brüns
In case the dir entry creation failed, ext4fs_write would later overwrite
a random inode, as inodeno was never initialized.

Signed-off-by: Stefan Brüns 
---
 fs/ext4/ext4_common.c | 12 ++--
 fs/ext4/ext4_common.h |  2 +-
 fs/ext4/ext4_write.c  |  4 +++-
 3 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/fs/ext4/ext4_common.c b/fs/ext4/ext4_common.c
index 3ecd9a8..b8c37cf 100644
--- a/fs/ext4/ext4_common.c
+++ b/fs/ext4/ext4_common.c
@@ -344,7 +344,7 @@ static int check_void_in_dentry(struct ext2_dirent *dir, 
char *filename)
return 0;
 }
 
-void ext4fs_update_parent_dentry(char *filename, int *p_ino, int file_type)
+int ext4fs_update_parent_dentry(char *filename, int file_type)
 {
unsigned int *zero_buffer = NULL;
char *root_first_block_buffer = NULL;
@@ -358,7 +358,7 @@ void ext4fs_update_parent_dentry(char *filename, int 
*p_ino, int file_type)
unsigned int last_entry_dirlen;
int sizeof_void_space = 0;
int templength = 0;
-   int inodeno;
+   int inodeno = -1;
int status;
struct ext_filesystem *fs = get_fs();
/* directory entry */
@@ -371,13 +371,13 @@ void ext4fs_update_parent_dentry(char *filename, int 
*p_ino, int file_type)
zero_buffer = zalloc(fs->blksz);
if (!zero_buffer) {
printf("No Memory\n");
-   return;
+   return -1;
}
root_first_block_buffer = zalloc(fs->blksz);
if (!root_first_block_buffer) {
free(zero_buffer);
printf("No Memory\n");
-   return;
+   return -1;
}
 restart:
 
@@ -496,8 +496,6 @@ restart:
temp_dir = temp_dir + sizeof(struct ext2_dirent);
memcpy(temp_dir, filename, strlen(filename));
 
-   *p_ino = inodeno;
-
/* update or write  the 1st block of root inode */
if (ext4fs_put_metadata(root_first_block_buffer,
first_block_no_of_root))
@@ -506,6 +504,8 @@ restart:
 fail:
free(zero_buffer);
free(root_first_block_buffer);
+
+   return inodeno;
 }
 
 static int search_dir(struct ext2_inode *parent_inode, char *dirname)
diff --git a/fs/ext4/ext4_common.h b/fs/ext4/ext4_common.h
index 370a717..cc9d0c5 100644
--- a/fs/ext4/ext4_common.h
+++ b/fs/ext4/ext4_common.h
@@ -61,7 +61,7 @@ int ext4fs_iterate_dir(struct ext2fs_node *dir, char *name,
 uint32_t ext4fs_div_roundup(uint32_t size, uint32_t n);
 uint16_t ext4fs_checksum_update(unsigned int i);
 int ext4fs_get_parent_inode_num(const char *dirname, char *dname, int flags);
-void ext4fs_update_parent_dentry(char *filename, int *p_ino, int file_type);
+int ext4fs_update_parent_dentry(char *filename, int file_type);
 uint32_t ext4fs_get_new_blk_no(void);
 int ext4fs_get_new_inode_no(void);
 void ext4fs_reset_block_bmap(long int blockno, unsigned char *buffer,
diff --git a/fs/ext4/ext4_write.c b/fs/ext4/ext4_write.c
index f5811aa..4235b95 100644
--- a/fs/ext4/ext4_write.c
+++ b/fs/ext4/ext4_write.c
@@ -890,7 +890,9 @@ int ext4fs_write(const char *fname, unsigned char *buffer,
goto fail;
}
 
-   ext4fs_update_parent_dentry(filename, &inodeno, FILETYPE_REG);
+   inodeno = ext4fs_update_parent_dentry(filename, FILETYPE_REG);
+   if (inodeno == -1)
+   goto fail;
/* prepare file inode */
inode_buffer = zalloc(fs->inodesz);
if (!inode_buffer)
-- 
2.9.2

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] CACHE: Misaligned operation

2016-08-14 Thread Clemens Gruber
Hi,

On Fri, Aug 12, 2016 at 09:27:29AM -0600, Simon Glass wrote:
> Yes it means there is an error in the calling code. If you can figure
> out who is calling this then it is worth fixing. But also see recent
> discussions on the mailing list. Also possibly this patch?
> 
> http://patchwork.ozlabs.org/patch/656474/

Thank you! Yes, this patch seems to fix the error. At least I can see no
more warnings at boot.
Will look into it more thoroughly next week and report back if there is
still a problem.

Regards,
Clemens
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH 0/3] Fix several possible crashes/corruptions in ext4

2016-08-14 Thread Stefan Brüns
The U-Boot ext4 support has some bugs which either cause U-Boot crashes
or lead to filesystem corruption.

This series goes on top of the endian patch series by Michael Walle.

The first patch has been sent earlier but contained a bug.

Stefan Brüns (3):
  ext4: fix possible crash on directory traversal, ignore deleted
entries
  ext4: propagate error if creation of directory entry fails
  ext4: Do not crash when trying to grow a directory using extents

 fs/ext4/ext4_common.c | 77 ++-
 fs/ext4/ext4_common.h |  2 +-
 fs/ext4/ext4_write.c  |  6 ++--
 include/ext4fs.h  |  2 +-
 4 files changed, 39 insertions(+), 48 deletions(-)

-- 
2.9.2

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH] ext4: fix possible crash on directory traversal, ignore deleted entries

2016-08-14 Thread Stefan Brüns
The following command triggers a segfault in search_dir:
./sandbox/u-boot -c 'host bind 0 ./sandbox/test/fs/3GB.ext4.img ;
ext4write host 0 0 /./foo 0x10'

The following command triggers a segfault in check_filename:
./sandbox/u-boot -c 'host bind 0 ./sandbox/test/fs/3GB.ext4.img ;
ext4write host 0 0 /. 0x10'

"." is the first entry in the directory, thus previous_dir is NULL. The
whole previous_dir block in search_dir seems to be a bad copy from
check_filename(...). As the changed data is not written to disk, the
statement is mostly harmless, save the possible NULL-ptr reference.

Typically a file is unlinked by extending the direntlen of the previous
entry. If the entry is the first entry in the directory block, it is
invalidated by setting inode=0.

The inode==0 case is hard to trigger without crafted filesystems. It only
hits if the first entry in a directory block is deleted and later a lookup
for the entry (by name) is done.

Signed-off-by: Stefan Brüns 
---
 fs/ext4/ext4_common.c | 57 ++-
 fs/ext4/ext4_write.c  |  2 +-
 include/ext4fs.h  |  2 +-
 3 files changed, 22 insertions(+), 39 deletions(-)

diff --git a/fs/ext4/ext4_common.c b/fs/ext4/ext4_common.c
index b00b84f..16c5f53 100644
--- a/fs/ext4/ext4_common.c
+++ b/fs/ext4/ext4_common.c
@@ -511,16 +511,14 @@ fail:
 static int search_dir(struct ext2_inode *parent_inode, char *dirname)
 {
int status;
-   int inodeno;
+   int inodeno = 0;
int totalbytes;
int templength;
int direct_blk_idx;
long int blknr;
-   int found = 0;
char *ptr = NULL;
unsigned char *block_buffer = NULL;
struct ext2_dirent *dir = NULL;
-   struct ext2_dirent *previous_dir = NULL;
struct ext_filesystem *fs = get_fs();
 
/* read the block no allocated to a file */
@@ -530,7 +528,7 @@ static int search_dir(struct ext2_inode *parent_inode, char 
*dirname)
if (blknr == 0)
goto fail;
 
-   /* read the blocks of parenet inode */
+   /* read the blocks of parent inode */
block_buffer = zalloc(fs->blksz);
if (!block_buffer)
goto fail;
@@ -550,15 +548,9 @@ static int search_dir(struct ext2_inode *parent_inode, 
char *dirname)
 * space in the block that means
 * it is a last entry of directory entry
 */
-   if (strlen(dirname) == dir->namelen) {
+   if (dir->inode && (strlen(dirname) == dir->namelen)) {
if (strncmp(dirname, ptr + sizeof(struct 
ext2_dirent), dir->namelen) == 0) {
-   uint16_t new_len;
-   new_len = 
le16_to_cpu(previous_dir->direntlen);
-   new_len += le16_to_cpu(dir->direntlen);
-   previous_dir->direntlen = 
cpu_to_le16(new_len);
inodeno = le32_to_cpu(dir->inode);
-   dir->inode = 0;
-   found = 1;
break;
}
}
@@ -569,19 +561,15 @@ static int search_dir(struct ext2_inode *parent_inode, 
char *dirname)
/* traversing the each directory entry */
templength = le16_to_cpu(dir->direntlen);
totalbytes = totalbytes + templength;
-   previous_dir = dir;
dir = (struct ext2_dirent *)((char *)dir + templength);
ptr = (char *)dir;
}
 
-   if (found == 1) {
-   free(block_buffer);
-   block_buffer = NULL;
-   return inodeno;
-   }
-
free(block_buffer);
block_buffer = NULL;
+
+   if (inodeno > 0)
+   return inodeno;
}
 
 fail:
@@ -757,15 +745,13 @@ fail:
return result_inode_no;
 }
 
-static int check_filename(char *filename, unsigned int blknr)
+static int unlink_filename(char *filename, unsigned int blknr)
 {
-   unsigned int first_block_no_of_root;
int totalbytes = 0;
int templength = 0;
int status, inodeno;
int found = 0;
char *root_first_block_buffer = NULL;
-   char *root_first_block_addr = NULL;
struct ext2_dirent *dir = NULL;
struct ext2_dirent *previous_dir = NULL;
char *ptr = NULL;
@@ -773,18 +759,15 @@ static int check_filename(char *filename, unsigned int 
blknr)
int ret = -1;
 
/* get the first block of root */
-   first_block_no_of_root = blknr;
root_first_block_buffer = zalloc(fs->blksz);
if (!

[U-Boot] UMS - maintain connection

2016-08-14 Thread John Tobias
Hello All,

I am using ums (USB Mass Storage) in u-boot to expose the storage of
my device into my host machine. Everything works okay except when the
host machine wakeup from the sleep - my device got disconnect from
host after it received an resume signal.

I tried the g_mass_storage driver in the kernel and it works fine. It
never disconnect when the host machine goes to sleep and wake it up.

Does anyone have encountered the said issue?. How did you fix it?.

Regards,

John
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH] mmc: sdhci: Add the programmable clock mode support

2016-08-14 Thread Andreas Bießmann
Dear Pantelis,

On 20.06.16 03:58, Wenyou Yang wrote:
> Add the programmable clock mode for the clock generator.
> 

this one is delegated to me, but I think it is out of my scope. Could
you please have a look?

Andreas

> Signed-off-by: Wenyou Yang 
> ---
> 
>  drivers/mmc/sdhci.c | 49 +++--
>  include/sdhci.h | 15 +++
>  2 files changed, 54 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/mmc/sdhci.c b/drivers/mmc/sdhci.c
> index 5c71ab8..ee6d4a1 100644
> --- a/drivers/mmc/sdhci.c
> +++ b/drivers/mmc/sdhci.c
> @@ -286,7 +286,7 @@ static int sdhci_send_command(struct mmc *mmc, struct 
> mmc_cmd *cmd,
>  static int sdhci_set_clock(struct mmc *mmc, unsigned int clock)
>  {
>   struct sdhci_host *host = mmc->priv;
> - unsigned int div, clk, timeout, reg;
> + unsigned int div, clk = 0, timeout, reg;
>  
>   /* Wait max 20 ms */
>   timeout = 200;
> @@ -310,14 +310,35 @@ static int sdhci_set_clock(struct mmc *mmc, unsigned 
> int clock)
>   return 0;
>  
>   if (SDHCI_GET_VERSION(host) >= SDHCI_SPEC_300) {
> - /* Version 3.00 divisors must be a multiple of 2. */
> - if (mmc->cfg->f_max <= clock)
> - div = 1;
> - else {
> - for (div = 2; div < SDHCI_MAX_DIV_SPEC_300; div += 2) {
> - if ((mmc->cfg->f_max / div) <= clock)
> + /*
> +  * Check if the Host Controller supports Programmable Clock
> +  * Mode.
> +  */
> + if (host->clk_mul) {
> + for (div = 1; div <= 1024; div++) {
> + if ((mmc->cfg->f_max * host->clk_mul / div)
> + <= clock)
>   break;
>   }
> +
> + /*
> +  * Set Programmable Clock Mode in the Clock
> +  * Control register.
> +  */
> + clk = SDHCI_PROG_CLOCK_MODE;
> + div--;
> + } else {
> + /* Version 3.00 divisors must be a multiple of 2. */
> + if (mmc->cfg->f_max <= clock) {
> + div = 1;
> + } else {
> + for (div = 2;
> +  div < SDHCI_MAX_DIV_SPEC_300; div += 2) {
> + if ((mmc->cfg->f_max / div) <= clock)
> + break;
> + }
> + }
> + div >>= 1;
>   }
>   } else {
>   /* Version 2.00 divisors must be a power of 2. */
> @@ -325,13 +346,13 @@ static int sdhci_set_clock(struct mmc *mmc, unsigned 
> int clock)
>   if ((mmc->cfg->f_max / div) <= clock)
>   break;
>   }
> + div >>= 1;
>   }
> - div >>= 1;
>  
>   if (host->set_clock)
>   host->set_clock(host->index, div);
>  
> - clk = (div & SDHCI_DIV_MASK) << SDHCI_DIVIDER_SHIFT;
> + clk |= (div & SDHCI_DIV_MASK) << SDHCI_DIVIDER_SHIFT;
>   clk |= ((div & SDHCI_DIV_HI_MASK) >> SDHCI_DIV_MASK_LEN)
>   << SDHCI_DIVIDER_HI_SHIFT;
>   clk |= SDHCI_CLOCK_INT_EN;
> @@ -480,7 +501,7 @@ static const struct mmc_ops sdhci_ops = {
>  
>  int add_sdhci(struct sdhci_host *host, u32 max_clk, u32 min_clk)
>  {
> - unsigned int caps;
> + unsigned int caps, caps_1;
>  
>   host->cfg.name = host->name;
>   host->cfg.ops = &sdhci_ops;
> @@ -546,6 +567,14 @@ int add_sdhci(struct sdhci_host *host, u32 max_clk, u32 
> min_clk)
>  
>   host->cfg.b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT;
>  
> + /*
> +  * In case of Host Controller v3.00, find out whether clock
> +  * multiplier is supported.
> +  */
> + caps_1 = sdhci_readl(host, SDHCI_CAPABILITIES_1);
> + host->clk_mul = (caps_1 & SDHCI_CLOCK_MUL_MASK) >>
> + SDHCI_CLOCK_MUL_SHIFT;
> +
>   sdhci_reset(host, SDHCI_RESET_ALL);
>  
>   host->mmc = mmc_create(&host->cfg, host);
> diff --git a/include/sdhci.h b/include/sdhci.h
> index e0f6667..5abe0a2 100644
> --- a/include/sdhci.h
> +++ b/include/sdhci.h
> @@ -97,6 +97,7 @@
>  #define  SDHCI_DIV_MASK  0xFF
>  #define  SDHCI_DIV_MASK_LEN  8
>  #define  SDHCI_DIV_HI_MASK   0x300
> +#define  SDHCI_PROG_CLOCK_MODE  0x0020
>  #define  SDHCI_CLOCK_CARD_EN 0x0004
>  #define  SDHCI_CLOCK_INT_STABLE  0x0002
>  #define  SDHCI_CLOCK_INT_EN  0x0001
> @@ -166,6 +167,19 @@
>  #define  SDHCI_CAN_64BIT 0x1000
>  
>  #define SDHCI_CAPABILITIES_1 0x44
> +#define  SDHCI_SUPPORT_SDR50 0x0001
> +#define  SDHCI_SUPPORT_SDR1040x0002
> +#define  SDHCI_SUPPORT_DDR50 0x0004
> +#define  SDHCI_DRIVER_TYPE_A 0x0010
> +#define  SDHCI_

[U-Boot] [PATCH 1/3] net: davinci_emac: Remove useless dcache ops on descriptors

2016-08-14 Thread Karl Beldan
ATM the rx and tx descriptors are handled as cached memory while they
lie in a dedicated RAM of the SoCs, which is an uncached area.
Removing the said dcache ops, while optimizing the logic and clarifying
the code, also gets rid of most of the check_cache_range() incurred
warnings:
CACHE: Misaligned operation at range

Signed-off-by: Karl Beldan 
---
 drivers/net/davinci_emac.c | 28 
 1 file changed, 28 deletions(-)

diff --git a/drivers/net/davinci_emac.c b/drivers/net/davinci_emac.c
index b030498..947bfab 100644
--- a/drivers/net/davinci_emac.c
+++ b/drivers/net/davinci_emac.c
@@ -108,26 +108,6 @@ static u_int8_tnum_phy;
 
 phy_t  phy[CONFIG_SYS_DAVINCI_EMAC_PHY_COUNT];
 
-static inline void davinci_flush_rx_descs(void)
-{
-   /* flush the whole RX descs area */
-   flush_dcache_range(EMAC_WRAPPER_RAM_ADDR + EMAC_RX_DESC_BASE,
-   EMAC_WRAPPER_RAM_ADDR + EMAC_TX_DESC_BASE);
-}
-
-static inline void davinci_invalidate_rx_descs(void)
-{
-   /* invalidate the whole RX descs area */
-   invalidate_dcache_range(EMAC_WRAPPER_RAM_ADDR + EMAC_RX_DESC_BASE,
-   EMAC_WRAPPER_RAM_ADDR + EMAC_TX_DESC_BASE);
-}
-
-static inline void davinci_flush_desc(emac_desc *desc)
-{
-   flush_dcache_range((unsigned long)desc,
-   (unsigned long)desc + sizeof(*desc));
-}
-
 static int davinci_eth_set_mac_addr(struct eth_device *dev)
 {
unsigned long   mac_hi;
@@ -491,8 +471,6 @@ static int davinci_eth_open(struct eth_device *dev, bd_t 
*bis)
emac_rx_active_tail = rx_desc;
emac_rx_queue_active = 1;
 
-   davinci_flush_rx_descs();
-
/* Enable TX/RX */
writel(EMAC_MAX_ETHERNET_PKT_SIZE, &adap_emac->RXMAXLEN);
writel(0, &adap_emac->RXBUFFEROFFSET);
@@ -655,7 +633,6 @@ static int davinci_eth_send_packet (struct eth_device *dev,
 
flush_dcache_range((unsigned long)packet,
(unsigned long)packet + length);
-   davinci_flush_desc(emac_tx_desc);
 
/* Send the packet */
writel(BD_TO_HW((unsigned long)emac_tx_desc), &adap_emac->TX0HDP);
@@ -689,8 +666,6 @@ static int davinci_eth_rcv_packet (struct eth_device *dev)
volatile emac_desc *tail_desc;
int status, ret = -1;
 
-   davinci_invalidate_rx_descs();
-
rx_curr_desc = emac_rx_active_head;
if (!rx_curr_desc)
return 0;
@@ -729,7 +704,6 @@ static int davinci_eth_rcv_packet (struct eth_device *dev)
rx_curr_desc->buff_off_len = EMAC_MAX_ETHERNET_PKT_SIZE;
rx_curr_desc->pkt_flag_len = EMAC_CPPI_OWNERSHIP_BIT;
rx_curr_desc->next = 0;
-   davinci_flush_desc(rx_curr_desc);
 
if (emac_rx_active_head == 0) {
printf ("INFO: emac_rcv_pkt: active queue head = 0\n");
@@ -747,13 +721,11 @@ static int davinci_eth_rcv_packet (struct eth_device *dev)
tail_desc->next = BD_TO_HW((ulong) curr_desc);
status = tail_desc->pkt_flag_len;
if (status & EMAC_CPPI_EOQ_BIT) {
-   davinci_flush_desc(tail_desc);
writel(BD_TO_HW((ulong)curr_desc),
   &adap_emac->RX0HDP);
status &= ~EMAC_CPPI_EOQ_BIT;
tail_desc->pkt_flag_len = status;
}
-   davinci_flush_desc(tail_desc);
}
return (ret);
}
-- 
2.9.2

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH] spi: tegra20: fix mode selection logic

2016-08-14 Thread Jagan Teki
On 13 August 2016 at 02:36, Stephen Warren  wrote:
> From: Stephen Warren 
>
> When the set_mode() function runs, the SPI bus is not active, and hence
> the clocks to the SPI controller are not running. Any register read/write
> at this time will hang the CPU. Remove the code from set_mode() that does
> this, and move it to the correct place in claim_bus().

The idea of claim_bus is just to enable the bus for any transaction to
start, since set_mode is running before claim (ex: spi_get_bus_and_cs
while 'sf probe') it's .probe which actual driver binding
responsibility to initialize the SPI bus so-that .set_mode and
.set_speed will set the mode and freq for that initialized bus based
on the inputs from user, drivers like zynq, exynos will follow the
same.

-- 
Jagan.
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH 1/3] net: davinci_emac: Remove useless dcache ops on descriptors

2016-08-14 Thread Tom Rini
On Sun, Aug 14, 2016 at 03:03:15PM +, Karl Beldan wrote:

> ATM the rx and tx descriptors are handled as cached memory while they
> lie in a dedicated RAM of the SoCs, which is an uncached area.
> Removing the said dcache ops, while optimizing the logic and clarifying
> the code, also gets rid of most of the check_cache_range() incurred
> warnings:
> CACHE: Misaligned operation at range
> 
> Signed-off-by: Karl Beldan 

Reviewed-by: Tom Rini 

-- 
Tom


signature.asc
Description: Digital signature
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH 2/3] net: davinci_emac: Round up top buffer boundaries for dcache ops

2016-08-14 Thread Tom Rini
On Sun, Aug 14, 2016 at 03:03:16PM +, Karl Beldan wrote:

> check_cache_range() warns that the top boundaries are not properly
> aligned while flushing and invalidating the buffers and make these
> operations to fail.
> ATM the RX bottom boundaries are aligned by design with EMAC_RXBUF_SIZE,
> properly aligned with ARCH_DMA_MINALIGN, however the top ones are not.
> 
> This gets rid of the warnings:
> CACHE: Misaligned operation at range
> 
> Signed-off-by: Karl Beldan 
> ---
>  drivers/net/davinci_emac.c | 6 --
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/davinci_emac.c b/drivers/net/davinci_emac.c
> index 947bfab..55461b0 100644
> --- a/drivers/net/davinci_emac.c
> +++ b/drivers/net/davinci_emac.c
> @@ -632,7 +632,8 @@ static int davinci_eth_send_packet (struct eth_device 
> *dev,
> EMAC_CPPI_EOP_BIT);
>  
>   flush_dcache_range((unsigned long)packet,
> - (unsigned long)packet + length);
> +round_up((unsigned long)packet + length,
> + ARCH_DMA_MINALIGN));

It's preferred to use:
(unsigned long)packet + ALIGN(length, PKTALIGN)); 
here instead of ARCH_DMA_MINALIGN.

-- 
Tom


signature.asc
Description: Digital signature
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH 2/3] net: davinci_emac: Round up top buffer boundaries for dcache ops

2016-08-14 Thread Karl Beldan
check_cache_range() warns that the top boundaries are not properly
aligned while flushing and invalidating the buffers and make these
operations to fail.
ATM the RX bottom boundaries are aligned by design with EMAC_RXBUF_SIZE,
properly aligned with ARCH_DMA_MINALIGN, however the top ones are not.

This gets rid of the warnings:
CACHE: Misaligned operation at range

Signed-off-by: Karl Beldan 
---
 drivers/net/davinci_emac.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/net/davinci_emac.c b/drivers/net/davinci_emac.c
index 947bfab..55461b0 100644
--- a/drivers/net/davinci_emac.c
+++ b/drivers/net/davinci_emac.c
@@ -632,7 +632,8 @@ static int davinci_eth_send_packet (struct eth_device *dev,
  EMAC_CPPI_EOP_BIT);
 
flush_dcache_range((unsigned long)packet,
-   (unsigned long)packet + length);
+  round_up((unsigned long)packet + length,
+   ARCH_DMA_MINALIGN));
 
/* Send the packet */
writel(BD_TO_HW((unsigned long)emac_tx_desc), &adap_emac->TX0HDP);
@@ -677,7 +678,8 @@ static int davinci_eth_rcv_packet (struct eth_device *dev)
} else {
unsigned long tmp = (unsigned long)rx_curr_desc->buffer;
 
-   invalidate_dcache_range(tmp, tmp + EMAC_RXBUF_SIZE);
+   invalidate_dcache_range(tmp, round_up(tmp + 
EMAC_RXBUF_SIZE,
+ 
ARCH_DMA_MINALIGN));
net_process_received_packet(
rx_curr_desc->buffer,
rx_curr_desc->buff_off_len & 0x);
-- 
2.9.2

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH 3/3] net: davinci_emac: Invalidate only the received portion of a buffer

2016-08-14 Thread Karl Beldan
ATM when receiving a packet the whole buffer is invalidated, this change
optimizes this behaviour.

Signed-off-by: Karl Beldan 
---
 drivers/net/davinci_emac.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/net/davinci_emac.c b/drivers/net/davinci_emac.c
index 55461b0..e26e727 100644
--- a/drivers/net/davinci_emac.c
+++ b/drivers/net/davinci_emac.c
@@ -677,13 +677,13 @@ static int davinci_eth_rcv_packet (struct eth_device *dev)
printf ("WARN: emac_rcv_pkt: Error in packet\n");
} else {
unsigned long tmp = (unsigned long)rx_curr_desc->buffer;
+   unsigned short len =
+   rx_curr_desc->buff_off_len & 0x;
 
-   invalidate_dcache_range(tmp, round_up(tmp + 
EMAC_RXBUF_SIZE,
- 
ARCH_DMA_MINALIGN));
-   net_process_received_packet(
-   rx_curr_desc->buffer,
-   rx_curr_desc->buff_off_len & 0x);
-   ret = rx_curr_desc->buff_off_len & 0x;
+   invalidate_dcache_range(tmp, round_up(tmp + len,
+   ARCH_DMA_MINALIGN));
+   net_process_received_packet(rx_curr_desc->buffer, len);
+   ret = len;
}
 
/* Ack received packet descriptor */
-- 
2.9.2

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [RFC PATCH 3/4] ext4: fix endianess problems in ext4 write support

2016-08-14 Thread Stefan Bruens
On Freitag, 12. August 2016 15:16:20 CEST Michael Walle wrote:
> All fields were accessed directly instead of using the proper byte swap
> functions. Thus, ext4 write support was only usable on little-endian
> architectures. Fix this.
> 
> Signed-off-by: Michael Walle 

I have tested this on sandbox (x86_64), no regressions found. Some remarks 
below.

Reviewed-by: Stefan Brüns 
Tested-by: Stefan Brüns 

> ---
> 
> Ok this patch is huge, please comment. I know, checkpatch fails because
> there are longer lines than 80 characters. I don't want do be rude, but the
> coding style is awful :/ Eg.
>  
> http://git.denx.de/?p=u-boot.git;a=blob;f=fs/ext4/ext4_common.c;h=eb49fce04
> c5a290e839575945da722bc97d2f670;hb=HEAD#l440
> http://git.denx.de/?p=u-boot.git;a=blob;f=fs/ext4/ext4_write.c;h=e027916763
> f9b52937c7fe13f1698b67b94eb901;hb=HEAD#l137
> 
> Many ugly places seems to come from the 80 characters limit. Most of the
> code looks like its right-aligned. I know there is a valid point for having
> this limit, eg refactor code into small functions. And frankly, the ext4
> write code badly needs such a refactoring. But I won't and can't do it. I
> can resend a new version which meet the 80 character restriction, but it
> won't make the code easier to read. And believe me, it is already hard to
> do it.
> 
> Ok, back to business. Sparse really helped to find the places where the
> byteswaps were missing once you annotated it correctly with the
> __le16/__le32 types. If someone want to do check again, just run
>  make C=1
> See Documentation/sparse.txt in the linux kernel for more information. I've
> done a short test, to verify I can (over)write a 700kB file. No cornertests
> etc.
> 
>  fs/ext4/ext4_common.c  | 260
> ++--- fs/ext4/ext4_common.h  | 
>  4 +-
>  fs/ext4/ext4_journal.c |  15 +--
>  fs/ext4/ext4_journal.h |   4 +-
>  fs/ext4/ext4_write.c   | 195 +++--
>  include/ext_common.h   |   2 +-
>  6 files changed, 251 insertions(+), 229 deletions(-)
> 
> diff --git a/fs/ext4/ext4_common.c b/fs/ext4/ext4_common.c
> index e8ed30a..4eb4e18 100644
> --- a/fs/ext4/ext4_common.c
> +++ b/fs/ext4/ext4_common.c
> @@ -33,19 +33,22 @@
> 
>  struct ext2_data *ext4fs_root;
>  struct ext2fs_node *ext4fs_file;
> -uint32_t *ext4fs_indir1_block;
> +__le32 *ext4fs_indir1_block;
>  int ext4fs_indir1_size;
>  int ext4fs_indir1_blkno = -1;
> -uint32_t *ext4fs_indir2_block;
> +__le32 *ext4fs_indir2_block;
>  int ext4fs_indir2_size;
>  int ext4fs_indir2_blkno = -1;
> 
> -uint32_t *ext4fs_indir3_block;
> +__le32 *ext4fs_indir3_block;
>  int ext4fs_indir3_size;
>  int ext4fs_indir3_blkno = -1;
>  struct ext2_inode *g_parent_inode;
>  static int symlinknest;
> 
> +#define DEC_LE16(x) (x = cpu_to_le16(le16_to_cpu(x) - 1))
> +#define DEC_LE32(x) (x = cpu_to_le32(le32_to_cpu(x) - 1))

I would prefer a static function *per variable/field* - this will make it 
easier to manipulate any high/low split counts for FEATURE_64BIT. Same for the 
INC_xxx in ext4_write.c


> @@ -360,6 +364,9 @@ void ext4fs_update_parent_dentry(char *filename, int
> *p_ino, int file_type) /* directory entry */
>   struct ext2_dirent *dir;
>   char *temp_dir = NULL;
> + uint32_t new_blk_no;
> + uint32_t new_size;
> + uint32_t new_blockcnt;
> 
>   zero_buffer = zalloc(fs->blksz);
>   if (!zero_buffer) {
> @@ -396,7 +403,7 @@ restart:
>   goto fail;
>   dir = (struct ext2_dirent *)root_first_block_buffer;
>   totalbytes = 0;
> - while (dir->direntlen > 0) {
> + while (le16_to_cpu(dir->direntlen) > 0) {

direntlen is at least 8, so this is "while (true) {"

>   /*
>* blocksize-totalbytes because last directory length
>* i.e. dir->direntlen is free availble space in the
> @@ -405,7 +412,7 @@ restart:
>*/
> 
>   /* traversing the each directory entry */
> - if (fs->blksz - totalbytes == dir->direntlen) {
> + if (fs->blksz - totalbytes == le16_to_cpu(dir->direntlen)) {
>   if (strlen(filename) % 4 != 0)
>   padding_factor = 4 - (strlen(filename) % 4);
> 
> @@ -430,32 +437,34 @@ restart:
>   printf("Directory exceeds limit\n");
>   goto fail;
>   }
> - g_parent_inode->b.blocks.dir_blocks
> - [direct_blk_idx] = ext4fs_get_new_blk_no();
> - if (g_parent_inode->b.blocks.dir_blocks
> - [direct_blk_idx] == -1) {
> + new_blk_no = ext4fs_get_new_blk_no();
> + if (new_blk_no == -1) {
>   printf("no block left to assign\n");
>   goto fail;
> 

Re: [U-Boot] [PATCH 2/2] fs/fat: Optimizes memory size with single global variable instead of 3

2016-08-14 Thread Benoît Thébaudeau
Hi,

On Tue, Aug 2, 2016 at 9:35 PM, Benoît Thébaudeau
 wrote:
> On Tue, Aug 2, 2016 at 8:53 PM, Stephen Warren  wrote:
>> On 07/28/2016 12:11 AM, Tien Fong Chee wrote:
>>>
>>> Single 64KB get_contents_vfatname_block global variable would be used for
>>> all FAT implementation instead of allocating additional two global
>>> variables
>>> which are get_denfromdir_block and do_fat_read_at_block. This
>>> implementation
>>> can help in saving up 128KB memory space.
>>
>>
>> The series,
>>
>> Tested-by: Stephen Warren 
>> (via DFU's FAT reading/writing on various Tegra; likely primarily FAT rather
>> than VFAT though)
>>
>> Reviewed-by: Stephen Warren 
>
> I suspect that reading a filename with VFAT entries crossing a cluster
> boundary in a FAT32 root directory will be broken by this series. I do
> not have time to test this and other corner cases right now though,
> but it will be possible in the next few weeks.

I have tested VFAT long filenames with the current implementation on
Sandbox. It's completely broken:
 - There is a length limit somewhere between 111 and 120 characters,
instead of 256 characters. Beyond this limit, the files are invisible
with ls.
 - Some filenames are truncated or mixed up between files. I have
tested 111-character random filenames for 1000 empty files in the root
directory. Most filenames had the expected length, but a few were
shorter or longer.
 - If there are too many files in the root directory, ls hangs.

I am pretty sure that this series introduces some regressions, but
they seem to be in corner cases that cannot even be used or tested
because of other bugs, so this series might not make this
implementation much more broken than it currently is. It's risky,
though.

I've quickly looked into TianoCore EDK II. It is so deeply tied to the
EFI driver model and APIs that it would be a pain to port to U-Boot.
Its FAT module is not designed to be portable beyond EFI. Its build
system would complicate things too.

Stephen, according to what you say in test/fs/fat-noncontig-test.sh,
your solution to accelerate FatFs seems to be working, even if the
author is not interested in it, so maybe it would still be worth
maintaining locally in order to have a reliable FAT support, also with
a small memory footprint. barebox uses FatFs.

Best regards,
Benoît
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot