Re: [U-Boot] [PATCH 3/4] imx6: spl: Reduce SPL limit size in case CONFIG_SECURE_BOOT is enabled

2019-09-17 Thread Jagan Teki
Hi Breno,

On Thu, Jul 18, 2019 at 6:06 PM Breno Matheus Lima  wrote:
>
> In case CONFIG_SECURE_BOOT is enabled we need to limit the SPL size to
> avoid a possible HAB failure event:
>
> - HAB Event 1 -
> event data:
> 0xdb 0x00 0x14 0x42 0x33 0x22 0x33 0x00
> 0x00 0x00 0x00 0x0f 0x00 0x90 0x70 0x00
> 0x00 0x01 0x10 0x00
> STS = HAB_FAILURE (0x33)
> RSN = HAB_INV_ADDRESS (0x22)
> CTX = HAB_CTX_TARGET (0x33)
> ENG = HAB_ENG_ANY (0x00)
>
> As explained in Commit 23612534fe0f ("spl: imx6: Provide a SPL_SIZE_LIMIT
> default") the i.MX6 SPL size limit is 68KB.
>
> The ROM code is copying the image size defined in boot data to its
> respective load address, in case we exceed the OCRAM free region a
> HAB invalid address failure event is generated.
>
> The maximum CSF size is defined in CONFIG_CSF_SIZE, reduce SPL size
> limit based on this configuration.
>
> Signed-off-by: Breno Lima 
> ---
>  tools/spl_size_limit.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/tools/spl_size_limit.c b/tools/spl_size_limit.c
> index 98ff491867..8902e30129 100644
> --- a/tools/spl_size_limit.c
> +++ b/tools/spl_size_limit.c
> @@ -14,6 +14,9 @@ int main(int argc, char *argv[])
>
>  #ifdef CONFIG_SPL_SIZE_LIMIT
> spl_size_limit = CONFIG_SPL_SIZE_LIMIT;
> +#if defined(CONFIG_SECURE_BOOT) && defined(CONFIG_CSF_SIZE)
> +   spl_size_limit -= CONFIG_CSF_SIZE;
> +#endif

But, if the target enable HAB on SPL the size would be part of SPL
limit, isn't ?

Just now I have looked at this, since one of my board (imx6_mamoj)
fails to build.

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


[U-Boot] [PATCH v2 3/3] ubi: Add "skipcheck" command to set/clear this bit in the UBI volume hdr

2019-09-17 Thread Stefan Roese
U-Boot now supports the "skip_check" flag to optionally skip the CRC
check at open time. Currently its only possible to set this bit upon
UBI volume creation. But it might be very useful to also set this bit
on already installed systems (e.g. field upgrade) to make also use of
the boot-time decrease on those systems.

This patch now adds a new "ubi" command "ubi skipcheck" to set or clear
this bit in the UBI volume header:

=> ubi skipcheck rootfs0 on
Setting skip_check on volume rootfs0

BTW: This saves approx. 10 seconds Linux bootup time on a MT7688 based
target with 128MiB of SPI NAND.

Signed-off-by: Stefan Roese 
Reviewed-by: Heiko Schocher 
Cc: Quentin Schulz 
Cc: Boris Brezillon 
Cc: Heiko Schocher 
Cc: Andreas Dannenberg 
---
v2:
- Add documentation to doc/README.ubi as suggested by Andreas

 cmd/ubi.c  | 34 ++
 doc/README.ubi | 33 +
 2 files changed, 67 insertions(+)

diff --git a/cmd/ubi.c b/cmd/ubi.c
index c857f07d93..42b5641b32 100644
--- a/cmd/ubi.c
+++ b/cmd/ubi.c
@@ -419,6 +419,30 @@ static int ubi_dev_scan(struct mtd_info *info, const char 
*vid_header_offset)
return 0;
 }
 
+static int ubi_set_skip_check(char *volume, bool skip_check)
+{
+   struct ubi_vtbl_record vtbl_rec;
+   struct ubi_volume *vol;
+
+   vol = ubi_find_volume(volume);
+   if (vol == NULL)
+   return ENODEV;
+
+   printf("%sing skip_check on volume %s\n",
+  skip_check ? "Sett" : "Clear", volume);
+
+   vtbl_rec = ubi->vtbl[vol->vol_id];
+   if (skip_check) {
+   vtbl_rec.flags |= UBI_VTBL_SKIP_CRC_CHECK_FLG;
+   vol->skip_check = 1;
+   } else {
+   vtbl_rec.flags &= ~UBI_VTBL_SKIP_CRC_CHECK_FLG;
+   vol->skip_check = 0;
+   }
+
+   return ubi_change_vtbl_record(ubi, vol->vol_id, &vtbl_rec);
+}
+
 static int ubi_detach(void)
 {
 #ifdef CONFIG_CMD_UBIFS
@@ -578,6 +602,14 @@ static int do_ubi(cmd_tbl_t *cmdtp, int flag, int argc, 
char * const argv[])
return ubi_remove_vol(argv[2]);
}
 
