[linux-sunxi] Re: [PATCH 05/17] SPL: FIT: allow loading multiple images

2017-03-26 Thread André Przywara
On 08/03/17 21:00, Simon Glass wrote:
> Hi Andre,
> 
> On 28 February 2017 at 19:25, Andre Przywara  wrote:
>> So far we were not using the FIT image format to its full potential:
>> The SPL FIT loader was just loading the first image from the /images
>> node plus one of the listed DTBs.
>> Now with the refactored loader code it's easy to load an arbitrary
>> number of images in addition to the two mentioned above.
>> As described in the FIT image source file format description, iterate
>> over all images listed at the "loadables" property in the configuration
>> node and load every image at its desired location.
>> This allows to load any kind of images:
>> - firmware images to execute before U-Boot proper (for instance
>>   ARM Trusted Firmware (ATF))
>> - firmware images for management processors (SCP, arisc, ...)
>> - firmware images for devices like WiFi controllers
>> - bit files for FPGAs
>> - additional configuration data
>> - kernels and/or ramdisks
>> The actual usage of this feature would be platform and/or board specific.
>>
>> Signed-off-by: Andre Przywara 
>> ---
>>  common/spl/spl_fit.c | 32 
>>  1 file changed, 28 insertions(+), 4 deletions(-)
>>
>> diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c
>> index ad5ba15..5583e09 100644
>> --- a/common/spl/spl_fit.c
>> +++ b/common/spl/spl_fit.c
>> @@ -178,10 +178,7 @@ static int spl_load_fit_image(struct spl_load_info 
>> *info, ulong sector,
>> if (image_info) {
>> image_info->load_addr = load_addr;
>> image_info->size = length;
>> -   if (entry == -1UL)
>> -   image_info->entry_point = load_addr;
>> -   else
>> -   image_info->entry_point = entry;
>> +   image_info->entry_point = entry;
> 
> Need to update function comment to indicate that it can put -1 in here.
> 
>> }
>>
>> return 0;
>> @@ -196,6 +193,7 @@ int spl_load_simple_fit(struct spl_image_info *spl_image,
>> struct spl_image_info image_info;
>> int node, images;
>> int base_offset, align_len = ARCH_DMA_MINALIGN - 1;
>> +   int index = 0;
>>
>> /*
>>  * Figure out where the external images start. This is the base for 
>> the
>> @@ -240,6 +238,11 @@ int spl_load_simple_fit(struct spl_image_info 
>> *spl_image,
>> if (node < 0) {
>> debug("could not find firmware image, trying 
>> loadables...\n");
>> node = spl_fit_get_image_node(fit, images, "loadables", 0);
>> +   /*
>> +* If we pick the U-Boot image from "loadables", start at
>> +* the second image when later loading additional images.
>> +*/
>> +   index = 1;
>> }
>> if (node < 0) {
>> debug("%s: Cannot find u-boot image node: %d\n",
>> @@ -265,5 +268,26 @@ int spl_load_simple_fit(struct spl_image_info 
>> *spl_image,
>> image_info.load_addr = spl_image->load_addr + spl_image->size;
>> spl_load_fit_image(info, sector, fit, base_offset, node, 
>> _info);
>>
>> +   /* Now check if there are more images for us to load */
>> +   for (; ; index++) {
>> +   node = spl_fit_get_image_node(fit, images, "loadables", 
>> index);
>> +   if (node < 0)
>> +   break;
>> +
>> +   spl_load_fit_image(info, sector, fit, base_offset, node,
>> +  _info);
> 
> Error check?
> 
>> +
>> +   /*
>> +* If the "firmware" image did not provide an entry point,
>> +* use the first valid entry point from the loadables.
>> +*/
>> +   if (spl_image->entry_point == -1UL &&
>> +   image_info.entry_point != -1UL)
>> +   spl_image->entry_point = image_info.entry_point;
>> +   }
>> +
>> +   if (spl_image->entry_point == -1UL || spl_image->entry_point == 0)
> 
> Why does 0 mean there is no entry point? I suppose that is safe, but
> would anyone use this?

So this is due to U-Boot's own Makefile, which sets
CONFIG_SYS_UBOOT_START to 0 if it isn't already defined. This then gets
passed on to mkimage -f auto as the -e argument.
So today's FIT images have 0 as an entry point - a least on sunxi.  As I
wanted to retain compatibility with that, I added this check.
Maybe sunxi (and other platforms?) should explicitly define the entry
point to avoid it being set to 0, or we should default to the load
address as the fallback in absence of such an explicit definition.

In any case I wanted to keep existing u-boot.img files booting, so I
added this safe guard here to do "the right thing (tm)".

I added a comment there to point this out.

Cheers,
Andre.

>> +   spl_image->entry_point = spl_image->load_addr;
>> +
>> return 0;
>>  }
>> --
>> 

[linux-sunxi] Re: [PATCH 16/17] sunxi: Store the device tree name in the SPL header

2017-03-26 Thread André Przywara
On 08/03/17 21:01, Simon Glass wrote:

Hi Simon,

many thanks for the review, finally found some time to look at this.
I have finished the needed rework (including documentation) and will
post something after some testing and some sleep ;-)

> On 28 February 2017 at 19:25, Andre Przywara  wrote:
>> From: Siarhei Siamashka 
>>
>> This patch updates the mksunxiboot tool to optionally add
>> the default device tree name string to the SPL header. This
>> information can be used by the firmware upgrade tools to
>> protect users from harming themselves by trying to upgrade
>> to an incompatible bootloader.
>>
>> The primary use case here is a non-removable bootable media
>> (such as NAND, eMMC or SPI flash), which already may have
>> a properly working, but a little bit outdated bootloader
>> installed. For example, the user may download or build a
>> new U-Boot image for "Cubieboard", and then attemept to
>> install it on a "Cubieboard2" hardware by mistake as a
>> replacement for the already existing bootloader. If this
>> happens, the flash programming tool can identify this
>> problem and warn the user.
>>
>> The size of the SPL header is also increased from 64 bytes
>> to 96 bytes to provide enough space for the device tree name
>> string.
>> [Andre: split patch to remove OF_LIST hash feature]
>>
>> Signed-off-by: Siarhei Siamashka 
>> Signed-off-by: Andre Przywara 
>> ---
>>  arch/arm/include/asm/arch-sunxi/spl.h | 19 +++---
>>  include/configs/sunxi-common.h|  8 +++---
>>  scripts/Makefile.spl  |  3 ++-
>>  tools/mksunxiboot.c   | 49 
>> ---
>>  4 files changed, 67 insertions(+), 12 deletions(-)
> 
> Can this code move into mkimage as a new image type? This is what
> rockchip does. It feels like this tool should be subsumed. If that
> doesn't work, perhaps binman?

Interesting, I wasn't aware that mkimage can do more than legacy and
FIT. Indeed that sounds useful, especially as mkimage seems to be
packaged separately and is available in some distros.

So I hacked something up, but that needs some more love.
I am tempted to drop (or split) this patch from this series for now,
since this extension here and the move to mkimage could be treated
separately from the SPL FIT code.

Cheers,
Andre.

-- 
You received this message because you are subscribed to the Google Groups 
"linux-sunxi" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to linux-sunxi+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[linux-sunxi] [PATCH v2 5/6] dt-bindings: List devicetree binding for the CCU of Allwinner A10

2017-03-26 Thread Priit Laes
Allwinner A10 is now driven by sunxi-ng CCU driver.

Add devicetree binding for it.

Signed-off-by: Priit Laes 
---
 Documentation/devicetree/bindings/clock/sunxi-ccu.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/clock/sunxi-ccu.txt 
b/Documentation/devicetree/bindings/clock/sunxi-ccu.txt
index de90988..db49cbc 100644
--- a/Documentation/devicetree/bindings/clock/sunxi-ccu.txt
+++ b/Documentation/devicetree/bindings/clock/sunxi-ccu.txt
@@ -3,6 +3,7 @@ Allwinner Clock Control Unit Binding
 
 Required properties :
 - compatible: must contain one of the following compatibles:
+   - "allwinner,sun4i-a10-ccu"
- "allwinner,sun6i-a31-ccu"
- "allwinner,sun7i-a20-ccu"
- "allwinner,sun8i-a23-ccu"
-- 
git-series 0.9.1

-- 
You received this message because you are subscribed to the Google Groups 
"linux-sunxi" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to linux-sunxi+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[linux-sunxi] [PATCH v2 4/6] dt-bindings: List devicetree binding for the CCU of Allwinner A20

2017-03-26 Thread Priit Laes
Allwinner A20 is now driven by sunxi-ng CCU driver.

Add devicetree binding for it.

Acked-by: Rob Herring 
Signed-off-by: Priit Laes 
---
 Documentation/devicetree/bindings/clock/sunxi-ccu.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/clock/sunxi-ccu.txt 
b/Documentation/devicetree/bindings/clock/sunxi-ccu.txt
index 68512aa..de90988 100644
--- a/Documentation/devicetree/bindings/clock/sunxi-ccu.txt
+++ b/Documentation/devicetree/bindings/clock/sunxi-ccu.txt
@@ -4,6 +4,7 @@ Allwinner Clock Control Unit Binding
 Required properties :
 - compatible: must contain one of the following compatibles:
- "allwinner,sun6i-a31-ccu"
+   - "allwinner,sun7i-a20-ccu"
- "allwinner,sun8i-a23-ccu"
- "allwinner,sun8i-a33-ccu"
- "allwinner,sun8i-h3-ccu"
-- 
git-series 0.9.1

-- 
You received this message because you are subscribed to the Google Groups 
"linux-sunxi" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to linux-sunxi+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[linux-sunxi] [PATCH v2 1/6] clk: sunxi-ng: Add sun4i/sun7i CCU driver

2017-03-26 Thread Priit Laes
Introduce a clock controller driver for sun4i A10 and sun7i A20
series SoCs.

Signed-off-by: Priit Laes 
---
 drivers/clk/sunxi-ng/Kconfig  |   13 +-
 drivers/clk/sunxi-ng/Makefile |1 +-
 drivers/clk/sunxi-ng/ccu-sunxi-a10-a20.c  | 1532 ++-
 drivers/clk/sunxi-ng/ccu-sunxi-a10-a20.h  |   59 +-
 include/dt-bindings/clock/sunxi-a10-a20-ccu.h |  208 ++-
 include/dt-bindings/reset/sunxi-a10-a20-ccu.h |   66 +-
 6 files changed, 1879 insertions(+)
 create mode 100644 drivers/clk/sunxi-ng/ccu-sunxi-a10-a20.c
 create mode 100644 drivers/clk/sunxi-ng/ccu-sunxi-a10-a20.h
 create mode 100644 include/dt-bindings/clock/sunxi-a10-a20-ccu.h
 create mode 100644 include/dt-bindings/reset/sunxi-a10-a20-ccu.h

diff --git a/drivers/clk/sunxi-ng/Kconfig b/drivers/clk/sunxi-ng/Kconfig
index 213cf64..abed614 100644
--- a/drivers/clk/sunxi-ng/Kconfig
+++ b/drivers/clk/sunxi-ng/Kconfig
@@ -65,6 +65,19 @@ config SUN50I_A64_CCU
default ARM64 && ARCH_SUNXI
depends on (ARM64 && ARCH_SUNXI) || COMPILE_TEST
 
+config SUNXI_A10_A20_CCU
+   bool "Support for the Allwinner A10/A20 CCU"
+   select SUNXI_CCU_DIV
+   select SUNXI_CCU_MULT
+   select SUNXI_CCU_NK
+   select SUNXI_CCU_NKM
+   select SUNXI_CCU_NM
+   select SUNXI_CCU_MP
+   select SUNXI_CCU_PHASE
+   default MACH_SUN4I
+   default MACH_SUN7I
+   depends on MACH_SUN4I || MACH_SUN7I || COMPILE_TEST
+
 config SUN5I_CCU
bool "Support for the Allwinner sun5i family CCM"
select SUNXI_CCU_DIV
diff --git a/drivers/clk/sunxi-ng/Makefile b/drivers/clk/sunxi-ng/Makefile
index 6feaac0..90bab0e 100644
--- a/drivers/clk/sunxi-ng/Makefile
+++ b/drivers/clk/sunxi-ng/Makefile
@@ -21,6 +21,7 @@ obj-$(CONFIG_SUNXI_CCU_MP)+= ccu_mp.o
 obj-$(CONFIG_SUN50I_A64_CCU)   += ccu-sun50i-a64.o
 obj-$(CONFIG_SUN5I_CCU)+= ccu-sun5i.o
 obj-$(CONFIG_SUN6I_A31_CCU)+= ccu-sun6i-a31.o
+obj-$(CONFIG_SUNXI_A10_A20_CCU)+= ccu-sunxi-a10-a20.o
 obj-$(CONFIG_SUN8I_A23_CCU)+= ccu-sun8i-a23.o
 obj-$(CONFIG_SUN8I_A33_CCU)+= ccu-sun8i-a33.o
 obj-$(CONFIG_SUN8I_H3_CCU) += ccu-sun8i-h3.o
diff --git a/drivers/clk/sunxi-ng/ccu-sunxi-a10-a20.c 
b/drivers/clk/sunxi-ng/ccu-sunxi-a10-a20.c
new file mode 100644
index 000..1884f5f
--- /dev/null
+++ b/drivers/clk/sunxi-ng/ccu-sunxi-a10-a20.c
@@ -0,0 +1,1532 @@
+/*
+ * Copyright (c) 2017 Priit Laes. All rights reserved.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+#include 
+
+#include "ccu_common.h"
+#include "ccu_reset.h"
+
+#include "ccu_div.h"
+#include "ccu_gate.h"
+#include "ccu_mp.h"
+#include "ccu_mult.h"
+#include "ccu_nk.h"
+#include "ccu_nkm.h"
+#include "ccu_nkmp.h"
+#include "ccu_nm.h"
+#include "ccu_phase.h"
+
+#include "ccu-sunxi-a10-a20.h"
+
+static struct ccu_nkmp pll_core_clk = {
+   .enable = BIT(31),
+   .n  = _SUNXI_CCU_MULT_OFFSET(8, 5, 0),
+   .k  = _SUNXI_CCU_MULT(4, 2),
+   .m  = _SUNXI_CCU_DIV(0, 2),
+   .p  = _SUNXI_CCU_DIV(16, 2),
+   .common = {
+   .reg= 0x000,
+   .hw.init= CLK_HW_INIT("pll-core",
+ "hosc",
+ _nkmp_ops,
+ 0),
+   },
+};
+
+/*
+ * The Audio PLL is supposed to have 4 outputs: 3 fixed factors from
+ * the base (2x, 4x and 8x), and one variable divider (the one true
+ * pll audio).
+ *
+ * We don't have any need for the variable divider for now, so we just
+ * hardcode it to match with the clock names.
+ */
+#define SUN4I_PLL_AUDIO_REG0x008
+static struct ccu_nm pll_audio_base_clk = {
+   .enable = BIT(31),
+   .n  = _SUNXI_CCU_MULT_OFFSET(8, 7, 0),
+   .m  = _SUNXI_CCU_DIV_OFFSET(0, 5, 0),
+   .common = {
+   .reg= 0x008,
+   .hw.init= CLK_HW_INIT("pll-audio-base",
+ "hosc",
+ _nm_ops,
+ 0),
+   },
+
+};
+
+static struct ccu_mult pll_video0_clk = {
+   .enable = BIT(31),
+   .mult   = _SUNXI_CCU_MULT_OFFSET_MIN_MAX(0, 7, 0, 9, 127),
+   .frac   = _SUNXI_CCU_FRAC(BIT(15), BIT(14),
+ 27000, 29700),
+   .common = {
+  

[linux-sunxi] [PATCH v2 2/6] ARM: sun7i: Convert to CCU

2017-03-26 Thread Priit Laes
Convert sun7i-a20.dtsi to new CCU driver.

Signed-off-by: Priit Laes 
---
 arch/arm/boot/dts/sun7i-a20.dtsi | 717 +++-
 1 file changed, 85 insertions(+), 632 deletions(-)

diff --git a/arch/arm/boot/dts/sun7i-a20.dtsi b/arch/arm/boot/dts/sun7i-a20.dtsi
index 2db97fc..9521194 100644
--- a/arch/arm/boot/dts/sun7i-a20.dtsi
+++ b/arch/arm/boot/dts/sun7i-a20.dtsi
@@ -47,7 +47,8 @@
 #include 
 #include 
 
-#include 
+#include 
+#include 
 #include 
 #include 
 
@@ -67,9 +68,9 @@
compatible = "allwinner,simple-framebuffer",
 "simple-framebuffer";
allwinner,pipeline = "de_be0-lcd0-hdmi";
-   clocks = <_gates 36>, <_gates 43>,
-<_gates 44>, <_be0_clk>,
-<_ch1_clk>, <_gates 26>;
+   clocks = < CLK_AHB_LCD0>, < CLK_AHB_HDMI1>,
+< CLK_AHB_DE_BE0>, < CLK_DE_BE0>,
+< CLK_TCON0_CH1>, < CLK_DRAM_DE_BE0>;
status = "disabled";
};
 
@@ -77,9 +78,9 @@
compatible = "allwinner,simple-framebuffer",
 "simple-framebuffer";
allwinner,pipeline = "de_be0-lcd0";
-   clocks = <_gates 36>, <_gates 44>,
-<_be0_clk>, <_ch0_clk>,
-<_gates 26>;
+   clocks = < CLK_AHB_LCD0>, < CLK_AHB_DE_BE0>,
+< CLK_DE_BE0>, < CLK_TCON0_CH0>,
+< CLK_DRAM_DE_BE0>;
status = "disabled";
};
 
@@ -87,10 +88,10 @@
compatible = "allwinner,simple-framebuffer",
 "simple-framebuffer";
allwinner,pipeline = "de_be0-lcd0-tve0";
-   clocks = <_gates 34>, <_gates 36>,
-<_gates 44>,
-<_be0_clk>, <_ch1_clk>,
-<_gates 5>, <_gates 26>;
+   clocks = < CLK_AHB_TVE0>, < CLK_AHB_LCD0>,
+< CLK_AHB_DE_BE0>,
+< CLK_DE_BE0>, < CLK_TCON0_CH1>,
+< CLK_DRAM_TVE0>, < CLK_DRAM_DE_BE0>;
status = "disabled";
};
};
@@ -103,7 +104,7 @@
compatible = "arm,cortex-a7";
device_type = "cpu";
reg = <0>;
-   clocks = <>;
+   clocks = < CLK_CPU>;
clock-latency = <244144>; /* 8 32k periods */
operating-points = <
/* kHzuV */
@@ -184,21 +185,11 @@
 
