Re: [U-Boot] [PATCH v4 4/5] dm: core: Don't include ofnode functions with of-platdata

2020-01-01 Thread Walter Lozano

Hi Simon

On 29/12/19 22:21, Simon Glass wrote:

Hi Walter,

On Thu, 7 Nov 2019 at 12:47, Walter Lozano  wrote:

Hi Simon,

Thanks for your patch.

On 7/11/19 12:53, Simon Glass wrote:

These functions cannot work with of-platdata since libfdt is not
available. At present when dev_read_...() functions are used it produces
error messages about ofnode which is confusing.

Adjust the Makefile and header to produce an error message for the actual
dev_read...() function which is called. This makes it easier to see what
code needs to be converted for use with of-platdata.

Signed-off-by: Simon Glass 
---

Changes in v4: None
Changes in v3:
- Fix eth_dev_get_mac_address() call dev_read...() only when available

   drivers/core/Makefile | 4 +++-
   include/dm/read.h | 3 +--
   net/eth-uclass.c  | 2 +-
   3 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/core/Makefile b/drivers/core/Makefile
index bce7467da1..b9e4a2aab1 100644
--- a/drivers/core/Makefile
+++ b/drivers/core/Makefile
@@ -13,6 +13,8 @@ obj-$(CONFIG_OF_LIVE) += of_access.o of_addr.o
   ifndef CONFIG_DM_DEV_READ_INLINE
   obj-$(CONFIG_OF_CONTROL) += read.o
   endif
-obj-$(CONFIG_OF_CONTROL) += of_extra.o ofnode.o read_extra.o
+ifdef CONFIG_$(SPL_TPL_)OF_LIBFDT
+obj-$(CONFIG_$(SPL_TPL_)OF_CONTROL) += of_extra.o ofnode.o read_extra.o
+endif

   ccflags-$(CONFIG_DM_DEBUG) += -DDEBUG
diff --git a/include/dm/read.h b/include/dm/read.h
index d37fcb504d..4f02d07d00 100644
--- a/include/dm/read.h
+++ b/include/dm/read.h
@@ -43,8 +43,7 @@ static inline bool dev_of_valid(struct udevice *dev)
   return ofnode_valid(dev_ofnode(dev));
   }

-#ifndef CONFIG_DM_DEV_READ_INLINE
-
+#if !defined(CONFIG_DM_DEV_READ_INLINE) || CONFIG_IS_ENABLED(OF_PLATDATA)
   /**
* dev_read_u32() - read a 32-bit integer from a device's DT property
*


I don't know if it has much sense, but as I understand it should be
possible to use DM without OF_CONTROL by adding U_BOOT_DEVICE entries
manually in a board file. Probably this won't be useful in mainline but
still could be useful in some contexts. If this is true maybe this
condition should be changed. In other words why not use
!CONFIG_IS_ENABLED(CONFIG_OF_LIBFDT) instead of
CONFIG_IS_ENABLED(OF_PLATDATA)?

Well if a U_BOOT_DEVICE is used (as you say, not in mainline), then
dev_read_...() cannot be used anyway, since there is no device-tree
node.

My goal here is to cause a compile/link error showing the code that
calls dev_read_...(). At present the error shows up in this header
instead, which is not very helpful.



I  now understand your point, thanks for your clarification.

I think that your approach will be help to improve the OF_PLATDATA 
support, which is great, however I'm still looking for a nice way to 
allow to take advantage of this kind of improvements when using 
U_BOOT_DEVICE. If I get some time I will work on this and ask for your 
review.






diff --git a/net/eth-uclass.c b/net/eth-uclass.c
index 3bd98b01ad..e3bfcdb6cc 100644
--- a/net/eth-uclass.c
+++ b/net/eth-uclass.c
@@ -462,7 +462,7 @@ static int eth_pre_unbind(struct udevice *dev)

   static bool eth_dev_get_mac_address(struct udevice *dev, u8 mac[ARP_HLEN])
   {
-#if IS_ENABLED(CONFIG_OF_CONTROL)
+#if CONFIG_IS_ENABLED(OF_CONTROL)
   const uint8_t *p;

   p = dev_read_u8_array_ptr(dev, "mac-address", ARP_HLEN);


Should this kind of #if be changed to

#if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)

Here's my thinking:

It is an error to call it with of-platdata, so my cause is to cause an
error (due to the unavailability of dev_read...() functions).

That way people see at build-time that they are doing something wrong.

If we change these to avoid the problem at build time, then it becomes
a runtime problem



Yes, you are right, thanks for your explanation.

Regards,



Regards,
Simon


[PATCH 0/4] sunxi: R40: Enable USB and Ethernet

2020-01-01 Thread Andre Przywara
This series enables the USB ports on boards with the Allwinner R40 SoC,
also updates the Bananapi M2 Berry board support.
Patch 1/4 updates the M2 Berry .dts file, so that we get the USB and
Ethernet nodes that we need to enable Ethernet in patch 2/4.
Patch 3/4 adds support for the USB PHY in the R40 SoC, so that the final
patch can enable USB for the two R40 boards that U-Boot supports.

Tested on the Bananapi M2 Berry. I don't have the M2 Ultra, but USB
should work there with this series too. Ethernet was already enabled.

Cheers,
Andre.

Andre Przywara (4):
  sunxi: dts: R40: Update Bananapi M2 Berry .dts
  sunxi: defconfig: Bananapi M2 Berry: enable Ethernet
  phy: sun4i-usb: Add Allwinner R40 support
  sunxi: defconfig: R40 boards: enable USB

 arch/arm/dts/sun8i-v40-bananapi-m2-berry.dts | 135 ---
 arch/arm/mach-sunxi/Kconfig  |   1 +
 configs/Bananapi_M2_Ultra_defconfig  |   4 +
 configs/bananapi_m2_berry_defconfig  |   6 ++
 drivers/phy/allwinner/phy-sun4i-usb.c|  12 +++
 5 files changed, 143 insertions(+), 15 deletions(-)

-- 
2.14.5



[PATCH 1/4] sunxi: dts: R40: Update Bananapi M2 Berry .dts

2020-01-01 Thread Andre Przywara
Update the .dts file from the kernel, which carries much more nodes,
some of them we need to enable USB and Ethernet support for the board.

Signed-off-by: Andre Przywara 
---
 arch/arm/dts/sun8i-v40-bananapi-m2-berry.dts | 135 ---
 1 file changed, 120 insertions(+), 15 deletions(-)

diff --git a/arch/arm/dts/sun8i-v40-bananapi-m2-berry.dts 
b/arch/arm/dts/sun8i-v40-bananapi-m2-berry.dts
index 54ad4db468..15c22b06fc 100644
--- a/arch/arm/dts/sun8i-v40-bananapi-m2-berry.dts
+++ b/arch/arm/dts/sun8i-v40-bananapi-m2-berry.dts
@@ -50,6 +50,7 @@
compatible = "sinovoip,bpi-m2-berry", "allwinner,sun8i-r40";
 
aliases {
+   ethernet0 = 
serial0 = 
};
 
@@ -57,6 +58,17 @@
stdout-path = "serial0:115200n8";
};
 
+   connector {
+   compatible = "hdmi-connector";
+   type = "a";
+
+   port {
+   hdmi_con_in: endpoint {
+   remote-endpoint = <_out_con>;
+   };
+   };
+   };
+
leds {
compatible = "gpio-leds";
 
@@ -84,12 +96,18 @@
wifi_pwrseq: wifi_pwrseq {
compatible = "mmc-pwrseq-simple";
reset-gpios = < 6 10 GPIO_ACTIVE_LOW>; /* PG10 WIFI_EN */
+   clocks = < CLK_OUTA>;
+   clock-names = "ext_clock";
};
 };
 
  {
-   phy-supply = <_eldo3>;  /* VDD12-SATA */
-   ahci-supply = <_dldo4>; /* VDD25-SATA */
+   ahci-supply = <_dldo4>;
+   phy-supply = <_eldo3>;
+   status = "okay";
+};
+
+ {
status = "okay";
 };
 
