Re: [PATCH] Documentation: riscv: bring BeagleV Starlight docs up-to-date

2024-03-24 Thread Antony Pavlov
On Fri, 22 Mar 2024 15:24:41 +0100
Ahmad Fatoum  wrote:

Hi Ahmad!

> The BeagleV Starlight hasn't exited the Beta phase and the BeagleV name
> is now associated with the BeagleV-Ahead, which used a different SoC.
> 
> Note this in the section title and also adjust the build instruction to
> make them reproducible in 2024:
> 
>   - Given that the board is discontinued, it's not worthwhile to move
> away from the vendor's OpenSBI fork, so pin the revision that was
> used for initial bring-up
> 
>   - fence.i is no longer part of the default -march=rv64imafdc in
> recent toolchains, therefore add it explicitly into the ISA string.
> 
> Signed-off-by: Ahmad Fatoum 
> ---
>  Documentation/boards/riscv.rst | 7 ---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/Documentation/boards/riscv.rst b/Documentation/boards/riscv.rst
> index 92f663cfb9e6..ade1443c9704 100644
> --- a/Documentation/boards/riscv.rst
> +++ b/Documentation/boards/riscv.rst
> @@ -60,8 +60,8 @@ into the config file.
>  
>  See https://barebox.org/jsbarebox/?graphic=1 for a live example.
>  
> -BeagleV
> 
> +BeagleV Starlight
> +-
>  
>  barebox has second-stage support for the BeagleV Starlight::
>  
> @@ -73,11 +73,12 @@ to opensbi::
>  
>git clone https://github.com/starfive-tech/opensbi
>cd opensbi
> +  git checkout 2524b0ecd8684b42bc7a4c69794f40f11cbbe2a5
>export ARCH=riscv
>export PLATFORM=starfive/vic7100
>export FW_PAYLOAD_PATH=$BAREBOX/build/images/barebox-beaglev-starlight.img
>  
> -  make ARCH=riscv
> +  make PLATFORM_RISCV_ISA=rv64imafdc_zifencei
>./fsz.sh ./build/platform/starfive/vic7100/firmware/fw_payload.bin 
> fw_payload.bin.out
>ls -l $OPENSBI/build/platform/starfive/vic7100/firmware/fw_payload.bin.out
>  
> -- 
> 2.39.2
> 

At the moment I have no BeagleV Starlight board at hand.
I can get it back for testing barebox in several days.

However here are my changes to the BeagleV Starlight barebox build process 
documentation:

--- a/Documentation/boards/riscv.rst
+++ b/Documentation/boards/riscv.rst
@@ -66,7 +66,7 @@ BeagleV Starlight
 barebox has second-stage support for the BeagleV Starlight::
 
   make ARCH=riscv rv64i_defconfig
-  make
+  make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu-
 
 Thie resulting ``./images/barebox-beaglev-starlight.img`` can be used as 
payload
 to opensbi::
@@ -75,21 +75,24 @@ to opensbi::
   cd opensbi
   git checkout 2524b0ecd8684b42bc7a4c69794f40f11cbbe2a5
   export ARCH=riscv
+  export CROSS_COMPILE=riscv64-linux-gnu-
   export PLATFORM=starfive/vic7100
-  export FW_PAYLOAD_PATH=$BAREBOX/build/images/barebox-beaglev-starlight.img
+  export FW_PAYLOAD_PATH=$(cd .. && pwd)/images/barebox-beaglev-starlight.img
 
   make PLATFORM_RISCV_ISA=rv64imafdc_zifencei
+  wget 
https://raw.githubusercontent.com/starfive-tech/freelight-u-sdk/JH7100_VisionFive/fsz.sh
+  chmod +x fsz.sh
   ./fsz.sh ./build/platform/starfive/vic7100/firmware/fw_payload.bin 
fw_payload.bin.out
-  ls -l $OPENSBI/build/platform/starfive/vic7100/firmware/fw_payload.bin.out
+  ls -l ./build/platform/starfive/vic7100/firmware/fw_payload.bin.out
 
-The resulting ``./platform/starfive/vic7100/firmware/fw_payload.bin.out`` can 
then
+The resulting 
``./build/platform/starfive/vic7100/firmware/fw_payload.bin.out`` can then
 be flashed via Xmodem to the board::
 
   picocom -b 115200 /dev/ttyUSB0 --send-cmd "sx -vv" --receive-cmd "rx -vv"
   0:update uboot
   select the function: 0␤
   send file by xmodem
-  ^A^S./platform/starfive/vic7100/firmware/fw_payload.bin.out␤
+  ^A^S./build/platform/starfive/vic7100/firmware/fw_payload.bin.out␤
 
 After reset, barebox should then boot to shell and attempt booting kernel 
``Image``
 and device tree ``jh7100-starlight.dtb`` from the first root partition with 
the same

-- 
Best regards,
  Antony Pavlov



Re: Documentation/boards/riscv.rst: can't rebuild image for BeagleV

2024-03-24 Thread Antony Pavlov
On Fri, 22 Mar 2024 15:29:48 +0100
Ahmad Fatoum  wrote:

> Hello Antony,
> 
> On 11.03.24 12:50, Ahmad Fatoum wrote:
> > Hello Antony,
> > 
> > On 10.03.24 21:33, Antony Pavlov wrote:
> >> Hi Ahmad!
> >>
> >> I have tried to rebuild barebox for BeagleV.
> >> Alas I was unable to reproduce the steps from 
> >> Documentation/boards/riscv.rst
> >> because of changes in opensbi repo.
> 
> I just Cc'd[1] you on a documentation patch that describes how it needs
> to be built now.

Thanks for your patch!
Unfortunately I have not succeed with patched documentation.
I'll reply to the patch message.

-- 
Best regards,
  Antony Pavlov



[PATCH] common: deep-probe: fix DEEP_PROBE_UNKNOWN misspelling

2024-03-20 Thread Antony Pavlov
Signed-off-by: Antony Pavlov 
---
 common/deep-probe.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/common/deep-probe.c b/common/deep-probe.c
index 931e5a17709..b270a10f7fe 100644
--- a/common/deep-probe.c
+++ b/common/deep-probe.c
@@ -7,18 +7,18 @@
 #include 
 
 enum deep_probe_state {
-   DEEP_PROBE_UNKONWN = -1,
+   DEEP_PROBE_UNKNOWN = -1,
DEEP_PROBE_NOT_SUPPORTED,
DEEP_PROBE_SUPPORTED
 };
 