+   if (strncmp(argv[1], "skipcheck", 9) == 0) {
+   /* E.g., change skip_check flag */
+   if (argc == 4) {
+   skipcheck = strncmp(argv[3], "on", 2) == 0;
+   return ubi_set_skip_check(argv[2], skipcheck);
+   }
+   }
+
if (strncmp(argv[1], "write", 5) == 0) {
int ret;
 
@@ -658,6 +690,8 @@ U_BOOT_CMD(
" - Read volume to address with size\n"
"ubi remove[vol] volume"
" - Remove volume\n"
+   "ubi skipcheck volume on/off"
+   " - Set or clear skip_check flag in volume header\n"
"[Legends]\n"
" volume: character name\n"
" size: specified in bytes\n"
diff --git a/doc/README.ubi b/doc/README.ubi
index 9efab6cdc9..c78a81795b 100644
--- a/doc/README.ubi
+++ b/doc/README.ubi
@@ -223,3 +223,36 @@ For example:
 
 => ubifsumount
 Unmounting UBIFS volume recovery!
+
+
+Usage of the UBI CRC skip-check flag of static volumes:
+---
+Some users of static UBI volumes implement their own integrity check,
+thus making the volume CRC check done at open time useless. For
+instance, this is the case when one use the ubiblock + dm-verity +
+squashfs combination, where dm-verity already checks integrity of the
+block device but this time at the block granularity instead of verifying
+the whole volume.
+
+Skipping this test drastically improves the boot-time.
+
+U-Boot now supports the "skip_check" flag to optionally skip the CRC
+check at open time.
+
+Usage: Case A - Upon UBI volume creation:
+You can optionally add "--skipcheck" to the "ubi create" command:
+
+ubi create[vol] volume [size] [type] [id] [--skipcheck]
+ - create volume name with size ('-' for maximum available size)
+
+Usage: Case B - With an already existing UBI volume:
+Use the "ubi skipcheck" command:
+
+ubi skipcheck volume on/off - Set or clear skip_check flag in volume header
+
+Example:
+=> ubi skipcheck rootfs0 on
+Setting skip_check on volume rootfs0
+
+BTW: This saves approx. 10 seconds Linux bootup time on a MT7688 based
+target with 128MiB of SPI NAND.
-- 
2.23.0

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


Re: [U-Boot] [PATCH v2 8/9] spl: Introduce SPL_DM_GPIO Kconfig define

2019-09-17 Thread Lukasz Majewski
Hi Simon,

> On Sun, 18 Aug 2019 at 19:30, Peng Fan  wrote:
> >  
> > > Subject: [PATCH v2 8/9] spl: Introduce SPL_DM_GPIO Kconfig define
> > >
> > > This define indicates if DM_GPIO shall be supported in SPL. This
> > > allows proper operation of DM converted GPIO drivers in SPL,
> > > which use #if !CONFIG_IS_ENABLED(DM_GPIO) to also support not yet
> > > DM/DTS converted boards.
> > >
> > > Signed-off-by: Lukasz Majewski 
> > > ---
> > >
> > > Changes in v2:
> > > - New patch
> > >
> > >  common/spl/Kconfig | 6 ++
> > >  1 file changed, 6 insertions(+)
> > >  
> 
> Reviewed-by: Simon Glass 
> 
> But how about adding && DM_GPIO as well to that depends clause?

I think that they shall be a separate Kconfig options. Please imagine
that one have board with SPL GPIO support, but not in U-Boot proper.

> 
> Regards,
> Simon



Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lu...@denx.de


pgphpwcZq82eC.pgp
Description: OpenPGP digital signature
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v2 3/7] clk: imx8: Update imx8 clock driver

2019-09-17 Thread Lukasz Majewski
Hi Peng,

> Hi All,
> 
> > Subject: [PATCH v2 3/7] clk: imx8: Update imx8 clock driver  
> 
> Sorry to bring back this topic.
> 
> This patch is not converting to CCF following Linux, but it could
> satisfy u-boot usage and make more feature work.
> 
> I checked Linux i.MX8 CCF recently, although Linux upstream has i.MX8
> CCF support, but NXP downstream has significantly reimplement the
> code. So we could not take code directly from Linux upstream, because
> this would introduce efforts in U-Boot after NXP downstream clk code
> upstreamed.
> 
> I have also tried to converting to use NXP downstream Linux ccf code
> in u-boot, but there is an issue is some clks are root clks, no
> parents. However u-boot ccf always requires a parent for a clk.
> Anyway there is still long time to upstream nxp Linux downstream clk
> code to Linux.
> 
> I would hear your voice about U-Boot part. Proceed with current patch
> or promoting CCF with NXP downstream clk?

It depends.

One reason for using Linux clocks (backported from Linux) is that there
is a chance that this code would be maintained for a long time and
hence subsequent updates from Linux would have the chance to work.

With NXP downstream code - it may happen that we will end up with some
in-mainline version not being in sync with Linux and with future NXP
internal BSP releases.


My standpoint is as follows - if you feel like there is a pretty high
chance that NXP downstream clk code will be accepted to Linux _soon_,
then I don't mind to have it in U-Boot.

This is all the matter of active maintenance of the CLK code ...

> 
> Thanks,
> Peng.
> 
> > 
> > Update imx8 clock driver to support LPCG and full clocks tree for
> > some modules aligned with kernel.
> > 
> > We classify the clock into serveral types: slice, fixed, lpcg, gpr
> > and mux. Generally slice and fixed clocks are the sources. lpcg,
> > gpr and mux are the downstream of those sources and are used for
> > gating, muxing or dividing functions.
> > 
> > This patch replaces the functions defined in imx8qm and imx8qxp
> > with the clock
> > tables of different clock types. clk-imx8 use unified functions to
> > process these clock tables.
> > 
> > Note: since the clock depends on the power domain of its resource,
> > must power
> > on the resource firstly, then we can get the clock. Otherwise, we
> > can't access lpcg.
> > Thus, the clock dump only works for the slice clock.
> > 
> > Signed-off-by: Ye Li 
> > ---
> > Changes in v2:
> >  - None
> > 
> >  drivers/clk/imx/clk-imx8.c| 304 +--
> >  drivers/clk/imx/clk-imx8.h|  83 +++-
> >  drivers/clk/imx/clk-imx8qm.c  | 479
> > --
> >  drivers/clk/imx/clk-imx8qxp.c | 432
> > + 4 files changed, 689
> > insertions(+), 609 deletions(-)
> > 
> > diff --git a/drivers/clk/imx/clk-imx8.c b/drivers/clk/imx/clk-imx8.c
> > index a755e26..afdb6ea 100644
> > --- a/drivers/clk/imx/clk-imx8.c
> > +++ b/drivers/clk/imx/clk-imx8.c
> > @@ -12,32 +12,294 @@
> >  #include 
> >  #include 
> >  #include 
> > +#include 
> > 
> >  #include "clk-imx8.h"
> > 
> > -__weak ulong imx8_clk_get_rate(struct clk *clk)
> > +struct imx8_clks_collect *soc_data[] = {
> > +#ifdef CONFIG_IMX8QXP
> > +   &imx8qxp_clk_collect,
> > +#endif
> > +#ifdef CONFIG_IMX8QM
> > +   &imx8qm_clk_collect,
> > +#endif
> > +};
> > +
> > +static ulong __imx8_clk_get_rate(struct udevice *dev, ulong id);
> > +static int __imx8_clk_enable(struct udevice *dev, ulong id, bool
> > enable); +static ulong __imx8_clk_set_rate(struct udevice *dev,
> > ulong id, unsigned long rate);
> > +
> > +static struct imx8_clks_collect * find_clks_collect(struct udevice
> > *dev) +{
> > +   ulong data = (ulong)dev_get_driver_data(dev);
> > +   int i;
> > +
> > +   for (i = 0; i < ARRAY_SIZE(soc_data); i++) {
> > +   if (soc_data[i]->match_flag == data)
> > +   return soc_data[i];
> > +   }
> > +
> > +   return NULL;
> > +}
> > +
> > +static void * check_imx8_clk(struct udevice *dev, enum
> > imx8_clk_type type, ulong id, u32 size_of_clk)
> > +{
> > +   u32 i, size;
> > +   struct imx8_clks_collect *clks_col =
> > find_clks_collect(dev);
> > +   struct imx8_clk_header *hdr;
> > +   ulong clks;
> > +
> > +   if (!clks_col || !(clks_col->clks[type].type_clks)) {
> > +   printf("%s fails to get clks for type %d\n",
> > +  __func__, type);
> > +   return NULL;
> > +   }
> > +
> > +   clks = (ulong)(clks_col->clks[type].type_clks);
> > +   size = clks_col->clks[type].num;
> > +
> > +   for (i = 0; i < size; i++) {
> > +   hdr = (struct imx8_clk_header *)clks;
> > +   if (id == hdr->id)
> > +   return (void *)hdr;
> > +
> > +   clks += size_of_clk;
> > +   }
> > +
> > +   return NULL;
> > +}
> > +
> > +static ulong imx8_get_rate_lpcg(struct udevice *dev, struct
> > imx8_lpcg_clks *lpcg_clk)
> > +{
> > +   if (lpcg_clk->parent_id != 0)

[U-Boot] [PATCH] configs: rk3288: Increase bootm length

2019-09-17 Thread Jagan Teki
Increase bootm length to 64MB satisfy max gunzip
size, even other rockchip and know SoC are following
same length check.

Reported-by: Michael Trimarchi 
Signed-off-by: Jagan Teki 
---
 include/configs/rk3288_common.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/configs/rk3288_common.h b/include/configs/rk3288_common.h
index bcda769af5..910fe58822 100644
--- a/include/configs/rk3288_common.h
+++ b/include/configs/rk3288_common.h
@@ -9,7 +9,7 @@
 #include 
 #include "rockchip-common.h"
 
-#define CONFIG_SYS_BOOTM_LEN (16 << 20) /* 16MB */
+#define CONFIG_SYS_BOOTM_LEN   (64 << 20) /* 64MB */
 
 #define CONFIG_SKIP_LOWLEVEL_INIT_ONLY
 #define CONFIG_SYS_CBSIZE  1024
-- 
2.18.0.321.gffc6fa0e3

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


Re: [U-Boot] [PATCH v2 2/4] libfdt: return correct value if #size-cells property is not present

2019-09-17 Thread Matthias Brugger
Hi Simon,

On 17/09/2019 07:48, Simon Glass wrote:
> Hi,
> 
> On Thu, 5 Sep 2019 at 02:49,  wrote:
>>
>> From: Matthias Brugger 
>>
>> According to the device tree specification, the default value for
>> was not present.
>>
>> This patch also makes fdt_address_cells() and fdt_size_cells() conform
>> to the behaviour documented in libfdt.h. The defaults are only returned
>> if fdt_getprop() returns -FDT_ERR_NOTFOUND, otherwise the actual error
>> is returned.
>>
>> This is based on upstream commit:
>> aa7254d ("libfdt: return correct value if #size-cells property is not 
>> present")
>> but misses the test case part, as we don't implement them in U-Boot.
>>
>> Signed-off-by: Matthias Brugger 
> 
> This is v2 but I don't see a change log?
> 

I put the changelog into the cover letter:
https://patchwork.ozlabs.org/cover/1158304/

From your email I understand that you prefer a patch by patch changelog, 
correct?

Regards,
Matthias

>> ---
>>
>>  scripts/dtc/libfdt/fdt_addresses.c | 16 +---
>>  scripts/dtc/libfdt/libfdt.h|  2 +-
>>  2 files changed, 14 insertions(+), 4 deletions(-)
> 
> Regards,
> Simon
> 
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] imx6dl_mamoj broken

2019-09-17 Thread Stefano Babic
Hi Robert,

On 17/09/19 01:37, Robert Hancock wrote:
> On 2019-09-16 3:08 p.m., Stefano Babic wrote:
>> Hi Anatolji,
>>
>> On 16/09/19 22:20, Anatolij Gustschin wrote:
>>> Hi Jagan,
>>>
>>> On Mon, 16 Sep 2019 13:36:03 +0530
>>> Jagan Teki ja...@amarulasolutions.com wrote:
>>> ...
>    arm:  +   imx6dl_mamoj
> +spl/u-boot-spl.bin exceeds file size limit:
> +  limit:  53248 bytes
> +  actual: 58597 bytes
> +  excess: 5349 bytes
>
> +make[1]: *** [spl/u-boot-spl.bin] Error 1
> +make[1]: *** Deleting file `spl/u-boot-spl.bin'
> +make: *** [sub-make] Error 2

 Any idea which commit make this blow-out. we didn't do anything with
 this board recently. I guess some default CLK framework or so?
>>>
>>> This check fails since the recent changes in SPL size limit check,
>>> see commit 25d38f9b34be (imx6: spl: Reduce SPL limit size in case
>>> CONFIG_SECURE_BOOT is enabled).
>>>
>>> i.MX6DL has 128KiB OCRAM, probably we could increase default
>>> SPL_SIZE_LIMIT config in common/spl/Kconfig for i.MX6DL?
>>
>> Well, the current size was computed for the Solo /DL - Dual / Quad has
>> twice OCRAM. According to chapter "8.4 Internal ROM / RAM map", for Solo
>> /Dl there is 68KB available for user (address 0x907000--0x917FFF). I do
>> not remember the details, but then we have to reserve space for gd,
>> stack, etc. This leads to the actual value.
> 
> The patch I posted a while ago ("[PATCH v2] ARM: imx: Support larger SPL
> size on IMX6DQ") may be helpful for this case.

Your patch is "in" - it is applied to u-boot-imx. However, it cannot
help because the current limitation is set for Solo / DL. With your
patch, SPL on Dual / Quad can be larger.

> If the platform doesn't
> need to support the "lite" chip versions with smaller OCRAM size,

The SOC is a DL, 128KB

> then
> the available size for the SPL can be increased.

It cannot

Best regards,
Stefano Babic


-- 
=
DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sba...@denx.de
=
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] imx6dl_mamoj broken

2019-09-17 Thread Stefano Babic
Hi Fabio,

On 16/09/19 23:21, Fabio Estevam wrote:
> Hi Anatolij/Stefano/Jagan,
> 
> On Mon, Sep 16, 2019 at 5:20 PM Anatolij Gustschin  wrote:
> 
>> This check fails since the recent changes in SPL size limit check,
>> see commit 25d38f9b34be (imx6: spl: Reduce SPL limit size in case
>> CONFIG_SECURE_BOOT is enabled).
> 
> If you agree I can send a patch doing:
> 
> --- a/configs/imx6dl_mamoj_defconfig
> +++ b/configs/imx6dl_mamoj_defconfig
> @@ -1,7 +1,6 @@
>  CONFIG_ARM=y
>  CONFIG_ARCH_MX6=y
>  CONFIG_SYS_TEXT_BASE=0x1780
> -CONFIG_SECURE_BOOT=y
>  CONFIG_TARGET_MX6DL_MAMOJ=y
>  CONFIG_NR_DRAM_BANKS=1
>  # CONFIG_CMD_BMODE is not set
> 
> which allows the target to build again.
> 
> It seems that this target does not boot currently, but if we remove
> CONFIG_SECURE_BOOT then it can build and boot, I suppose.
> 

I can't decide for the board maintainer - yes, I have also dropped some
feature, and I can build, but I have no idea which feature can be
removed (and I could not test at all). The decision should be taken by
board maintainer, I  hope as soon as possible.

Best regards,
Stefano

-- 
=
DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sba...@denx.de
=
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 1/5] configs: stm32f429-discovery: Disable CONFIG_NET flag

2019-09-17 Thread Patrice Chotard
Network support was never added on this board, disable
CONFIG_NET flag to avoid following warning:

= WARNING ==
This board does not use CONFIG_DM_ETH (Driver Model
for Ethernet drivers). Please update the board to use
CONFIG_DM_ETH before the v2020.07 release. Failure to
update by the deadline may result in board removal.
See doc/driver-model/migration.rst for more info.


Signed-off-by: Patrice Chotard 
---

 configs/stm32f429-discovery_defconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/configs/stm32f429-discovery_defconfig 
b/configs/stm32f429-discovery_defconfig
index 3c3501566c..45fdb9d2ad 100644
--- a/configs/stm32f429-discovery_defconfig
+++ b/configs/stm32f429-discovery_defconfig
@@ -21,5 +21,6 @@ CONFIG_CMD_TIMER=y
 CONFIG_OF_CONTROL=y
 CONFIG_DEFAULT_DEVICE_TREE="stm32f429-disco"
 CONFIG_ENV_IS_IN_FLASH=y
+# CONFIG_NET is not set
 # CONFIG_MMC is not set
 CONFIG_MTD_NOR_FLASH=y
-- 
2.17.1

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


[U-Boot] [PATCH 2/5] configs: stm32f429-evaluation: Disable CONFIG_NET flag

2019-09-17 Thread Patrice Chotard
Network support was never added on this board, disable
CONFIG_NET flag to avoid following warning:

= WARNING ==
This board does not use CONFIG_DM_ETH (Driver Model
for Ethernet drivers). Please update the board to use
CONFIG_DM_ETH before the v2020.07 release. Failure to
update by the deadline may result in board removal.
See doc/driver-model/migration.rst for more info.


Signed-off-by: Patrice Chotard 
---

 configs/stm32f429-evaluation_defconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configs/stm32f429-evaluation_defconfig 
b/configs/stm32f429-evaluation_defconfig
index 51f587f629..2b118a0dff 100644
--- a/configs/stm32f429-evaluation_defconfig
+++ b/configs/stm32f429-evaluation_defconfig
@@ -17,12 +17,12 @@ CONFIG_CMD_GPT=y
 # CONFIG_RANDOM_UUID is not set
 CONFIG_CMD_MMC=y
 # CONFIG_CMD_SETEXPR is not set
-# CONFIG_CMD_MII is not set
 CONFIG_CMD_CACHE=y
 CONFIG_CMD_TIMER=y
 # CONFIG_ISO_PARTITION is not set
 CONFIG_OF_CONTROL=y
 CONFIG_DEFAULT_DEVICE_TREE="stm32429i-eval"
+# CONFIG_NET is not set
 CONFIG_DM_MMC=y
 CONFIG_ARM_PL180_MMCI=y
 CONFIG_MTD_NOR_FLASH=y
-- 
2.17.1

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


[U-Boot] [PATCH 3/5] configs: stm32f469-discovery: Disable CONFIG_NET flag

2019-09-17 Thread Patrice Chotard
Network support was never added on this board, disable
CONFIG_NET flag to avoid following warning:

= WARNING ==
This board does not use CONFIG_DM_ETH (Driver Model
for Ethernet drivers). Please update the board to use
CONFIG_DM_ETH before the v2020.07 release. Failure to
update by the deadline may result in board removal.
See doc/driver-model/migration.rst for more info.


Signed-off-by: Patrice Chotard 
---

 configs/stm32f469-discovery_defconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configs/stm32f469-discovery_defconfig 
b/configs/stm32f469-discovery_defconfig
index dcd0697677..5cedb765d1 100644
--- a/configs/stm32f469-discovery_defconfig
+++ b/configs/stm32f469-discovery_defconfig
@@ -18,12 +18,12 @@ CONFIG_CMD_GPT=y
 CONFIG_CMD_MMC=y
 CONFIG_CMD_SF=y
 # CONFIG_CMD_SETEXPR is not set
-# CONFIG_CMD_MII is not set
 CONFIG_CMD_CACHE=y
 CONFIG_CMD_TIMER=y
 # CONFIG_ISO_PARTITION is not set
 CONFIG_OF_CONTROL=y
 CONFIG_DEFAULT_DEVICE_TREE="stm32f469-disco"
+# CONFIG_NET is not set
 CONFIG_DM_MMC=y
 CONFIG_ARM_PL180_MMCI=y
 CONFIG_MTD=y
-- 
2.17.1

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


[U-Boot] [PATCH 4/5] configs: stm32h743-disco: Disable CONFIG_NET flag

2019-09-17 Thread Patrice Chotard
Network support was never added on this board, disable
CONFIG_NET flag to avoid following warning:

= WARNING ==
This board does not use CONFIG_DM_ETH (Driver Model
for Ethernet drivers). Please update the board to use
CONFIG_DM_ETH before the v2020.07 release. Failure to
update by the deadline may result in board removal.
See doc/driver-model/migration.rst for more info.


Signed-off-by: Patrice Chotard 
---

 configs/stm32h743-disco_defconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/configs/stm32h743-disco_defconfig 
b/configs/stm32h743-disco_defconfig
index 1691c2ea19..ea4c128430 100644
--- a/configs/stm32h743-disco_defconfig
+++ b/configs/stm32h743-disco_defconfig
@@ -24,6 +24,7 @@ CONFIG_CMD_EXT4_WRITE=y
 # CONFIG_ISO_PARTITION is not set
 CONFIG_OF_CONTROL=y
 CONFIG_DEFAULT_DEVICE_TREE="stm32h743i-disco"
+# CONFIG_NET is not set
 CONFIG_DM_MMC=y
 CONFIG_STM32_SDMMC2=y
 # CONFIG_PINCTRL_FULL is not set
-- 
2.17.1

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


[U-Boot] [PATCH 0/5] Disable CONFIG_NET flag for STM32F4 and STM32H7 boards

2019-09-17 Thread Patrice Chotard

All STM32F4 and STM32H7 boards have CONFIG_NET flags enable in
their defconfig whereas network support was never added. Simply
disable CONFIG_NET to avoid following compilation warning:

= WARNING ==
This board does not use CONFIG_DM_ETH (Driver Model
for Ethernet drivers). Please update the board to use
CONFIG_DM_ETH before the v2020.07 release. Failure to
update by the deadline may result in board removal.
See doc/driver-model/migration.rst for more info.



Patrice Chotard (5):
  configs: stm32f429-discovery: Disable CONFIG_NET flag
  configs: stm32f429-evaluation: Disable CONFIG_NET flag
  configs: stm32f469-discovery: Disable CONFIG_NET flag
  configs: stm32h743-disco: Disable CONFIG_NET flag
  configs: stm32h743-eval: Disable CONFIG_NET flag

 configs/stm32f429-discovery_defconfig  | 1 +
 configs/stm32f429-evaluation_defconfig | 2 +-
 configs/stm32f469-discovery_defconfig  | 2 +-
 configs/stm32h743-disco_defconfig  | 1 +
 configs/stm32h743-eval_defconfig   | 1 +
 5 files changed, 5 insertions(+), 2 deletions(-)

-- 
2.17.1

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


[U-Boot] [PATCH 5/5] configs: stm32h743-eval: Disable CONFIG_NET flag

2019-09-17 Thread Patrice Chotard
Network support was never added on this board, disable
CONFIG_NET flag to avoid following warning:

= WARNING ==
This board does not use CONFIG_DM_ETH (Driver Model
for Ethernet drivers). Please update the board to use
CONFIG_DM_ETH before the v2020.07 release. Failure to
update by the deadline may result in board removal.
See doc/driver-model/migration.rst for more info.


Signed-off-by: Patrice Chotard 
---

 configs/stm32h743-eval_defconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/configs/stm32h743-eval_defconfig b/configs/stm32h743-eval_defconfig
index e1c6cbf503..cacfdb5eb2 100644
--- a/configs/stm32h743-eval_defconfig
+++ b/configs/stm32h743-eval_defconfig
@@ -24,6 +24,7 @@ CONFIG_CMD_EXT4_WRITE=y
 # CONFIG_ISO_PARTITION is not set
 CONFIG_OF_CONTROL=y
 CONFIG_DEFAULT_DEVICE_TREE="stm32h743i-eval"
+# CONFIG_NET is not set
 CONFIG_DM_MMC=y
 CONFIG_STM32_SDMMC2=y
 # CONFIG_PINCTRL_FULL is not set
-- 
2.17.1

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


Re: [U-Boot] [PATCH 2/4] habv4: tools: Avoid hardcoded CSF size for SPL targets

2019-09-17 Thread Stefano Babic
On 17/09/19 05:26, Breno Matheus Lima wrote:
> Hi Stefano,
> 
> Em seg, 16 de set de 2019 às 05:17, Stefano Babic  escreveu:
>>
>> Hi Breno,
>>
>> On 12/09/19 03:07, Peng Fan wrote:
>>> Hi Breno,
>>>
 Subject: [PATCH 2/4] habv4: tools: Avoid hardcoded CSF size for SPL targets
>>>
>>> I saw this patch in imx/master, not in Tom's tree. But this patch breaks
>>> build for other archs, such as arc and etc.
>>>
>>
>> Any news on this ? I dropped it from u-boot-imx due the breakage, but I
>> can easy pick it up again if it will be fixed.
>>
> 
> Sorry the delay. I'm still trying to reproduce the issue, probably
> something is missing in my buildman setup.

It looks like that a header is missing, maybe this came together with
the moving to a common place for gzip & Co (patch for Simon). I think it
could be easy for you to reproduce if you set current u-boot-imx.

> 
> One workaround would be to enclose the code with CONFIG_SECURE_BOOT,
> this code is only used by IH_TYPE_FIRMWARE_IVT which requires HAB to
> be enabled. I can send a patch but I would like to confirm before.

Nevertheless, HAB code should be put in just if needed. I agree on the
patch independently from the issue.

Regards,
Stefano

> 
> Thanks,
> Breno Lima
> 


-- 
=
DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sba...@denx.de
=
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] rockchip: rk3399: TPL: rockpro64: Wrong memory size detected

2019-09-17 Thread Jagan Teki
On Thu, Aug 29, 2019 at 3:15 AM Kurt Miller  wrote:
>
> The board has 4G memory but only 2G is detected by TPL. Please
> let me know if additional information is needed.
>
> With u-boot master TPL output:
>
> U-Boot TPL 2019.10-rc3-00020-ge4b8dd9b34-dirty (Aug 28 2019 - 17:26:44)
> LPDDR4, 50MHz
> BW=32 Col=10 Bk=8 CS0 Row=15 CS=1 Die BW=16 Size=1024MB
> LPDDR4, 50MHz
> BW=32 Col=10 Bk=8 CS0 Row=15 CS=1 Die BW=16 Size=1024MB
> 256B stride
> Trying to boot from BOOTROM
> Returning to boot ROM...

U-Boot TPL 2019.10-rc3-00333-g5d07dd3f42-dirty (Sep 17 2019 - 14:52:32)
Channel 0: LPDDR4, 50MHz
BW=32 Col=10 Bk=8 CS0 Row=15 CS1 Row=15 CS=2 Die BW=16 Size=2048MB
Channel 1: LPDDR4, 50MHz
BW=32 Col=10 Bk=8 CS0 Row=15 CS1 Row=15 CS=2 Die BW=16 Size=2048MB
256B stride
lpddr4_set_rate: change freq to 400 mhz 0, 1
lpddr4_set_rate: change freq to 800 mhz 1, 0
Trying to boot from BOOTROM
Returning to boot ROM...

Please check it I can able to detect 2GB each channel, so total 4GB.
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH V2 1/2] power: domain: add dev_power_domain_on

2019-09-17 Thread Peng Fan
Add this new API to power on multiple domains attached
to a device.

Signed-off-by: Peng Fan 
---

V2:
 New patch

 drivers/power/domain/power-domain-uclass.c | 19 +++
 include/power-domain.h | 17 +
 2 files changed, 36 insertions(+)

diff --git a/drivers/power/domain/power-domain-uclass.c 
b/drivers/power/domain/power-domain-uclass.c
index 2ea0ff24c7..95aa9b30ef 100644
--- a/drivers/power/domain/power-domain-uclass.c
+++ b/drivers/power/domain/power-domain-uclass.c
@@ -107,6 +107,25 @@ int power_domain_off(struct power_domain *power_domain)
return ops->off(power_domain);
 }
 
+int dev_power_domain_on(struct udevice *dev)
+{
+   struct power_domain pd;
+   int i, count, ret;
+
+   count = dev_count_phandle_with_args(dev, "power-domains",
+   "#power-domain-cells");
+   for (i = 0; i < count; i++) {
+   ret = power_domain_get_by_index(dev, &pd, i);
+   if (ret)
+   return ret;
+   ret = power_domain_on(&pd);
+   if (ret)
+   return ret;
+   }
+
+   return 0;
+}
+
 UCLASS_DRIVER(power_domain) = {
.id = UCLASS_POWER_DOMAIN,
.name   = "power_domain",
diff --git a/include/power-domain.h b/include/power-domain.h
index ef15dc9f60..23a63f3b18 100644
--- a/include/power-domain.h
+++ b/include/power-domain.h
@@ -155,4 +155,21 @@ static inline int power_domain_off(struct power_domain 
*power_domain)
 }
 #endif
 
+/**
+ * dev_power_domain_on - Enable power domains for a device .
+ *
+ * @dev:   The client device.
+ *
+ * @return 0 if OK, or a negative error code.
+ */
+#if (CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)) && \
+   CONFIG_IS_ENABLED(POWER_DOMAIN)
+int dev_power_domain_on(struct udevice *dev);
+#else
+int dev_power_domain_on(struct udevice *dev)
+{
+   return 0;
+}
+#endif
+
 #endif
-- 
2.16.4

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


[U-Boot] [PATCH V2 2/2] core: device: use dev_power_domain_on

2019-09-17 Thread Peng Fan
When multiple power domains attached to a device, need power on
them all, so use dev_power_domain_on to do that.

Signed-off-by: Peng Fan 
---

V2:
 use dev_power_domain_on in patch 1/2

 drivers/core/device.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/core/device.c b/drivers/core/device.c
index 05dadf98f9..f4d7140698 100644
--- a/drivers/core/device.c
+++ b/drivers/core/device.c
@@ -307,7 +307,6 @@ static void *alloc_priv(int size, uint flags)
 
 int device_probe(struct udevice *dev)
 {
-   struct power_domain pd;
const struct driver *drv;
int size = 0;
int ret;
@@ -390,8 +389,9 @@ int device_probe(struct udevice *dev)
 
if (CONFIG_IS_ENABLED(POWER_DOMAIN) && dev->parent &&
device_get_uclass_id(dev) != UCLASS_POWER_DOMAIN) {
-   if (!power_domain_get(dev, &pd))
-   power_domain_on(&pd);
+   ret = dev_power_domain_on(dev);
+   if (ret)
+   goto fail;
}
 
ret = uclass_pre_probe_device(dev);
-- 
2.16.4

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


Re: [U-Boot] rockchip: rk3399: TPL: rockpro64: Wrong memory size detected

2019-09-17 Thread Jagan Teki
On Thu, Aug 29, 2019 at 3:15 AM Kurt Miller  wrote:
>
> The board has 4G memory but only 2G is detected by TPL. Please
> let me know if additional information is needed.
>
> With u-boot master TPL output:
>
> U-Boot TPL 2019.10-rc3-00020-ge4b8dd9b34-dirty (Aug 28 2019 - 17:26:44)
> LPDDR4, 50MHz
> BW=32 Col=10 Bk=8 CS0 Row=15 CS=1 Die BW=16 Size=1024MB
> LPDDR4, 50MHz
> BW=32 Col=10 Bk=8 CS0 Row=15 CS=1 Die BW=16 Size=1024MB
> 256B stride
> Trying to boot from BOOTROM
> Returning to boot ROM...

So, even tired the same commit.

U-Boot TPL 2019.10-rc3-00020-ge4b8dd9b34-dirty (Sep 17 2019 - 15:01:07)
Channel 0: LPDDR4, 50MHz
BW=32 Col=10 Bk=8 CS0 Row=15 CS1 Row=15 CS=2 Die BW=16 Size=2048MB
Channel 1: LPDDR4, 50MHz
BW=32 Col=10 Bk=8 CS0 Row=15 CS1 Row=15 CS=2 Die BW=16 Size=2048MB
256B stride
lpddr4_set_rate: change freq to 400 mhz 0, 1
lpddr4_set_rate: change freq to 800 mhz 1, 0
Trying to boot from BOOTROM
Returning to boot ROM...
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH] armv8: ls1028a: add more personalities support

2019-09-17 Thread Priyanka Jain


>-Original Message-
>From: U-Boot  On Behalf Of Yuantian Tang
>Sent: Tuesday, September 17, 2019 8:21 AM
>To: Prabhakar Kushwaha 
>Cc: Andy Tang ; u-boot@lists.denx.de
>Subject: [U-Boot] [PATCH] armv8: ls1028a: add more personalities support
Be more specific about which personalities in subject. May be something like
armv8: ls1028a: add ls1018a, ls1027a, ls1017a support

>
>Add three more personalities support to LS1028A processor soc family.
Same as above
>
>LS1028A processor is the prime personality of LS1028A soc family.
>LS1027A processor is a lower funtionality version of QorIQ LS1028A which
>does not support the multimedia subsystems, such as LCD controller, GPU,
>and eDP PHY.
>The QorIQ LS1018A and LS1017A are low power versions of the QorIQ LS1028A
>and LS1027A processors, respectively which integrate single 64-bit Arm A72
>core.
>
>Signed-off-by: Tang Yuantian 
>---

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


Re: [U-Boot] [PATCH v1 18/20] configs: enable eSDHC device module for T1042D4RDB board

2019-09-17 Thread Priyanka Jain


>-Original Message-
>From: Yinbo Zhu 
>Sent: Tuesday, September 17, 2019 8:26 AM
>To: Wolfgang Denk ; Priyanka Jain ;
>Shengzhou Liu ; u-boot@lists.denx.de
>Cc: Yinbo Zhu ; Xiaobo Xie ;
>Jiafei Pan ; Prabhakar Kushwaha
>; Bin Meng ; Simon
>Goldschmidt ; Adam Ford
>; Patrick Delaunay ; Jeremy
>Gebben ; Joe Hershberger
>; Y.b. Lu 
>Subject: [PATCH v1 18/20] configs: enable eSDHC device module for
>T1042D4RDB board
Better to add T1042D4RDB in prefix. Something like
configs: T1042D4RDB: enable eSDHC device module for
>
>This patch is to enable eSDHC device module for T1042D4RDB board
No need of string : "This patch is to"
>
>Signed-off-by: Yinbo Zhu 
>---


Same comments for other similar patches

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


Re: [U-Boot] [PATCH 04/14] dfu: allow to manage DFU on several devices

2019-09-17 Thread Lukasz Majewski
Hi Patrick,

> Add support of DFU for several interface/device
> with one command.
> 
> The format for "dfu_alt_info" in this case is :
>   interface with devstring'='alternate list (';' separated)
>   and each interface is separated by '&'
> 
> The previous behavior is always supported.
> 
> One example for NOR (bootloaders) + NAND (rootfs in UBI):
> 
> U-Boot> env set dfu_alt_info \
> "sf 0:0:1000:0=spl part 0 1;u-boot part 0 2; \
> u-boot-env part 0 3&nand 0=UBI partubi 0,3"
> 
> U-Boot> dfu 0 list
> 
> DFU alt settings list:
> dev: SF alt: 0 name: spl layout: RAW_ADDR
> dev: SF alt: 1 name: ssbl layout: RAW_ADDR
> dev: SF alt: 2 name: u-boot-env layout: RAW_ADDR
> dev: NAND alt: 3 name: UBI layout: RAW_ADDR
> 
> U-Boot> dfu 0
> 
> $> dfu-util -l  
> 
> Found DFU: [0483:5720] ver=, devnum=96, cfg=1,\
>  intf=0, alt=3, name="UBI", serial="00270038511934383330"
> Found DFU: [0483:5720] ver=, devnum=96, cfg=1,\
>  intf=0, alt=2, name="u-boot-env", serial="00270038511934383330"
> Found DFU: [0483:5720] ver=, devnum=96, cfg=1,\
>  intf=0, alt=1, name="u-boot", serial="00270038511934383330"
> Found DFU: [0483:5720] ver=, devnum=96, cfg=1,\
>  intf=0, alt=0, name="spl", serial="00270038511934383330"
> 

My two remarks:

1. As you mentioned above - the current behavior must be preserved
(this is my main concern).

2. You added the example of usage to the commit message. Could you also
add it to the ./doc/README.dfu (not yet present) file ?

Anyway, thanks for your work :-)

> Signed-off-by: Patrick Delaunay 

Acked-by: Lukasz Majewski 

> ---
> 
>  cmd/dfu.c | 21 ++---
>  drivers/dfu/dfu.c | 60
> ++- 2 files changed, 72
> insertions(+), 9 deletions(-)
> 
> diff --git a/cmd/dfu.c b/cmd/dfu.c
> index 91a750a4fc..33491d0bc9 100644
> --- a/cmd/dfu.c
> +++ b/cmd/dfu.c
> @@ -21,23 +21,28 @@
>  static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const
> argv[]) {
>  
> - if (argc < 4)
> + if (argc < 2)
>   return CMD_RET_USAGE;
>  
>  #ifdef CONFIG_DFU_OVER_USB
>   char *usb_controller = argv[1];
>  #endif
>  #if defined(CONFIG_DFU_OVER_USB) || defined(CONFIG_DFU_OVER_TFTP)
> - char *interface = argv[2];
> - char *devstring = argv[3];
> + char *interface = NULL;
> + char *devstring = NULL;
> +
> + if (argc >= 4) {
> + interface = argv[2];
> + devstring = argv[3];
> + }
>  #endif
>  
>   int ret = 0;
>  #ifdef CONFIG_DFU_OVER_TFTP
>   unsigned long addr = 0;
>   if (!strcmp(argv[1], "tftp")) {
> - if (argc == 5)
> - addr = simple_strtoul(argv[4], NULL, 0);
> + if (argc == 5 || argc == 3)
> + addr = simple_strtoul(argv[argc - 1], NULL,
> 0); 
>   return update_tftp(addr, interface, devstring);
>   }
> @@ -48,7 +53,7 @@ static int do_dfu(cmd_tbl_t *cmdtp, int flag, int
> argc, char * const argv[]) goto done;
>  
>   ret = CMD_RET_SUCCESS;
> - if (argc > 4 && strcmp(argv[4], "list") == 0) {
> + if (strcmp(argv[argc - 1], "list") == 0) {
>   dfu_show_entities();
>   goto done;
>   }
> @@ -67,7 +72,7 @@ U_BOOT_CMD(dfu, CONFIG_SYS_MAXARGS, 1, do_dfu,
>   "Device Firmware Upgrade",
>   ""
>  #ifdef CONFIG_DFU_OVER_USB
> - "   [list]\n"
> + " [ ] [list]\n"
>   "  - device firmware upgrade via \n"
>   "on device , attached to interface\n"
>   "\n"
> @@ -77,7 +82,7 @@ U_BOOT_CMD(dfu, CONFIG_SYS_MAXARGS, 1, do_dfu,
>  #ifdef CONFIG_DFU_OVER_USB
>   "dfu "
>  #endif
> - "tftp   []\n"
> + "tftp [ ] []\n"
>   "  - device firmware upgrade via TFTP\n"
>   "on device , attached to interface\n"
>   "\n"
> diff --git a/drivers/dfu/dfu.c b/drivers/dfu/dfu.c
> index 900a844d15..8bd5216017 100644
> --- a/drivers/dfu/dfu.c
> +++ b/drivers/dfu/dfu.c
> @@ -53,6 +53,54 @@ static int dfu_find_alt_num(const char *s)
>   return ++i;
>  }
>  
> +/*
> + * treat dfu_alt_info with several interface information
> + * to allow DFU on several device with one command,
> + * the string format is
> + * interface devstring'='alternate list (';' separated)
> + * and each interface separated by '&'
> + */
> +int dfu_config_interfaces(char *env)
> +{
> + struct dfu_entity *dfu;
> + char *s, *i, *d, *a, *part;
> + int ret = -EINVAL;
> + int n = 1;
> +
> + s = env;
> + for (; *s; s++) {
> + if (*s == ';')
> + n++;
> + if (*s == '&')
> + n++;
> + }
> + ret = dfu_alt_init(n, &dfu);
> + if (ret)
> + return ret;
> +
> + s = env;
> + while (s) {
> + ret = -EINVAL;
> + i = strsep(&s, " ");
> + if (!i)
> + break;
> + d = strsep(&s, "=");
> + if (!d)
> + break;
> +   

Re: [U-Boot] [PATCH 05/14] dfu: allow read with 0 data for EOF indication

2019-09-17 Thread Lukasz Majewski
Hi Patrick,

> This patch allows into the DFU backend to indicate that there is no
> remaining data (for EOF for example). That allows users to read a
> buffer greater than the device size; the dfu stack stops the read
> request when the backend return a length=0 without error.
> 
> Signed-off-by: Patrick Delaunay 
> ---
> 
>  drivers/dfu/dfu.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/dfu/dfu.c b/drivers/dfu/dfu.c
> index 8bd5216017..50919fcae9 100644
> --- a/drivers/dfu/dfu.c
> +++ b/drivers/dfu/dfu.c
> @@ -396,6 +396,8 @@ static int dfu_read_buffer_fill(struct dfu_entity
> *dfu, void *buf, int size) debug("%s: Read error!\n", __func__);
>   return ret;
>   }
> + if (dfu->b_left == 0)
> + break;

I guess that this is the use case for sending commands?

Could you provide a more descriptive use case for this change (the
description in the above commit message is not enough for me to get it).

>   dfu->offset += dfu->b_left;
>   dfu->r_left -= dfu->b_left;
>  



Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lu...@denx.de


pgp0sHBBzA3e3.pgp
Description: OpenPGP digital signature
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH 06/14] dfu: add backend for MTD device

2019-09-17 Thread Lukasz Majewski
Hi Patrick,

> Add DFU backend for MTD device: allow to read
> and write on any MTD device (RAW or SPI)
> 
> For example :
> > set dfu_alt_info "nand_raw raw 0x0 0x10"
> > dfu 0 mtd nand0  
> 
> This MTD backend provides the same level than dfu nand
 ^ - shouldn't there be
 "functionality" or such?

> backend for NAND in RAW mode and sf backend for NOR;
> So it can replace booth of them but it can also
> add support of spi-nand.

If I understood correctly - it allows reading "raw" data from MTD
device - NAND, SPI-NOR and SPI-NAND?

> 
> > set dfu_alt_info "nand_raw raw 0x0 0x10"
> > dfu 0 mtd spi-nand0  
> 
> The backend code is based on the MTD command
> introduced by commit 5db66b3aee6f ("cmd: mtd:
> add 'mtd' command")
> 
> Signed-off-by: Patrick Delaunay 
> ---
> 
>  drivers/dfu/Kconfig   |   6 ++
>  drivers/dfu/Makefile  |   1 +
>  drivers/dfu/dfu.c |   5 +-
>  drivers/dfu/dfu_mtd.c | 230
> ++ include/dfu.h |
> 21  5 files changed, 262 insertions(+), 1 deletion(-)
>  create mode 100644 drivers/dfu/dfu_mtd.c
> 
> diff --git a/drivers/dfu/Kconfig b/drivers/dfu/Kconfig
> index 4692736c9d..ee664a331b 100644
> --- a/drivers/dfu/Kconfig
> +++ b/drivers/dfu/Kconfig
> @@ -46,5 +46,11 @@ config DFU_SF
> This option enables using DFU to read and write to SPI
> flash based storage.
>  
> +config DFU_MTD
> + bool "MTD back end for DFU"
> + depends on MTD
> + help
> +   This option enables using DFU to read and write to on any
> MTD device. +
>  endif
>  endmenu
> diff --git a/drivers/dfu/Makefile b/drivers/dfu/Makefile
> index 4164f342ac..ebb119f398 100644
> --- a/drivers/dfu/Makefile
> +++ b/drivers/dfu/Makefile
> @@ -5,6 +5,7 @@
>  
>  obj-$(CONFIG_$(SPL_)DFU) += dfu.o
>  obj-$(CONFIG_$(SPL_)DFU_MMC) += dfu_mmc.o
> +obj-$(CONFIG_$(SPL_)DFU_MTD) += dfu_mtd.o
>  obj-$(CONFIG_$(SPL_)DFU_NAND) += dfu_nand.o
>  obj-$(CONFIG_$(SPL_)DFU_RAM) += dfu_ram.o
>  obj-$(CONFIG_$(SPL_)DFU_SF) += dfu_sf.o
> diff --git a/drivers/dfu/dfu.c b/drivers/dfu/dfu.c
> index 50919fcae9..4f4a07b790 100644
> --- a/drivers/dfu/dfu.c
> +++ b/drivers/dfu/dfu.c
> @@ -462,6 +462,9 @@ static int dfu_fill_entity(struct dfu_entity
> *dfu, char *s, int alt, if (strcmp(interface, "mmc") == 0) {
>   if (dfu_fill_entity_mmc(dfu, devstr, s))
>   return -1;
> + } else if (strcmp(interface, "mtd") == 0) {
> + if (dfu_fill_entity_mtd(dfu, devstr, s))
> + return -1;
>   } else if (strcmp(interface, "nand") == 0) {
>   if (dfu_fill_entity_nand(dfu, devstr, s))
>   return -1;
> @@ -566,7 +569,7 @@ int dfu_config_entities(char *env, char
> *interface, char *devstr) const char *dfu_get_dev_type(enum
> dfu_device_type t) {
>   const char *const dev_t[] = {NULL, "eMMC", "OneNAND",
> "NAND", "RAM",
> -  "SF"};
> +  "SF", "MTD"};
>   return dev_t[t];
>  }
>  
> diff --git a/drivers/dfu/dfu_mtd.c b/drivers/dfu/dfu_mtd.c
> new file mode 100644
> index 00..1168a6e278
> --- /dev/null
> +++ b/drivers/dfu/dfu_mtd.c
> @@ -0,0 +1,230 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * dfu_mtd.c -- DFU for MTD device.
> + *
> + * Copyright (C) 2019,STMicroelectronics - All Rights Reserved
> + *
> + * Based on dfu_nand.c
> + */
> +
> +#include 
> +#include 
> +#include 
> +
> +static bool mtd_is_aligned_with_block_size(struct mtd_info *mtd, u64
> size) +{
> + return !do_div(size, mtd->erasesize);
> +}
> +
> +static int mtd_block_op(enum dfu_op op, struct dfu_entity *dfu,
> + u64 offset, void *buf, long *len)
> +{
> + u64 off, lim, remaining;
> + struct mtd_info *mtd = dfu->data.mtd.info;
> + struct mtd_oob_ops io_op = {};
> + int ret = 0;
> + bool has_pages = mtd->type == MTD_NANDFLASH ||
> +  mtd->type == MTD_MLCNANDFLASH;
> +
> + /* if buf == NULL return total size of the area */
> + if (!buf) {
> + *len = dfu->data.mtd.size;
> + return 0;
> + }
> +
> + off = dfu->data.mtd.start + offset + dfu->bad_skip;
> + lim = dfu->data.mtd.start + dfu->data.mtd.size;
> +
> + if (off >= lim) {
> + printf("Limit reached 0x%llx\n", lim);
> + *len = 0;
> + return op == DFU_OP_READ ? 0 : -EIO;
> + }
> + /* limit request with the available size */
> + if (off + *len >= lim)
> + *len = lim - off;
> +
> + if (!mtd_is_aligned_with_block_size(mtd, off)) {
> + printf("Offset not aligned with a block (0x%x)\n",
> +mtd->erasesize);
> + return 0;
> + }
> +
> + /* first erase */
> + if (op == DFU_OP_WRITE) {
> + struct erase_info erase_op = {};
> +
> + erase_op.mtd = mtd;
> + erase_op.addr 

Re: [U-Boot] [PATCH 07/14] dfu: add partition support for MTD backend

2019-09-17 Thread Lukasz Majewski
Hi Patrick,

> Add the support of MTD partition for the MTD backend.
> 
> The expected dfu_alt_info for one alternate on the mtd device :
>part 
>  partubi 
> 
> "partubi" also erase up to the end of the partition after write
> operation.
> 
> For example: dfu_alt_info = "spl part 1;u-boot part 2; UBI partubi 3"
> 
> U-Boot> dfu 0 mtd nand0

The above information shall also be placed to dedicated
./doc/README.dfu file.

> 
> Signed-off-by: Patrick Delaunay 

Acked-by: Lukasz Majewski 

> ---
> 
>  drivers/dfu/dfu_mtd.c | 78
> ++- include/dfu.h |
> 2 ++ 2 files changed, 79 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/dfu/dfu_mtd.c b/drivers/dfu/dfu_mtd.c
> index 1168a6e278..223b0fe977 100644
> --- a/drivers/dfu/dfu_mtd.c
> +++ b/drivers/dfu/dfu_mtd.c
> @@ -10,6 +10,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  
>  static bool mtd_is_aligned_with_block_size(struct mtd_info *mtd, u64
> size) {
> @@ -181,11 +182,49 @@ static int dfu_write_medium_mtd(struct
> dfu_entity *dfu, 
>  static int dfu_flush_medium_mtd(struct dfu_entity *dfu)
>  {
> + struct mtd_info *mtd = dfu->data.mtd.info;
> + int ret;
> +
> + /* in case of ubi partition, erase rest of the partition */
> + if (dfu->data.nand.ubi) {
> + struct erase_info erase_op = {};
> +
> + erase_op.mtd = dfu->data.mtd.info;
> + erase_op.addr = round_up(dfu->data.mtd.start +
> dfu->offset +
> +  dfu->bad_skip,
> mtd->erasesize);
> + erase_op.len = dfu->data.mtd.start +
> dfu->data.mtd.size -
> +erase_op.addr;
> + erase_op.scrub = 0;
> +
> + while (erase_op.len) {
> + ret = mtd_erase(mtd, &erase_op);
> + /* Abort if its not a bad block error */
> + if (ret != -EIO)
> + break;
> +
> + printf("Skipping bad block at 0x%08llx\n",
> +erase_op.fail_addr);
> +
> + /* Skip bad block and continue behind it */
> + erase_op.addr = erase_op.fail_addr +
> mtd->erasesize;
> + erase_op.len = dfu->data.mtd.start +
> +dfu->data.mtd.size -
> +erase_op.addr;
> + }
> + }
>   return 0;
>  }
>  
>  static unsigned int dfu_polltimeout_mtd(struct dfu_entity *dfu)
>  {
> + /*
> +  * Currently, Poll Timeout != 0 is only needed on nand
> +  * ubi partition, as sectors which are not used need
> +  * to be erased
> +  */
> + if (dfu->data.nand.ubi)
> + return DFU_MANIFEST_POLL_TIMEOUT;
> +
>   return DFU_DEFAULT_POLL_TIMEOUT;
>  }
>  
> @@ -194,6 +233,7 @@ int dfu_fill_entity_mtd(struct dfu_entity *dfu,
> char *devstr, char *s) char *st;
>   struct mtd_info *mtd;
>   bool has_pages;
> + int ret, part;
>  
>   mtd = get_mtd_device_nm(devstr);
>   if (IS_ERR_OR_NULL(mtd))
> @@ -212,11 +252,47 @@ int dfu_fill_entity_mtd(struct dfu_entity *dfu,
> char *devstr, char *s) dfu->data.mtd.start = simple_strtoul(s, &s,
> 16); s++;
>   dfu->data.mtd.size = simple_strtoul(s, &s, 16);
> + } else if ((!strcmp(st, "part")) || (!strcmp(st,
> "partubi"))) {
> + char mtd_id[32];
> + struct mtd_device *mtd_dev;
> + u8 part_num;
> + struct part_info *pi;
> +
> + dfu->layout = DFU_RAW_ADDR;
> +
> + part = simple_strtoul(s, &s, 10);
> +
> + sprintf(mtd_id, "%s,%d", devstr, part - 1);
> + printf("using id '%s'\n", mtd_id);
> +
> + mtdparts_init();
> +
> + ret = find_dev_and_part(mtd_id, &mtd_dev, &part_num,
> &pi);
> + if (ret != 0) {
> + printf("Could not locate '%s'\n", mtd_id);
> + return -1;
> + }
> +
> + dfu->data.mtd.start = pi->offset;
> + dfu->data.mtd.size = pi->size;
> + if (!strcmp(st, "partubi"))
> + dfu->data.mtd.ubi = 1;
>   } else {
> - printf("%s: (%s) not supported!\n", __func__, st);
> + printf("%s: Memory layout (%s) not supported!\n",
> __func__, st); return -1;
>   }
>  
> + if (!mtd_is_aligned_with_block_size(mtd,
> dfu->data.mtd.start)) {
> + printf("Offset not aligned with a block (0x%x)\n",
> +mtd->erasesize);
> + return -EINVAL;
> + }
> + if (!mtd_is_aligned_with_block_size(mtd,
> dfu->data.mtd.size)) {
> + printf("Size not aligned with a block (0x%x)\n",
> +mtd->erasesize);
> + return -EINVAL;
> + }
> +
>   dfu->get_medium_size = dfu_get_medium_size_mtd;
>   dfu->read_medium = dfu_read_medium_mtd;
>   dfu->write_medi

Re: [U-Boot] [PATCH 08/14] dfu: add DFU virtual backend

2019-09-17 Thread Lukasz Majewski
Hi Patrick,

> Add a virtual DFU backend to allow board specific read and write
> (for OTP update for example).
> 
> Signed-off-by: Patrick Delaunay 
> ---
> 
>  drivers/dfu/Kconfig|  7 ++
>  drivers/dfu/Makefile   |  1 +
>  drivers/dfu/dfu.c  |  5 -
>  drivers/dfu/dfu_virt.c | 49
> ++ include/dfu.h  |
> 22 +++ 5 files changed, 83 insertions(+), 1
> deletion(-) create mode 100644 drivers/dfu/dfu_virt.c
> 
> diff --git a/drivers/dfu/Kconfig b/drivers/dfu/Kconfig
> index ee664a331b..c0e6e5d8f0 100644
> --- a/drivers/dfu/Kconfig
> +++ b/drivers/dfu/Kconfig
> @@ -52,5 +52,12 @@ config DFU_MTD
>   help
> This option enables using DFU to read and write to on any
> MTD device. 
> +config DFU_VIRT
> + bool "VIRTUAL flash back end for DFU"
> + help
> +   This option enables using DFU to read and write to VIRTUAL
> device
> +   used at board level to manage specific behavior
> +   (OTP update for example).
> +
>  endif
>  endmenu
> diff --git a/drivers/dfu/Makefile b/drivers/dfu/Makefile
> index ebb119f398..0d7925c083 100644
> --- a/drivers/dfu/Makefile
> +++ b/drivers/dfu/Makefile
> @@ -10,3 +10,4 @@ obj-$(CONFIG_$(SPL_)DFU_NAND) += dfu_nand.o
>  obj-$(CONFIG_$(SPL_)DFU_RAM) += dfu_ram.o
>  obj-$(CONFIG_$(SPL_)DFU_SF) += dfu_sf.o
>  obj-$(CONFIG_$(SPL_)DFU_TFTP) += dfu_tftp.o
> +obj-$(CONFIG_$(SPL_)DFU_VIRT) += dfu_virt.o
> diff --git a/drivers/dfu/dfu.c b/drivers/dfu/dfu.c
> index 4f4a07b790..2697235c24 100644
> --- a/drivers/dfu/dfu.c
> +++ b/drivers/dfu/dfu.c
> @@ -474,6 +474,9 @@ static int dfu_fill_entity(struct dfu_entity
> *dfu, char *s, int alt, } else if (strcmp(interface, "sf") == 0) {
>   if (dfu_fill_entity_sf(dfu, devstr, s))
>   return -1;
> + } else if (strcmp(interface, "virt") == 0) {
> + if (dfu_fill_entity_virt(dfu, devstr, s))
> + return -1;
>   } else {
>   printf("%s: Device %s not (yet) supported!\n",
>  __func__,  interface);
> @@ -569,7 +572,7 @@ int dfu_config_entities(char *env, char
> *interface, char *devstr) const char *dfu_get_dev_type(enum
> dfu_device_type t) {
>   const char *const dev_t[] = {NULL, "eMMC", "OneNAND",
> "NAND", "RAM",
> -  "SF", "MTD"};
> +  "SF", "MTD", "VIRT"};
>   return dev_t[t];
>  }
>  
> diff --git a/drivers/dfu/dfu_virt.c b/drivers/dfu/dfu_virt.c
> new file mode 100644
> index 00..ea8c71f100
> --- /dev/null
> +++ b/drivers/dfu/dfu_virt.c
> @@ -0,0 +1,49 @@
> +// SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
> +/*
> + * Copyright (C) 2019, STMicroelectronics - All Rights Reserved
> + */
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +int __weak dfu_write_medium_virt(struct dfu_entity *dfu, u64 offset,
> +  void *buf, long *len)
> +{
> + debug("%s: off=0x%llx, len=0x%x\n", __func__, offset,
> (u32)*len); +
> + return 0;
> +}
> +
> +int __weak dfu_get_medium_size_virt(struct dfu_entity *dfu, u64
> *size) +{
> + *size = 0;
> +
> + return 0;
> +}
> +
> +int __weak dfu_read_medium_virt(struct dfu_entity *dfu, u64 offset,
> + void *buf, long *len)
> +{
> + debug("%s: off=0x%llx, len=0x%x\n", __func__, offset,
> (u32)*len);
> + *len = 0;
> +
> + return 0;
> +}
> +
> +int dfu_fill_entity_virt(struct dfu_entity *dfu, char *devstr, char
> *s) +{
> + debug("%s: devstr = %s\n", __func__, devstr);
> +
> + dfu->dev_type = DFU_DEV_VIRT;
> + dfu->layout = DFU_RAW_ADDR;
> + dfu->data.virt.dev_num = simple_strtoul(devstr, NULL, 10);
> +
> + dfu->write_medium = dfu_write_medium_virt;
> + dfu->get_medium_size = dfu_get_medium_size_virt;
> + dfu->read_medium = dfu_read_medium_virt;
> +
> + dfu->inited = 0;
> +
> + return 0;
> +}
> diff --git a/include/dfu.h b/include/dfu.h
> index a90732cc43..4de7d35914 100644
> --- a/include/dfu.h
> +++ b/include/dfu.h
> @@ -23,6 +23,7 @@ enum dfu_device_type {
>   DFU_DEV_RAM,
>   DFU_DEV_SF,
>   DFU_DEV_MTD,
> + DFU_DEV_VIRT,
>  };
>  
>  enum dfu_layout {
> @@ -92,6 +93,10 @@ struct sf_internal_data {
>   unsigned int ubi;
>  };
>  
> +struct virt_internal_data {
> + int dev_num;
> +};
> +
>  #define DFU_NAME_SIZE32
>  #ifndef CONFIG_SYS_DFU_DATA_BUF_SIZE
>  #define CONFIG_SYS_DFU_DATA_BUF_SIZE
> (1024*1024*8) /* 8 MiB */ @@ -120,6 +125,7 @@ struct
> dfu_entity { struct nand_internal_data nand;
>   struct ram_internal_data ram;
>   struct sf_internal_data sf;
> + struct virt_internal_data virt;
>   } data;
>  
>   int (*get_medium_size)(struct dfu_entity *dfu, u64 *size);
> @@ -272,6 +278,22 @@ static inline int dfu_fill_entity_mtd(struct
> dfu_entity *dfu, char *devstr, }
>  #endif
>  
> +#ifdef CONFIG_DFU_VIRT
> +int dfu_fill_e

Re: [U-Boot] [PATCH 09/14] dfu: add callback for flush and initiated operation

2019-09-17 Thread Lukasz Majewski
Hi Patrick,

> Add weak callback to allow board specific behavior
> - flush
> - initiated
> 
> This patch prepare usage of DFU back end for communication with
> STM32CubeProgrammer on stm32mp1 platform with stm32prog command.

As I've said previously - please add this use case and info to
./doc/README.dtu.

> 
> Signed-off-by: Patrick Delaunay 
> ---
> 
>  drivers/dfu/dfu.c | 19 +++
>  include/dfu.h |  2 ++
>  2 files changed, 21 insertions(+)
> 
> diff --git a/drivers/dfu/dfu.c b/drivers/dfu/dfu.c
> index 2697235c24..f12c5afc66 100644
> --- a/drivers/dfu/dfu.c
> +++ b/drivers/dfu/dfu.c
> @@ -22,6 +22,22 @@ static int dfu_alt_num;
>  static int alt_num_cnt;
>  static struct hash_algo *dfu_hash_algo;
>  
> +/*
> + * The purpose of the dfu_flush_callback() function is to
> + * provide callback for dfu user
> + */
> +__weak void dfu_flush_callback(struct dfu_entity *dfu)
> +{
> +}
> +
> +/*
> + * The purpose of the dfu_flush_callback() function is to
> + * provide callback for dfu user

Please update this repeated comment.

> + */
> +__weak void dfu_initiated_callback(struct dfu_entity *dfu)
> +{
> +}
> +
>  /*
>   * The purpose of the dfu_usb_get_reset() function is to
>   * provide information if after USB_DETACH request
> @@ -263,6 +279,7 @@ int dfu_transaction_initiate(struct dfu_entity
> *dfu, bool read) }
>  
>   dfu->inited = 1;
> + dfu_initiated_callback(dfu);
>  
>   return 0;
>  }
> @@ -282,6 +299,8 @@ int dfu_flush(struct dfu_entity *dfu, void *buf,
> int size, int blk_seq_num) printf("\nDFU complete %s: 0x%08x\n",
> dfu_hash_algo->name, dfu->crc);
>  
> + dfu_flush_callback(dfu);
> +
>   dfu_transaction_cleanup(dfu);
>  
>   return ret;
> diff --git a/include/dfu.h b/include/dfu.h
> index 4de7d35914..5d85cc35ef 100644
> --- a/include/dfu.h
> +++ b/include/dfu.h
> @@ -182,6 +182,8 @@ bool dfu_usb_get_reset(void);
>  int dfu_read(struct dfu_entity *de, void *buf, int size, int
> blk_seq_num); int dfu_write(struct dfu_entity *de, void *buf, int
> size, int blk_seq_num); int dfu_flush(struct dfu_entity *de, void
> *buf, int size, int blk_seq_num); +void dfu_flush_callback(struct
> dfu_entity *dfu); +void dfu_initiated_callback(struct dfu_entity
> *dfu); 
>  /*
>   * dfu_defer_flush - pointer to store dfu_entity for deferred
> flashing.



Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lu...@denx.de


pgpsRNcR4roIz.pgp
Description: OpenPGP digital signature
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH] spi: Fix manual relocation calling more times

2019-09-17 Thread Michal Simek
From: Ashok Reddy Soma 

When two instances of AXI QSPI with flash are added and tested
simultaneously the spi driver operations are relocated twice.
As a result code is accessing addresses outside of RAM when
relocated second time which is causing a crash.

Tested on Microblaze.

Similar change was done in past by:
commit f238b3f0fbc9 ("watchdog: dm: Support manual relocation for watchdogs")
commit 2588f2ddfd60 ("dm: sf: Add support for all targets which requires 
MANUAL_RELOC")
commit 1b4c2aa25bdf ("gpio: dm: Support manual relocation for gpio")

Signed-off-by: Ashok Reddy Soma 
Signed-off-by: Michal Simek 
---

 drivers/spi/spi-uclass.c | 34 +++---
 1 file changed, 19 insertions(+), 15 deletions(-)

diff --git a/drivers/spi/spi-uclass.c b/drivers/spi/spi-uclass.c
index 88cb2a126227..6d63006d186c 100644
--- a/drivers/spi/spi-uclass.c
+++ b/drivers/spi/spi-uclass.c
@@ -129,21 +129,25 @@ static int spi_post_probe(struct udevice *bus)
 #endif
 #if defined(CONFIG_NEEDS_MANUAL_RELOC)
struct dm_spi_ops *ops = spi_get_ops(bus);
-
-   if (ops->claim_bus)
-   ops->claim_bus += gd->reloc_off;
-   if (ops->release_bus)
-   ops->release_bus += gd->reloc_off;
-   if (ops->set_wordlen)
-   ops->set_wordlen += gd->reloc_off;
-   if (ops->xfer)
-   ops->xfer += gd->reloc_off;
-   if (ops->set_speed)
-   ops->set_speed += gd->reloc_off;
-   if (ops->set_mode)
-   ops->set_mode += gd->reloc_off;
-   if (ops->cs_info)
-   ops->cs_info += gd->reloc_off;
+   static int reloc_done;
+
+   if (!reloc_done) {
+   if (ops->claim_bus)
+   ops->claim_bus += gd->reloc_off;
+   if (ops->release_bus)
+   ops->release_bus += gd->reloc_off;
+   if (ops->set_wordlen)
+   ops->set_wordlen += gd->reloc_off;
+   if (ops->xfer)
+   ops->xfer += gd->reloc_off;
+   if (ops->set_speed)
+   ops->set_speed += gd->reloc_off;
+   if (ops->set_mode)
+   ops->set_mode += gd->reloc_off;
+   if (ops->cs_info)
+   ops->cs_info += gd->reloc_off;
+   reloc_done++;
+   }
 #endif
 
return 0;
-- 
2.17.1

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


Re: [U-Boot] [PATCH 04/14] dfu: allow to manage DFU on several devices

2019-09-17 Thread Patrick DELAUNAY
Hi Lukasz,

> From: Lukasz Majewski 
> Sent: mardi 17 septembre 2019 12:26
> To: Patrick DELAUNAY 
> Cc: u-boot@lists.denx.de; U-Boot STM32  mailman.stormreply.com>
> Subject: Re: [PATCH 04/14] dfu: allow to manage DFU on several devices
> Importance: High
> 
> Hi Patrick,
> 
> > Add support of DFU for several interface/device with one command.
> >
> > The format for "dfu_alt_info" in this case is :
> >   interface with devstring'='alternate list (';' separated)
> >   and each interface is separated by '&'
> >
> > The previous behavior is always supported.
> >
> > One example for NOR (bootloaders) + NAND (rootfs in UBI):
> >
> > U-Boot> env set dfu_alt_info \
> > "sf 0:0:1000:0=spl part 0 1;u-boot part 0 2; \ u-boot-env part 0
> > 3&nand 0=UBI partubi 0,3"
> >
> > U-Boot> dfu 0 list
> >
> > DFU alt settings list:
> > dev: SF alt: 0 name: spl layout: RAW_ADDR
> > dev: SF alt: 1 name: ssbl layout: RAW_ADDR
> > dev: SF alt: 2 name: u-boot-env layout: RAW_ADDR
> > dev: NAND alt: 3 name: UBI layout: RAW_ADDR
> >
> > U-Boot> dfu 0
> >
> > $> dfu-util -l
> >
> > Found DFU: [0483:5720] ver=, devnum=96, cfg=1,\  intf=0, alt=3,
> > name="UBI", serial="00270038511934383330"
> > Found DFU: [0483:5720] ver=, devnum=96, cfg=1,\  intf=0, alt=2,
> > name="u-boot-env", serial="00270038511934383330"
> > Found DFU: [0483:5720] ver=, devnum=96, cfg=1,\  intf=0, alt=1,
> > name="u-boot", serial="00270038511934383330"
> > Found DFU: [0483:5720] ver=, devnum=96, cfg=1,\  intf=0, alt=0,
> > name="spl", serial="00270038511934383330"
> >
> 
> My two remarks:
> 
> 1. As you mentioned above - the current behavior must be preserved (this is my
> main concern).

I agree, it was also my concern.

I don't indicated it clearly by I test it on my board and it but it is 
preserved.

For example, on my stm32mp1 board :

STM32MP> env set dfu_alt_info "sdcard_fsbl1 part 0 1;sdcard_fsbl2 part 0 
2;sdcard_ssbl part 0 3;sdcard_bootfs part 0 4;sdcard_vendorfs part 0 
5;sdcard_rootfs part 0 6"
STM32MP> dfu 0 mmc 0

On the host side 

dfu-util -l
dfu-util 0.9

Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2016 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to http://sourceforge.net/p/dfu-util/tickets/

Found DFU: [0483:df11] ver=0200, devnum=17, cfg=1, intf=0, path="3-1.3.1", 
alt=5, name="sdcard_rootfs", serial="00270038511934383330"
Found DFU: [0483:df11] ver=0200, devnum=17, cfg=1, intf=0, path="3-1.3.1", 
alt=4, name="sdcard_vendorfs", serial="00270038511934383330"
Found DFU: [0483:df11] ver=0200, devnum=17, cfg=1, intf=0, path="3-1.3.1", 
alt=3, name="sdcard_bootfs", serial="00270038511934383330"
Found DFU: [0483:df11] ver=0200, devnum=17, cfg=1, intf=0, path="3-1.3.1", 
alt=2, name="sdcard_ssbl", serial="00270038511934383330"
Found DFU: [0483:df11] ver=0200, devnum=17, cfg=1, intf=0, path="3-1.3.1", 
alt=1, name="sdcard_fsbl2", serial="00270038511934383330"
Found DFU: [0483:df11] ver=0200, devnum=17, cfg=1, intf=0, path="3-1.3.1", 
alt=0, name="sdcard_fsbl1", serial="00270038511934383330"


> 2. You added the example of usage to the commit message. Could you also add it
> to the ./doc/README.dfu (not yet present) file ?

Yes I willl create the file in V2

> Anyway, thanks for your work :-)
> 
> > Signed-off-by: Patrick Delaunay 
> 
> Acked-by: Lukasz Majewski 
> 

Regards

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


Re: [U-Boot] [PATCH 06/14] dfu: add backend for MTD device

2019-09-17 Thread Patrick DELAUNAY
Hi,

> From: Lukasz Majewski 
> Sent: mardi 17 septembre 2019 12:36
> 
> Hi Patrick,
> 
> > Add DFU backend for MTD device: allow to read and write on any MTD
> > device (RAW or SPI)
> >
> > For example :
> > > set dfu_alt_info "nand_raw raw 0x0 0x10"
> > > dfu 0 mtd nand0
> >
> > This MTD backend provides the same level than dfu nand
>  ^ - shouldn't there be
>  "functionality" or such?
> 
> > backend for NAND in RAW mode and sf backend for NOR; So it can replace
> > booth of them but it can also add support of spi-nand.
> 
> If I understood correctly - it allows reading "raw" data from MTD device - 
> NAND,
> SPI-NOR and SPI-NAND?

Yes, "all MTD devices" :  NAND, SPI-NOR, SPI-NAND

My message wasn't clear except if you know the driver organization, I update it 
in V2

drivers/mtd/raw 
drivers/mtd/nand
drivers/mtd/spi

and potentially also ONENAND als o (not tested) with drivers/mtd/onenand

> >
> > > set dfu_alt_info "nand_raw raw 0x0 0x10"
> > > dfu 0 mtd spi-nand0
> >
> > The backend code is based on the MTD command introduced by commit
> > 5db66b3aee6f ("cmd: mtd:
> > add 'mtd' command")
> >
> > Signed-off-by: Patrick Delaunay 
> > ---
> 
> 
> 
> Best regards,
> 
> Lukasz Majewski
> 
> --
> 

Beast regards

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


Re: [U-Boot] [PATCH 07/14] dfu: add partition support for MTD backend

2019-09-17 Thread Patrick DELAUNAY
Hi,

> From: Lukasz Majewski 
> Sent: mardi 17 septembre 2019 12:39
> 
> Hi Patrick,
> 
> > Add the support of MTD partition for the MTD backend.
> >
> > The expected dfu_alt_info for one alternate on the mtd device :
> >  part 
> >  partubi 
> >
> > "partubi" also erase up to the end of the partition after write
> > operation.
> >
> > For example: dfu_alt_info = "spl part 1;u-boot part 2; UBI partubi 3"
> >
> > U-Boot> dfu 0 mtd nand0
> 
> The above information shall also be placed to dedicated ./doc/README.dfu file.

Yes, I will add informations in V2

> >
> > Signed-off-by: Patrick Delaunay 
> 
> Acked-by: Lukasz Majewski 

Best regards,

Patrick Delaunay
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH] spl: add a generic function board_init_r

2019-09-17 Thread Simon Goldschmidt
On Thu, Sep 5, 2019 at 6:50 PM Philippe Reynes
 wrote:
>
> This commit add a generic function board_init_r that
> only initialize some device (for example serial). It
> avoid to define a board function only to launch the
> serial configuration.
>
> Signed-off-by: Philippe Reynes 
> ---
>  common/spl/Kconfig |  8 
>  common/spl/spl.c   | 19 +++
>  2 files changed, 27 insertions(+)
>
> diff --git a/common/spl/Kconfig b/common/spl/Kconfig
> index f467eca..d5b331a 100644
> --- a/common/spl/Kconfig
> +++ b/common/spl/Kconfig
> @@ -25,6 +25,14 @@ config SPL_FRAMEWORK
>   supports MMC, NAND and YMODEM and other methods loading of U-Boot
>   and the Linux Kernel.  If unsure, say Y.
>
> +config SPL_FRAMEWORK_BOARD_INIT_F
> +   bool "Define a generic function board_init_f"
> +   depends on SPL_FRAMEWORK
> +   default n
> +   help
> + Define a generic function board_init_f, unless you want to
> + provide your own board_init_f, you should say Y.
> +
>  config SPL_SIZE_LIMIT
> int "Maximum size of SPL image"
> depends on SPL
> diff --git a/common/spl/spl.c b/common/spl/spl.c
> index 082fa2b..73bf984 100644
> --- a/common/spl/spl.c
> +++ b/common/spl/spl.c
> @@ -566,6 +566,25 @@ static int boot_from_devices(struct spl_image_info 
> *spl_image,
> return -ENODEV;
>  }
>
> +#if defined(CONFIG_SPL_FRAMEWORK_BOARD_INIT_F)
> +void board_init_f(ulong dummy)

You're actually defining 'board_init_f' here, not 'board_init_r' like
the commit message says...

Regards,
Simon

> +{
> +#if CONFIG_IS_ENABLED(OF_CONTROL)
> +   int ret;
> +
> +   ret = spl_early_init();
> +   if (ret) {
> +   debug("spl_early_init() failed: %d\n", ret);
> +   hang();
> +   }
> +#endif
> +
> +#if CONFIG_IS_ENABLED(SERIAL_SUPPORT)
> +   preloader_console_init();
> +#endif
> +}
> +#endif
> +
>  void board_init_r(gd_t *dummy1, ulong dummy2)
>  {
> u32 spl_boot_list[] = {
> --
> 2.7.4
>
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH 09/17] mx6sabresd: convert to DM_VIDEO

2019-09-17 Thread Fabio Estevam
Hi Anatolij,

On Mon, Sep 16, 2019 at 4:21 PM Anatolij Gustschin  wrote:

> Most probably this is because there was no user of the video
> device when booting and therefore the video driver was not
> probed/bound. Please try do display some bitmap with bmp
> command or try to switch to the video console by command
> "setenv stdout vidconsole0". Then, the video device will be
> probed and you should see the LVDS output.

Here is what I tried:

=> setenv stdout vidconsole0
## Error inserting "stdout" variable, errno=22

Then I see garbage on the LVDS panel.

Any ideas as to why setting "stdout" failed?

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


Re: [U-Boot] [PATCH] spi: Fix manual relocation calling more times

2019-09-17 Thread Jagan Teki
On Tue, Sep 17, 2019 at 4:52 PM Michal Simek  wrote:
>
> From: Ashok Reddy Soma 
>
> When two instances of AXI QSPI with flash are added and tested
> simultaneously the spi driver operations are relocated twice.
> As a result code is accessing addresses outside of RAM when
> relocated second time which is causing a crash.
>
> Tested on Microblaze.
>
> Similar change was done in past by:
> commit f238b3f0fbc9 ("watchdog: dm: Support manual relocation for watchdogs")
> commit 2588f2ddfd60 ("dm: sf: Add support for all targets which requires 
> MANUAL_RELOC")
> commit 1b4c2aa25bdf ("gpio: dm: Support manual relocation for gpio")
>
> Signed-off-by: Ashok Reddy Soma 
> Signed-off-by: Michal Simek 
> ---

Reviewed-by: Jagan Teki 

Would like to take it coming MW? since we are close to release.
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH] spi: Fix manual relocation calling more times

2019-09-17 Thread Simon Goldschmidt
On Tue, Sep 17, 2019 at 1:22 PM Michal Simek  wrote:
>
> From: Ashok Reddy Soma 
>
> When two instances of AXI QSPI with flash are added and tested
> simultaneously the spi driver operations are relocated twice.
> As a result code is accessing addresses outside of RAM when
> relocated second time which is causing a crash.
>
> Tested on Microblaze.
>
> Similar change was done in past by:
> commit f238b3f0fbc9 ("watchdog: dm: Support manual relocation for watchdogs")
> commit 2588f2ddfd60 ("dm: sf: Add support for all targets which requires 
> MANUAL_RELOC")
> commit 1b4c2aa25bdf ("gpio: dm: Support manual relocation for gpio")
>
> Signed-off-by: Ashok Reddy Soma 
> Signed-off-by: Michal Simek 
> ---
>
>  drivers/spi/spi-uclass.c | 34 +++---
>  1 file changed, 19 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/spi/spi-uclass.c b/drivers/spi/spi-uclass.c
> index 88cb2a126227..6d63006d186c 100644
> --- a/drivers/spi/spi-uclass.c
> +++ b/drivers/spi/spi-uclass.c
> @@ -129,21 +129,25 @@ static int spi_post_probe(struct udevice *bus)
>  #endif
>  #if defined(CONFIG_NEEDS_MANUAL_RELOC)
> struct dm_spi_ops *ops = spi_get_ops(bus);
> -
> -   if (ops->claim_bus)
> -   ops->claim_bus += gd->reloc_off;
> -   if (ops->release_bus)
> -   ops->release_bus += gd->reloc_off;
> -   if (ops->set_wordlen)
> -   ops->set_wordlen += gd->reloc_off;
> -   if (ops->xfer)
> -   ops->xfer += gd->reloc_off;
> -   if (ops->set_speed)
> -   ops->set_speed += gd->reloc_off;
> -   if (ops->set_mode)
> -   ops->set_mode += gd->reloc_off;
> -   if (ops->cs_info)
> -   ops->cs_info += gd->reloc_off;
> +   static int reloc_done;

So with CONFIG_NEEDS_MANUAL_RELOC, we don't support multiple
(differen) spi (or watchdog, sf, gpio) drivers?

Regards,
Simon

> +
> +   if (!reloc_done) {
> +   if (ops->claim_bus)
> +   ops->claim_bus += gd->reloc_off;
> +   if (ops->release_bus)
> +   ops->release_bus += gd->reloc_off;
> +   if (ops->set_wordlen)
> +   ops->set_wordlen += gd->reloc_off;
> +   if (ops->xfer)
> +   ops->xfer += gd->reloc_off;
> +   if (ops->set_speed)
> +   ops->set_speed += gd->reloc_off;
> +   if (ops->set_mode)
> +   ops->set_mode += gd->reloc_off;
> +   if (ops->cs_info)
> +   ops->cs_info += gd->reloc_off;
> +   reloc_done++;
> +   }
>  #endif
>
> return 0;
> --
> 2.17.1
>
> ___
> U-Boot mailing list
> U-Boot@lists.denx.de
> https://lists.denx.de/listinfo/u-boot
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH] spi: Fix manual relocation calling more times

2019-09-17 Thread Michal Simek
On 17. 09. 19 14:43, Simon Goldschmidt wrote:
> On Tue, Sep 17, 2019 at 1:22 PM Michal Simek  wrote:
>>
>> From: Ashok Reddy Soma 
>>
>> When two instances of AXI QSPI with flash are added and tested
>> simultaneously the spi driver operations are relocated twice.
>> As a result code is accessing addresses outside of RAM when
>> relocated second time which is causing a crash.
>>
>> Tested on Microblaze.
>>
>> Similar change was done in past by:
>> commit f238b3f0fbc9 ("watchdog: dm: Support manual relocation for watchdogs")
>> commit 2588f2ddfd60 ("dm: sf: Add support for all targets which requires 
>> MANUAL_RELOC")
>> commit 1b4c2aa25bdf ("gpio: dm: Support manual relocation for gpio")
>>
>> Signed-off-by: Ashok Reddy Soma 
>> Signed-off-by: Michal Simek 
>> ---
>>
>>  drivers/spi/spi-uclass.c | 34 +++---
>>  1 file changed, 19 insertions(+), 15 deletions(-)
>>
>> diff --git a/drivers/spi/spi-uclass.c b/drivers/spi/spi-uclass.c
>> index 88cb2a126227..6d63006d186c 100644
>> --- a/drivers/spi/spi-uclass.c
>> +++ b/drivers/spi/spi-uclass.c
>> @@ -129,21 +129,25 @@ static int spi_post_probe(struct udevice *bus)
>>  #endif
>>  #if defined(CONFIG_NEEDS_MANUAL_RELOC)
>> struct dm_spi_ops *ops = spi_get_ops(bus);
>> -
>> -   if (ops->claim_bus)
>> -   ops->claim_bus += gd->reloc_off;
>> -   if (ops->release_bus)
>> -   ops->release_bus += gd->reloc_off;
>> -   if (ops->set_wordlen)
>> -   ops->set_wordlen += gd->reloc_off;
>> -   if (ops->xfer)
>> -   ops->xfer += gd->reloc_off;
>> -   if (ops->set_speed)
>> -   ops->set_speed += gd->reloc_off;
>> -   if (ops->set_mode)
>> -   ops->set_mode += gd->reloc_off;
>> -   if (ops->cs_info)
>> -   ops->cs_info += gd->reloc_off;
>> +   static int reloc_done;
> 
> So with CONFIG_NEEDS_MANUAL_RELOC, we don't support multiple
> (differen) spi (or watchdog, sf, gpio) drivers?

If you look at commits above you will see that several subsystems
support multiple instances already.
We can check others as well.

M




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


Re: [U-Boot] [PATCH 09/14] dfu: add callback for flush and initiated operation

2019-09-17 Thread Patrick DELAUNAY
Hi,

> From: Lukasz Majewski 
> Sent: mardi 17 septembre 2019 12:45
> 
> Hi Patrick,
> 
> > Add weak callback to allow board specific behavior
> > - flush
> > - initiated
> >
> > This patch prepare usage of DFU back end for communication with
> > STM32CubeProgrammer on stm32mp1 platform with stm32prog command.
> 
> As I've said previously - please add this use case and info to 
> ./doc/README.dtu.

Yes

> 
> >
> > Signed-off-by: Patrick Delaunay 
> > ---
> >
> >  drivers/dfu/dfu.c | 19 +++
> >  include/dfu.h |  2 ++
> >  2 files changed, 21 insertions(+)
> >
> > diff --git a/drivers/dfu/dfu.c b/drivers/dfu/dfu.c index
> > 2697235c24..f12c5afc66 100644
> > --- a/drivers/dfu/dfu.c
> > +++ b/drivers/dfu/dfu.c
> > @@ -22,6 +22,22 @@ static int dfu_alt_num;  static int alt_num_cnt;
> > static struct hash_algo *dfu_hash_algo;
> >
> > +/*
> > + * The purpose of the dfu_flush_callback() function is to
> > + * provide callback for dfu user
> > + */
> > +__weak void dfu_flush_callback(struct dfu_entity *dfu) { }
> > +
> > +/*
> > + * The purpose of the dfu_flush_callback() function is to
> > + * provide callback for dfu user
> 
> Please update this repeated comment.

Yes, in V2

> 
> > + */
> > +__weak void dfu_initiated_callback(struct dfu_entity *dfu)
> > +{
> > +}
> > +
> >  /*
> >   * The purpose of the dfu_usb_get_reset() function is to
> >   * provide information if after USB_DETACH request
> > @@ -263,6 +279,7 @@ int dfu_transaction_initiate(struct dfu_entity
> > *dfu, bool read) }
> >
> > dfu->inited = 1;
> > +   dfu_initiated_callback(dfu);
> >
> > return 0;
> >  }
> > @@ -282,6 +299,8 @@ int dfu_flush(struct dfu_entity *dfu, void *buf,
> > int size, int blk_seq_num) printf("\nDFU complete %s: 0x%08x\n",
> > dfu_hash_algo->name, dfu->crc);
> >
> > +   dfu_flush_callback(dfu);
> > +
> > dfu_transaction_cleanup(dfu);
> >
> > return ret;
> > diff --git a/include/dfu.h b/include/dfu.h
> > index 4de7d35914..5d85cc35ef 100644
> > --- a/include/dfu.h
> > +++ b/include/dfu.h
> > @@ -182,6 +182,8 @@ bool dfu_usb_get_reset(void);
> >  int dfu_read(struct dfu_entity *de, void *buf, int size, int
> > blk_seq_num); int dfu_write(struct dfu_entity *de, void *buf, int
> > size, int blk_seq_num); int dfu_flush(struct dfu_entity *de, void
> > *buf, int size, int blk_seq_num); +void dfu_flush_callback(struct
> > dfu_entity *dfu); +void dfu_initiated_callback(struct dfu_entity
> > *dfu);
> >  /*
> >   * dfu_defer_flush - pointer to store dfu_entity for deferred
> > flashing.
> 
> 
> 
> Best regards,
> 
> Lukasz Majewski
> 
> --

Best regards
Patrick
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH] spi: Fix manual relocation calling more times

2019-09-17 Thread Simon Goldschmidt
On Tue, Sep 17, 2019 at 2:48 PM Michal Simek  wrote:
>
> On 17. 09. 19 14:43, Simon Goldschmidt wrote:
> > On Tue, Sep 17, 2019 at 1:22 PM Michal Simek  
> > wrote:
> >>
> >> From: Ashok Reddy Soma 
> >>
> >> When two instances of AXI QSPI with flash are added and tested
> >> simultaneously the spi driver operations are relocated twice.
> >> As a result code is accessing addresses outside of RAM when
> >> relocated second time which is causing a crash.
> >>
> >> Tested on Microblaze.
> >>
> >> Similar change was done in past by:
> >> commit f238b3f0fbc9 ("watchdog: dm: Support manual relocation for 
> >> watchdogs")
> >> commit 2588f2ddfd60 ("dm: sf: Add support for all targets which requires 
> >> MANUAL_RELOC")
> >> commit 1b4c2aa25bdf ("gpio: dm: Support manual relocation for gpio")
> >>
> >> Signed-off-by: Ashok Reddy Soma 
> >> Signed-off-by: Michal Simek 
> >> ---
> >>
> >>  drivers/spi/spi-uclass.c | 34 +++---
> >>  1 file changed, 19 insertions(+), 15 deletions(-)
> >>
> >> diff --git a/drivers/spi/spi-uclass.c b/drivers/spi/spi-uclass.c
> >> index 88cb2a126227..6d63006d186c 100644
> >> --- a/drivers/spi/spi-uclass.c
> >> +++ b/drivers/spi/spi-uclass.c
> >> @@ -129,21 +129,25 @@ static int spi_post_probe(struct udevice *bus)
> >>  #endif
> >>  #if defined(CONFIG_NEEDS_MANUAL_RELOC)
> >> struct dm_spi_ops *ops = spi_get_ops(bus);
> >> -
> >> -   if (ops->claim_bus)
> >> -   ops->claim_bus += gd->reloc_off;
> >> -   if (ops->release_bus)
> >> -   ops->release_bus += gd->reloc_off;
> >> -   if (ops->set_wordlen)
> >> -   ops->set_wordlen += gd->reloc_off;
> >> -   if (ops->xfer)
> >> -   ops->xfer += gd->reloc_off;
> >> -   if (ops->set_speed)
> >> -   ops->set_speed += gd->reloc_off;
> >> -   if (ops->set_mode)
> >> -   ops->set_mode += gd->reloc_off;
> >> -   if (ops->cs_info)
> >> -   ops->cs_info += gd->reloc_off;
> >> +   static int reloc_done;
> >
> > So with CONFIG_NEEDS_MANUAL_RELOC, we don't support multiple
> > (differen) spi (or watchdog, sf, gpio) drivers?
>
> If you look at commits above you will see that several subsystems
> support multiple instances already.
> We can check others as well.

I have looked at the commits above, that's why I ask. To me, this code
relocates the ops of the device called first. If a second device has different
ops, it won't get relocated, or am I wrong?

Given your other similar commits that were already accepted, I don't want to
hold this one, but I still would like to understand.

Regards,
Simon

>
> M
>
>
>
>
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH] Revert "mx6sabresd: convert to DM_VIDEO"

2019-09-17 Thread Fabio Estevam
The conversion to CONFIG_DM_VIDEO causes no output at all
in the LVDS panel.

Switch back to the non-DM video option until this is resolved,
to avoid splashscreen functionality regression.

This reverts commit f3592ceac9810b34801772b6d335d8f7cff4c287.

Signed-off-by: Fabio Estevam 
---
 configs/mx6sabresd_defconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configs/mx6sabresd_defconfig b/configs/mx6sabresd_defconfig
index e7e989df9c..b3853c544c 100644
--- a/configs/mx6sabresd_defconfig
+++ b/configs/mx6sabresd_defconfig
@@ -96,5 +96,5 @@ CONFIG_USB_GADGET_PRODUCT_NUM=0xa4a5
 CONFIG_CI_UDC=y
 CONFIG_USB_HOST_ETHER=y
 CONFIG_USB_ETHER_ASIX=y
-CONFIG_DM_VIDEO=y
+CONFIG_VIDEO=y
 CONFIG_VIDEO_IPUV3=y
-- 
2.17.1

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


Re: [U-Boot] [PATCH] spi: Fix manual relocation calling more times

2019-09-17 Thread Michal Simek
On 17. 09. 19 14:41, Jagan Teki wrote:
> On Tue, Sep 17, 2019 at 4:52 PM Michal Simek  wrote:
>>
>> From: Ashok Reddy Soma 
>>
>> When two instances of AXI QSPI with flash are added and tested
>> simultaneously the spi driver operations are relocated twice.
>> As a result code is accessing addresses outside of RAM when
>> relocated second time which is causing a crash.
>>
>> Tested on Microblaze.
>>
>> Similar change was done in past by:
>> commit f238b3f0fbc9 ("watchdog: dm: Support manual relocation for watchdogs")
>> commit 2588f2ddfd60 ("dm: sf: Add support for all targets which requires 
>> MANUAL_RELOC")
>> commit 1b4c2aa25bdf ("gpio: dm: Support manual relocation for gpio")
>>
>> Signed-off-by: Ashok Reddy Soma 
>> Signed-off-by: Michal Simek 
>> ---
> 
> Reviewed-by: Jagan Teki 
> 
> Would like to take it coming MW? since we are close to release.

Taking it for next release is fine.

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


Re: [U-Boot] [PATCH] Revert "mx6sabresd: convert to DM_VIDEO"

2019-09-17 Thread Otavio Salvador
On Tue, Sep 17, 2019 at 10:03 AM Fabio Estevam  wrote:
>
> The conversion to CONFIG_DM_VIDEO causes no output at all
> in the LVDS panel.
>
> Switch back to the non-DM video option until this is resolved,
> to avoid splashscreen functionality regression.
>
> This reverts commit f3592ceac9810b34801772b6d335d8f7cff4c287.
>
> Signed-off-by: Fabio Estevam 

Acked-by: Otavio Salvador 

-- 
Otavio Salvador O.S. Systems
http://www.ossystems.com.brhttp://code.ossystems.com.br
Mobile: +55 (53) 9 9981-7854  Mobile: +1 (347) 903-9750
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v2 1/2] dm: core: Add functions to read 64-bit dt properties

2019-09-17 Thread Michal Simek
On 17. 09. 19 7:47, Simon Glass wrote:
> On Mon, 2 Sep 2019 at 09:24, Bin Meng  wrote:
>>
>> On Mon, Sep 2, 2019 at 10:34 PM Michal Simek  wrote:
>>>
>>> From: T Karthik Reddy 
>>>
>>> This patch adds functions dev_read_u64_default & dev_read_u64
>>> to read unsigned 64-bit values from devicetree.
>>>
>>> Signed-off-by: T Karthik Reddy 
>>> Signed-off-by: Michal Simek 
>>> ---
>>>
>>> Changes in v2:
>>> - Moved newly added 64-bit funtion definations & prototypes below
>>>32-bit functions.
>>>
>>>  drivers/core/ofnode.c |  2 +-
>>>  drivers/core/read.c   | 10 ++
>>>  include/dm/ofnode.h   |  2 +-
>>>  include/dm/read.h | 33 +
>>>  4 files changed, 45 insertions(+), 2 deletions(-)
>>>
>>
>> Reviewed-by: Bin Meng 
> 
> How about adding a few tests for these new functions?
> 
> See for example here:
> 
> https://gitlab.denx.de/u-boot/custodians/u-boot-dm/commit/63453b90049cef10309f254c35d8a33e1e6552ba

It shouldn't be a problem to put some u64 properties and read them back.

Karthik: Can you please take a look at it?

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


[U-Boot] Ethernet on i.MX8MM with mainline U-Boot

2019-09-17 Thread Schrempf Frieder
Hi Peng,

I tried to get Ethernet running on i.MX8MM with mainline U-Boot and your 
latest patches for SoC-support.
I added the missing clocks, but something still seems to be wrong. It 
seems like the clock parents are not set correctly.

If I run "dm tree", I see that the enet_axi is a child of clock-osc-24m, 
but I would expect it to be under sys_pll1_266m as specified in the 
devicetree.

Do you have an idea what could be wrong or some working code to look at?

Thanks for your help!

Regards,
Frieder
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH V2] [RFC] usb: storage: Limit transfer size to 120 kiB

2019-09-17 Thread Marek Vasut
Due to constant influx of more and more weird and broken USB sticks,
do as Linux does in commit 779b457f66e10de3471479373463b27fd308dc85

usb: storage: scsiglue: further describe our 240 sector limit

Just so we have some sort of documentation as to why
we limit our Mass Storage transfers to 240 sectors,
let's update the comment to make clearer that
devices were found that would choke with larger
transfers.

While at that, also make sure to clarify that other
operating systems have similar, albeit different,
limits on mass storage transfers.

And reduce the maximum transfer length of USB storage to 120 kiB.

Signed-off-by: Marek Vasut 
Cc: Bin Meng 
Cc: Simon Glass 
---
V2: Reshuffle the code a bit, always clamp the transfer size to 240 blocks
---
 common/usb_storage.c | 43 ++-
 1 file changed, 22 insertions(+), 21 deletions(-)

diff --git a/common/usb_storage.c b/common/usb_storage.c
index 8c889bb1a6..e1b539a082 100644
--- a/common/usb_storage.c
+++ b/common/usb_storage.c
@@ -938,31 +938,32 @@ do_retry:
 static void usb_stor_set_max_xfer_blk(struct usb_device *udev,
  struct us_data *us)
 {
-   unsigned short blk;
-   size_t __maybe_unused size;
-   int __maybe_unused ret;
-
-#if !CONFIG_IS_ENABLED(DM_USB)
-#ifdef CONFIG_USB_EHCI_HCD
/*
-* The U-Boot EHCI driver can handle any transfer length as long as
-* there is enough free heap space left, but the SCSI READ(10) and
-* WRITE(10) commands are limited to 65535 blocks.
+* Limit the total size of a transfer to 120 KB.
+*
+* Some devices are known to choke with anything larger. It seems like
+* the problem stems from the fact that original IDE controllers had
+* only an 8-bit register to hold the number of sectors in one transfer
+* and even those couldn't handle a full 256 sectors.
+*
+* Because we want to make sure we interoperate with as many devices as
+* possible, we will maintain a 240 sector transfer size limit for USB
+* Mass Storage devices.
+*
+* Tests show that other operating have similar limits with Microsoft
+* Windows 7 limiting transfers to 128 sectors for both USB2 and USB3
+* and Apple Mac OS X 10.11 limiting transfers to 256 sectors for USB2
+* and 2048 for USB3 devices.
 */
-   blk = USHRT_MAX;
-#else
-   blk = 20;
-#endif
-#else
+   unsigned short blk = 240;
+
+#if CONFIG_IS_ENABLED(DM_USB)
+   size_t size;
+   int ret;
+
ret = usb_get_max_xfer_size(udev, (size_t *)&size);
-   if (ret < 0) {
-   /* unimplemented, let's use default 20 */
-   blk = 20;
-   } else {
-   if (size > USHRT_MAX * 512)
-   size = USHRT_MAX * 512;
+   if ((ret >= 0) && (size < 240 * 512))
blk = size / 512;
-   }
 #endif
 
us->max_xfer_blk = blk;
-- 
2.23.0.rc1

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


[U-Boot] [PATCH 1/2] am335x, guardian: update guardian board

2019-09-17 Thread BollavarapuMoses.Christopher
From: Moses Christopher 

  - add BOARD_LATE_INIT function calls in board.c
  - add swi_status detection in board.c
  - mux: add guardian interfaces to single pinmux structure
  - am33xx, kconfig: add BOARD_LATE_INIT for GUARDIAN board

Signed-off-by: Moses Christopher 
---
 arch/arm/mach-omap2/am33xx/Kconfig |  1 +
 board/bosch/guardian/board.c   | 53 ++
 board/bosch/guardian/mux.c | 32 ---
 3 files changed, 65 insertions(+), 21 deletions(-)

diff --git a/arch/arm/mach-omap2/am33xx/Kconfig 
b/arch/arm/mach-omap2/am33xx/Kconfig
index 7f6b344..39d9c28 100644
--- a/arch/arm/mach-omap2/am33xx/Kconfig
+++ b/arch/arm/mach-omap2/am33xx/Kconfig
@@ -89,6 +89,7 @@ config TARGET_AM335X_SHC
 
 config TARGET_AM335X_GUARDIAN
bool "Support am335x based guardian board from bosch"
+   select BOARD_LATE_INIT
select DM
select DM_SERIAL
select DM_GPIO
diff --git a/board/bosch/guardian/board.c b/board/bosch/guardian/board.c
index ec0c4a17..072aa4e 100644
--- a/board/bosch/guardian/board.c
+++ b/board/bosch/guardian/board.c
@@ -172,6 +172,8 @@ void sdram_init(void)
 
 int board_init(void)
 {
+   save_omap_boot_params();
+
 #if defined(CONFIG_HW_WATCHDOG)
hw_watchdog_init();
 #endif
@@ -183,3 +185,54 @@ int board_init(void)
 #endif
return 0;
 }
+
+#ifdef CONFIG_BOARD_LATE_INIT
+static void set_bootmode_env(void)
+{
+   char *boot_device_name = NULL;
+   char *boot_mode_gpio = "gpio@44e07000_14";
+   int   ret;
+   int   value;
+
+   struct gpio_desc boot_mode_desc;
+
+   switch (gd->arch.omap_boot_device) {
+   case BOOT_DEVICE_NAND:
+   boot_device_name = "nand";
+   break;
+   case BOOT_DEVICE_USBETH:
+   boot_device_name = "usbeth";
+   break;
+   default:
+   break;
+   }
+
+   if (boot_device_name)
+   env_set("boot_device", boot_device_name);
+
+   ret = dm_gpio_lookup_name(boot_mode_gpio, &boot_mode_desc);
+   if (ret) {
+   printf("%s is not found\n", boot_mode_gpio);
+   goto err;
+   }
+
+   ret = dm_gpio_request(&boot_mode_desc, "setup_bootmode_env");
+   if (ret && ret != -EBUSY) {
+   printf("requesting gpio: %s failed\n", boot_mode_gpio);
+   goto err;
+   }
+
+   value = dm_gpio_get_value(&boot_mode_desc);
+   value ? env_set("swi_status", "0") : env_set("swi_status", "1");
+   return;
+
+err:
+   env_set("swi_status", "err");
+}
+
+int board_late_init(void)
+{
+   set_bootmode_env();
+   return 0;
+}
+#endif /* CONFIG_BOARD_LATE_INIT */
diff --git a/board/bosch/guardian/mux.c b/board/bosch/guardian/mux.c
index 708c3e7..20a1f25 100644
--- a/board/bosch/guardian/mux.c
+++ b/board/bosch/guardian/mux.c
@@ -26,24 +26,16 @@ static struct module_pin_mux i2c0_pin_mux[] = {
{-1},
 };
 
-static struct module_pin_mux adc_voltages_en[] = {
-   {OFFSET(mcasp0_ahclkx), (MODE(7) | PULLUP_EN)},
-   {-1},
-};
-
-static struct module_pin_mux asp_power_en[] = {
-   {OFFSET(mcasp0_aclkx), (MODE(7) | PULLUP_EN)},
-   {-1},
-};
-
-static struct module_pin_mux switch_off_3v6_pin_mux[] = {
-   {OFFSET(mii1_txd0), (MODE(7) | PULLUP_EN)},
-   /*
-* The uart1 lines are made floating inputs, based on the Guardian
-* A2 Sample Power Supply Schematics
-*/
-   {OFFSET(uart1_rxd), (MODE(7) | PULLUDDIS)},
-   {OFFSET(uart1_txd), (MODE(7) | PULLUDDIS)},
+static struct module_pin_mux guardian_interfaces_pin_mux[] = {
+   {OFFSET(mcasp0_ahclkx), (MODE(7) | PULLDOWN_EN)},
+   {OFFSET(mcasp0_aclkx),  (MODE(7) | PULLUP_EN)},
+   {OFFSET(mii1_txd0), (MODE(7) | PULLUP_EN)},
+   {OFFSET(uart1_rxd), (MODE(7) | RXACTIVE | PULLUDDIS)},
+   {OFFSET(uart1_txd), (MODE(7) | PULLUDDIS)},
+   {OFFSET(mii1_crs),  (MODE(7) | PULLDOWN_EN)},
+   {OFFSET(rmii1_refclk),  (MODE(7) | PULLDOWN_EN)},
+   {OFFSET(mii1_txd3), (MODE(7) | PULLUDDIS)},
+   {OFFSET(mii1_rxdv), (MODE(7) | PULLDOWN_EN)},
{-1},
 };
 
@@ -93,7 +85,5 @@ void enable_board_pin_mux(void)
 #ifdef CONFIG_NAND
configure_module_pin_mux(nand_pin_mux);
 #endif
-   configure_module_pin_mux(adc_voltages_en);
-   configure_module_pin_mux(asp_power_en);
-   configure_module_pin_mux(switch_off_3v6_pin_mux);
+   configure_module_pin_mux(guardian_interfaces_pin_mux);
 }
-- 
2.8.1

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


[U-Boot] [PATCH 2/2] am335x, guardian: adapt guardian board to DM

2019-09-17 Thread BollavarapuMoses.Christopher
From: Moses Christopher 

  - update partition table - remove env partitions
  - dts: add new interfaces (uart2, extra gpio-key)
 remove unneeded entries
 update nand timings for performance improvement
  - defconfig: adapt configurations to suit DM
   remove unneeded configs
  - am335x_guardian.h: remove mmc boot

Signed-off-by: Moses Christopher 
---
 arch/arm/dts/am335x-guardian.dts  | 102 ++
 configs/am335x_guardian_defconfig |  25 ++
 include/configs/am335x_guardian.h |  11 ++--
 3 files changed, 80 insertions(+), 58 deletions(-)

diff --git a/arch/arm/dts/am335x-guardian.dts b/arch/arm/dts/am335x-guardian.dts
index f3f022c..5ed2133 100644
--- a/arch/arm/dts/am335x-guardian.dts
+++ b/arch/arm/dts/am335x-guardian.dts
@@ -32,12 +32,19 @@
gpio_keys {
compatible = "gpio-keys";
pinctrl-names = "default";
-   pinctrl-0 = <&gpio_keys_pins>;
+   pinctrl-0 = <&guardian_button_pins>;
 
-   button21 {
+   select-button {
+   label = "guardian-select-button";
+   linux,code = ;
+   gpios = <&gpio1 31 GPIO_ACTIVE_LOW>;
+   wakeup-source;
+   };
+
+   power-button {
label = "guardian-power-button";
linux,code = ;
-   gpios = <&gpio2 21 0>;
+   gpios = <&gpio2 21 GPIO_ACTIVE_LOW>;
wakeup-source;
};
};
@@ -45,19 +52,12 @@
leds {
compatible = "gpio-leds";
pinctrl-names = "default";
-   pinctrl-0 = <&leds_pins>;
-
-   led1 {
-   label = "green:heartbeat";
-   gpios = <&gpio1 27 GPIO_ACTIVE_HIGH>;
-   linux,default-trigger = "heartbeat";
-   default-state = "off";
-   };
+   pinctrl-0 = <&guardian_led_pins>;
 
-   led2 {
-   label = "green:mmc0";
+   life-led {
+   label = "guardian:life-led";
gpios = <&gpio1 26 GPIO_ACTIVE_HIGH>;
-   linux,default-trigger = "mmc0";
+   linux,default-trigger = "heartbeat";
default-state = "off";
};
};
@@ -140,22 +140,25 @@
gpmc,device-width = <1>;
gpmc,sync-clk-ps = <0>;
gpmc,cs-on-ns = <0>;
-   gpmc,cs-rd-off-ns = <44>;
-   gpmc,cs-wr-off-ns = <44>;
-   gpmc,adv-on-ns = <6>;
-   gpmc,adv-rd-off-ns = <34>;
-   gpmc,adv-wr-off-ns = <44>;
+   gpmc,cs-rd-off-ns = <30>;
+   gpmc,cs-wr-off-ns = <30>;
+   gpmc,adv-on-ns = <0>;
+   gpmc,adv-rd-off-ns = <30>;
+   gpmc,adv-wr-off-ns = <30>;
gpmc,we-on-ns = <0>;
-   gpmc,we-off-ns = <40>;
-   gpmc,oe-on-ns = <0>;
-   gpmc,oe-off-ns = <54>;
-   gpmc,access-ns = <64>;
-   gpmc,rd-cycle-ns = <82>;
-   gpmc,wr-cycle-ns = <82>;
+   gpmc,we-off-ns = <15>;
+   gpmc,oe-on-ns = <1>;
+   gpmc,oe-off-ns = <15>;
+   gpmc,access-ns = <30>;
+   gpmc,rd-cycle-ns = <30>;
+   gpmc,wr-cycle-ns = <30>;
+   gpmc,wait-on-read = "true";
+   gpmc,wait-on-write = "true";
gpmc,bus-turnaround-ns = <0>;
gpmc,cycle2cycle-delay-ns = <0>;
gpmc,clk-activation-ns = <0>;
-   gpmc,wr-access-ns = <40>;
+   gpmc,wait-monitoring-ns = <0>;
+   gpmc,wr-access-ns = <0>;
gpmc,wr-data-mux-bus-ns = <0>;
 
/*
@@ -199,18 +202,8 @@
};
 
partition@6 {
-   label = "u-boot-env";
-   reg = <0x30 0x4>;
-   };
-
-   partition@7 {
-   label = "u-boot-env.backup1";
-   reg = <0x34 0x4>;
-   };
-
-   partition@8 {
label = "UBI";
-   reg = <0x38 0x1fc8>;
+   reg = <0x30 0x1fd0>;
};
};
 };
@@ -326,6 +319,12 @@
status = "okay";
 };
 
+&uart2 {
+   pinctrl-names = "default";
+   pinctrl-0 = <&uart2_pins>;
+   status = "okay";
+};
+
 &usb {
status = "okay";
 };
@@ -354,7 +353,7 @@
 
 &am33xx_pinmux {
pinctrl-names = "default";
-   pinctrl-0 = <&clkout2_pin &gpio_pins>;
+   pinctrl-0 = <&clkout2_pin &guardian_interface_pins>;
 
clkout2_pin: pinmux_clkout2_pin {
pinctrl-single,

[U-Boot] Raspberry PI Compute Module - UART Issue

2019-09-17 Thread Lee Annamalai
Hi

I am using a Raspberry PI compute module (CM 3+), which seems to be running 
U-Boot - U-Boot 2019.04-dirty (Aug 21 2019 - 14:41:54 +)

The CM3+ is communicating on the UART at boot, before the Kernel loads:

U-Boot 2019.04-dirty (Aug 21 2019 - 14:41:54 +)

DRAM:  948 MiB
RPI Compute Module 3 (0xa220a0)
MMC:   mmc@7e202000: 0, sdhci@7e30: 1
Loading Environment from FAT... WARNING at 
drivers/mmc/bcm2835_sdhost.c:408/bcm2835_send_command()!
WARNING at drivers/mmc/bcm2835_sdhost.c:408/bcm2835_send_OK
In:serial
Out:   serial
 1  0
WARNING at drivers/mmc/bcm2835_sdhost.c:408/bcm2835_send_command()!
WARNING at drivers/mmc/bcm2835_sdhost.c:408/bcm2835_send_command()!
switch to partitions #0, OK
mmc0(part 0) is current device
LOADBOOTENV
Running uenvcmd ...
ENVCMD
6697472 bytes read in 285 ms (22.4 MiB/s)
3647066 bytes read in 155 ms (22.4 MiB/s)
42064 bytes read in 12 ms (3.3 MiB/s)
Kernel image @ 0x20 [ 0x00 - 0x663200 ]
## Flattened Device Tree blob at 0200
   Booting using the fdt blob at OK
   Loa
Starting kern



I however have a serial device connected to the UART and it starts 
communicating on power on to the UART. This is causing the boot process to stop.

I would like to find out how to stop U-BOOT from reading messages on the UART 
at boot?

Regards
Lee Annamalai
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] rockchip: rk3399: TPL: rockpro64: Wrong memory size detected

2019-09-17 Thread Kurt Miller
On Tue, 2019-09-17 at 10:57 +0800, Kever Yang wrote:
> Hi Kurt,
> 
>  Could you try with below update:
> 
> 
> diff --git a/arch/arm/dts/rk3399-sdram-lpddr4-100.dtsi 
> b/arch/arm/dts/rk3399-sdram-lpddr4-100.dtsi
> index 4a4414a960..dc9db047cb 100644
> --- a/arch/arm/dts/rk3399-sdram-lpddr4-100.dtsi
> +++ b/arch/arm/dts/rk3399-sdram-lpddr4-100.dtsi
> @@ -13,8 +13,8 @@
>                  0x2
>                  0x1
>                  0x0
> -               0xf
> -               0xf
> +               0x10
> +               0x10
>                  1
>                  0x80241d22
>                  0x15050f08
> @@ -28,8 +28,8 @@
>                  0x2
>                  0x1
>                  0x0
> -               0xf
> -               0xf
> +               0x10
> +               0x10
>                  1
>                  0x80241d22
>                  0x15050f08
> 
> Thanks,
> - Kever

Hi Kever,

Yes, that diff does correct the memory size detection
for my board:

U-Boot TPL 2019.10-rc3-00332-ga314ec1bfd-dirty (Sep 17 2019 - 11:55:26)
con reg
cru , cic , grf , sgrf , pmucru , pmu 
Starting SDRAM initialization...
sdram_init: data trained for rank 1, ch 0
sdram_init: data trained for rank 1, ch 1
Channel 0: LPDDR4, 50MHz
BW=32 Col=10 Bk=8 CS0 Row=16 CS=1 Die BW=16 Size=2048MB
Channel 1: LPDDR4, 50MHz
BW=32 Col=10 Bk=8 CS0 Row=16 CS=1 Die BW=16 Size=2048MB
256B stride
lpddr4_set_ctl: channel 0 training pass
lpddr4_set_ctl: channel 1 training pass
lpddr4_set_rate: change freq to 400 mhz 0, 1
lpddr4_set_ctl: channel 0 training pass
lpddr4_set_ctl: channel 1 training pass
lpddr4_set_rate: change freq to 800 mhz 1, 0
Finish SDRAM initialization...
Trying to boot from BOOTROM
Returning to boot ROM...

Thank you,
-Kurt
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v2 2/4] libfdt: return correct value if #size-cells property is not present

2019-09-17 Thread Simon Glass
Hi Matthias,

On Tue, 17 Sep 2019 at 00:29, Matthias Brugger  wrote:
>
> Hi Simon,
>
> On 17/09/2019 07:48, Simon Glass wrote:
> > Hi,
> >
> > On Thu, 5 Sep 2019 at 02:49,  wrote:
> >>
> >> From: Matthias Brugger 
> >>
> >> According to the device tree specification, the default value for
> >> was not present.
> >>
> >> This patch also makes fdt_address_cells() and fdt_size_cells() conform
> >> to the behaviour documented in libfdt.h. The defaults are only returned
> >> if fdt_getprop() returns -FDT_ERR_NOTFOUND, otherwise the actual error
> >> is returned.
> >>
> >> This is based on upstream commit:
> >> aa7254d ("libfdt: return correct value if #size-cells property is not 
> >> present")
> >> but misses the test case part, as we don't implement them in U-Boot.
> >>
> >> Signed-off-by: Matthias Brugger 
> >
> > This is v2 but I don't see a change log?
> >
>
> I put the changelog into the cover letter:
> https://patchwork.ozlabs.org/cover/1158304/
>
> From your email I understand that you prefer a patch by patch changelog, 
> correct?

Both is best. If you use patman it does this for you.

Regards,
Simon
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH 1/4] mx6: clock: Allow enable_ipu_clock() to be built for SPL code

2019-09-17 Thread Fabio Estevam
Hi Stefano,

Could this series be applied, please?

On Fri, Jul 12, 2019 at 9:32 AM Fabio Estevam  wrote:
>
> Allow enable_ipu_clock() to be built for SPL code. This is done
> in preparation for configuring the NoC registers on i.MX6QP in SPL.
>
> Signed-off-by: Fabio Estevam 
> ---
>  arch/arm/mach-imx/mx6/clock.c | 32 
>  1 file changed, 16 insertions(+), 16 deletions(-)
>
> diff --git a/arch/arm/mach-imx/mx6/clock.c b/arch/arm/mach-imx/mx6/clock.c
> index 366a4e3c6b..5af1ae7cf3 100644
> --- a/arch/arm/mach-imx/mx6/clock.c
> +++ b/arch/arm/mach-imx/mx6/clock.c
> @@ -1275,6 +1275,22 @@ unsigned int mxc_get_clock(enum mxc_clock clk)
> return 0;
>  }
>
> +#ifndef CONFIG_MX6SX
> +void enable_ipu_clock(void)
> +{
> +   struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
> +   int reg;
> +   reg = readl(&mxc_ccm->CCGR3);
> +   reg |= MXC_CCM_CCGR3_IPU1_IPU_MASK;
> +   writel(reg, &mxc_ccm->CCGR3);
> +
> +   if (is_mx6dqp()) {
> +   setbits_le32(&mxc_ccm->CCGR6, MXC_CCM_CCGR6_PRG_CLK0_MASK);
> +   setbits_le32(&mxc_ccm->CCGR3, MXC_CCM_CCGR3_IPU2_IPU_MASK);
> +   }
> +}
> +#endif
> +
>  #ifndef CONFIG_SPL_BUILD
>  /*
>   * Dump some core clockes.
> @@ -1311,22 +1327,6 @@ int do_mx6_showclocks(cmd_tbl_t *cmdtp, int flag, int 
> argc, char * const argv[])
> return 0;
>  }
>
> -#ifndef CONFIG_MX6SX
> -void enable_ipu_clock(void)
> -{
> -   struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
> -   int reg;
> -   reg = readl(&mxc_ccm->CCGR3);
> -   reg |= MXC_CCM_CCGR3_IPU1_IPU_MASK;
> -   writel(reg, &mxc_ccm->CCGR3);
> -
> -   if (is_mx6dqp()) {
> -   setbits_le32(&mxc_ccm->CCGR6, MXC_CCM_CCGR6_PRG_CLK0_MASK);
> -   setbits_le32(&mxc_ccm->CCGR3, MXC_CCM_CCGR3_IPU2_IPU_MASK);
> -   }
> -}
> -#endif
> -
>  #if defined(CONFIG_MX6Q) || defined(CONFIG_MX6D) || defined(CONFIG_MX6DL) || 
> \
> defined(CONFIG_MX6S)
>  static void disable_ldb_di_clock_sources(void)
> --
> 2.17.1
>
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH] dm: pinctrl: Skip not associated gpio phandle and rise an error message

2019-09-17 Thread Michael Nazzareno Trimarchi
Hi

On Tue, Sep 17, 2019 at 7:48 AM Simon Glass  wrote:
>
> Hi Michael,
>
> On Sun, 15 Sep 2019 at 04:45, Michael Trimarchi
>  wrote:
> >
> > Skip not associated gpio phandle let register the other gpios and
> > the error message add some information to debug the problem using
> > a decompiled version of the dts
> >
> > dtc -I dtb -O dts -o devicetree.dts spl/u-boot-spl.dtb
> >
> > Signed-off-by: Michael Trimarchi 
> > ---
> >  drivers/pinctrl/pinctrl-uclass.c | 14 ++
> >  1 file changed, 10 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/pinctrl/pinctrl-uclass.c 
> > b/drivers/pinctrl/pinctrl-uclass.c
> > index 5b1cd29d86..87b0c3e35b 100644
> > --- a/drivers/pinctrl/pinctrl-uclass.c
> > +++ b/drivers/pinctrl/pinctrl-uclass.c
> > @@ -91,12 +91,18 @@ static int pinctrl_select_state_full(struct udevice 
> > *dev, const char *statename)
> > phandle = fdt32_to_cpu(*list++);
> > ret = uclass_get_device_by_phandle_id(UCLASS_PINCONFIG, 
> > phandle,
> >   &config);
> > -   if (ret)
> > -   return ret;
> > +   if (ret) {
> > +   dev_err(dev, "%s: uclass_get_device_by_phandle_id: 
> > err=%d\n",
> > +   __func__, ret);
> > +   continue;
>
> If is is an error, why continue?

It's not a fatal error, it helps to people to fix their board-uboot.dtsi file
>
> Perhaps a warning or a log_debug() instead?

Ok I will change

Michael

>
> > +   }
> >
> > ret = pinctrl_config_one(config);
> > -   if (ret)
> > -   return ret;
> > +   if (ret) {
> > +   dev_err(dev, "%s: pinctrl_config_one: err=%d\n",
> > +   __func__, ret);
> > +   continue;
> > +   }
> > }
> >
> > return 0;
> > --
> > 2.17.1
> >
>
> Regards,
> Simon



-- 
| Michael Nazzareno Trimarchi Amarula Solutions BV |
| COO  -  Founder  Cruquiuskade 47 |
| +31(0)851119172 Amsterdam 1018 AM NL |
|  [`as] http://www.amarulasolutions.com   |
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH] mmc: dw_mmc: Clean up variable name