@@ -98,6 +116,32 @@
status = "okay";
 };
 
+ {
+   pinctrl-names = "default";
+   pinctrl-0 = <_rgmii_pins>;
+   phy-handle = <>;
+   phy-mode = "rgmii";
+   phy-supply = <_dc1sw>;
+   status = "okay";
+};
+
+_mdio {
+   phy1: ethernet-phy@1 {
+   compatible = "ethernet-phy-ieee802.3-c22";
+   reg = <1>;
+   };
+};
+
+ {
+   status = "okay";
+};
+
+_out {
+   hdmi_out_con: endpoint {
+   remote-endpoint = <_con_in>;
+   };
+};
+
  {
status = "okay";
 
@@ -111,6 +155,41 @@
 
 #include "axp22x.dtsi"
 
+ {
+   vmmc-supply = <_dcdc1>;
+   bus-width = <4>;
+   cd-gpios = < 7 13 GPIO_ACTIVE_LOW>; /* PH13 */
+   status = "okay";
+};
+
+ {
+   pinctrl-names = "default";
+   pinctrl-0 = <_pg_pins>;
+   vmmc-supply = <_dldo2>;
+   vqmmc-supply = <_dldo1>;
+   mmc-pwrseq = <_pwrseq>;
+   bus-width = <4>;
+   non-removable;
+   status = "okay";
+};
+
+ {
+   pinctrl-names = "default";
+   pinctrl-0 = <_out_a_pin>;
+   vcc-pa-supply = <_aldo2>;
+   vcc-pc-supply = <_dcdc1>;
+   vcc-pd-supply = <_dcdc1>;
+   vcc-pe-supply = <_eldo1>;
+   vcc-pf-supply = <_dcdc1>;
+   vcc-pg-supply = <_dldo1>;
+};
+
+_aldo2 {
+   regulator-min-microvolt = <250>;
+   regulator-max-microvolt = <250>;
+   regulator-name = "vcc-pa";
+};
+
 _aldo3 {
regulator-always-on;
regulator-min-microvolt = <270>;
@@ -118,6 +197,12 @@
regulator-name = "avcc";
 };
 
+_dc1sw {
+   regulator-min-microvolt = <300>;
+   regulator-max-microvolt = <300>;
+   regulator-name = "vcc-gmac-phy";
+};
+
 _dcdc1 {
regulator-always-on;
regulator-min-microvolt = <300>;
@@ -152,12 +237,27 @@
regulator-name = "vcc-wifi-io";
 };
 
+/*
+ * Our WiFi chip needs both DLDO2 and DLDO3 to be powered at the same
+ * time, with the two being in sync, to be able to meet maximum power
+ * consumption during transmits. Since this is not really supported
+ * right now, just use the two as always on, and we will fix it later.
+ */
+
 _dldo2 {
+   regulator-always-on;
regulator-min-microvolt = <330>;
regulator-max-microvolt = <330>;
regulator-name = "vcc-wifi";
 };
 
+_dldo3 {
+   regulator-always-on;
+   regulator-min-microvolt = <330>;
+   regulator-max-microvolt = <330>;
+   regulator-name = "vcc-wifi-2";
+};
+
 _dldo4 {
regulator-min-microvolt = <250>;
regulator-max-microvolt = <250>;
@@ -170,28 +270,33 @@
regulator-name = "vdd1v2-sata";
 };
 
- {
-   vmmc-supply = <_dcdc1>;
-   bus-width = <4>;
-   cd-gpios = < 7 13 GPIO_ACTIVE_LOW>; /* PH13 */
+_tv0 {
status = "okay";
 };
 
- {
+ {
pinctrl-names = "default";
-   pinctrl-0 = <_pg_pins>;
-   vmmc-supply = <_dldo2>;
-   vqmmc-supply = <_dldo1>;
-   mmc-pwrseq = <_pwrseq>;
-   bus-width = <4>;
-   non-removable;
+   pinctrl-0 = <_pb_pins>;
status = "okay";
 };
 
- {
+ {
pinctrl-names = "default";
-   pinctrl-0 = <_pb_pins>;
+   pinctrl-0 = <_pg_pins>, <_rts_cts_pg_pins>;
+   uart-has-rtscts;
status = "okay";
+
+   bluetooth {
+   

[PATCH 3/4] phy: sun4i-usb: Add Allwinner R40 support

2020-01-01 Thread Andre Przywara
Since every Allwinner USB PHY seems to be slightly different from each
other, we need to add the compatible string and the respective data
structure to make it work on the R40/V40 SoC.
Nothing spectacular this time, just one less USB controller than the H3.
Copied from the Linux kernel.

Signed-off-by: Andre Przywara 
---
 arch/arm/mach-sunxi/Kconfig   |  1 +
 drivers/phy/allwinner/phy-sun4i-usb.c | 12 
 2 files changed, 13 insertions(+)

diff --git a/arch/arm/mach-sunxi/Kconfig b/arch/arm/mach-sunxi/Kconfig
index 16d41b83af..3a3b673430 100644
--- a/arch/arm/mach-sunxi/Kconfig
+++ b/arch/arm/mach-sunxi/Kconfig
@@ -250,6 +250,7 @@ config MACH_SUN8I_R40
select SUPPORT_SPL
select SUNXI_DRAM_DW
select SUNXI_DRAM_DW_32BIT
+   select PHY_SUN4I_USB
 
 config MACH_SUN8I_V3S
bool "sun8i (Allwinner V3s)"
diff --git a/drivers/phy/allwinner/phy-sun4i-usb.c 
b/drivers/phy/allwinner/phy-sun4i-usb.c
index 5e8f87717f..f7309057b9 100644
--- a/drivers/phy/allwinner/phy-sun4i-usb.c
+++ b/drivers/phy/allwinner/phy-sun4i-usb.c
@@ -73,6 +73,7 @@ enum sun4i_usb_phy_type {
sun8i_a33_phy,
sun8i_a83t_phy,
sun8i_h3_phy,
+   sun8i_r40_phy,
sun8i_v3s_phy,
sun50i_a64_phy,
sun50i_h6_phy,
@@ -571,6 +572,16 @@ static const struct sun4i_usb_phy_cfg sun8i_h3_cfg = {
.phy0_dual_route = true,
 };
 
+static const struct sun4i_usb_phy_cfg sun8i_r40_cfg = {
+   .num_phys = 3,
+   .type = sun8i_r40_phy,
+   .disc_thresh = 3,
+   .phyctl_offset = REG_PHYCTL_A33,
+   .dedicated_clocks = true,
+   .enable_pmu_unk1 = true,
+   .phy0_dual_route = true,
+};
+
 static const struct sun4i_usb_phy_cfg sun8i_v3s_cfg = {
.num_phys = 1,
.type = sun8i_v3s_phy,
@@ -611,6 +622,7 @@ static const struct udevice_id sun4i_usb_phy_ids[] = {
{ .compatible = "allwinner,sun8i-a33-usb-phy", .data = 
(ulong)_a33_cfg },
{ .compatible = "allwinner,sun8i-a83t-usb-phy", .data = 
(ulong)_a83t_cfg },
{ .compatible = "allwinner,sun8i-h3-usb-phy", .data = 
(ulong)_h3_cfg },
+   { .compatible = "allwinner,sun8i-r40-usb-phy", .data = 
(ulong)_r40_cfg },
{ .compatible = "allwinner,sun8i-v3s-usb-phy", .data = 
(ulong)_v3s_cfg },
{ .compatible = "allwinner,sun50i-a64-usb-phy", .data = 
(ulong)_a64_cfg},
{ .compatible = "allwinner,sun50i-h6-usb-phy", .data = 
(ulong)_h6_cfg},
-- 
2.14.5



[PATCH 2/4] sunxi: defconfig: Bananapi M2 Berry: enable Ethernet

2020-01-01 Thread Andre Przywara
The M2 Berry features the normal Gigabit PHY connected to the SoC's MAC,
so enable the sun8i-emac driver to support Ethernet on the board.

Signed-off-by: Andre Przywara 
---
 configs/bananapi_m2_berry_defconfig | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/configs/bananapi_m2_berry_defconfig 
b/configs/bananapi_m2_berry_defconfig
index a5b8632ef6..a97be06188 100644
--- a/configs/bananapi_m2_berry_defconfig
+++ b/configs/bananapi_m2_berry_defconfig
@@ -15,3 +15,5 @@ CONFIG_SCSI_AHCI=y
 CONFIG_AXP_DLDO4_VOLT=2500
 CONFIG_AXP_ELDO3_VOLT=1200
 CONFIG_SCSI=y
+CONFIG_SUN8I_EMAC=y
+CONFIG_RGMII=y
-- 
2.14.5



[PATCH 4/4] sunxi: defconfig: R40 boards: enable USB

2020-01-01 Thread Andre Przywara
Now that the USB PHY on the Allwinner R40 SoC is supported, enable USB
support for the two R40 boards U-Boot supports.
For this we need to add the GPIO pin that powers the USB port(s), also
enable the usual suspects (OHCI/EHCI support).

Signed-off-by: Andre Przywara 
---
 configs/Bananapi_M2_Ultra_defconfig | 4 
 configs/bananapi_m2_berry_defconfig | 4 
 2 files changed, 8 insertions(+)

diff --git a/configs/Bananapi_M2_Ultra_defconfig 
b/configs/Bananapi_M2_Ultra_defconfig
index 7a30dd7f7f..bbf931329c 100644
--- a/configs/Bananapi_M2_Ultra_defconfig
+++ b/configs/Bananapi_M2_Ultra_defconfig
@@ -19,4 +19,8 @@ CONFIG_SUN8I_EMAC=y
 CONFIG_AXP_DLDO4_VOLT=2500
 CONFIG_AXP_ELDO3_VOLT=1200
 CONFIG_SCSI=y
+CONFIG_USB_EHCI_HCD=y
+CONFIG_USB_OHCI_HCD=y
+CONFIG_USB1_VBUS_PIN="PH23"
+CONFIG_USB2_VBUS_PIN="PH23"
 CONFIG_SYS_USB_EVENT_POLL_VIA_INT_QUEUE=y
diff --git a/configs/bananapi_m2_berry_defconfig 
b/configs/bananapi_m2_berry_defconfig
index a97be06188..654974e47d 100644
--- a/configs/bananapi_m2_berry_defconfig
+++ b/configs/bananapi_m2_berry_defconfig
@@ -17,3 +17,7 @@ CONFIG_AXP_ELDO3_VOLT=1200
 CONFIG_SCSI=y
 CONFIG_SUN8I_EMAC=y
 CONFIG_RGMII=y
+CONFIG_USB_EHCI_HCD=y
+CONFIG_USB_OHCI_HCD=y
+CONFIG_USB1_VBUS_PIN="PH23"
+CONFIG_SYS_USB_EVENT_POLL_VIA_INT_QUEUE=y
-- 
2.14.5



[PATCH 1/1] net: tftp: use correct printf codes

2020-01-01 Thread Heinrich Schuchardt
When printing unsigned numbers use %u.

Signed-off-by: Heinrich Schuchardt 
---
 net/tftp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/tftp.c b/net/tftp.c
index 1e3c18ae69..6b8369242c 100644
--- a/net/tftp.c
+++ b/net/tftp.c
@@ -222,7 +222,7 @@ static int load_block(unsigned block, uchar *dst, unsigned 
len)

tosend = min(net_boot_file_size - offset, tosend);
(void)memcpy(dst, (void *)(save_addr + offset), tosend);
-   debug("%s: block=%d, offset=%ld, len=%d, tosend=%ld\n", __func__,
+   debug("%s: block=%u, offset=%lu, len=%u, tosend=%lu\n", __func__,
  block, offset, len, tosend);
return tosend;
 }
--
2.24.1



Bug: qemu_arm64: Cannot access the second flash bank

2020-01-01 Thread Robin Randhawa
Hi folks.

[CC'ing some hopefully relevant folks].

As of:

commit 0ba41ce1b7816c229cc19e0621148b98f990cb68
libfdt: return correct value if #size-cells property is not present

.. accesses to the second flash bank on the qemu_arm64 virtual board
appear broken.

To demonstrate, consider that the physical memory map for the 2 flash
banks is:

Bank 1: 0x_ - 0x03FC_
Bank 2: 0x0400_ - 0x7FC0_

Now, consider the abbreviated output of the flinfo command pre and post
the above commit:

Pre:
===

=> flinfo

Bank # 1: CFI conformant flash (32 x 16)  Size: 64 MB in 256 Sectors
  Intel Extended command set, Manufacturer ID: 0x89, Device ID: 0x0018
  Erase timeout: 16384 ms, write timeout: 3 ms
  Buffer write timeout: 3 ms, buffer size: 2048 bytes

  Sector Start Addresses:
     RO   0004   RO   0008   RO   000C0010
  00140018001C00200024
  .
  .
  03E803EC03F003F403F8
  03FC

Bank # 2: CFI conformant flash (32 x 16)  Size: 64 MB in 256 Sectors
  Intel Extended command set, Manufacturer ID: 0x89, Device ID: 0x0018
  Erase timeout: 16384 ms, write timeout: 3 ms
  Buffer write timeout: 3 ms, buffer size: 2048 bytes

  Sector Start Addresses:
  0400   RO   04040408040C0410
  04140418041C04200424
  .
  .
  07E807EC07F007F407F8
  07FC

Post:


=> flinfo

Bank # 1: CFI conformant flash (32 x 16)  Size: 64 MB in 256 Sectors
  Intel Extended command set, Manufacturer ID: 0x89, Device ID: 0x0018
  Erase timeout: 16384 ms, write timeout: 3 ms
  Buffer write timeout: 3 ms, buffer size: 2048 bytes

  Sector Start Addresses:
     RO   0004   RO   0008   RO   000C0010
  00140018001C00200024
  .
  .
  03E803EC03F003F403F8
  03FC

Bank # 2: CFI conformant flash (32 x 16)  Size: 64 MB in 256 Sectors
  Intel Extended command set, Manufacturer ID: 0x89, Device ID: 0x0018
  Erase timeout: 16384 ms, write timeout: 3 ms
  Buffer write timeout: 3 ms, buffer size: 2048 bytes

  Sector Start Addresses:
  400404408
40C410
  41441841C
420424
  .
  .
 
40003E840003EC40003F040
003F440003F8
  40003FC

As a result, the second bank is unusable for environment stores
(CONFIG_ENV_ADDR is 0x400):

=> saveenv
Saving Environment to Flash... Error: start and/or end address not on
sector boundary
Error: start and/or end address not on sector boundary
Failed (1)

Rewinding the u-boot repo to before this commit fixes the problem.

Manually (uncleanly) reverting the commit and it's dependent commits
fixes the problem.

Here are the HEAD commits from the relevant repos that I used for the data 
above:

qemu: commit dd5b0f95490883cd8bc7d070db8de70d5c979cbc
u-boot: commit 6cb87cbb1475f668689f95911d1521ee6ba7f55c

Here is the qemu invocation I used:

$ dd if=/dev/zero of=./flash0-with-uboot.img bs=1M count=64 && dd 
if=/path/to/u-boot.bin of=./flash0-with-uboot.img conv=notrunc
$ qemu-system-aarch64 -M virt -cpu cortex-a53 -m 1024M -nographic -drive 
if=pflash,format=raw,index=0,file=flash0-with-uboot.img  -drive 
if=pflash,format=raw,index=1,file=flash1.img

I'm happy to help test any fixes if and as needed.

Cheers,
Robin



qemu_arm64_defconfig: PCI autoconfig fails for qemu-system-aarch64 -m 4G

2020-01-01 Thread Heinrich Schuchardt
Dear all,

I want to run qemu_arm64_defconfig with 4G.

qemu-system-aarch64 -machine virt -m 4G -smp cores=2 \
-bios u-boot.bin -cpu cortex-a53 -nographic -gdb tcp::1234 \
-netdev user,id=eth0,tftp=tftp -device e1000,netdev=eth0 \
-device virtio-rng-pci

I see an error:

No working controllers found
e1000: 52:54:00:12:34:56

Warning: e1000#0 using MAC address from ROM
BOOTP broadcast 1
pci_hose_phys_to_bus: invalid physical address
BOOTP broadcast 2
pci_hose_phys_to_bus: invalid physical address

The error does not occur for a smaller RAM size.

I added some debug output:

_dm_pci_phys_to_bus:
phys_addr 0x00013ffecb40,
res->phys_start 0x1000,
res->bus_start 0x1000

As qemu_arm64_defconfig does not define CONFIG_SYS_PCI_64BIT the
calculated bus address is truncated.

If CONFIG_SYS_PCI_64BIT is defined for qemu_arm64_defconfig and the
memory is less then 4 GiB an error
PCI: Failed autoconfig bar 10
occurs.

For 3GiB memory I observed the following values:

_dm_pci_phys_to_bus:
phys_addr 0xfffecbc0,
res->phys_start 0x1000,
res->bus_start 0x1000

When I define type pci_addr_t as 64bit everything works correctly.

Why does the number of bits in pci_addr_t depend on CONFIG_SYS_PCI_64BIT
and not on the bitness of the system?

It is especially worrisome that CONFIG_SYS_PCI_64BIT is not documented
at all. I wonder if Kumar remembers why he introduced it in 2008.

I tried to change the definition of the following types in pci.h

typedef phys_addr_t pci_addr_t;
typedef phys_addr_t pci_size_t;

This lets qemu-x86_defconfig fail with
Error binding driver 'cpu_qemu': -12

Using

typedef unsigned long pci_addr_t;
typedef unsigned long pci_size_t;

does not produce the error but I am not sure if this is the right approach.

Best regards

Heinrich


[PATCH 1/1] trace: provide Sphinx style comments

2020-01-01 Thread Heinrich Schuchardt
Correct some function comments. Convert to Sphinx style.

Signed-off-by: Heinrich Schuchardt 
---
 lib/trace.c | 54 +++--
 1 file changed, 36 insertions(+), 18 deletions(-)

diff --git a/lib/trace.c b/lib/trace.c
index 6716c7c2f0..ea8c8e0d40 100644
--- a/lib/trace.c
+++ b/lib/trace.c
@@ -130,13 +130,13 @@ static void __attribute__((no_instrument_function)) 
add_textbase(void)
 }

 /**
- * This is called on every function entry
+ * __cyg_profile_func_enter() - record function entry
  *
  * We add to our tally for this function and add to the list of called
  * functions.
  *
- * @param func_ptr Pointer to function being entered
- * @param caller   Pointer to function which called this function
+ * @func_ptr:  pointer to function being entered
+ * @caller:pointer to function which called this function
  */
 void __attribute__((no_instrument_function)) __cyg_profile_func_enter(
void *func_ptr, void *caller)
@@ -161,12 +161,10 @@ void __attribute__((no_instrument_function)) 
__cyg_profile_func_enter(
 }

 /**
- * This is called on every function exit
+ * __cyg_profile_func_exit() - record function exit
  *
- * We do nothing here.
- *
- * @param func_ptr Pointer to function being entered
- * @param caller   Pointer to function which called this function
+ * @func_ptr:  pointer to function being entered
+ * @caller:pointer to function which called this function
  */
 void __attribute__((no_instrument_function)) __cyg_profile_func_exit(
void *func_ptr, void *caller)
@@ -180,16 +178,16 @@ void __attribute__((no_instrument_function)) 
__cyg_profile_func_exit(
 }

 /**
- * Produce a list of called functions
+ * trace_list_functions() - produce a list of called functions
  *
  * The information is written into the supplied buffer - a header followed
  * by a list of function records.
  *
- * @param buff Buffer to place list into
- * @param buff_sizeSize of buffer
- * @param needed   Returns size of buffer needed, which may be
- * greater than buff_size if we ran out of space.
- * @return 0 if ok, -1 if space was exhausted
+ * @buff:  buffer to place list into
+ * @buff_size: size of buffer
+ * @needed:returns size of buffer needed, which may be
+ * greater than buff_size if we ran out of space.
+ * Return: 0 if ok, -ENOSPC if space was exhausted
  */
 int trace_list_functions(void *buff, size_t buff_size, size_t *needed)
 {
@@ -236,6 +234,18 @@ int trace_list_functions(void *buff, size_t buff_size, 
size_t *needed)
return 0;
 }

+/**
+ * trace_list_functions() - produce a list of function calls
+ *
+ * The information is written into the supplied buffer - a header followed
+ * by a list of function records.
+ *
+ * @buff:  buffer to place list into
+ * @buff_size: size of buffer
+ * @needed:returns size of buffer needed, which may be
+ * greater than buff_size if we ran out of space.
+ * Return: 0 if ok, -ENOSPC if space was exhausted
+ */
 int trace_list_calls(void *buff, size_t buff_size, size_t *needed)
 {
struct trace_output_hdr *output_hdr = NULL;
@@ -281,7 +291,9 @@ int trace_list_calls(void *buff, size_t buff_size, size_t 
*needed)
return 0;
 }

-/* Print basic information about tracing */
+/**
+ * trace_print_stats() - print basic information about tracing
+ */
 void trace_print_stats(void)
 {
ulong count;
@@ -320,10 +332,11 @@ void __attribute__((no_instrument_function)) 
trace_set_enabled(int enabled)
 }

 /**
- * Init the tracing system ready for used, and enable it
+ * trace_init() - initialize the tracing system and enable it
  *
- * @param buff Pointer to trace buffer
- * @param buff_sizeSize of trace buffer
+ * @buff:  Pointer to trace buffer
+ * @buff_size: Size of trace buffer
+ * Return: 0 if ok
  */
 int __attribute__((no_instrument_function)) trace_init(void *buff,
size_t buff_size)
@@ -385,6 +398,11 @@ int __attribute__((no_instrument_function)) 
trace_init(void *buff,
 }

 #ifdef CONFIG_TRACE_EARLY
+/**
+ * trace_early_init() - initialize the tracing system for early tracing
+ *
+ * Return: 0 if ok, -ENOSPC if not enough memory is available
+ */
 int __attribute__((no_instrument_function)) trace_early_init(void)
 {
ulong func_count = gd->mon_len / FUNC_SITE_SIZE;
--
2.24.1



Re: [PATCH] drivers: pci: initialise class to 0 before reading

2020-01-01 Thread Bin Meng
Hi Hugh,

On Wed, Jan 1, 2020 at 9:50 PM Hugh Cole-Baker  wrote:
>
> Hi Bin,
>
> > On 1 Jan 2020, at 13:25, Bin Meng  wrote:
> >
> > On Wed, Jan 1, 2020 at 7:15 PM Hugh Cole-Baker  wrote:
> >>
> >> Otherwise, uninitialised memory from the upper 32 bits can end up in
> >> find_id.class, and this causes bugs later when looking for a driver for
> >> the class.
> >>
> >> Signed-off-by: Hugh Cole-Baker 
> >> ---
> >> drivers/pci/pci-uclass.c | 2 +-
> >> 1 file changed, 1 insertion(+), 1 deletion(-)
> >>
> >> diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c
> >> index fab20fc60e..c28a1cc363 100644
> >> --- a/drivers/pci/pci-uclass.c
> >> +++ b/drivers/pci/pci-uclass.c
> >> @@ -773,7 +773,7 @@ int pci_bind_bus_devices(struct udevice *bus)
> >> bdf += PCI_BDF(0, 0, 1)) {
> >>struct pci_child_platdata *pplat;
> >>struct udevice *dev;
> >> -   ulong class;
> >> +   ulong class = 0;
> >>
> >>if (!PCI_FUNC(bdf))
> >>found_multi = false;
> >> --
> >
> > I see class is initialized in the call to:
> >
> > pci_bus_read_config(bus, bdf, PCI_CLASS_REVISION, ,
> >PCI_SIZE_32);
> > class >>= 8;
> >
>
> Maybe the driver I'm working with is doing its read_config wrongly? I'm
> trying to use this Rockchip PCIe driver [1] with upstream u-boot. The
> driver casts  to u32*, uses readl() and only sets the lower 32
> bits. I was assuming that this was normal for a read of PCI_SIZE_32.
> However, looking at some of the other drivers, it seems like it should
> be using pci_conv_32_to_size() instead?
>

The bug should be that

https://github.com/radxa/u-boot/blob/rk3399-pie-gms-express-baseline/drivers/pci/pcie_rockchip.c#L318

u32 *val should be declared as ulong *val.

> [1] 
> https://github.com/radxa/u-boot/blob/rk3399-pie-gms-express-baseline/drivers/pci/pcie_rockchip.c#L435
>

Regards,
Bin


Re: [PATCH] drivers: pci: initialise class to 0 before reading

2020-01-01 Thread Hugh Cole-Baker
Hi Bin,

> On 1 Jan 2020, at 13:25, Bin Meng  wrote:
> 
> On Wed, Jan 1, 2020 at 7:15 PM Hugh Cole-Baker  wrote:
>> 
>> Otherwise, uninitialised memory from the upper 32 bits can end up in
>> find_id.class, and this causes bugs later when looking for a driver for
>> the class.
>> 
>> Signed-off-by: Hugh Cole-Baker 
>> ---
>> drivers/pci/pci-uclass.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>> 
>> diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c
>> index fab20fc60e..c28a1cc363 100644
>> --- a/drivers/pci/pci-uclass.c
>> +++ b/drivers/pci/pci-uclass.c
>> @@ -773,7 +773,7 @@ int pci_bind_bus_devices(struct udevice *bus)
>> bdf += PCI_BDF(0, 0, 1)) {
>>struct pci_child_platdata *pplat;
>>struct udevice *dev;
>> -   ulong class;
>> +   ulong class = 0;
>> 
>>if (!PCI_FUNC(bdf))
>>found_multi = false;
>> --
> 
> I see class is initialized in the call to:
> 
> pci_bus_read_config(bus, bdf, PCI_CLASS_REVISION, ,
>PCI_SIZE_32);
> class >>= 8;
> 

Maybe the driver I'm working with is doing its read_config wrongly? I'm
trying to use this Rockchip PCIe driver [1] with upstream u-boot. The
driver casts  to u32*, uses readl() and only sets the lower 32
bits. I was assuming that this was normal for a read of PCI_SIZE_32.
However, looking at some of the other drivers, it seems like it should
be using pci_conv_32_to_size() instead?

[1] 
https://github.com/radxa/u-boot/blob/rk3399-pie-gms-express-baseline/drivers/pci/pcie_rockchip.c#L435

Thanks,
Hugh

> Regards,
> Bin



Re: [PATCH] drivers: pci: initialise class to 0 before reading

2020-01-01 Thread Bin Meng
On Wed, Jan 1, 2020 at 7:15 PM Hugh Cole-Baker  wrote:
>
> Otherwise, uninitialised memory from the upper 32 bits can end up in
> find_id.class, and this causes bugs later when looking for a driver for
> the class.
>
> Signed-off-by: Hugh Cole-Baker 
> ---
>  drivers/pci/pci-uclass.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c
> index fab20fc60e..c28a1cc363 100644
> --- a/drivers/pci/pci-uclass.c
> +++ b/drivers/pci/pci-uclass.c
> @@ -773,7 +773,7 @@ int pci_bind_bus_devices(struct udevice *bus)
>  bdf += PCI_BDF(0, 0, 1)) {
> struct pci_child_platdata *pplat;
> struct udevice *dev;
> -   ulong class;
> +   ulong class = 0;
>
> if (!PCI_FUNC(bdf))
> found_multi = false;
> --

I see class is initialized in the call to:

pci_bus_read_config(bus, bdf, PCI_CLASS_REVISION, ,
PCI_SIZE_32);
class >>= 8;

Regards,
Bin


[PATCH v2 1/1] efi_loader: __cyg_profile_func_enter/_exit

2020-01-01 Thread Heinrich Schuchardt
U-Boot can be compiled with function tracing enabled.

When compiling with FTRACE __cyg_profile_func_enter() is called when a
function is entered and __cyg_profile_func_exit() when the function is
left.

To avoid a crash we have to define these function for the free-standing
UEFI binaries.

Signed-off-by: Heinrich Schuchardt 
---
v2
remove changes in Makefile that slipped in by error
---
 lib/efi_loader/efi_freestanding.c | 32 +++
 1 file changed, 32 insertions(+)

diff --git a/lib/efi_loader/efi_freestanding.c 
b/lib/efi_loader/efi_freestanding.c
index bd9da5bbc8..dcf5d1c49a 100644
--- a/lib/efi_loader/efi_freestanding.c
+++ b/lib/efi_loader/efi_freestanding.c
@@ -88,3 +88,35 @@ void *memset(void *s, int c, size_t n)
*d++ = c;
return s;
 }
+
+/**
+ * __cyg_profile_func_enter() - record function entry
+ *
+ * This is called on every function entry when compiling with
+ * -finstrument-functions.
+ *
+ * We do nothing here.
+ *
+ * @param func_ptr Pointer to function being entered
+ * @param caller   Pointer to function which called this function
+ */
+void __attribute__((no_instrument_function))
+__cyg_profile_func_enter(void *func_ptr, void *caller)
+{
+}
+
+/**
+ * __cyg_profile_func_exit() - record function exit
+ *
+ * This is called on every function exit when compiling with
+ * -finstrument-functions.
+ *
+ * We do nothing here.
+ *
+ * @param func_ptr Pointer to function being entered
+ * @param caller   Pointer to function which called this function
+ */
+void __attribute__((no_instrument_function))
+__cyg_profile_func_exit(void *func_ptr, void *caller)
+{
+}
--
2.24.1



[PATCH 1/1] efi_loader: __cyg_profile_func_enter/_exit

2020-01-01 Thread Heinrich Schuchardt
U-Boot can be compiled with function tracing enabled.

When compiling with FTRACE __cyg_profile_func_enter() is called when a
function is entered and __cyg_profile_func_exit() when a function is
left.

To avoid a crash we have to define these function for the free-standing
UEFI binaries.

Signed-off-by: Heinrich Schuchardt 
---
 lib/efi_loader/Makefile   |  2 ++
 lib/efi_loader/efi_freestanding.c | 32 +++
 2 files changed, 34 insertions(+)

diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile
index 04dc864851..f1de2158c3 100644
--- a/lib/efi_loader/Makefile
+++ b/lib/efi_loader/Makefile
@@ -9,6 +9,8 @@
 asflags-y += -DHOST_ARCH="$(HOST_ARCH)"
 ccflags-y += -DHOST_ARCH="$(HOST_ARCH)"

+ccflags-y += -finstrument-functions
+
 CFLAGS_efi_boottime.o += \
   -DFW_VERSION="0x$(VERSION)" \
   -DFW_PATCHLEVEL="0x$(PATCHLEVEL)"
diff --git a/lib/efi_loader/efi_freestanding.c 
b/lib/efi_loader/efi_freestanding.c
index bd9da5bbc8..dcf5d1c49a 100644
--- a/lib/efi_loader/efi_freestanding.c
+++ b/lib/efi_loader/efi_freestanding.c
@@ -88,3 +88,35 @@ void *memset(void *s, int c, size_t n)
*d++ = c;
return s;
 }
+
+/**
+ * __cyg_profile_func_enter() - record function entry
+ *
+ * This is called on every function entry when compiling with
+ * -finstrument-functions.
+ *
+ * We do nothing here.
+ *
+ * @param func_ptr Pointer to function being entered
+ * @param caller   Pointer to function which called this function
+ */
+void __attribute__((no_instrument_function))
+__cyg_profile_func_enter(void *func_ptr, void *caller)
+{
+}
+
+/**
+ * __cyg_profile_func_exit() - record function exit
+ *
+ * This is called on every function exit when compiling with
+ * -finstrument-functions.
+ *
+ * We do nothing here.
+ *
+ * @param func_ptr Pointer to function being entered
+ * @param caller   Pointer to function which called this function
+ */
+void __attribute__((no_instrument_function))
+__cyg_profile_func_exit(void *func_ptr, void *caller)
+{
+}
--
2.24.1



[PATCH] drivers: pci: initialise class to 0 before reading

2020-01-01 Thread Hugh Cole-Baker
Otherwise, uninitialised memory from the upper 32 bits can end up in
find_id.class, and this causes bugs later when looking for a driver for
the class.

Signed-off-by: Hugh Cole-Baker 
---
 drivers/pci/pci-uclass.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c
index fab20fc60e..c28a1cc363 100644
--- a/drivers/pci/pci-uclass.c
+++ b/drivers/pci/pci-uclass.c
@@ -773,7 +773,7 @@ int pci_bind_bus_devices(struct udevice *bus)
 bdf += PCI_BDF(0, 0, 1)) {
struct pci_child_platdata *pplat;
struct udevice *dev;
-   ulong class;
+   ulong class = 0;
 
if (!PCI_FUNC(bdf))
found_multi = false;
-- 
2.17.2 (Apple Git-113)