Re: [PATCH 1/7] libfile: introduce copy_file_2 for copying starting with offset

2019-09-12 Thread Sascha Hauer
On Thu, Sep 12, 2019 at 03:37:49PM +0200, Ahmad Fatoum wrote:
> Hello Uwe,
> 
> On 9/12/19 3:06 PM, Uwe Kleine-König wrote:
> > Hello Ahmad,
> > 
> > On Thu, Sep 12, 2019 at 12:28:59PM +0200, Ahmad Fatoum wrote:
> >> barebox already has a copy_file for copying files. Extend the API by a
> >> copy_file_2 that takes a source offset into account.
> > 
> > Can you give that function a more descriptive name? Something like
> > copy_file_from_offset()?
> 
> I chose copy_file_2 for consistency with the read_file function, which
> had a copy renamed to read_file_2 when it gained a (max) offset parameter.
> 
> Should read_file_2 be renamed as well? 

read_file_2 is named like that because it is a better read_file.
copy_file_2 more looks like another type of copy_file, so I too would
prefer copy_file_from_offset, or even better with an additional size
or end argument and named copy_file_window ;)

Sascha

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

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


Re: [PATCH 1/7] libfile: introduce copy_file_2 for copying starting with offset

2019-09-12 Thread Ahmad Fatoum
Hello Uwe,

On 9/12/19 3:06 PM, Uwe Kleine-König wrote:
> Hello Ahmad,
> 
> On Thu, Sep 12, 2019 at 12:28:59PM +0200, Ahmad Fatoum wrote:
>> barebox already has a copy_file for copying files. Extend the API by a
>> copy_file_2 that takes a source offset into account.
> 
> Can you give that function a more descriptive name? Something like
> copy_file_from_offset()?

I chose copy_file_2 for consistency with the read_file function, which
had a copy renamed to read_file_2 when it gained a (max) offset parameter.

Should read_file_2 be renamed as well? 

> 
> Best regards
> Uwe
> 

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

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


Re: [PATCH 1/7] libfile: introduce copy_file_2 for copying starting with offset

2019-09-12 Thread Uwe Kleine-König
Hello Ahmad,

On Thu, Sep 12, 2019 at 12:28:59PM +0200, Ahmad Fatoum wrote:
> barebox already has a copy_file for copying files. Extend the API by a
> copy_file_2 that takes a source offset into account.

Can you give that function a more descriptive name? Something like
copy_file_from_offset()?

Best regards
Uwe

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

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


[PATCH 7/7] Documentation: boards: document layerscape support

2019-09-12 Thread Ahmad Fatoum
Some peripherals are still missing, but the main functionality to boot
an OS is already in place. Document how to use it.

Signed-off-by: Ahmad Fatoum 
---
 Documentation/boards/layerscape.rst   | 61 +++
 .../boards/layerscape/ls1046ardb.rst  | 36 +++
 .../boards/layerscape/tqmls1046a.rst  | 49 +++
 3 files changed, 146 insertions(+)
 create mode 100644 Documentation/boards/layerscape.rst
 create mode 100644 Documentation/boards/layerscape/ls1046ardb.rst
 create mode 100644 Documentation/boards/layerscape/tqmls1046a.rst