-static enum deep_probe_state boardstate = DEEP_PROBE_UNKONWN;
+static enum deep_probe_state boardstate = DEEP_PROBE_UNKNOWN;
 
 bool deep_probe_is_supported(void)
 {
struct deep_probe_entry *board;
 
-   if (boardstate > DEEP_PROBE_UNKONWN)
+   if (boardstate > DEEP_PROBE_UNKNOWN)
return boardstate;
 
/* determine boardstate */
-- 
2.39.0




[PATCH] treewide: drop unused header files

2024-03-19 Thread Antony Pavlov
Signed-off-by: Antony Pavlov 
---
 include/usb_dfu_trailer.h |   32 --
 lib/bzlib_private.h   |  521 ---
 lib/zstd/zstd_opt.h   | 1014 -
 net/nfs.h |   68 ---
 4 files changed, 1635 deletions(-)

diff --git a/include/usb_dfu_trailer.h b/include/usb_dfu_trailer.h
deleted file mode 100644
index 64b84072755..000
--- a/include/usb_dfu_trailer.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-only */
-#ifndef _USB_DFU_TRAILER_H
-#define _USB_DFU_TRAILER_H
-
-/* trailer handling for DFU files */
-
-#define BAREBOX_DFU_TRAILER_V1 1
-#define BAREBOX_DFU_TRAILER_MAGIC  0x19731978
-struct barebox_dfu_trailer {
-   u_int32_t   magic;
-   u_int16_t   version;
-   u_int16_t   length;
-   u_int16_t   vendor;
-   u_int16_t   product;
-   u_int32_t   revision;
-} __attribute__((packed));
-
-/* we mirror the trailer because we want it to be longer in later versions
- * while keeping backwards compatibility */
-static inline void dfu_trailer_mirror(struct barebox_dfu_trailer *trailer,
- unsigned char *eof)
-{
-   int i;
-   int len = sizeof(struct barebox_dfu_trailer);
-   unsigned char *src = eof - len;
-   unsigned char *dst = (unsigned char *) trailer;
-
-   for (i = 0; i < len; i++)
-   dst[len-1-i] = src[i];
-}
-
-#endif /* _USB_DFU_TRAILER_H */
diff --git a/lib/bzlib_private.h b/lib/bzlib_private.h
deleted file mode 100644
index de10dd42150..000
--- a/lib/bzlib_private.h
+++ /dev/null
@@ -1,521 +0,0 @@
-/*
- * This file is a modified version of bzlib_private.h from the bzip2-1.0.2
- * distribution which can be found at http://sources.redhat.com/bzip2/
- */
-
-/*-*/
-/*--- Private header file for the library.  ---*/
-/*---   bzlib_private.h ---*/
-/*-*/
-
-/*--
-  This file is a part of bzip2 and/or libbzip2, a program and
-  library for lossless, block-sorting data compression.
-
-  Copyright (C) 1996-2002 Julian R Seward.  All rights reserved.
-
-  Redistribution and use in source and binary forms, with or without
-  modification, are permitted provided that the following conditions
-  are met:
-
-  1. Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
-
-  2. The origin of this software must not be misrepresented; you must
- not claim that you wrote the original software.  If you use this
- software in a product, an acknowledgment in the product
- documentation would be appreciated but is not required.
-
-  3. Altered source versions must be plainly marked as such, and must
- not be misrepresented as being the original software.
-
-  4. The name of the author may not be used to endorse or promote
- products derived from this software without specific prior written
- permission.
-
-  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
-  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-  ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
-  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
-  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-  Julian Seward, Cambridge, UK.
-  jsew...@acm.org
-  bzip2/libbzip2 version 1.0 of 21 March 2000
-
-  This program is based on (at least) the work of:
- Mike Burrows
- David Wheeler
- Peter Fenwick
- Alistair Moffat
- Radford Neal
- Ian H. Witten
- Robert Sedgewick
- Jon L. Bentley
-
-  For more information on these sources, see the manual.
---*/
-
-
-#ifndef _BZLIB_PRIVATE_H
-#define _BZLIB_PRIVATE_H
-
-#include 
-#include 
-
-#include "bzlib.h"
-
-#ifndef BZ_NO_STDIO
-#include 
-#include 
-#include 
-#endif
-
-
-/*-- General stuff. --*/
-
-#define BZ_VERSION  "1.0.2, 30-Dec-2001"
-
-typedef charChar;
-typedef unsigned char   Bool;
-typedef unsigned char   UChar;
-typedef int Int32;
-typedef unsigned intUInt32;
-typedef short   Int16;
-typedef unsigned short  UInt16;
-
-#define True  ((Bool)1)
-#define False ((Bool)0)
-
-#ifndef __GNUC__
-#define __inline__  /* */
-#endif
-
-#ifndef BZ_NO_STDIO
-extern void BZ2_bz__AssertH__fail ( int errcode );
-#define AssertH(cond,errcode) \
-   { if (!(cond)) BZ2_bz__AssertH__fail ( err

[PATCH] MIPS: add generic device tree 2nd stage support

2024-03-10 Thread Antony Pavlov
Building and running barebox for 32-bit malta:

export ARCH=mips
export CROSS_COMPILE=mips-linux-gnu-
make -s qemu-malta_defconfig
sed -i "s/# \(CONFIG_BOARD_MIPS_GENERIC_DT\) is not set/\1=y/" .config
make -s oldconfig
make -s
qemu-system-mips -M malta -cpu 24Kf -m 256M \
-nographic -serial mon:stdio \
-bios images/barebox-qemu-malta.img \
-net user,tftp=$(pwd) -net nic,model=e1000

Building and running barebox for 64-bit malta:

export ARCH=mips
export CROSS_COMPILE=mips-linux-gnu-
make -s qemu-malta64el_defconfig
sed -i "s/# \(CONFIG_BOARD_MIPS_GENERIC_DT\) is not set/\1=y/" .config
make -s oldconfig
make -s
qemu-system-mips64el -M malta -cpu MIPS64R2-generic -m 256M \
-nographic -serial mon:stdio \
-bios images/barebox-qemu-malta.img.swapped \
-net user,tftp=$(pwd) -net nic,model=e1000

Use bootm to run barebox-dt-2nd.img (external device tree):

barebox@qemu malta:/ dhcp
barebox@qemu malta:/ cp /mnt/tftp/images/barebox-dt-2nd.img barebox.img
barebox@qemu malta:/ cp /mnt/tftp/arch/mips/dts/qemu-malta.dtb .
barebox@qemu malta:/ imd barebox.img
barebox@qemu malta:/ bootm -o qemu-malta.dtb barebox.img

Use bootm to run barebox-qemu-malta.img (encapsulated device tree):

barebox@qemu malta:/ dhcp
barebox@qemu malta:/ cp /mnt/tftp/images/barebox-qemu-malta.img barebox.img
barebox@qemu malta:/ imd barebox.img
barebox@qemu malta:/ bootm barebox.img

N.B. Use just the same commands for both 32-bit and 64-bit malta boards.

Signed-off-by: Antony Pavlov 
---
 arch/mips/Kconfig   | 10 ++
 arch/mips/boards/Makefile   |  2 ++
 arch/mips/boards/board-dt-2nd.S | 35 +
 arch/mips/boot/main_entry-pbl.c |  4 
 arch/mips/lib/bootm.c   | 13 ++--
 5 files changed, 62 insertions(+), 2 deletions(-)

diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index 63ba6aa9d5a..14062dee347 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -319,6 +319,16 @@ config 64BIT
 
 endchoice
 
+config BOARD_MIPS_GENERIC_DT
+   select BOARD_GENERIC_DT
+   depends on OFDEVICE
+   bool "Build generic MIPS device tree 2nd stage image"
+   help
+ This enables compilation of a generic image that can be started 2nd
+ stage from barebox or from qemu. It picks up a device tree passed
+ in a1 like the Kernel does.
+ The image will be called images/barebox-dt-2nd.img
+
 menu "MIPS specific settings"
 
 config CMD_MIPS_CPUINFO
diff --git a/arch/mips/boards/Makefile b/arch/mips/boards/Makefile
index 9402035856c..c4ce599c934 100644
--- a/arch/mips/boards/Makefile
+++ b/arch/mips/boards/Makefile
@@ -13,3 +13,5 @@ obj-$(CONFIG_BOARD_QEMU_MALTA) += qemu-malta/
 obj-$(CONFIG_BOARD_RZX50) += ritmix-rzx50/
 obj-$(CONFIG_BOARD_TPLINK_MR3020) += tplink-mr3020/
 obj-$(CONFIG_BOARD_TPLINK_WDR4300) += tplink-wdr4300/
+
+pbl-$(CONFIG_BOARD_MIPS_GENERIC_DT) += board-dt-2nd.o
diff --git a/arch/mips/boards/board-dt-2nd.S b/arch/mips/boards/board-dt-2nd.S
new file mode 100644
index 000..a1465f09e36
--- /dev/null
+++ b/arch/mips/boards/board-dt-2nd.S
@@ -0,0 +1,35 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Startup Code for generic MIPS device tree 2nd stage image
+ *
+ * Copyright (C) 2024 Antony Pavlov 
+ */
+
+#include 
+#include 
+#include 
+
+ENTRY_FUNCTION(start_dt_2nd)
+
+   /* save device tree address in v1 */
+   movev1, a1
+
+   mips_cpu_setup
+
+   copy_to_link_location   start_dt_2nd
+
+   stack_setup
+
+   /* pbl_main_entry() computes fdt_len by itself
+* if fdt == fdt_end */
+   movea0, v1 /* fdt */
+   movea1, v1 /* fdt_end */
+   PTR_LI  a2, SZ_256M /* ram_size */
+   PTR_LA  v0, pbl_main_entry
+   jal v0
+nop
+
+   /* No return */
+1:
+   b   1b
+nop
diff --git a/arch/mips/boot/main_entry-pbl.c b/arch/mips/boot/main_entry-pbl.c
index 78982fd995e..389dc94f370 100644
--- a/arch/mips/boot/main_entry-pbl.c
+++ b/arch/mips/boot/main_entry-pbl.c
@@ -11,6 +11,7 @@
 #include 
 #include 
 #include 
+#include 
 
 extern void *input_data;
 extern void *input_data_end;
@@ -45,6 +46,9 @@ void __section(.text_entry) pbl_main_entry(void *fdt, void 
*fdt_end,
barebox_uncompress(_data, piggy_len);
 
fdt_len = (unsigned long)fdt_end - (unsigned long)fdt;
+   if (!fdt_len) {
+   fdt_len = get_unaligned_be32((void *)((unsigned long)fdt + 4));
+   }
fdt_new = (void *)PAGE_ALIGN_DOWN(TEXT_BASE - MALLOC_SIZE - STACK_SIZE 
- fdt_len);
memcpy(fdt_new, fdt, fdt_len);
 
diff --git a/arch/mips/lib/bootm.c b/arch/mips/lib/bootm.c
index 643ad57e4db..86573dec7f1 100644
--- a/arch/mips/lib/bootm.c
+++ b/arch/mips/lib/bootm.c
@@ -16,12 +16,21 @@
 
 static int do_bootm_barebox(struct image_data *data)
 {
-   void (*barebox)(void);
+   void (*barebox)(int, void *);
+   void *f

Documentation/boards/riscv.rst: can't rebuild image for BeagleV

2024-03-10 Thread Antony Pavlov
Hi Ahmad!

I have tried to rebuild barebox for BeagleV.
Alas I was unable to reproduce the steps from Documentation/boards/riscv.rst
because of changes in opensbi repo.

I have successfully rebuild U-Boot from the 
https://github.com/andreiw/uboot_jh7100 repo
and used it for running sbi-less BeagleV barebox image.

I planned to use BeagleV for picotcp demonstration but BeagleV ethernet adapter
does not works neither under U-Boot nor under barebox. My dhcp server can't even
receive any request from BeagleV.

Have we any chance to make BeagleV ethernet adapter works under barebox?

-- 
Best regards,
  Antony Pavlov



Re: barebox + picotcp-1.7.0

2024-03-10 Thread Antony Pavlov
On Mon, 4 Mar 2024 15:47:39 +0100
Sascha Hauer  wrote:

Hi Sascha!

> On Sun, Mar 03, 2024 at 09:58:03PM +0300, Antony Pavlov wrote:
> > Hi all!
> > 
> > In the message [1] Sascha proposed to have the barebox network stack
> > and picotcp in parallel.
> > 
> > This approach is used in the branch 20240303.picotcp-1.7.0 from
> > https://github.com/frantony/barebox/ repo [2]:
> > 
> > * all incoming packets go through the barebox network stack and only if
> >   they are not processed by it, they are forwarded to the picotcp network
> >   stack (all incoming ARP packets always go to the picotcp network stack).
> > 
> > * risc-v virtual qemu machine with user networking (slirp network stack)
> >   is used for demonstration; one needs only qemu risc-v emulator
> >   for demonstration;
> > 
> > * these barebox commands are introduced for picotcp stack capabilities
> >   demonstration:
> > 
> >   * dhclient --- setup picotcp network interface using the DHCP protocol;
> >   * ifconfig --- print/setup picotcp network interface information;
> >   * route --- print picotcp routing table;
> >   * picoping --- send ICMP ECHO_REQUEST to network hosts, receive replies;
> >   * picohost --- perform DNS lookup (google DNS server is used);
> >   * app_wget --- download file using the HTTP protocol.
> > 
> > * tcpdump code is incorporated into barebox for network stack debugging.
> >   tcpdump supports parsing most of the protocols supported by barebox
> >   (DHCP, ARP, ICMP, DNS, TFTP and TCP).
> 
> I gave this a test on real hardware. I think the result is similar to
> yours, dhclient, ifconfig, route, picoping, picohost work as expected.
> app_wget does not work, it bails out with a NULL pointer exception.

I have updated my picotcp branches (see [1], [2]). I have tested
picotcp-1.7.0 on my Raspberry Pi 2. app_wget works on Raspberry Pi 2
without any exceptions.

I have found that using picotcp on real hardware has negative effect
on UART console (at least on Praspberry Pi 2 with USB-connected ethernet
adapter): console drops characters from time to time.

> I don't seem to have access to the Google DNS server, I switched this to
> our local nameserver. Here global.net.nameserver should be used finally.
>
> It's a bit odd that barebox and picotcp both use different configs, so
> that we have to call barebox dhcp and also dhclient to make a network
> interface usable in both barebox and picotcp. That should be a solvable
> issue though.

I have fixed this problem. Now dhclient updates ethX.* and global.net.*
variables. Please note that picotcp dhcp client does not handle
rootpath, device tree and tftp server parameters. I think
that we can ignore current disadvantages of dhclient, picoping and picohost.
These commands are used just for demonstration. They are just
slightly reworked demo programs. We have to rework them more
carefully to replace our traditional network commands.

The TCP support is much more attractive feature. app_wget is adapted
example from picotcp-modules repo [3] (not the main picotcp repo!).
app_wget relies on incomplete libhttp library. You can see that app_wget
dumps html-page with wrong offset. I used app_wget just for demonstration
because it was most simple TCP-enabled application.
Now I think that telnet-client/server would be more useful demo program.
Also please note that there is "the old" picotcp-1.7.0 and "the modern"
picotcp-2.1. I have the branch with picotcp-2.1 but it lacks
libhttp support.

My next step is to add tcp-enabled application to picotcp-2.1.

[1] https://github.com/frantony/barebox/tree/20240310.picotcp-1.7.0
[2] https://github.com/frantony/barebox/tree/20240310.picotcp-2.1
[3] https://github.com/tass-belgium/picotcp-modules

-- 
Best regards,
  Antony Pavlov



[PATCH v2] gitignore: ignore *.dtbo and *.dtbo.*

2024-03-05 Thread Antony Pavlov
Signed-off-by: Antony Pavlov 
---
 .gitignore | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/.gitignore b/.gitignore
index f0afd899e1a..5e1b0c2b68f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -38,6 +38,8 @@ binary.0
 Module.symvers
 *.dtb
 *.dtb.*
+*.dtbo
+*.dtbo.*
 
 #
 # Top-level generic files
-- 
2.39.0




[PATCH] gitignore: ignore *.dtbo and *.dtbo.S

2024-03-04 Thread Antony Pavlov
Signed-off-by: Antony Pavlov 
---
 .gitignore | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/.gitignore b/.gitignore
index f0afd899e1a..c9921d83ed1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -38,6 +38,8 @@ binary.0
 Module.symvers
 *.dtb
 *.dtb.*
+*.dtbo
+*.dtbo.S
 
 #
 # Top-level generic files
-- 
2.39.0




barebox + picotcp-1.7.0

2024-03-03 Thread Antony Pavlov
Hi all!

In the message [1] Sascha proposed to have the barebox network stack
and picotcp in parallel.

This approach is used in the branch 20240303.picotcp-1.7.0 from
https://github.com/frantony/barebox/ repo [2]:

* all incoming packets go through the barebox network stack and only if
  they are not processed by it, they are forwarded to the picotcp network
  stack (all incoming ARP packets always go to the picotcp network stack).

* risc-v virtual qemu machine with user networking (slirp network stack)
  is used for demonstration; one needs only qemu risc-v emulator
  for demonstration;

* these barebox commands are introduced for picotcp stack capabilities
  demonstration:

  * dhclient --- setup picotcp network interface using the DHCP protocol;
  * ifconfig --- print/setup picotcp network interface information;
  * route --- print picotcp routing table;
  * picoping --- send ICMP ECHO_REQUEST to network hosts, receive replies;
  * picohost --- perform DNS lookup (google DNS server is used);
  * app_wget --- download file using the HTTP protocol.

* tcpdump code is incorporated into barebox for network stack debugging.
  tcpdump supports parsing most of the protocols supported by barebox
  (DHCP, ARP, ICMP, DNS, TFTP and TCP).

Please comment!

  [1] http://lists.infradead.org/pipermail/barebox/2024-February/045937.html
  [2] https://github.com/frantony/barebox/tree/20240303.picotcp-1.7.0

-- 
Best regards,
  Antony Pavlov



Re: NFSv4 boot support?

2024-02-28 Thread Antony Pavlov
On Wed, 28 Feb 2024 10:20:27 +0100
Sascha Hauer  wrote:


Hi Sascha!

> On Wed, Feb 28, 2024 at 10:26:15AM +0300, Antony Pavlov wrote:
> > On Sat, 17 Feb 2024 09:51:02 +0100
> > Ahmad Fatoum  wrote:
> > 
> > Hi All!
> > 
> > > Hello Antony,
> > > 
> > > On 05.02.24 10:59, Antony Pavlov wrote:
> > > > On Wed, 31 Jan 2024 22:37:50 +0100
> > > > Ahmad Fatoum  wrote:
> > > > 
> > > > Hi All!
> > > > 
> > > >> Hello Dan,
> > > >>
> > > >> On 31.01.24 22:03, Dan Shelton wrote:
> > > >>> Hello!
> > > >>>
> > > >>> Does barebox support booting from a NFSv4 filesystem, e.g. boot from
> > > >>> NFSv4 filesystem into a Linux NFSv4 netroot (diskless machine)?
> > > >>
> > > >> The barebox network stack only does UDP/IP. There have been attempts to
> > > >> bring a TCP stack into barebox, but none have so far succeeded to
> > > >> make it mainline. This is a hard requirement before we can consider
> > > >> supporting NFSv4. I hope that lwIP could fill this gap in the future,
> > > >> but no one is actively continuing this work as far as I am aware[1].
> > > > 
> > > > I have started integration on picotcp into barebox in 2015, see
> > > >   
> > > > https://lore.barebox.org/barebox/1436991230-14251-10-git-send-email-antonynpav...@gmail.com/T/
> > 
> > Actually I made the first attempt to integrate picotcp into barebox in 2014,
> > see http://lists.infradead.org/pipermail/barebox/2014-May/019243.html
> > 
> > 10 years is too long for this task :)
> > 
> > In the message 
> > http://lists.infradead.org/pipermail/barebox/2015-July/024244.html
> > if I understand correctly Sascha asked me to keep network stuff
> > users (tftp, nfs, netconsole) as intact as possible.
> > 
> > At the moment I understand that this task is too hard.
> > 
> > The problem is: the network stuff users don't rely on "a network stack"
> > in the true sense. E.g. tftp_handler() takes an ETHERNET PACKET on
> > it's input, tftp_handler() skips Ethernet and IP stuff by itself
> > and modifies UDP fields directly!
> > 
> > This week I have connected picotcp code to the existing network code
> > in the way that makes it possible to keep dhcp_handler() and
> > ftp_handler() intact. The result is ugly: barebox netdevice driver
> > receives frame from network, pass it to picotcp, picotcp parses
> > network protocol headers and extracts udp payload, next
> > picotcp passes udp payload back to my picotcp-to-barebox adapter,
> > the adapter RECONSTRUCTS ETHERNET PACKET and give it to tftp/dhcp_handler()!
> > This horrible approach creates more problems than it solves!

> So if I understand correctly you tried passing *all* incoming packets to
> picotcp and route some of them back to the barebox network stack.

for every barebox network device I create picotcp network device
which can send packets by picotcp initiative.
net_receive() just calls pico_stack_recv() with corresponding
picotcp network device as an argument, so no code change in drivers/net/.
net_poll() just calls pico_stack_tick().
So all incoming packets go to picotcp only.
Picotcp can send packet if necessary without barebox interraction.

UDP datagrams processed by picotcp routed to corresponding dhcp/tftp_handler().
Are dhcp/tftp_handlers parts of barebox network stack?

> Instead of passing all packets to picotcp, can't we just dispatch the
> incoming packets on a per-port basis in barebox and only pass the ones
> picotcp shall handle to picotcp?

Good idea. I have to try. We can reroute IPv6 traffic to picotcp in 
net_receive()
and reroute TCP/IPv4 traffic to picotcp in net_handle_ip().

> So basically a struct net_connection with the handler set to the picotcp
> receive function?

net_connection handler is set to the normal unamended dhcp/tftp_handlers.

> That way it might be possible to have the barebox network stack and
> picotcp in parallel and port the handlers over to pictotcp one by one.

But I see a problem here. If there is a ARP respond in the incoming traffic
I have no idea there to send it. Both barebox network code and picotcp
can make ARP request. I suppose can just route ARP respond to the both stacks.

But what I have to do if an ARP or ICMP echo __request__ is received?

I suppose it is possible to add some simple dynamic incoming packet filtration 
rules
that can be changed on-the-fly for testing purposes.

-- 
Best regards,
  Antony Pavlov



Re: [PATCH] net: drop unused rarp.h

2024-02-28 Thread Antony Pavlov
On Tue, 27 Feb 2024 10:39:23 +0300
Antony Pavlov  wrote:

Hi All!

Actually there are much more unused header files:

$ git clone https://github.com/barebox/barebox
$ cd barebox
barebox$ for i in $(git grep -h "#.*include" | sed "s/ //g" | grep 
"^#include" | sed "s/^#include[\"<]//g" | sed "s/[>\"]$//g" | sort | uniq); do 
basename $i; done | sort | uniq > /tmp/list1
barebox$ for i in $(find -iname '*.h'); do basename $i; done | sort | uniq 
> /tmp/list2


Show unused header files:

barebox$ for i in $(comm -13 /tmp/list1 /tmp/list2); do find -iname $i 
-type f ; done | grep -v ^./dts/ | sort

./arch/arm/boards/phytec-phycard-omap3/pca-a-l1.h
./arch/arm/include/asm/arch-check.h
./arch/powerpc/include/asm/pci_io.h
./arch/powerpc/include/asm/status_led.h
./arch/x86/include/asm/modes.h
./arch/x86/include/asm/segment.h
./drivers/mtd/nand/atmel/atmel_nand_ecc.h
./drivers/usb/host/ehci-core.h
./fs/fat/ffconf.h
./include/gpiod.h
./include/linux/mtd/ndfc.h
./include/linux/mtd/nftl.h
./include/linux/usb/usbroothubdes.h
./include/mach/imx/ccm.h
./include/mach/imx/devices-imx21.h
./include/mach/imx/devices-imx31.h
./include/mach/imx/devices-imx35.h
./include/mach/imx/devices-imx50.h
./include/mach/imx/habv3-imx25-gencsf.h
./include/mach/imx/iomux-mx21.h
./include/mach/imx/iomux-mx35.h
./include/mach/imx/iomux-mx50.h
./include/mach/omap/intc.h
./include/usb_dfu_trailer.h
./lib/bzlib_private.h
./lib/zstd/zstd_opt.h
./net/nfs.h
./net/rarp.h


Check for false positives:

barebox$ for i in $(comm -13 /tmp/list1 /tmp/list2); do git grep $i ; done  
| grep -v ^dts\/ | grep "#include"

drivers/mtd/nand/atmel/legacy.c:#include "atmel_nand_ecc.h" /* Hardware ECC 
registers */
fs/fat/ff.h:#include "ffconf.h" /* FatFs configuration options */
arch/arm/boards/phytec-phycore-pxa270/lowlevel_init.S:#include 




> Signed-off-by: Antony Pavlov 
> ---
>  net/rarp.h | 23 ---
>  1 file changed, 23 deletions(-)
> 
> diff --git a/net/rarp.h b/net/rarp.h
> deleted file mode 100644
> index 0986b02513f..000
> --- a/net/rarp.h
> +++ /dev/null
> @@ -1,23 +0,0 @@
> -/* SPDX-License-Identifier: GPL-2.0-or-later */
> -/* SPDX-FileCopyrightText: 2000 Wolfgang Denk , DENX Software 
> Engineering */
> -
> -#ifndef __RARP_H__
> -#define __RARP_H__
> -
> -#ifndef __NET_H__
> -#include 
> -#endif /* __NET_H__ */
> -
> -
> -/**/
> -/*
> - *   Global functions and variables.
> - */
> -
> -extern int   RarpTry;
> -
> -extern void RarpRequest (void);  /* Send a RARP request */
> -
> -/**/
> -
> -#endif /* __RARP_H__ */
> -- 
> 2.39.0
> 


-- 
Best regards,
  Antony Pavlov



Re: NFSv4 boot support?

2024-02-27 Thread Antony Pavlov
On Sat, 17 Feb 2024 09:51:02 +0100
Ahmad Fatoum  wrote:

Hi All!

> Hello Antony,
> 
> On 05.02.24 10:59, Antony Pavlov wrote:
> > On Wed, 31 Jan 2024 22:37:50 +0100
> > Ahmad Fatoum  wrote:
> > 
> > Hi All!
> > 
> >> Hello Dan,
> >>
> >> On 31.01.24 22:03, Dan Shelton wrote:
> >>> Hello!
> >>>
> >>> Does barebox support booting from a NFSv4 filesystem, e.g. boot from
> >>> NFSv4 filesystem into a Linux NFSv4 netroot (diskless machine)?
> >>
> >> The barebox network stack only does UDP/IP. There have been attempts to
> >> bring a TCP stack into barebox, but none have so far succeeded to
> >> make it mainline. This is a hard requirement before we can consider
> >> supporting NFSv4. I hope that lwIP could fill this gap in the future,
> >> but no one is actively continuing this work as far as I am aware[1].
> > 
> > I have started integration on picotcp into barebox in 2015, see
> >   
> > https://lore.barebox.org/barebox/1436991230-14251-10-git-send-email-antonynpav...@gmail.com/T/

Actually I made the first attempt to integrate picotcp into barebox in 2014,
see http://lists.infradead.org/pipermail/barebox/2014-May/019243.html

10 years is too long for this task :)

In the message 
http://lists.infradead.org/pipermail/barebox/2015-July/024244.html
if I understand correctly Sascha asked me to keep network stuff
users (tftp, nfs, netconsole) as intact as possible.

At the moment I understand that this task is too hard.

The problem is: the network stuff users don't rely on "a network stack"
in the true sense. E.g. tftp_handler() takes an ETHERNET PACKET on
it's input, tftp_handler() skips Ethernet and IP stuff by itself
and modifies UDP fields directly!

This week I have connected picotcp code to the existing network code
in the way that makes it possible to keep dhcp_handler() and
ftp_handler() intact. The result is ugly: barebox netdevice driver
receives frame from network, pass it to picotcp, picotcp parses
network protocol headers and extracts udp payload, next
picotcp passes udp payload back to my picotcp-to-barebox adapter,
the adapter RECONSTRUCTS ETHERNET PACKET and give it to tftp/dhcp_handler()!
This horrible approach creates more problems than it solves!

I propose another experiment: disable old network
stuff and integrate picotcp with all network applications (dhcp, tftp,
dns etc) on top of picotcp. This approach was used in the
'barebox picotcp integration (2015.06.14)' see
http://lists.infradead.org/pipermail/barebox/2015-June/023749.html
This experiment is not for use in production, probably it will break
compatibility but it will allow us to assess the benefits and drawbacks
of using a picotcp stack.

At the moment I understand that in order to achieve success in barebox
network stack upgrade I need to put more effort into ensuring the
reproducibility of the picotcp demonstration. E.g. in 2015 Sascha was unable
to get my code work, see 
http://lists.infradead.org/pipermail/barebox/2015-July/024304.html


> > At the moment I have WIP barebox-v2023.11 with integrated picotcp 2.1:
> > 
> >   https://github.com/frantony/barebox/tree/20231127.picotcp
> 
> Cool. Looking at Oleksij's repo, it was based on your work. How well does
> picotcp work for you? What open issues remain with the patch stack? Is the
> barebox integration actively used in projects?
> 
> Is https://github.com/tass-belgium/picotcp the official repository? This 
> hasn't
> seen development activity in 5 years. lwIP on the other hand still sees active
> development.
> 
> Regarding the license, inclusion of BSD-licensed code is ok. You can check out
> the LICENSES/ subdirectory for the licenses covering barebox.
> 
> Cheers,
> Ahmad
> 
> 
> 
> 
> >>> We need NFSv4, because it does not need rpcbind, and combines
> >>> filesystem, lockd and other stuff all in one TCP port (2049). Site
> >>> policy also does not allow NFSv2/NFSv3, but allows NFSv4.
> >>
> >> Please note that this only concerns barebox and that kernel nfsroot is
> >> unaffected. You can load kernel and device tree over TFTP and supply a
> >> suitable command line argument to the kernel to use a NFS root.
> >>
> >> The standard net boot target does just that:
> >> https://elixir.bootlin.com/barebox/v2024.01.0/source/defaultenv/defaultenv-2-base/boot/net
> >>
> >> It specifies TCP, but hardcodes v3 currently. I guess we could drop the v3 
> >> and let
> >> the kernel decide on its own what version it will use? If that doesn't 
> >> work, you can
> >> override the file locally in your environment, e.g. via 
> >

[PATCH] net: drop unused rarp.h

2024-02-26 Thread Antony Pavlov
Signed-off-by: Antony Pavlov 
---
 net/rarp.h | 23 ---
 1 file changed, 23 deletions(-)

diff --git a/net/rarp.h b/net/rarp.h
deleted file mode 100644
index 0986b02513f..000
--- a/net/rarp.h
+++ /dev/null
@@ -1,23 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later */
-/* SPDX-FileCopyrightText: 2000 Wolfgang Denk , DENX Software 
Engineering */
-
-#ifndef __RARP_H__
-#define __RARP_H__
-
-#ifndef __NET_H__
-#include 
-#endif /* __NET_H__ */
-
-
-/**/
-/*
- * Global functions and variables.
- */
-
-extern int RarpTry;
-
-extern void RarpRequest (void);/* Send a RARP request */
-
-/**/
-
-#endif /* __RARP_H__ */
-- 
2.39.0




Re: NFSv4 boot support?

2024-02-19 Thread Antony Pavlov
On Sat, 17 Feb 2024 09:51:02 +0100
Ahmad Fatoum  wrote:

Hi Ahmad!

> Hello Antony,
> 
> On 05.02.24 10:59, Antony Pavlov wrote:
> > On Wed, 31 Jan 2024 22:37:50 +0100
> > Ahmad Fatoum  wrote:
> > 
> > Hi All!
> > 
> >> Hello Dan,
> >>
> >> On 31.01.24 22:03, Dan Shelton wrote:
> >>> Hello!
> >>>
> >>> Does barebox support booting from a NFSv4 filesystem, e.g. boot from
> >>> NFSv4 filesystem into a Linux NFSv4 netroot (diskless machine)?
> >>
> >> The barebox network stack only does UDP/IP. There have been attempts to
> >> bring a TCP stack into barebox, but none have so far succeeded to
> >> make it mainline. This is a hard requirement before we can consider
> >> supporting NFSv4. I hope that lwIP could fill this gap in the future,
> >> but no one is actively continuing this work as far as I am aware[1].
> > 
> > I have started integration on picotcp into barebox in 2015, see
> >   
> > https://lore.barebox.org/barebox/1436991230-14251-10-git-send-email-antonynpav...@gmail.com/T/
> > 
> > At the moment I have WIP barebox-v2023.11 with integrated picotcp 2.1:
> > 
> >   https://github.com/frantony/barebox/tree/20231127.picotcp
> 
> Cool. Looking at Oleksij's repo, it was based on your work. How well does
> picotcp work for you? What open issues remain with the patch stack? Is the
> barebox integration actively used in projects?

I don't use picotcp in any of my projects.
It is very experimental feature. At the moment my picotcp branch can't correctly
handle arp processing. Alas at the moment I have no much time to make picotcp 
work.

Instead of integration of picotcp into existing barebox code I think barebox 
needs
some work to make adding new "external" network interface more simple,
so a "new" network stack picotcp/lwIP/uIP/Cyclone/iPXE can be added easely.

> Is https://github.com/tass-belgium/picotcp the official repository? This 
> hasn't
> seen development activity in 5 years.

Please see https://github.com/virtualsquare/picotcp

> lwIP on the other hand still sees active development.

I agree with you. It looks like lwIP is more popular than picotcp.

> Regarding the license, inclusion of BSD-licensed code is ok. You can check out
> the LICENSES/ subdirectory for the licenses covering barebox.

Thanks for the tip, now I see that we can use BSD-licensed code.


> 
> Cheers,
> Ahmad
> 
> 
> 
> 
> >>> We need NFSv4, because it does not need rpcbind, and combines
> >>> filesystem, lockd and other stuff all in one TCP port (2049). Site
> >>> policy also does not allow NFSv2/NFSv3, but allows NFSv4.
> >>
> >> Please note that this only concerns barebox and that kernel nfsroot is
> >> unaffected. You can load kernel and device tree over TFTP and supply a
> >> suitable command line argument to the kernel to use a NFS root.
> >>
> >> The standard net boot target does just that:
> >> https://elixir.bootlin.com/barebox/v2024.01.0/source/defaultenv/defaultenv-2-base/boot/net
> >>
> >> It specifies TCP, but hardcodes v3 currently. I guess we could drop the v3 
> >> and let
> >> the kernel decide on its own what version it will use? If that doesn't 
> >> work, you can
> >> override the file locally in your environment, e.g. via 
> >> CONFIG_DEFAULT_ENVIRONMENT
> >> pointing at a directory that contains a boot/net file with the appropriate
> >> changes (or just call your boot target something else like boot/nfsv4).
> >>
> >> Hope this helps.
> >>
> >> [1]: Some attempts I am aware of:
> >>  https://github.com/a3f/barebox/tree/lwip
> >>  https://github.com/olerem/barebox/tree/picotcp-2019.06.29
> >>  
> >> https://github.com/jmaselbas/barebox/commit/4a987bfdc2ad50c13126dd6290d2477c3fc0c87d
> >>
> >> Cheers,
> >> Ahmad
> >>
> >>>
> >>> Dan
> >>
> >> -- 
> >> Pengutronix e.K.   |         |
> >> Steuerwalder Str. 21   | http://www.pengutronix.de/  |
> >> 31137 Hildesheim, Germany  | Phone: +49-5121-206917-0|
> >> Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |
> >>
> >>
> > 
> > 
> 
> -- 
> Pengutronix e.K.   | |
> Steuerwalder Str. 21   | http://www.pengutronix.de/  |
> 31137 Hildesheim, Germany  | Phone: +49-5121-206917-0|
> Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |
> 


-- 
Best regards,
  Antony Pavlov



Re: NFSv4 boot support?

2024-02-05 Thread Antony Pavlov
On Wed, 31 Jan 2024 22:37:50 +0100
Ahmad Fatoum  wrote:

Hi all!

> Hello Dan,
> 
> On 31.01.24 22:03, Dan Shelton wrote:
> > Hello!
> > 
> > Does barebox support booting from a NFSv4 filesystem, e.g. boot from
> > NFSv4 filesystem into a Linux NFSv4 netroot (diskless machine)?
> 
> The barebox network stack only does UDP/IP. There have been attempts to
> bring a TCP stack into barebox, but none have so far succeeded to
> make it mainline. This is a hard requirement before we can consider
> supporting NFSv4. I hope that lwIP could fill this gap in the future,
> but no one is actively continuing this work as far as I am aware[1].
> 
> > We need NFSv4, because it does not need rpcbind, and combines
> > filesystem, lockd and other stuff all in one TCP port (2049). Site
> > policy also does not allow NFSv2/NFSv3, but allows NFSv4.
> 
> Please note that this only concerns barebox and that kernel nfsroot is
> unaffected. You can load kernel and device tree over TFTP and supply a
> suitable command line argument to the kernel to use a NFS root.
> 
> The standard net boot target does just that:
> https://elixir.bootlin.com/barebox/v2024.01.0/source/defaultenv/defaultenv-2-base/boot/net
> 
> It specifies TCP, but hardcodes v3 currently. I guess we could drop the v3 
> and let
> the kernel decide on its own what version it will use? If that doesn't work, 
> you can
> override the file locally in your environment, e.g. via 
> CONFIG_DEFAULT_ENVIRONMENT
> pointing at a directory that contains a boot/net file with the appropriate
> changes (or just call your boot target something else like boot/nfsv4).
> 
> Hope this helps.
> 
> [1]: Some attempts I am aware of:
>  https://github.com/a3f/barebox/tree/lwip

It looks like lwip is BSD-3-clause-licensed. Can we use the BSD-3-clause code 
in barebox?


>  https://github.com/olerem/barebox/tree/picotcp-2019.06.29
>  
> https://github.com/jmaselbas/barebox/commit/4a987bfdc2ad50c13126dd6290d2477c3fc0c87d

-- 
Best regards,
  Antony Pavlov



Re: NFSv4 boot support?

2024-02-05 Thread Antony Pavlov
On Wed, 31 Jan 2024 22:37:50 +0100
Ahmad Fatoum  wrote:

Hi All!

> Hello Dan,
> 
> On 31.01.24 22:03, Dan Shelton wrote:
> > Hello!
> > 
> > Does barebox support booting from a NFSv4 filesystem, e.g. boot from
> > NFSv4 filesystem into a Linux NFSv4 netroot (diskless machine)?
> 
> The barebox network stack only does UDP/IP. There have been attempts to
> bring a TCP stack into barebox, but none have so far succeeded to
> make it mainline. This is a hard requirement before we can consider
> supporting NFSv4. I hope that lwIP could fill this gap in the future,
> but no one is actively continuing this work as far as I am aware[1].

I have started integration on picotcp into barebox in 2015, see
  
https://lore.barebox.org/barebox/1436991230-14251-10-git-send-email-antonynpav...@gmail.com/T/

At the moment I have WIP barebox-v2023.11 with integrated picotcp 2.1:

  https://github.com/frantony/barebox/tree/20231127.picotcp


> > We need NFSv4, because it does not need rpcbind, and combines
> > filesystem, lockd and other stuff all in one TCP port (2049). Site
> > policy also does not allow NFSv2/NFSv3, but allows NFSv4.
> 
> Please note that this only concerns barebox and that kernel nfsroot is
> unaffected. You can load kernel and device tree over TFTP and supply a
> suitable command line argument to the kernel to use a NFS root.
> 
> The standard net boot target does just that:
> https://elixir.bootlin.com/barebox/v2024.01.0/source/defaultenv/defaultenv-2-base/boot/net
> 
> It specifies TCP, but hardcodes v3 currently. I guess we could drop the v3 
> and let
> the kernel decide on its own what version it will use? If that doesn't work, 
> you can
> override the file locally in your environment, e.g. via 
> CONFIG_DEFAULT_ENVIRONMENT
> pointing at a directory that contains a boot/net file with the appropriate
> changes (or just call your boot target something else like boot/nfsv4).
> 
> Hope this helps.
> 
> [1]: Some attempts I am aware of:
>  https://github.com/a3f/barebox/tree/lwip
>  https://github.com/olerem/barebox/tree/picotcp-2019.06.29
>  
> https://github.com/jmaselbas/barebox/commit/4a987bfdc2ad50c13126dd6290d2477c3fc0c87d
> 
> Cheers,
> Ahmad
> 
> > 
> > Dan
> 
> -- 
> Pengutronix e.K.   | |
> Steuerwalder Str. 21   | http://www.pengutronix.de/  |
> 31137 Hildesheim, Germany  | Phone: +49-5121-206917-0|
> Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |
> 
> 


-- 
Best regards,
  Antony Pavlov



[RFC] uimagefs segmentation fault

2024-01-03 Thread Antony Pavlov
Hi!

I have prepared a linux uImage file for testing my uImage-related patches.

barebox$ dumpimage -l ./defaultenv/defaultenv-2-base/uImage
Image Name:   Linux-6.7.0-rc4-3-ge185a416f
Created:  Wed Jan  3 15:28:27 2024
Image Type:   ARM Linux Kernel Image (uncompressed)
Data Size:6131616 Bytes = 5987.91 KiB = 5.85 MiB
Load Address: 
Entry Point:  

I tryed to mount my uImage under mainline master sandbox barebox:

barebox@Sandbox:/ mount -t uimagefs env/uImage /mnt/
Segmentation fault

The problem is in the uimagefs_add_str(). if s == NULL then strlen() fails:

static int uimagefs_add_str(struct uimagefs_handle *priv, enum uimagefs_type 
type,
char *s)
{
struct uimagefs_handle_data *d;

d = xzalloc(sizeof(*d));
d->type = type;
d->name = xstrdup(uimagefs_type_to_str(type));
d->data = s;
d->size = strlen(s); <<<<<<<<<<<<<<<<<<<<<<<<<<< s == NULL!

list_add_tail(>list, >list);

return 0;
}


It looks like my uImage lacks some attributes, e.g. "os".

So I can propose several solutions for the problem:

1. don't call strlen(s) if s == NULL:

@@ -226,7 +226,7 @@ static int uimagefs_add_str(struct uimagefs_handle *priv, 
enum uimagefs_type typ
d->type = type;
d->name = xstrdup(uimagefs_type_to_str(type));
d->data = s;
-   d->size = strlen(s);
+   d->size = (s != NULL) ? strlen(s) : 0;

list_add_tail(>list, >list);

So we will have empty files (len == 0) for absent attributes.

2. regard the s == NULL situation as error:

@@ -222,6 +222,9 @@ static int uimagefs_add_str(struct uimagefs_handle *priv, 
enum uimagefs_type typ
 {
struct uimagefs_handle_data *d;
 
+   if (!s)
+   return -ENODATA;
+
d = xzalloc(sizeof(*d));
d->type = type;
d->name = xstrdup(uimagefs_type_to_str(type));

So we can't mount uImages without required attributes.

3. don't show absent attributes, e.g.:

@@ -222,6 +222,9 @@ static int uimagefs_add_str(struct uimagefs_handle *priv, 
enum uimagefs_type typ
 {
struct uimagefs_handle_data *d;
 
+   if (!s)
+   return -ENODATA;
+
d = xzalloc(sizeof(*d));
d->type = type;
d->name = xstrdup(uimagefs_type_to_str(type));
@@ -421,7 +421,7 @@ static int __uimage_open(struct uimagefs_handle *priv)
goto err_out;
 
ret = uimagefs_add_os(priv);
-   if (ret)
+   if (ret && ret != -ENODATA)
goto err_out;
 
ret = uimagefs_add_time(priv);


I'm not a skilled uImage user so I have no idea which solution is acceptable 
for the users.

Please comment!

-- 
Best regards,
  Antony Pavlov



[PATCH 2/2] common: Kconfig: TIMESTAMP: fix help

2024-01-03 Thread Antony Pavlov
At the moment CONFIG_TIMESTAMP help text is inherited from U-Boot.
Fix it in accordance with barebox realities.

Signed-off-by: Antony Pavlov 
---
 common/Kconfig | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/common/Kconfig b/common/Kconfig
index c8c23a8e03a..3efa8402b9b 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -533,12 +533,11 @@ config TIMESTAMP
bool
default y
select GREGORIAN_CALENDER
-   prompt "print timestamp information from images"
+   prompt "print timestamp information from uImages"
help
  When CONFIG_TIMESTAMP is selected, the timestamp
- (date and time) of an image is printed by image
- commands like bootm or iminfo. This option is
- automatically enabled when you select CFG_CMD_DATE .
+ (date and time) of an uImage is printed by image
+ commands like bootm or uimage.
 
 menuconfig BOOTM
select UIMAGE
-- 
2.39.0




[PATCH 1/2] uImage: use IS_ENABLED(CONFIG_TIMESTAMP)

2024-01-03 Thread Antony Pavlov
Signed-off-by: Antony Pavlov 
---
 common/uimage.c | 22 --
 fs/uimagefs.c   | 24 ++--
 2 files changed, 22 insertions(+), 24 deletions(-)

diff --git a/common/uimage.c b/common/uimage.c
index 72c37b7d15d..3c9a79d9109 100644
--- a/common/uimage.c
+++ b/common/uimage.c
@@ -29,17 +29,19 @@ static inline int uimage_is_multi_image(struct 
uimage_handle *handle)
 void uimage_print_contents(struct uimage_handle *handle)
 {
struct image_header *hdr = >header;
-#if defined(CONFIG_TIMESTAMP)
-   struct rtc_time tm;
-#endif
+
printf("   Image Name:   %.*s\n", IH_NMLEN, hdr->ih_name);
-#if defined(CONFIG_TIMESTAMP)
-   printf("   Created:  ");
-   to_tm(hdr->ih_time, );
-   printf("%4d-%02d-%02d  %2d:%02d:%02d UTC\n",
-   tm.tm_year, tm.tm_mon, tm.tm_mday,
-   tm.tm_hour, tm.tm_min, tm.tm_sec);
-#endif
+
+   if (IS_ENABLED(CONFIG_TIMESTAMP)) {
+   struct rtc_time tm;
+
+   printf("   Created:  ");
+   to_tm(hdr->ih_time, );
+   printf("%4d-%02d-%02d  %2d:%02d:%02d UTC\n",
+   tm.tm_year, tm.tm_mon, tm.tm_mday,
+   tm.tm_hour, tm.tm_min, tm.tm_sec);
+   }
+
 #if defined(CONFIG_BOOTM_SHOW_TYPE)
printf("   OS:   %s\n", image_get_os_name(hdr->ih_os));
printf("   Architecture: %s\n", image_get_arch_name(hdr->ih_arch));
diff --git a/fs/uimagefs.c b/fs/uimagefs.c
index 7af10ca9864..3099f6a1e62 100644
--- a/fs/uimagefs.c
+++ b/fs/uimagefs.c
@@ -300,28 +300,24 @@ static int uimagefs_add_data_entry(struct uimagefs_handle 
*priv, size_t offset,
return 0;
 }
 
-#if defined(CONFIG_TIMESTAMP)
 static int uimagefs_add_time(struct uimagefs_handle *priv)
 {
struct image_header *header = >header;
-   struct rtc_time tm;
-   char *val;
 
-   to_tm(header->ih_time, );
-   val = basprintf("%4d-%02d-%02d  %2d:%02d:%02d UTC",
-   tm.tm_year, tm.tm_mon, tm.tm_mday,
-   tm.tm_hour, tm.tm_min, tm.tm_sec);
+   if (IS_ENABLED(CONFIG_TIMESTAMP)) {
+   struct rtc_time tm;
+   char *val;
 
-   return uimagefs_add_str(priv, UIMAGEFS_TIME, val);
-}
-#else
-static int uimagefs_add_time(struct uimagefs_handle *priv)
-{
-   struct image_header *header = >header;
+   to_tm(header->ih_time, );
+   val = basprintf("%4d-%02d-%02d  %2d:%02d:%02d UTC",
+   tm.tm_year, tm.tm_mon, tm.tm_mday,
+   tm.tm_hour, tm.tm_min, tm.tm_sec);
+
+   return uimagefs_add_str(priv, UIMAGEFS_TIME, val);
+   }
 
return uimagefs_add_hex(priv, UIMAGEFS_TIME, header->ih_time);
 }
-#endif
 
 static int uimagefs_add_os(struct uimagefs_handle *priv)
 {
-- 
2.39.0




[PATCH 0/2] uImage fixes

2024-01-03 Thread Antony Pavlov
Antony Pavlov (2):
  uImage: use IS_ENABLED(CONFIG_TIMESTAMP)
  common: Kconfig: TIMESTAMP: fix help

 common/Kconfig  |  7 +++
 common/uimage.c | 22 --
 fs/uimagefs.c   | 24 ++--
 3 files changed, 25 insertions(+), 28 deletions(-)

-- 
2.39.0




[PATCH] MIPS: qemu-malta*_defconfig: enable e1000 network driver

2024-01-03 Thread Antony Pavlov
Thanks to Denis Orlov's work on dma_sync_single_for_*()
interface and e1000 patches we can enable e1000 support
on both 32-bit and 64-bit qemu malta boards.

32-bit malta qemu command line:

qemu-system-mips -M malta -cpu 24Kf -m 256M \
-nographic -serial mon:stdio \
-bios images/barebox-qemu-malta.img \
-net user,tftp=$(pwd) -net nic,model=e1000

64-bit malta qemu command line:

qemu-system-mips64el -M malta -cpu MIPS64R2-generic -m 256M \
-nographic -serial mon:stdio \
-bios images/barebox-qemu-malta.img.swapped \
-net user,tftp=$(pwd) -net nic,model=e1000

Barebox commands to check e1000 network interface:

barebox@qemu malta:/ devinfo eth0
Parent: pci-8086:100e.0
Parameters:
  ethaddr: 52:54:00:12:34:56 (type: MAC)
  gateway: 0.0.0.0 (type: ipv4)
  ipaddr: 0.0.0.0 (type: ipv4)
  linux.bootargs:  (type: string)
  linux.devname:  (type: string)
  mode: dhcp (type: enum) (values: "dhcp", "static", "disabled")
  netmask: 0.0.0.0 (type: ipv4)
  serverip:  (type: string)
barebox@qemu malta:/ devinfo pci-8086:100e.0
Driver: e1000
Bus: pci
Parameters:
  class: 0200 (type: string)
  devfn: 90 (type: string)
  device: 100e (type: string)
  revision: 0003 (type: string)
  vendor: 8086 (type: string)
barebox@qemu malta:/ dhcp eth0
eth0: DHCP client bound to address 10.0.2.15
barebox@qemu malta:/ tftp images/barebox-qemu-malta.img
[####]

Signed-off-by: Antony Pavlov 
---
 arch/mips/configs/qemu-malta64el_defconfig | 1 +
 arch/mips/configs/qemu-malta_defconfig | 1 +
 2 files changed, 2 insertions(+)

diff --git a/arch/mips/configs/qemu-malta64el_defconfig 
b/arch/mips/configs/qemu-malta64el_defconfig
index da3396246d5..c1f7366d76d 100644
--- a/arch/mips/configs/qemu-malta64el_defconfig
+++ b/arch/mips/configs/qemu-malta64el_defconfig
@@ -63,6 +63,7 @@ CONFIG_NET_NETCONSOLE=y
 CONFIG_OFDEVICE=y
 CONFIG_OF_BAREBOX_DRIVERS=y
 CONFIG_VIRTIO_CONSOLE=y
+CONFIG_DRIVER_NET_E1000=y
 CONFIG_DRIVER_NET_RTL8139=y
 CONFIG_DRIVER_NET_VIRTIO=y
 # CONFIG_SPI is not set
diff --git a/arch/mips/configs/qemu-malta_defconfig 
b/arch/mips/configs/qemu-malta_defconfig
index 4be05b7e5a3..99714aa3068 100644
--- a/arch/mips/configs/qemu-malta_defconfig
+++ b/arch/mips/configs/qemu-malta_defconfig
@@ -60,6 +60,7 @@ CONFIG_NET_NETCONSOLE=y
 CONFIG_OFDEVICE=y
 CONFIG_OF_BAREBOX_DRIVERS=y
 CONFIG_VIRTIO_CONSOLE=y
+CONFIG_DRIVER_NET_E1000=y
 CONFIG_DRIVER_NET_RTL8139=y
 CONFIG_DRIVER_NET_VIRTIO=y
 # CONFIG_SPI is not set
-- 
2.39.0




[PATCH] MIPS: asm/pbl_nmon.h: add guard macro

2024-01-01 Thread Antony Pavlov
Signed-off-by: Antony Pavlov 
---
 arch/mips/include/asm/pbl_nmon.h | 5 +
 1 file changed, 5 insertions(+)

diff --git a/arch/mips/include/asm/pbl_nmon.h b/arch/mips/include/asm/pbl_nmon.h
index 7c8ec9d204f..73e4a9d2e9c 100644
--- a/arch/mips/include/asm/pbl_nmon.h
+++ b/arch/mips/include/asm/pbl_nmon.h
@@ -5,6 +5,9 @@
  * Copyright (C) 2013 Antony Pavlov 
  */
 
+#ifndef __ASM_PBL_NMON_H
+#define __ASM_PBL_NMON_H
+
 #include 
 
 #define CODE_ESC   0x1b
@@ -286,3 +289,5 @@
 #endif /* CONFIG_NMON */
.setpop
.endm
+
+#endif /* __ASM_PBL_NMON_H */
-- 
2.39.0




Re: barebox.org browser demo uses barebox-v2022.02

2023-11-26 Thread Antony Pavlov
On Fri, 24 Nov 2023 08:22:27 +0100
Ahmad Fatoum  wrote:

Hi Ahmad!

> On 24.11.23 07:57, Ahmad Fatoum wrote:
> > Hi Antony,
> > 
> > On 06.10.23 12:24, Ahmad Fatoum wrote:
> >> Hello Antony,
> >>
> >> On 30.09.23 11:17, Antony Pavlov wrote:
> >>> Hi Ahmad!
> >>>
> >>> barebox browser demo (https://www.barebox.org/jsbarebox/) looks very 
> >>> impressive.
> >>> But it uses old barebox-v2022.02. Could you update it please.
> >>
> >> You're right. I will try to find some time to update it. Eventually, I'd 
> >> like
> >> the tutorial to actually boot a kernel as well and have at 
> >> github.com/barebox/
> >> a separate project (maybe Yocto-based?) that builds all the necessary 
> >> artifacts,
> >> but there's still some work to be done until we can do that...
> > 
> > I have updated it to v2023.10.0. Sorry for the delay.
> > To use it, you'll have to clear browser cache for the site.
> > 
> > If you know how one could force an update for cache older than a given time,
> > I'd be happy to add that.
> 
> We have migrated the barebox.org host a while back and Leonard tells me that
> the HTTP header now sports the correct Last-Modified timestamp, so manual
> cache clearing shouldn't be necessary anymore to force a new version.
> 
> Can you confirm?

Thanks for updating demo!

I have no browser cache issue. The browser demo works perfectly!

I see only one thing that can confuse a new user: the blue uncommented toggle 
button is used for
selecting demo mode "just console" (default) or "doom autoboot". I propose to 
add more instruction
on running Doom or even change toggle button to radio buttons with appropriate 
comments.

> > 
> >>
> >>>
> >>> As barebox browser demo runs on top of RISC-V machine can we add RISC-V 
> >>> mention
> >>> to barebox.org/index.html page?
> >>
> >> I guess. Sascha, is that ok for you?
> > 
> > I went ahead and replaced PowerPC with RISC-V. Sascha, let me know if that's
> > not ok.
> > 
> > Cheers,
> > Ahmad
> > 
> >>
> >> Cheers,
> >> Ahmad

-- 
Best regards,
  Antony Pavlov



[PATCH 2/2] MIPS: qemu-malta*_defconfig: enable virtio network driver

2023-11-23 Thread Antony Pavlov
Signed-off-by: Antony Pavlov 
---
 arch/mips/configs/qemu-malta64el_defconfig | 1 +
 arch/mips/configs/qemu-malta_defconfig | 1 +
 2 files changed, 2 insertions(+)

diff --git a/arch/mips/configs/qemu-malta64el_defconfig 
b/arch/mips/configs/qemu-malta64el_defconfig
index 6091e6d0301..da3396246d5 100644
--- a/arch/mips/configs/qemu-malta64el_defconfig
+++ b/arch/mips/configs/qemu-malta64el_defconfig
@@ -64,6 +64,7 @@ CONFIG_OFDEVICE=y
 CONFIG_OF_BAREBOX_DRIVERS=y
 CONFIG_VIRTIO_CONSOLE=y
 CONFIG_DRIVER_NET_RTL8139=y
+CONFIG_DRIVER_NET_VIRTIO=y
 # CONFIG_SPI is not set
 CONFIG_I2C=y
 CONFIG_I2C_GPIO=y
diff --git a/arch/mips/configs/qemu-malta_defconfig 
b/arch/mips/configs/qemu-malta_defconfig
index 6cbc4efa86f..4be05b7e5a3 100644
--- a/arch/mips/configs/qemu-malta_defconfig
+++ b/arch/mips/configs/qemu-malta_defconfig
@@ -61,6 +61,7 @@ CONFIG_OFDEVICE=y
 CONFIG_OF_BAREBOX_DRIVERS=y
 CONFIG_VIRTIO_CONSOLE=y
 CONFIG_DRIVER_NET_RTL8139=y
+CONFIG_DRIVER_NET_VIRTIO=y
 # CONFIG_SPI is not set
 CONFIG_I2C=y
 CONFIG_I2C_GPIO=y
-- 
2.39.0




[PATCH 0/2] virtio: ring: fix erroneous behavior on MIPS

2023-11-23 Thread Antony Pavlov
Antony Pavlov (2):
  virtio: ring: fix erroneous behavior on MIPS
  MIPS: qemu-malta*_defconfig: enable virtio network driver

 arch/mips/configs/qemu-malta64el_defconfig | 1 +
 arch/mips/configs/qemu-malta_defconfig | 1 +
 drivers/virtio/virtio_ring.c   | 4 ++--
 3 files changed, 4 insertions(+), 2 deletions(-)

-- 
2.39.0




[PATCH 1/2] virtio: ring: fix erroneous behavior on MIPS

2023-11-23 Thread Antony Pavlov
How to reproduce the crash on the 64-bit malta board:

export ARCH=mips
export CROSS_COMPILE=mips-linux-gnu-
make qemu-malta64el_defconfig
sed -i "s/# \(CONFIG_DRIVER_NET_VIRTIO\).*$/\1=y/" .config
make oldconfig
make
...
qemu-system-mips64el -m 256 -M malta -cpu MIPS64R2-generic \
-bios ./images/barebox-qemu-malta.img.swapped \
-nodefaults -nographic \
-serial mon:stdio \
-net nic,model=virtio-net-pci -net user
...
barebox@qemu malta:/ dhcp
WARNING: eth0: No MAC address set. Using random address 9e:85:56:74:55:bb

Ooops, TLB miss on load or ifetch!

$ 0   :  0004 000c 0001
$ 4   : afb7fee8 0fb7402c 024e 0020
$ 8   : 0001 0001 0110 afba6df0
$12   : 0008 affc9584 0001 646e617220676e69
$16   : afb7fee8 afb6fee8 b2d05e00 affeb090
$20   : afb800c0 0100 0122 afb800f0
$24   : 0006 aff93974
$28   :  afb5f9f0 afff aff7a6e4
Hi: 
Lo: 000235e8a800
epc   : affb5db0
ra: aff7a6e4
Status: 0082
Cause : 0408
Config: 80004482
BadVA : 0fb74039

Signed-off-by: Antony Pavlov 
---
 drivers/virtio/virtio_ring.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index fd21d3adcdb..0efe1e00250 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -256,8 +256,8 @@ void *virtqueue_get_buf(struct virtqueue *vq, unsigned int 
*len)
virtio_store_mb(_used_event(>vring),
cpu_to_virtio16(vq->vdev, vq->last_used_idx));
 
-   return (void *)(uintptr_t)virtio64_to_cpu(vq->vdev,
- vq->vring.desc[i].addr);
+   return IOMEM((uintptr_t)virtio64_to_cpu(vq->vdev,
+ vq->vring.desc[i].addr));
 }
 
 static struct virtqueue *__vring_new_virtqueue(unsigned int index,
-- 
2.39.0




[PATCH] MIPS: qemu-malta: use 320 MHz input clock for CP0 clocksource

2023-10-30 Thread Antony Pavlov
Modern qemu uses 24Kf CPU at 320 MHz for malta board.
By default arch/mips/lib/csrc-r4k.c clocksource driver
relies on CPU running at 200 MHz and CP0 timer runs
at the half of CPU clock that is 100 MHz.
As a result the `sleep 15` command runs for only
9 seconds on qemu-malta.

Setting CPU clock to 320 MHz in the qemu-malta.dts file
fixes the problem.

See these qemu commits for details:

  eea1f5bac6f hw/mips/malta: Set CPU frequency to 320 MHz
  a7519f2b39b mips: malta/boston: replace cpu_model with cpu_type

Signed-off-by: Antony Pavlov 
---
 arch/mips/Kconfig|  3 +++
 arch/mips/dts/qemu-malta.dts | 20 
 2 files changed, 23 insertions(+)

diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index e05ee2d7f1a..89fc16be133 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -79,6 +79,9 @@ config MACH_MIPS_MALTA
select SYS_SUPPORTS_BIG_ENDIAN
select SYS_SUPPORTS_LITTLE_ENDIAN
select HAS_DEBUG_LL
+   select COMMON_CLK
+   select COMMON_CLK_OF_PROVIDER
+   select CLKDEV_LOOKUP
select GPIOLIB
select HW_HAS_PCI
select HAVE_PBL_IMAGE
diff --git a/arch/mips/dts/qemu-malta.dts b/arch/mips/dts/qemu-malta.dts
index f08832735f8..c2bc03dd463 100644
--- a/arch/mips/dts/qemu-malta.dts
+++ b/arch/mips/dts/qemu-malta.dts
@@ -19,6 +19,26 @@ memory@0 {
reg = <0x 0x1000>;
};
 
+   clocks {
+   ref_clk: ref_clk {
+   #clock-cells = <0>;
+   compatible = "fixed-clock";
+   clock-frequency = <32000>;
+   };
+   };
+
+   cpus {
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   cpu@0 {
+   device_type = "cpu";
+   compatible = "mips,mips24Kf";
+   clocks = <_clk>;
+   reg = <0>;
+   };
+   };
+
uart0: serial@180003f8 {
compatible = "ns16550a";
reg = <0x180003f8 0x08>;
-- 
2.39.0




Re: v2023.10.0

2023-10-25 Thread Antony Pavlov
On Tue, 24 Oct 2023 11:29:04 +0200
Sascha Hauer  wrote:

> Hi All,
> 
> We finally have a release for October.

I see the v2023.10.0 tag in the https://github.com/barebox/barebox repo
but no such tag in the git://git.pengutronix.de/git/barebox.git repo.

-- 
Best regards,
  Antony Pavlov



barebox.org browser demo uses barebox-v2022.02

2023-09-30 Thread Antony Pavlov
Hi Ahmad!

barebox browser demo (https://www.barebox.org/jsbarebox/) looks very impressive.
But it uses old barebox-v2022.02. Could you update it please.

As barebox browser demo runs on top of RISC-V machine can we add RISC-V mention
to barebox.org/index.html page?

-- 
Best regards,
  Antony Pavlov



Re: [RFC 0/4] Run barebox on sc6531e-based feature phone

2023-07-05 Thread Antony Pavlov
On Tue, 4 Jul 2023 14:03:56 +0200
Sascha Hauer  wrote:

> Hi Antony,
> 
> This has stayed unanswered for some time.
> 
> I am not sure what I should do with it. In the current form I think it's
> a bit too basic to be useful. Maybe we can add it once the LCD and
> Keypad driver is ready?

It's just RFC. With LCD and keypad support SC6531E barebox port will be a nice
demo for barebox presentation and can be added to mainline repo.

There are some ready-to-use SC6531E drivers in the 
https://github.com/strongtz/linux-sprd repo.
LCD display is connected via SPI so drivers/spi/spi-sprd.c can be used,
also we need backlight driver.
Keypad is supported by drivers/input/keyboard/sprd_keypad.c.


> Sascha
> 
> On Sat, Jun 10, 2023 at 01:32:16PM +0300, Antony Pavlov wrote:
> > This patch series adds initial support for SC6531E chip.
> > 
> > SC6431E chip is specially designed solution for creating
> > feature phones. It contains
> > 
> >   * ARM926EJ-S core (up to 208 MHz)
> >   * embedded PSRAM
> >   * peripherals: USB, SPI, UART, IIS, PCM, I2C, keypad, LCD
> >   * SIM card and GSM/GPRS/FM/BT stuff
> > 
> > This work is based on FPDoom, see [1], [2], [3] for details.
> > 
> > At the moment only timer and debug_ll output via USB
> > are supported.
> > 
> > After adding lcd and keypad driver running bareDOOM [4]
> > on SC6531E will be possible.
> > 
> >   [1] https://github.com/ilyakurdyukov/fpdoom
> >   [2] https://habr.com/ru/articles/706766/
> >   [3] https://www.youtube.com/watch?v=tln_Iace1O8
> >   [4] https://github.com/a3f/bareDOOM
> > 
> > Antony Pavlov (4):
> >   clocksource: add sc6531e driver
> >   ARM: add sc6531e and F+ Ezzy 4 phone support
> >   sc6531e: add debug_ll support
> >   Documentation: add sc6531e instructions
> > 
> >  Documentation/boards/sc6531e.rst  | 187 +
> >  arch/arm/Kconfig  |  10 +
> >  arch/arm/Makefile |   1 +
> >  arch/arm/boards/Makefile  |   1 +
> >  arch/arm/boards/ezzy-4/Makefile   |   6 +
> >  arch/arm/boards/ezzy-4/env/init/automount |  27 ++
> >  arch/arm/boards/ezzy-4/lowlevel.c |  19 +
> >  arch/arm/boards/ezzy-4/usbio.c| 449 ++
> >  arch/arm/configs/ezzy-4_defconfig |  49 +++
> >  arch/arm/cpu/uncompress.c |   7 +
> >  arch/arm/dts/Makefile |   1 +
> >  arch/arm/dts/ezzy-4.dts   |  22 ++
> >  arch/arm/include/asm/debug_ll.h   |   2 +
> >  arch/arm/mach-sc6531e/Kconfig |  17 +
> >  arch/arm/mach-sc6531e/Makefile|   3 +
> >  drivers/clocksource/Makefile  |   1 +
> >  drivers/clocksource/timer-sc6531e.c   |  70 
> >  include/mach/sc6531e/debug_ll.h   |  17 +
> >  18 files changed, 889 insertions(+)
> >  create mode 100644 Documentation/boards/sc6531e.rst
> >  create mode 100644 arch/arm/boards/ezzy-4/Makefile
> >  create mode 100644 arch/arm/boards/ezzy-4/env/init/automount
> >  create mode 100644 arch/arm/boards/ezzy-4/lowlevel.c
> >  create mode 100644 arch/arm/boards/ezzy-4/usbio.c
> >  create mode 100644 arch/arm/configs/ezzy-4_defconfig
> >  create mode 100644 arch/arm/dts/ezzy-4.dts
> >  create mode 100644 arch/arm/mach-sc6531e/Kconfig
> >  create mode 100644 arch/arm/mach-sc6531e/Makefile
> >  create mode 100644 drivers/clocksource/timer-sc6531e.c
> >  create mode 100644 include/mach/sc6531e/debug_ll.h
> > 
> > -- 
> > 2.39.0
> > 
> > 
> 
> -- 
> Pengutronix e.K.   | |
> Steuerwalder Str. 21   | http://www.pengutronix.de/  |
> 31137 Hildesheim, Germany  | Phone: +49-5121-206917-0|
> Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |


-- 
Best regards,
  Antony Pavlov



[RFC 1/4] clocksource: add sc6531e driver

2023-06-10 Thread Antony Pavlov
Signed-off-by: Antony Pavlov 
---
 drivers/clocksource/Makefile|  1 +
 drivers/clocksource/timer-sc6531e.c | 70 +
 2 files changed, 71 insertions(+)

diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile
index eceaa990d43..863a7e931cf 100644
--- a/drivers/clocksource/Makefile
+++ b/drivers/clocksource/Makefile
@@ -26,3 +26,4 @@ obj-$(CONFIG_CLINT_TIMER) += timer-clint.o
 obj-$(CONFIG_RISCV_TIMER) += timer-riscv.o
 obj-$(CONFIG_ARMV7M_SYSTICK) += armv7m_systick.o
 obj-$(CONFIG_CLKSRC_STM32) += timer-stm32.o
+obj-$(CONFIG_ARCH_SC6531E) += timer-sc6531e.o
diff --git a/drivers/clocksource/timer-sc6531e.c 
b/drivers/clocksource/timer-sc6531e.c
new file mode 100644
index 000..c5f095f1a2e
--- /dev/null
+++ b/drivers/clocksource/timer-sc6531e.c
@@ -0,0 +1,70 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2023 Antony Pavlov 
+ *
+ * This file is part of barebox.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#define SC6531E_TIMER_CLOCK 1000
+
+#define SYST_VALUE_SHDW 0x0c
+
+static void __iomem *timer_base;
+
+static uint64_t sc6531e_cs_read(void)
+{
+   return (uint64_t)readl(timer_base + SYST_VALUE_SHDW);
+}
+
+static struct clocksource sc6531e_cs = {
+   .read   = sc6531e_cs_read,
+   .mask   = CLOCKSOURCE_MASK(32),
+   .priority = 60,
+};
+
+static int sc6531e_timer_probe(struct device *dev)
+{
+   struct resource *iores;
+
+   /* use only one timer */
+   if (timer_base)
+   return -EBUSY;
+
+   iores = dev_request_mem_resource(dev, 0);
+   if (IS_ERR(iores)) {
+   dev_err(dev, "could not get memory region\n");
+   return PTR_ERR(iores);
+   }
+
+   timer_base = IOMEM(iores->start);
+   clocks_calc_mult_shift(_cs.mult, _cs.shift,
+   SC6531E_TIMER_CLOCK, NSEC_PER_SEC, 1);
+
+   init_clock(_cs);
+
+   return 0;
+}
+
+static __maybe_unused struct of_device_id sc6531e_timer_dt_ids[] = {
+   {
+   .compatible = "sc6531e-timer",
+   }, {
+   /* sentinel */
+   }
+};
+
+static struct driver sc6531e_timer_driver = {
+   .probe  = sc6531e_timer_probe,
+   .name   = "sc6531e-timer",
+   .of_compatible = DRV_OF_COMPAT(sc6531e_timer_dt_ids),
+};
+
+coredevice_platform_driver(sc6531e_timer_driver);
-- 
2.39.0




[RFC 0/4] Run barebox on sc6531e-based feature phone

2023-06-10 Thread Antony Pavlov
This patch series adds initial support for SC6531E chip.

SC6431E chip is specially designed solution for creating
feature phones. It contains

  * ARM926EJ-S core (up to 208 MHz)
  * embedded PSRAM
  * peripherals: USB, SPI, UART, IIS, PCM, I2C, keypad, LCD
  * SIM card and GSM/GPRS/FM/BT stuff

This work is based on FPDoom, see [1], [2], [3] for details.

At the moment only timer and debug_ll output via USB
are supported.

After adding lcd and keypad driver running bareDOOM [4]
on SC6531E will be possible.

  [1] https://github.com/ilyakurdyukov/fpdoom
  [2] https://habr.com/ru/articles/706766/
  [3] https://www.youtube.com/watch?v=tln_Iace1O8
  [4] https://github.com/a3f/bareDOOM

Antony Pavlov (4):
  clocksource: add sc6531e driver
  ARM: add sc6531e and F+ Ezzy 4 phone support
  sc6531e: add debug_ll support
  Documentation: add sc6531e instructions

 Documentation/boards/sc6531e.rst  | 187 +
 arch/arm/Kconfig  |  10 +
 arch/arm/Makefile |   1 +
 arch/arm/boards/Makefile  |   1 +
 arch/arm/boards/ezzy-4/Makefile   |   6 +
 arch/arm/boards/ezzy-4/env/init/automount |  27 ++
 arch/arm/boards/ezzy-4/lowlevel.c |  19 +
 arch/arm/boards/ezzy-4/usbio.c| 449 ++
 arch/arm/configs/ezzy-4_defconfig |  49 +++
 arch/arm/cpu/uncompress.c |   7 +
 arch/arm/dts/Makefile |   1 +
 arch/arm/dts/ezzy-4.dts   |  22 ++
 arch/arm/include/asm/debug_ll.h   |   2 +
 arch/arm/mach-sc6531e/Kconfig |  17 +
 arch/arm/mach-sc6531e/Makefile|   3 +
 drivers/clocksource/Makefile  |   1 +
 drivers/clocksource/timer-sc6531e.c   |  70 
 include/mach/sc6531e/debug_ll.h   |  17 +
 18 files changed, 889 insertions(+)
 create mode 100644 Documentation/boards/sc6531e.rst
 create mode 100644 arch/arm/boards/ezzy-4/Makefile
 create mode 100644 arch/arm/boards/ezzy-4/env/init/automount
 create mode 100644 arch/arm/boards/ezzy-4/lowlevel.c
 create mode 100644 arch/arm/boards/ezzy-4/usbio.c
 create mode 100644 arch/arm/configs/ezzy-4_defconfig
 create mode 100644 arch/arm/dts/ezzy-4.dts
 create mode 100644 arch/arm/mach-sc6531e/Kconfig
 create mode 100644 arch/arm/mach-sc6531e/Makefile
 create mode 100644 drivers/clocksource/timer-sc6531e.c
 create mode 100644 include/mach/sc6531e/debug_ll.h

-- 
2.39.0




[RFC 4/4] Documentation: add sc6531e instructions

2023-06-10 Thread Antony Pavlov
Signed-off-by: Antony Pavlov 
---
 Documentation/boards/sc6531e.rst | 187 +++
 1 file changed, 187 insertions(+)

diff --git a/Documentation/boards/sc6531e.rst b/Documentation/boards/sc6531e.rst
new file mode 100644
index 000..cbda8b6def0
--- /dev/null
+++ b/Documentation/boards/sc6531e.rst
@@ -0,0 +1,187 @@
+SC6531E
+===
+
+F+ Ezzy 4
+-
+
+Barebox has limited support for the SC6531E-based feature phones::
+
+  ARCH=arm make ezzy-4_defconfig
+  ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- make
+
+The resulting ``./images/barebox.img`` can be loaded with
+``spd_dump`` utility::
+
+  git clone https://github.com/ilyakurdyukov/spreadtrum_flash
+  ( cd spreadtrum_flash && git log -1 --pretty='%h %s' && make )
+  6886a85 Readme update about smartphones.
+  
+  wget 
https://github.com/ilyakurdyukov/fpdoom/releases/download/1.20230513/fpdoom.zip
+  unzip fpdoom.zip nor_fdl1.bin
+  
+  git clone https://github.com/ilyakurdyukov/fpdoom
+  ( cd fpdoom/libc_server && git log -1 --pretty='%h %s' && make )
+  cc90d2a faster usb io
+  
+  ./spreadtrum_flash/spd_dump --wait 300 fdl nor_fdl1.bin 0x40004000 fdl 
images/barebox.img ram && ./fpdoom/libc_server/libc_server
+
+  BSL_REP_VER: "SPRD3\0"
+  BSL_REP_VER: "Custom FDL1: CHIP ID = 0x65620001\0"
+  + ./fpdoom/libc_server/libc_server
+  !!! debug_ll
+  
+  Hello world
+  
+  start.c: memory at 0x1400, size 0x0040
+  start.c: found DTB in boarddata, copying to 0x142ffe80
+  start.c: initializing malloc pool at 0x141ffe80 (size 0x0010)
+  start.c: starting barebox...
+  initcall-> 0x143021fc
+  initcall-> 0x14307040
+  initcall-> 0x1430d598
+  initcall-> 0x1430dfd8
+  initcall-> 0x143263f4
+  initcall-> 0x1432a9c0
+  start.c: barebox_arm_boot_dtb: using barebox_boarddata
+  initcall-> 0x143012fc
+  initcall-> 0x143120f0
+  initcall-> 0x1432602c
+  initcall-> 0x14312060
+  initcall-> 0x14310844
+  initcall-> 0x14300058
+  initcall-> 0x14312390
+  initcall-> 0x14300590
+  initcall-> 0x1430bfe8
+  initcall-> 0x1430d6e4
+  initcall-> 0x143233fc
+  initcall-> 0x14324b7c
+  initcall-> 0x14325a10
+  initcall-> 0x14329c74
+  initcall-> 0x14301238
+  initcall-> 0x143090bc
+  initcall-> 0x14300dc8
+  initcall-> 0x143018ac
+  initcall-> 0x14304b8c
+  initcall-> 0x1430dbd0
+  initcall-> 0x1430de24
+  initcall-> 0x14312268
+  initcall-> 0x143127fc
+  initcall-> 0x143127bc
+  initcall-> 0x1431277c
+  initcall-> 0x1431273c
+  initcall-> 0x14323224
+  initcall-> 0x1432a228
+  initcall-> 0x143109ac
+  initcall-> 0x143000cc
+  initcall-> 0x14300b00
+  initcall-> 0x14303244
+  initcall-> 0x143049c0
+  initcall-> 0x14308588
+  malloc space: 0x141ffe80 -> 0x142ffe7f (size 1 MiB)
+  initcall-> 0x143088a0
+  initcall-> 0x1430b920
+  initcall-> 0x1430cf14
+  initcall-> 0x1430d794
+  initcall-> 0x14310fe4
+  initcall-> 0x1432af50
+  initcall-> 0x143012bc
+  environment load /dev/env0: No such file or directory
+  Maybe you have to create the partition.
+  initcalls done
+  Executing '/env/init/automount'...
+  
+  barebox 2023.05.0-00182-g726a6ded65fc-dirty #1 Sat Jun 10 10:50:06 MSK 2023
+  
+  
+  
+  Information commands:
+?, cpuinfo, devinfo, drvinfo, gpioinfo, help, iomem, meminfo, version
+  Boot commands:
+boot, go
+  Partition commands:
+automount
+  Environment commands:
+export, global, nv, setenv
+  File commands:
+basename, cat, cd, cp, digest, dirname, ll, ls, md5sum, mkdir, readlink, rm
+rmdir, sha1sum
+  Scripting commands:
+., :, [, exit, false, getopt, let, msleep, sh, sleep, source, test, true
+  Console commands:
+echo, edit, sedit, timeout, vi
+  Memory commands:
+md, memcmp, memcpy, memset, memtest, mm, mw
+  Hardware manipulation commands:
+gpio_direction_input, gpio_direction_output, gpio_get_value, gpio_set_value
+led
+  Miscellaneous commands:
+of_dump, of_node, of_property, oftree, time, uptime
+  Use 'help COMMAND' for more details.
+  
+  
+  implementer: ARM
+  architecture: v5TEJ
+  I-cache: 8192 bytes (linelen = 32)
+  D-cache: 8192 bytes (linelen = 32)
+  Control register: A W P D L I DT IT 
+  
+  0x - 0x (size 0x) iomem
+0x1400 - 0x143f (size 0x0040) ram0
+  0x141ffe80 - 0x142ffe7f (size 0x0010) malloc space
+  0x142ffe80 - 0x142e (size 0x017f) board data
+  0x1430 - 0x1433149f (size 0x000314a0) barebox
+  0x143314a0 - 0x14333fbf (size 0x2b20) barebox data
+  0x14333fc0 - 0x14336973 (size 0x29b4) bss
+  0x143f - 0x143f7fff (size 0x8000) stack
+0x81003000 - 0x810030ff (size 0x0100) 81003000.ti...@81003000.of
+  
+  Maximum system memory: 139648
+  Current system memory: 139648
+  in use: 136240
+  
+   {
+  model = "F+ Ezzy 4";
+

[RFC 2/4] ARM: add sc6531e and F+ Ezzy 4 phone support

2023-06-10 Thread Antony Pavlov
Signed-off-by: Antony Pavlov 
---
 arch/arm/Kconfig  |  9 +
 arch/arm/Makefile |  1 +
 arch/arm/boards/Makefile  |  1 +
 arch/arm/boards/ezzy-4/Makefile   |  3 ++
 arch/arm/boards/ezzy-4/env/init/automount | 27 +
 arch/arm/boards/ezzy-4/lowlevel.c | 19 +
 arch/arm/configs/ezzy-4_defconfig | 49 +++
 arch/arm/dts/Makefile |  1 +
 arch/arm/dts/ezzy-4.dts   | 22 ++
 arch/arm/mach-sc6531e/Kconfig | 17 
 arch/arm/mach-sc6531e/Makefile|  3 ++
 11 files changed, 152 insertions(+)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index e76ee0f6dfe..b46d73f5084 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -84,6 +84,14 @@ config ARCH_DIGIC
help
  Support for Canon's digital cameras that use the DIGIC4 chip.
 
+config ARCH_SC6531E
+   bool "SC6531E-based devices"
+   depends on 32BIT
+   select CPU_ARM926T
+   select GPIOLIB
+   help
+ Support for feature phones based on the SC6531E chipset.
+
 config ARCH_EP93XX
bool "Cirrus Logic EP93xx"
depends on 32BIT
@@ -330,6 +338,7 @@ source "arch/arm/mach-nomadik/Kconfig"
 source "arch/arm/mach-omap/Kconfig"
 source "arch/arm/mach-pxa/Kconfig"
 source "arch/arm/mach-rockchip/Kconfig"
+source "arch/arm/mach-sc6531e/Kconfig"
 source "arch/arm/mach-socfpga/Kconfig"
 source "arch/arm/mach-stm32mp/Kconfig"
 source "arch/arm/mach-versatile/Kconfig"
diff --git a/arch/arm/Makefile b/arch/arm/Makefile
index 2208b071ac1..96a32aca8b4 100644
--- a/arch/arm/Makefile
+++ b/arch/arm/Makefile
@@ -104,6 +104,7 @@ machine-$(CONFIG_ARCH_OMAP) += omap
 machine-$(CONFIG_ARCH_PXA) += pxa
 machine-$(CONFIG_ARCH_ROCKCHIP)+= rockchip
 machine-$(CONFIG_ARCH_SAMSUNG) += samsung
+machine-$(CONFIG_ARCH_SC6531E) += sc6531e
 machine-$(CONFIG_ARCH_SOCFPGA) += socfpga
 machine-$(CONFIG_ARCH_STM32MP) += stm32mp
 machine-$(CONFIG_ARCH_VERSATILE)   += versatile
diff --git a/arch/arm/boards/Makefile b/arch/arm/boards/Makefile
index 2877debad53..8abd8872757 100644
--- a/arch/arm/boards/Makefile
+++ b/arch/arm/boards/Makefile
@@ -44,6 +44,7 @@ obj-$(CONFIG_MACH_EMBEST_MARSBOARD)   += 
embest-marsboard/
 obj-$(CONFIG_MACH_EMBEST_RIOTBOARD)+= embest-riotboard/
 obj-$(CONFIG_MACH_ELTEC_HIPERCAM)  += eltec-hipercam/
 obj-y  += freescale-mx51-babbage/
+obj-$(CONFIG_MACH_EZZY4)   += ezzy-4/
 obj-$(CONFIG_MACH_FREESCALE_MX53_LOCO) += freescale-mx53-qsb/
 obj-$(CONFIG_MACH_FREESCALE_MX53_VMX53)+= freescale-mx53-vmx53/
 obj-$(CONFIG_MACH_FREESCALE_MX7_SABRESD)   += freescale-mx7-sabresd/
diff --git a/arch/arm/boards/ezzy-4/Makefile b/arch/arm/boards/ezzy-4/Makefile
new file mode 100644
index 000..458f5209008
--- /dev/null
+++ b/arch/arm/boards/ezzy-4/Makefile
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+lwl-y += lowlevel.o
diff --git a/arch/arm/boards/ezzy-4/env/init/automount 
b/arch/arm/boards/ezzy-4/env/init/automount
new file mode 100644
index 000..6be2b6508a0
--- /dev/null
+++ b/arch/arm/boards/ezzy-4/env/init/automount
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+version
+echo
+help
+echo
+cpuinfo
+echo
+iomem
+echo
+meminfo
+echo
+of_dump
+echo
+drvinfo
+echo
+
+timeout 3
+echo
+
+echo sleep 0
+sleep 1
+echo sleep 1
+sleep 1
+echo sleep 2
+sleep 1
+echo sleep 3
diff --git a/arch/arm/boards/ezzy-4/lowlevel.c 
b/arch/arm/boards/ezzy-4/lowlevel.c
new file mode 100644
index 000..e06ac493bc6
--- /dev/null
+++ b/arch/arm/boards/ezzy-4/lowlevel.c
@@ -0,0 +1,19 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include 
+#include 
+#include 
+#include 
+
+extern char __dtb_ezzy_4_start[];
+
+void __naked barebox_arm_reset_vector(uint32_t r0, uint32_t r1, uint32_t r2)
+{
+   void *fdt;
+
+   arm_cpu_lowlevel_init();
+
+   fdt = __dtb_ezzy_4_start + get_runtime_offset();
+
+   barebox_arm_entry(0x1400, SZ_4M, fdt);
+}
diff --git a/arch/arm/configs/ezzy-4_defconfig 
b/arch/arm/configs/ezzy-4_defconfig
new file mode 100644
index 000..4701f78fc6a
--- /dev/null
+++ b/arch/arm/configs/ezzy-4_defconfig
@@ -0,0 +1,49 @@
+CONFIG_TEXT_BASE=0x1430
+CONFIG_ARCH_SC6531E=y
+CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
+CONFIG_PBL_IMAGE=y
+CONFIG_IMAGE_COMPRESSION_NONE=y
+CONFIG_MALLOC_SIZE=0x10
+CONFIG_PROMPT="ezzy-4 > "
+CONFIG_HUSH_FANCY_PROMPT=y
+CONFIG_CMDLINE_EDITING=y
+CONFIG_AUTO_COMPLETE=y
+CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW=y
+CONFIG_DEFAULT_ENVIRONMENT_PATH="arch/arm/boards/ezzy-4/env"
+CONFIG_DEBUG_LL=y
+CONFIG_DEBUG_INITCALLS=y
+CONFIG_DEBUG_PBL=y
+CONFIG_CMD_IOMEM=y
+CONFIG_

[RFC 3/4] sc6531e: add debug_ll support

2023-06-10 Thread Antony Pavlov
Signed-off-by: Antony Pavlov 
---
 arch/arm/Kconfig|   1 +
 arch/arm/boards/ezzy-4/Makefile |   3 +
 arch/arm/boards/ezzy-4/usbio.c  | 449 
 arch/arm/cpu/uncompress.c   |   7 +
 arch/arm/include/asm/debug_ll.h |   2 +
 include/mach/sc6531e/debug_ll.h |  17 ++
 6 files changed, 479 insertions(+)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index b46d73f5084..ffd2ff8b531 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -88,6 +88,7 @@ config ARCH_SC6531E
bool "SC6531E-based devices"
depends on 32BIT
select CPU_ARM926T
+   select HAS_DEBUG_LL
select GPIOLIB
help
  Support for feature phones based on the SC6531E chipset.
diff --git a/arch/arm/boards/ezzy-4/Makefile b/arch/arm/boards/ezzy-4/Makefile
index 458f5209008..c1253f3f64f 100644
--- a/arch/arm/boards/ezzy-4/Makefile
+++ b/arch/arm/boards/ezzy-4/Makefile
@@ -1,3 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0-only
 
 lwl-y += lowlevel.o
+
+lwl-y += usbio.o
+obj-y += usbio.o
diff --git a/arch/arm/boards/ezzy-4/usbio.c b/arch/arm/boards/ezzy-4/usbio.c
new file mode 100644
index 000..954765d70fd
--- /dev/null
+++ b/arch/arm/boards/ezzy-4/usbio.c
@@ -0,0 +1,449 @@
+/*
+ * This file is part of fpdoom
+ * https://github.com/ilyakurdyukov/fpdoom/blob/main/fpdoom/usbio.c
+ */
+
+#include 
+#include 
+
+void *memcpy(void *dst, const void *src, size_t count);
+size_t strlen(const char *src);
+
+void usb_debug_ll_init(void);
+int usb_PUTC_LL(char ch);
+
+#define ALIGN(n) __attribute__((aligned(n)))
+
+#define readl(a) (*(volatile uint32_t *)(a))
+#define writel(v,a)(*(volatile uint32_t *)(a) = (v))
+
+#define MEM4(addr) *(volatile uint32_t*)(addr)
+
+#define READ32_BE(p) (uint32_t)( \
+   ((uint8_t*)(p))[0] << 24 | \
+   ((uint8_t*)(p))[1] << 16 | \
+   ((uint8_t*)(p))[2] << 8 | \
+   ((uint8_t*)(p))[3])
+
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+
+static inline uint32_t swap_be32(uint32_t v) {
+   uint32_t t = v >> 24 | v << 24, m = 0xff00;
+   return t | (v >> 8 & m) | (v & m) << 8;
+}
+#endif
+
+static unsigned fastchk16(unsigned crc, const void *src, int len)
+{
+   uint8_t *s = (uint8_t*)src;
+
+   while (len > 1) {
+   crc += s[1] << 8 | s[0]; s += 2;
+   len -= 2;
+   }
+
+   if (len)
+   crc += *s;
+
+   crc = (crc >> 16) + (crc & 0x);
+   crc += crc >> 16;
+
+   return crc & 0x;
+}
+
+enum {
+   HOST_CONNECT = 0x00,
+
+   CMD_MESSAGE = 0x80,
+   CMD_FOPEN = 0x81,
+   CMD_FREAD = 0x82,
+   CMD_FWRITE = 0x83,
+   CMD_FCLOSE = 0x84,
+   CMD_FSEEK = 0x85,
+   CMD_FTELL = 0x86,
+   CMD_GETARGS = 0x87,
+};
+
+#define CHECKSUM_INIT 0x5a5a
+#define USB_WAIT 1
+#define USB_NOWAIT 0
+
+#define USB_BASE_INIT
+#define USB_BASE 0x9000
+
+#define USB_CR(o) MEM4(USB_BASE + o)
+
+#define USB_MAXREAD 64
+
+// not necessary, because USB is already
+// initialized by the bootloader
+#define INIT_USB 1
+
+#define USB_BUFSIZE 0x800
+
+#if (USB_BUFSIZE) & (USB_BUFSIZE - 1)
+#error
+#endif
+
+typedef struct {
+   uint32_t rpos, wpos;
+   uint8_t buf[USB_BUFSIZE];
+} usb_buf_t;
+
+usb_buf_t usb_buf;
+
+static const uint8_t dev_desc[] ALIGN(4) = {
+   0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x40,
+   0x82, 0x17, 0x00, 0x4d, 0x02, 0x02, 0x00, 0x00,
+   0x00, 0x01
+};
+
+static const uint8_t config_desc[] ALIGN(4) = {
+   0x09, 0x02, 0x20, 0x00, 0x01, 0x01, 0x00, 0xc0, 0x32,
+   0x09, 0x04, 0x00, 0x00, 0x02, 0xff, 0x00, 0x00, 0x00,
+   0x07, 0x05, 0x83, 0x02, 0x40, 0x00, 0x00,
+   0x07, 0x05, 0x02, 0x02, 0x40, 0x00, 0x00
+};
+
+enum {
+   USB_CTRL = 0,
+   INT_STS = 0x18,
+   INT_CLR = 0x1c,
+   TIMEOUT_LMT = 0x28,
+
+   TR_SIZE_IN_ENDP0 = 0x40,
+   REQ_SETUP_LOW = 0x5c,
+   REQ_SETUP_HIGH = 0x60,
+   ENDP0_CTRL = 0x64,
+   INT_CTRL_ENDP0 = 0x68,
+   INT_STS_ENDP0 = 0x6c,
+   INT_CLR_ENDP0 = 0x70,
+
+   ENDP1_CTRL = 0xc0,
+   TRANS_SIZE_ENDP1 = 0xc8,
+   INT_CTRL_ENDP1 = 0xcc,
+   INT_STS_ENDP1 = 0xd0,
+   INT_CLR_ENDP1 = 0xd4,
+
+   ENDP2_CTRL = 0x100,
+   RCV_DATA_ENDP2 = 0x104,
+   INT_CTRL_ENDP2 = 0x10c,
+   INT_STS_ENDP2 = 0x110,
+   INT_CLR_ENDP2 = 0x114,
+
+   ENDP3_CTRL = 0x140,
+   TRANS_SIZE_ENDP3 = 0x148,
+   INT_CTRL_ENDP3 = 0x14c,
+   INT_STS_ENDP3 = 0x150,
+   INT_CLR_ENDP3 = 0x154,
+};
+
+#define FIFO_entry_endp0_in (uint32_t*)(USB_BASE + 0x8)
+#define FIFO_entry_endp1 (FIFO_entry_endp0_in + 1)
+#define FIFO_entry_endp3 (FIFO_entry_endp0_in + 2)
+
+#define FIFO_entry_endp_out (uint32_t*)(USB_BASE + 0x8000c)
+#define FIFO_entry_endp2 (FIFO_entry_endp_out + 1)
+
+/* max packet size */
+#define USB_MAXPSIZE(o, n) \
+   (USB_CR(o) = (USB_CR(o) & ~0x7ff000) | (n) &

Re: [PATCH 1/3] MIPS: add qemu-malta64el_defconfig

2023-06-08 Thread Antony Pavlov
Hi Denis!

On Wed,  7 Jun 2023 07:59:38 +0300
Denis Orlov  wrote:

> This defconfig will compile barebox for Malta board and MIPS64 5KEc/5KEf
> CPUs, emulatable in QEMU. The analogous 32-bit defconfig uses big endian
> CPU as the default one. So, for the sake of variety, and to improve the
> coverage of options, set the CPU as little endian for this one.

One more reason to run MIPS 64-bit barebox in little endian mode:
there is the Debian MIPS64 little endian port but
there is no Debian MIPS64 big endian port.

Also please note that the Debian 32-bit MIPS big endian port was discontinued
after Debian 10 (Buster).

-- 
Best regards,
  Antony Pavlov



[PATCH] crypto: imx-scc: Kconfig: drop references to unknown symbols

2023-05-12 Thread Antony Pavlov
barebox has neither CRYPTO_BLKCIPHER nor CRYPTO_DES.

Signed-off-by: Antony Pavlov 
---
 drivers/crypto/imx-scc/Kconfig | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/crypto/imx-scc/Kconfig b/drivers/crypto/imx-scc/Kconfig
index c5b0ac2e83..75038fd2a5 100644
--- a/drivers/crypto/imx-scc/Kconfig
+++ b/drivers/crypto/imx-scc/Kconfig
@@ -2,8 +2,6 @@
 config CRYPTO_DEV_MXC_SCC
tristate "Support for Freescale Security Controller (SCC)"
depends on (ARCH_IMX25 || COMPILE_TEST) && OFTREE
-   select CRYPTO_BLKCIPHER
-   select CRYPTO_DES
help
  This option enables support for the Security Controller (SCC)
  found in Freescale i.MX25 chips.
-- 
2.39.0




[PATCH] powerpc: Kconfig: fix reference to unknown symbol

2023-05-11 Thread Antony Pavlov
In Kconfig files, the symbols don't have a CONFIG_ prefix.
Fix an unknown Kconfig symbol introduced in d3b8a88d34
("treewide: rename CONFIG_HAS_ARCH_SJLJ to CONFIG_ARCH_HAS_SJLJ").

Signed-off-by: Antony Pavlov 
---
 arch/powerpc/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 4ae6d423af..ba875767b2 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -8,7 +8,7 @@ config PPC
select HAS_CACHE
select GENERIC_FIND_NEXT_BIT
select OFTREE
-   select CONFIG_ARCH_HAS_SJLJ
+   select ARCH_HAS_SJLJ
default y
 
 choice
-- 
2.39.0




Re: [PATCH v2 6/7] RISC-V: squash 64bit defconfigs into rv64i_defconfig

2022-10-22 Thread Antony Pavlov
On Wed,  5 Oct 2022 13:12:13 +0200
Marco Felsch  wrote:

Hi Marco!

It looks like this commit breaks emulate.pl, e.g.

  ARCH=riscv
  ARCH=${ARCH} ./test/emulate.pl --kconfig-full --test -- 
--junitxml=$PWD/$ARCH.tests.xml --lg-log=$PWD/log/$ARCH

reports

  Can't find default configuration "arch/riscv/configs/virt64_defconfig"!

Please see details: https://gitlab.com/frantony/barebox/-/jobs/3211154690#L111

-- 
Best regards,
  Antony Pavlov

> This commit squashes all 64bit risc-v defconfigs into one like armv8.
> The 32bit defconfigs are not changed since those systems have tight
> resource constraints and a generic defconfig may break some systems.
> 
> Signed-off-by: Marco Felsch 
> ---
> v2:
> - new commit
> 
>  Documentation/boards/emulated.rst |   4 +-
>  Documentation/boards/riscv.rst|   6 +-
>  arch/riscv/Makefile   |   2 +-
>  .../{virt64_defconfig => rv64i_defconfig} |  42 +-
>  arch/riscv/configs/sifive_defconfig   | 129 -
>  arch/riscv/configs/starfive_defconfig | 131 --
>  6 files changed, 47 insertions(+), 267 deletions(-)
>  rename arch/riscv/configs/{virt64_defconfig => rv64i_defconfig} (76%)
>  delete mode 100644 arch/riscv/configs/sifive_defconfig
>  delete mode 100644 arch/riscv/configs/starfive_defconfig
> 
> diff --git a/Documentation/boards/emulated.rst 
> b/Documentation/boards/emulated.rst
> index 584883d6ef..ef035ec69a 100644
> --- a/Documentation/boards/emulated.rst
> +++ b/Documentation/boards/emulated.rst
> @@ -64,12 +64,12 @@ The script can also be used with a precompiled barebox 
> tree::
>  ``emulate.pl`` also has some knowledge on paravirtualized devices::
>  
># Run target and pass a block device (here /dev/virtioblk0)
> -  ARCH=riscv ./test/emulate.pl --blk=rootfs.ext4 virt64_defconfig
> +  ARCH=riscv ./test/emulate.pl --blk=rootfs.ext4 rv64i_defconfig
>  
>  Needed command line options can be passed directly to the
>  emulator/``pytest`` as well by placing them behind ``--``::
>  
># appends -device ? to the command line. Add -n to see the final result
> -  ARCH=riscv ./test/emulate.pl virt64_defconfig -- -device ?
> +  ARCH=riscv ./test/emulate.pl rv64i_defconfig -- -device ?
>  
>  For a complete listing of options run ``./test/emulate.pl -h``.
> diff --git a/Documentation/boards/riscv.rst b/Documentation/boards/riscv.rst
> index b7a3a95f0f..e69eca78c8 100644
> --- a/Documentation/boards/riscv.rst
> +++ b/Documentation/boards/riscv.rst
> @@ -6,10 +6,10 @@ QEMU Virt
>  
>  barebox supports both the qemu riscv32 and riscv64 ``-M virt`` boards::
>  
> -  make ARCH=riscv virt64_defconfig
> +  make ARCH=riscv rv64i_defconfig
>qemu-system-riscv64 -M virt -serial stdio -kernel 
> build/images/barebox-dt-2nd.img
>  
> -Replace ``64`` by ``32`` for 32-bit build. :ref:`virtio_sect` over MMIO is 
> supported and
> +For 32-bit builds use ``virt32_defconfig``. :ref:`virtio_sect` over MMIO is 
> supported and
>  can be used for e.g. an extra console or to pass in a virtio-blk device::
>  
>qemu-system-riscv64 -M virt -serial stdio\
> @@ -65,7 +65,7 @@ BeagleV
>  
>  barebox has second-stage support for the BeagleV Starlight::
>  
> -  make ARCH=riscv starfive_defconfig
> +  make ARCH=riscv rv64i_defconfig
>make
>  
>  Thie resulting ``./images/barebox-beaglev-starlight.img`` can be used as 
> payload
> diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile
> index 6fbf1d4ddd..279db046c0 100644
> --- a/arch/riscv/Makefile
> +++ b/arch/riscv/Makefile
> @@ -1,6 +1,6 @@
>  # SPDX-License-Identifier: GPL-2.0-only
>  
> -KBUILD_DEFCONFIG := virt64_defconfig
> +KBUILD_DEFCONFIG := rv64i_defconfig
>  
>  KBUILD_CPPFLAGS += -fno-strict-aliasing
>  
> diff --git a/arch/riscv/configs/virt64_defconfig 
> b/arch/riscv/configs/rv64i_defconfig
> similarity index 76%
> rename from arch/riscv/configs/virt64_defconfig
> rename to arch/riscv/configs/rv64i_defconfig
> index c2edd2dc28..6c8409567d 100644
> --- a/arch/riscv/configs/virt64_defconfig
> +++ b/arch/riscv/configs/rv64i_defconfig
> @@ -1,5 +1,11 @@
>  CONFIG_ARCH_RV64I=y
> +CONFIG_SOC_SIFIVE=y
> +CONFIG_SOC_STARFIVE=y
>  CONFIG_SOC_VIRT=y
> +CONFIG_BOARD_BEAGLEV=y
> +CONFIG_BOARD_BEAGLEV_BETA=y
> +CONFIG_BOARD_HIFIVE=y
> +CONFIG_BOARD_RISCV_GENERIC_DT=y
>  CONFIG_RISCV_OPTIMZED_STRING_FUNCTIONS=y
>  CONFIG_STACK_SIZE=0x2
>  CONFIG_MALLOC_SIZE=0x0
> @@ -13,6 +19,7 @@ CONFIG_AUTO_COMPLETE=y
>  CONFIG_MENU=y
>  CONFIG_BOOTM_VERBOSE=y
>  CONFIG_BOOTM_INITRD=y
> +CONFIG_SYSTEM_PARTITIONS=y
>  CONFIG_BLSPEC=y
>  CONFIG_CONSOLE_ACTIVATE_

Re: Makefile.lib: cmd_dtc: warning: missing whitespace after the macro name

2022-09-22 Thread Antony Pavlov
On Mon, 19 Sep 2022 11:14:10 +0200
Sascha Hauer  wrote:

Hi Sascha!

> Hi Antony,
> 
> On Mon, Sep 12, 2022 at 12:07:34PM +0300, Antony Pavlov wrote:
> > On Mon, 12 Sep 2022 10:01:52 +0200
> > Sascha Hauer  wrote:
> > 
> > > One side effect is that this gets even less readable.
> > 
> > Yes, you are right :)
> > 
> > > Another one would be that two dts filenames which only differ in the
> > > usage of '.' and '_' would result in the same define, but I think that
> > > case is negligible as this define is unused in barebox itself. It could
> >
> > > be used by external dts fragments passed in via 
> > > CONFIG_EXTERNAL_DTS_FRAGMENTS.
> > > 
> > > Other than that, what side effects are you afraid of?
> > 
> > I have an idea that someone relies on these *_dts macros.
> > 
> > Now I see (as you have noted above) that there is no macro users in 
> > mainline source tree:
> 
> Could you create a formal patch from this?

I'll a formal patch in a few days.

-- 
Best regards,
  Antony Pavlov



Re: [RFC] Documentation/conf.py: fix copyright years

2022-09-16 Thread Antony Pavlov
On Fri, 16 Sep 2022 08:28:43 +0200
Sascha Hauer  wrote:

Hi Sascha!

> On Thu, Sep 15, 2022 at 09:18:20AM +0300, Antony Pavlov wrote:
> > On Mon, 12 Sep 2022 11:46:27 +0300
> > Antony Pavlov  wrote:
> > 
> > Hi Sascha!
> > 
> > Here is the barebox documentation generated in my gitlab CI/CD system with 
> > 'make docs':
> >   
> > https://frantony.gitlab.io/-/barebox/-/jobs/3029093142/artifacts/Documentation/html/index.html
> > 
> > and this is the barebox documentation from barebox.org:
> >   https://www.barebox.org/doc/latest/index.html
> > 
> > The index.html pages look different (different color scheme is used, no 
> > barebox logo in the left top
> > conner after 'make docs' etc).
> > 
> > Could you please publish an instruction how to reproduce barebox html 
> > documentation from barebox.org?
> 
> We have the theme here internally. Sorry, I can't give you any
> instructions on how to reproduce the docs as found on the website.
> What do you need them for?

I want to extend my gitlab.com CI-CD scripts.

-- 
Best regards,
  Antony Pavlov



Re: [RFC] Documentation/conf.py: fix copyright years

2022-09-15 Thread Antony Pavlov
On Mon, 12 Sep 2022 11:46:27 +0300
Antony Pavlov  wrote:

Hi Sascha!

Here is the barebox documentation generated in my gitlab CI/CD system with 
'make docs':
  
https://frantony.gitlab.io/-/barebox/-/jobs/3029093142/artifacts/Documentation/html/index.html

and this is the barebox documentation from barebox.org:
  https://www.barebox.org/doc/latest/index.html

The index.html pages look different (different color scheme is used, no barebox 
logo in the left top
conner after 'make docs' etc).

Could you please publish an instruction how to reproduce barebox html 
documentation from barebox.org?


> N.B. N-dash is used!
> 
> Signed-off-by: Antony Pavlov 
> ---
>  Documentation/conf.py | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/Documentation/conf.py b/Documentation/conf.py
> index bcd8633c919..5fb8b07c380 100644
> --- a/Documentation/conf.py
> +++ b/Documentation/conf.py
> @@ -44,7 +44,7 @@ master_doc = 'index'
>  
>  # General information about the project.
>  project = u'barebox'
> -copyright = u'2014, The barebox project'
> +copyright = u'2014–2022, The barebox project'
>  
>  # The version info for the project you're documenting, acts as replacement 
> for
>  # |version| and |release|, also used in various other places throughout the
> -- 
> 2.37.2
> 


-- 
Best regards,
  Antony Pavlov



Re: [PATCH next] Documentation: filesystems: tftp: fix code blocks

2022-09-13 Thread Antony Pavlov
On Tue, 13 Sep 2022 10:08:37 +0200
Sascha Hauer  wrote:

Hi Sascha!

> On Mon, Sep 12, 2022 at 11:50:47AM +0300, Antony Pavlov wrote:
> > The patch fixes these sphinx errors:
> > 
> >   Documentation/filesystems/tftp.rst:44: ERROR: Error in "code-block" 
> > directive:
> > maximum 1 argument(s) allowed, 3 supplied.
> >   Documentation/filesystems/tftp.rst:53: ERROR: Error in "code-block" 
> > directive:
> > maximum 1 argument(s) allowed, 4 supplied.
> > 
> > Signed-off-by: Antony Pavlov 
> > ---
> >  Documentation/filesystems/tftp.rst | 2 ++
> >  1 file changed, 2 insertions(+)
> 
> Applied, thanks

I thought that this patch is for ammend. My bad! I shell add "for ammend" or 
"fixup" tag to the message subject next time.

> > 
> > diff --git a/Documentation/filesystems/tftp.rst 
> > b/Documentation/filesystems/tftp.rst
> > index 8929213d3c4..e88ad3dd4c8 100644
> > --- a/Documentation/filesystems/tftp.rst
> > +++ b/Documentation/filesystems/tftp.rst
> > @@ -42,6 +42,7 @@ the opposite effect.  Performance depends on:
> > 100 Mb/s) it had to be reduced to
> >  
> > .. code-block:: console
> > +
> >   global tftp.windowsize=26
> >  
> > for example.
> > @@ -51,6 +52,7 @@ the opposite effect.  Performance depends on:
> > example, the `fec-imx` driver reserves place for
> >  
> > .. code-block:: c
> > +
> >   #define FEC_RBD_NUM   64
> >  
> > packets before they are dropped
> > -- 
> > 2.37.2
> > 
> > 
> 
> -- 
> Pengutronix e.K.   | |
> Steuerwalder Str. 21   | http://www.pengutronix.de/  |
> 31137 Hildesheim, Germany  | Phone: +49-5121-206917-0|
> Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |


-- 
Best regards,
  Antony Pavlov



Re: Makefile.lib: cmd_dtc: warning: missing whitespace after the macro name

2022-09-12 Thread Antony Pavlov
On Mon, 12 Sep 2022 10:01:52 +0200
Sascha Hauer  wrote:

Hi Sascha!

> On Wed, Sep 07, 2022 at 11:21:18AM +0300, Antony Pavlov wrote:
> > Hi Everyone!
> > 
> > During MIPS ath79_defconfig build I have a 'missing whitespace after the 
> > macro name' warning:
> > 
> >   AS [P]  arch/mips/dts/ar9331_tl_mr3020.dtb.pbl.o
> >   DTC arch/mips/dts/ar9344-tl-wdr4300-v1.7.dtb
> > :1:9: warning: missing whitespace after the macro name
> >   XZKERN  arch/mips/dts/ar9344-tl-wdr4300-v1.7.dtb.z
> > 
> > E.g. see https://gitlab.com/frantony/barebox/-/jobs/2969826747#L47
> > 
> > The reason is the scripts/Makefile.lib generates a C macro with the point 
> > symbol in the macro name because the 
> > arch/mips/dts/ar9344-tl-wdr4300-v1.7.dts file name contains the point 
> > symbol before '.dts', as a result we have:
> > 
> >   #define ar9344_tl_wdr4300_v1.7_dts 1
> > 
> > e.g.
> > 
> >   barebox$ grep -RHn -o "define ar9344_tl_wdr4300_v1.* 1" . 2>/dev/null
> >   ./arch/mips/dts/.ar9344-tl-wdr4300-v1.7.dtb.cmd:1:define 
> > ar9344_tl_wdr4300_v1.7_dts 1
> > 
> > cmd_dtc in scripts/Makefile.lib substitutes the '-' symbols with the '_' 
> > symbols but do nothing with other unwanted C preprocessor macro name 
> > symbols.
> > 
> > It looks like the linux kernel has no problems with extra point symbols in 
> > dts file names, there are several files with extra dot in dts:
> > 
> >   barebox$ find dts/ -iname '*.*.dts' | wc -l
> >   33
> > 
> > So we have to fix Makefile.lib.
> > 
> > This simple patch fixes the warning problem:
> > 
> > diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
> > index 16308497b84..2f79656c1e9 100644
> > --- a/scripts/Makefile.lib
> > +++ b/scripts/Makefile.lib
> > @@ -363,7 +363,7 @@ $(obj)/%.dtb.z: $(obj)/%.dtb FORCE
> >  dts-frags = $(subst $(quote),,$(CONFIG_EXTERNAL_DTS_FRAGMENTS))
> >  quiet_cmd_dtc = DTC $@
> >  # For compatibility between make 4.2 and 4.3
> > -cmd_dtc = /usr/bin/env echo -e '$(pound)define $(subst -,_,$(*F))_dts 
> > 1\n'$(foreach f,$< $(dts-frags),'$(pound)include "$(f)"\n') | \
> > +cmd_dtc = /usr/bin/env echo -e '$(pound)define $(subst -,_,$(subst 
> > .,_,$(*F)))_dts 1\n'$(foreach f,$< $(dts-frags),'$(pound)include "$(f)"\n') 
> > | \
> > $(CPP) $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) - ; \
> > $(objtree)/scripts/dtc/dtc -O dtb -o $@ -b 0 \
> > -i $(srctree)/arch/$(SRCARCH)/dts $(DTC_FLAGS) \
> > 
> > I suppose that this simple patch may lead to some undesirable side effects.
> 
> One side effect is that this gets even less readable.

Yes, you are right :)

> Another one would be that two dts filenames which only differ in the
> usage of '.' and '_' would result in the same define, but I think that
> case is negligible as this define is unused in barebox itself. It could
   
> be used by external dts fragments passed in via CONFIG_EXTERNAL_DTS_FRAGMENTS.
> 
> Other than that, what side effects are you afraid of?

I have an idea that someone relies on these *_dts macros.

Now I see (as you have noted above) that there is no macro users in mainline 
source tree:

  $ git grep -w .*_dts
  common/Kconfig:   #ifdef foo_board_dts
  scripts/Makefile.lib:cmd_dtc = /usr/bin/env echo -e '$(pound)define $(subst 
-,_,$(*F))_dts 1\n'$(foreach f,$< $(dts-frags),'$(pound)include "$(f)"\n') | \

-- 
Best regards,
  Antony Pavlov



[PATCH next] Documentation: filesystems: tftp: fix code blocks

2022-09-12 Thread Antony Pavlov
The patch fixes these sphinx errors:

  Documentation/filesystems/tftp.rst:44: ERROR: Error in "code-block" directive:
maximum 1 argument(s) allowed, 3 supplied.
  Documentation/filesystems/tftp.rst:53: ERROR: Error in "code-block" directive:
maximum 1 argument(s) allowed, 4 supplied.

Signed-off-by: Antony Pavlov 
---
 Documentation/filesystems/tftp.rst | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/Documentation/filesystems/tftp.rst 
b/Documentation/filesystems/tftp.rst
index 8929213d3c4..e88ad3dd4c8 100644
--- a/Documentation/filesystems/tftp.rst
+++ b/Documentation/filesystems/tftp.rst
@@ -42,6 +42,7 @@ the opposite effect.  Performance depends on:
100 Mb/s) it had to be reduced to
 
.. code-block:: console
+
  global tftp.windowsize=26
 
for example.
@@ -51,6 +52,7 @@ the opposite effect.  Performance depends on:
example, the `fec-imx` driver reserves place for
 
.. code-block:: c
+
  #define FEC_RBD_NUM   64
 
packets before they are dropped
-- 
2.37.2




[RFC] Documentation/conf.py: fix copyright years

2022-09-12 Thread Antony Pavlov
N.B. N-dash is used!

Signed-off-by: Antony Pavlov 
---
 Documentation/conf.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Documentation/conf.py b/Documentation/conf.py
index bcd8633c919..5fb8b07c380 100644
--- a/Documentation/conf.py
+++ b/Documentation/conf.py
@@ -44,7 +44,7 @@ master_doc = 'index'
 
 # General information about the project.
 project = u'barebox'
-copyright = u'2014, The barebox project'
+copyright = u'2014–2022, The barebox project'
 
 # The version info for the project you're documenting, acts as replacement for
 # |version| and |release|, also used in various other places throughout the
-- 
2.37.2




[PATCH 5/7] Documentation: barebox environment: fix list rendering

2022-09-12 Thread Antony Pavlov
Signed-off-by: Antony Pavlov 
---
 .../devicetree/bindings/barebox/barebox,environment.rst  | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/barebox/barebox,environment.rst 
b/Documentation/devicetree/bindings/barebox/barebox,environment.rst
index 918efd15f55..8a57bf1add8 100644
--- a/Documentation/devicetree/bindings/barebox/barebox,environment.rst
+++ b/Documentation/devicetree/bindings/barebox/barebox,environment.rst
@@ -9,6 +9,7 @@ Required properties:
 * ``device-path``: path to the device environment is on
 
 Optional properties:
+
 * ``file-path``: path to a file in the device named by device-path
 
 The device-path is a multistring property. The first string should contain
-- 
2.37.2




[PATCH 7/7] Documentation: Voltage/Current Regulators: fix sphinx error

2022-09-12 Thread Antony Pavlov
sphinx error:

Documentation/devicetree/bindings/regulator/regulator.rst:8:
  ERROR: Unexpected indentation.

Signed-off-by: Antony Pavlov 
---
 Documentation/devicetree/bindings/regulator/regulator.rst | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/regulator/regulator.rst 
b/Documentation/devicetree/bindings/regulator/regulator.rst
index 9afc020acd3..754c4743286 100644
--- a/Documentation/devicetree/bindings/regulator/regulator.rst
+++ b/Documentation/devicetree/bindings/regulator/regulator.rst
@@ -4,6 +4,7 @@ Voltage/Current Regulators
 In addition to the upstream bindings, another property is added:
 
 Optional properties:
+
 - ``barebox,allow-dummy-supply`` : A property to allow usage of dummy power
   regulator. This can be added to regulator nodes, whose drivers are not yet
   supported. It will rely on regulator reset defaults and use of dummy 
regulator
-- 
2.37.2




[PATCH 1/7] Documentation: OKUD Max9331: fix sphinx warning

2022-09-12 Thread Antony Pavlov
sphinx warning:

  Documentation/boards/mips/max9331.rst:129: WARNING:
Pygments lexer name 'assembly' is not known

Use pygments lexer for Gas (AT) assembly code, see
https://pygments.org/docs/lexers/#lexers-for-assembly-languages
for details.

Signed-off-by: Antony Pavlov 
---
 Documentation/boards/mips/max9331.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Documentation/boards/mips/max9331.rst 
b/Documentation/boards/mips/max9331.rst
index f09dabc2da1..f7529f9874d 100644
--- a/Documentation/boards/mips/max9331.rst
+++ b/Documentation/boards/mips/max9331.rst
@@ -126,7 +126,7 @@ it jump to 0x9f02 where the first instruction of 
barebox.
 This is usefull when debug with jtag or choosing different bootloaders.
 or even boot kernel without bootloader.
 
-.. code-block:: assembly
+.. code-block:: asm
 
  lui  ra, 0x9f02
  jr   ra
-- 
2.37.2




[PATCH 6/7] Documentation: Common leds properties: fix 'panic-indicator' list entry rendering

2022-09-12 Thread Antony Pavlov
Signed-off-by: Antony Pavlov 
---
 Documentation/devicetree/bindings/leds/common.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/leds/common.rst 
b/Documentation/devicetree/bindings/leds/common.rst
index 911a55f4f66..09b4e401bc2 100644
--- a/Documentation/devicetree/bindings/leds/common.rst
+++ b/Documentation/devicetree/bindings/leds/common.rst
@@ -14,4 +14,4 @@ Common leds properties
   from the node name (excluding the unit address).
 
 * ``panic-indicator`` - This property specifies that the LED should be used as 
a
- panic indicator.
+  panic indicator.
-- 
2.37.2




[PATCH 4/7] Documentation: barebox DT aliases: fix sphinx issues

2022-09-12 Thread Antony Pavlov
sphinx issues:

  Documentation/devicetree/bindings/barebox/aliases.rst:8:
ERROR: Unexpected indentation.
  Documentation/devicetree/bindings/barebox/aliases.rst:12:
WARNING: Definition list ends without a blank line; unexpected unindent.
  Documentation/devicetree/bindings/barebox/aliases.rst:13:
WARNING: Definition list ends without a blank line; unexpected unindent.

Signed-off-by: Antony Pavlov 
---
 Documentation/devicetree/bindings/barebox/aliases.rst | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/barebox/aliases.rst 
b/Documentation/devicetree/bindings/barebox/aliases.rst
index 527cc85ef69..e6face2c331 100644
--- a/Documentation/devicetree/bindings/barebox/aliases.rst
+++ b/Documentation/devicetree/bindings/barebox/aliases.rst
@@ -2,9 +2,10 @@ barebox DT aliases
 ==
 
 barebox can use the properties in the ``/aliases`` node to arrive
-at deterministic names for devices, e.g.::
+at deterministic names for devices, e.g.:
 
 .. code-block:: none
+
/ {
aliases {
mmc0 = 
-- 
2.37.2




[PATCH 3/7] Documentation: Altera FPGAs in passive-serial mode: fix sphinx issues

2022-09-12 Thread Antony Pavlov
sphinx issues:

  Documentation/devicetree/bindings/firmware/altr,passive-serial.rst:10:
ERROR: Unexpected indentation.
  Documentation/devicetree/bindings/firmware/altr,passive-serial.rst:11:
WARNING: Block quote ends without a blank line; unexpected unindent.

Insert necessary empty line to fix the problem.

Signed-off-by: Antony Pavlov 
---
 .../devicetree/bindings/firmware/altr,passive-serial.rst | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/firmware/altr,passive-serial.rst 
b/Documentation/devicetree/bindings/firmware/altr,passive-serial.rst
index 1012137bc93..cbddd700ce9 100644
--- a/Documentation/devicetree/bindings/firmware/altr,passive-serial.rst
+++ b/Documentation/devicetree/bindings/firmware/altr,passive-serial.rst
@@ -6,6 +6,7 @@ passive serial mode. This is used to upload the firmware and
 to start the FPGA.
 
 Required properties:
+
 - ``compatible``: shall be ``"altr,fpga-passive-serial"`` or
   ``"altr,fpga-arria10-passive-serial"`` for Arria 10
 - ``reg``: SPI chip select
-- 
2.37.2




[PATCH 2/7] Documentation: Altera SOCFPGA FPGA Manager: fix sphinx error

2022-09-12 Thread Antony Pavlov
sphinx error:

  Documentation/devicetree/bindings/firmware/altr,socfpga-fpga-mgr.rst:10:
   ERROR: Unexpected indentation.

Insert necessary whitespaces and empty lines to form correct
nested lists structure.

Signed-off-by: Antony Pavlov 
---
 .../devicetree/bindings/firmware/altr,socfpga-fpga-mgr.rst  | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git 
a/Documentation/devicetree/bindings/firmware/altr,socfpga-fpga-mgr.rst 
b/Documentation/devicetree/bindings/firmware/altr,socfpga-fpga-mgr.rst
index 9f7de6b9858..478e8e6fc44 100644
--- a/Documentation/devicetree/bindings/firmware/altr,socfpga-fpga-mgr.rst
+++ b/Documentation/devicetree/bindings/firmware/altr,socfpga-fpga-mgr.rst
@@ -5,10 +5,12 @@ This binding defines the FPGA Manager on Altera SOCFPGAs. 
This is used to upload
 the firmware to the FPGA part of the SoC.
 
 Required properties:
+
 - ``compatible``: shall be ``"altr,socfpga-fpga-mgr"``
 - ``reg``: Must contain 2 register ranges:
-   1. The control address space of the FPGA manager.
-   2. The configuration data address space where the firmware data is 
written to.
+
+  1. The control address space of the FPGA manager.
+  2. The configuration data address space where the firmware data is written 
to.
 
 Example:
 
-- 
2.37.2




[PATCH 0/7] Documentation misc fixes

2022-09-12 Thread Antony Pavlov
Antony Pavlov (7):
  Documentation: OKUD Max9331: fix sphinx warning
  Documentation: Altera SOCFPGA FPGA Manager: fix sphinx error
  Documentation: Altera FPGAs in passive-serial mode: fix sphinx issues
  Documentation: barebox DT aliases: fix sphinx issues
  Documentation: barebox environment: fix list rendering
  Documentation: Common leds properties: fix 'panic-indicator' list
entry rendering
  Documentation: Voltage/Current Regulators: fix sphinx error

 Documentation/boards/mips/max9331.rst   | 2 +-
 Documentation/devicetree/bindings/barebox/aliases.rst   | 3 ++-
 .../devicetree/bindings/barebox/barebox,environment.rst | 1 +
 .../devicetree/bindings/firmware/altr,passive-serial.rst| 1 +
 .../devicetree/bindings/firmware/altr,socfpga-fpga-mgr.rst  | 6 --
 Documentation/devicetree/bindings/leds/common.rst   | 2 +-
 Documentation/devicetree/bindings/regulator/regulator.rst   | 1 +
 7 files changed, 11 insertions(+), 5 deletions(-)

-- 
2.37.2




Makefile.lib: cmd_dtc: warning: missing whitespace after the macro name

2022-09-07 Thread Antony Pavlov
Hi Everyone!

During MIPS ath79_defconfig build I have a 'missing whitespace after the macro 
name' warning:

  AS [P]  arch/mips/dts/ar9331_tl_mr3020.dtb.pbl.o
  DTC arch/mips/dts/ar9344-tl-wdr4300-v1.7.dtb
:1:9: warning: missing whitespace after the macro name
  XZKERN  arch/mips/dts/ar9344-tl-wdr4300-v1.7.dtb.z

E.g. see https://gitlab.com/frantony/barebox/-/jobs/2969826747#L47

The reason is the scripts/Makefile.lib generates a C macro with the point 
symbol in the macro name because the arch/mips/dts/ar9344-tl-wdr4300-v1.7.dts 
file name contains the point symbol before '.dts', as a result we have:

  #define ar9344_tl_wdr4300_v1.7_dts 1

e.g.

  barebox$ grep -RHn -o "define ar9344_tl_wdr4300_v1.* 1" . 2>/dev/null
  ./arch/mips/dts/.ar9344-tl-wdr4300-v1.7.dtb.cmd:1:define 
ar9344_tl_wdr4300_v1.7_dts 1

cmd_dtc in scripts/Makefile.lib substitutes the '-' symbols with the '_' 
symbols but do nothing with other unwanted C preprocessor macro name symbols.

It looks like the linux kernel has no problems with extra point symbols in dts 
file names, there are several files with extra dot in dts:

  barebox$ find dts/ -iname '*.*.dts' | wc -l
  33

So we have to fix Makefile.lib.

This simple patch fixes the warning problem:

diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 16308497b84..2f79656c1e9 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -363,7 +363,7 @@ $(obj)/%.dtb.z: $(obj)/%.dtb FORCE
 dts-frags = $(subst $(quote),,$(CONFIG_EXTERNAL_DTS_FRAGMENTS))
 quiet_cmd_dtc = DTC $@
 # For compatibility between make 4.2 and 4.3
-cmd_dtc = /usr/bin/env echo -e '$(pound)define $(subst -,_,$(*F))_dts 
1\n'$(foreach f,$< $(dts-frags),'$(pound)include "$(f)"\n') | \
+cmd_dtc = /usr/bin/env echo -e '$(pound)define $(subst -,_,$(subst 
.,_,$(*F)))_dts 1\n'$(foreach f,$< $(dts-frags),'$(pound)include "$(f)"\n') | \
$(CPP) $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) - ; \
$(objtree)/scripts/dtc/dtc -O dtb -o $@ -b 0 \
-i $(srctree)/arch/$(SRCARCH)/dts $(DTC_FLAGS) \

I suppose that this simple patch may lead to some undesirable side effects.

Any suggestions?

-- 
Best regards,
  Antony Pavlov



[PATCH] fixup-next: linux/nvmem-consumer.h: fix warning

2022-08-31 Thread Antony Pavlov
This fixes the commit 06825a0ec35343a1
("nvmem: import Linux nvmem_cell_read_variable_le_u32")
from the next branch.

The warning is:

include/linux/nvmem-consumer.h:84:9: warning: returning 'void *' from a
function with return type 'int' makes integer from pointer without a
cast [-Wint-conversion]
   84 |  return ERR_PTR(-EOPNOTSUPP);
  | ^~~~

Signed-off-by: Antony Pavlov 
---
 include/linux/nvmem-consumer.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/nvmem-consumer.h b/include/linux/nvmem-consumer.h
index b461f840957..1fce7e1ae09 100644
--- a/include/linux/nvmem-consumer.h
+++ b/include/linux/nvmem-consumer.h
@@ -81,7 +81,7 @@ static inline int nvmem_cell_read_variable_le_u32(struct 
device_d *dev,
  const char *cell_id,
  u32 *val)
 {
-   return ERR_PTR(-EOPNOTSUPP);
+   return -EOPNOTSUPP;
 }
 
 static inline int nvmem_cell_write(struct nvmem_cell *cell,
-- 
2.37.2




[PATCH] Documentation/gen_commands.py: use python3

2022-08-31 Thread Antony Pavlov
Signed-off-by: Antony Pavlov 
---
 Documentation/gen_commands.py | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/Documentation/gen_commands.py b/Documentation/gen_commands.py
index a55b1acd82f..7c62a030dce 100755
--- a/Documentation/gen_commands.py
+++ b/Documentation/gen_commands.py
@@ -1,6 +1,4 @@
-#!/usr/bin/env python
-
-from __future__ import print_function
+#!/usr/bin/env python3
 
 import errno
 import os
-- 
2.37.2




Re: [PATCH v2 2/2] RISC-V: sifive: enable SPI Flash and SD in config

2022-08-30 Thread Antony Pavlov
On Tue, 23 Aug 2022 07:18:02 +0200
Ahmad Fatoum  wrote:

Hi Ahmad,

> Hello Antony,
> 
> On 22.08.22 13:32, Antony Pavlov wrote:
> > On Tue, 26 Apr 2022 08:46:04 +0200
> > Ahmad Fatoum  wrote:
> > 
> > Hi Ahmad!
> > 
> > I'm trying to run SiFive target with emulate.pl, e.g.
> > 
> > barebox$ dd if=/dev/zero of=/tmp/1M count=1 bs=1M
> > barebox$ ./test/emulate.pl sifive_defconfig  -- -drive file=/tmp/1M,if=sd
> > ...
> > qemu-system-riscv64: -drive file=/tmp/1M,if=sd: machine type does not 
> > support if=sd,bus=0,unit=0
> > Error running emulator: 256
> > 
> > I use QEMU emulator version 5.2.0 (Debian 1:5.2+dfsg-11+deb11u2), please 
> > see https://gitlab.com/frantony/barebox-gitlab-ci-runner .
> 
> I am running QEMU emulator version 7.0.0 (Debian 1:7.0+dfsg-2~bpo11+2), where 
> the above
> worked for just fine.
> 
> > If I skip the '-drive file=/tmp/1M,if=sd' qemu option then I see "Load 
> > access fault", e.g.
> > 
> > barebox$ ./test/emulate.pl sifive_defconfig
> > ...
> > barebox 2022.08.0-00162-g7fce4ae853b0 #1 @1661158478
> 
> Without -drive if=sd, MMC controller is probed, but no card can be detected:
> 
>   WARNING: mci0: Cannot reset the SD/MMC card
>   WARNING: mci0: Cannot reset the SD/MMC card
> 
> No crashes here. Can you update to a newer QEMU version on your CI host?

I have update QEMU. At the moment almost all tests were passed successfully.

There is the problem with emulate.pl test_bselftest, please see 
https://gitlab.com/frantony/barebox/-/jobs/2952886676#L242

Can you please run emulate.pl from the master branch in your software 
environment?

-- 
Best regards,
  Antony Pavlov



Re: [PATCH v2 2/2] RISC-V: sifive: enable SPI Flash and SD in config

2022-08-23 Thread Antony Pavlov
On Tue, 23 Aug 2022 07:18:02 +0200
Ahmad Fatoum  wrote:

Hello Ahmad,

> Hello Antony,
> 
> On 22.08.22 13:32, Antony Pavlov wrote:
> > On Tue, 26 Apr 2022 08:46:04 +0200
> > Ahmad Fatoum  wrote:
> > 
> > Hi Ahmad!
> > 
> > I'm trying to run SiFive target with emulate.pl, e.g.
> > 
> > barebox$ dd if=/dev/zero of=/tmp/1M count=1 bs=1M
> > barebox$ ./test/emulate.pl sifive_defconfig  -- -drive file=/tmp/1M,if=sd
> > ...
> > qemu-system-riscv64: -drive file=/tmp/1M,if=sd: machine type does not 
> > support if=sd,bus=0,unit=0
> > Error running emulator: 256
> > 
> > I use QEMU emulator version 5.2.0 (Debian 1:5.2+dfsg-11+deb11u2), please 
> > see https://gitlab.com/frantony/barebox-gitlab-ci-runner .
> 
> I am running QEMU emulator version 7.0.0 (Debian 1:7.0+dfsg-2~bpo11+2), where 
> the above
> worked for just fine.
> 
> > If I skip the '-drive file=/tmp/1M,if=sd' qemu option then I see "Load 
> > access fault", e.g.
> > 
> > barebox$ ./test/emulate.pl sifive_defconfig
> > ...
> > barebox 2022.08.0-00162-g7fce4ae853b0 #1 @1661158478
> 
> Without -drive if=sd, MMC controller is probed, but no card can be detected:
> 
>   WARNING: mci0: Cannot reset the SD/MMC card
>   WARNING: mci0: Cannot reset the SD/MMC card
> 
> No crashes here. Can you update to a newer QEMU version on your CI host?
> 

I suppose I can install qemu-system-riscv*7.0 from bullseye-backports (see  
https://packages.debian.org/bullseye-backports/qemu-system-misc).

-- 
Best regards,
  Antony Pavlov



Re: [PATCH v2 2/2] RISC-V: sifive: enable SPI Flash and SD in config

2022-08-22 Thread Antony Pavlov
On Tue, 26 Apr 2022 08:46:04 +0200
Ahmad Fatoum  wrote:

Hi Ahmad!

I'm trying to run SiFive target with emulate.pl, e.g.

barebox$ dd if=/dev/zero of=/tmp/1M count=1 bs=1M
barebox$ ./test/emulate.pl sifive_defconfig  -- -drive file=/tmp/1M,if=sd
...
qemu-system-riscv64: -drive file=/tmp/1M,if=sd: machine type does not support 
if=sd,bus=0,unit=0
Error running emulator: 256

I use QEMU emulator version 5.2.0 (Debian 1:5.2+dfsg-11+deb11u2), please see 
https://gitlab.com/frantony/barebox-gitlab-ci-runner .

If I skip the '-drive file=/tmp/1M,if=sd' qemu option then I see "Load access 
fault", e.g.

barebox$ ./test/emulate.pl sifive_defconfig
...
barebox 2022.08.0-00162-g7fce4ae853b0 #1 @1661158478


Board: SiFive HiFive Unleashed A00
Unhandled exception: 5 "Load access fault"
E [<87e224fc>] ra: [<87e224f0>] tval: 10040014

sp:  87fffd70 gp:   tp:  0001
t0:  83f16cf0 t1:  0002 t2:  
s0:  83f16c78 s1:  87eaf590 a0:  03f940aa
a1:  83f0fee0 a2:  0001 a3:  83f0f3d8
a4:  0002 a5:  1004 a6:  0001
a7:  00ff s2:  83f0fee0 s3:  
s4:  f000 s5:  0008 s6:  80201ca0
s7:  0001 s8:  000db4f8 s9:  87fe
s10:  s11:  t3:  0048
t4:   t5:   t6:  fffd
### ERROR ### Please RESET the board ###

If I revert the 'RISC-V: sifive: enable SPI Flash and SD in config' commit then 
'./test/emulate.pl sifive_defconfig' runs successfully.

> To test SD-Card:
> 
>   ./test/emulate.pl sifive_defconfig  -- -drive file=image.sdcard,if=sd
> 
> Signed-off-by: Ahmad Fatoum 
> ---
> v1 -> v2:
>   - No change
> ---
>  arch/riscv/configs/sifive_defconfig | 13 +++--
>  1 file changed, 7 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/riscv/configs/sifive_defconfig 
> b/arch/riscv/configs/sifive_defconfig
> index 59cfebf194df..6ebe6eaf3785 100644
> --- a/arch/riscv/configs/sifive_defconfig
> +++ b/arch/riscv/configs/sifive_defconfig
> @@ -13,13 +13,10 @@ CONFIG_HUSH_FANCY_PROMPT=y
>  CONFIG_CMDLINE_EDITING=y
>  CONFIG_AUTO_COMPLETE=y
>  CONFIG_MENU=y
> -CONFIG_IMD_TARGET=y
>  CONFIG_CONSOLE_ALLOW_COLOR=y
>  CONFIG_PBL_CONSOLE=y
>  CONFIG_PARTITION_DISK_EFI=y
>  CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW=y
> -CONFIG_BAREBOXENV_TARGET=y
> -CONFIG_BAREBOXCRC32_TARGET=y
>  CONFIG_STATE=y
>  CONFIG_STATE_CRYPTO=y
>  CONFIG_BOOTCHOOSER=y
> @@ -85,20 +82,21 @@ CONFIG_VIRTIO_CONSOLE=y
>  CONFIG_SERIAL_SIFIVE=y
>  CONFIG_DRIVER_NET_MACB=y
>  CONFIG_DRIVER_SPI_GPIO=y
> +CONFIG_SPI_SIFIVE=y
>  CONFIG_I2C=y
>  CONFIG_I2C_GPIO=y
>  CONFIG_MTD=y
> -# CONFIG_MTD_OOB_DEVICE is not set
> +CONFIG_MTD_RAW_DEVICE=y
>  CONFIG_MTD_CONCAT=y
>  CONFIG_MTD_M25P80=y
>  CONFIG_DRIVER_CFI=y
>  CONFIG_DRIVER_CFI_BANK_WIDTH_8=y
> -CONFIG_DISK=y
> -CONFIG_DISK_WRITE=y
>  CONFIG_VIRTIO_BLK=y
>  CONFIG_VIDEO=y
>  CONFIG_FRAMEBUFFER_CONSOLE=y
>  CONFIG_DRIVER_VIDEO_SIMPLEFB_CLIENT=y
> +CONFIG_MCI=y
> +CONFIG_MCI_SPI=y
>  CONFIG_CLOCKSOURCE_DUMMY_RATE=6
>  CONFIG_EEPROM_AT24=y
>  CONFIG_HWRNG=y
> @@ -126,3 +124,6 @@ CONFIG_ZSTD_DECOMPRESS=y
>  CONFIG_XZ_DECOMPRESS=y
>  CONFIG_BASE64=y
>  CONFIG_DIGEST_CRC32_GENERIC=y
> +CONFIG_IMD_TARGET=y
> +CONFIG_BAREBOXENV_TARGET=y
> +CONFIG_BAREBOXCRC32_TARGET=y
> -- 
> 2.34.1
> 
> 
> ___
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox


-- 
Best regards,
  Antony Pavlov



Re: [PATCH v2 2/4] pbl: export pbl_barebox_verify

2022-08-20 Thread Antony Pavlov
atic int pbl_barebox_verify(void *compressed_start, unsigned int len, void 
> *hash,
> -   unsigned int hash_len)
> +int pbl_barebox_verify(const void *compressed_start, unsigned int len,
> +const void *hash, unsigned int hash_len)
>  {
>   struct sha256_state sha_state = { 0 };
>   struct digest d = { .ctx = _state };
>   char computed_hash[SHA256_DIGEST_SIZE];
>   int i;
> - char *char_hash = hash;
> + const char *char_hash = hash;
>  
>   if (hash_len != SHA256_DIGEST_SIZE)
>   return -1;
> -- 
> 2.30.2
> 
> 


-- 
Best regards,
  Antony Pavlov



[PATCH] asm-generic: provide phys_to_virt() and virt_to_phys()

2022-07-26 Thread Antony Pavlov
The arm, riscv, sandbox and x86 architectures use
just the same phys_to_virt()/virt_to_phys() implementation.
Only the mips architecture has its own special implementation.

So we can move phys_to_virt() and virt_to_phys()
generic implementation to include/asm-generic/io.h.

Use override functions way introduced in the 9216efafc52ff99e
("asm-generic/io.h: Reconcile I/O accessor overrides")
linux kernel commit.

Signed-off-by: Antony Pavlov 
---
 arch/arm/include/asm/io.h | 10 --
 arch/mips/include/asm/io.h|  2 ++
 arch/riscv/include/asm/io.h   | 10 --
 arch/sandbox/include/asm/io.h | 10 --
 arch/x86/include/asm/io.h | 10 --
 include/asm-generic/io.h  | 20 
 6 files changed, 22 insertions(+), 40 deletions(-)

diff --git a/arch/arm/include/asm/io.h b/arch/arm/include/asm/io.h
index 1c0f522d1d4..486b1429502 100644
--- a/arch/arm/include/asm/io.h
+++ b/arch/arm/include/asm/io.h
@@ -18,14 +18,4 @@ extern void memcpy_fromio(void *, const volatile void 
__iomem *, size_t);
 extern void memcpy_toio(volatile void __iomem *, const void *, size_t);
 extern void memset_io(volatile void __iomem *, int, size_t);
 
-static inline void *phys_to_virt(unsigned long phys)
-{
-   return (void *)phys;
-}
-
-static inline unsigned long virt_to_phys(volatile void *mem)
-{
-   return (unsigned long)mem;
-}
-
 #endif /* __ASM_ARM_IO_H */
diff --git a/arch/mips/include/asm/io.h b/arch/mips/include/asm/io.h
index 0d228aa0f51..a3acbd7017c 100644
--- a/arch/mips/include/asm/io.h
+++ b/arch/mips/include/asm/io.h
@@ -27,6 +27,7 @@ void dma_inv_range(unsigned long, unsigned long);
  * The returned physical address is the physical (CPU) mapping for
  * the memory address given.
  */
+#define virt_to_phys virt_to_phys
 static inline unsigned long virt_to_phys(const void *address)
 {
return (unsigned long)CPHYSADDR(address);
@@ -39,6 +40,7 @@ static inline unsigned long virt_to_phys(const void *address)
  * The returned virtual address is a current CPU mapping for
  * the memory address given.
  */
+#define phys_to_virt phys_to_virt
 static inline void *phys_to_virt(unsigned long address)
 {
if (IS_ENABLED(CONFIG_MMU)) {
diff --git a/arch/riscv/include/asm/io.h b/arch/riscv/include/asm/io.h
index 978f6443407..76d66c0a3b8 100644
--- a/arch/riscv/include/asm/io.h
+++ b/arch/riscv/include/asm/io.h
@@ -7,14 +7,4 @@
 
 #include 
 
-static inline void *phys_to_virt(unsigned long phys)
-{
-   return (void *)phys;
-}
-
-static inline unsigned long virt_to_phys(volatile void *mem)
-{
-   return (unsigned long)mem;
-}
-
 #endif /* __ASM_RISCV_IO_H */
diff --git a/arch/sandbox/include/asm/io.h b/arch/sandbox/include/asm/io.h
index 71cf50cd9a0..eec279b8883 100644
--- a/arch/sandbox/include/asm/io.h
+++ b/arch/sandbox/include/asm/io.h
@@ -11,14 +11,4 @@ extern unsigned char __pci_iobase[IO_SPACE_LIMIT];
 
 #include 
 
-static inline void *phys_to_virt(unsigned long phys)
-{
-   return (void *)phys;
-}
-
-static inline unsigned long virt_to_phys(volatile void *mem)
-{
-   return (unsigned long)mem;
-}
-
 #endif /* __ASM_SANDBOX_IO_H */
diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
index 41c5cb3c14f..d4b5c269190 100644
--- a/arch/x86/include/asm/io.h
+++ b/arch/x86/include/asm/io.h
@@ -84,16 +84,6 @@ static inline void io_delay(void)
inb(0x80);
 }
 
-static inline void *phys_to_virt(unsigned long phys)
-{
-   return (void *)phys;
-}
-
-static inline unsigned long virt_to_phys(volatile void *mem)
-{
-   return (unsigned long)mem;
-}
-
 #include 
 
 #endif /* __ASM_X86_IO_H */
diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h
index 47f8c3ec1be..e41b4df4036 100644
--- a/include/asm-generic/io.h
+++ b/include/asm-generic/io.h
@@ -421,6 +421,26 @@ static inline void iowrite64be(u64 value, volatile void 
__iomem *addr)
 #endif
 #endif /* CONFIG_64BIT */
 
+/*
+ * Change virtual addresses to physical addresses and vv.
+ * These are pretty trivial
+ */
+#ifndef virt_to_phys
+#define virt_to_phys virt_to_phys
+static inline unsigned long virt_to_phys(volatile void *mem)
+{
+   return (unsigned long)mem;
+}
+#endif
+
+#ifndef phys_to_virt
+#define phys_to_virt phys_to_virt
+static inline void *phys_to_virt(unsigned long phys)
+{
+   return (void *)phys;
+}
+#endif
+
 #ifndef IOMEM
 #define IOMEM(addr)((void __force __iomem *)(addr))
 #endif
-- 
2.36.1




[PATCH] net: rtl8169: make it work on big-endian system

2022-06-16 Thread Antony Pavlov
Signed-off-by: Antony Pavlov 
---
 drivers/net/rtl8169.c | 34 +-
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/drivers/net/rtl8169.c b/drivers/net/rtl8169.c
index 80997dc89f4..341f5f240e4 100644
--- a/drivers/net/rtl8169.c
+++ b/drivers/net/rtl8169.c
@@ -230,13 +230,13 @@ static void rtl8169_init_ring(struct rtl8169_priv *priv)
for (i = 0; i < NUM_RX_DESC; i++) {
if (i == (NUM_RX_DESC - 1))
priv->rx_desc[i].status =
-   BD_STAT_OWN | BD_STAT_EOR | PKT_BUF_SIZE;
+   cpu_to_le32(BD_STAT_OWN | BD_STAT_EOR | 
PKT_BUF_SIZE);
else
priv->rx_desc[i].status =
-   BD_STAT_OWN | PKT_BUF_SIZE;
+   cpu_to_le32(BD_STAT_OWN | PKT_BUF_SIZE);
 
priv->rx_desc[i].buf_addr =
-   virt_to_phys(priv->rx_buf + i * PKT_BUF_SIZE);
+   cpu_to_le32(virt_to_phys(priv->rx_buf + i * 
PKT_BUF_SIZE));
}
 }
 
@@ -358,21 +358,21 @@ static int rtl8169_eth_send(struct eth_device *edev, void 
*packet,
 
priv->tx_desc[entry].buf_Haddr = 0;
priv->tx_desc[entry].buf_addr =
-   virt_to_phys(priv->tx_buf + entry * PKT_BUF_SIZE);
+   cpu_to_le32(virt_to_phys(priv->tx_buf + entry * PKT_BUF_SIZE));
 
if (entry != (NUM_TX_DESC - 1)) {
priv->tx_desc[entry].status =
-   BD_STAT_OWN | BD_STAT_FS | BD_STAT_LS |
-   ((packet_length > ETH_ZLEN) ? packet_length : ETH_ZLEN);
+   cpu_to_le32(BD_STAT_OWN | BD_STAT_FS | BD_STAT_LS |
+   ((packet_length > ETH_ZLEN) ? packet_length : 
ETH_ZLEN));
} else {
priv->tx_desc[entry].status =
-   BD_STAT_OWN | BD_STAT_EOR | BD_STAT_FS | BD_STAT_LS |
-   ((packet_length > ETH_ZLEN) ? packet_length : ETH_ZLEN);
+   cpu_to_le32(BD_STAT_OWN | BD_STAT_EOR | BD_STAT_FS | 
BD_STAT_LS |
+   ((packet_length > ETH_ZLEN) ? packet_length : 
ETH_ZLEN));
}
 
RTL_W8(priv, TxPoll, 0x40);
 
-   while (priv->tx_desc[entry].status & BD_STAT_OWN)
+   while (le32_to_cpu(priv->tx_desc[entry].status) & BD_STAT_OWN)
;
 
dma_sync_single_for_cpu((unsigned long)priv->tx_buf + entry *
@@ -391,9 +391,9 @@ static int rtl8169_eth_rx(struct eth_device *edev)
 
entry = priv->cur_rx % NUM_RX_DESC;
 
-   if ((priv->rx_desc[entry].status & BD_STAT_OWN) == 0) {
-   if (!(priv->rx_desc[entry].status & BD_STAT_RX_RES)) {
-   pkt_size = (priv->rx_desc[entry].status & 0x1fff) - 4;
+   if ((le32_to_cpu(priv->rx_desc[entry].status) & BD_STAT_OWN) == 0) {
+   if (!(le32_to_cpu(priv->rx_desc[entry].status) & 
BD_STAT_RX_RES)) {
+   pkt_size = (le32_to_cpu(priv->rx_desc[entry].status) & 
0x1fff) - 4;
 
dma_sync_single_for_cpu((unsigned long)priv->rx_buf
+ entry * PKT_BUF_SIZE,
@@ -407,14 +407,14 @@ static int rtl8169_eth_rx(struct eth_device *edev)
   pkt_size, DMA_FROM_DEVICE);
 
if (entry == NUM_RX_DESC - 1)
-   priv->rx_desc[entry].status = BD_STAT_OWN |
-   BD_STAT_EOR | PKT_BUF_SIZE;
+   priv->rx_desc[entry].status = 
cpu_to_le32(BD_STAT_OWN |
+   BD_STAT_EOR | PKT_BUF_SIZE);
else
priv->rx_desc[entry].status =
-   BD_STAT_OWN | PKT_BUF_SIZE;
+   cpu_to_le32(BD_STAT_OWN | PKT_BUF_SIZE);
priv->rx_desc[entry].buf_addr =
-   virt_to_phys(priv->rx_buf +
-entry * PKT_BUF_SIZE);
+   cpu_to_le32(virt_to_phys(priv->rx_buf +
+entry * PKT_BUF_SIZE));
} else {
dev_err(>dev, "rx error\n");
}
-- 
2.36.1




move dma_ops to common code

2022-06-16 Thread Antony Pavlov
Hi!

In 0e885ce81d0e ('RISC-V: dma: support multiple dma_alloc_coherent backends') ,
(see 
https://lore.barebox.org/barebox/20210619045055.779-10-a.fat...@pengutronix.de/)
multiple dma_alloc_coherent backends was introduced for RISC-V.

At the moment MIPS dma_alloc_coherent stuff is messy and I want to rework it.
I can reuse some parts of 0e885ce81d0e by moving it to the common code.
Any comments or suggestions?

-- 
Best regards,
  Antony Pavlov



Re: [PATCH 0/1] MIPS: fix optimised memset returning garbage

2022-03-10 Thread Antony Pavlov
On Thu, 10 Mar 2022 16:40:39 +0300
Denis Orlov  wrote:

Hi Denis!

I'm very glad to see that you have found this anoying bug!

Some tips:

* you comment from "PATCH 0/1" is very informative but after applying "PATCH 
1/1"
to the mainline this very informative comment remain in maillist archive but not
in the barebox git repo; Could you please combine "PATCH 0/1" comment and 
"PATCH 1/1"
comment and resend single "PATCH v2" ?

* I propose this ammendment for your comment:

> --- a/PATCH-0/1
> +++ b/PATCH-0/1
> @@ -108,8 +108,8 @@ List-Archive: <https://lore.barebox.org/barebox/>
>  There is currently a bug in memset implementation from
>  arch/mips/lib/memset.S that is used when MIPS_OPTIMIZED_STRING_FUNCTIONS
>  option is enabled. It stems from a missing '.set noreorder' directive
> -before the first branch. This results in an assembler stuffing a 'nop'
> -instruction in a delay slot instead of an instruction writing the return
> +before the first beqz instruction. This results in an assembler stuffing a 
> 'nop'
> +instruction in the beqz delay slot instead of an instruction writing the 
> return
>  value into v0 register that was supposed to go there. That leads to an
>  error that appears when reading memory from SPI Flash and that was
>  mentioned here:

-- 
Best regards,
  Antony Pavlov



> There is currently a bug in memset implementation from
> arch/mips/lib/memset.S that is used when MIPS_OPTIMIZED_STRING_FUNCTIONS
> option is enabled. It stems from a missing '.set noreorder' directive
> before the first branch. This results in an assembler stuffing a 'nop'
> instruction in a delay slot instead of an instruction writing the return
> value into v0 register that was supposed to go there. That leads to an
> error that appears when reading memory from SPI Flash and that was
> mentioned here:
> http://lists.infradead.org/pipermail/barebox/2021-June/036557.html.
> 
> There are a few ways of fixing this bug. The directive '.set noreorder'
> that shows up a bit later in code could be moved up and placed right
> before the memset label (as it was originally in Linux codebase - see
> a583158c9ce822c96a718fbf877cec1e5f9ad75d). Or, rather, the move and the
> branch instruction could be swapped, thus allowing the assembler to
> properly place move in delay slot (as it is done in Linux now - see
> 68dec269ee29c3abfd09596fbee7e40d875a6ab3) - that is what is done in
> patch.
> 
> Denis Orlov (1):
>   MIPS: fix optimised memset returning garbage
> 
>  arch/mips/lib/memset.S | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> -- 
> 2.20.1
> 
> 
> ___
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox


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


Re: [PATCH 1/1] Documentation: devel: add new project ideas section

2022-02-18 Thread Antony Pavlov
On Thu, 17 Feb 2022 09:27:14 +0100
Ahmad Fatoum  wrote:

Hi!

...

> +Update barebox networking stack for IPv6 support
> +
> +
> +Skills: C, Networking
> +
> +The barebox network stack is mainly used for TFTP and NFSv3 (over UDP) boot.
> +Most embedded systems barebox runs on aren't deployed to IPv6 networks yet,
> +so it's the right time now to future-proof and learn more about networking
> +internals. One major complication with IPv6 support is neighbor discovery
> +protocols that require networking to be possible "in the background".
> +barebox' recent improvements of resource sharing and cooperative scheduling
> +makes it possible to integrate an IPv6 stack, e.g. lwIP.

Several years ago I have tried to integrate picotcp network stack into barebox,
please see 
http://lists.infradead.org/pipermail/barebox/2015-June/thread.html#23749
and https://github.com/frantony/barebox/tree/20190707.picotcp
This work can be revived after current picotcp state of affairs investigation.

> +There are also community patches to integrate a TCP stack into barebox.
> +These can be evaluated as time allows.

picotcp supports both IPv6 and TCP.

> +This project does not require dedicated hardware. QEMU or barebox built
> +to run under Linux (sandbox) may be used.
> +

-- 
Best regards,
  Antony Pavlov

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


[PATCH] imd: add optional endianness= parameter for bi-endian systems

2022-02-10 Thread Antony Pavlov
MIPS architecture supports both little- and big-endian modes.
It's handy to have means to determine endianness of barebox
image. This patch adds necessary record into imd block.

Signed-off-by: Antony Pavlov 
---
 common/Kconfig   |  6 ++
 common/imd-barebox.c | 10 ++
 2 files changed, 16 insertions(+)

diff --git a/common/Kconfig b/common/Kconfig
index 667b0a1e79..f8d99bd48c 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -730,6 +730,12 @@ config IMD
select CRC32
bool "barebox metadata support"
 
+config IMD_ENDIANNESS
+   bool "add endianness record to metadata"
+   depends on IMD
+   depends on SYS_SUPPORTS_LITTLE_ENDIAN && SYS_SUPPORTS_BIG_ENDIAN
+   default y
+
 choice
prompt "console support"
default CONSOLE_FULL
diff --git a/common/imd-barebox.c b/common/imd-barebox.c
index e11fdca845..7877c8de39 100644
--- a/common/imd-barebox.c
+++ b/common/imd-barebox.c
@@ -23,6 +23,16 @@ __BAREBOX_IMD_SECTION(.barebox_imd_end) = {
.type = cpu_to_le32(IMD_TYPE_END),
 };
 
+#ifdef CONFIG_IMD_ENDIANNESS
+#ifdef CONFIG_CPU_LITTLE_ENDIAN
+#define IMD_ENDIANNESS "little"
+#else
+#define IMD_ENDIANNESS "big"
+#endif
+BAREBOX_IMD_TAG_STRING(imd_endianness_tag, IMD_TYPE_PARAMETER,
+   "endianness=" IMD_ENDIANNESS, 1);
+#endif /* CONFIG_IMD_ENDIANNESS */
+
 BAREBOX_IMD_TAG_STRING(imd_build_tag, IMD_TYPE_BUILD, UTS_VERSION, 1);
 BAREBOX_IMD_TAG_STRING(imd_release_tag, IMD_TYPE_RELEASE, UTS_RELEASE, 1);
 BAREBOX_IMD_TAG_STRING(imd_buildsystem_version_tag, IMD_TYPE_BUILDSYSTEM, 
BUILDSYSTEM_VERSION, 1);
-- 
2.33.0


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


Re: RFC: Gitlab CI for barebox

2022-02-08 Thread Antony Pavlov
On Sat, 5 Feb 2022 17:12:33 +0300
Antony Pavlov  wrote:

> On Mon, 31 Jan 2022 11:39:45 +0100
> Ahmad Fatoum  wrote:
> 
> Hello Ahmad!
> 
> > On 30.01.22 13:00, Antony Pavlov wrote:
> > > Hi!
> > > 
> > > I have made simple Gitlab CI for barebox.
> > 
> > Nice.
> > 
> > > Gitlab CI runner setup instruction and
> > > the source for Debian 11 docker image can be found at:
> > > 
> > >   https://gitlab.com/frantony/barebox-gitlab-ci-runner
> > 
> > I had tried something similar, but with Github actions
> > 
> > https://github.com/a3f/barebox/actions/runs/740206381
> > 
> > I didn't have the time to pursue this further. I am fine
> > with Gitlab as well.
> > 
> > > 
> > > Sample gitlab-ci.yaml config file:
> > > 
> > >   
> > > https://gitlab.com/frantony/barebox/-/commit/b1ed597d8e67c8f76f4f98cd1c6605b936cf2471
> > 
> > Here's how it looks for Github actions with emulate.pl:
> > 
> > https://github.com/a3f/barebox/blob/emulate.pl/.github/workflows/build-configs.yaml
> 
> I have just update gitlab runner, please see 
> https://gitlab.com/frantony/barebox-gitlab-ci-runner/-/commit/f90c3932f1e90f900c4d4304c6a54898a5ee0e1e
> 
> As a result runner can build barebox for openrisc architecture and run 
> emulate.pl, see
> https://gitlab.com/frantony/barebox/-/pipelines/464224894
> 
> There is a problem with emulate.pl for MIPS (see 
> https://gitlab.com/frantony/barebox/-/jobs/2058215656).
> 
> log/mips/console_main artifact contains the fragment:
> 
>  begin 
> Hit any to stop autoboot:3
> barebox@qemu malta:/ echo "YGIS""XTJCSB"
> YGISXTJCSB
> barebox@qemu malta:/ echo -o /cmd 'cat /env/data/config'; echo 
> "EOVL""SAWCFS"; sh /cmd; echo "EOVL""SAWCFS" $?;
> EOVLSAWCFS
> could not open /env/data/config: No such file or directory
> EOVLSAWCFS 1
> barebox@qemu malta:/ echo -o /cmd selftest; echo "BOCZ""OJHGFV"; sh /cmd; 
> echo "BOCZ""OJHGFV" $?;
> BOCZOJHGFV
> printf: all 116 tests passed
> progress_notifier: all 12 tests passed
> BOCZOJHGFV 0
> barebox@qemu malta:/
>  end 
> 
> there is a problem: "could not open /env/data/config: No such file or 
> directory"

The same problem with ARM architecture.
It looks like CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW_IKCONFIG=y is set only in 
RISC-V virt{32/64}_defconfig.

-- 
Best regards,
  Antony Pavlov

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


Re: RFC: Gitlab CI for barebox

2022-02-05 Thread Antony Pavlov
On Mon, 31 Jan 2022 11:39:45 +0100
Ahmad Fatoum  wrote:

Hello Ahmad!

> On 30.01.22 13:00, Antony Pavlov wrote:
> > Hi!
> > 
> > I have made simple Gitlab CI for barebox.
> 
> Nice.
> 
> > Gitlab CI runner setup instruction and
> > the source for Debian 11 docker image can be found at:
> > 
> >   https://gitlab.com/frantony/barebox-gitlab-ci-runner
> 
> I had tried something similar, but with Github actions
> 
> https://github.com/a3f/barebox/actions/runs/740206381
> 
> I didn't have the time to pursue this further. I am fine
> with Gitlab as well.
> 
> > 
> > Sample gitlab-ci.yaml config file:
> > 
> >   
> > https://gitlab.com/frantony/barebox/-/commit/b1ed597d8e67c8f76f4f98cd1c6605b936cf2471
> 
> Here's how it looks for Github actions with emulate.pl:
> 
> https://github.com/a3f/barebox/blob/emulate.pl/.github/workflows/build-configs.yaml

I have just update gitlab runner, please see 
https://gitlab.com/frantony/barebox-gitlab-ci-runner/-/commit/f90c3932f1e90f900c4d4304c6a54898a5ee0e1e

As a result runner can build barebox for openrisc architecture and run 
emulate.pl, see
https://gitlab.com/frantony/barebox/-/pipelines/464224894

There is a problem with emulate.pl for MIPS (see 
https://gitlab.com/frantony/barebox/-/jobs/2058215656).

log/mips/console_main artifact contains the fragment:

 begin 
Hit any to stop autoboot:3
barebox@qemu malta:/ echo "YGIS""XTJCSB"
YGISXTJCSB
barebox@qemu malta:/ echo -o /cmd 'cat /env/data/config'; echo "EOVL""SAWCFS"; 
sh /cmd; echo "EOVL""SAWCFS" $?;
EOVLSAWCFS
could not open /env/data/config: No such file or directory
EOVLSAWCFS 1
barebox@qemu malta:/ echo -o /cmd selftest; echo "BOCZ""OJHGFV"; sh /cmd; echo 
"BOCZ""OJHGFV" $?;
BOCZOJHGFV
printf: all 116 tests passed
progress_notifier: all 12 tests passed
BOCZOJHGFV 0
barebox@qemu malta:/
 end 

there is a problem: "could not open /env/data/config: No such file or directory"

How we can pass error to gitlab runner? Now runner reports that there is no 
error.

> > 
> > @Ahmad
> > 
> > I suppose we can add your qemu barebox/test/emulate.pl tests into CI.
> 
> Here is the Github action config for the tests:
> https://github.com/a3f/barebox/blob/emulate.pl/.github/workflows/vm-tests.yaml
> 
> Any thoughts on how/if to integrate with the mailing list?

I suppose gitlab itself can send e-mails on CI pipeline fail.


-- 
Best regards,
  Antony Pavlov

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


RFC: Gitlab CI for barebox

2022-01-30 Thread Antony Pavlov
Hi!

I have made simple Gitlab CI for barebox.

Gitlab CI runner setup instruction and
the source for Debian 11 docker image can be found at:

  https://gitlab.com/frantony/barebox-gitlab-ci-runner

Sample gitlab-ci.yaml config file:

  
https://gitlab.com/frantony/barebox/-/commit/b1ed597d8e67c8f76f4f98cd1c6605b936cf2471

Corresponding gitlab pipeline results:

  https://gitlab.com/frantony/barebox/-/pipelines/459422690


Some notes:

  * there are several "images size > maximum size" errors during 'build ARM'
  * fake firmware blobs for ARM are used
  * 'build doc' produces sphinx generated html docs archive artifact
  * 'build ARM/MIPS/RISC-V/X86/sandbox' produce log/ directory archive artifacts
  * no support for kvx, openrisc and powerpc

@Ahmad

I suppose we can add your qemu barebox/test/emulate.pl tests into CI.

-- 
Best regards,
  Antony Pavlov

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


[PATCH] pinctrl: rockchip: drop unused variable 'name'

2022-01-30 Thread Antony Pavlov
Signed-off-by: Antony Pavlov 
---
 drivers/pinctrl/pinctrl-rockchip.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/pinctrl/pinctrl-rockchip.c 
b/drivers/pinctrl/pinctrl-rockchip.c
index 869cce1982..c99074407f 100644
--- a/drivers/pinctrl/pinctrl-rockchip.c
+++ b/drivers/pinctrl/pinctrl-rockchip.c
@@ -877,7 +877,6 @@ static struct rockchip_pin_ctrl 
*rockchip_pinctrl_get_soc_data(
struct device_node *np;
struct rockchip_pin_ctrl *ctrl;
struct rockchip_pin_bank *bank;
-   char *name;
int grf_offs, pmu_offs, drv_grf_offs, drv_pmu_offs, i, j;
int gpio = 0;
 
-- 
2.33.0


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


Re: [PATCH v2 1/1] kbuild: dtc: Allow adding device tree fragments via config

2022-01-26 Thread Antony Pavlov
s-frags = $(subst $(quote),,$(CONFIG_EXTERNAL_DTS_FRAGMENTS))
>  quiet_cmd_dtc = DTC $@
> -cmd_dtc = $(CPP) $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) $< ; \
> +# For compatibility between make 4.2 and 4.3
> +H := \#
> +cmd_dtc = /bin/echo -e '$(H)define $(subst -,_,$(*F))_dts 1\n'$(foreach f,$< 
> $(dts-frags),'$(H)include "$(f)"\n') | \
> + $(CPP) $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) - ; \
>   $(objtree)/scripts/dtc/dtc -O dtb -o $@ -b 0 \
>   -i $(srctree)/arch/$(SRCARCH)/dts $(DTC_FLAGS) \
>   -i $(srctree)/dts/src/$(SRCARCH) \
> -- 
> 2.31.1
> 
> 
> ___
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox


-- 
Best regards,
  Antony Pavlov

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


Re: [PATCH 06/12] mci: sdhci: Use Linux defines for SDHCI_HOST_CONTROL register

2022-01-26 Thread Antony Pavlov
On Wed, 26 Jan 2022 10:23:17 +0100
Sascha Hauer  wrote:

> On Wed, Jan 26, 2022 at 09:32:33AM +0300, Antony Pavlov wrote:
> > On Mon,  7 Jun 2021 12:44:05 +0200
> > Sascha Hauer  wrote:
> > 
> > Hi Sascha!
> > 
> > > To ease porting and comparing of Linux code.
> > > 
> > > Signed-off-by: Sascha Hauer 
> > > ---
> > >  drivers/mci/arasan-sdhci.c   | 12 ++--
> > >  drivers/mci/atmel-sdhci-common.c | 14 +++---
> > >  drivers/mci/dove-sdhci.c | 10 +-
> > >  drivers/mci/sdhci.h  | 17 -
> > >  4 files changed, 30 insertions(+), 23 deletions(-)
> > > 
> > > diff --git a/drivers/mci/arasan-sdhci.c b/drivers/mci/arasan-sdhci.c
> > > index e22db4cfa3..e02f222345 100644
> > > --- a/drivers/mci/arasan-sdhci.c
> > > +++ b/drivers/mci/arasan-sdhci.c
> > 
> > ...
> > 
> > > @@ -200,21 +200,21 @@ static void arasan_sdhci_set_ios(struct mci_host 
> > > *mci, struct mci_ios *ios)
> > >   }
> > >  
> > >   val = sdhci_read8(>sdhci, SDHCI_HOST_CONTROL) &
> > > - ~(SDHCI_DATA_WIDTH_4BIT | SDHCI_DATA_WIDTH_8BIT);
> > > + ~(SDHCI_CTRL_8BITBUS | SDHCI_CTRL_8BITBUS);
> > >  
> > >   switch (ios->bus_width) {
> > >   case MMC_BUS_WIDTH_8:
> > > - val |= SDHCI_DATA_WIDTH_8BIT;
> > > + val |= SDHCI_CTRL_8BITBUS;
> > >   break;
> > >   case MMC_BUS_WIDTH_4:
> >  
> > > - val |= SDHCI_DATA_WIDTH_4BIT;
> >   ^^^
> > > + val |= SDHCI_CTRL_8BITBUS;
> >   ^^^
> > Is this correct?
> 
> Nope, indeed not. Fortunately it's fixed in the same series in "[PATCH
> 08/12] mci: sdhci: arasan: Use sdhci_set_bus_width()". The other places
> need fixing though, patch is out.
> 
> Thanks for noting
> 

It looks like that there is one more line to fix. Please see

> diff --git a/drivers/mci/dove-sdhci.c b/drivers/mci/dove-sdhci.c
> index 9c10e67eb8..cafc9dc579 100644
> --- a/drivers/mci/dove-sdhci.c
> +++ b/drivers/mci/dove-sdhci.c
> @@ -224,20 +224,20 @@ static void dove_sdhci_mci_set_ios(struct mci_host 
> *mci, struct mci_ios *ios)
>  
>   /* set bus width */
>   val = sdhci_read8(>sdhci, SDHCI_HOST_CONTROL) &
> - ~(SDHCI_DATA_WIDTH_4BIT | SDHCI_DATA_WIDTH_8BIT);
> + ~(SDHCI_CTRL_8BITBUS | SDHCI_CTRL_8BITBUS);

"SDHCI_CTRL_4BITBUS | SDHCI_CTRL_8BITBUS" instead of "SDHCI_CTRL_8BITBUS | 
SDHCI_CTRL_8BITBUS",
I suppose.


-- 
Best regards,
  Antony Pavlov

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


Re: [PATCH 06/12] mci: sdhci: Use Linux defines for SDHCI_HOST_CONTROL register

2022-01-25 Thread Antony Pavlov
On Mon,  7 Jun 2021 12:44:05 +0200
Sascha Hauer  wrote:

Hi Sascha!

> To ease porting and comparing of Linux code.
> 
> Signed-off-by: Sascha Hauer 
> ---
>  drivers/mci/arasan-sdhci.c   | 12 ++--
>  drivers/mci/atmel-sdhci-common.c | 14 +++---
>  drivers/mci/dove-sdhci.c | 10 +-
>  drivers/mci/sdhci.h  | 17 -
>  4 files changed, 30 insertions(+), 23 deletions(-)
> 
> diff --git a/drivers/mci/arasan-sdhci.c b/drivers/mci/arasan-sdhci.c
> index e22db4cfa3..e02f222345 100644
> --- a/drivers/mci/arasan-sdhci.c
> +++ b/drivers/mci/arasan-sdhci.c

...

> @@ -200,21 +200,21 @@ static void arasan_sdhci_set_ios(struct mci_host *mci, 
> struct mci_ios *ios)
>   }
>  
>   val = sdhci_read8(>sdhci, SDHCI_HOST_CONTROL) &
> - ~(SDHCI_DATA_WIDTH_4BIT | SDHCI_DATA_WIDTH_8BIT);
> + ~(SDHCI_CTRL_8BITBUS | SDHCI_CTRL_8BITBUS);
>  
>   switch (ios->bus_width) {
>   case MMC_BUS_WIDTH_8:
> - val |= SDHCI_DATA_WIDTH_8BIT;
> + val |= SDHCI_CTRL_8BITBUS;
>   break;
>   case MMC_BUS_WIDTH_4:
 
> - val |= SDHCI_DATA_WIDTH_4BIT;
  ^^^
> + val |= SDHCI_CTRL_8BITBUS;
  ^^^
Is this correct?

>   break;
>   }
>  
>   if (ios->clock > 2600)
> - val |= SDHCI_HIGHSPEED_EN;
> + val |= SDHCI_CTRL_HISPD;
>   else
> - val &= ~SDHCI_HIGHSPEED_EN;
> + val &= ~SDHCI_CTRL_HISPD;
>  
>   sdhci_write8(>sdhci, SDHCI_HOST_CONTROL, val);
>  }
> diff --git a/drivers/mci/atmel-sdhci-common.c 
> b/drivers/mci/atmel-sdhci-common.c
> index b391775b00..d2b777a93c 100644
> --- a/drivers/mci/atmel-sdhci-common.c
> +++ b/drivers/mci/atmel-sdhci-common.c

...

> @@ -297,15 +297,15 @@ static int at91_sdhci_set_bus_width(struct at91_sdhci 
> *host, unsigned bus_width)
>  
>   switch(bus_width) {
>   case MMC_BUS_WIDTH_8:
> - reg |= SDHCI_DATA_WIDTH_8BIT;
> + reg |= SDHCI_CTRL_8BITBUS;
>   break;
>   case MMC_BUS_WIDTH_4:
 ^^^

> - reg &= ~SDHCI_DATA_WIDTH_8BIT;
> - reg |= SDHCI_DATA_WIDTH_4BIT;
  ^^^
> + reg &= ~SDHCI_CTRL_8BITBUS;
> + reg |= SDHCI_CTRL_8BITBUS;
  

just the same question here

>   break;
>   default:
> - reg &= ~SDHCI_DATA_WIDTH_8BIT;
> - reg &= ~SDHCI_DATA_WIDTH_4BIT;
> + reg &= ~SDHCI_CTRL_8BITBUS;
> + reg &= ~SDHCI_CTRL_8BITBUS;

and here

>   }
>  
>   sdhci_write8(sdhci, SDHCI_HOST_CONTROL, reg);
> diff --git a/drivers/mci/dove-sdhci.c b/drivers/mci/dove-sdhci.c
> index 9c10e67eb8..cafc9dc579 100644
> --- a/drivers/mci/dove-sdhci.c
> +++ b/drivers/mci/dove-sdhci.c
> @@ -224,20 +224,20 @@ static void dove_sdhci_mci_set_ios(struct mci_host 
> *mci, struct mci_ios *ios)
>  
>   /* set bus width */
>   val = sdhci_read8(>sdhci, SDHCI_HOST_CONTROL) &
> - ~(SDHCI_DATA_WIDTH_4BIT | SDHCI_DATA_WIDTH_8BIT);
> + ~(SDHCI_CTRL_8BITBUS | SDHCI_CTRL_8BITBUS);
>   switch (ios->bus_width) {
>   case MMC_BUS_WIDTH_8:
> - val |= SDHCI_DATA_WIDTH_8BIT;
> + val |= SDHCI_CTRL_8BITBUS;
>   break;
>   case MMC_BUS_WIDTH_4:
> - val |= SDHCI_DATA_WIDTH_4BIT;
> + val |= SDHCI_CTRL_8BITBUS;

and here

>   break;
>   }
>  
>   if (ios->clock > 2600)
> - val |= SDHCI_HIGHSPEED_EN;
> + val |= SDHCI_CTRL_HISPD;
>   else
> - val &= ~SDHCI_HIGHSPEED_EN;
> + val &= ~SDHCI_CTRL_HISPD;
>  
>   sdhci_write8(>sdhci, SDHCI_HOST_CONTROL, val);
>  

-- 
Best regards,
  Antony Pavlov

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


Re: [PATCH 7/9] RISC-V: don't use x8/s0/fp in assembly

2022-01-10 Thread Antony Pavlov
,11 +140,11 @@ nmon_cmd_g:
> > jal a2, _nmon_outc_a0
> >  
> > jal a2, _nmon_gethexw
> > -   moves2, s0
> > +   moves3, s1
> >  
> > nmon_outs   msg_nl
> >  
> > -   jalrs2
> > +   jalrs3
> > j   nmon_main
> >  
> >  _nmon_outc_a0:
> > @@ -169,37 +169,37 @@ _nmon_gethexw:
> >  _get_hex_digit:
> > debug_ll_getc
> >  
> > -   li  s1, CODE_ESC
> > -   beq s0, s1, nmon_main
> > +   li  s2, CODE_ESC
> > +   beq s1, s2, nmon_main
> >  
> > -   li  s1, '0'
> > -   bge s0, s1, 0f
> > +   li  s2, '0'
> > +   bge s1, s2, 0f
> > j   _get_hex_digit
> >  
> >  0:
> > -   li  s1, '9'
> > -   ble s0, s1, 9f
> > +   li  s2, '9'
> > +   ble s1, s2, 9f
> >  
> > -   li  s1, 'f'
> > -   ble s0, s1, 1f
> > +   li  s2, 'f'
> > +   ble s1, s2, 1f
> > j   _get_hex_digit
> >  
> >  1:
> > -   li  s1, 'a'
> > -   bge s0, s1, 8f
> > +   li  s2, 'a'
> > +   bge s1, s2, 8f
> >  
> > j   _get_hex_digit
> >  
> > -8: /* s0 \in {'a', 'b' ... 'f'} */
> > -   sub a3, s0, s1
> > +8: /* s1 \in {'a', 'b' ... 'f'} */
> > +   sub a3, s1, s2
> > addia3, a3, 0xa
> > j   0f
> >  
> > -9: /* s0 \in {'0', '1' ... '9'} */
> > +9: /* s1 \in {'0', '1' ... '9'} */
> > li  a3, '0'
> > -   sub a3, s0, a3
> > +   sub a3, s1, a3
> >  
> > -0: movea0, s0
> > +0: movea0, s1
> > debug_ll_outc_a0
> >  
> > sll t2, t2, 4
> > @@ -212,7 +212,7 @@ _get_hex_digit:
> > j   _get_hex_digit
> >  
> >  0:
> > -   moves0, t2
> > +   moves1, t2
> >  
> >  _nmon_jr_ra_exit:
> > jr  a2
> > 
> 
> 
> -- 
> Pengutronix e.K.   | |
> Steuerwalder Str. 21   | http://www.pengutronix.de/  |
> 31137 Hildesheim, Germany  | Phone: +49-5121-206917-0|
> Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |


-- 
Best regards,
  Antony Pavlov

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


[PATCH] rtc: import pcf85363 support from linux-5.12

2021-12-26 Thread Antony Pavlov
Signed-off-by: Antony Pavlov 
---
 drivers/rtc/Kconfig|   6 ++
 drivers/rtc/Makefile   |   1 +
 drivers/rtc/rtc-pcf85363.c | 169 +
 3 files changed, 176 insertions(+)

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index e9374d0f2a..314c2c085a 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -37,6 +37,12 @@ config RTC_DRV_DS1307
 config RTC_DRV_ABRACON
tristate "Abracon RTCs"
 
+config RTC_DRV_PCF85363
+   tristate "NXP PCF85363"
+   depends on I2C
+   help
+ If you say yes here you get support for the PCF85363 RTC chip.
+
 endif # I2C
 
 config RTC_DRV_IMXDI
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index c831198872..9b2893e585 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -12,3 +12,4 @@ obj-$(CONFIG_RTC_DRV_ABRACON)   += rtc-abracon.o
 obj-$(CONFIG_RTC_DRV_DS1307)+= rtc-ds1307.o
 obj-$(CONFIG_RTC_DRV_IMXDI)+= rtc-imxdi.o
 obj-$(CONFIG_RTC_DRV_JZ4740)   += rtc-jz4740.o
+obj-$(CONFIG_RTC_DRV_PCF85363) += rtc-pcf85363.o
diff --git a/drivers/rtc/rtc-pcf85363.c b/drivers/rtc/rtc-pcf85363.c
new file mode 100644
index 00..7b785d6a77
--- /dev/null
+++ b/drivers/rtc/rtc-pcf85363.c
@@ -0,0 +1,169 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * drivers/rtc/rtc-pcf85363.c
+ *
+ * Driver for NXP PCF85363 real-time clock.
+ *
+ * Copyright (C) 2017 Eric Nelson
+ *
+ * This code is ported from linux-5.12
+ * by Antony Pavlov 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/*
+ * Date/Time registers
+ */
+#define DT_100THS  0x00
+#define DT_SECS0x01
+#define DT_MINUTES 0x02
+#define DT_HOURS   0x03
+#define DT_DAYS0x04
+#define DT_WEEKDAYS0x05
+#define DT_MONTHS  0x06
+#define DT_YEARS   0x07
+
+/*
+ * control registers
+ */
+#define CTRL_STOP_EN   0x2e
+
+#define STOP_EN_STOP   BIT(0)
+
+#define RESET_CPR  0xa4
+
+struct pcf85363 {
+   struct rtc_device   rtc;
+   struct regmap   *regmap;
+};
+
+static inline struct pcf85363 *to_pcf85363_priv(struct rtc_device *rtcdev)
+{
+   return container_of(rtcdev, struct pcf85363, rtc);
+}
+
+static int pcf85363_rtc_read_time(struct rtc_device *rtcdev,
+   struct rtc_time *tm)
+{
+   struct device_d *dev = rtcdev->dev;
+   struct pcf85363 *pcf85363 = to_pcf85363_priv(rtcdev);
+   unsigned char buf[DT_YEARS + 1];
+   int ret, len = sizeof(buf);
+
+   /* read the RTC date and time registers all at once */
+   ret = regmap_bulk_read(pcf85363->regmap, DT_100THS, buf, len);
+   if (ret) {
+   dev_err(dev, "%s: error %d\n", __func__, ret);
+   return ret;
+   }
+
+   tm->tm_year = bcd2bin(buf[DT_YEARS]);
+   /* adjust for 1900 base of rtc_time */
+   tm->tm_year += 100;
+
+   tm->tm_wday = buf[DT_WEEKDAYS] & 7;
+   buf[DT_SECS] &= 0x7F;
+   tm->tm_sec = bcd2bin(buf[DT_SECS]);
+   buf[DT_MINUTES] &= 0x7F;
+   tm->tm_min = bcd2bin(buf[DT_MINUTES]);
+   tm->tm_hour = bcd2bin(buf[DT_HOURS]);
+   tm->tm_mday = bcd2bin(buf[DT_DAYS]);
+   tm->tm_mon = bcd2bin(buf[DT_MONTHS]) - 1;
+
+   return 0;
+}
+
+static int pcf85363_rtc_set_time(struct rtc_device *rtcdev, struct rtc_time 
*tm)
+{
+   struct pcf85363 *pcf85363 = to_pcf85363_priv(rtcdev);
+   unsigned char tmp[11];
+   unsigned char *buf = [2];
+   int ret;
+
+   tmp[0] = STOP_EN_STOP;
+   tmp[1] = RESET_CPR;
+
+   buf[DT_100THS] = 0;
+   buf[DT_SECS] = bin2bcd(tm->tm_sec);
+   buf[DT_MINUTES] = bin2bcd(tm->tm_min);
+   buf[DT_HOURS] = bin2bcd(tm->tm_hour);
+   buf[DT_DAYS] = bin2bcd(tm->tm_mday);
+   buf[DT_WEEKDAYS] = tm->tm_wday;
+   buf[DT_MONTHS] = bin2bcd(tm->tm_mon + 1);
+   buf[DT_YEARS] = bin2bcd(tm->tm_year % 100);
+
+   ret = regmap_bulk_write(pcf85363->regmap, CTRL_STOP_EN,
+   tmp, 2);
+   if (ret)
+   return ret;
+
+   ret = regmap_bulk_write(pcf85363->regmap, DT_100THS,
+   buf, sizeof(tmp) - 2);
+   if (ret)
+   return ret;
+
+   return regmap_write(pcf85363->regmap, CTRL_STOP_EN, 0);
+}
+
+static const struct rtc_class_ops rtc_ops = {
+   .read_time  = pcf85363_rtc_read_time,
+   .set_time   = pcf85363_rtc_set_time,
+};
+
+static const struct regmap_config pcf85363_regmap_i2c_config = {
+   .reg_bits = 8,
+   .val_bits = 8,
+   .max_register = 0x7f,
+};
+
+static int pcf85363_probe(struct device_d *dev)
+{
+   struct i2c_client *client = to_i2c_client(dev);
+   struct pcf85363 *pcf85363;
+   struct regmap *regmap;
+   int ret;
+
+   regmap = regmap_init_i2c(client,
+   

Re: [PATCH] spi: add STM32 SPI controller driver

2021-11-19 Thread Antony Pavlov
On Thu, 18 Nov 2021 13:32:18 +0100
Ahmad Fatoum  wrote:

Hi Ahmad!

> On 08.11.21 18:01, Antony Pavlov wrote:
> > On Fri,  5 Nov 2021 08:46:57 +0100
> > Ahmad Fatoum  wrote:
> > 
> >> Tested on a STM32MP1 communicating with a ksz9563.
> > 
> > ...
> > 
> >> diff --git a/drivers/spi/stm32_spi.c b/drivers/spi/stm32_spi.c
> >> new file mode 100644
> >> index ..0cb04a968c8a
> >> --- /dev/null
> >> +++ b/drivers/spi/stm32_spi.c
> >> @@ -0,0 +1,590 @@
> >> +// SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
> >> +/*
> >> + * Copyright (C) 2019, STMicroelectronics - All Rights Reserved
> >> + *
> >> + * Driver for STMicroelectronics Serial peripheral interface (SPI)
> >> + */
> >> +
> > 
> > ...
> > 
> >> +/* STM32_SPI_CR2 bit fields */
> >> +#define SPI_CR2_TSIZE GENMASK(15, 0)
> > 
> > So SPI_CR2_TSIZE is (64K - 1)
> > 
> > ...
> > 
> >> +
> >> +static int stm32_spi_transfer_one(struct stm32_spi_priv *priv,
> >> +struct spi_transfer *t)
> >> +{
> >> +  struct device_d *dev = priv->master.dev;
> >> +  u32 sr;
> >> +  u32 ifcr = 0;
> >> +  u32 mode;
> >> +  int xfer_status = 0;
> >> +
> >> +  if (t->len <= SPI_CR2_TSIZE)
> >> +  writel(t->len, priv->base + STM32_SPI_CR2);
> >> +  else
> >> +  return -EMSGSIZE;
> > 
> > So stm32_spi_transfer_one() can transfer no more than (64K - 1).
> > At the other hand imd tends to read more than  (64K - 1) from SPI flash, 
> > e.g.
> > 
> >   barebox:/ imd /dev/m25p0
> >   imd: error 90
> > 
> > Here is my solution for handling SPI flash by stm32 SPI driver (not tested 
> > on stm32):
> 
> Thanks for the input. I believe I have STM32 with a SPI flash, where
> I should be able to test this. I'll report back once I come around to it.
> 
> Can I have your Signed-off-by for this patch here?

Yes, please add my Signed-off-by for the patch.

-- 
Best regards,
  Antony Pavlov

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


Re: [PATCH] spi: add STM32 SPI controller driver

2021-11-08 Thread Antony Pavlov
On Fri,  5 Nov 2021 08:46:57 +0100
Ahmad Fatoum  wrote:

> Tested on a STM32MP1 communicating with a ksz9563.

...

> diff --git a/drivers/spi/stm32_spi.c b/drivers/spi/stm32_spi.c
> new file mode 100644
> index ..0cb04a968c8a
> --- /dev/null
> +++ b/drivers/spi/stm32_spi.c
> @@ -0,0 +1,590 @@
> +// SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
> +/*
> + * Copyright (C) 2019, STMicroelectronics - All Rights Reserved
> + *
> + * Driver for STMicroelectronics Serial peripheral interface (SPI)
> + */
> +

...

> +/* STM32_SPI_CR2 bit fields */
> +#define SPI_CR2_TSIZEGENMASK(15, 0)

So SPI_CR2_TSIZE is (64K - 1)

...

> +
> +static int stm32_spi_transfer_one(struct stm32_spi_priv *priv,
> +   struct spi_transfer *t)
> +{
> + struct device_d *dev = priv->master.dev;
> + u32 sr;
> + u32 ifcr = 0;
> + u32 mode;
> + int xfer_status = 0;
> +
> + if (t->len <= SPI_CR2_TSIZE)
> + writel(t->len, priv->base + STM32_SPI_CR2);
> + else
> + return -EMSGSIZE;

So stm32_spi_transfer_one() can transfer no more than (64K - 1).
At the other hand imd tends to read more than  (64K - 1) from SPI flash, e.g.

  barebox:/ imd /dev/m25p0
  imd: error 90

Here is my solution for handling SPI flash by stm32 SPI driver (not tested on 
stm32):

+#include 
+
+static int stm32_spi_adjust_op_size(struct spi_mem *mem, struct spi_mem_op *op)
+{
+   if (op->data.nbytes > SPI_CR2_TSIZE) {
+   op->data.nbytes = SPI_CR2_TSIZE;
+   }
+
+   return 0;
+}
+
+static int stm32_spi_exec_op(struct spi_mem *mem, const struct spi_mem_op *op)
+{
+   return -ENOTSUPP;
+}
+
+static const struct spi_controller_mem_ops stm32_spi_mem_ops = {
+   .adjust_op_size = stm32_spi_adjust_op_size,
+   .exec_op = stm32_spi_exec_op,
+};
+

...

@@ static int stm32_spi_probe(struct device_d *dev)

...

master->setup = stm32_spi_setup;
master->transfer = stm32_spi_transfer;
+   master->mem_ops = _spi_mem_ops;
master->bus_num = -1;
stm32_spi_dt_probe(priv);

-- 
Best regards,
  Antony Pavlov

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


Re: do we need regmap-i2c in barebox?

2021-11-03 Thread Antony Pavlov
Hi Ahmad!

On Wed, 3 Nov 2021 at 20:39, Ahmad Fatoum  wrote:
>
> Hello Antony,
>
> On 03.11.21 18:35, Antony Pavlov wrote:
> > Hi!
> >
> > I have made draft version of pcf85363 i2c rtc driver for barebox.
> > I used drivers/rtc/rtc-pcf85363.c from linux kernel as a prototype.
> > The linux driver uses REGMAP_I2C linux feature. Barebox has regmap
> > framework, but no special i2c regmap features.
>
> There is d827f61e149b ("regmap: implement regmap_init_i2c")
> since barebox v2021.07.0. What extra functionality are you missing?

Many thanks for pointing on d827f61e149b, I have missed it in the maillist!

At the moment I use v2021.06.0 as the base of my production branch.

I'll try to upgrade my pcf85363 driver to use regmap_init_i2c and test
it in a several days.

-- 
Best regards,
  Antony Pavlov

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


[just draft RFC] rtc: add simple pcf85363 driver

2021-11-03 Thread Antony Pavlov
Signed-off-by: Antony Pavlov 
---
 drivers/rtc/Kconfig|   7 ++
 drivers/rtc/Makefile   |   1 +
 drivers/rtc/rtc-pcf85363.c | 195 +
 3 files changed, 203 insertions(+)
 create mode 100644 drivers/rtc/rtc-pcf85363.c

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 9d2c6e614b..50f352f422 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -36,6 +36,13 @@ config RTC_DRV_DS1307
 config RTC_DRV_ABRACON
tristate "Abracon RTCs"
 
+config RTC_DRV_PCF85363
+   tristate "NXP PCF85363"
+   depends on I2C
+   select REGMAP_I2C
+   help
+ If you say yes here you get support for the PCF85363 RTC chip.
+
 endif # I2C
 
 config RTC_DRV_IMXDI
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 1308beff38..163264a8c6 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -11,3 +11,4 @@ obj-$(CONFIG_RTC_DRV_ABRACON)   += rtc-abracon.o
 obj-$(CONFIG_RTC_DRV_DS1307)+= rtc-ds1307.o
 obj-$(CONFIG_RTC_DRV_IMXDI)+= rtc-imxdi.o
 obj-$(CONFIG_RTC_DRV_JZ4740)   += rtc-jz4740.o
+obj-$(CONFIG_RTC_DRV_PCF85363) += rtc-pcf85363.o
diff --git a/drivers/rtc/rtc-pcf85363.c b/drivers/rtc/rtc-pcf85363.c
new file mode 100644
index 00..3c4da5a536
--- /dev/null
+++ b/drivers/rtc/rtc-pcf85363.c
@@ -0,0 +1,195 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * drivers/rtc/rtc-pcf85363.c
+ *
+ * Driver for NXP PCF85363 real-time clock.
+ *
+ * Copyright (C) 2017 Eric Nelson
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/*
+ * Date/Time registers
+ */
+#define DT_100THS  0x00
+#define DT_SECS0x01
+#define DT_MINUTES 0x02
+#define DT_HOURS   0x03
+#define DT_DAYS0x04
+#define DT_WEEKDAYS0x05
+#define DT_MONTHS  0x06
+#define DT_YEARS   0x07
+
+/*
+ * control registers
+ */
+#define CTRL_STOP_EN   0x2e
+
+#define STOP_EN_STOP   BIT(0)
+
+#define RESET_CPR  0xa4
+
+struct pcf85363 {
+   struct rtc_device   rtc;
+   struct regmap   *regmap;
+
+   struct i2c_client   *client;
+};
+
+
+static int pcf85363_i2c_reg_read(void *ctx, unsigned int reg, unsigned int 
*val)
+{
+   struct pcf85363 *pcf85363 = ctx;
+   u8 buf[1];
+   int ret;
+
+   ret = i2c_read_reg(pcf85363->client, reg, buf, 1);
+   *val = buf[0];
+
+   return ret == 1 ? 0 : ret;
+}
+
+static int pcf85363_i2c_reg_write(void *ctx, unsigned int reg, unsigned int 
val)
+{
+   struct pcf85363 *pcf85363 = ctx;
+   u8 buf[] = {
+   val & 0xff,
+   };
+   int ret;
+
+   ret = i2c_write_reg(pcf85363->client, reg, buf, 1);
+
+   return ret == 1 ? 0 : ret;
+}
+
+static struct regmap_bus regmap_pcf85363_i2c_bus = {
+   .reg_write = pcf85363_i2c_reg_write,
+   .reg_read = pcf85363_i2c_reg_read,
+};
+
+static inline struct pcf85363 *to_pcf85363_priv(struct rtc_device *rtcdev)
+{
+   return container_of(rtcdev, struct pcf85363, rtc);
+}
+
+static int pcf85363_rtc_read_time(struct rtc_device *rtcdev, struct rtc_time 
*tm)
+{
+   struct device_d *dev = rtcdev->dev;
+   struct pcf85363 *pcf85363 = to_pcf85363_priv(rtcdev);
+   unsigned char buf[DT_YEARS + 1];
+   int ret, len = sizeof(buf);
+
+   /* read the RTC date and time registers all at once */
+   ret = regmap_bulk_read(pcf85363->regmap, DT_100THS, buf, len);
+   if (ret) {
+   dev_err(dev, "%s: error %d\n", __func__, ret);
+   return ret;
+   }
+
+   tm->tm_year = bcd2bin(buf[DT_YEARS]);
+   /* adjust for 1900 base of rtc_time */
+   tm->tm_year += 100;
+
+   tm->tm_wday = buf[DT_WEEKDAYS] & 7;
+   buf[DT_SECS] &= 0x7F;
+   tm->tm_sec = bcd2bin(buf[DT_SECS]);
+   buf[DT_MINUTES] &= 0x7F;
+   tm->tm_min = bcd2bin(buf[DT_MINUTES]);
+   tm->tm_hour = bcd2bin(buf[DT_HOURS]);
+   tm->tm_mday = bcd2bin(buf[DT_DAYS]);
+   tm->tm_mon = bcd2bin(buf[DT_MONTHS]) - 1;
+
+   return 0;
+}
+
+static int pcf85363_rtc_set_time(struct rtc_device *rtcdev, struct rtc_time 
*tm)
+{
+   struct pcf85363 *pcf85363 = to_pcf85363_priv(rtcdev);
+   unsigned char tmp[11];
+   unsigned char *buf = [2];
+   int ret;
+
+   tmp[0] = STOP_EN_STOP;
+   tmp[1] = RESET_CPR;
+
+   buf[DT_100THS] = 0;
+   buf[DT_SECS] = bin2bcd(tm->tm_sec);
+   buf[DT_MINUTES] = bin2bcd(tm->tm_min);
+   buf[DT_HOURS] = bin2bcd(tm->tm_hour);
+   buf[DT_DAYS] = bin2bcd(tm->tm_mday);
+   buf[DT_WEEKDAYS] = tm->tm_wday;
+   buf[DT_MONTHS] = bin2bcd(tm->tm_mon + 1);
+   buf[DT_YEARS] = bin2bcd(tm->tm_year % 100);
+
+   ret = regmap_bulk_write(pcf85363->regmap, CTRL_STOP_EN,
+   tmp, 2);
+   if (ret)
+   return ret;
+
+   ret = regmap_bulk

do we need regmap-i2c in barebox?

2021-11-03 Thread Antony Pavlov
Hi!

I have made draft version of pcf85363 i2c rtc driver for barebox.
I used drivers/rtc/rtc-pcf85363.c from linux kernel as a prototype.
The linux driver uses REGMAP_I2C linux feature. Barebox has regmap
framework, but no special i2c regmap features.

In barebox source tree I have found drivers/mfd/stpmic1.c which
uses regmap for i2c device without REGMAP_I2C linux feature.
So I have just stolen i2c regmap code from stpmic1.c for pcf85363
driver. I'll send pcf85363 i2c rtc driver for barebox in a separate
message.

Is there any sense in porting drivers/base/regmap/regmap-i2c.c from
linux into barebox?

-- 
Best regards,
  Antony Pavlov

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


Re: [PATCH 4/4] bareboximd: make the '-c' option work again

2021-10-28 Thread Antony Pavlov
On Thu, 28 Oct 2021 08:45:19 +0200
Ahmad Fatoum  wrote:


Hi Ahmad!

> On 28.10.21 03:28, Antony Pavlov wrote:
> > bareboximd with the '-c' option craches while
> > trying to alter an image file, e.g.:
> > 
> > barebox$ git describe
> > v2021.10.0-125-gd136ec5ac6
> > barebox$ make ARCH=arm CROSS_COMPILE=aarch64-linux-gnu- imx_v8_defconfig
> > ...
> > barebox$ make ARCH=arm CROSS_COMPILE=aarch64-linux-gnu-
> > ...
> > images built:
> > barebox-nxp-imx8mm-evk.img
> > barebox-prt-prt8mm.img
> > barebox-nxp-imx8mn-evk.img
> > barebox-nxp-imx8mp-evk.img
> > barebox-nxp-imx8mq-evk.img
> > barebox-zii-imx8mq-dev.img
> > barebox-phytec-phycore-imx8mq.img
> > barebox$ ./scripts/bareboximd images/barebox-phytec-phycore-imx8mq.img
> > build: #1 Thu Oct 28 01:11:07 UTC 2021
> > buildsystem version:
> > crc32: 0x
> > release: 2021.10.0-00125-gd136ec5ac6
> > barebox$ ./scripts/bareboximd -c 
> > images/barebox-phytec-phycore-imx8mq.img
> > Segmentation fault (core dumped)
> > 
> > The problem is that the bareboximd uses mmap() on an image file
> > in read-only mode.
> > 
> > Signed-off-by: Antony Pavlov 
> > ---
> >  scripts/bareboximd.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/scripts/bareboximd.c b/scripts/bareboximd.c
> > index c3dcb4dcf0..fe0d274380 100644
> > --- a/scripts/bareboximd.c
> > +++ b/scripts/bareboximd.c
> > @@ -97,7 +97,7 @@ static int read_file_2(const char *filename, size_t 
> > *size, void **outbuf, size_t
> > goto close;
> > }
> >  
> > -   buf = mmap(NULL, max_size, PROT_READ, MAP_SHARED, fd, 0);
> > +   buf = mmap(NULL, max_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
> 
> I think this here only works incidentally, by failing and then doing a 
> malloc. See mmap(2):
> 
> Errors: EACCESMAP_SHARED was requested and PROT_WRITE is set, but fd is  
> not  open 
>   in  read/write  (O_RDWR)  mode.
> 
> Correct would be MAP_PRIVATE. I sent a patch to that effect yesterday:
> https://lore.barebox.org/barebox/20211027060150.28184-1-a.fat...@pengutronix.de/T/#u

Aghh! I have not seen your patch :(

> 
> > if (buf == MAP_FAILED ) {
> > buf = malloc(max_size);
> > if (!buf) {
> > 
> 
> 
> -- 
> Pengutronix e.K.   | |
> Steuerwalder Str. 21   | http://www.pengutronix.de/  |
> 31137 Hildesheim, Germany  | Phone: +49-5121-206917-0|
> Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |


-- 
Best regards,
  Antony Pavlov

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


[PATCH 2/4] imd: reuse imd_is_crc32()

2021-10-27 Thread Antony Pavlov
Signed-off-by: Antony Pavlov 
---
 common/imd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/imd.c b/common/imd.c
index e1d5733c6b..0295d84d34 100644
--- a/common/imd.c
+++ b/common/imd.c
@@ -317,7 +317,7 @@ static int imd_calculate_crc32(void *input, const struct 
imd_header *imd_start,
length = ALIGN(length, 4);
length += sizeof(struct imd_header);
 
-   if (imd_read_type(imd) == IMD_TYPE_CRC32) {
+   if (imd_is_crc32(imd_read_type(imd))) {
*imd_crc = (struct imd_header *)imd;
debug("Found crc token at %d\n", end_ofs);
break;
-- 
2.33.0


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


[PATCH 1/4] imd: fix imd_is_crc32()

2021-10-27 Thread Antony Pavlov
Signed-off-by: Antony Pavlov 
---
 include/image-metadata.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/image-metadata.h b/include/image-metadata.h
index a9cb9cfe8f..439a0cba81 100644
--- a/include/image-metadata.h
+++ b/include/image-metadata.h
@@ -67,7 +67,7 @@ struct imd_entry_crc32 {
 
 static inline int imd_is_crc32(uint32_t type)
 {
-   return (type & IMD_TYPE_CRC32) ? 1 : 0;
+   return type == IMD_TYPE_CRC32;
 }
 
 static inline int imd_crc32_is_valid(uint32_t flags)
-- 
2.33.0


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


[PATCH 0/4] imd fixes

2021-10-27 Thread Antony Pavlov
Antony Pavlov (4):
  imd: fix imd_is_crc32()
  imd: reuse imd_is_crc32()
  include/image-metadata.h: fix whitespaces in the BAREBOX_IMD_CRC macro
  bareboximd: make the '-c' option work again

 common/imd.c | 2 +-
 include/image-metadata.h | 8 
 scripts/bareboximd.c | 2 +-
 3 files changed, 6 insertions(+), 6 deletions(-)

-- 
2.33.0


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


[PATCH 4/4] bareboximd: make the '-c' option work again

2021-10-27 Thread Antony Pavlov
bareboximd with the '-c' option craches while
trying to alter an image file, e.g.:

barebox$ git describe
v2021.10.0-125-gd136ec5ac6
barebox$ make ARCH=arm CROSS_COMPILE=aarch64-linux-gnu- imx_v8_defconfig
...
barebox$ make ARCH=arm CROSS_COMPILE=aarch64-linux-gnu-
...
images built:
barebox-nxp-imx8mm-evk.img
barebox-prt-prt8mm.img
barebox-nxp-imx8mn-evk.img
barebox-nxp-imx8mp-evk.img
barebox-nxp-imx8mq-evk.img
barebox-zii-imx8mq-dev.img
barebox-phytec-phycore-imx8mq.img
barebox$ ./scripts/bareboximd images/barebox-phytec-phycore-imx8mq.img
build: #1 Thu Oct 28 01:11:07 UTC 2021
buildsystem version:
crc32: 0x
release: 2021.10.0-00125-gd136ec5ac6
barebox$ ./scripts/bareboximd -c images/barebox-phytec-phycore-imx8mq.img
Segmentation fault (core dumped)

The problem is that the bareboximd uses mmap() on an image file
in read-only mode.

Signed-off-by: Antony Pavlov 
---
 scripts/bareboximd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/bareboximd.c b/scripts/bareboximd.c
index c3dcb4dcf0..fe0d274380 100644
--- a/scripts/bareboximd.c
+++ b/scripts/bareboximd.c
@@ -97,7 +97,7 @@ static int read_file_2(const char *filename, size_t *size, 
void **outbuf, size_t
goto close;
}
 
-   buf = mmap(NULL, max_size, PROT_READ, MAP_SHARED, fd, 0);
+   buf = mmap(NULL, max_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (buf == MAP_FAILED ) {
buf = malloc(max_size);
if (!buf) {
-- 
2.33.0


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


[PATCH 3/4] include/image-metadata.h: fix whitespaces in the BAREBOX_IMD_CRC macro

2021-10-27 Thread Antony Pavlov
Signed-off-by: Antony Pavlov 
---
 include/image-metadata.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/image-metadata.h b/include/image-metadata.h
index 439a0cba81..bf4e08d98a 100644
--- a/include/image-metadata.h
+++ b/include/image-metadata.h
@@ -139,12 +139,12 @@ int imd_verify_crc32(void *buf, size_t size);
}
 
 #define BAREBOX_IMD_CRC(_name, _crc, _keep_if_unused)  
\
-   const struct imd_entry_crc32 __barebox_imd_##__name 
\
-   __BAREBOX_IMD_SECTION(.barebox_imd_ ## _keep_if_unused ## _ ## _name) = 
{   \
+   const struct imd_entry_crc32 __barebox_imd_##__name 
\
+   __BAREBOX_IMD_SECTION(.barebox_imd_ ## _keep_if_unused ## _ ## _name) = 
{   \
.header.type = cpu_to_le32(IMD_TYPE_CRC32), 
\
.header.datalength = cpu_to_le32(sizeof(uint32_t) * 2), 
\
.data = _crc,   
\
-  }
+   }
 
 #ifdef CONFIG_IMD
 void imd_used(const void *);
-- 
2.33.0


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


[PATCH] Documentation/boards/riscv.rst: fix code blocks

2021-10-06 Thread Antony Pavlov
Signed-off-by: Antony Pavlov 
---
 Documentation/boards/riscv.rst | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Documentation/boards/riscv.rst b/Documentation/boards/riscv.rst
index 97f4d1deb7..b7a3a95f0f 100644
--- a/Documentation/boards/riscv.rst
+++ b/Documentation/boards/riscv.rst
@@ -168,13 +168,13 @@ Connect to board's UART with your favorite serial 
communication software
 (e.g. minicom) and check 'nmon> ' prompt (nmon runs from onchip ROM).
 
 Next close your communication software and use ./scripts/nmon-loader
-to load barebox image into board's DRAM, e.g.
+to load barebox image into board's DRAM, e.g.::
 
   # ./scripts/nmon-loader barebox.erizo.nmon /dev/ttyUSB0 115200
 
 Wait several munutes for 'nmon> ' prompt.
 
-Next, start barebox from DRAM:
+Next, start barebox from DRAM::
 
   nmon> g 8000
   Switch to console [cs0]
-- 
2.33.0


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


inkscape 1.1.1 issue

2021-10-06 Thread Antony Pavlov
Hi!

I have just update inkscape from Debian repo.
It looks like inkscape-1.1.1 has new unexpected behaviour.

During barebox sandbox build process I have faced with unexpected
inkscape dialog. Also the '--without-gui=' option is depricated.
See my build log

barebox$ make
...
Warning: Option --without-gui= is deprecated
Unable to init server: Could not connect: Connection refused
Background RRGGBBAA: ff00
Area 0:0:3000:1500 exported to 640 x 320 pixels (20.48 dpi)
  LOGO.S   lib/logo/barebox-logo-w640.bblogo.S
  AS  lib/logo/barebox-logo-w640.bblogo.o
  AR  lib/logo/built-in.a
  AR  lib/built-in.a
  GEN .version
  CHK include/generated/compile.h
  UPD include/generated/compile.h
  CC  common/version.o
  CC  common/imd-barebox.o
  AR  common/built-in.a
  LD  barebox
  SYSMAP  System.map
  OBJCOPY barebox.bin
  CHKFILESIZE barebox.bin
  LN  barebox-flash-image
antony@cinco:~/barebox$ dpkg -l | grep inkscape
ii  inkscape 1.1.1-2
   amd64vector-based drawing program

-- 
Best regards,
  Antony Pavlov

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


[PATCH] mtd: core: fix whitespaces

2021-10-04 Thread Antony Pavlov
Signed-off-by: Antony Pavlov 
---
 drivers/mtd/core.c | 22 +++---
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/drivers/mtd/core.c b/drivers/mtd/core.c
index 37fccda6be..c6c1e1e7cf 100644
--- a/drivers/mtd/core.c
+++ b/drivers/mtd/core.c
@@ -377,7 +377,7 @@ int mtd_block_markgood(struct mtd_info *mtd, loff_t ofs)
 }
 
 int mtd_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen,
- u_char *buf)
+u_char *buf)
 {
struct mtd_oob_ops ops = {
.len = len,
@@ -420,23 +420,23 @@ int mtd_write_oob(struct mtd_info *mtd, loff_t to,
 }
 
 int mtd_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen,
-  const u_char *buf)
+ const u_char *buf)
 {
-struct mtd_oob_ops ops = {
-.len = len,
-.datbuf = (u8 *)buf,
-};
-int ret;
+   struct mtd_oob_ops ops = {
+   .len = len,
+   .datbuf = (u8 *)buf,
+   };
+   int ret;
 
if (to < 0 || to >= mtd->size || len > mtd->size - to)
return -EINVAL;
if (!len)
return 0;
 
-ret = mtd_write_oob(mtd, to, );
-*retlen = ops.retlen;
+   ret = mtd_write_oob(mtd, to, );
+   *retlen = ops.retlen;
 
-return ret;
+   return ret;
 }
 
 int mtd_erase(struct mtd_info *mtd, struct erase_info *instr)
@@ -757,7 +757,7 @@ err:
return ret;
 }
 
-int del_mtd_device (struct mtd_info *mtd)
+int del_mtd_device(struct mtd_info *mtd)
 {
struct mtddev_hook *hook;
 
-- 
2.33.0


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


Re: 'of_compatible' and 'model' imd records are unusable

2021-10-02 Thread Antony Pavlov
On Sat, 2 Oct 2021 10:48:50 +0200
Sascha Hauer  wrote:

Hi Sascha!

> On Fri, Oct 01, 2021 at 02:24:53PM +0300, Antony Pavlov wrote:
> > Hi all!
> > 
> > I have cloned barebox c67ada0024da (v2021.08.0) and found that
> > 'of_compatible' and 'model' imd records are unusable.
> > 
> > E.g.
> > 
> > barebox$ make ARCH=arm CROSS_COMPILE=aarch64-linux-gnu- imx_v8_defconfig
> > barebox$ make ARCH=arm CROSS_COMPILE=aarch64-linux-gnu-
> > ...
> > images built:
> > barebox-nxp-imx8mm-evk.img
> > barebox-prt-prt8mm.img
> > barebox-nxp-imx8mp-evk.img
> > barebox-nxp-imx8mq-evk.img
> > barebox-zii-imx8mq-dev.img
> > barebox-phytec-phycore-imx8mq.img
> > 
> > barebox$ ./scripts/bareboximd images/barebox-nxp-imx8mm-evk.img
> > build: #1 Fri Oct 1 10:16:30 UTC 2021
> > buildsystem version: 
> > crc32: 0x
> > release: 2021.08.0
> > barebox$ 
> > 
> > There is no 'of_compatible' and 'model' imd records in bareboximd output.
> > 
> > So there is no chance to imd_find_type(..., IMD_TYPE_OF_COMPATIBLE)
> > (see common/bbu.c) in a barebox image file.
> > 
> > scripts/gen-dtb-s puts IMD_TYPE_OF_COMPATIBLE and IMD_TYPE_MODEL
> > records into barebox_imd_0 section.
> > 
> > BAREBOX_IMD macro (include/asm-generic/barebox.lds.h)
> > does not KEEP barebox_imd_0 section":
> 
> This is done on purpose because otherwise...
> 
> > 
> > #define BAREBOX_IMD \
> > STRUCT_ALIGN(); \
> > KEEP(*(.barebox_imd_start)) \
> > KEEP(*(.barebox_imd_1*))\
> > *(.barebox_imd_0*)  \
> > KEEP(*(.barebox_imd_end))
> > 
> > KEEPing barebox_imd_0 leads to several 'of_compatible' and 'model' records
> > in one barebox image file, e.g.:
> 
> ...exactly this would happen.
> 
> To get the of_compatible and model imd tags in an image you have to put
> IMD_USED_OF() explicitly into the entry function of the image handling
> this compatible, there's no way for the build process to know which
> image handles which device tree. See below for an example which adds the
> tags for the boards you are currently compiling.

There are two remarks:

1. It looks like we still able to automatically add of_compatible and model imd 
tags.
Please see my message 
http://lists.infradead.org/pipermail/barebox/2021-October/037412.html

2. I have no lowlevel.c board files on MIPS :(

Can we automaticaly generate of_compatible and model imd tags for most of the 
boards
and explicitly generate tags with IMD_USED_OF() just for selected boards?

-- 
Best regards,
  Antony Pavlov


> 
> Sascha
> 
> 8<-
> 
> From 456d90992fe0b9f4258b693a946f8d13ba5b0b4c Mon Sep 17 00:00:00 2001
> From: Sascha Hauer 
> Date: Sat, 2 Oct 2021 10:45:04 +0200
> Subject: [PATCH] ARM: i.MX8m: Add of_compatible imd tags for i.MX8 boards
> 
> The build process has to be manually told which image is compatible to
> which device tree. Add the IMD_USED_OF() calls to the i.MX8m based
> boards.
> 
> Signed-off-by: Sascha Hauer 
> ---
>  arch/arm/boards/nxp-imx8mm-evk/lowlevel.c| 3 +++
>  arch/arm/boards/nxp-imx8mp-evk/lowlevel.c| 3 +++
>  arch/arm/boards/nxp-imx8mq-evk/lowlevel.c| 3 +++
>  arch/arm/boards/protonic-imx8m/lowlevel-prt8mm.c | 3 +++
>  arch/arm/boards/zii-imx8mq-dev/lowlevel.c| 4 
>  5 files changed, 16 insertions(+)
> 
> diff --git a/arch/arm/boards/nxp-imx8mm-evk/lowlevel.c 
> b/arch/arm/boards/nxp-imx8mm-evk/lowlevel.c
> index 4bd29c2269..c2f6206cfd 100644
> --- a/arch/arm/boards/nxp-imx8mm-evk/lowlevel.c
> +++ b/arch/arm/boards/nxp-imx8mm-evk/lowlevel.c
> @@ -21,6 +21,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  
>  extern char __dtb_imx8mm_evk_start[];
>  
> @@ -177,5 +178,7 @@ ENTRY_FUNCTION(start_nxp_imx8mm_evk, r0, r1, r2)
>   relocate_to_current_adr();
>   setup_c();
>  
> + IMD_USED_OF(imx8mm_evk);
> +
>   nxp_imx8mm_evk_start();
>  }
> diff --git a/arch/arm/boards/nxp-imx8mp-evk/lowlevel.c 
> b/arch/arm/boards/nxp-imx8mp-evk/lowlevel.c
> index 3298ded586..5732ccc645 100644
> --- a/arch/arm/boards/nxp-imx8mp-evk/lowlevel.c
> +++ b/arch/arm/boards/nxp-imx8mp-evk/lowlevel.c
> @@ -4,6 +4,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -189,5 +190,7 @@ ENTRY_FUNCTION(start_nxp_imx8mp_evk, r0, r1, r2)
>   relocate_to_current_adr();
>   setup_c();
>  
> + IMD_USED_O

Re: 'of_compatible' and 'model' imd records are unusable

2021-10-01 Thread Antony Pavlov
On Fri, 1 Oct 2021 14:46:19 +0300
Antony Pavlov  wrote:

Hi all!

> I have cloned barebox c67ada0024da (v2021.08.0) and found that
> 'of_compatible' and 'model' imd records are unusable.

I have found a quick-and-dirty solution for the problem.

of_compatible and model imd types were introduced in

commit 97e81f2d78f30fb4936f0f6fe52b317d8dbc9881
Author: Sascha Hauer 
Date:   Mon Jul 28 07:22:40 2014 +0200

Add support for metadata in barebox images


the commit
commit 58eae8361c10fea661bcb48c4c5e75e7ad19e1c1
Author: Sascha Hauer 
Date:   Fri Oct 23 09:14:54 2015 +0200

ARM: Allow compressed dtb binaries

breaks adding of of_compatible and model records
by changing in scripts/gen-dtb-s.


the commit 
commit c1c818735caa8222d88aa9286a219d6055c1699d
Author: Uwe Kleine-König 
Date:   Thu Feb 21 11:25:30 2019 +0100

imd: create new helper macro to add data from oftree to image meta data

introduces macro for explicit adding of of_compatible
imd record from C code.


You can resurrect of_compatible and model imd records adding
by partialy reverting c1c818735caa822:scripts/gen-dtb-s and 
58eae8361c10fea66:scripts/gen-dtb-s
e.g.

barebox$ make rpi_defconfig
...
barebox$ make
...
barebox$ ./scripts/bareboximd images/barebox-raspberry-pi-3.img
buildsystem version: 
crc32: 0x
build: #8 Fri Oct 1 23:23:30 UTC 2021
release: 2021.08.0

barebox$ patch -p1 < E.g.
> 
> barebox$ make ARCH=arm CROSS_COMPILE=aarch64-linux-gnu- imx_v8_defconfig
> barebox$ make ARCH=arm CROSS_COMPILE=aarch64-linux-gnu-
> ...
> images built:
> barebox-nxp-imx8mm-evk.img
> barebox-prt-prt8mm.img
> barebox-nxp-imx8mp-evk.img
> barebox-nxp-imx8mq-evk.img
> barebox-zii-imx8mq-dev.img
> barebox-phytec-phycore-imx8mq.img
> 
> barebox$ ./scripts/bareboximd images/barebox-nxp-imx8mm-evk.img
> build: #1 Fri Oct 1 10:16:30 UTC 2021
> buildsystem version: 
> crc32: 0x
> release: 2021.08.0
> barebox$ 
> 
> There is no 'of_compatible' and 'model' imd records in bareboximd output.
> 

-- 
Best regards,
  Antony Pavlov

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


'of_compatible' and 'model' imd records are unusable

2021-10-01 Thread Antony Pavlov
Hi all!

I have cloned barebox c67ada0024da (v2021.08.0) and found that
'of_compatible' and 'model' imd records are unusable.

E.g.

barebox$ make ARCH=arm CROSS_COMPILE=aarch64-linux-gnu- imx_v8_defconfig
barebox$ make ARCH=arm CROSS_COMPILE=aarch64-linux-gnu-
...
images built:
barebox-nxp-imx8mm-evk.img
barebox-prt-prt8mm.img
barebox-nxp-imx8mp-evk.img
barebox-nxp-imx8mq-evk.img
barebox-zii-imx8mq-dev.img
barebox-phytec-phycore-imx8mq.img

barebox$ ./scripts/bareboximd images/barebox-nxp-imx8mm-evk.img
build: #1 Fri Oct 1 10:16:30 UTC 2021
buildsystem version: 
crc32: 0x
release: 2021.08.0
barebox$ 

There is no 'of_compatible' and 'model' imd records in bareboximd output.

So there is no chance to imd_find_type(..., IMD_TYPE_OF_COMPATIBLE)
(see common/bbu.c) in a barebox image file.

scripts/gen-dtb-s puts IMD_TYPE_OF_COMPATIBLE and IMD_TYPE_MODEL
records into barebox_imd_0 section.

BAREBOX_IMD macro (include/asm-generic/barebox.lds.h)
does not KEEP barebox_imd_0 section":

#define BAREBOX_IMD \
STRUCT_ALIGN(); \
KEEP(*(.barebox_imd_start)) \
KEEP(*(.barebox_imd_1*))\
*(.barebox_imd_0*)  \
KEEP(*(.barebox_imd_end))

KEEPing barebox_imd_0 leads to several 'of_compatible' and 'model' records
in one barebox image file, e.g.:

barebox$ ./scripts/bareboximd images/barebox-prt-prt8mm.img
build: #2 Fri Oct 1 10:19:07 UTC 2021
buildsystem version: 
crc32: 0x
release: 2021.08.0-dirty
of_compatible: fsl,imx8mm-evk fsl,imx8mm
model: FSL i.MX8MM EVK board
of_compatible: prt,prt8mm fsl,imx8mm
model: Protonic PRT8MM
of_compatible: fsl,imx8mp-evk fsl,imx8mp
model: NXP i.MX8MPlus EVK board
of_compatible: fsl,imx8mq-evk fsl,imx8mq
model: NXP i.MX8MQ EVK
of_compatible: phytec,imx8mq-pcl066 fsl,imx8mq
model: Phytec phyCORE-i.MX8
of_compatible: zii,imx8mq-ultra-rmb3 zii,imx8mq-ultra fsl,imx8mq
model: ZII Ultra RMB3 Board
of_compatible: zii,imx8mq-ultra-zest zii,imx8mq-ultra fsl,imx8mq
model: ZII Ultra Zest Board
builduser@ae676260680c:~/barebox$ 

-- 
Best regards,
  Antony Pavlov

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


Re: Fwd: [PATCH] serial: implement riscv SBI console support

2021-09-25 Thread Antony Pavlov
vice *cdev)
> +{
> +   struct sbi_serial_priv *priv = cdev->dev->priv;
> +   int c = sbi_console_getchar();
> +
> +   if (c != -1)
> +   priv->b[priv->tail++ & 0x1] = c;
> +   return priv->head != priv->tail;
> +}
> +
> +static int sbi_serial_probe(struct device_d *dev)
> +{
> +   struct sbi_serial_priv *priv;
> +
> +   priv = dev->priv = xzalloc(sizeof(*priv));
> +   priv->cdev.dev= dev;
> +   priv->cdev.putc   = sbi_serial_putc;
> +   priv->cdev.getc   = sbi_serial_getc;
> +   priv->cdev.tstc   = sbi_serial_tstc;
> +   priv->cdev.flush  = 0;
> +   priv->cdev.setbrg = 0;
> +
> +   return console_register(>cdev);
> +}
> +
> +static struct driver_d serial_sbi_driver = {
> +   .name   = "riscv-serial-sbi",
> +   .probe  = sbi_serial_probe,
> +};
> +postcore_platform_driver(serial_sbi_driver);
> --
> 2.32.0
> 
> ___
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox


-- 
Best regards,
  Antony Pavlov

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


Re: [PATCH RESEND v4 7/8] RISC-V: add LiteX SoC and linux-on-litex-vexriscv support

2021-08-30 Thread Antony Pavlov
On Mon, 23 Aug 2021 14:06:09 +0200
Ahmad Fatoum  wrote:

Hi Ahmad!

> On 17.08.21 12:11, Antony Pavlov wrote:
> > LiteX is a Migen-based System on Chip, supporting softcore
> > VexRiscv CPU, a 32-bits Linux Capable RISC-V CPU.
> > 
> > See https://github.com/enjoy-digital/litex and
> > https://github.com/litex-hub/linux-on-litex-vexriscv
> > for details.
> > 
> > Signed-off-by: Antony Pavlov 
> > ---
> >  arch/riscv/Kconfig.socs  |  14 +++
> >  arch/riscv/boards/Makefile   |   1 +
> >  arch/riscv/boards/litex-linux/Makefile   |   3 +
> >  arch/riscv/boards/litex-linux/lowlevel.c |  22 
> >  arch/riscv/dts/Makefile  |   1 +
> >  arch/riscv/dts/litex-linux.dts   |  92 +
> >  arch/riscv/dts/litex_soc_linux.dtsi  |  49 +
> >  arch/riscv/include/asm/debug_ll.h|   3 +
> >  arch/riscv/include/asm/debug_ll_litex.h  | 123 +++
> >  common/Kconfig   |   4 +
> >  images/Makefile.riscv|   4 +
> >  11 files changed, 316 insertions(+)
> > 
> > diff --git a/arch/riscv/Kconfig.socs b/arch/riscv/Kconfig.socs
> > index 221ea133d4..5c281918d5 100644
> > --- a/arch/riscv/Kconfig.socs
> > +++ b/arch/riscv/Kconfig.socs
> > @@ -95,4 +95,18 @@ config SIFIVE_L2
> > bool "SiFive L2 cache controller"
> > depends on CPU_SIFIVE
> >  
> > +config SOC_LITEX
> > +   bool "LiteX SoCs"
> > +   depends on ARCH_RV32I
> > +   select HAS_ASM_DEBUG_LL
> > +   select HAS_NMON
> > +   select USE_COMPRESSED_DTB
> > +   select RISCV_TIMER
> > +
> > +config BOARD_LITEX_LINUX
> > +   bool "litex linux board"
> > +   depends on SOC_LITEX
> > +   select RISCV_M_MODE
> > +   def_bool y
> > +
> >  endmenu
> > diff --git a/arch/riscv/boards/Makefile b/arch/riscv/boards/Makefile
> > index cb28a25d8b..8d5d9d4fc6 100644
> > --- a/arch/riscv/boards/Makefile
> > +++ b/arch/riscv/boards/Makefile
> > @@ -2,3 +2,4 @@
> >  obj-$(CONFIG_BOARD_ERIZO_GENERIC)  += erizo/
> >  obj-$(CONFIG_BOARD_HIFIVE) += hifive/
> >  obj-$(CONFIG_BOARD_BEAGLEV)+= beaglev/
> > +obj-$(CONFIG_BOARD_LITEX_LINUX)+= litex-linux/
> > diff --git a/arch/riscv/boards/litex-linux/Makefile 
> > b/arch/riscv/boards/litex-linux/Makefile
> > new file mode 100644
> > index 00..3d217ffe0b
> > --- /dev/null
> > +++ b/arch/riscv/boards/litex-linux/Makefile
> > @@ -0,0 +1,3 @@
> > +# SPDX-License-Identifier: GPL-2.0
> > +
> > +pbl-y += lowlevel.o
> > diff --git a/arch/riscv/boards/litex-linux/lowlevel.c 
> > b/arch/riscv/boards/litex-linux/lowlevel.c
> > new file mode 100644
> > index 00..da23ef5633
> > --- /dev/null
> > +++ b/arch/riscv/boards/litex-linux/lowlevel.c
> > @@ -0,0 +1,22 @@
> > +// SPDX-License-Identifier: GPL-2.0-only
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +ENTRY_FUNCTION(start_litex_linux, a0, a1, a2)
> > +{
> > +   extern char __dtb_z_litex_linux_start[];
> > +   void *fdt;
> > +
> > +   barebox_nmon_entry();
> > +
> > +   putc_ll('>');
> > +
> > +   /* On POR, we are running from read-only memory here. */
> 
> Do we? I thought BIOS loads barebox to RAM first?

Yes, your are right. At the moment litex BIOS loads barebox to RAM first
and this comment must be dropped.

Please note there is a possibility to use barebox instead of litex BIOS
and start barebox on POR from ROM.
linux-on-litex-vexriscv bitstream for Arty board incorporates litex BIOS
so on Arty litex BIOS runs on POR unconditionally.
Litex BIOS is no more than 64K and "one does not simply push barebox into 64K".
But litex works on boards with tiny FPGA resources e.g. iCEBreaker-bitsy.
litex configuration for these tiny FPGA skips internal RAM/ROM and BIOS
starts from SPI flash so there is no limit on barebox image size.



> 
> > +
> > +   fdt = __dtb_z_litex_linux_start + get_runtime_offset();
> > +
> > +   barebox_riscv_machine_entry(0x4000, SZ_256M, fdt);
> > +}
> > diff --git a/arch/riscv/dts/Makefile b/arch/riscv/dts/Makefile
> > index 4a15423b7f..17d7d249e4 100644
> > --- a/arch/riscv/dts/Makefile
> > +++ b/arch/riscv/dts/Makefile
> > @@ -8,5 +8,6 @@ pbl-$(CONFIG_BOARD_ERIZO_GENERIC) += erizo-generic.dtb.o
> >  pbl-$(CONFIG_BOARD_HIFIVE) += hifive-unmatched-a00.dtb.o \
> >hifive-unleashed

Re: [PATCH RESEND v4 1/8] clocksource: timer-riscv: select CSR from device tree

2021-08-30 Thread Antony Pavlov
On Mon, 23 Aug 2021 14:08:52 +0200
Ahmad Fatoum  wrote:

Hi Ahmad!

> On 17.08.21 12:10, Antony Pavlov wrote:
> > barebox timer-riscv driver supports one of user counters:
> > 
> >   * 'cycle', counter for RDCYCLE instruction (CSR 0xc00);
> >   * 'time', timer for RDTIME instruction (CSR 0xc01).
> > 
> > At the moment in M-mode timer-riscv uses the 'cycle' counter,
> > and in S-mode timer-riscv uses the 'time' timer.
> > 
> > Alas picorv32 CPU core supports only the 'cycle' counter.
> > VexRiscV CPU core in M-mode supports only the 'time' timer.
> > 
> > This patch makes it possible to use the 'time' timer
> > for VexRiscV CPU in M-mode.
> > 
> > See also http://lists.infradead.org/pipermail/barebox/2021-May/036067.html
> 
> Comment from earlier series:
> 
> "It also changes the default for M-Mode from cycle to time.
> 
> I can't comment on whether this is ok, I just copied the logic
> 
> from Linux."
> 
> Can you say why this is ok?

v4 patch removes riscv_mode() mention from timer-riscv code
so timer-riscv uses the 'time' timer by default disregarding
M-mode or S-mode is used.

I suppose that the 'time' timer is "more popular" than
the 'cycle' counter.
So IMHO it is ok to use "more popular" feature by default.

> 
> > 
> > Signed-off-by: Antony Pavlov 
> > ---
> >  arch/riscv/dts/erizo.dtsi |  2 ++
> >  drivers/clocksource/timer-riscv.c | 24 
> >  2 files changed, 14 insertions(+), 12 deletions(-)
> > 
> > diff --git a/arch/riscv/dts/erizo.dtsi b/arch/riscv/dts/erizo.dtsi
> > index 228711bd69..4eb92ae6f1 100644
> > --- a/arch/riscv/dts/erizo.dtsi
> > +++ b/arch/riscv/dts/erizo.dtsi
> > @@ -22,6 +22,8 @@
> >  
> > timebase-frequency = <2400>;
> >  
> > +   barebox,csr-cycle;
> > +
> > cpu@0 {
> > device_type = "cpu";
> > compatible = "cliffordwolf,picorv32", "riscv";
> > diff --git a/drivers/clocksource/timer-riscv.c 
> > b/drivers/clocksource/timer-riscv.c
> > index 5a517fe6b4..96637f988a 100644
> > --- a/drivers/clocksource/timer-riscv.c
> > +++ b/drivers/clocksource/timer-riscv.c
> > @@ -12,9 +12,8 @@
> >  #include 
> >  #include 
> >  #include 
> > -#include 
> >  
> > -static u64 notrace riscv_timer_get_count_sbi(void)
> > +static u64 notrace riscv_timer_get_count_time(void)
> >  {
> > __maybe_unused u32 hi, lo;
> >  
> > @@ -29,7 +28,7 @@ static u64 notrace riscv_timer_get_count_sbi(void)
> > return ((u64)hi << 32) | lo;
> >  }
> >  
> > -static u64 notrace riscv_timer_get_count_rdcycle(void)
> > +static u64 notrace riscv_timer_get_count_cycle(void)
> >  {
> > __maybe_unused u32 hi, lo;
> >  
> > @@ -44,24 +43,25 @@ static u64 notrace riscv_timer_get_count_rdcycle(void)
> > return ((u64)hi << 32) | lo;
> >  }
> >  
> > -static u64 notrace riscv_timer_get_count(void)
> > -{
> > -   if (riscv_mode() == RISCV_S_MODE)
> > -   return riscv_timer_get_count_sbi();
> > -   else
> > -   return riscv_timer_get_count_rdcycle();
> > -}
> > -
> >  static struct clocksource riscv_clocksource = {
> > -   .read   = riscv_timer_get_count,
> > .mask   = CLOCKSOURCE_MASK(64),
> > .priority   = 100,
> >  };
> >  
> >  static int riscv_timer_init(struct device_d* dev)
> >  {
> > +   struct device_node *cpu;
> > +
> > dev_dbg(dev, "running at %lu Hz\n", riscv_timebase);
> >  
> > +   cpu = of_find_node_by_path("/cpus");
> > +
> > +   if (of_property_read_bool(cpu, "barebox,csr-cycle")) {
> > +   riscv_clocksource.read = riscv_timer_get_count_cycle;
> > +   } else {
> > +   riscv_clocksource.read = riscv_timer_get_count_time;
> > +   }
> > +
> > riscv_clocksource.mult = clocksource_hz2mult(riscv_timebase, 
> > riscv_clocksource.shift);
> >  
> > return init_clock(_clocksource);
> > 
> 
> 
> -- 
> Pengutronix e.K.   | |
> Steuerwalder Str. 21   | http://www.pengutronix.de/  |
> 31137 Hildesheim, Germany  | Phone: +49-5121-206917-0|
> Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |


-- 
Best regards,
  Antony Pavlov

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


Re: [PATCH v3 00/10] RISC-V: add LiteX SoC support; resurrect nmon

2021-08-17 Thread Antony Pavlov
On Wed, 11 Aug 2021 10:52:53 +0200
Ahmad Fatoum  wrote:

Hi Ahmad!

> Hello Antony,
> 
> On 25.05.21 09:19, Antony Pavlov wrote:
> > Changes since v2:
> > 
> >   * rebase on top of master branch (f873c7ff2497) +
> > "RISC-V: extend multi-image to support both S- and M-Mode"
> > (http://lists.infradead.org/pipermail/barebox/2021-May/036086.html).
> >   * "litex serial: add setbrg callback" patch by Marek Czerski is added
> > for review;
> >   * fix "clocksource: timer-riscv: select CSR from device tree" patch;
> >   * change gpio IP-block base addresses in litex dts;
> >   * gpio-74xx-mmio uses device_get_match_data() now.
> > 
> > Changes since v1:
> > 
> >   * rebased on top of next branch;
> >   * new patches are introduced:
> > * clocksource: timer-riscv: select CSR from device tree
> > * RISC-V: make RISCV_SBI and RISCV_M_MODE explicitly mutually exclusive
> > * RISC-V: make it possible to build RV32I multi-image with DEBUG_LL=n
> >   * almost all of Ahmad's notes are fixed (e.g. unused header files 
> > inclusions are dropped);
> >   * NOT FIXED: gpio-74xx-mmio still uses dev_get_drvdata(), not 
> > device_get_match_data()
> > 
> > Antony Pavlov (9):
> >   clocksource: timer-riscv: select CSR from device tree
> >   RISC-V: make it possible to run nmon from PBL C code
> >   RISC-V: boards: erizo: make it possible to use nmon
> >   serial: add litex UART driver
> >   gpio: add driver for 74xx-ICs with MMIO access
> >   spi: add litex spiflash driver
> >   net: add LiteEth driver
> >   RISC-V: add LiteX SoC and linux-on-litex-vexriscv support
> >   RISC-V: add litex_linux_defconfig
> > 
> > Marek Czerski (1):
> >   litex serial: add setbrg callback
> 
> I'd like to give this a try eventually while following:
> https://github.com/enjoy-digital/litex/wiki/Use-LiteX-on-the-Acorn-CLE-215
> 
> Do you intend to submit a new revision soon? Is it ok for you if I respin
> this series?

Sorry for delay with reply, I was on vacation.

I have just resend litex patchseries v4.
I have tested it with linux binaries from this repo:

   https://github.com/frantony/arty-linux-on-litex-vexriscv-prebuilt

What do you want to respin in the litex patchseries?

-- 
Best regards,
  Antony Pavlov
 
> Cheers,
> Ahmad
> 
> >  arch/riscv/Kconfig.socs  |  14 +
> >  arch/riscv/boards/Makefile   |   1 +
> >  arch/riscv/boards/erizo/lowlevel.c   |   4 +
> >  arch/riscv/boards/litex-linux/Makefile   |   3 +
> >  arch/riscv/boards/litex-linux/lowlevel.c |  22 ++
> >  arch/riscv/boot/Makefile |   1 +
> >  arch/riscv/boot/nmon_entry.S |  13 +
> >  arch/riscv/configs/litex_linux_defconfig |  76 +
> >  arch/riscv/dts/Makefile  |   1 +
> >  arch/riscv/dts/erizo.dtsi|   2 +
> >  arch/riscv/dts/litex-linux.dts   |  92 ++
> >  arch/riscv/dts/litex_soc_linux.dtsi  |  49 +++
> >  arch/riscv/include/asm/debug_ll.h|   3 +
> >  arch/riscv/include/asm/debug_ll_litex.h  | 123 
> >  arch/riscv/include/asm/riscv_nmon.h  |  49 ++-
> >  common/Kconfig   |   4 +
> >  drivers/clocksource/timer-riscv.c|  24 +-
> >  drivers/gpio/Kconfig |  14 +
> >  drivers/gpio/Makefile|   1 +
> >  drivers/gpio/gpio-74xx-mmio.c| 165 ++
> >  drivers/net/Kconfig  |   8 +
> >  drivers/net/Makefile |   1 +
> >  drivers/net/liteeth.c| 376 +++
> >  drivers/serial/Makefile  |   1 +
> >  drivers/serial/serial_litex.c| 103 +++
> >  drivers/spi/Kconfig  |   3 +
> >  drivers/spi/Makefile |   1 +
> >  drivers/spi/litex_spiflash.c | 241 +++
> >  images/Makefile.riscv|   4 +
> >  29 files changed, 1370 insertions(+), 29 deletions(-)
> >  create mode 100644 arch/riscv/boards/litex-linux/Makefile
> >  create mode 100644 arch/riscv/boards/litex-linux/lowlevel.c
> >  create mode 100644 arch/riscv/boot/nmon_entry.S
> >  create mode 100644 arch/riscv/configs/litex_linux_defconfig
> >  create mode 100644 arch/riscv/dts/litex-linux.dts
> >  create mode 100644 arch/riscv/dts/litex_soc_linux.dtsi
> >  create mode 100644 arch/riscv/include/asm/debug_ll_litex.h
> >  create mode 100644 drivers/gpio/gpio-74xx-mmio.c
> >  create mode 100644 drivers/net/lite

[PATCH RESEND v4 7/8] RISC-V: add LiteX SoC and linux-on-litex-vexriscv support

2021-08-17 Thread Antony Pavlov
LiteX is a Migen-based System on Chip, supporting softcore
VexRiscv CPU, a 32-bits Linux Capable RISC-V CPU.

See https://github.com/enjoy-digital/litex and
https://github.com/litex-hub/linux-on-litex-vexriscv
for details.

Signed-off-by: Antony Pavlov 
---
 arch/riscv/Kconfig.socs  |  14 +++
 arch/riscv/boards/Makefile   |   1 +
 arch/riscv/boards/litex-linux/Makefile   |   3 +
 arch/riscv/boards/litex-linux/lowlevel.c |  22 
 arch/riscv/dts/Makefile  |   1 +
 arch/riscv/dts/litex-linux.dts   |  92 +
 arch/riscv/dts/litex_soc_linux.dtsi  |  49 +
 arch/riscv/include/asm/debug_ll.h|   3 +
 arch/riscv/include/asm/debug_ll_litex.h  | 123 +++
 common/Kconfig   |   4 +
 images/Makefile.riscv|   4 +
 11 files changed, 316 insertions(+)

diff --git a/arch/riscv/Kconfig.socs b/arch/riscv/Kconfig.socs
index 221ea133d4..5c281918d5 100644
--- a/arch/riscv/Kconfig.socs
+++ b/arch/riscv/Kconfig.socs
@@ -95,4 +95,18 @@ config SIFIVE_L2
bool "SiFive L2 cache controller"
depends on CPU_SIFIVE
 
+config SOC_LITEX
+   bool "LiteX SoCs"
+   depends on ARCH_RV32I
+   select HAS_ASM_DEBUG_LL
+   select HAS_NMON
+   select USE_COMPRESSED_DTB
+   select RISCV_TIMER
+
+config BOARD_LITEX_LINUX
+   bool "litex linux board"
+   depends on SOC_LITEX
+   select RISCV_M_MODE
+   def_bool y
+
 endmenu
diff --git a/arch/riscv/boards/Makefile b/arch/riscv/boards/Makefile
index cb28a25d8b..8d5d9d4fc6 100644
--- a/arch/riscv/boards/Makefile
+++ b/arch/riscv/boards/Makefile
@@ -2,3 +2,4 @@
 obj-$(CONFIG_BOARD_ERIZO_GENERIC)  += erizo/
 obj-$(CONFIG_BOARD_HIFIVE) += hifive/
 obj-$(CONFIG_BOARD_BEAGLEV)+= beaglev/
+obj-$(CONFIG_BOARD_LITEX_LINUX)+= litex-linux/
diff --git a/arch/riscv/boards/litex-linux/Makefile 
b/arch/riscv/boards/litex-linux/Makefile
new file mode 100644
index 00..3d217ffe0b
--- /dev/null
+++ b/arch/riscv/boards/litex-linux/Makefile
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+pbl-y += lowlevel.o
diff --git a/arch/riscv/boards/litex-linux/lowlevel.c 
b/arch/riscv/boards/litex-linux/lowlevel.c
new file mode 100644
index 00..da23ef5633
--- /dev/null
+++ b/arch/riscv/boards/litex-linux/lowlevel.c
@@ -0,0 +1,22 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include 
+#include 
+#include 
+#include 
+
+ENTRY_FUNCTION(start_litex_linux, a0, a1, a2)
+{
+   extern char __dtb_z_litex_linux_start[];
+   void *fdt;
+
+   barebox_nmon_entry();
+
+   putc_ll('>');
+
+   /* On POR, we are running from read-only memory here. */
+
+   fdt = __dtb_z_litex_linux_start + get_runtime_offset();
+
+   barebox_riscv_machine_entry(0x4000, SZ_256M, fdt);
+}
diff --git a/arch/riscv/dts/Makefile b/arch/riscv/dts/Makefile
index 4a15423b7f..17d7d249e4 100644
--- a/arch/riscv/dts/Makefile
+++ b/arch/riscv/dts/Makefile
@@ -8,5 +8,6 @@ pbl-$(CONFIG_BOARD_ERIZO_GENERIC) += erizo-generic.dtb.o
 pbl-$(CONFIG_BOARD_HIFIVE) += hifive-unmatched-a00.dtb.o \
   hifive-unleashed-a00.dtb.o
 pbl-$(CONFIG_BOARD_BEAGLEV) += jh7100-beaglev-starlight.dtb.o
+pbl-$(CONFIG_BOARD_LITEX_LINUX) += litex-linux.dtb.o
 
 clean-files := *.dtb *.dtb.S .*.dtc .*.pre .*.dts
diff --git a/arch/riscv/dts/litex-linux.dts b/arch/riscv/dts/litex-linux.dts
new file mode 100644
index 00..d21fa57e30
--- /dev/null
+++ b/arch/riscv/dts/litex-linux.dts
@@ -0,0 +1,92 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include "litex_soc_linux.dtsi"
+
+#include 
+
+/ {
+   model = "LiteX VexRiscV-SoC-Linux";
+   compatible = "litex,vexriscv-soc-linux";
+
+   aliases {
+   rom = 
+   sram = 
+   };
+
+   /* ARTY board */
+   rom: rom@ {
+   compatible = "mmio-sram";
+   reg = <0x 0x8000>;
+   read-only;
+   };
+
+   sram: sram@2000 {
+   compatible = "mmio-sram";
+   reg = <0x2000 0x4000>;
+   };
+
+   main_ram: memory@4000 {
+   device_type = "memory";
+   reg = <0x4000 0x1000>;
+   };
+};
+
+ {
+   status = "okay";
+};
+
+ {
+   status = "okay";
+};
+
+ {
+   status = "okay";
+
+   spiflash: w25q128@0 {
+   #address-cells = <1>;
+   #size-cells = <1>;
+   compatible = "winbond,w25q128", "jedec,spi-nor";
+   spi-max-frequency = <10400>;
+   reg = <0>;
+   };
+};
+
+/ {
+   ledsgpio: gpio@f000a800 {
+   compatible = "ti,74175";
+   reg = <0xf000a800

[PATCH RESEND v4 5/8] spi: add litex spiflash driver

2021-08-17 Thread Antony Pavlov
Signed-off-by: Antony Pavlov 
---
 drivers/spi/Kconfig  |   3 +
 drivers/spi/Makefile |   1 +
 drivers/spi/litex_spiflash.c | 241 +++
 3 files changed, 245 insertions(+)

diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
index 91083ee709..e92cf675ab 100644
--- a/drivers/spi/Kconfig
+++ b/drivers/spi/Kconfig
@@ -74,6 +74,9 @@ config DRIVER_SPI_IMX_2_3
depends on ARCH_IMX50 || ARCH_IMX51 || ARCH_IMX53 || ARCH_IMX6 || 
ARCH_IMX7 || ARCH_IMX8M
default y
 
+config DRIVER_SPI_LITEX_SPIFLASH
+   bool "Litex SPIFLASH bitbang master driver"
+
 config DRIVER_SPI_MXS
bool "i.MX (23,28) SPI Master driver"
depends on ARCH_IMX28
diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile
index 908d514a01..ac95ffc1db 100644
--- a/drivers/spi/Makefile
+++ b/drivers/spi/Makefile
@@ -4,6 +4,7 @@ obj-$(CONFIG_DRIVER_SPI_ATH79) += ath79_spi.o
 obj-$(CONFIG_DRIVER_SPI_GPIO) += gpio_spi.o
 obj-$(CONFIG_DRIVER_SPI_FSL_QUADSPI) += spi-fsl-qspi.o
 obj-$(CONFIG_DRIVER_SPI_IMX) += imx_spi.o
+obj-$(CONFIG_DRIVER_SPI_LITEX_SPIFLASH) += litex_spiflash.o
 obj-$(CONFIG_DRIVER_SPI_MVEBU) += mvebu_spi.o
 obj-$(CONFIG_DRIVER_SPI_MXS) += mxs_spi.o
 obj-$(CONFIG_DRIVER_SPI_ALTERA) += altera_spi.o
diff --git a/drivers/spi/litex_spiflash.c b/drivers/spi/litex_spiflash.c
new file mode 100644
index 00..26ef207699
--- /dev/null
+++ b/drivers/spi/litex_spiflash.c
@@ -0,0 +1,241 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2020 Antony Pavlov 
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct litex_spiflash_spi {
+   struct spi_master   master;
+   void __iomem*regs;
+   u32 val;
+};
+
+#define SPIFLASH_BITBANG 0x0
+#define  SPIFLASH_BB_MOSI BIT(0)
+#define  SPIFLASH_BB_CLK BIT(1)
+#define  SPIFLASH_BB_CSN BIT(2)
+#define  SPIFLASH_BB_DIR BIT(3)
+
+#define SPIFLASH_MISO 0x4
+#define SPIFLASH_BITBANG_EN 0x8
+
+static inline u32 litex_spiflash_spi_rr(struct litex_spiflash_spi *sp, int reg)
+{
+   return readl(sp->regs + reg);
+}
+
+static inline void litex_spiflash_spi_wr(struct litex_spiflash_spi *sp, u32 
val, int reg)
+{
+   writel(val, sp->regs + reg);
+}
+
+static inline void setbits(struct litex_spiflash_spi *sp, int bits, int on)
+{
+   /*
+* We are the only user of SCSPTR so no locking is required.
+* Reading bit 2 and 0 in SCSPTR gives pin state as input.
+* Writing the same bits sets the output value.
+* This makes regular read-modify-write difficult so we
+* use sp->val to keep track of the latest register value.
+*/
+
+   if (on)
+   sp->val |= bits;
+   else
+   sp->val &= ~bits;
+
+   litex_spiflash_spi_wr(sp, sp->val, SPIFLASH_BITBANG);
+}
+
+static inline struct litex_spiflash_spi *litex_spiflash_spidev_to_sp(struct 
spi_device *spi)
+{
+   return container_of(spi->master, struct litex_spiflash_spi, master);
+}
+
+static inline void setsck(struct spi_device *spi, int on)
+{
+   struct litex_spiflash_spi *sc = litex_spiflash_spidev_to_sp(spi);
+
+   setbits(sc, SPIFLASH_BB_CLK, on);
+}
+
+static inline void setmosi(struct spi_device *spi, int on)
+{
+   struct litex_spiflash_spi *sc = litex_spiflash_spidev_to_sp(spi);
+
+   sc->val &= ~SPIFLASH_BB_DIR;
+   setbits(sc, SPIFLASH_BB_MOSI, on);
+}
+
+static inline u32 getmiso(struct spi_device *spi)
+{
+   struct litex_spiflash_spi *sc = litex_spiflash_spidev_to_sp(spi);
+
+   setbits(sc, SPIFLASH_BB_DIR, 1);
+   return !!((litex_spiflash_spi_rr(sc, SPIFLASH_MISO) & 1));
+}
+
+#define spidelay(nsecs) udelay(nsecs/1000)
+
+#include "spi-bitbang-txrx.h"
+
+static inline void litex_spiflash_spi_chipselect(struct litex_spiflash_spi 
*sc, int on)
+{
+   setbits(sc, SPIFLASH_BB_CSN, on);
+}
+
+static int litex_spiflash_spi_setup(struct spi_device *spi)
+{
+   struct spi_master *master = spi->master;
+   struct device_d spi_dev = spi->dev;
+
+   if (spi->bits_per_word != 8) {
+   dev_err(master->dev, "master doesn't support %d bits per word 
requested by %s\n",
+   spi->bits_per_word, spi_dev.name);
+   return -EINVAL;
+   }
+
+   if ((spi->mode & (SPI_CPHA | SPI_CPOL)) != SPI_MODE_0) {
+   dev_err(master->dev, "master doesn't support SPI_MODE%d 
requested by %s\n",
+   spi->mode & (SPI_CPHA | SPI_CPOL), spi_dev.name);
+   return -EINVAL;
+   }
+
+   return 0;
+}
+
+static int litex_spiflash_spi_read(struct spi_device *spi, void *buf, size_t 
nbyte)
+{
+   ssize_t cnt = 0;
+   u8 *rxf_buf = buf;
+
+   while (cnt < nbyte) {
+   *rxf_buf = bitbang_txrx_be_cpha1(spi, 1000, 1, 0, 8);
+   rxf_buf++

  1   2   3   4   5   6   7   8   9   10   >