2019-09-17 Thread Michael Nazzareno Trimarchi
Hi

On Mon, Sep 16, 2019 at 3:24 AM Peng Fan  wrote:
>
> > Subject: [PATCH] mmc: dw_mmc: Clean up variable name
>

I will resend.

Michael
> Please at least write some commit message here.
>
> Thanks,
> Peng.
>
> >
> > Signed-off-by: Michael Trimarchi 
> > ---
> >  drivers/mmc/dw_mmc.c | 4 ++--
> >  include/dwmmc.h  | 4 ++--
> >  2 files changed, 4 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/mmc/dw_mmc.c b/drivers/mmc/dw_mmc.c index
> > ebe7bcdd90..e5b532a862 100644
> > --- a/drivers/mmc/dw_mmc.c
> > +++ b/drivers/mmc/dw_mmc.c
> > @@ -86,7 +86,7 @@ static void dwmci_prepare_data(struct dwmci_host
> > *host,
> >   flush_dcache_range(data_start, roundup(data_end,
> > ARCH_DMA_MINALIGN));
> >
> >   ctrl = dwmci_readl(host, DWMCI_CTRL);
> > - ctrl |= DWMCI_IDMAC_EN | DWMCI_DMA_EN;
> > + ctrl |= DWMCI_CTRL_USE_IDMAC | DWMCI_CTRL_DMA_EN;
> >   dwmci_writel(host, DWMCI_CTRL, ctrl);
> >
> >   ctrl = dwmci_readl(host, DWMCI_BMOD);
> > @@ -383,7 +383,7 @@ static int dwmci_send_cmd(struct mmc *mmc, struct
> > mmc_cmd *cmd,
> >   dwmci_writel(host, DWMCI_IDSTS, DWMCI_IDINTEN_MASK);
> >
> >   ctrl = dwmci_readl(host, DWMCI_CTRL);
> > - ctrl &= ~(DWMCI_DMA_EN);
> > + ctrl &= ~(DWMCI_CTRL_DMA_EN);
> >   dwmci_writel(host, DWMCI_CTRL, ctrl);
> >   bounce_buffer_stop(&bbstate);
> >   }
> > diff --git a/include/dwmmc.h b/include/dwmmc.h index
> > f06720dc0d..2f57b6e774 100644
> > --- a/include/dwmmc.h
> > +++ b/include/dwmmc.h
> > @@ -75,9 +75,9 @@
> >  #define DWMCI_CTRL_RESET (1 << 0)
> >  #define DWMCI_CTRL_FIFO_RESET(1 << 1)
> >  #define DWMCI_CTRL_DMA_RESET (1 << 2)
> > -#define DWMCI_DMA_EN (1 << 5)
> > +#define DWMCI_CTRL_DMA_EN(1 << 5)
> >  #define DWMCI_CTRL_SEND_AS_CCSD  (1 << 10)
> > -#define DWMCI_IDMAC_EN   (1 << 25)
> > +#define DWMCI_CTRL_USE_IDMAC (1 << 25)
> >  #define DWMCI_RESET_ALL  (DWMCI_CTRL_RESET |
> > DWMCI_CTRL_FIFO_RESET |\
> >   DWMCI_CTRL_DMA_RESET)
> >
> > --
> > 2.17.1
>