diff --git a/Documentation/boards/layerscape.rst 
b/Documentation/boards/layerscape.rst
new file mode 100644
index ..ae089539e564
--- /dev/null
+++ b/Documentation/boards/layerscape.rst
@@ -0,0 +1,61 @@
+NXP Layerscape
+==
+
+barebox has support for some of the ARM64 based Layerscape SoCs from NXP.
+
+Booting barebox
+---
+
+The Layerscape SoCs contain logic dubbed the Pre-Bootloader (PBL). This unit
+reads the boot medium and conducts basic IO multiplexing according to the RCW
+(Reset Configuration Word). The RCW then refers the PBL to the location of the
+Pre-Bootloader Instructions (PBI). These do basic device configuration and
+afterwards poke the barebox PBL into On-Chip SRAM.
+The barebox PBL then loads the complete barebox image and runs the PBL again,
+this time from SDRAM after it has been set up.
+
+For each board, a barebox image per supported boot medium is generated.
+They may differ in the RCW, PBI and endianess depending on the boot medium.
+
+Flashing barebox
+
+
+The barebox binary is expected to be located 4K bytes into the SD-Card::
+
+  dd if=images/barebox-${boardname}-sd.image of=/dev/sdX bs=512 seek=8
+
+From there on, ``barebox_update`` can be used to flash
+barebox to the QSPI NOR-Flash if required::
+
+  barebox_update -t qspi /mnt/tftp/barebox-${global.hostname}-qspi.imaag
+
+Flashing to the eMMC is possible likewise::
+
+  barebox_update -t sd /mnt/tftp/barebox-${global.hostname}-sd.imaag
+
+.. note:: Some SoCs like the LS1046A feature only a single eSDHC.
+  In such a case, using eMMC and SD-Card at the same time is not possible.
+  Boot from QSPI to flash the eMMC.
+
+Firmware Blobs
+--
+
+Network: `fsl_fman_ucode_ls1046_r1.0_106_4_18.bin 
`_.
+
+PSCI Firmware: `ppa-ls1046a.bin 
`_.
+
+Layerscape boards
+-
+
+With multi-image and device trees, it's expected to have 
``layerscape_defconfig``
+as sole defconfig for all Layerscape boards::
+
+  make ARCH=arm layerscape_defconfig
+
+Generated images will be placed under ``images/``.
+
+.. toctree::
+  :glob:
+  :maxdepth: 1
+
+  layerscape/*
diff --git a/Documentation/boards/layerscape/ls1046ardb.rst 
b/Documentation/boards/layerscape/ls1046ardb.rst
new file mode 100644
index ..323f2ca990c9
--- /dev/null
+++ b/Documentation/boards/layerscape/ls1046ardb.rst
@@ -0,0 +1,36 @@
+NXP LS1046A Reference Design Board
+==
+
+Boot DIP Switches
+-
+
+Boot source selection happens via the the bottom most DIP switch (near the 
micro-usb port)::
+
+ OFF -> ON
++-+
+  1 |  O  |
+  2 |  O  |
+  3 |  O  |
+  4 |  O  |
+  5 |  O  |
+  6 |  O  |
+  7 |  O  |  < Boot from QSPI (default)
+  8 |  O  |
++-+
+
+ OFF -> ON
++-+
+  1 |  O  |
+  2 |  O  |
+  3 |  O  |
+  4 |  O  |
+  5 |  O  |
+  6 |  O  |
+  7 |  O  |  < Boot from SDHC
+  8 |  O  |
++-+
+
+Known Issues
+
+
+System reset may not complete if the CMSIS-DAP micro-usb is connected.
diff --git a/Documentation/boards/layerscape/tqmls1046a.rst 
b/Documentation/boards/layerscape/tqmls1046a.rst
new file mode 100644
index ..55a5dff4a396
--- /dev/null
+++ b/Documentation/boards/layerscape/tqmls1046a.rst
@@ -0,0 +1,49 @@
+TQ-Group TQMLS1046A Module
+==
+
+Ethernet Ports
+--
+
+There two RGMII ports are the two closest to the RS-232 socket.
+They are ``eth2`` for the lower port and ``eth3`` for the upper port.
+
+MBLS10xxA (Base Board) Boot DIP Switches
+
+
+Boot source selection happens via the ``S5`` DIP-Switch::
+
+  +-+
+  | |
+  | | | O x |
+  | | | | x |  < SDHC (X31)
+  | O O | x |
+  | |
+  | 1 2 3 4 |
+  +-+
+
+  +-+
+  | |
+  | O | O x |
+  | | | | x |  < eMMC
+  | | O | x |
+  | |
+  | 1 2 3 4 |
+  +-+
+
+  +-+
+  | |
+  | | O O x |
+  | | | | x |  < QSPI (eSDHC controls SDHC)
+  | O | | x |
+  | |
+  | 1 2 3 4 |
+  +-+
+
+  +-+
+  | |
+  | O O O x |
+  | | | | x |  <

[PATCH 5/7] scripts: pblimage: explicitly set architecture to ARM

2019-09-12 Thread Ahmad Fatoum
architecture is statically initialized to zero, which happens to be
ARCH_ARM as it's the first enum element.
Make this a bit clearer by explicitly assigning ARM_ARM to architecture.

Signed-off-by: Ahmad Fatoum 
---
 scripts/pblimage.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/pblimage.c b/scripts/pblimage.c
index 73c0169ac1c1..235af8aa11b1 100644
--- a/scripts/pblimage.c
+++ b/scripts/pblimage.c
@@ -61,7 +61,7 @@ enum arch {
ARCH_POWERPC,
 };
 
-enum arch architecture;
+enum arch architecture = ARCH_ARM;
 static char *rcwfile;
 static char *pbifile;
 static char *outfile;
-- 
2.23.0


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


[PATCH 3/7] ARM: Layerscape: don't generate second-stage 2nd.image

2019-09-12 Thread Ahmad Fatoum
For layerscape images, barebox currently generates a second stage
barebox that lacks the RCW and PBI and as such can be bootm'd as
any other barebox ARM image. A previous commit implemented bootm
handlers for the RCW and PBI prefixed images and thus the 2nd.image
no longer serves a real purpose. Drop it.

Signed-off-by: Ahmad Fatoum 
---
 images/Makefile.layerscape | 8 ++--
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/images/Makefile.layerscape b/images/Makefile.layerscape
index d20cc6a37e03..806c09d8fbce 100644
--- a/images/Makefile.layerscape
+++ b/images/Makefile.layerscape
@@ -21,8 +21,6 @@ quiet_cmd_lspbl_spi_image = LSPBL-SPI-IMG $@
-m $($(patsubst $(obj)/%.pblb,PBL_CODE_SIZE_%,$<)) 
-p $(lspbl-pbi-tmp) -i $<
 
 pbl-$(CONFIG_MACH_LS1046ARDB) += start_ls1046ardb.pbl
-$(obj)/barebox-ls1046ardb-2nd.image: $(obj)/start_ls1046ardb.pblb
-   $(call if_changed,shipped)
 
 $(obj)/barebox-ls1046ardb-sd.image: $(obj)/start_ls1046ardb.pblb \
$(board)/ls1046ardb/ls1046ardb_rcw_sd.cfg \
@@ -40,11 +38,9 @@ $(obj)/barebox-ls1046ardb-qspi.image: 
$(obj)/start_ls1046ardb.pblb \
$(call if_changed,lspbl_spi_image)
 
 image-$(CONFIG_MACH_LS1046ARDB) += barebox-ls1046ardb-sd.image 
barebox-ls1046ardb-qspi.image \
-   barebox-ls1046ardb-emmc.image barebox-ls1046ardb-2nd.image
+   barebox-ls1046ardb-emmc.image
 
 pbl-$(CONFIG_MACH_TQMLS1046A) += start_tqmls1046a.pbl
-$(obj)/barebox-tqmls1046a-2nd.image: $(obj)/start_tqmls1046a.pblb
-   $(call if_changed,shipped)
 
 $(obj)/barebox-tqmls1046a-sd.image: $(obj)/start_tqmls1046a.pblb \
$(board)/tqmls1046a/tqmls1046a_rcw_sd__5559.cfg \
@@ -57,4 +53,4 @@ $(obj)/barebox-tqmls1046a-qspi.image: 
$(obj)/start_tqmls1046a.pblb \
$(call if_changed,lspbl_spi_image)
 
 image-$(CONFIG_MACH_TQMLS1046A) += barebox-tqmls1046a-sd.image \
-   barebox-tqmls1046a-qspi.image barebox-tqmls1046a-2nd.image
+   barebox-tqmls1046a-qspi.image
-- 
2.23.0


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


[PATCH 6/7] ARM: layerscape: tqmls1046a: disable all SGMII PHYs

2019-09-12 Thread Ahmad Fatoum
We already disable PHYs 4-7, which are currently unusable as they hang
off SGMII, which barebox' FMan driver does not yet support.

Follow suit for the SGMII eth0 and eth1 as well, so they don't
unnecessarily clutter the barebox output with

Unable to find a PHY (unknown ID?)

messages.

Signed-off-by: Ahmad Fatoum 
---
 .../arm/boards/tqmls1046a/defaultenv-tqmls1046a/nv/dev.eth0.mode | 1 +
 .../arm/boards/tqmls1046a/defaultenv-tqmls1046a/nv/dev.eth1.mode | 1 +
 2 files changed, 2 insertions(+)
 create mode 100644 
arch/arm/boards/tqmls1046a/defaultenv-tqmls1046a/nv/dev.eth0.mode
 create mode 100644 
arch/arm/boards/tqmls1046a/defaultenv-tqmls1046a/nv/dev.eth1.mode

diff --git a/arch/arm/boards/tqmls1046a/defaultenv-tqmls1046a/nv/dev.eth0.mode 
b/arch/arm/boards/tqmls1046a/defaultenv-tqmls1046a/nv/dev.eth0.mode
new file mode 100644
index ..7a68b11da8b1
--- /dev/null
+++ b/arch/arm/boards/tqmls1046a/defaultenv-tqmls1046a/nv/dev.eth0.mode
@@ -0,0 +1 @@
+disabled
diff --git a/arch/arm/boards/tqmls1046a/defaultenv-tqmls1046a/nv/dev.eth1.mode 
b/arch/arm/boards/tqmls1046a/defaultenv-tqmls1046a/nv/dev.eth1.mode
new file mode 100644
index ..7a68b11da8b1
--- /dev/null
+++ b/arch/arm/boards/tqmls1046a/defaultenv-tqmls1046a/nv/dev.eth1.mode
@@ -0,0 +1 @@
+disabled
-- 
2.23.0


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


[PATCH 4/7] filetype: support fastboot barebox_update with layerscape image

2019-09-12 Thread Ahmad Fatoum
We do not yet support USB on the Layerscape platforms, but when we do,
it's imaginable that we would want to export barebox_update targets over
Fastboot. Prepare for this by adding the layerscape images to those that
filetype_is_barebox_image returns true for.

Signed-off-by: Ahmad Fatoum 
---
 common/filetype.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/common/filetype.c b/common/filetype.c
index 825bf25ad107..4966c5e068bd 100644
--- a/common/filetype.c
+++ b/common/filetype.c
@@ -460,6 +460,8 @@ bool filetype_is_barebox_image(enum filetype ft)
case filetype_mips_barebox:
case filetype_ch_image:
case filetype_ch_image_be:
+   case filetype_layerscape_image:
+   case filetype_layerscape_qspi_image:
return true;
default:
return false;
-- 
2.23.0


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


[PATCH 2/7] ARM: Layerscape: add bootm handler for images

2019-09-12 Thread Ahmad Fatoum
The layerscape images are preceeded by a RCW and PBI, which are interpreted
by the Layerscape Hardware Pre-Bootloader and aren't executable as ARM code.
To maintain the ability to network boot them, add a bootm handler that
skips the fixed-size header.

Signed-off-by: Ahmad Fatoum 
---
 arch/arm/mach-layerscape/Makefile   |  1 +
 arch/arm/mach-layerscape/pblimage.c | 46 +
 2 files changed, 47 insertions(+)
 create mode 100644 arch/arm/mach-layerscape/pblimage.c

diff --git a/arch/arm/mach-layerscape/Makefile 
b/arch/arm/mach-layerscape/Makefile
index 8a814f944161..854a327c9125 100644
--- a/arch/arm/mach-layerscape/Makefile
+++ b/arch/arm/mach-layerscape/Makefile
@@ -5,3 +5,4 @@ obj-y += icid.o
 obj-pbl-y += boot.o
 pbl-y += xload-qspi.o xload.o
 obj-$(CONFIG_ARCH_LAYERSCAPE_PPA) += ppa.o ppa-entry.o
+obj-$(CONFIG_BOOTM) += pblimage.o
diff --git a/arch/arm/mach-layerscape/pblimage.c 
b/arch/arm/mach-layerscape/pblimage.c
new file mode 100644
index ..74a4c805bc67
--- /dev/null
+++ b/arch/arm/mach-layerscape/pblimage.c
@@ -0,0 +1,46 @@
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define BAREBOX_STAGE2_OFFSET  SZ_128K
+
+static int do_bootm_layerscape_pblimage(struct image_data *pbl_data)
+{
+   int ret;
+   char pblimage_filename[] = "/.layerscape-pbl.img";
+   struct bootm_data bb_data = {
+   .initrd_address = UIMAGE_INVALID_ADDRESS,
+   .os_address = UIMAGE_SOME_ADDRESS,
+   .os_file = pblimage_filename,
+   };
+
+   ret = copy_file_2(pbl_data->os_file, bb_data.os_file,
+ BAREBOX_STAGE2_OFFSET, 0);
+   if (ret)
+   return ret;
+
+   return bootm_boot(&bb_data);
+}
+
+static struct image_handler image_handler_layerscape_pbl_image = {
+   .name = "Layerscape image",
+   .bootm = do_bootm_layerscape_pblimage,
+   .filetype = filetype_layerscape_image,
+};
+
+static struct image_handler image_handler_layerscape_qspi_pbl_image = {
+   .name = "Layerscape QSPI image",
+   .bootm = do_bootm_layerscape_pblimage,
+   .filetype = filetype_layerscape_qspi_image,
+};
+
+static int layerscape_register_pbl_image_handler(void)
+{
+   register_image_handler(&image_handler_layerscape_pbl_image);
+   register_image_handler(&image_handler_layerscape_qspi_pbl_image);
+
+   return 0;
+}
+late_initcall(layerscape_register_pbl_image_handler);
-- 
2.23.0


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


[PATCH 1/7] libfile: introduce copy_file_2 for copying starting with offset

2019-09-12 Thread Ahmad Fatoum
barebox already has a copy_file for copying files. Extend the API by a
copy_file_2 that takes a source offset into account.

This is useful for handling SoC-specific image formats which have a
fixed-size header, as copy_file_2 can now skip that header and create a
file with the full barebox image in one go.

Signed-off-by: Ahmad Fatoum 
---
 include/libfile.h |  1 +
 lib/libfile.c | 25 +++--
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/include/libfile.h b/include/libfile.h
index f1d695187790..02269f4877e6 100644
--- a/include/libfile.h
+++ b/include/libfile.h
@@ -16,6 +16,7 @@ int write_file(const char *filename, const void *buf, size_t 
size);
 int write_file_flash(const char *filename, const void *buf, size_t size);
 
 int copy_file(const char *src, const char *dst, int verbose);
+int copy_file_2(const char *src, const char *dst, loff_t pos, int verbose);
 
 int copy_recursive(const char *src, const char *dst);
 
diff --git a/lib/libfile.c b/lib/libfile.c
index b42753c2b5ea..4bc980816a67 100644
--- a/lib/libfile.c
+++ b/lib/libfile.c
@@ -318,14 +318,15 @@ out_close:
 EXPORT_SYMBOL(write_file_flash);
 
 /**
- * copy_file - Copy a file
+ * copy_file_2 - Copy a file
  * @src:   The source filename
  * @dst:   The destination filename
+ * @pos:   source file position to start reading at
  * @verbose:   if true, show a progression bar
  *
  * Return: 0 for success or negative error code
  */