osc24M: clk@01c20050 {
#clock-cells = <0>;
-   compatible = "allwinner,sun4i-a10-osc-clk";
-   reg = <0x01c20050 0x4>;
+   compatible = "fixed-clock";
clock-frequency = <2400>;
clock-output-names = "osc24M";
};
 
-   osc3M: osc3M_clk {
-   #clock-cells = <0>;
-   compatible = "fixed-factor-clock";
-   clock-div = <8>;
-   clock-mult = <1>;
-   clocks = <>;
-   clock-output-names = "osc3M";
-   };
-
osc32k: clk@0 {
#clock-cells = <0>;
compatible = "fixed-clock";
@@ -206,528 +197,6 @@
clock-output-names = "osc32k";
};
 
-   pll1: clk@01c2 {
-   #clock-cells = <0>;
-   compatible = "allwinner,sun4i-a10-pll1-clk";
-   reg = <0x01c2 0x4>;
-   clocks = <>;
-   clock-output-names = "pll1";
-   };
-
-   pll2: clk@01c20008 {
-   #clock-cells = <1>;
-   compatible = "allwinner,sun4i-a10-pll2-clk";
-   reg = <0x01c20008 0x8>;
-   clocks = <>;
-   clock-output-names = "pll2-1x", "pll2-2x",
-"pll2-4x", "pll2-8x";
-   };
-
-   pll3: clk@01c20010 {
-   #clock-cells = <0>;
-   compatible = "allwinner,sun4i-a10-pll3-clk";
-   reg = <0x01c20010 0x4>;
-   clocks = <>;
-   clock-output-names = "pll3";
-   };
-
-   pll3x2: pll3x2_clk {
-   #clock-cells = 

[linux-sunxi] [PATCH v2 0/6] ARM: sunxi: Convert sun4i/sun7i series SoCs to sunxi-ng

2017-03-26 Thread Priit Laes
Hi,

This serie brings A10 (sun4i) and A20 (sun7i) SoCs into the
sunxi-ng world.

As mentioned in sun5i conversion, this is pretty much standard
stuff as all the required clocks were already implemented in
the sunxi-ng framework.

Unfortunately there's an issue with LVDS reset control that
causes issues with LVDS displays unless 'clk_ignore_unused'
option is used.

Need help with that :(

Changes from v1:
 - Drop useless comments
 - Add support for A10 / sun4i.
 - Rename driver to sunxi-a10-a20.
 - Add previously unimplemented clocks.
 - Document the audio pll hardcoded post-divider
 - Add Acked-by: Rob Herring  on patch 4

Priit Laes (6):
  clk: sunxi-ng: Add sun4i/sun7i CCU driver
  ARM: sun7i: Convert to CCU
  ARM: sun4i: Convert to CCU
  dt-bindings: List devicetree binding for the CCU of Allwinner A20
  dt-bindings: List devicetree binding for the CCU of Allwinner A10
  clk: sunxi-ng: Display index when clock registration fails

 Documentation/devicetree/bindings/clock/sunxi-ccu.txt |2 +-
 arch/arm/boot/dts/sun4i-a10.dtsi  |  636 +
 arch/arm/boot/dts/sun7i-a20.dtsi  |  717 +-
 drivers/clk/sunxi-ng/Kconfig  |   13 +-
 drivers/clk/sunxi-ng/Makefile |1 +-
 drivers/clk/sunxi-ng/ccu-sunxi-a10-a20.c  | 1532 ++-
 drivers/clk/sunxi-ng/ccu-sunxi-a10-a20.h  |   59 +-
 drivers/clk/sunxi-ng/ccu_common.c |4 +-
 include/dt-bindings/clock/sunxi-a10-a20-ccu.h |  208 +-
 include/dt-bindings/reset/sunxi-a10-a20-ccu.h |   66 +-
 10 files changed, 2050 insertions(+), 1188 deletions(-)
 create mode 100644 drivers/clk/sunxi-ng/ccu-sunxi-a10-a20.c
 create mode 100644 drivers/clk/sunxi-ng/ccu-sunxi-a10-a20.h
 create mode 100644 include/dt-bindings/clock/sunxi-a10-a20-ccu.h
 create mode 100644 include/dt-bindings/reset/sunxi-a10-a20-ccu.h

base-commit: 8e19fb843be8934d48b31fafbb32a4176f7feb65
-- 
git-series 0.9.1

-- 
You received this message because you are subscribed to the Google Groups 
"linux-sunxi" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to linux-sunxi+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.