-- 
| Michael Nazzareno Trimarchi Amarula Solutions BV |
| COO  -  Founder  Cruquiuskade 47 |
| +31(0)851119172 Amsterdam 1018 AM NL |
|  [`as] http://www.amarulasolutions.com   |
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v2 8/9] spl: Introduce SPL_DM_GPIO Kconfig define

2019-09-17 Thread Simon Glass
Hi Lukasz,

On Tue, 17 Sep 2019 at 00:22, Lukasz Majewski  wrote:
>
> Hi Simon,
>
> > On Sun, 18 Aug 2019 at 19:30, Peng Fan  wrote:
> > >
> > > > Subject: [PATCH v2 8/9] spl: Introduce SPL_DM_GPIO Kconfig define
> > > >
> > > > This define indicates if DM_GPIO shall be supported in SPL. This
> > > > allows proper operation of DM converted GPIO drivers in SPL,
> > > > which use #if !CONFIG_IS_ENABLED(DM_GPIO) to also support not yet
> > > > DM/DTS converted boards.
> > > >
> > > > Signed-off-by: Lukasz Majewski 
> > > > ---
> > > >
> > > > Changes in v2:
> > > > - New patch
> > > >
> > > >  common/spl/Kconfig | 6 ++
> > > >  1 file changed, 6 insertions(+)
> > > >
> >
> > Reviewed-by: Simon Glass 
> >
> > But how about adding && DM_GPIO as well to that depends clause?
>
> I think that they shall be a separate Kconfig options. Please imagine
> that one have board with SPL GPIO support, but not in U-Boot proper.

Do we really want to support that? It seems a bit odd to me.

Most of the DM SPL configs assume/requiree you have U-Boot proper enabled.

Regards,
Simon
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] Raspberry PI Compute Module - UART Issue

2019-09-17 Thread Belisko Marek
Hi Lee,

On Tue, Sep 17, 2019 at 4:45 PM Lee Annamalai  wrote:
>
> Hi
>
> I am using a Raspberry PI compute module (CM 3+), which seems to be running 
> U-Boot - U-Boot 2019.04-dirty (Aug 21 2019 - 14:41:54 +)
>
> The CM3+ is communicating on the UART at boot, before the Kernel loads:
>
> U-Boot 2019.04-dirty (Aug 21 2019 - 14:41:54 +)
>
> DRAM:  948 MiB
> RPI Compute Module 3 (0xa220a0)
> MMC:   mmc@7e202000: 0, sdhci@7e30: 1
> Loading Environment from FAT... WARNING at 
> drivers/mmc/bcm2835_sdhost.c:408/bcm2835_send_command()!
> WARNING at drivers/mmc/bcm2835_sdhost.c:408/bcm2835_send_OK
> In:serial
> Out:   serial
> 1 0
> WARNING at drivers/mmc/bcm2835_sdhost.c:408/bcm2835_send_command()!
> WARNING at drivers/mmc/bcm2835_sdhost.c:408/bcm2835_send_command()!
> switch to partitions #0, OK
> mmc0(part 0) is current device
> LOADBOOTENV
> Running uenvcmd ...
> ENVCMD
> 6697472 bytes read in 285 ms (22.4 MiB/s)
> 3647066 bytes read in 155 ms (22.4 MiB/s)
> 42064 bytes read in 12 ms (3.3 MiB/s)
> Kernel image @ 0x20 [ 0x00 - 0x663200 ]
> ## Flattened Device Tree blob at 0200
>Booting using the fdt blob at OK
>Loa
> Starting kern
>
>
>
> I however have a serial device connected to the UART and it starts 
> communicating on power on to the UART. This is causing the boot process to 
> stop.
>
> I would like to find out how to stop U-BOOT from reading messages on the UART 
> at boot?
Please try to set bootdelay to 0 or -1 (this will force not to read
for user input). I suggest to read in u-boot docs article about
autoboot (will give you some more background).
>
> Regards
> Lee Annamalai
> ___
> U-Boot mailing list
> U-Boot@lists.denx.de
> https://lists.denx.de/listinfo/u-boot

BR,

marek

-- 
as simple and primitive as possible
-
Marek Belisko - OPEN-NANDRA
Freelance Developer

Ruska Nova Ves 219 | Presov, 08005 Slovak Republic
Tel: +421 915 052 184
skype: marekwhite
twitter: #opennandra
web: http://open-nandra.com
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v2 8/9] spl: Introduce SPL_DM_GPIO Kconfig define

2019-09-17 Thread Adam Ford
On Tue, Sep 17, 2019 at 1:34 PM Simon Glass  wrote:
>
> Hi Lukasz,
>
> On Tue, 17 Sep 2019 at 00:22, Lukasz Majewski  wrote:
> >
> > Hi Simon,
> >
> > > On Sun, 18 Aug 2019 at 19:30, Peng Fan  wrote:
> > > >
> > > > > Subject: [PATCH v2 8/9] spl: Introduce SPL_DM_GPIO Kconfig define
> > > > >
> > > > > This define indicates if DM_GPIO shall be supported in SPL. This
> > > > > allows proper operation of DM converted GPIO drivers in SPL,
> > > > > which use #if !CONFIG_IS_ENABLED(DM_GPIO) to also support not yet
> > > > > DM/DTS converted boards.
> > > > >

Many of the drivers list the SPL_DM options under their respective
heading.  For example, SPL_DM_USB is under the USB menu right next to
the option to select CONFIG_DM_USB.
If we're going to add the option to separate DM_GPIO from SPL_DM_GPIO,
I would suggest following that pattern and place it in the GPIO menu
so they are next to each other and make the dependency obvious.

adam

> > > > > Signed-off-by: Lukasz Majewski 
> > > > > ---
> > > > >
> > > > > Changes in v2:
> > > > > - New patch
> > > > >
> > > > >  common/spl/Kconfig | 6 ++
> > > > >  1 file changed, 6 insertions(+)
> > > > >
> > >
> > > Reviewed-by: Simon Glass 
> > >
> > > But how about adding && DM_GPIO as well to that depends clause?
> >
> > I think that they shall be a separate Kconfig options. Please imagine
> > that one have board with SPL GPIO support, but not in U-Boot proper.
>
> Do we really want to support that? It seems a bit odd to me.
>
> Most of the DM SPL configs assume/requiree you have U-Boot proper enabled.
>
> Regards,
> Simon
> ___
> U-Boot mailing list
> U-Boot@lists.denx.de
> https://lists.denx.de/listinfo/u-boot
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v2 1/2] Revert "configs: Remove am335x_boneblack_defconfig"

2019-09-17 Thread Sam Protsenko
On Tue, Sep 17, 2019 at 7:50 AM Lokesh Vutla  wrote:
>
>
>
> On 16/09/19 4:53 PM, Sam Protsenko wrote:
> > Hi Lokesh,
> >
> > On Mon, Sep 16, 2019 at 11:34 AM Lokesh Vutla  wrote:
> >>
> >>
> >>
> >> On 12/09/19 11:20 PM, Sam Protsenko wrote:
> >>> Commit 8fa7f65dd02c ("configs: Remove am335x_boneblack_defconfig")
> >>> removes defconfig for BeagleBone Black board, and it's advised to use
> >>> am335x_evm_defconfig for all AM335x boards. But it's impossible to store
> >>> environment in eMMC with am335x_evm_defconfig without modifications
> >>> (NAND must be disabled, MMC enabled, etc). This is inconvenient for user
> >>> to do such modifications via menuconfig (only developer knows what
> >>> should be done). Furthermore, enabling MMC options in
> >>> am335x_evm_defconfig leads to wrong pin-muxing scheme in
> >>> board/ti/am335x/mux.c, because both NAND and MMC options are enabled in
> >>> the config, so that pins are muxed for BBB with NAND cape, which in turn
> >>> leads to non-functioning eMMC. There is no way to make the single 
> >>> defconfig
> >>> working for both eMMC and NAND use-cases, because we can't figure out in
> >>> run-time which board configuration is used by user (EVM, BBB, or BBB with
> >>> NAND cape). Hence we rely on CONFIG options to figure out which
> >>> configuration is used. Because of this we can't use single defconfig for
> >>> AM335x EVM and BBB.
> >>>
> >>> All that said, let's bring back am335x_boneblack_defconfig, because
> >>> right now users are not able to use U-Boot for BBB. Further patch will
> >>
> >> I did not understand why users are not able to use BBB using
> >> am335x_evm_defconfig? ENV is stored in FAT and is working properly. What is
> >> wrong with that? Is it that eMMC boot is failing?
> >>
> >
> > The eMMC boot works. But with that config it's impossible to store ENV
> > on eMMC. Some users prefer to use eMMC exclusively, with SD card
> > removed. In that case the user won't be able to store U-Boot
> > environment on eMMC. Furthermore, when enabling environment in eMMC by
>
> Hmm..Creating a defconfig for supporting separate env storage doesn't sound
> right. U-boot has support for storing env in multiple places. Any chance you
> tried that option?
>

I tried to enable both CONFIG_ENV_IS_IN_MMC=y and
CONFIG_ENV_IS_NAND=y, that's the case I'm describing above, hope
that's what you mean by multiple env? The issue is pinmuxing, as I
said, which can't be done differently (at least I don't see such
options), which leads to broken pinmux configuration when enabling
CONFIG_ENV_IS_IN_MMC=y along with CONFIG_ENV_IS_IN_NAND=y.

So basically I want the defconfig which I can use "as is" for
BeagleBone Black with eMMC and SD card. am335x_boneblack_defconfig was
such defconfig. With am335x_evm_defconfig I wasn't able to make U-Boot
store env on eMMC (without disabling NAND).

Do you see by chance some better way around, other than creating new
defconfig? Maybe pinmuxing can be done in other way, like probing
current NAND/NOR/MMC configuration dynamically (can be hard for cases
like BBB with NAND cape connected)?

Thanks!

> Thanks and regards,
> Lokesh
>
> > next two options:>
> >   1. CONFIG_ENV_IS_IN_MMC=y
> >   2. CONFIG_SYS_EXTRA_OPTIONS="EMMC_BOOT"
> >
> > the boot will be broken due to wrong pin muxing when both CONFIG_NAND
> > and CONFIG_EMMC_BOOT are enabled. And we can't fix pin muxing, because
> > it relies on compile-time configuration, because we don't have means
> > to figure out configurations like BBB + NAND cape in run-time. So the
> > only way I see to provide a way to store ENV on eMMC is to keep
> > separate config.
> >
> > I agree that commit message should be fixed. Also, maybe we should
> > rename configs like this:
> >
> >- am335x_evm_defconfig -> am335x_nand_defconfig
> >- am335x_boneblack_defconfig -> am335x_emmc_defconfig> Do you think it's 
> > correct way to do so? Or some better way exists?
> >
> > Thanks!
> >
> >> Thanks and regards,
> >> Lokesh
> >>
> >>> update this defconfig by enabling Driver Model and pulling some other
> >>> useful options from am335x_evm_defconfig.
> >>>
> >>> Fixes: 8fa7f65dd02c ("configs: Remove am335x_boneblack_defconfig")
> >>> Signed-off-by: Sam Protsenko 
> >>> ---
> >>> Changes in v2:
> >>>   - improve commit message by saying explicitly about eMMC env
> >>>
> >>>  configs/am335x_boneblack_defconfig | 50 ++
> >>>  1 file changed, 50 insertions(+)
> >>>  create mode 100644 configs/am335x_boneblack_defconfig
> >>>
> >>> diff --git a/configs/am335x_boneblack_defconfig 
> >>> b/configs/am335x_boneblack_defconfig
> >>> new file mode 100644
> >>> index 00..439d0cba05
> >>> --- /dev/null
> >>> +++ b/configs/am335x_boneblack_defconfig
> >>> @@ -0,0 +1,50 @@
> >>> +CONFIG_ARM=y
> >>> +CONFIG_ARCH_OMAP2PLUS=y
> >>> +CONFIG_TI_COMMON_CMD_OPTIONS=y
> >>> +CONFIG_AM33XX=y
> >>> +CONFIG_SPL=y
> >>> +CONFIG_DISTRO_DEFAULTS=y
> >>> +CONFIG_SYS_EXTRA_OPTIONS="EMMC_BOOT"
> >>> +CONFIG_

[U-Boot] [PATCH] configs: ti: Use addr_fit for run_fit environment variable

2019-09-17 Thread Andrew F. Davis
When running 'run_fit' the FIT file should have been loaded at
'addr_fit', although at this point they should be the same
use this variable instead of 'loadaddr'.

Signed-off-by: Andrew F. Davis 
---
 include/configs/ti_armv7_common.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/configs/ti_armv7_common.h 
b/include/configs/ti_armv7_common.h
index 2de6bc2390..6d15304a65 100644
--- a/include/configs/ti_armv7_common.h
+++ b/include/configs/ti_armv7_common.h
@@ -60,7 +60,7 @@
"do;" \
"setenv overlaystring ${overlaystring}'#'${overlay};" \
"done;\0" \
-   "run_fit=bootm ${loadaddr}#${fdtfile}${overlaystring}\0" \
+   "run_fit=bootm ${addr_fit}#${fdtfile}${overlaystring}\0" \
"loadfit=run args_mmc; run run_fit;\0" \
 
 /*
-- 
2.17.1

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


[U-Boot] [PATCH V2] dm: pinctrl: Skip not associated gpio phandle and rise a warning message

2019-09-17 Thread Michael Trimarchi
Skip not associated gpio phandle let register the other gpios on a group.
We need anyway to send out a warning to the user to fix their uboot-board.dtsi.
Thhe handle id can be found inside the decompiled dtb

dtc -I dtb -O dts -o devicetree.dts spl/u-boot-spl.dtb

Signed-off-by: Michael Trimarchi 
---
V1 -> V2:
- move dev_err to dev_warn
- adjust the commit message
---
 drivers/pinctrl/pinctrl-uclass.c | 14 ++
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/drivers/pinctrl/pinctrl-uclass.c b/drivers/pinctrl/pinctrl-uclass.c
index 5b1cd29d86..7d98fbc4ec 100644
--- a/drivers/pinctrl/pinctrl-uclass.c
+++ b/drivers/pinctrl/pinctrl-uclass.c
@@ -91,12 +91,18 @@ static int pinctrl_select_state_full(struct udevice *dev, 
const char *statename)
phandle = fdt32_to_cpu(*list++);
ret = uclass_get_device_by_phandle_id(UCLASS_PINCONFIG, phandle,
  &config);
-   if (ret)
-   return ret;
+   if (ret) {
+   dev_warn(dev, "%s: uclass_get_device_by_phandle_id: 
err=%d\n",
+   __func__, ret);
+   continue;
+   }
 
ret = pinctrl_config_one(config);
-   if (ret)
-   return ret;
+   if (ret) {
+   dev_warn(dev, "%s: pinctrl_config_one: err=%d\n",
+   __func__, ret);
+   continue;
+   }
}
 
return 0;
-- 
2.17.1

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


Re: [U-Boot] [PATCH v2 1/2] efi_loader: variable: support APPEND_WRITE

2019-09-17 Thread Heinrich Schuchardt

On 9/6/19 8:09 AM, AKASHI Takahiro wrote:

If EFI_VARIABLE_APPEND_WRITE is specified in attributes at
efi_set_variable(), specified data will be appended to the variable's
original value. Attributes other than APPEND_WRITE should not be
modified.

With this patch, APPEND_WRITE test in 'variables' selftest will pass.

Signed-off-by: AKASHI Takahiro 
---
  lib/efi_loader/efi_variable.c | 70 ++-
  1 file changed, 44 insertions(+), 26 deletions(-)

diff --git a/lib/efi_loader/efi_variable.c b/lib/efi_loader/efi_variable.c
index 6687b69a400d..48ee255f879b 100644
--- a/lib/efi_loader/efi_variable.c
+++ b/lib/efi_loader/efi_variable.c
@@ -424,17 +424,17 @@ efi_status_t EFIAPI efi_set_variable(u16 *variable_name,
 efi_uintn_t data_size, const void *data)
  {
char *native_name = NULL, *val = NULL, *s;
+   const char *old_val;
+   size_t old_size;
efi_status_t ret = EFI_SUCCESS;
u32 attr;

EFI_ENTRY("\"%ls\" %pUl %x %zu %p", variable_name, vendor, attributes,
  data_size, data);

-   /* TODO: implement APPEND_WRITE */
if (!variable_name || !*variable_name || !vendor ||
((attributes & EFI_VARIABLE_RUNTIME_ACCESS) &&
-!(attributes & EFI_VARIABLE_BOOTSERVICE_ACCESS)) ||
-   (attributes & EFI_VARIABLE_APPEND_WRITE)) {
+!(attributes & EFI_VARIABLE_BOOTSERVICE_ACCESS))) {
ret = EFI_INVALID_PARAMETER;
goto out;
}
@@ -445,35 +445,51 @@ efi_status_t EFIAPI efi_set_variable(u16 *variable_name,

  #define ACCESS_ATTR (EFI_VARIABLE_RUNTIME_ACCESS | 
EFI_VARIABLE_BOOTSERVICE_ACCESS)

-   if ((data_size == 0) || !(attributes & ACCESS_ATTR)) {
-   /* delete the variable: */
-   env_set(native_name, NULL);
-   ret = EFI_SUCCESS;
-   goto out;
-   }
+   old_val = env_get(native_name);
+   if (old_val) {
+   old_val = parse_attr(old_val, &attr);

-   val = env_get(native_name);
-   if (val) {
-   parse_attr(val, &attr);
-
-   /* We should not free val */
-   val = NULL;
+   /* check read-only first */
if (attr & READ_ONLY) {
ret = EFI_WRITE_PROTECTED;
goto out;
}

-   /*
-* attributes won't be changed
-* TODO: take care of APPEND_WRITE once supported
-*/
-   if (attr != attributes) {
+   if ((data_size == 0) || !(attributes & ACCESS_ATTR)) {


The understanding of EDK2 is that no access attributes means 'attributes
== 0' (Function VariableServiceSetVariable() in
MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c).

EFI_VARIABLE_APPEND_WRITE and data_size = 0 should not delete a variable
according to the UEFI spec:

"Unless the EFI_VARIABLE_APPEND_WRITE,
EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS, or
EFI_VARIABLE_ENHANCED_AUTHENTICATED_ACCESS attribute is set (see below),
using SetVariable() with a DataSize of zero will cause the entire
variable to be deleted."

Best regards

Heinrich


+   /* delete the variable: */
+   env_set(native_name, NULL);
+   ret = EFI_SUCCESS;
+   goto out;
+   }
+
+   /* attributes won't be changed */
+   if (attr != (attributes & ~EFI_VARIABLE_APPEND_WRITE)) {
ret = EFI_INVALID_PARAMETER;
goto out;
}
+
+   if (attributes & EFI_VARIABLE_APPEND_WRITE) {
+   if (!prefix(old_val, "(blob)")) {
+   return EFI_DEVICE_ERROR;
+   goto out;
+   }
+   old_size = strlen(old_val);
+   } else {
+   old_size = 0;
+   }
+   } else {
+   if ((data_size == 0) || !(attributes & ACCESS_ATTR) ||
+   (attributes & EFI_VARIABLE_APPEND_WRITE)) {
+   /* delete, but nothing to do */
+   ret = EFI_NOT_FOUND;
+   goto out;
+   }
+
+   old_size = 0;
}

-   val = malloc(2 * data_size + strlen("{ro,run,boot,nv}(blob)") + 1);
+   val = malloc(old_size + 2 * data_size
++ strlen("{ro,run,boot,nv}(blob)") + 1);
if (!val) {
ret = EFI_OUT_OF_RESOURCES;
goto out;
@@ -481,10 +497,7 @@ efi_status_t EFIAPI efi_set_variable(u16 *variable_name,

s = val;

-   /*
-* store attributes
-* TODO: several attributes are not supported
-*/
+   /* store attributes */
attributes &= (EFI_VARIABLE_NON_VOLATILE |
   EFI_VARIABLE_BOOTSERVICE_AC

Re: [U-Boot] [PATCH v2 8/9] spl: Introduce SPL_DM_GPIO Kconfig define

2019-09-17 Thread Lukasz Majewski
Hi Simon,

> Hi Lukasz,
> 
> On Tue, 17 Sep 2019 at 00:22, Lukasz Majewski  wrote:
> >
> > Hi Simon,
> >  
> > > On Sun, 18 Aug 2019 at 19:30, Peng Fan  wrote:  
> > > >  
> > > > > Subject: [PATCH v2 8/9] spl: Introduce SPL_DM_GPIO Kconfig
> > > > > define
> > > > >
> > > > > This define indicates if DM_GPIO shall be supported in SPL.
> > > > > This allows proper operation of DM converted GPIO drivers in
> > > > > SPL, which use #if !CONFIG_IS_ENABLED(DM_GPIO) to also
> > > > > support not yet DM/DTS converted boards.
> > > > >
> > > > > Signed-off-by: Lukasz Majewski 
> > > > > ---
> > > > >
> > > > > Changes in v2:
> > > > > - New patch
> > > > >
> > > > >  common/spl/Kconfig | 6 ++
> > > > >  1 file changed, 6 insertions(+)
> > > > >  
> > >
> > > Reviewed-by: Simon Glass 
> > >
> > > But how about adding && DM_GPIO as well to that depends clause?  
> >
> > I think that they shall be a separate Kconfig options. Please
> > imagine that one have board with SPL GPIO support, but not in
> > U-Boot proper.  
> 
> Do we really want to support that? It seems a bit odd to me.
> 
> Most of the DM SPL configs assume/requiree you have U-Boot proper
> enabled.

After some thoughts - I think that we shall add the dependency on 
DM_GPIO (the SPL_DM_GPIO shall be only visible when DM_GPIO is defined).

> 
> Regards,
> Simon



Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lu...@denx.de


pgpwJBvBN2x7j.pgp
Description: OpenPGP digital signature
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v2 8/9] spl: Introduce SPL_DM_GPIO Kconfig define

2019-09-17 Thread Lukasz Majewski
On Tue, 17 Sep 2019 14:19:33 -0500
Adam Ford  wrote:

> On Tue, Sep 17, 2019 at 1:34 PM Simon Glass  wrote:
> >
> > Hi Lukasz,
> >
> > On Tue, 17 Sep 2019 at 00:22, Lukasz Majewski 
> > wrote:  
> > >
> > > Hi Simon,
> > >  
> > > > On Sun, 18 Aug 2019 at 19:30, Peng Fan 
> > > > wrote:  
> > > > >  
> > > > > > Subject: [PATCH v2 8/9] spl: Introduce SPL_DM_GPIO Kconfig
> > > > > > define
> > > > > >
> > > > > > This define indicates if DM_GPIO shall be supported in SPL.
> > > > > > This allows proper operation of DM converted GPIO drivers
> > > > > > in SPL, which use #if !CONFIG_IS_ENABLED(DM_GPIO) to also
> > > > > > support not yet DM/DTS converted boards.
> > > > > >  
> 
> Many of the drivers list the SPL_DM options under their respective
> heading.  For example, SPL_DM_USB is under the USB menu right next to
> the option to select CONFIG_DM_USB.
> If we're going to add the option to separate DM_GPIO from SPL_DM_GPIO,
> I would suggest following that pattern and place it in the GPIO menu
> so they are next to each other and make the dependency obvious.

For the current patch I've followed the pattern and added SPL_DM_GPIO
to the "spl" submenu of menuconfig.

And as I've written in the other mail - I think that SPL_DM_GPIO shall
depend on DM_GPIO.

Considering the above - shall I place SPL_DM_GPIO next to DM_GPIO
section or to the "spl" submenu?

> 
> adam
> 
> > > > > > Signed-off-by: Lukasz Majewski 
> > > > > > ---
> > > > > >
> > > > > > Changes in v2:
> > > > > > - New patch
> > > > > >
> > > > > >  common/spl/Kconfig | 6 ++
> > > > > >  1 file changed, 6 insertions(+)
> > > > > >  
> > > >
> > > > Reviewed-by: Simon Glass 
> > > >
> > > > But how about adding && DM_GPIO as well to that depends clause?
> > > >  
> > >
> > > I think that they shall be a separate Kconfig options. Please
> > > imagine that one have board with SPL GPIO support, but not in
> > > U-Boot proper.  
> >
> > Do we really want to support that? It seems a bit odd to me.
> >
> > Most of the DM SPL configs assume/requiree you have U-Boot proper
> > enabled.
> >
> > Regards,
> > Simon
> > ___
> > U-Boot mailing list
> > U-Boot@lists.denx.de
> > https://lists.denx.de/listinfo/u-boot  



Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lu...@denx.de


pgpTfP0LuPMY5.pgp
Description: OpenPGP digital signature
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 2/3] tools: fit_image: Use fit_image_get_data_and_size for getting offset/size

2019-09-17 Thread Andrew F. Davis
This is very similar to fit_image_get_data but has the benefit of working
on FIT images with external data unlike fit_image_get_data. This is
useful for extracting sub-images from type of FIT image as this would
previously just silently fail. Add an error message also so if this
still fails it is easier to find out why.

Signed-off-by: Andrew F. Davis 
---
 tools/fit_image.c | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/tools/fit_image.c b/tools/fit_image.c
index 5aca634b5e..0e4c2271ce 100644
--- a/tools/fit_image.c
+++ b/tools/fit_image.c
@@ -738,9 +738,14 @@ static int fit_image_extract(
 {
const void *file_data;
size_t file_size = 0;
+   int ret;
 
-   /* get the "data" property of component at offset "image_noffset" */
-   fit_image_get_data(fit, image_noffset, &file_data, &file_size);
+   /* get the data address and size of component at offset "image_noffset" 
*/
+   ret = fit_image_get_data_and_size(fit, image_noffset, &file_data, 
&file_size);
+   if (ret) {
+   fprintf(stderr, "Could not get component information\n");
+   return ret;
+   }
 
/* save the "file_data" into the file specified by "file_name" */
return imagetool_save_subimage(file_name, (ulong) file_data, file_size);
-- 
2.17.1

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


[U-Boot] [PATCH 3/3] tools: dumpimage: Fall-though to print usage for help command

2019-09-17 Thread Andrew F. Davis
This has the same result but some compilers will warn about this
fall-through if there are statements as part of the label block.

Signed-off-by: Andrew F. Davis 
---
 tools/dumpimage.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/tools/dumpimage.c b/tools/dumpimage.c
index d5f893daf1..e5481435a7 100644
--- a/tools/dumpimage.c
+++ b/tools/dumpimage.c
@@ -104,7 +104,6 @@ int main(int argc, char **argv)
printf("dumpimage version %s\n", PLAIN_VERSION);
exit(EXIT_SUCCESS);
case 'h':
-   usage();
default:
usage();
break;
-- 
2.17.1

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


[U-Boot] [PATCH 1/3] tools: dumpimage: Provide more feedback on internal errors

2019-09-17 Thread Andrew F. Davis
The dumpimage utility errors out in a number of places without providing
sufficient feedback to allow the user to easily determine what has gone
wrong. Add additional error messages to make the cause of the failure
more obvious.

Signed-off-by: Andrew F. Davis 
---
 tools/dumpimage.c | 14 +-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/tools/dumpimage.c b/tools/dumpimage.c
index ee3d41dda4..d5f893daf1 100644
--- a/tools/dumpimage.c
+++ b/tools/dumpimage.c
@@ -35,14 +35,23 @@ static int dumpimage_extract_subimage(struct 
image_type_params *tparams,
if (tparams->verify_header) {
retval = tparams->verify_header((unsigned char *)ptr,
sbuf->st_size, ¶ms);
-   if (retval != 0)
+   if (retval != 0) {
+   fprintf(stderr, "%s: failed to verify header of %s\n",
+   params.cmdname, tparams->name);
return -1;
+   }
+
/*
 * Extract the file from the image
 * if verify is successful
 */
if (tparams->extract_subimage) {
retval = tparams->extract_subimage(ptr, ¶ms);
+   if (retval != 0) {
+   fprintf(stderr, "%s: extract_subimage failed 
for %s\n",
+   params.cmdname, tparams->name);
+   return -3;
+   }
} else {
fprintf(stderr,
"%s: extract_subimage undefined for %s\n",
@@ -175,6 +184,9 @@ int main(int argc, char **argv)
 * image type. Returns the error code if not matched
 */
retval = dumpimage_extract_subimage(tparams, ptr, &sbuf);
+   if (retval)
+   fprintf(stderr, "%s: Can't extract subimage from %s\n",
+   params.cmdname, params.imagefile);
} else {
/*
 * Print the image information for matched image type
-- 
2.17.1

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


Re: [U-Boot] [PATCH v4 01/15] video: bmp: check resolutions of panel/bitmap

2019-09-17 Thread Heinrich Schuchardt

On 9/13/19 11:47 AM, Yannick Fertré wrote:

If the size of the bitmap is bigger than the size of
the panel then errors appear when calculating axis alignment
and the copy of bitmap is done outside of framebuffer.

Signed-off-by: Yannick Fertré 
---
  drivers/video/video_bmp.c | 14 ++
  1 file changed, 14 insertions(+)

diff --git a/drivers/video/video_bmp.c b/drivers/video/video_bmp.c
index 193f37d..544bd5f 100644
--- a/drivers/video/video_bmp.c
+++ b/drivers/video/video_bmp.c
@@ -54,6 +54,13 @@ static void video_display_rle8_bitmap(struct udevice *dev,
height = get_unaligned_le32(&bmp->header.height);
bmap = (uchar *)bmp + get_unaligned_le32(&bmp->header.data_offset);

+   /* check if picture size exceed panel size */


%s/exceed/exceeds/


+   if (priv->xsize < width)
+   width = priv->xsize;


In case of BMP_RLE8_DELTA width is not checked before writing to the
frame buffer. So this modification of width will lead to unexpected effects.

In the 'default' case width is checked and this may lead to decoding errors.


+
+   if (priv->ysize < height)
+   height = priv->ysize;
+
x = 0;
y = height - 1;

@@ -249,6 +256,13 @@ int video_bmp_display(struct udevice *dev, ulong 
bmp_image, int x, int y,

padded_width = (width & 0x3 ? (width & ~0x3) + 4 : width);

+   /* check if picture size exceed panel size */
+   if (pwidth < width)
+   width = pwidth;
+
+   if (priv->ysize < height)
+   height = priv->ysize;
+


You forgot to consider the position (x,y) of the picture.

Best regards

Heinrich


if (align) {
video_splash_align_axis(&x, priv->xsize, width);
video_splash_align_axis(&y, priv->ysize, height);



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


[U-Boot] [PATCH] board: ti: am654: Disable TRNG node for HS devices

2019-09-17 Thread Andrew F. Davis
On HS devices the access to TRNG is restricted on the non-secure
ARM side, disable the node in DT to prevent firewall violations.

Signed-off-by: Andrew F. Davis 
---
 arch/arm/mach-k3/common.c | 20 
 arch/arm/mach-k3/include/mach/sys_proto.h |  2 ++
 board/ti/am65x/evm.c  | 15 +--
 3 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-k3/common.c b/arch/arm/mach-k3/common.c
index 3e36d90ace..c16afc654f 100644
--- a/arch/arm/mach-k3/common.c
+++ b/arch/arm/mach-k3/common.c
@@ -137,6 +137,26 @@ int fdt_fixup_msmc_ram(void *blob, char *parent_path, char 
*node_name)
 
return 0;
 }
+
+int fdt_disable_node(void *blob, char *node_path)
+{
+   int offs;
+   int ret;
+
+   offs = fdt_path_offset(blob, node_path);
+   if (offs < 0) {
+   debug("Node %s not found.\n", node_path);
+   return 0;
+   }
+   ret = fdt_setprop_string(blob, offs, "status", "disabled");
+   if (ret < 0) {
+   printf("Could not add status property to node %s: %s\n",
+  node_path, fdt_strerror(ret));
+   return ret;
+   }
+   return 0;
+}
+
 #endif
 
 #ifndef CONFIG_SYSRESET
diff --git a/arch/arm/mach-k3/include/mach/sys_proto.h 
b/arch/arm/mach-k3/include/mach/sys_proto.h
index 45832b45a1..3c825aa3d1 100644
--- a/arch/arm/mach-k3/include/mach/sys_proto.h
+++ b/arch/arm/mach-k3/include/mach/sys_proto.h
@@ -14,4 +14,6 @@ struct ti_sci_handle *get_ti_sci_handle(void);
 int fdt_fixup_msmc_ram(void *blob, char *parent_path, char *node_name);
 int do_board_detect(void);
 void release_resources_for_core_shutdown(void);
+int fdt_disable_node(void *blob, char *node_path);
+
 #endif
diff --git a/board/ti/am65x/evm.c b/board/ti/am65x/evm.c
index e01adcd642..ad333ad883 100644
--- a/board/ti/am65x/evm.c
+++ b/board/ti/am65x/evm.c
@@ -96,10 +96,21 @@ int ft_board_setup(void *blob, bd_t *bd)
int ret;
 
ret = fdt_fixup_msmc_ram(blob, "/interconnect@10", "sram@7000");
-   if (ret)
+   if (ret) {
printf("%s: fixing up msmc ram failed %d\n", __func__, ret);
+   return ret;
+   }
 
-   return ret;
+#if defined(CONFIG_TI_SECURE_DEVICE)
+   /* Make HW RNG reserved for secure world use */
+   ret = fdt_disable_node(blob, "/interconnect@10/trng@4e1");
+   if (ret) {
+   printf("%s: disabling TRGN failed %d\n", __func__, ret);
+   return ret;
+   }
+#endif
+
+   return 0;
 }
 #endif
 
-- 
2.17.1

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


[U-Boot] [PATCH] ARM: keystone2: update the default addresses of the secure monitor

2019-09-17 Thread Andrew F. Davis
From: Jean-Jacques Hiblot 

To accommodate the growth of u-boot, we need to shift the location of the
secure monitor. Moving it 64kB further.

Signed-off-by: Jean-Jacques Hiblot 
---
 include/configs/ti_armv7_keystone2.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/configs/ti_armv7_keystone2.h 
b/include/configs/ti_armv7_keystone2.h
index d7bb1efcbf..ba12428dbe 100644
--- a/include/configs/ti_armv7_keystone2.h
+++ b/include/configs/ti_armv7_keystone2.h
@@ -217,8 +217,8 @@
"addr_secdb_key=0xc00\0"\
"name_kern=zImage\0"\
"addr_mon=0x8700\0" \
-   "addr_non_sec_mon=0x0c087fc0\0" \
-   "addr_load_sec_bm=0x0c08c000\0" \
+   "addr_non_sec_mon=0x0c097fc0\0" \
+   "addr_load_sec_bm=0x0c09c000\0" \
"run_mon=mon_install ${addr_mon}\0" \
"run_mon_hs=mon_install ${addr_non_sec_mon} "   \
"${addr_load_sec_bm}\0" \
-- 
2.17.1

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


Re: [U-Boot] [PATCH] net: Always build the string_to_enetaddr() helper

2019-09-17 Thread Joe Hershberger
Hi Simon,

On Sat, Sep 14, 2019 at 1:55 PM Simon Goldschmidt
 wrote:
>
> Joe Hershberger  schrieb am Sa., 14. Sep. 2019,
> 20:46:
>
> > On Sat, Sep 14, 2019 at 1:32 PM Tom Rini  wrote:
> > >
> > > On Sat, Sep 14, 2019 at 04:05:44PM +0200, Ondřej Jirman wrote:
> > > > Hi,
> > > >
> > > > On Fri, Sep 13, 2019 at 07:40:22PM -0500, Joe Hershberger wrote:
> > > > > Part of the env cleanup moved this out of the environment code and
> > into
> > > > > the net code. However, this helper is sometimes needed even when the
> > net
> > > > > stack isn't included.
> > > > >
> > > > > Move the helper to lib/net_utils.c like it's similarly-purposed
> > > > > string_to_ip(). Also rename the moved function to similar naming.
> > > > >
> > > > > Signed-off-by: Joe Hershberger 
> > > > > Reported-by: Ondrej Jirman 
> > > >
> > > > I've tested the patch and it works, but I'be found other related
> > issue, where
> > > > u-boot thinks %pM will format a MAC address string, but it does just
> > > > print out the pointer due to relevant functions being gated by
> > CONFIG_CMD_NET
> > > > guard in lib/vsprintf.c.
> > > >
> > > > The gating should probably be done so that it panics/halts the u-boot
> > if gated
> > > > pointer flags are used by u-boot code, because that will clearly be
> > incorrect,
> > > > without calling code ever knowing. This way the user will know that
> > something
> > > > is wrong and will have to fix the code.
> > >
> > > I'm not in favor of panic because of calling an unimplemented print
> > > format character.  I guess we'll need to see what the size increase is
> > > on un-guarding these formats and go from there.
> >
> > I'll look into it. I'm also not in favor of a panic.
> >
>
> In lwIP, we're using macros for such format characters. Would it work to do
> that here and make the compiler complain about an undefined symbol of the
> macro for this extended format character isn't defined?

Maybe... Though, if we don't successfully police the usage of the
macro, it won't help. I'd like to evaluate the code-size impact and
maybe just always include it.

-Joe

> Regards,
> Simon
> ___
> U-Boot mailing list
> U-Boot@lists.denx.de
> https://lists.denx.de/listinfo/u-boot
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH 09/17] mx6sabresd: convert to DM_VIDEO

2019-09-17 Thread Anatolij Gustschin
Hi Fabio,

On Tue, 17 Sep 2019 09:32:37 -0300
Fabio Estevam feste...@gmail.com wrote:

> Hi Anatolij,
> 
> On Mon, Sep 16, 2019 at 4:21 PM Anatolij Gustschin  wrote:
> 
> > Most probably this is because there was no user of the video
> > device when booting and therefore the video driver was not
> > probed/bound. Please try do display some bitmap with bmp
> > command or try to switch to the video console by command
> > "setenv stdout vidconsole0". Then, the video device will be
> > probed and you should see the LVDS output.  
> 
> Here is what I tried:
> 
> => setenv stdout vidconsole0  
> ## Error inserting "stdout" variable, errno=22
> 
> Then I see garbage on the LVDS panel.
> 
> Any ideas as to why setting "stdout" failed?

Does "setenv stdout vidconsole" work? I think I've suggested
wrong command, sorry. "vidconsole0" is the driver instance name
for the first video console, "vidconsole" is the correct name
for console device on framebuffer.

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


Re: [U-Boot] [PATCH v2 0/4] arm: socfpga: Convert drivers from struct to defines

2019-09-17 Thread Dinh Nguyen


On 9/10/19 3:37 AM, Ley Foon Tan wrote:
> This is 2nd version of patchset to convert reset, system and clock manager
> drivers to use #define instead of struct.
> 
> Tested on Cyclone 5, Arria 10 and Stratix 10 devices.
> 
> Patch 1 is new one, patch 2 to 4 have changes.
> 
> Main changes in this version are:
> - Get base address from DT
> - Change to use writel(), readl(), setbits_le32() and clrbits_le32().
> - Add prefix to defines.
> - Add "u-boot,dm-pre-reloc" to clock and system manager nodes.
> 
> History:
> v1: https://patchwork.ozlabs.org/cover/1149731/
> 

I think you also need to Simon Goldschmidt to this series.

Beside the minor incorrect address missing a zero in patch 1, I've
tested this series on the Sockit.

Tested-by: Dinh Nguyen 

Dinh


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


Re: [U-Boot] Pull request: u-boot-spi/master

2019-09-17 Thread Tom Rini
On Mon, Sep 16, 2019 at 08:15:49AM +0530, Jagan Teki wrote:

> Hi Tom,
> 
> Please pull this for v2019.10 release.
> 
> Summary:
> - fix mvebu_a3700_spi clock prescale (Marek Behún)
> - unmark MXS_SPI, DEPRECATED (Lukasz)
> - add spi_write_then_read (Jagan)
> - fix SST26* flash ICs (Eugeniy)
> - fix soft_spi data abort (Christophe)
> 
> The following changes since commit 23b93e33adde0a8313388eda7c78d1d0786e3c92:
> 
>   Merge branch '2019-09-13-ti-imports' (2019-09-14 19:53:24 -0400)
> 
> are available in the Git repository at:
> 
>   https://gitlab.denx.de/u-boot/custodians/u-boot-spi.git master
> 
> for you to fetch changes up to ce704ea11f29b0ee8c195f17370a4048b6be29a9:
> 
>   doc: driver-model: Update SPI migration status (2019-09-16 08:09:22 +0530)
> 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH 1/2] am335x, guardian: update guardian board

2019-09-17 Thread Tom Rini
On Tue, Sep 17, 2019 at 02:25:37PM +, 
bollavarapumoses.christop...@in.bosch.com wrote:

> From: Moses Christopher 
> 
>   - add BOARD_LATE_INIT function calls in board.c
>   - add swi_status detection in board.c
>   - mux: add guardian interfaces to single pinmux structure
>   - am33xx, kconfig: add BOARD_LATE_INIT for GUARDIAN board
> 
> Signed-off-by: Moses Christopher 

Reviewed-by: Tom Rini 

-- 
Tom


signature.asc
Description: PGP signature
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH 2/2] am335x, guardian: adapt guardian board to DM

2019-09-17 Thread Tom Rini
On Tue, Sep 17, 2019 at 02:25:38PM +, 
bollavarapumoses.christop...@in.bosch.com wrote:

> From: Moses Christopher 
> 
>   - update partition table - remove env partitions
>   - dts: add new interfaces (uart2, extra gpio-key)
>  remove unneeded entries
>  update nand timings for performance improvement
>   - defconfig: adapt configurations to suit DM
>remove unneeded configs
>   - am335x_guardian.h: remove mmc boot
> 
> Signed-off-by: Moses Christopher 

Reviewed-by: Tom Rini 

-- 
Tom


signature.asc
Description: PGP signature
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] pull request u-boot-fsl-qoriq

2019-09-17 Thread Tom Rini
On Mon, Sep 16, 2019 at 05:17:11AM +, Priyanka Jain wrote:

> Dear Tom,
> 
> Please find my pull-request for u-boot-fsl-qoriq/master
> https://travis-ci.org/p-priyanka-jain/u-boot/builds/584428184
> 
> 
> Summary
> Add emmc hs200 support
> Few bug fixes related to serdes, I2C, ethernet, etc
> 
> priyankajain
> 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v2 1/2] efi_loader: variable: support APPEND_WRITE

2019-09-17 Thread AKASHI Takahiro
On Tue, Sep 17, 2019 at 10:38:47PM +0200, Heinrich Schuchardt wrote:
> On 9/6/19 8:09 AM, AKASHI Takahiro wrote:
> >If EFI_VARIABLE_APPEND_WRITE is specified in attributes at
> >efi_set_variable(), specified data will be appended to the variable's
> >original value. Attributes other than APPEND_WRITE should not be
> >modified.
> >
> >With this patch, APPEND_WRITE test in 'variables' selftest will pass.
> >
> >Signed-off-by: AKASHI Takahiro 
> >---
> >  lib/efi_loader/efi_variable.c | 70 ++-
> >  1 file changed, 44 insertions(+), 26 deletions(-)
> >
> >diff --git a/lib/efi_loader/efi_variable.c b/lib/efi_loader/efi_variable.c
> >index 6687b69a400d..48ee255f879b 100644
> >--- a/lib/efi_loader/efi_variable.c
> >+++ b/lib/efi_loader/efi_variable.c
> >@@ -424,17 +424,17 @@ efi_status_t EFIAPI efi_set_variable(u16 
> >*variable_name,
> >  efi_uintn_t data_size, const void *data)
> >  {
> > char *native_name = NULL, *val = NULL, *s;
> >+const char *old_val;
> >+size_t old_size;
> > efi_status_t ret = EFI_SUCCESS;
> > u32 attr;
> >
> > EFI_ENTRY("\"%ls\" %pUl %x %zu %p", variable_name, vendor, attributes,
> >   data_size, data);
> >
> >-/* TODO: implement APPEND_WRITE */
> > if (!variable_name || !*variable_name || !vendor ||
> > ((attributes & EFI_VARIABLE_RUNTIME_ACCESS) &&
> >- !(attributes & EFI_VARIABLE_BOOTSERVICE_ACCESS)) ||
> >-(attributes & EFI_VARIABLE_APPEND_WRITE)) {
> >+ !(attributes & EFI_VARIABLE_BOOTSERVICE_ACCESS))) {
> > ret = EFI_INVALID_PARAMETER;
> > goto out;
> > }
> >@@ -445,35 +445,51 @@ efi_status_t EFIAPI efi_set_variable(u16 
> >*variable_name,
> >
> >  #define ACCESS_ATTR (EFI_VARIABLE_RUNTIME_ACCESS | 
> > EFI_VARIABLE_BOOTSERVICE_ACCESS)
> >
> >-if ((data_size == 0) || !(attributes & ACCESS_ATTR)) {
> >-/* delete the variable: */
> >-env_set(native_name, NULL);
> >-ret = EFI_SUCCESS;
> >-goto out;
> >-}
> >+old_val = env_get(native_name);
> >+if (old_val) {
> >+old_val = parse_attr(old_val, &attr);
> >
> >-val = env_get(native_name);
> >-if (val) {
> >-parse_attr(val, &attr);
> >-
> >-/* We should not free val */
> >-val = NULL;
> >+/* check read-only first */
> > if (attr & READ_ONLY) {
> > ret = EFI_WRITE_PROTECTED;
> > goto out;
> > }
> >
> >-/*
> >- * attributes won't be changed
> >- * TODO: take care of APPEND_WRITE once supported
> >- */
> >-if (attr != attributes) {
> >+if ((data_size == 0) || !(attributes & ACCESS_ATTR)) {
> 
> The understanding of EDK2 is that no access attributes means 'attributes
> == 0' (Function VariableServiceSetVariable() in
> MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c).

No, it's not correct. The right place you should refer to is:
UpdateVariable (
   [snip up to l.2279 or so]
//
// Setting a data variable with no access, or zero DataSize attributes
// causes it to be deleted.
// When the EFI_VARIABLE_APPEND_WRITE attribute is set, DataSize of zero 
will
// not delete the variable.
//
if Attributes & EFI_VARIABLE_APPEND_WRITE) == 0) && (DataSize == 0))|| 
((Attributes & (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)) 
== 0)) {

> EFI_VARIABLE_APPEND_WRITE and data_size = 0 should not delete a variable
> according to the UEFI spec:

This is correct.

Thanks,
-Takahiro Akashi

> "Unless the EFI_VARIABLE_APPEND_WRITE,
> EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS, or
> EFI_VARIABLE_ENHANCED_AUTHENTICATED_ACCESS attribute is set (see below),
> using SetVariable() with a DataSize of zero will cause the entire
> variable to be deleted."
> 
> Best regards
> 
> Heinrich
> 
> >+/* delete the variable: */
> >+env_set(native_name, NULL);
> >+ret = EFI_SUCCESS;
> >+goto out;
> >+}
> >+
> >+/* attributes won't be changed */
> >+if (attr != (attributes & ~EFI_VARIABLE_APPEND_WRITE)) {
> > ret = EFI_INVALID_PARAMETER;
> > goto out;
> > }
> >+
> >+if (attributes & EFI_VARIABLE_APPEND_WRITE) {
> >+if (!prefix(old_val, "(blob)")) {
> >+return EFI_DEVICE_ERROR;
> >+goto out;
> >+}
> >+old_size = strlen(old_val);
> >+} else {
> >+old_size = 0;
> >+}
> >+} else {
> >+if ((data_size == 0) || !(attributes & ACCESS_ATTR) ||
> >+(attributes & EFI_VARIABLE_APPEND_WRITE)) {
> >+/* delete, but nothing 

[U-Boot] [RFC 00/15] efi_loader: add secure boot support

2019-09-17 Thread AKASHI Takahiro
One of major missing features in current UEFI implementation is "secure boot."
The ultimate goal of my attempt is to implement image authentication based
on signature and provide UEFI secure boot support which would be fully
compliant with UEFI specification, section 32[1].
(The code was originally developed by Patrick Wildt.)

While this patch/RFC is still rough-edged, the aim here is to get early
feedbacks from the community as the patch is quite huge (in total) and also
as it's a security enhancement.

Please note, however, this patch doesn't work on its own; there are
a couple of functional dependencies[2], [3] and [4], that I have submitted
before, in addition to related preparatory patches[5], [6], [7] and [8] for
pytest support. For complete workable patch set, see my repository[9],
which also contains exeperimental timestamp-based revocation suuport.

My "non-volatile" support[10], which is under reviews now, is not mandatory
and so not included here, but this inevitably implies that, for example,
signature database variables, like db and dbx, won't be persistent unless you
explicitly run "env save" command and that UEFI variables are not separated
from U-Boot environment. Anyhow, Linaro is also working on implementing
real "secure storage" solution based on TF-A and OP-TEE.


Supported features:
* image authentication based on db and dbx
* supported signature types are
EFI_CERT_SHA256_GUID (SHA256 digest for unsigned images)
EFI_CERT_X509_GUID (x509 certificate for signed images)
* SecureBoot/SignatureSupport variables
* SetupMode and user mode
* variable authentication based on PK and KEK
EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS
* pytest test cases

Unsupported features:
* hash algorithms other than SHA256
* dbt: timestamp(RFC6131)-based certificate revocation
* dbr: OS recovery 
* xxxDefault: default values for signature stores
* transition to AuditMode and DeployedMode
* recording rejected images in EFI_IMAGE_EXECUTION_INFO_TABLE
* variable authentication based on PK and KEK
EFI_VARIABLE_ENHANCED_AUTHENTICATED_ACCESS
* real secure storage, including hardware-specific PK (Platform Key)
  installation

Known issues:
* [3] and [4] have not been well reviewed yet.
* Some test case(test_efi_var_auth1:1g) still fails.
* Extensive clean-ups
* not bisect-ready (for easier code modification) for now

TODO:
* implement "unsupported" features, in particular, timestamp-based
  revocation
* fix some workarounds in the source (marked as TODO/FIXME)
* extensive test suite (or more test cases) to confirm compatibility
  with EDK2


Hints about how to use:
(Please see other documents, or my pytest scripts, for details.)
* You can create your own certificates with openssl.
* You can sign your application with pesign (on Ubuntu).
* You can create raw data for signature database with efitools, and
  install/manage authenticated variables with "env -set -e" command
  or efitools' "UpdateVars.efi" application.


[1] https://uefi.org/sites/default/files/resources/UEFI_Spec_2_8_final.pdf
[2] https://lists.denx.de/pipermail/u-boot/2019-September/382911.html
(support APPEND_WRITE)
[3] https://lists.denx.de/pipermail/u-boot/2019-September/382573.html
(import x509/pkcs7 parsers from linux)
[4] https://lists.denx.de/pipermail/u-boot/2019-September/382917.html
(extend rsa_verify() for UEFI secure boot)
[5] https://lists.denx.de/pipermail/u-boot/2019-August/382027.html
(sandbox: fix cpu property in test.dts for pytest)
[6] https://lists.denx.de/pipermail/u-boot/2019-September/382914.html
(extend "env [set|print] -e to manage UEFI variables v1)
[7] https://lists.denx.de/pipermail/u-boot/2019-September/383343.html
(install FILE_SYSTEM_PROTOCOL to a whole disk)
[8] https://lists.denx.de/pipermail/u-boot/2019-September/383348.html
(support Sandbox's "host" device)
[9] http://git.linaro.org/people/takahiro.akashi/u-boot.git/ efi/secboot
[10] https://lists.denx.de/pipermail/u-boot/2019-September/382835.html
(non-volatile variables support)


AKASHI Takahiro (15):
  lib: charset: add u16_strcmp()
  test: add tests for u16_strcmp()
  include: pe.h: add image-signing-related definitions
  include: image.h: add key info to image_sign_info
  include: image.h: export hash algorithm helper functions
  secure boot: rename CONFIG_SECURE_BOOT
  efi_loader: add signature verification functions
  efi_loader: variable: support variable authentication
  efi_loader: variable: add VendorKeys and SignatureSupport variables
  efi_loader: image_loader: support image authentication
  efi_loader: initialize secure boot state
  efi_loader: add CONFIG_EFI_SECURE_BOOT
  cmd: env: provide appropriate guid for well-defined variable
  efi_loader, pytest: add UEFI secure boot tests (image)
  efi_loader, pytest: add UEFI secure boot tests (authenticated
variables)

 Kconfig   |   7 +
 arch/arm/cpu/armv7/ls102xa/Kconfig|   3 +-
 arch/arm/cpu/armv8/fsl-

[U-Boot] [RFC 01/15] lib: charset: add u16_strcmp()

2019-09-17 Thread AKASHI Takahiro
u16 version of strcmp(): u16_strncmp() works like u16_strcmp() but only
at most n characters (in u16) are compared.
This function will be used in my UEFI secure boot patch.

Signed-off-by: AKASHI Takahiro 
---
 include/charset.h | 15 +++
 lib/charset.c | 25 +
 2 files changed, 40 insertions(+)

diff --git a/include/charset.h b/include/charset.h
index 020f8a90df07..fde6bddbc2fb 100644
--- a/include/charset.h
+++ b/include/charset.h
@@ -168,6 +168,21 @@ s32 utf_to_lower(const s32 code);
  */
 s32 utf_to_upper(const s32 code);
 
+/*
+ * u16_strncmp() - compare two u16 string
+ *
+ * @s1:first string to compare
+ * @s2:second string to compare
+ * @n: maximum number of u16 to compare
+ * Return: 0  if the first n u16 are the same in s1 and s2
+ * < 0 if the first different u16 in s1 is less than the
+ * corresponding u16 in s2
+ * > 0 if the first different u16 in s1 is greater than the
+ * corresponding u16 in s2
+ */
+int u16_strncmp(const u16 *s1, const u16 *s2, size_t n);
+#define u16_strcmp(s1, s2) u16_strncmp((s1), (s2), SIZE_MAX)
+
 /**
  * u16_strlen - count non-zero words
  *
diff --git a/lib/charset.c b/lib/charset.c
index 72d745da4f4e..1c6a7f693de4 100644
--- a/lib/charset.c
+++ b/lib/charset.c
@@ -335,6 +335,31 @@ s32 utf_to_upper(const s32 code)
return ret;
 }
 
+/*
+ * u16_strncmp() - compare two u16 string
+ *
+ * @s1:first string to compare
+ * @s2:second string to compare
+ * @n: maximum number of u16 to compare
+ * Return: 0  if the first n u16 are the same in s1 and s2
+ * < 0 if the first different u16 in s1 is less than the
+ * corresponding u16 in s2
+ * > 0 if the first different u16 in s1 is greater than the
+ * corresponding u16 in s2
+ */
+int u16_strncmp(const u16 *s1, const u16 *s2, size_t n)
+{
+   int ret = 0;
+
+   for (; n; --n, ++s1, ++s2) {
+   ret = *s1 - *s2;
+   if (ret || !*s1)
+   break;
+   }
+
+   return ret;
+}
+
 size_t u16_strlen(const void *in)
 {
const char *pos = in;
-- 
2.21.0

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


[U-Boot] [RFC 02/15] test: add tests for u16_strcmp()

2019-09-17 Thread AKASHI Takahiro
New seven test cases for u16_strcmp() are added under Unicode unit test,
which should be executed by "ut unicode" command.

Signed-off-by: AKASHI Takahiro 
---
 test/unicode_ut.c | 13 +
 1 file changed, 13 insertions(+)

diff --git a/test/unicode_ut.c b/test/unicode_ut.c
index 1ccd36e7c9e8..8875cdc6b2f5 100644
--- a/test/unicode_ut.c
+++ b/test/unicode_ut.c
@@ -567,6 +567,19 @@ static int unicode_test_utf_to_upper(struct 
unit_test_state *uts)
 }
 UNICODE_TEST(unicode_test_utf_to_upper);
 
+static int unicode_test_u16_strncmp(struct unit_test_state *uts)
+{
+   ut_assert(u16_strncmp(L"abc", L"abc", 3) == 0);
+   ut_assert(u16_strncmp(L"abcdef", L"abcghi", 3) == 0);
+   ut_assert(u16_strncmp(L"abcdef", L"abcghi", 6) < 0);
+   ut_assert(u16_strncmp(L"abcghi", L"abcdef", 6) > 0);
+   ut_assert(u16_strcmp(L"abc", L"abc") == 0);
+   ut_assert(u16_strcmp(L"abcdef", L"deghi") < 0);
+   ut_assert(u16_strcmp(L"deghi", L"abcdef") > 0);
+   return 0;
+}
+UNICODE_TEST(unicode_test_u16_strncmp);
+
 int do_ut_unicode(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
struct unit_test *tests = ll_entry_start(struct unit_test, 
unicode_test);
-- 
2.21.0

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


[U-Boot] [RFC 04/15] include: image.h: add key info to image_sign_info

2019-09-17 Thread AKASHI Takahiro
For FIT verification, all the properties of a public key come from
"control fdt" pointed to by fdt_blob. In UEFI secure boot, on the other
hand, a public key is located and retrieved from dedicated signature
database stored as UEFI variables.

Added two fields may hold values of a public key if fdt_blob is NULL, and
will be used in rsa_verify_with_pkey() to verify a signature in UEFI
sub-system.

Signed-off-by: AKASHI Takahiro 
---
 include/image.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/image.h b/include/image.h
index 97b6a82d9754..685f5181c829 100644
--- a/include/image.h
+++ b/include/image.h
@@ -1136,6 +1136,8 @@ struct image_sign_info {
struct checksum_algo *checksum; /* Checksum algorithm information */
struct padding_algo *padding;   /* Padding algorithm information */
struct crypto_algo *crypto; /* Crypto algorithm information */
+   const void *key;
+   int keylen;
const void *fdt_blob;   /* FDT containing public keys */
int required_keynode;   /* Node offset of key to use: -1=any */
const char *require_keys;   /* Value for 'required' property */
-- 
2.21.0

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


[U-Boot] [RFC 03/15] include: pe.h: add image-signing-related definitions

2019-09-17 Thread AKASHI Takahiro
The index (IMAGE_DIRECTORY_ENTRY_CERTTABLE) in a table points to
a region containing authentication information (image's signature)
in PE format.

WIN_CERTIFICATE structure defines an embedded signature format.

Those definitions will be used in my UEFI secure boot patch.

Signed-off-by: AKASHI Takahiro 
---
 include/pe.h | 16 
 1 file changed, 16 insertions(+)

diff --git a/include/pe.h b/include/pe.h
index bff3b0aa7a6c..650478ca78af 100644
--- a/include/pe.h
+++ b/include/pe.h
@@ -155,6 +155,7 @@ typedef struct _IMAGE_SECTION_HEADER {
uint32_t Characteristics;
 } IMAGE_SECTION_HEADER, *PIMAGE_SECTION_HEADER;
 
+#define IMAGE_DIRECTORY_ENTRY_CERTTABLE 4
 #define IMAGE_DIRECTORY_ENTRY_BASERELOC 5
 
 typedef struct _IMAGE_BASE_RELOCATION
@@ -252,4 +253,19 @@ typedef struct _IMAGE_RELOCATION
 #define IMAGE_REL_AMD64_PAIR0x000F
 #define IMAGE_REL_AMD64_SSPAN32 0x0010
 
+/* certificate appended to PE image */
+typedef struct _WIN_CERTIFICATE {
+   uint32_t dwLength;
+   uint16_t wRevision;
+   uint16_t wCertificateType;
+   uint8_t bCertificate[];
+} WIN_CERTIFICATE, *LPWIN_CERTIFICATE;
+
+#define WIN_CERT_TYPE_PKCS_SIGNED_DATA 0x0002
+#define WIN_CERT_TYPE_EFI_OKCS115  0x0EF0
+#define WIN_CERT_TYPE_EFI_GUID 0x0EF1
+
+#define WIN_CERT_REVISION_1_0  0x0100
+#define WIN_CERT_REVISION_2_0  0x0200
+
 #endif /* _PE_H */
-- 
2.21.0

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


[U-Boot] [RFC 08/15] efi_loader: variable: support variable authentication

2019-09-17 Thread AKASHI Takahiro
With this commit, EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS
is supported for authenticated variables and the system secure state
will transfer between setup mode and user mode as UEFI specification
section 32.3 describes.

Internally, authentication data is stored as part of authenticated
variable's value. It is nothing but a pkcs7 message (but we need some
wrapper, see efi_variable_parse_signature()) and will be validated by
efi_variable_authenticate(), hence efi_signature_verify_with_db().

Associated time value will be encoded in "{...,time=...}" along with
other UEFI variable's attributes.

Signed-off-by: AKASHI Takahiro 
---
 include/efi_loader.h  |   4 +
 lib/efi_loader/efi_variable.c | 855 ++
 2 files changed, 757 insertions(+), 102 deletions(-)

diff --git a/include/efi_loader.h b/include/efi_loader.h
index c75ee5fcb6ba..caac8efba89a 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -162,6 +162,7 @@ extern const efi_guid_t efi_guid_image_security_database;
 extern const efi_guid_t efi_guid_sha256;
 extern const efi_guid_t efi_guid_cert_x509;
 extern const efi_guid_t efi_guid_cert_x509_sha256;
+extern const efi_guid_t efi_guid_cert_type_pkcs7;
 
 extern unsigned int __efi_runtime_start, __efi_runtime_stop;
 extern unsigned int __efi_runtime_rel_start, __efi_runtime_rel_stop;
@@ -699,6 +700,9 @@ efi_status_t efi_image_region_add(efi_image_regions *ctx,
 
 void efi_sigstore_free(efi_signature_store *ctx);
 efi_signature_store *efi_sigstore_parse_sigdb(u16 *name);
+
+bool efi_secure_boot_enabled(void);
+efi_status_t efi_init_secure_boot(void);
 #endif /* CONFIG_EFI_SECURE_BOOT */
 
 #else /* CONFIG_IS_ENABLED(EFI_LOADER) */
diff --git a/lib/efi_loader/efi_variable.c b/lib/efi_loader/efi_variable.c
index 5d1ee50a606e..fa706f1ad6b8 100644
--- a/lib/efi_loader/efi_variable.c
+++ b/lib/efi_loader/efi_variable.c
@@ -11,8 +11,25 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
+#include 
+/*
+ * avoid duplicated inclusion:
+ * #include "../lib/crypto/x509_parser.h"
+ */
+#include "../lib/crypto/pkcs7_parser.h"
+
+enum efi_secure_mode {
+   EFI_MODE_SETUP,
+   EFI_MODE_USER,
+   EFI_MODE_AUDIT,
+   EFI_MODE_DEPLOYED,
+};
+
+const efi_guid_t efi_guid_cert_type_pkcs7 = EFI_CERT_TYPE_PKCS7_GUID;
+static bool efi_secure_boot;
 
 #define READ_ONLY BIT(31)
 
@@ -109,7 +126,7 @@ static const char *prefix(const char *str, const char 
*prefix)
  * @attrp: pointer to UEFI attributes
  * Return: pointer to remainder of U-Boot variable value
  */
-static const char *parse_attr(const char *str, u32 *attrp)
+static const char *parse_attr(const char *str, u32 *attrp, u64 *timep)
 {
u32 attr = 0;
char sep = '{';
@@ -132,6 +149,12 @@ static const char *parse_attr(const char *str, u32 *attrp)
attr |= EFI_VARIABLE_BOOTSERVICE_ACCESS;
} else if ((s = prefix(str, "run"))) {
attr |= EFI_VARIABLE_RUNTIME_ACCESS;
+   } else if ((s = prefix(str, "time="))) {
+   attr |= 
EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS;
+   hex2bin((u8 *)timep, s, sizeof(*timep));
+   s += sizeof(*timep) * 2;
+   } else if (*str == '}') {
+   break;
} else {
printf("invalid attribute: %s\n", str);
break;
@@ -148,49 +171,454 @@ static const char *parse_attr(const char *str, u32 
*attrp)
return str;
 }
 
-/**
- * efi_get_variable() - retrieve value of a UEFI variable
- *
- * This function implements the GetVariable runtime service.
- *
- * See the Unified Extensible Firmware Interface (UEFI) specification for
- * details.
- *
- * @variable_name: name of the variable
- * @vendor:vendor GUID
- * @attributes:attributes of the variable
- * @data_size: size of the buffer to which the variable value is copied
- * @data:  buffer to which the variable value is copied
- * Return: status code
+static efi_status_t efi_set_variable_internal(u16 *variable_name,
+ const efi_guid_t *vendor,
+ u32 attributes,
+ efi_uintn_t data_size,
+ const void *data,
+ bool ro_check);
+
+static efi_status_t efi_transfer_secure_state(enum efi_secure_mode mode)
+{
+   u32 attributes;
+   u8 val;
+   efi_status_t ret;
+
+   debug("Secure state from %d to %d\n", efi_secure_mode, mode);
+
+   attributes = EFI_VARIABLE_BOOTSERVICE_ACCESS |
+EFI_VARIABLE_RUNTIME_ACCESS;
+   if (mode == EFI_MODE_DEPLOYED) {
+   val = 1;
+   ret = efi_set_variable_internal(L"SecureBoot",
+   

[U-Boot] [RFC 09/15] efi_loader: variable: add VendorKeys and SignatureSupport variables

2019-09-17 Thread AKASHI Takahiro
Those two variables are well defined UEFI variables:
SignatureSupport: array of GUIDs representing the type of signatures
  supported by the platform firmware
VendorKeys: whether the system is configured to use only vendor-provided
keys or not

Signed-off-by: AKASHI Takahiro 
---
 lib/efi_loader/efi_variable.c | 85 ---
 1 file changed, 79 insertions(+), 6 deletions(-)

diff --git a/lib/efi_loader/efi_variable.c b/lib/efi_loader/efi_variable.c
index fa706f1ad6b8..9b7654bde017 100644
--- a/lib/efi_loader/efi_variable.c
+++ b/lib/efi_loader/efi_variable.c
@@ -28,8 +28,14 @@ enum efi_secure_mode {
EFI_MODE_DEPLOYED,
 };
 
+static const efi_guid_t signature_types[] = {
+   /* EFI_CERT_SHA256_GUID, */
+   EFI_CERT_X509_GUID,
+};
 const efi_guid_t efi_guid_cert_type_pkcs7 = EFI_CERT_TYPE_PKCS7_GUID;
 static bool efi_secure_boot;
+static int efi_secure_mode;
+static u8 efi_vendor_keys;
 
 #define READ_ONLY BIT(31)
 
@@ -337,6 +343,8 @@ static efi_status_t efi_transfer_secure_state(enum 
efi_secure_mode mode)
return EFI_INVALID_PARAMETER;
}
 
+   efi_secure_mode = mode;
+
return EFI_SUCCESS;
 
 err:
@@ -347,16 +355,57 @@ err:
 
 efi_status_t efi_init_secure_boot(void)
 {
-   efi_uintn_t size = 0;
+   enum efi_secure_mode mode;
+   efi_uintn_t size;
efi_status_t ret;
 
+   ret = efi_set_variable_internal(L"SignatureSupport",
+   &efi_global_variable_guid,
+   EFI_VARIABLE_BOOTSERVICE_ACCESS
+| EFI_VARIABLE_RUNTIME_ACCESS
+| READ_ONLY,
+   sizeof(signature_types),
+   &signature_types,
+   false);
+   if (ret != EFI_SUCCESS)
+   goto err;
+
+   /*
+* TODO:
+* Since there is currently no "platform-specific" installation
+* method of Platform Key, we can't say if VendorKeys is 0 or 1
+* precisely.
+*/
+
+   size = 0;
ret = EFI_CALL(efi_get_variable(L"PK", &efi_global_variable_guid,
NULL, &size, NULL));
-   if (ret == EFI_BUFFER_TOO_SMALL && IS_ENABLED(CONFIG_EFI_SECURE_BOOT))
-   ret = efi_transfer_secure_state(EFI_MODE_USER);
-   else
-   ret = efi_transfer_secure_state(EFI_MODE_SETUP);
+   if (ret == EFI_BUFFER_TOO_SMALL) {
+   if (IS_ENABLED(CONFIG_EFI_SECURE_BOOT))
+   mode = EFI_MODE_USER;
+   else
+   mode = EFI_MODE_SETUP;
+
+   efi_vendor_keys = 0;
+   } else if (ret == EFI_NOT_FOUND) {
+   mode = EFI_MODE_SETUP;
+   efi_vendor_keys = 1;
+   } else {
+   goto err;
+   }
 
+   ret = efi_transfer_secure_state(mode);
+   if (ret == EFI_SUCCESS)
+   ret = efi_set_variable_internal(L"VendorKeys",
+   &efi_global_variable_guid,
+   EFI_VARIABLE_BOOTSERVICE_ACCESS
+| EFI_VARIABLE_RUNTIME_ACCESS
+| READ_ONLY,
+   sizeof(efi_vendor_keys),
+   &efi_vendor_keys,
+   false);
+
+err:
return ret;
 }
 
@@ -1086,6 +1135,8 @@ out:
if (env_set(native_name, val)) {
ret = EFI_DEVICE_ERROR;
} else {
+   bool vendor_keys_modified = false;
+
if ((u16_strcmp(variable_name, L"PK") == 0 &&
 guidcmp(vendor, &efi_global_variable_guid) == 0)) {
ret = efi_transfer_secure_state(
@@ -1093,8 +1144,30 @@ out:
  EFI_MODE_USER));
if (ret != EFI_SUCCESS)
goto err;
+
+   if (efi_secure_mode != EFI_MODE_SETUP)
+   vendor_keys_modified = true;
+   } else if ((u16_strcmp(variable_name, L"KEK") == 0 &&
+guidcmp(vendor, &efi_global_variable_guid) == 0)) {
+   if (efi_secure_mode != EFI_MODE_SETUP)
+   vendor_keys_modified = true;
+   }
+
+   /* update VendorKeys */
+   if (vendor_keys_modified & efi_vendor_keys) {
+   efi_vendor_keys = 0;
+   ret = efi_set_variable_internal(
+   L"VendorKeys",
+   &efi_global_variable_guid,
+  

[U-Boot] [RFC 05/15] include: image.h: export hash algorithm helper functions

2019-09-17 Thread AKASHI Takahiro
This commit allows us to use common/image-sig.c even if CONFIG_FIT
is disabled but CONFIG_EFI_LOADER is enabled.

Signed-off-by: AKASHI Takahiro 
---
 include/image.h | 15 +--
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/include/image.h b/include/image.h
index 685f5181c829..c9fe1d8eaed8 100644
--- a/include/image.h
+++ b/include/image.h
@@ -53,7 +53,7 @@ struct fdt_region;
 
 #endif /* USE_HOSTCC */
 
-#if IMAGE_ENABLE_FIT
+#if IMAGE_ENABLE_FIT || defined(CONFIG_EFI_SECURE_BOOT)
 #include 
 #include 
 #include 
@@ -86,13 +86,14 @@ struct fdt_region;
 #endif
 
 #if defined(CONFIG_FIT_ENABLE_SHA256_SUPPORT) || \
-   defined(CONFIG_SPL_SHA256_SUPPORT)
+   defined(CONFIG_SPL_SHA256_SUPPORT) || \
+   defined(CONFIG_EFI_SECURE_BOOT)
 #define IMAGE_ENABLE_SHA2561
 #else
 #define IMAGE_ENABLE_SHA2560
 #endif
 
-#endif /* IMAGE_ENABLE_FIT */
+#endif /* IMAGE_ENABLE_FIT || defined(CONFIG_EFI_SECURE_BOOT) */
 
 #ifdef CONFIG_SYS_BOOT_GET_CMDLINE
 # define IMAGE_BOOT_GET_CMDLINE1
@@ -1085,6 +1086,7 @@ int fit_conf_get_prop_node(const void *fit, int noffset,
 
 int fit_check_ramdisk(const void *fit, int os_noffset,
uint8_t arch, int verify);
+#endif /* IMAGE_ENABLE_FIT */
 
 int calculate_hash(const void *data, int data_len, const char *algo,
uint8_t *value, int *value_len);
@@ -1143,7 +1145,6 @@ struct image_sign_info {
const char *require_keys;   /* Value for 'required' property */
const char *engine_id;  /* Engine to use for signing */
 };
-#endif /* Allow struct image_region to always be defined for rsa.h */
 
 /* A part of an image, used for hashing */
 struct image_region {
@@ -1151,7 +1152,7 @@ struct image_region {
int size;
 };
 
-#if IMAGE_ENABLE_FIT
+#if IMAGE_ENABLE_FIT || defined(CONFIG_EFI_SECURE_BOOT)
 
 #if IMAGE_ENABLE_VERIFY
 # include 
@@ -1252,7 +1253,9 @@ struct crypto_algo *image_get_crypto_algo(const char 
*full_name);
  * @return pointer to algorithm information, or NULL if not found
  */
 struct padding_algo *image_get_padding_algo(const char *name);
+#endif /* IMAGE_ENABLE_FIT || defined(CONFIG_EFI_SECURE_BOOT) */
 
+#if IMAGE_ENABLE_FIT
 /**
  * fit_image_verify_required_sigs() - Verify signatures marked as 'required'
  *
@@ -1328,7 +1331,7 @@ static inline int fit_image_check_target_arch(const void 
*fdt, int node)
 #define fit_unsupported(msg)
 #define fit_unsupported_reset(msg)
 #endif /* CONFIG_FIT_VERBOSE */
-#endif /* CONFIG_FIT */
+#endif /* IMAGE_ENABLE_FIT */
 
 #if defined(CONFIG_ANDROID_BOOT_IMAGE)
 struct andr_img_hdr;
-- 
2.21.0

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


[U-Boot] [RFC 10/15] efi_loader: image_loader: support image authentication

2019-09-17 Thread AKASHI Takahiro
With this commit, image validation can be enforced, as UEFI specification
section 32.5 describes, if CONFIG_EFI_SECURE_BOOT is enabled.

Currently we support
* authentication based on db and dbx,
  so dbx-validated image will always be rejected.
* following signature types:
EFI_CERT_SHA256_GUID (SHA256 digest for unsigned images)
EFI_CERT_X509_GUID (x509 certificate for signed images)
Timestamp-based certifcate revocation is not supported here.

Internally, authentication data is stored in one of certificates tables
of PE image (See efi_image_parse()) and will be verified by
efi_image_authenticate(), hence efi_signature_verify_with_db(), before
loading a given image.

Signed-off-by: AKASHI Takahiro 
---
 include/efi_loader.h  |   7 +-
 lib/efi_loader/efi_boottime.c |   2 +-
 lib/efi_loader/efi_image_loader.c | 364 +-
 3 files changed, 366 insertions(+), 7 deletions(-)

diff --git a/include/efi_loader.h b/include/efi_loader.h
index caac8efba89a..b0e1a3b7902d 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -11,6 +11,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /* No need for efi loader support in SPL */
 #if CONFIG_IS_ENABLED(EFI_LOADER)
@@ -385,7 +386,8 @@ efi_status_t efi_set_watchdog(unsigned long timeout);
 /* Called from places to check whether a timer expired */
 void efi_timer_check(void);
 /* PE loader implementation */
-efi_status_t efi_load_pe(struct efi_loaded_image_obj *handle, void *efi,
+efi_status_t efi_load_pe(struct efi_loaded_image_obj *handle,
+void *efi, size_t efi_size,
 struct efi_loaded_image *loaded_image_info);
 /* Called once to store the pristine gd pointer */
 void efi_save_gd(void);
@@ -703,6 +705,9 @@ efi_signature_store *efi_sigstore_parse_sigdb(u16 *name);
 
 bool efi_secure_boot_enabled(void);
 efi_status_t efi_init_secure_boot(void);
+
+bool efi_image_parse(void *efi, size_t len, efi_image_regions **regp,
+WIN_CERTIFICATE **auth, size_t *auth_len);
 #endif /* CONFIG_EFI_SECURE_BOOT */
 
 #else /* CONFIG_IS_ENABLED(EFI_LOADER) */
diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c
index b9bff894cbba..e27a52493291 100644
--- a/lib/efi_loader/efi_boottime.c
+++ b/lib/efi_loader/efi_boottime.c
@@ -1879,7 +1879,7 @@ efi_status_t EFIAPI efi_load_image(bool boot_policy,
efi_dp_split_file_path(file_path, &dp, &fp);
ret = efi_setup_loaded_image(dp, fp, image_obj, &info);
if (ret == EFI_SUCCESS)
-   ret = efi_load_pe(*image_obj, dest_buffer, info);
+   ret = efi_load_pe(*image_obj, dest_buffer, source_size, info);
if (!source_buffer)
/* Release buffer to which file was loaded */
efi_free_pages((uintptr_t)dest_buffer,
diff --git a/lib/efi_loader/efi_image_loader.c 
b/lib/efi_loader/efi_image_loader.c
index 13541cfa7a28..3004cb34a3cd 100644
--- a/lib/efi_loader/efi_image_loader.c
+++ b/lib/efi_loader/efi_image_loader.c
@@ -9,7 +9,13 @@
 
 #include 
 #include 
+#include 
 #include 
+/*
+ * avoid duplicated inclusion:
+ * #include "../lib/crypto/x509_parser.h"
+ */
+#include "../lib/crypto/pkcs7_parser.h"
 
 const efi_guid_t efi_global_variable_guid = EFI_GLOBAL_VARIABLE_GUID;
 const efi_guid_t efi_guid_device_path = EFI_DEVICE_PATH_PROTOCOL_GUID;
@@ -205,6 +211,288 @@ static void efi_set_code_and_data_type(
}
 }
 
+#ifdef CONFIG_EFI_SECURE_BOOT
+/*
+ * Parse image binary in PE32(+) format
+ *   Assuming that sanity of PE image has been checked by a caller.
+ *
+ * Return: true on success, false on failure
+ */
+bool efi_image_parse(void *efi, size_t len, efi_image_regions **regp,
+WIN_CERTIFICATE **auth, size_t *auth_len)
+{
+   efi_image_regions *regs;
+   IMAGE_DOS_HEADER *dos;
+   IMAGE_NT_HEADERS32 *nt;
+   IMAGE_SECTION_HEADER *sections;
+   int num_sections, i;
+   int ctidx = IMAGE_DIRECTORY_ENTRY_CERTTABLE;
+   u32 align, size, authsz, authoff;
+   size_t bytes_hashed;
+
+   regs = calloc(1, sizeof(*regs));
+   if (!regs)
+   goto err;
+
+   dos = (void *)efi;
+   nt = (void *)(efi + dos->e_lfanew);
+
+   /*
+* Collect data regions for hash calculation
+* 1. File headers
+*/
+   if (nt->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC) {
+   IMAGE_NT_HEADERS64 *nt64 = (void *)nt;
+   IMAGE_OPTIONAL_HEADER64 *opt = &nt64->OptionalHeader;
+
+   /* Skip CheckSum */
+   efi_image_region_add(regs, efi, &opt->CheckSum, 0);
+   if (nt64->OptionalHeader.NumberOfRvaAndSizes <= ctidx) {
+   efi_image_region_add(regs,
+&opt->CheckSum + 1,
+efi + opt->SizeOfHeaders, 0);
+   } else {
+   /* Skip Certificates Table */
+  

[U-Boot] [RFC 11/15] efi_loader: initialize secure boot state

2019-09-17 Thread AKASHI Takahiro
We call efi_init_secure_boot() after loading saved UEFI variables so that
the initial secure boot status will be initialized.

Signed-off-by: AKASHI Takahiro 
---
 lib/efi_loader/efi_setup.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c
index 0d915ba386da..de8f0bd7e68e 100644
--- a/lib/efi_loader/efi_setup.c
+++ b/lib/efi_loader/efi_setup.c
@@ -132,6 +132,11 @@ efi_status_t efi_init_obj_list(void)
if (ret != EFI_SUCCESS)
goto out;
 
+   /* Secure boot */
+   ret = efi_init_secure_boot();
+   if (ret != EFI_SUCCESS)
+   goto out;
+
/* Indicate supported runtime services */
ret = efi_init_runtime_supported();
if (ret != EFI_SUCCESS)
-- 
2.21.0

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


[U-Boot] [RFC 06/15] secure boot: rename CONFIG_SECURE_BOOT

2019-09-17 Thread AKASHI Takahiro
The configuration, CONFIG_SECURE_BOOT, was scattered among different
architecture directories for different implementation. This will prevent
UEFI secure boot from being added later.

So let's rename them, giving each implementation to different
configuration option. CONFIG_SECURE_BOOT still remains not to break
existing implicit dependency.

Signed-off-by: AKASHI Takahiro 
---
 Kconfig   | 7 +++
 arch/arm/cpu/armv7/ls102xa/Kconfig| 3 ++-
 arch/arm/cpu/armv8/fsl-layerscape/Kconfig | 3 ++-
 arch/arm/mach-imx/Kconfig | 3 ++-
 arch/powerpc/cpu/mpc85xx/Kconfig  | 3 ++-
 5 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/Kconfig b/Kconfig
index 1f0904f7045e..c11fc102a7d4 100644
--- a/Kconfig
+++ b/Kconfig
@@ -282,6 +282,13 @@ config SYS_LDSCRIPT
 
 endmenu# General setup
 
+config SECURE_BOOT
+   bool "Secure Boot"
+   imply SHA256
+   help
+ Enable Secure Boot feature. The actual behavior may vary
+ from architecture to architecture.
+
 menu "Boot images"
 
 config ANDROID_BOOT_IMAGE
diff --git a/arch/arm/cpu/armv7/ls102xa/Kconfig 
b/arch/arm/cpu/armv7/ls102xa/Kconfig
index 94fa68250ddf..ce1bc580d23d 100644
--- a/arch/arm/cpu/armv7/ls102xa/Kconfig
+++ b/arch/arm/cpu/armv7/ls102xa/Kconfig
@@ -50,8 +50,9 @@ config MAX_CPUS
  cores, count the reserved ports. This will allocate enough memory
  in spin table to properly handle all cores.
 
-config SECURE_BOOT
+config FSL_ARMV7_ENABLE_SECURE_BOOT
bool"Secure Boot"
+   depends on SECURE_BOOT
help
Enable Freescale Secure Boot feature. Normally selected
by defconfig. If unsure, do not change.
diff --git a/arch/arm/cpu/armv8/fsl-layerscape/Kconfig 
b/arch/arm/cpu/armv8/fsl-layerscape/Kconfig
index 42d31fdab0a0..d4cfe31f8ebf 100644
--- a/arch/arm/cpu/armv8/fsl-layerscape/Kconfig
+++ b/arch/arm/cpu/armv8/fsl-layerscape/Kconfig
@@ -383,8 +383,9 @@ config EMC2305
 Enable the EMC2305 fan controller for configuration of fan
 speed.
 
-config SECURE_BOOT
+config FSI_ARMV8_ENABLE_SECURE_BOOT
bool "Secure Boot"
+   depends on SECURE_BOOT
help
Enable Freescale Secure Boot feature
 
diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig
index aeb54934888d..e1602fd5f0e8 100644
--- a/arch/arm/mach-imx/Kconfig
+++ b/arch/arm/mach-imx/Kconfig
@@ -34,8 +34,9 @@ config USE_IMXIMG_PLUGIN
  i.MX6/7 supports DCD and Plugin. Enable this configuration
  to use Plugin, otherwise DCD will be used.
 
-config SECURE_BOOT
+config FSL_IMX_ENABLE_SECURE_BOOT
bool "Support i.MX HAB features"
+   depends on SECURE_BOOT
depends on ARCH_MX7 || ARCH_MX6 || ARCH_MX5
select FSL_CAAM if HAS_CAAM
imply CMD_DEKBLOB
diff --git a/arch/powerpc/cpu/mpc85xx/Kconfig b/arch/powerpc/cpu/mpc85xx/Kconfig
index c038a6ddb0f4..9cf6ebbfe3ce 100644
--- a/arch/powerpc/cpu/mpc85xx/Kconfig
+++ b/arch/powerpc/cpu/mpc85xx/Kconfig
@@ -1208,8 +1208,9 @@ config FSL_LAW
help
Use Freescale common code for Local Access Window
 
-config SECURE_BOOT
+config FSL_MPC_ENABLE_SECURE_BOOT
bool"Secure Boot"
+   depends on SECURE_BOOT
help
Enable Freescale Secure Boot feature. Normally selected
by defconfig. If unsure, do not change.
-- 
2.21.0

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


[U-Boot] [RFC 07/15] efi_loader: add signature verification functions

2019-09-17 Thread AKASHI Takahiro
In this commit, implemented are efi_signature_verify_with_db(),
efi_signature_parse_sigdb() and a couple of helper functions which will be
used for variable authentication as well as image authentication in UEFI
secure boot.

efi_signature_verify_with_db() - authenticate an image with its hash value
for unsigned image, and with its embedded pkcs7 signature with a given
signature store if signed. This function will also be used to validate
authentication data in authenticated variables.

efi_signature_parse_sigdb() - parse signature database variable and
retrieve signature lists, which may consist of x509 certificates or message
digests (SHA256 only for now).

Signed-off-by: AKASHI Takahiro 
---
 include/efi_api.h  |  47 +++
 include/efi_loader.h   |  47 +++
 lib/efi_loader/Makefile|   1 +
 lib/efi_loader/efi_signature.c | 602 +
 4 files changed, 697 insertions(+)
 create mode 100644 lib/efi_loader/efi_signature.c

diff --git a/include/efi_api.h b/include/efi_api.h
index 9f49a4575e07..72999f762515 100644
--- a/include/efi_api.h
+++ b/include/efi_api.h
@@ -18,6 +18,7 @@
 
 #include 
 #include 
+#include 
 
 #ifdef CONFIG_EFI_LOADER
 #include 
@@ -307,6 +308,10 @@ struct efi_runtime_services {
EFI_GUID(0x8be4df61, 0x93ca, 0x11d2, 0xaa, 0x0d, \
 0x00, 0xe0, 0x98, 0x03, 0x2b, 0x8c)
 
+#define EFI_IMAGE_SECURITY_DATABASE_GUID \
+   EFI_GUID(0xd719b2cb, 0x3d3a, 0x4596, 0xa3, 0xbc, \
+0xda, 0xd0, 0x0e, 0x67, 0x65, 0x6f)
+
 #define EFI_FDT_GUID \
EFI_GUID(0xb1b621d5, 0xf19c, 0x41a5, \
 0x83, 0x0b, 0xd9, 0x15, 0x2c, 0x69, 0xaa, 0xe0)
@@ -1597,4 +1602,46 @@ struct efi_unicode_collation_protocol {
 #define LOAD_OPTION_CATEGORY_BOOT  0x
 #define LOAD_OPTION_CATEGORY_APP   0x0100
 
+/* Secure boot */
+#define EFI_CERT_SHA256_GUID \
+   EFI_GUID(0xc1c41626, 0x504c, 0x4092, 0xac, 0xa9, \
+0x41, 0xf9, 0x36, 0x93, 0x43, 0x28)
+#define EFI_CERT_RSA2048_GUID \
+   EFI_GUID(0x3c5766e8, 0x269c, 0x4e34, 0xaa, 0x14, \
+0xed, 0x77, 0x6e, 0x85, 0xb3, 0xb6)
+#define EFI_CERT_X509_GUID \
+   EFI_GUID(0xa5c059a1, 0x94e4, 0x4aa7, 0x87, 0xb5, \
+0xab, 0x15, 0x5c, 0x2b, 0xf0, 0x72)
+#define EFI_CERT_X509_SHA256_GUID \
+   EFI_GUID(0x3bd2a492, 0x96c0, 0x4079, 0xb4, 0x20, \
+0xfc, 0xf9, 0x8e, 0xf1, 0x03, 0xed)
+#define EFI_CERT_TYPE_PKCS7_GUID \
+   EFI_GUID(0x4aafd29d, 0x68df, 0x49ee, 0x8a, 0xa9, \
+0x34, 0x7d, 0x37, 0x56, 0x65, 0xa7)
+
+struct win_certificate_uefi_guid {
+   WIN_CERTIFICATE hdr;
+   efi_guid_t  cert_type;
+   u8  cert_data[];
+} __attribute__((__packed__));
+
+struct efi_variable_authentication_2 {
+   struct efi_time  time_stamp;
+   struct win_certificate_uefi_guid auth_info;
+} __attribute__((__packed__));
+
+struct efi_signature_data {
+   efi_guid_t  signature_owner;
+   u8  signature_data[];
+} __attribute__((__packed__));
+
+struct efi_signature_list {
+   efi_guid_t  signature_type;
+   u32 signature_list_size;
+   u32 signature_header_size;
+   u32 signature_size;
+/* u8  signature_header[signature_header_size]; */
+/* struct efi_signature_data signatures[...][signature_size]; */
+} __attribute__((__packed__));
+
 #endif
diff --git a/include/efi_loader.h b/include/efi_loader.h
index 5298ea7997f7..c75ee5fcb6ba 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -16,6 +16,7 @@
 #if CONFIG_IS_ENABLED(EFI_LOADER)
 
 #include 
+#include 
 
 /* Maximum number of configuration tables */
 #define EFI_MAX_CONFIGURATION_TABLES 16
@@ -156,6 +157,11 @@ extern const efi_guid_t 
efi_guid_hii_config_routing_protocol;
 extern const efi_guid_t efi_guid_hii_config_access_protocol;
 extern const efi_guid_t efi_guid_hii_database_protocol;
 extern const efi_guid_t efi_guid_hii_string_protocol;
+/* GUID for authentication */
+extern const efi_guid_t efi_guid_image_security_database;
+extern const efi_guid_t efi_guid_sha256;
+extern const efi_guid_t efi_guid_cert_x509;
+extern const efi_guid_t efi_guid_cert_x509_sha256;
 
 extern unsigned int __efi_runtime_start, __efi_runtime_stop;
 extern unsigned int __efi_runtime_rel_start, __efi_runtime_rel_stop;
@@ -654,6 +660,47 @@ void efi_deserialize_load_option(struct efi_load_option 
*lo, u8 *data);
 unsigned long efi_serialize_load_option(struct efi_load_option *lo, u8 **data);
 efi_status_t efi_bootmgr_load(efi_handle_t *handle);
 
+#ifdef CONFIG_EFI_SECURE_BOOT
+#include 
+
+#define EFI_REGS_MAX 16 /* currently good enough */
+
+typedef struct {
+   int num;
+   struct image_region reg[EFI_REGS_MAX];
+} efi_image_regions;
+
+struct efi_sig_data {
+   struct efi_sig_data *next;
+   efi_guid_t owner;
+   void *data;
+   size_t size;
+};
+

[U-Boot] [RFC 13/15] cmd: env: provide appropriate guid for well-defined variable

2019-09-17 Thread AKASHI Takahiro
Any signature database variable is associated with a specific guid.
For convenience, if user doesn't supply any guid info, "env set|print -e"
should complement it.

Signed-off-by: AKASHI Takahiro 
---
 cmd/nvedit_efi.c | 31 +++
 1 file changed, 23 insertions(+), 8 deletions(-)

diff --git a/cmd/nvedit_efi.c b/cmd/nvedit_efi.c
index 4532124c33d0..a4dbf37f3f2e 100644
--- a/cmd/nvedit_efi.c
+++ b/cmd/nvedit_efi.c
@@ -41,6 +41,11 @@ static const struct {
 } efi_guid_text[] = {
/* signature database */
{EFI_GLOBAL_VARIABLE_GUID, "EFI_GLOBAL_VARIABLE_GUID"},
+   {EFI_IMAGE_SECURITY_DATABASE_GUID, "EFI_IMAGE_SECURITY_DATABASE_GUID"},
+   /* certificate type */
+   {EFI_CERT_SHA256_GUID, "EFI_CERT_SHA256_GUID"},
+   {EFI_CERT_X509_GUID, "EFI_CERT_X509_GUID"},
+   {EFI_CERT_TYPE_PKCS7_GUID, "EFI_CERT_TYPE_PKCS7_GUID"},
 };
 
 /* "----" */
@@ -135,6 +140,7 @@ static int efi_dump_vars(int argc,  char * const argv[], 
bool verbose)
 {
u16 *var_name16, *p;
efi_uintn_t buf_size, size;
+   efi_guid_t *guid;
 
buf_size = 128;
var_name16 = malloc(buf_size);
@@ -156,9 +162,13 @@ static int efi_dump_vars(int argc,  char * const argv[], 
bool verbose)
p = var_name16;
utf8_utf16_strcpy(&p, argv[0]);
 
-   efi_dump_single_var(var_name16,
-   (efi_guid_t *)&efi_global_variable_guid,
-   verbose);
+   if (!strcmp(argv[0], "db") || !strcmp(argv[0], "dbx") ||
+   !strcmp(argv[0], "dbt"))
+   guid = (efi_guid_t *)&efi_guid_image_security_database;
+   else
+   guid = (efi_guid_t *)&efi_global_variable_guid;
+
+   efi_dump_single_var(var_name16, guid, verbose);
}
 
free(var_name16);
@@ -167,7 +177,7 @@ static int efi_dump_vars(int argc,  char * const argv[], 
bool verbose)
 }
 
 /**
- * efi_dump_vars() - show information about all the UEFI variables
+ * efi_dump_var_all() - show information about all the UEFI variables
  *
  * @verbose:   if true, dump data
  * Return: CMD_RET_SUCCESS on success, or CMD_RET_RET_FAILURE
@@ -463,9 +473,9 @@ int do_env_set_efi(cmd_tbl_t *cmdtp, int flag, int argc, 
char * const argv[])
if (*ep != ',')
return CMD_RET_USAGE;
 
+   /* 0 should be allowed for delete */
size = simple_strtoul(++ep, NULL, 16);
-   if (!size)
-   return CMD_RET_FAILURE;
+
value_on_memory = true;
} else if (!strcmp(argv[0], "-v")) {
verbose = true;
@@ -477,8 +487,13 @@ int do_env_set_efi(cmd_tbl_t *cmdtp, int flag, int argc, 
char * const argv[])
return CMD_RET_USAGE;
 
var_name = argv[0];
-   if (default_guid)
-   guid = efi_global_variable_guid;
+   if (default_guid) {
+   if (!strcmp(var_name, "db") || !strcmp(var_name, "dbx") ||
+   !strcmp(var_name, "dbt"))
+   guid = efi_guid_image_security_database;
+   else
+   guid = efi_global_variable_guid;
+   }
 
if (verbose) {
printf("GUID: %s\n", efi_guid_to_str(&guid));
-- 
2.21.0

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


[U-Boot] [RFC 15/15] efi_loader, pytest: add UEFI secure boot tests (authenticated variables)

2019-09-17 Thread AKASHI Takahiro
test_efi_secboot/test_authvar.py: provide test cases of variable
authentication

This test relies on efitools and user should compile it on his own.
(Currently some local change has been applied.)

Signed-off-by: AKASHI Takahiro 
---
 .../py/tests/test_efi_secboot/test_authvar.py | 287 ++
 1 file changed, 287 insertions(+)
 create mode 100644 test/py/tests/test_efi_secboot/test_authvar.py

diff --git a/test/py/tests/test_efi_secboot/test_authvar.py 
b/test/py/tests/test_efi_secboot/test_authvar.py
new file mode 100644
index ..2ae25e8ce7eb
--- /dev/null
+++ b/test/py/tests/test_efi_secboot/test_authvar.py
@@ -0,0 +1,287 @@
+# SPDX-License-Identifier:  GPL-2.0+
+# Copyright (c) 2019, Linaro Limited
+# Author: AKASHI Takahiro 
+#
+# U-Boot UEFI: Variable Authentication Test
+
+"""
+This test verifies variable authentication
+"""
+
+import pytest
+import re
+from defs import *
+
+@pytest.mark.boardspec('sandbox')
+@pytest.mark.buildconfigspec('efi_secure_boot')
+@pytest.mark.slow
+class TestEfiAuthVar(object):
+def test_efi_var_auth1(self, u_boot_console, efi_boot_env):
+"""
+Test Case 1 - Install signature database
+"""
+disk_img = efi_boot_env
+with u_boot_console.log.section('Test Case 1a'):
+# Test Case 1a, Initial secure state
+output = u_boot_console.run_command_list([
+'host bind 0 %s' % disk_img,
+'printenv -e -v SecureBoot'])
+assert(re.search(': 00', ''.join(output)))
+
+output = u_boot_console.run_command(
+'printenv -e -v SecureBoot')
+assert(': 00' in output)
+output = u_boot_console.run_command(
+'printenv -e -v SetupMode')
+assert(': 01' in output)
+
+with u_boot_console.log.section('Test Case 1b'):
+# Test Case 1b, PK without AUTHENTICATED_WRITE_ACCESS
+output = u_boot_console.run_command_list([
+'host bind 0 %s' % disk_img,
+'fatload host 0:0 400 PK.auth',
+'setenv -e -nv -bs -rt -i 400,$filesize PK'])
+assert(re.search('Failed to set EFI variable', ''.join(output)))
+
+with u_boot_console.log.section('Test Case 1c'):
+# Test Case 1c, install PK
+output = u_boot_console.run_command_list([
+'fatload host 0:0 400 PK.auth',
+'setenv -e -nv -bs -rt -at -i 400,$filesize PK',
+'printenv -e PK'])
+assert(re.search('PK:', ''.join(output)))
+
+output = u_boot_console.run_command(
+'printenv -e -v SecureBoot')
+assert(': 01' in output)
+output = u_boot_console.run_command(
+'printenv -e -v SetupMode')
+assert(': 00' in output)
+
+with u_boot_console.log.section('Test Case 1d'):
+# Test Case 1d, db/dbx without KEK
+output = u_boot_console.run_command_list([
+'fatload host 0:0 400 DB.auth',
+'setenv -e -nv -bs -rt -at -i 400,$filesize db'])
+assert(re.search('Failed to set EFI variable', ''.join(output)))
+
+output = u_boot_console.run_command_list([
+'fatload host 0:0 400 DB.auth',
+'setenv -e -nv -bs -rt -at -i 400,$filesize dbx'])
+assert(re.search('Failed to set EFI variable', ''.join(output)))
+
+with u_boot_console.log.section('Test Case 1e'):
+# Test Case 1e, install KEK
+output = u_boot_console.run_command_list([
+'fatload host 0:0 400 KEK.auth',
+'setenv -e -nv -bs -rt -i 400,$filesize KEK'])
+assert(re.search('Failed to set EFI variable', ''.join(output)))
+
+output = u_boot_console.run_command_list([
+'fatload host 0:0 400 KEK.auth',
+'setenv -e -nv -bs -rt -at -i 400,$filesize KEK',
+'printenv -e KEK'])
+assert(re.search('KEK:', ''.join(output)))
+
+output = u_boot_console.run_command(
+'printenv -e -v SecureBoot')
+assert(': 01' in output)
+
+with u_boot_console.log.section('Test Case 1f'):
+# Test Case 1f, install db
+output = u_boot_console.run_command_list([
+'fatload host 0:0 400 DB.auth',
+'setenv -e -nv -bs -rt -i 400,$filesize db'])
+assert(re.search('Failed to set EFI variable', ''.join(output)))
+
+output = u_boot_console.run_command_list([
+'fatload host 0:0 400 DB.auth',
+'setenv -e -nv -bs -rt -at -i 400,$filesize db',
+'printenv -e db'])
+assert(re.search('db:', ''.join(output)))
+
+output = u_boot_consol

[U-Boot] [RFC 14/15] efi_loader, pytest: add UEFI secure boot tests (image)

2019-09-17 Thread AKASHI Takahiro
test_efi_secboot/test_signed.py: provide test cases of image authentication
for signed images
test_efi_secboot/test_unsigned.py: provide test cases of image
authentication for unsigned images

This test relies on efitools and user should compile it on his own.
(Currently some local change has been applied.)

Signed-off-by: AKASHI Takahiro 
---
 test/py/tests/test_efi_secboot/conftest.py| 168 ++
 test/py/tests/test_efi_secboot/defs.py|   7 +
 test/py/tests/test_efi_secboot/test_signed.py |  97 ++
 .../tests/test_efi_secboot/test_unsigned.py   | 126 +
 4 files changed, 398 insertions(+)
 create mode 100644 test/py/tests/test_efi_secboot/conftest.py
 create mode 100644 test/py/tests/test_efi_secboot/defs.py
 create mode 100644 test/py/tests/test_efi_secboot/test_signed.py
 create mode 100644 test/py/tests/test_efi_secboot/test_unsigned.py

diff --git a/test/py/tests/test_efi_secboot/conftest.py 
b/test/py/tests/test_efi_secboot/conftest.py
new file mode 100644
index ..3806f305a138
--- /dev/null
+++ b/test/py/tests/test_efi_secboot/conftest.py
@@ -0,0 +1,168 @@
+# SPDX-License-Identifier:  GPL-2.0+
+# Copyright (c) 2019, Linaro Limited
+# Author: AKASHI Takahiro 
+
+import os
+import os.path
+import pytest
+import re
+from subprocess import call, check_call, check_output, CalledProcessError
+from defs import *
+
+#
+# Helper functions
+#
+def mk_fs(config, fs_type, size, id):
+"""Create a file system volume.
+
+Args:
+fs_type: File system type.
+size: Size of file system in MiB.
+id: Prefix string of volume's file name.
+
+Return:
+Nothing.
+"""
+fs_img = '%s.%s.img' % (id, fs_type)
+fs_img = config.persistent_data_dir + '/' + fs_img
+
+if fs_type == 'fat16':
+mkfs_opt = '-F 16'
+elif fs_type == 'fat32':
+mkfs_opt = '-F 32'
+elif fs_type == 'ext4':
+mkfs_opt = '-O ^metadata_csum'
+else:
+mkfs_opt = ''
+
+if re.match('fat', fs_type):
+fs_lnxtype = 'vfat'
+else:
+fs_lnxtype = fs_type
+
+count = (size + 1048576 - 1) / 1048576
+
+try:
+check_call('rm -f %s' % fs_img, shell=True)
+check_call('dd if=/dev/zero of=%s bs=1M count=%d'
+% (fs_img, count), shell=True)
+check_call('mkfs.%s %s %s'
+% (fs_lnxtype, mkfs_opt, fs_img), shell=True)
+return fs_img
+except CalledProcessError:
+call('rm -f %s' % fs_img, shell=True)
+raise
+
+# from test/py/conftest.py
+def tool_is_in_path(tool):
+"""Check whether a given command is available on host.
+
+Args:
+tool: Command name.
+
+Return:
+True if available, False if not.
+"""
+for path in os.environ['PATH'].split(os.pathsep):
+fn = os.path.join(path, tool)
+if os.path.isfile(fn) and os.access(fn, os.X_OK):
+return True
+return False
+
+fuse_mounted = False
+
+def mount_fs(fs_type, device, mount_point):
+"""Mount a volume.
+
+Args:
+fs_type: File system type.
+device: Volume's file name.
+mount_point: Mount point.
+
+Return:
+Nothing.
+"""
+global fuse_mounted
+
+fuse_mounted = False
+try:
+if tool_is_in_path('guestmount'):
+fuse_mounted = True
+check_call('guestmount -a %s -m /dev/sda %s'
+% (device, mount_point), shell=True)
+else:
+mount_opt = 'loop,rw'
+if re.match('fat', fs_type):
+mount_opt += ',umask='
+
+check_call('sudo mount -o %s %s %s'
+% (mount_opt, device, mount_point), shell=True)
+
+# may not be effective for some file systems
+check_call('sudo chmod a+rw %s' % mount_point, shell=True)
+except CalledProcessError:
+raise
+
+def umount_fs(mount_point):
+"""Unmount a volume.
+
+Args:
+mount_point: Mount point.
+
+Return:
+Nothing.
+"""
+if fuse_mounted:
+call('sync')
+call('guestunmount %s' % mount_point, shell=True)
+else:
+call('sudo umount %s' % mount_point, shell=True)
+
+#
+# Fixture for TestEfiSignedImage test
+#
+# NOTE: yield_fixture was deprecated since pytest-3.0
+@pytest.yield_fixture()
+def efi_boot_env(request, u_boot_config):
+"""Set up a file system to be used in basic fs test.
+
+Args:
+request: Pytest request object.
+   u_boot_config: U-boot configuration.
+
+Return:
+A fixture for basic fs test, i.e. a triplet of file system type,
+volume file name and  a list of MD5 hashes.
+"""
+fs_type = 'fat32'
+fs_img = ''
+
+mount_dir = u_boot_config.persistent_data_dir + '/mnt'
+
+try:
+
+# test volume
+fs_img = mk_fs(u_boot_config, 'fat32', TEST_VOL_SIZE, 'test')
+
+# Mount the image so we can populate it.
+check_ou

[U-Boot] [RFC 12/15] efi_loader: add CONFIG_EFI_SECURE_BOOT

2019-09-17 Thread AKASHI Takahiro
Now we can enable UEFI secure boot with this option.

Signed-off-by: AKASHI Takahiro 
---
 lib/efi_loader/Kconfig | 13 +
 1 file changed, 13 insertions(+)

diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
index c7027a967653..fb66766d2b7a 100644
--- a/lib/efi_loader/Kconfig
+++ b/lib/efi_loader/Kconfig
@@ -115,4 +115,17 @@ config EFI_GRUB_ARM32_WORKAROUND
  GRUB prior to version 2.04 requires U-Boot to disable caches. This
  workaround currently is also needed on systems with caches that
  cannot be managed via CP15.
+
+config EFI_SECURE_BOOT
+   bool "Enable EFI secure boot support"
+   depends on EFI_LOADER
+   depends on SECURE_BOOT
+   imply RSA_VERIFY_WITH_PKEY
+   default n
+   help
+ Select this option to enable EFI secure boot support.
+ Once SecureBoot mode is enforced, any EFI binary can run only if
+ it is signed with a trusted key. To do that, you need to install,
+ at least, PK, KEK and db.
+
 endif
-- 
2.21.0

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


Re: [U-Boot] [PATCH V2] [RFC] usb: storage: Limit transfer size to 120 kiB

2019-09-17 Thread Bin Meng
On Tue, Sep 17, 2019 at 10:43 PM Marek Vasut  wrote:
>
> Due to constant influx of more and more weird and broken USB sticks,
> do as Linux does in commit 779b457f66e10de3471479373463b27fd308dc85
>
> usb: storage: scsiglue: further describe our 240 sector limit
>
> Just so we have some sort of documentation as to why
> we limit our Mass Storage transfers to 240 sectors,
> let's update the comment to make clearer that
> devices were found that would choke with larger
> transfers.
>
> While at that, also make sure to clarify that other
> operating systems have similar, albeit different,
> limits on mass storage transfers.
>
> And reduce the maximum transfer length of USB storage to 120 kiB.
>
> Signed-off-by: Marek Vasut 
> Cc: Bin Meng 
> Cc: Simon Glass 
> ---
> V2: Reshuffle the code a bit, always clamp the transfer size to 240 blocks
> ---
>  common/usb_storage.c | 43 ++-
>  1 file changed, 22 insertions(+), 21 deletions(-)
>
> diff --git a/common/usb_storage.c b/common/usb_storage.c
> index 8c889bb1a6..e1b539a082 100644
> --- a/common/usb_storage.c
> +++ b/common/usb_storage.c
> @@ -938,31 +938,32 @@ do_retry:
>  static void usb_stor_set_max_xfer_blk(struct usb_device *udev,
>   struct us_data *us)
>  {
> -   unsigned short blk;
> -   size_t __maybe_unused size;
> -   int __maybe_unused ret;
> -
> -#if !CONFIG_IS_ENABLED(DM_USB)
> -#ifdef CONFIG_USB_EHCI_HCD
> /*
> -* The U-Boot EHCI driver can handle any transfer length as long as
> -* there is enough free heap space left, but the SCSI READ(10) and
> -* WRITE(10) commands are limited to 65535 blocks.
> +* Limit the total size of a transfer to 120 KB.
> +*
> +* Some devices are known to choke with anything larger. It seems like
> +* the problem stems from the fact that original IDE controllers had
> +* only an 8-bit register to hold the number of sectors in one 
> transfer
> +* and even those couldn't handle a full 256 sectors.
> +*
> +* Because we want to make sure we interoperate with as many devices 
> as
> +* possible, we will maintain a 240 sector transfer size limit for USB
> +* Mass Storage devices.
> +*
> +* Tests show that other operating have similar limits with Microsoft
> +* Windows 7 limiting transfers to 128 sectors for both USB2 and USB3
> +* and Apple Mac OS X 10.11 limiting transfers to 256 sectors for USB2
> +* and 2048 for USB3 devices.
>  */
> -   blk = USHRT_MAX;
> -#else
> -   blk = 20;
> -#endif
> -#else
> +   unsigned short blk = 240;
> +
> +#if CONFIG_IS_ENABLED(DM_USB)
> +   size_t size;
> +   int ret;
> +
> ret = usb_get_max_xfer_size(udev, (size_t *)&size);
> -   if (ret < 0) {
> -   /* unimplemented, let's use default 20 */
> -   blk = 20;
> -   } else {
> -   if (size > USHRT_MAX * 512)
> -   size = USHRT_MAX * 512;
> +   if ((ret >= 0) && (size < 240 * 512))

size < blk * 512

> blk = size / 512;
> -   }
>  #endif
>
> us->max_xfer_blk = blk;
> --

Looks good otherwise

Reviewed-by: Bin Meng 
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2 01/28] serial: serial_mtk: enable FIFO and disable flow control

2019-09-17 Thread Weijie Gao
This patch adds codes to enable FIFO and disable flow control taken from
ns16550 driver.

Signed-off-by: Weijie Gao 
---
 drivers/serial/serial_mtk.c | 21 +
 1 file changed, 21 insertions(+)

diff --git a/drivers/serial/serial_mtk.c b/drivers/serial/serial_mtk.c
index bce1be8227..11892a8740 100644
--- a/drivers/serial/serial_mtk.c
+++ b/drivers/serial/serial_mtk.c
@@ -46,6 +46,22 @@ struct mtk_serial_regs {
 
 #define UART_LSR_DR0x01/* Data ready */
 #define UART_LSR_THRE  0x20/* Xmit holding register empty */
+#define UART_LSR_TEMT  0x40/* Xmitter empty */
+
+#define UART_MCR_DTR   0x01/* DTR   */
+#define UART_MCR_RTS   0x02/* RTS   */
+
+#define UART_FCR_FIFO_EN   0x01/* Fifo enable */
+#define UART_FCR_RXSR  0x02/* Receiver soft reset */
+#define UART_FCR_TXSR  0x04/* Transmitter soft reset */
+
+#define UART_MCRVAL (UART_MCR_DTR | \
+UART_MCR_RTS)
+
+/* Clear & enable FIFOs */
+#define UART_FCRVAL (UART_FCR_FIFO_EN | \
+UART_FCR_RXSR |\
+UART_FCR_TXSR)
 
 /* the data is correct if the real baud is within 3%. */
 #define BAUD_ALLOW_MAX(baud)   ((baud) + (baud) * 3 / 100)
@@ -175,6 +191,9 @@ static int mtk_serial_probe(struct udevice *dev)
/* Disable interrupt */
writel(0, &priv->regs->ier);
 
+   writel(UART_MCRVAL, &priv->regs->mcr);
+   writel(UART_FCRVAL, &priv->regs->fcr);
+
return 0;
 }
 
@@ -248,6 +267,8 @@ static inline void _debug_uart_init(void)
priv.clock = CONFIG_DEBUG_UART_CLOCK;
 
writel(0, &priv.regs->ier);
+   writel(UART_MCRVAL, &priv.regs->mcr);
+   writel(UART_FCRVAL, &priv.regs->fcr);
 
_mtk_serial_setbrg(&priv, CONFIG_BAUDRATE);
 }
-- 
2.17.1

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


[U-Boot] [PATCH v2 00/28] Add and update drivers for MediaTek MT76x8 SoCs

2019-09-17 Thread Weijie Gao
This patch series have the following changes:

- Add pinctrl(both pinmux and pinconf) driver, reset controller driver and
   clock driver for mt7628.
- Add mt7628 platform to mtk-sd driver.
- Modify mt7628's ethernet & usb phy driver to take advantages from the new
   drivers.
- Update mt7621-spi driver with a new transfer method.
- Enable fifo, disable flow control, and enable non-DM implementation for mtk
   hsuart driver.
- Enanble the new drivers for currently existed mt7628 boards.

Changes of v2:
- Change clock gateing driver to a more 'generic' driver which supports output
  clock rates of CPU/SYS_BUS/peripherals.
- mt7621-spi now uses accurate sys_freq from clock driver.
- Make PHY link detection optional via DT.
- Select essential drivers in Kconfig instead of setting in defconfig files.

Weijie Gao (28):
  serial: serial_mtk: enable FIFO and disable flow control
  serial: serial_mtk: add non-DM version for SPL
  dts: mtmips: move uart property clock-frequency into mt7628an.dtsi
  dts: mtmips: enable high-speed UART support for mt7628
  clk: add clock driver for MediaTek MT76x8 platform
  dts: mtmips: add clock node for mt7628
  spi: mt7621-spi: use clock frequency from clk driver
  spi: mt7621-spi: remove data cache and rewrite its xfer function
  spi: mt7621-spi: restore default register value after each xfer
  pinctrl: add support for MediaTek MT7628
  dts: mtmips: add pinctrl node for mt7628
  dts: mtmips: add default pinctrl for uart nodes
  reset: add reset controller driver for MediaTek MIPS platform
  dts: mtmips: update reset controller node for mt7628
  phy: mt76x8-usb-phy: add slew rate calibration and remove non-mt7628
part
  net: mt7628-eth: remove hardcoded gpio settings and regmap-based phy
reset
  net: mt7628-eth: make phy link up detection optional via DT
  net: mt7628-eth: free rx descriptor on receiving failure
  net: mt7628-eth: add support to isolate LAN/WAN ports
  dts: mtmips: enable eth port0 led and link poll functions for all
boards
  mmc: mtk-sd: add support for MediaTek MT7620/MT7628 SoCs
  mmc: mtk-sd: add a dts property cd-active-high for builtin-cd mode
  dts: mtmips: add mmc related nodes for mt7628an.dtsi
  dts: mtmips: add default pinctrl for gardena-smart-gateway-mt7688
  dts: mtmips: add default pinctrl to eth nodes for all boards
  mips: mtmips: change baudrate table for all boards
  mips: mtmips: select essential drivers in Kconfig
  configs: mtmips: remove configs which are selected in Kconfig or
useless

 arch/mips/Kconfig |   6 +
 .../mips/dts/gardena-smart-gateway-mt7688.dts |  19 +-
 arch/mips/dts/linkit-smart-7688.dts   |  16 +-
 arch/mips/dts/mt7628a.dtsi| 246 +++-
 arch/mips/mach-mtmips/Kconfig |   2 +
 ...gardena-smart-gateway-mt7688-ram_defconfig |   7 -
 .../gardena-smart-gateway-mt7688_defconfig|   7 -
 configs/linkit-smart-7688-ram_defconfig   |   7 -
 configs/linkit-smart-7688_defconfig   |   7 -
 drivers/clk/Makefile  |   1 +
 drivers/clk/mtmips/Makefile   |   3 +
 drivers/clk/mtmips/clk-mt7628.c   | 158 +
 drivers/mmc/Kconfig   |   2 +-
 drivers/mmc/mtk-sd.c  |  32 +-
 drivers/net/Kconfig   |   1 +
 drivers/net/mt7628-eth.c  | 135 ++--
 drivers/phy/Kconfig   |   2 +
 drivers/phy/mt76x8-usb-phy.c  | 225 +--
 drivers/pinctrl/Kconfig   |   1 +
 drivers/pinctrl/Makefile  |   1 +
 drivers/pinctrl/mtmips/Kconfig|  13 +
 drivers/pinctrl/mtmips/Makefile   |   7 +
 drivers/pinctrl/mtmips/pinctrl-mt7628.c   | 585 ++
 .../pinctrl/mtmips/pinctrl-mtmips-common.c|  87 +++
 .../pinctrl/mtmips/pinctrl-mtmips-common.h|  53 ++
 drivers/reset/Kconfig |   7 +
 drivers/reset/Makefile|   1 +
 drivers/reset/reset-mtmips.c  |  82 +++
 drivers/serial/serial.c   |   2 +
 drivers/serial/serial_mtk.c   | 223 ++-
 drivers/spi/mt7621_spi.c  | 247 
 .../configs/gardena-smart-gateway-mt7688.h|   2 +-
 include/configs/linkit-smart-7688.h   |   2 +-
 include/dt-bindings/clock/mt7628-clk.h|  37 ++
 include/dt-bindings/reset/mt7628-reset.h  |  36 ++
 35 files changed, 1933 insertions(+), 329 deletions(-)
 create mode 100644 drivers/clk/mtmips/Makefile
 create mode 100644 drivers/clk/mtmips/clk-mt7628.c
 create mode 100644 drivers/pinctrl/mtmips/Kconfig
 create mode 100644 drivers/pinctrl/mtmips/Makefile
 create mode 100644 drivers/pinctrl/mtmips/pinctrl-mt7628.c
 create mode 100644 drivers/pinctrl/mtmips/pinctrl-mtmips-common.c
 create mode 100644 drivers/pinctrl/mtmips/pinctrl-mtmips-common.h
 create mode 100644 drivers/reset/reset-mtmip

[U-Boot] [PATCH v2 02/28] serial: serial_mtk: add non-DM version for SPL

2019-09-17 Thread Weijie Gao
This patch adds non-DM version for mtk hsuart driver and makes it
compatible with ns16550a driver in configuration.
This is needed in SPL with CONFIG_SPL_DM disabled for reducing size.

Signed-off-by: Weijie Gao 
---
 drivers/serial/serial.c |   2 +
 drivers/serial/serial_mtk.c | 202 +---
 2 files changed, 187 insertions(+), 17 deletions(-)

diff --git a/drivers/serial/serial.c b/drivers/serial/serial.c
index b907508dbe..bf5f39215d 100644
--- a/drivers/serial/serial.c
+++ b/drivers/serial/serial.c
@@ -124,6 +124,7 @@ serial_initfunc(ns16550_serial_initialize);
 serial_initfunc(pl01x_serial_initialize);
 serial_initfunc(pxa_serial_initialize);
 serial_initfunc(sh_serial_initialize);
+serial_initfunc(mtk_serial_initialize);
 
 /**
  * serial_register() - Register serial driver with serial driver core
@@ -177,6 +178,7 @@ void serial_initialize(void)
pl01x_serial_initialize();
pxa_serial_initialize();
sh_serial_initialize();
+   mtk_serial_initialize();
 
serial_assign(default_serial_console()->name);
 }
diff --git a/drivers/serial/serial_mtk.c b/drivers/serial/serial_mtk.c
index 11892a8740..18530a4fd1 100644
--- a/drivers/serial/serial_mtk.c
+++ b/drivers/serial/serial_mtk.c
@@ -140,6 +140,37 @@ static void _mtk_serial_setbrg(struct mtk_serial_priv 
*priv, int baud)
}
 }
 
+static int _mtk_serial_putc(struct mtk_serial_priv *priv, const char ch)
+{
+   if (!(readl(&priv->regs->lsr) & UART_LSR_THRE))
+   return -EAGAIN;
+
+   writel(ch, &priv->regs->thr);
+
+   if (ch == '\n')
+   WATCHDOG_RESET();
+
+   return 0;
+}
+
+static int _mtk_serial_getc(struct mtk_serial_priv *priv)
+{
+   if (!(readl(&priv->regs->lsr) & UART_LSR_DR))
+   return -EAGAIN;
+
+   return readl(&priv->regs->rbr);
+}
+
+static int _mtk_serial_pending(struct mtk_serial_priv *priv, bool input)
+{
+   if (input)
+   return (readl(&priv->regs->lsr) & UART_LSR_DR) ? 1 : 0;
+   else
+   return (readl(&priv->regs->lsr) & UART_LSR_THRE) ? 0 : 1;
+}
+
+#if defined(CONFIG_DM_SERIAL) && \
+   (!defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_DM))
 static int mtk_serial_setbrg(struct udevice *dev, int baudrate)
 {
struct mtk_serial_priv *priv = dev_get_priv(dev);
@@ -153,35 +184,21 @@ static int mtk_serial_putc(struct udevice *dev, const 
char ch)
 {
struct mtk_serial_priv *priv = dev_get_priv(dev);
 
-   if (!(readl(&priv->regs->lsr) & UART_LSR_THRE))
-   return -EAGAIN;
-
-   writel(ch, &priv->regs->thr);
-
-   if (ch == '\n')
-   WATCHDOG_RESET();
-
-   return 0;
+   return _mtk_serial_putc(priv, ch);
 }
 
 static int mtk_serial_getc(struct udevice *dev)
 {
struct mtk_serial_priv *priv = dev_get_priv(dev);
 
-   if (!(readl(&priv->regs->lsr) & UART_LSR_DR))
-   return -EAGAIN;
-
-   return readl(&priv->regs->rbr);
+   return _mtk_serial_getc(priv);
 }
 
 static int mtk_serial_pending(struct udevice *dev, bool input)
 {
struct mtk_serial_priv *priv = dev_get_priv(dev);
 
-   if (input)
-   return (readl(&priv->regs->lsr) & UART_LSR_DR) ? 1 : 0;
-   else
-   return (readl(&priv->regs->lsr) & UART_LSR_THRE) ? 0 : 1;
+   return _mtk_serial_pending(priv, input);
 }
 
 static int mtk_serial_probe(struct udevice *dev)
@@ -254,6 +271,157 @@ U_BOOT_DRIVER(serial_mtk) = {
.ops = &mtk_serial_ops,
.flags = DM_FLAG_PRE_RELOC,
 };
+#else
+
+DECLARE_GLOBAL_DATA_PTR;
+
+#define DECLARE_HSUART_PRIV(port) \
+   static struct mtk_serial_priv mtk_hsuart##port = { \
+   .regs = (struct mtk_serial_regs *)CONFIG_SYS_NS16550_COM##port, \
+   .clock = CONFIG_SYS_NS16550_CLK \
+};
+
+#define DECLARE_HSUART_FUNCTIONS(port) \
+   static int mtk_serial##port##_init(void) \
+   { \
+   writel(0, &mtk_hsuart##port.regs->ier); \
+   writel(UART_MCRVAL, &mtk_hsuart##port.regs->mcr); \
+   writel(UART_FCRVAL, &mtk_hsuart##port.regs->fcr); \
+   _mtk_serial_setbrg(&mtk_hsuart##port, gd->baudrate); \
+   return 0 ; \
+   } \
+   static void mtk_serial##port##_setbrg(void) \
+   { \
+   _mtk_serial_setbrg(&mtk_hsuart##port, gd->baudrate); \
+   } \
+   static int mtk_serial##port##_getc(void) \
+   { \
+   int err; \
+   do { \
+   err = _mtk_serial_getc(&mtk_hsuart##port); \
+   if (err == -EAGAIN) \
+   WATCHDOG_RESET(); \
+   } while (err == -EAGAIN); \
+   return err >= 0 ? err : 0; \
+   } \
+   static int mtk_serial##port##_tstc(void) \
+   { \
+   return _mtk_serial_pending(&mtk_hsuart##port, true); \
+   } \
+   static void mtk_serial##port##_putc(const char c) \
+   { \
+   int 

[U-Boot] [PATCH v2 03/28] dts: mtmips: move uart property clock-frequency into mt7628an.dtsi

2019-09-17 Thread Weijie Gao
The UART of MT7628 has fixed 40MHz input clock so there is no need to put
clock-frequency in every dts files. Just put it into the common dtsi file.

Reviewed-by: Stefan Roese 
Signed-off-by: Weijie Gao 
---
 arch/mips/dts/gardena-smart-gateway-mt7688.dts | 1 -
 arch/mips/dts/linkit-smart-7688.dts| 1 -
 arch/mips/dts/mt7628a.dtsi | 6 ++
 3 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/arch/mips/dts/gardena-smart-gateway-mt7688.dts 
b/arch/mips/dts/gardena-smart-gateway-mt7688.dts
index eedde89dfd..95675a3947 100644
--- a/arch/mips/dts/gardena-smart-gateway-mt7688.dts
+++ b/arch/mips/dts/gardena-smart-gateway-mt7688.dts
@@ -87,7 +87,6 @@
 
 &uart0 {
status = "okay";
-   clock-frequency = <4000>;
 };
 
 &spi0 {
diff --git a/arch/mips/dts/linkit-smart-7688.dts 
b/arch/mips/dts/linkit-smart-7688.dts
index bb10402174..935315743c 100644
--- a/arch/mips/dts/linkit-smart-7688.dts
+++ b/arch/mips/dts/linkit-smart-7688.dts
@@ -28,7 +28,6 @@
 
 &uart2 {
status = "okay";
-   clock-frequency = <4000>;
 };
 
 &spi0 {
diff --git a/arch/mips/dts/mt7628a.dtsi b/arch/mips/dts/mt7628a.dtsi
index 1e7d0a6ec5..6bc0722b07 100644
--- a/arch/mips/dts/mt7628a.dtsi
+++ b/arch/mips/dts/mt7628a.dtsi
@@ -127,6 +127,8 @@
compatible = "ns16550a";
reg = <0xc00 0x100>;
 
+   clock-frequency = <4000>;
+
resets = <&resetc 12>;
reset-names = "uart0";
 
@@ -140,6 +142,8 @@
compatible = "ns16550a";
reg = <0xd00 0x100>;
 
+   clock-frequency = <4000>;
+
resets = <&resetc 19>;
reset-names = "uart1";
 
@@ -153,6 +157,8 @@
compatible = "ns16550a";
reg = <0xe00 0x100>;
 
+   clock-frequency = <4000>;
+
resets = <&resetc 20>;
reset-names = "uart2";
 
-- 
2.17.1

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


[U-Boot] [PATCH v2 04/28] dts: mtmips: enable high-speed UART support for mt7628

2019-09-17 Thread Weijie Gao
All three UARTs of mt7628 are actually MediaTek's high-speed UARTs which
support baudrate up to 921600.
The high-speed UART is compatible with ns16550 when baudrate <= 115200.

Add compatible string to dtsi file so u-boot can use it when serial_mtk
driver is built in.

Reviewed-by: Stefan Roese 
Signed-off-by: Weijie Gao 
---
 arch/mips/dts/mt7628a.dtsi | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/mips/dts/mt7628a.dtsi b/arch/mips/dts/mt7628a.dtsi
index 6bc0722b07..e9241a0737 100644
--- a/arch/mips/dts/mt7628a.dtsi
+++ b/arch/mips/dts/mt7628a.dtsi
@@ -124,7 +124,7 @@
};
 
uart0: uartlite@c00 {
-   compatible = "ns16550a";
+   compatible = "mediatek,hsuart", "ns16550a";
reg = <0xc00 0x100>;
 
clock-frequency = <4000>;
@@ -139,7 +139,7 @@
};
 
uart1: uart1@d00 {
-   compatible = "ns16550a";
+   compatible = "mediatek,hsuart", "ns16550a";
reg = <0xd00 0x100>;
 
clock-frequency = <4000>;
@@ -154,7 +154,7 @@
};
 
uart2: uart2@e00 {
-   compatible = "ns16550a";
+   compatible = "mediatek,hsuart", "ns16550a";
reg = <0xe00 0x100>;
 
clock-frequency = <4000>;
-- 
2.17.1

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


[U-Boot] [PATCH v2 07/28] spi: mt7621-spi: use clock frequency from clk driver

2019-09-17 Thread Weijie Gao
This patch lets the spi driver to use clock provided by the clk driver
since the new clk-mt7628 driver provides accurate sys clock frequency.

Signed-off-by: Weijie Gao 
---
v2: newly added
---
 drivers/spi/mt7621_spi.c | 20 +---
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/drivers/spi/mt7621_spi.c b/drivers/spi/mt7621_spi.c
index 107e58f657..b37f859b98 100644
--- a/drivers/spi/mt7621_spi.c
+++ b/drivers/spi/mt7621_spi.c
@@ -9,6 +9,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -266,19 +267,24 @@ static int mt7621_spi_xfer(struct udevice *dev, unsigned 
int bitlen,
 static int mt7621_spi_probe(struct udevice *dev)
 {
struct mt7621_spi *rs = dev_get_priv(dev);
+   struct clk clk;
+   int ret;
 
rs->base = dev_remap_addr(dev);
if (!rs->base)
return -EINVAL;
 
-   /*
-* Read input clock via DT for now. At some point this should be
-* replaced by implementing a clock driver for this SoC and getting
-* the SPI frequency via this clock driver.
-*/
-   rs->sys_freq = dev_read_u32_default(dev, "clock-frequency", 0);
+   ret = clk_get_by_index(dev, 0, &clk);
+   if (ret < 0) {
+   printf("Please provide a clock!\n");
+   return ret;
+   }
+
+   clk_enable(&clk);
+
+   rs->sys_freq = clk_get_rate(&clk);
if (!rs->sys_freq) {
-   printf("Please provide clock-frequency!\n");
+   printf("Please provide a valid clock!\n");
return -EINVAL;
}
 
-- 
2.17.1

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


[U-Boot] [PATCH v2 08/28] spi: mt7621-spi: remove data cache and rewrite its xfer function

2019-09-17 Thread Weijie Gao
The mt7621 spi controller supports continuous generic half-duplex spi
transaction. There is no need to cache xfer data at all.

To achieve this goal, the OPADDR register must be used as the first data
to be sent. And follows the eight generic DIDO registers. But one thing
different between OPADDR and DIDO registers is OPADDR has a reversed byte
order.

With this patch, any amount of data can be read/written in a single xfer
function call.

Reviewed-by: Stefan Roese 
Signed-off-by: Weijie Gao 
---
 drivers/spi/mt7621_spi.c | 197 ++-
 1 file changed, 91 insertions(+), 106 deletions(-)

diff --git a/drivers/spi/mt7621_spi.c b/drivers/spi/mt7621_spi.c
index b37f859b98..716256ab59 100644
--- a/drivers/spi/mt7621_spi.c
+++ b/drivers/spi/mt7621_spi.c
@@ -15,9 +15,8 @@
 #include 
 #include 
 
-#define SPI_MSG_SIZE_MAX   32  /* SPI message chunk size */
-/* Enough for SPI NAND page read / write with page size 2048 bytes */
-#define SPI_MSG_SIZE_OVERALL   (2048 + 16)
+#define MT7621_RX_FIFO_LEN 32
+#define MT7621_TX_FIFO_LEN 36
 
 #define MT7621_SPI_TRANS   0x00
 #define MT7621_SPI_TRANS_START BIT(8)
@@ -39,11 +38,16 @@
 #define MASTER_RS_CLK_SEL_SHIFT16
 #define MASTER_RS_SLAVE_SELGENMASK(31, 29)
 
+#define MOREBUF_CMD_CNTGENMASK(29, 24)
+#define MOREBUF_CMD_CNT_SHIFT  24
+#define MOREBUF_MISO_CNT   GENMASK(20, 12)
+#define MOREBUF_MISO_CNT_SHIFT 12
+#define MOREBUF_MOSI_CNT   GENMASK(8, 0)
+#define MOREBUF_MOSI_CNT_SHIFT 0
+
 struct mt7621_spi {
void __iomem *base;
unsigned int sys_freq;
-   u32 data[(SPI_MSG_SIZE_OVERALL / 4) + 1];
-   int tx_len;
 };
 
 static void mt7621_spi_reset(struct mt7621_spi *rs, int duplex)
@@ -129,20 +133,89 @@ static inline int mt7621_spi_wait_till_ready(struct 
mt7621_spi *rs)
return ret;
 }
 
+static int mt7621_spi_read(struct mt7621_spi *rs, u8 *buf, size_t len)
+{
+   size_t rx_len;
+   int i, ret;
+   u32 val = 0;
+
+   while (len) {
+   rx_len = min_t(size_t, len, MT7621_RX_FIFO_LEN);
+
+   iowrite32((rx_len * 8) << MOREBUF_MISO_CNT_SHIFT,
+ rs->base + MT7621_SPI_MOREBUF);
+   iowrite32(MT7621_SPI_TRANS_START, rs->base + MT7621_SPI_TRANS);
+
+   ret = mt7621_spi_wait_till_ready(rs);
+   if (ret)
+   return ret;
+
+   for (i = 0; i < rx_len; i++) {
+   if ((i % 4) == 0)
+   val = ioread32(rs->base + MT7621_SPI_DATA0 + i);
+   *buf++ = val & 0xff;
+   val >>= 8;
+   }
+
+   len -= rx_len;
+   }
+
+   return ret;
+}
+
+static int mt7621_spi_write(struct mt7621_spi *rs, const u8 *buf, size_t len)
+{
+   size_t tx_len, opcode_len, dido_len;
+   int i, ret;
+   u32 val;
+
+   while (len) {
+   tx_len = min_t(size_t, len, MT7621_TX_FIFO_LEN);
+
+   opcode_len = min_t(size_t, tx_len, 4);
+   dido_len = tx_len - opcode_len;
+
+   val = 0;
+   for (i = 0; i < opcode_len; i++) {
+   val <<= 8;
+   val |= *buf++;
+   }
+
+   iowrite32(val, rs->base + MT7621_SPI_OPCODE);
+
+   val = 0;
+   for (i = 0; i < dido_len; i++) {
+   val |= (*buf++) << ((i % 4) * 8);
+
+   if ((i % 4 == 3) || (i == dido_len - 1)) {
+   iowrite32(val, rs->base + MT7621_SPI_DATA0 +
+ (i & ~3));
+   val = 0;
+   }
+   }
+
+   iowrite32(((opcode_len * 8) << MOREBUF_CMD_CNT_SHIFT) |
+ ((dido_len * 8) << MOREBUF_MOSI_CNT_SHIFT),
+ rs->base + MT7621_SPI_MOREBUF);
+   iowrite32(MT7621_SPI_TRANS_START, rs->base + MT7621_SPI_TRANS);
+
+   ret = mt7621_spi_wait_till_ready(rs);
+   if (ret)
+   return ret;
+
+   len -= tx_len;
+   }
+
+   return 0;
+}
+
 static int mt7621_spi_xfer(struct udevice *dev, unsigned int bitlen,
   const void *dout, void *din, unsigned long flags)
 {
struct udevice *bus = dev->parent;
struct mt7621_spi *rs = dev_get_priv(bus);
-   const u8 *tx_buf = dout;
-   u8 *ptr = (u8 *)dout;
-   u8 *rx_buf = din;
int total_size = bitlen >> 3;
-   int chunk_size;
-   int rx_len = 0;
-   u32 data[(SPI_MSG_SIZE_MAX / 4) + 1] = { 0 };
-   u32 val;
-   int i;
+   int ret = 0;
 
debug("%s: dout=%p, din=%p, len=%x, flags=%lx\n", __func__, dout, din,
  total_size, flags);
@@ -156,13 +229,6 @@ static int mt7621_spi_xfer(struct udevice *dev, unsigned 
int bitlen,
return -EIO;

[U-Boot] [PATCH v2 11/28] dts: mtmips: add pinctrl node for mt7628

2019-09-17 Thread Weijie Gao
This patch adds pinctrl node with default pin state for mt7628an.dtsi.

Signed-off-by: Weijie Gao 
---
 arch/mips/dts/mt7628a.dtsi | 150 +
 1 file changed, 150 insertions(+)

diff --git a/arch/mips/dts/mt7628a.dtsi b/arch/mips/dts/mt7628a.dtsi
index 6d2142f429..8afea1865d 100644
--- a/arch/mips/dts/mt7628a.dtsi
+++ b/arch/mips/dts/mt7628a.dtsi
@@ -57,6 +57,156 @@
u-boot,dm-pre-reloc;
};
 
+   pinctrl: pinctrl@60 {
+   compatible = "mediatek,mt7628-pinctrl";
+   reg = <0x3c 0x2c>, <0x1300 0x100>;
+   reg-names = "gpiomode", "padconf";
+
+   pinctrl-names = "default";
+   pinctrl-0 = <&state_default>;
+
+   state_default: pin_state {
+   };
+
+   spi_single_pins: spi_single_pins {
+   groups = "spi";
+   function = "spi";
+   };
+
+   spi_dual_pins: spi_dual_pins {
+   spi_master_pins {
+   groups = "spi";
+   function = "spi";
+   };
+
+   spi_cs1_pin {
+   groups = "spi cs1";
+   function = "spi cs1";
+   };
+   };
+
+   uart0_pins: uart0_pins {
+   groups = "uart0";
+   function = "uart0";
+   };
+
+   uart1_pins: uart1_pins {
+   groups = "uart1";
+   function = "uart1";
+   };
+
+   uart2_pins: uart2_pins {
+   groups = "uart2";
+   function = "uart2";
+   };
+
+   i2c_pins: i2c_pins {
+   groups = "i2c";
+   function = "i2c";
+   };
+
+   ephy_iot_mode: ephy_iot_mode {
+   ephy4_1_dis {
+   groups = "ephy4_1_pad";
+   function = "digital";
+   };
+
+   ephy0_en {
+   groups = "ephy0";
+   function = "enable";
+   };
+   };
+
+   ephy_router_mode: ephy_router_mode {
+   ephy4_1_en {
+   groups = "ephy4_1_pad";
+   function = "analog";
+   };
+
+   ephy0_en {
+   groups = "ephy0";
+   function = "enable";
+   };
+   };
+
+   sd_iot_mode: sd_iot_mode {
+   ephy4_1_dis {
+   groups = "ephy4_1_pad";
+   function = "digital";
+   };
+
+   sdxc_en {
+   groups = "sdmode";
+   function = "sdxc";
+   };
+
+   sdxc_iot_mode {
+   groups = "sd router";
+   function = "iot";
+   };
+
+   sd_clk_pad {
+   pins = "sd_clk";
+   drive-strength-4g = <8>;
+   };
+   };
+
+   sd_router_mode: sd_router_mode {
+   sdxc_router_mode {
+   groups = "sd router";
+   function = "router";
+   };
+
+   sdxc_map_pins {
+   groups = "gpio0", "i2s", "sdmode", \
+"i2c", "uart1";
+   function = "gpio";
+   };
+
+   sd_clk_pad {
+   pins = "gpio0";
+   drive-strength-28 = <8>;
+   };
+   };
+
+   emmc_iot_8bit_mode: emmc_iot_8bit_mode {
+ 

  1   2   >