-int copy_file(const char *src, const char *dst, int verbose)
+int copy_file_2(const char *src, const char *dst, loff_t pos, int verbose)
 {
char *rw_buf = NULL;
int srcfd = 0, dstfd = 0;
@@ -337,11 +338,9 @@ int copy_file(const char *src, const char *dst, int 
verbose)
 
rw_buf = xmalloc(RW_BUF_SIZE);
 
-   srcfd = open(src, O_RDONLY);
-   if (srcfd < 0) {
-   printf("could not open %s: %s\n", src, errno_str());
+   srcfd = open_and_lseek(src, O_RDONLY, pos);
+   if (srcfd < 0)
goto out;
-   }
 
mode = O_WRONLY | O_CREAT;
 
@@ -403,6 +402,20 @@ out:
 
return ret ?: err1;
 }
+EXPORT_SYMBOL(copy_file_2);
+
+/**
+ * copy_file - Copy a file
+ * @src:   The source filename
+ * @dst:   The destination filename
+ * @verbose:   if true, show a progression bar
+ *
+ * Return: 0 for success or negative error code
+ */
+int copy_file(const char *src, const char *dst, int verbose)
+{
+   return copy_file_2(src, dst, 0, verbose);
+}
 EXPORT_SYMBOL(copy_file);
 
 int copy_recursive(const char *src, const char *dst)
-- 
2.23.0


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


[PATCH] mtd: nand: Fix retrieving nand_chip from mtd_info

2019-09-12 Thread Sascha Hauer
With 76b6f74c53 we begin embedding a struct mtd_info into struct
nand_chip. With this mtd_to_nand() must be changed accordingly.

Fixes: 76b6f74c53 ("mtd: nand: Embed struct mtd_info into struct nand_chip")
Signed-off-by: Sascha Hauer 
---
 include/linux/mtd/nand.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h
index 762f9c4f2a..401f630570 100644
--- a/include/linux/mtd/nand.h
+++ b/include/linux/mtd/nand.h
@@ -803,7 +803,7 @@ const struct nand_sdr_timings 
*onfi_async_timing_mode_to_sdr_timings(int mode);
 
 static inline struct nand_chip *mtd_to_nand(struct mtd_info *mtd)
 {
-   return mtd->priv;
+   return container_of(mtd, struct nand_chip, mtd);
 }
 
 #endif /* __LINUX_MTD_NAND_H */
-- 
2.23.0


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


[PATCH] clk: i.MX6qp: Fix location of the enfc_sel mux

2019-09-12 Thread Sascha Hauer
On the i.MX6qp the enfc_sel mux is at bits 15-17, not on 16-17. Fix
this. During clock tree initialization we reparented the enfc_sel to:

clk_set_parent(clks[IMX6QDL_CLK_ENFC_SEL], 
clks[IMX6QDL_CLK_PLL2_PFD2_396M]);

This resulted in a register setting 0b110 for the enfc_sel mux which is
reserved. Apparently this reserved setting resulted in the enfc clock
being driven from pll3_pfd3_454m. This means our enfc clock was the
factor 454/396 too high.

With b534f79112f0 ("clk: imx6: Fix procedure to switch the parent of
LDB_DI_CLK") we happened to disable pll3_pfd3_454m during init, so with
this commit NAND stopped working entirely on i.MX6qp.

Both issues are fixed with this patch

Fixes: b534f79112f0 ("clk: imx6: Fix procedure to switch the parent of 
LDB_DI_CLK")
Fixes: 92fd61d12723 ("clk: i.MX6: Fix enfc_sel for i.MX6dqp")

Signed-off-by: Sascha Hauer 
---
 drivers/clk/imx/clk-imx6.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/clk/imx/clk-imx6.c b/drivers/clk/imx/clk-imx6.c
index c47281b16e..ed29e8c271 100644
--- a/drivers/clk/imx/clk-imx6.c
+++ b/drivers/clk/imx/clk-imx6.c
@@ -708,7 +708,7 @@ static int imx6_ccm_probe(struct device_d *dev)
clks[IMX6QDL_CLK_USDHC3_SEL]   = imx_clk_mux("usdhc3_sel",   
base + 0x1c, 18, 1, usdhc_sels,ARRAY_SIZE(usdhc_sels));
clks[IMX6QDL_CLK_USDHC4_SEL]   = imx_clk_mux("usdhc4_sel",   
base + 0x1c, 19, 1, usdhc_sels,ARRAY_SIZE(usdhc_sels));
if (cpu_mx6_is_plus())
-   clks[IMX6QDL_CLK_ENFC_SEL] = imx_clk_mux("enfc_sel",
 base + 0x2c, 16, 2, enfc_sels_plus,ARRAY_SIZE(enfc_sels_plus));
+   clks[IMX6QDL_CLK_ENFC_SEL] = imx_clk_mux("enfc_sel",
 base + 0x2c, 15, 3, enfc_sels_plus,ARRAY_SIZE(enfc_sels_plus));
else
clks[IMX6QDL_CLK_ENFC_SEL] = imx_clk_mux("enfc_sel",
 base + 0x2c, 16, 2, enfc_sels, ARRAY_SIZE(enfc_sels));
clks[IMX6QDL_CLK_EIM_SEL]  = imx_clk_mux("eim_sel",  
base + 0x1c, 27, 2, eim_sels,  ARRAY_SIZE(eim_sels));
-- 
2.23.0


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


[PATCH 2/3] of: add of_diff()

2019-09-12 Thread Sascha Hauer
of_diff compares two device trees against each other and prints a
diff-like result.

Signed-off-by: Sascha Hauer 
---
 drivers/of/base.c | 141 ++
 include/of.h  |   1 +
 2 files changed, 132 insertions(+), 10 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 22077fa397..63e0879f06 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -1776,24 +1776,21 @@ struct device_node *of_get_child_by_name(const struct 
device_node *node,
 }
 EXPORT_SYMBOL(of_get_child_by_name);
 
-void of_print_nodes(struct device_node *node, int indent)
+static void __of_print_nodes(struct device_node *node, int indent, const char 
*prefix)
 {
struct device_node *n;
struct property *p;
-   int i;
 
if (!node)
return;
 
-   for (i = 0; i < indent; i++)
-   printf("\t");
+   if (!prefix)
+   prefix = "";
 
-   printf("%s%s\n", node->name, node->name ? " {" : "{");
+   printf("%s%*s%s%s\n", prefix, indent * 8, "", node->name, node->name ? 
" {" : "{");
 
list_for_each_entry(p, &node->properties, list) {
-   for (i = 0; i < indent + 1; i++)
-   printf("\t");
-   printf("%s", p->name);
+   printf("%s%*s%s", prefix, (indent + 1) * 8, "", p->name);
if (p->length) {
printf(" = ");
of_print_property(of_property_get_value(p), p->length);
@@ -1802,12 +1799,136 @@ void of_print_nodes(struct device_node *node, int 
indent)
}
 
list_for_each_entry(n, &node->children, parent_list) {
-   of_print_nodes(n, indent + 1);
+   __of_print_nodes(n, indent + 1, prefix);
+   }
+
+   printf("%s%*s};\n", prefix, indent * 8, "");
+}
+
+void of_print_nodes(struct device_node *node, int indent)
+{
+   __of_print_nodes(node, indent, NULL);
+}
+
+static void __of_print_property(struct property *p, int indent)
+{
+   int i;
+
+   for (i = 0; i < indent; i++)
+   printf("\t");
+
+   printf("%s", p->name);
+   if (p->length) {
+   printf(" = ");
+   of_print_property(of_property_get_value(p), p->length);
}
+   printf(";\n");
+}
+
+static int __of_print_parents(struct device_node *node)
+{
+   int indent, i;
+
+   if (!node->parent)
+   return 0;
+
+   indent = __of_print_parents(node->parent);
 
for (i = 0; i < indent; i++)
printf("\t");
-   printf("};\n");
+
+   printf("%s {\n", node->name);
+
+   return indent + 1;
+}
+
+static void of_print_parents(struct device_node *node, int *printed)
+{
+   if (*printed)
+   return;
+
+   __of_print_parents(node);
+
+   *printed = 1;
+}
+
+static void of_print_close(struct device_node *node, int *printed)
+{
+   int depth = 0, i, j;
+
+   if (!*printed)
+   return;
+
+   while ((node = node->parent))
+   depth++;
+
+   for (i = depth; i > 0; i--) {
+   for (j = 0; j + 1 < i; j++)
+   printf("\t");
+   printf("};\n");
+   }
+}
+
+/**
+ * of_diff - compare two device trees against each other
+ * @a: The first device tree
+ * @b: The second device tree
+ * @indent: The initial indentation level when printing
+ *
+ * This function compares two device trees against each other and prints
+ * a diff-like result.
+ */
+void of_diff(struct device_node *a, struct device_node *b, int indent)
+{
+   struct property *ap, *bp;
+   struct device_node *ca, *cb;
+   int printed = 0;
+
+   list_for_each_entry(ap, &a->properties, list) {
+   bp = of_find_property(b, ap->name, NULL);
+   if (!bp) {
+   of_print_parents(a, &printed);
+   printf("- ");
+   __of_print_property(ap, indent);
+   continue;
+   }
+
+   if (ap->length != bp->length || 
memcmp(of_property_get_value(ap), of_property_get_value(bp), bp->length)) {
+   of_print_parents(a, &printed);
+   printf("- ");
+   __of_print_property(ap, indent);
+   printf("+ ");
+   __of_print_property(bp, indent);
+   }
+   }
+
+   list_for_each_entry(bp, &b->properties, list) {
+   ap = of_find_property(a, bp->name, NULL);
+   if (!ap) {
+   of_print_parents(a, &printed);
+   printf("+ ");
+   __of_print_property(bp, indent);
+   }
+   }
+
+   for_each_child_of_node(a, ca) {
+   cb = of_get_child_by_name(b, ca->name);
+   if (cb) {
+   of_diff(ca, cb, indent + 1);
+   } else {
+   of_print_parents(a, 

[PATCH 1/3] of: Fix memory hole in of_find_node_by_reproducible_name()

2019-09-12 Thread Sascha Hauer
of_get_reproducible_name() returns an allocated string, so we must free
it.

Signed-off-by: Sascha Hauer 
---
 drivers/of/base.c | 12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 838f530f85..22077fa397 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -2306,9 +2306,17 @@ struct device_node 
*of_find_node_by_reproducible_name(struct device_node *from,
 {
struct device_node *np;
 
-   of_tree_for_each_node_from(np, from)
-   if (!of_node_cmp(of_get_reproducible_name(np), name))
+   of_tree_for_each_node_from(np, from) {
+   char *rep = of_get_reproducible_name(np);
+   int res;
+
+   res = of_node_cmp(rep, name);
+
+   free(rep);
+
+   if (!res)
return np;
+   }
return NULL;
 }
 
-- 
2.23.0


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


[PATCH 3/3] add of_diff command

2019-09-12 Thread Sascha Hauer
The of_diff command compares two device trees against each other
and prints a diff-like result. This can be handy to find out the
differences between the barebox live tree and the one we start the
kernel with. Another usecase would be to examine the changes our
of_fixup process introduces (of_diff - +)

Signed-off-by: Sascha Hauer 
---
 commands/Kconfig   |   7 +++
 commands/Makefile  |   1 +
 commands/of_diff.c | 110 +
 3 files changed, 118 insertions(+)
 create mode 100644 commands/of_diff.c

diff --git a/commands/Kconfig b/commands/Kconfig
index e03110fd46..24fd47b5cd 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -2012,6 +2012,13 @@ config CMD_LSMOD
help
  List loaded barebox modules.
 
+config CMD_OF_DIFF
+   tristate
+   select OFTREE
+   prompt "of_diff"
+   help
+ Compare two device tree files against each other.
+
 config CMD_OF_DUMP
tristate
select OFTREE
diff --git a/commands/Makefile b/commands/Makefile
index 5cd35b78a7..a619ee5765 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -73,6 +73,7 @@ obj-$(CONFIG_CMD_LED_TRIGGER) += trigger.o
 obj-$(CONFIG_CMD_USB)  += usb.o
 obj-$(CONFIG_CMD_TIME) += time.o
 obj-$(CONFIG_CMD_OFTREE)   += oftree.o
+obj-$(CONFIG_CMD_OF_DIFF)  += of_diff.o
 obj-$(CONFIG_CMD_OF_PROPERTY)  += of_property.o
 obj-$(CONFIG_CMD_OF_NODE)  += of_node.o
 obj-$(CONFIG_CMD_OF_DUMP)  += of_dump.o
diff --git a/commands/of_diff.c b/commands/of_diff.c
new file mode 100644
index 00..4ea801729f
--- /dev/null
+++ b/commands/of_diff.c
@@ -0,0 +1,110 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * of_diff.c - compare device tree files
+ *
+ * Copyright (c) 2019 Sascha Hauer , Pengutronix
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static struct device_node *get_tree(const char *filename, struct device_node 
*root)
+{
+   struct device_node *node;
+   void *fdt;
+   size_t size;
+   int ret;
+
+   if (!strcmp(filename, "-")) {
+   node = of_get_root_node();
+   if (!node)
+   return ERR_PTR(-ENOENT);
+
+   return of_copy_node(NULL, node);
+   }
+
+   if (!strcmp(filename, "+")) {
+   node = of_get_root_node();
+   if (!node)
+   return ERR_PTR(-ENOENT);
+
+   node = of_copy_node(NULL, root);
+
+   of_fix_tree(node);
+
+   return node;
+   }
+
+   ret = read_file_2(filename, &size, &fdt, FILESIZE_MAX);
+   if (ret)
+   return ERR_PTR(ret);
+
+   node = of_unflatten_dtb(fdt);
+
+   free(fdt);
+
+   return node;
+}
+
+// of_diff - /mnt/tftp/sha-oftree-phyCORE-i.MX6
+
+static int do_of_diff(int argc, char *argv[])
+{
+   int ret = 0;
+   struct device_node *a, *b, *root;
+
+   if (argc < 3)
+   return COMMAND_ERROR_USAGE;
+
+   root = of_get_root_node();
+   a = get_tree(argv[1], root);
+   b = get_tree(argv[2], root);
+
+   if (IS_ERR(a)) {
+   printf("Cannot read %s: %s\n", argv[1], strerrorp(a));
+   ret = COMMAND_ERROR;
+   a = NULL;
+   goto out;
+   }
+
+   if (IS_ERR(b)) {
+   printf("Cannot read %s: %s\n", argv[2], strerrorp(b));
+   ret = COMMAND_ERROR;
+   b = NULL;
+   goto out;
+   }
+
+   of_diff(a, b, 0);
+
+   ret = 0;
+out:
+   if (a && a != root)
+   of_delete_node(a);
+   if (b && b != root)
+   of_delete_node(b);
+
+   return ret;
+}
+
+BAREBOX_CMD_HELP_START(of_diff)
+BAREBOX_CMD_HELP_TEXT("This command prints a diff between two given device 
trees.")
+BAREBOX_CMD_HELP_TEXT("The device trees are given as dtb files or:")
+BAREBOX_CMD_HELP_TEXT("'-' to compare against the barebox live tree, or")
+BAREBOX_CMD_HELP_TEXT("'+' to compare against the fixed barebox live tree")
+BAREBOX_CMD_HELP_END
+
+BAREBOX_CMD_START(of_diff)
+   .cmd= do_of_diff,
+   BAREBOX_CMD_DESC("diff device trees")
+   BAREBOX_CMD_OPTS(" ")
+   BAREBOX_CMD_GROUP(CMD_GRP_MISC)
+   BAREBOX_CMD_HELP(cmd_of_diff_help)
+BAREBOX_CMD_END
-- 
2.23.0


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


Re: [PATCH] bootm: release tee_res

2019-09-12 Thread Rouven Czerwinski
On Thu, 2019-09-12 at 09:13 +0200, Sascha Hauer wrote:
> When a tee_res has been acquired it must be released when bootm
> returns
> (for dryrun)
> 
> Signed-off-by: Sascha Hauer 
> ---
>  common/bootm.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/common/bootm.c b/common/bootm.c
> index d7232f6afa..b50b76ed6f 100644
> --- a/common/bootm.c
> +++ b/common/bootm.c
> @@ -682,6 +682,8 @@ err_out:
>   release_sdram_region(data->initrd_res);
>   if (data->oftree_res)
>   release_sdram_region(data->oftree_res);
> + if (data->tee_res)
> + release_sdram_region(data->tee_res);
>   if (data->initrd && data->initrd != data->os)
>   uimage_close(data->initrd);
>   if (data->os)

Reviewed-by: Rouven Czerwinski 

Regards,
Rouven Czerwinski


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


[PATCH] bootm: release tee_res

2019-09-12 Thread Sascha Hauer
When a tee_res has been acquired it must be released when bootm returns
(for dryrun)

Signed-off-by: Sascha Hauer 
---
 common/bootm.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/common/bootm.c b/common/bootm.c
index d7232f6afa..b50b76ed6f 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -682,6 +682,8 @@ err_out:
release_sdram_region(data->initrd_res);
if (data->oftree_res)
release_sdram_region(data->oftree_res);
+   if (data->tee_res)
+   release_sdram_region(data->tee_res);
if (data->initrd && data->initrd != data->os)
uimage_close(data->initrd);
if (data->os)
-- 
2.23.0


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


Re: [PATCH v2 0/2] ARM: imx6: add new MarsBoard support

2019-09-12 Thread Sascha Hauer
On Thu, Sep 12, 2019 at 08:54:10AM +0200, Ahmad Fatoum wrote:
> I've picked up v1 of the patch from here:
> https://barebox.infradead.narkive.com/mn9ZpGu6/patch-2-3-marsboard-add-new-board
> 
> and worked in the review feedback from back then.
> 
> v1 -> v2:
>  - rebased on current upstream/next
>  - removed seperate defconfig and added board to imx_v7_defconfig (Lucas)
>  - added boot mode documentation
>  - removed redundant VPU/IPU AXI configurations from DCD-Table (Sascha)
>  - removed setting console in linux bootargs (Sascha)
>  - have board-specific environment use bbenv-y in Makefile (Sascha)
>  - added barebox device tree that includes kernel device tree
>  - used imx6_uart_setup_ll and imx_setup_pad for debug_ll UART
>  - used compressed DTB
>  - used imx6q_barebox_entry instead of hardcoding RAM size
> 
> Ahmad Fatoum (2):
>   ARM: imx6: add Embest MarSBoard support
>   ARM: imx_v7_defconfig: enable Embdest MarS board
> 

Applied, thanks

Sascha

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

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