mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* New RISCV board (cartesi-machine)
@ 2021-09-15 20:30 Marcelo Politzer
  2021-09-15 21:17 ` Ahmad Fatoum
  0 siblings, 1 reply; 7+ messages in thread
From: Marcelo Politzer @ 2021-09-15 20:30 UTC (permalink / raw)
  To: barebox

Hi, I'm new to barebox

I'm currently porting barebox to a riscv board (cartesi-machine).

I got it mostly working:
- new serial: serial_sbi.c and
- ext4 filesystem with mtdram

1) What I am still trying to figure out is how to customize `env` correctly.
I got it to build and appear based on the docs [1], [2],
however the only way I found around [3] was to replace `bin/init` with
this[4] layout.
Is there a recommended way to go about this?

2) I also would like clarification on the upstreaming process, is it
PR based, patches on this list?

best,
Marcelo


[1] Makefile:
```
bbenv-$(CONFIG_BOARD_CARTESI) += defaultenv-cartesi
```

[2] arch/riscv/boards/cartesi:
```
defaultenv-cartesi
├── boot
│   └── cartesi
├── init
│   ├── automount
│   └── ps1
└── nv
    ├── allow_color
    ├── autoboot_timeout
    └── user
```

[3]
```
Hit m for menu or any to stop autoboot:    0
Booting entry 'net'
```

[4]
```
defaultenv-cartesi
├── bin
│   └── init
└── boot
    └── cartesi
```

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: New RISCV board (cartesi-machine)
  2021-09-15 20:30 New RISCV board (cartesi-machine) Marcelo Politzer
@ 2021-09-15 21:17 ` Ahmad Fatoum
  2021-09-15 21:43   ` Marcelo Politzer
  0 siblings, 1 reply; 7+ messages in thread
From: Ahmad Fatoum @ 2021-09-15 21:17 UTC (permalink / raw)
  To: Marcelo Politzer, barebox

Hello Marcelo,

On 15.09.21 22:30, Marcelo Politzer wrote:
> Hi, I'm new to barebox
> 
> I'm currently porting barebox to a riscv board (cartesi-machine).

Oh, looks interesting! What SoC does it use?

> I got it mostly working:
> - new serial: serial_sbi.c and

Keep in mind that newer SBI versions deprecate
sbi_console_getchar() and sbi_console_putchar() with no replacement.

But if your board's firmware provides it, there is no issue with
adding a driver for it.

> - ext4 filesystem with mtdram
> 
> 1) What I am still trying to figure out is how to customize `env` correctly.
> I got it to build and appear based on the docs [1], [2],

Those look ok. I assume you have

defaultenv_append_directory(defaultenv_cartesi); in your board code?

> however the only way I found around [3] was to replace `bin/init` with
> this[4] layout.

After drivers probe, barebox invokes init to source init scripts and
do the countdown and such. This is written in C, but you can override
it with an /env/bin/init shell script, which is what you did here.

I would not recommend this. Drop /env/bin/init and use the same C init
nearly everyone else does. You can still customize it via the
/env/init/ scripts

> Is there a recommended way to go about this?

You need to set boot.default, e.g.

echo 'cartesi net' > defaultenv-cartesi/nv/boot.default

Which would try cartesi first and then net if the first one failed.

> 2) I also would like clarification on the upstreaming process, is it
> PR based, patches on this list?

Patches to the mailing list are the usual way of contributing.

Cheers,
Ahmad

> 
> best,
> Marcelo
> 
> 
> [1] Makefile:
> ```
> bbenv-$(CONFIG_BOARD_CARTESI) += defaultenv-cartesi
> ```
> 
> [2] arch/riscv/boards/cartesi:
> ```
> defaultenv-cartesi
> ├── boot
> │   └── cartesi
> ├── init
> │   ├── automount
> │   └── ps1
> └── nv
>     ├── allow_color
>     ├── autoboot_timeout
>     └── user
> ```
> 
> [3]
> ```
> Hit m for menu or any to stop autoboot:    0
> Booting entry 'net'
> ```
> 
> [4]
> ```
> defaultenv-cartesi
> ├── bin
> │   └── init
> └── boot
>     └── cartesi
> ```
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 


-- 
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-5555 |

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: New RISCV board (cartesi-machine)
  2021-09-15 21:17 ` Ahmad Fatoum
@ 2021-09-15 21:43   ` Marcelo Politzer
  2021-09-15 21:58     ` Ahmad Fatoum
  0 siblings, 1 reply; 7+ messages in thread
From: Marcelo Politzer @ 2021-09-15 21:43 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

On Wed, Sep 15, 2021 at 6:17 PM Ahmad Fatoum <a.fatoum@pengutronix.de> wrote:
>
> Hello Marcelo,
>
> On 15.09.21 22:30, Marcelo Politzer wrote:
> > Hi, I'm new to barebox
> >
> > I'm currently porting barebox to a riscv board (cartesi-machine).
>
> Oh, looks interesting! What SoC does it use?

It uses SOC_VIRT. It is an emulator to be precise, we use it for
verifiable computations.
It is pretty easy to try it out (there is a docker image for it):
https://www.cartesi.io/en/docs/machine/host/overview/

>
> > I got it mostly working:
> > - new serial: serial_sbi.c and
>
> Keep in mind that newer SBI versions deprecate
> sbi_console_getchar() and sbi_console_putchar() with no replacement.
>
> But if your board's firmware provides it, there is no issue with
> adding a driver for it.

That is what the emulator implements for now.
I have to admit that a virtio system would be cool, maybe in the future.

>
> > - ext4 filesystem with mtdram
> >
> > 1) What I am still trying to figure out is how to customize `env` correctly.
> > I got it to build and appear based on the docs [1], [2],
>
> Those look ok. I assume you have
>
> defaultenv_append_directory(defaultenv_cartesi); in your board code?

yes

>
> > however the only way I found around [3] was to replace `bin/init` with
> > this[4] layout.
>
> After drivers probe, barebox invokes init to source init scripts and
> do the countdown and such. This is written in C, but you can override
> it with an /env/bin/init shell script, which is what you did here.
>
> I would not recommend this. Drop /env/bin/init and use the same C init
> nearly everyone else does. You can still customize it via the
> /env/init/ scripts
>
> > Is there a recommended way to go about this?
>
> You need to set boot.default, e.g.
>
> echo 'cartesi net' > defaultenv-cartesi/nv/boot.default
>
> Which would try cartesi first and then net if the first one failed.

That worked great.
Looks a lot cleaner now.

>
> > 2) I also would like clarification on the upstreaming process, is it
> > PR based, patches on this list?
>
> Patches to the mailing list are the usual way of contributing.

OK, I'll clean this up and send it as two patches:
- serial_sbi
- cartesi (board)

>
> Cheers,
> Ahmad
>
> >
> > best,
> > Marcelo
> >
> >
> > [1] Makefile:
> > ```
> > bbenv-$(CONFIG_BOARD_CARTESI) += defaultenv-cartesi
> > ```
> >
> > [2] arch/riscv/boards/cartesi:
> > ```
> > defaultenv-cartesi
> > ├── boot
> > │   └── cartesi
> > ├── init
> > │   ├── automount
> > │   └── ps1
> > └── nv
> >     ├── allow_color
> >     ├── autoboot_timeout
> >     └── user
> > ```
> >
> > [3]
> > ```
> > Hit m for menu or any to stop autoboot:    0
> > Booting entry 'net'
> > ```
> >
> > [4]
> > ```
> > defaultenv-cartesi
> > ├── bin
> > │   └── init
> > └── boot
> >     └── cartesi
> > ```
> >
> > _______________________________________________
> > barebox mailing list
> > barebox@lists.infradead.org
> > http://lists.infradead.org/mailman/listinfo/barebox
> >
>
>
> --
> 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-5555 |

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: New RISCV board (cartesi-machine)
  2021-09-15 21:43   ` Marcelo Politzer
@ 2021-09-15 21:58     ` Ahmad Fatoum
  2021-09-16 18:01       ` Marcelo Politzer
  0 siblings, 1 reply; 7+ messages in thread
From: Ahmad Fatoum @ 2021-09-15 21:58 UTC (permalink / raw)
  To: Marcelo Politzer; +Cc: barebox

Hello Marcelo,

On 15.09.21 23:43, Marcelo Politzer wrote:
> On Wed, Sep 15, 2021 at 6:17 PM Ahmad Fatoum <a.fatoum@pengutronix.de> wrote:
>>
>> Hello Marcelo,
>>
>> On 15.09.21 22:30, Marcelo Politzer wrote:
>>> Hi, I'm new to barebox
>>>
>>> I'm currently porting barebox to a riscv board (cartesi-machine).
>>
>> Oh, looks interesting! What SoC does it use?
> 
> It uses SOC_VIRT. It is an emulator to be precise, we use it for
> verifiable computations.
> It is pretty easy to try it out (there is a docker image for it):
> https://www.cartesi.io/en/docs/machine/host/overview/

Thanks, will check it out.

>>> I got it mostly working:
>>> - new serial: serial_sbi.c and
>>
>> Keep in mind that newer SBI versions deprecate
>> sbi_console_getchar() and sbi_console_putchar() with no replacement.
>>
>> But if your board's firmware provides it, there is no issue with
>> adding a driver for it.
> 
> That is what the emulator implements for now.
> I have to admit that a virtio system would be cool, maybe in the future.

Like this? :-)

https://www.barebox.org/jsbarebox/

>>> - ext4 filesystem with mtdram
>>>
>>> 1) What I am still trying to figure out is how to customize `env` correctly.
>>> I got it to build and appear based on the docs [1], [2],
>>
>> Those look ok. I assume you have
>>
>> defaultenv_append_directory(defaultenv_cartesi); in your board code?
> 
> yes
> 
>>
>>> however the only way I found around [3] was to replace `bin/init` with
>>> this[4] layout.
>>
>> After drivers probe, barebox invokes init to source init scripts and
>> do the countdown and such. This is written in C, but you can override
>> it with an /env/bin/init shell script, which is what you did here.
>>
>> I would not recommend this. Drop /env/bin/init and use the same C init
>> nearly everyone else does. You can still customize it via the
>> /env/init/ scripts
>>
>>> Is there a recommended way to go about this?
>>
>> You need to set boot.default, e.g.
>>
>> echo 'cartesi net' > defaultenv-cartesi/nv/boot.default
>>
>> Which would try cartesi first and then net if the first one failed.
> 
> That worked great.
> Looks a lot cleaner now.
> 
>>
>>> 2) I also would like clarification on the upstreaming process, is it
>>> PR based, patches on this list?
>>
>> Patches to the mailing list are the usual way of contributing.
> 
> OK, I'll clean this up and send it as two patches:
> - serial_sbi
> - cartesi (board)

Sounds good.

Cheers,
Ahmad

> 
>>
>> Cheers,
>> Ahmad
>>
>>>
>>> best,
>>> Marcelo
>>>
>>>
>>> [1] Makefile:
>>> ```
>>> bbenv-$(CONFIG_BOARD_CARTESI) += defaultenv-cartesi
>>> ```
>>>
>>> [2] arch/riscv/boards/cartesi:
>>> ```
>>> defaultenv-cartesi
>>> ├── boot
>>> │   └── cartesi
>>> ├── init
>>> │   ├── automount
>>> │   └── ps1
>>> └── nv
>>>     ├── allow_color
>>>     ├── autoboot_timeout
>>>     └── user
>>> ```
>>>
>>> [3]
>>> ```
>>> Hit m for menu or any to stop autoboot:    0
>>> Booting entry 'net'
>>> ```
>>>
>>> [4]
>>> ```
>>> defaultenv-cartesi
>>> ├── bin
>>> │   └── init
>>> └── boot
>>>     └── cartesi
>>> ```
>>>
>>> _______________________________________________
>>> barebox mailing list
>>> barebox@lists.infradead.org
>>> http://lists.infradead.org/mailman/listinfo/barebox
>>>
>>
>>
>> --
>> 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-5555 |
> 


-- 
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-5555 |

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: New RISCV board (cartesi-machine)
  2021-09-15 21:58     ` Ahmad Fatoum
@ 2021-09-16 18:01       ` Marcelo Politzer
  2021-09-16 21:21         ` Ahmad Fatoum
  0 siblings, 1 reply; 7+ messages in thread
From: Marcelo Politzer @ 2021-09-16 18:01 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

[-- Attachment #1: Type: text/plain, Size: 4538 bytes --]

On Wed, Sep 15, 2021 at 6:58 PM Ahmad Fatoum <a.fatoum@pengutronix.de> wrote:
>
> Hello Marcelo,
>
> On 15.09.21 23:43, Marcelo Politzer wrote:
> > On Wed, Sep 15, 2021 at 6:17 PM Ahmad Fatoum <a.fatoum@pengutronix.de> wrote:
> >>
> >> Hello Marcelo,
> >>
> >> On 15.09.21 22:30, Marcelo Politzer wrote:
> >>> Hi, I'm new to barebox
> >>>
> >>> I'm currently porting barebox to a riscv board (cartesi-machine).
> >>
> >> Oh, looks interesting! What SoC does it use?
> >
> > It uses SOC_VIRT. It is an emulator to be precise, we use it for
> > verifiable computations.
> > It is pretty easy to try it out (there is a docker image for it):
> > https://www.cartesi.io/en/docs/machine/host/overview/
>
> Thanks, will check it out.
>
> >>> I got it mostly working:
> >>> - new serial: serial_sbi.c and
> >>
> >> Keep in mind that newer SBI versions deprecate
> >> sbi_console_getchar() and sbi_console_putchar() with no replacement.
> >>
> >> But if your board's firmware provides it, there is no issue with
> >> adding a driver for it.
> >
> > That is what the emulator implements for now.
> > I have to admit that a virtio system would be cool, maybe in the future.
>
> Like this? :-)
>
> https://www.barebox.org/jsbarebox/

That is cool!

>
> >>> - ext4 filesystem with mtdram
> >>>
> >>> 1) What I am still trying to figure out is how to customize `env` correctly.
> >>> I got it to build and appear based on the docs [1], [2],
> >>
> >> Those look ok. I assume you have
> >>
> >> defaultenv_append_directory(defaultenv_cartesi); in your board code?
> >
> > yes
> >
> >>
> >>> however the only way I found around [3] was to replace `bin/init` with
> >>> this[4] layout.
> >>
> >> After drivers probe, barebox invokes init to source init scripts and
> >> do the countdown and such. This is written in C, but you can override
> >> it with an /env/bin/init shell script, which is what you did here.
> >>
> >> I would not recommend this. Drop /env/bin/init and use the same C init
> >> nearly everyone else does. You can still customize it via the
> >> /env/init/ scripts
> >>
> >>> Is there a recommended way to go about this?
> >>
> >> You need to set boot.default, e.g.
> >>
> >> echo 'cartesi net' > defaultenv-cartesi/nv/boot.default
> >>
> >> Which would try cartesi first and then net if the first one failed.
> >
> > That worked great.
> > Looks a lot cleaner now.
> >
> >>
> >>> 2) I also would like clarification on the upstreaming process, is it
> >>> PR based, patches on this list?
> >>
> >> Patches to the mailing list are the usual way of contributing.
> >
> > OK, I'll clean this up and send it as two patches:
> > - serial_sbi
> > - cartesi (board)
>
> Sounds good.

Patches attached, please review at your convenience.

>
> Cheers,
> Ahmad
>
> >
> >>
> >> Cheers,
> >> Ahmad
> >>
> >>>
> >>> best,
> >>> Marcelo
> >>>
> >>>
> >>> [1] Makefile:
> >>> ```
> >>> bbenv-$(CONFIG_BOARD_CARTESI) += defaultenv-cartesi
> >>> ```
> >>>
> >>> [2] arch/riscv/boards/cartesi:
> >>> ```
> >>> defaultenv-cartesi
> >>> ├── boot
> >>> │   └── cartesi
> >>> ├── init
> >>> │   ├── automount
> >>> │   └── ps1
> >>> └── nv
> >>>     ├── allow_color
> >>>     ├── autoboot_timeout
> >>>     └── user
> >>> ```
> >>>
> >>> [3]
> >>> ```
> >>> Hit m for menu or any to stop autoboot:    0
> >>> Booting entry 'net'
> >>> ```
> >>>
> >>> [4]
> >>> ```
> >>> defaultenv-cartesi
> >>> ├── bin
> >>> │   └── init
> >>> └── boot
> >>>     └── cartesi
> >>> ```
> >>>
> >>> _______________________________________________
> >>> barebox mailing list
> >>> barebox@lists.infradead.org
> >>> http://lists.infradead.org/mailman/listinfo/barebox
> >>>
> >>
> >>
> >> --
> >> 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-5555 |
> >
>
>
> --
> 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-5555 |

[-- Attachment #2: 0002-RISC-V-cartesi-Initial-port.patch --]
[-- Type: text/x-patch, Size: 5107 bytes --]

From f4a3cf20582dec08fd2b02b62ce864fcae7bb038 Mon Sep 17 00:00:00 2001
From: Marcelo Politzer <marcelo.politzer@cartesi.io>
Date: Thu, 16 Sep 2021 14:33:17 -0300
Subject: [PATCH 2/2] RISC-V: cartesi: Initial port

---
 arch/riscv/Kconfig.socs                       |  7 +++++
 arch/riscv/boards/Makefile                    |  1 +
 arch/riscv/boards/cartesi/Makefile            |  2 ++
 arch/riscv/boards/cartesi/board.c             | 28 +++++++++++++++++++
 .../cartesi/defaultenv-cartesi/boot/cartesi   |  3 ++
 .../cartesi/defaultenv-cartesi/init/automount |  6 ++++
 .../defaultenv-cartesi/nv/autoboot_timeout    |  1 +
 .../defaultenv-cartesi/nv/boot.default        |  1 +
 arch/riscv/configs/cartesi_defconfig          | 15 ++++++++++
 9 files changed, 64 insertions(+)
 create mode 100644 arch/riscv/boards/cartesi/Makefile
 create mode 100644 arch/riscv/boards/cartesi/board.c
 create mode 100755 arch/riscv/boards/cartesi/defaultenv-cartesi/boot/cartesi
 create mode 100644 arch/riscv/boards/cartesi/defaultenv-cartesi/init/automount
 create mode 100644 arch/riscv/boards/cartesi/defaultenv-cartesi/nv/autoboot_timeout
 create mode 100644 arch/riscv/boards/cartesi/defaultenv-cartesi/nv/boot.default
 create mode 100644 arch/riscv/configs/cartesi_defconfig

diff --git a/arch/riscv/Kconfig.socs b/arch/riscv/Kconfig.socs
index 221ea133d..12e8e04fc 100644
--- a/arch/riscv/Kconfig.socs
+++ b/arch/riscv/Kconfig.socs
@@ -22,6 +22,13 @@ config SOC_VIRT
 	  Generates an image tht can be be booted by QEMU. The image is called
 	  barebox-dt-2nd.img
 
+config BOARD_CARTESI
+	bool "Cartesi Machine"
+	select SOC_VIRT
+	help
+	  Generates an image tht can be be booted by a cartesi-machine. The
+	  image is called barebox-dt-2nd.img
+
 config CPU_SIFIVE
 	bool
 	select HAS_CACHE
diff --git a/arch/riscv/boards/Makefile b/arch/riscv/boards/Makefile
index cb28a25d8..cee3d2e27 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_CARTESI)		+= cartesi/
diff --git a/arch/riscv/boards/cartesi/Makefile b/arch/riscv/boards/cartesi/Makefile
new file mode 100644
index 000000000..0e3453178
--- /dev/null
+++ b/arch/riscv/boards/cartesi/Makefile
@@ -0,0 +1,2 @@
+obj-$(CONFIG_BOARD_CARTESI) += board.o
+bbenv-$(CONFIG_BOARD_CARTESI) += defaultenv-cartesi
diff --git a/arch/riscv/boards/cartesi/board.c b/arch/riscv/boards/cartesi/board.c
new file mode 100644
index 000000000..a1a33c8d8
--- /dev/null
+++ b/arch/riscv/boards/cartesi/board.c
@@ -0,0 +1,28 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2021 Marcelo Politzer, Cartesi
+ */
+
+#include <common.h>
+#include <driver.h>
+#include <bbu.h>
+#include <envfs.h>
+
+static int cartesi_probe(struct device_d *dev)
+{
+	barebox_set_hostname("cartesi");
+	defaultenv_append_directory(defaultenv_cartesi);
+	return 0;
+}
+
+static const struct of_device_id cartesi_of_match[] = {
+	{ .compatible = "ucbbar,riscvemu-bar_dev" },
+	{ /* sentinel */ },
+};
+
+static struct driver_d cartesi_board_driver = {
+	.name = "board-cartesi",
+	.probe = cartesi_probe,
+	.of_compatible = cartesi_of_match,
+};
+device_platform_driver(cartesi_board_driver);
diff --git a/arch/riscv/boards/cartesi/defaultenv-cartesi/boot/cartesi b/arch/riscv/boards/cartesi/defaultenv-cartesi/boot/cartesi
new file mode 100755
index 000000000..b175ff556
--- /dev/null
+++ b/arch/riscv/boards/cartesi/defaultenv-cartesi/boot/cartesi
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+global.bootm.image=/mnt/rootfs/boot/Image
diff --git a/arch/riscv/boards/cartesi/defaultenv-cartesi/init/automount b/arch/riscv/boards/cartesi/defaultenv-cartesi/init/automount
new file mode 100644
index 000000000..362ec68ed
--- /dev/null
+++ b/arch/riscv/boards/cartesi/defaultenv-cartesi/init/automount
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+# mtdram0
+mkdir -p /mnt/rootfs
+automount -d /mnt/rootfs 'mount -t ext4 /dev/mtdram0 /mnt/rootfs'
+
diff --git a/arch/riscv/boards/cartesi/defaultenv-cartesi/nv/autoboot_timeout b/arch/riscv/boards/cartesi/defaultenv-cartesi/nv/autoboot_timeout
new file mode 100644
index 000000000..573541ac9
--- /dev/null
+++ b/arch/riscv/boards/cartesi/defaultenv-cartesi/nv/autoboot_timeout
@@ -0,0 +1 @@
+0
diff --git a/arch/riscv/boards/cartesi/defaultenv-cartesi/nv/boot.default b/arch/riscv/boards/cartesi/defaultenv-cartesi/nv/boot.default
new file mode 100644
index 000000000..98698769f
--- /dev/null
+++ b/arch/riscv/boards/cartesi/defaultenv-cartesi/nv/boot.default
@@ -0,0 +1 @@
+cartesi net
diff --git a/arch/riscv/configs/cartesi_defconfig b/arch/riscv/configs/cartesi_defconfig
new file mode 100644
index 000000000..79a7a9b42
--- /dev/null
+++ b/arch/riscv/configs/cartesi_defconfig
@@ -0,0 +1,15 @@
+# minimal
+CONFIG_ARCH_RV64I=y
+CONFIG_BOARD_CARTESI=y
+CONFIG_BOOTM_ELF=y
+CONFIG_CMD_AUTOMOUNT=y
+CONFIG_CMD_BOOT=y
+CONFIG_FS_EXT4=y
+CONFIG_MTD=y
+CONFIG_MTD_MTDRAM=y
+CONFIG_SERIAL_SBI=y
+CONFIG_SOC_VIRT=y
+
+# convenience
+CONFIG_CMD_READLINE=y
+CONFIG_HUSH_FANCY_PROMPT=y
-- 
2.32.0


[-- Attachment #3: 0001-serial-implement-SBI-UART-support.patch --]
[-- Type: text/x-patch, Size: 3961 bytes --]

From 5953062ce13c4b07190d455d2aae228cd3756d42 Mon Sep 17 00:00:00 2001
From: Marcelo Politzer <marcelo.politzer@cartesi.io>
Date: Thu, 16 Sep 2021 14:29:51 -0300
Subject: [PATCH 1/2] serial: implement SBI UART support

---
 arch/riscv/lib/sbi.c        | 11 ++++++
 drivers/serial/Kconfig      |  7 ++++
 drivers/serial/Makefile     |  1 +
 drivers/serial/serial_sbi.c | 77 +++++++++++++++++++++++++++++++++++++
 4 files changed, 96 insertions(+)
 create mode 100644 drivers/serial/serial_sbi.c

diff --git a/arch/riscv/lib/sbi.c b/arch/riscv/lib/sbi.c
index 45a04fb82..209069c98 100644
--- a/arch/riscv/lib/sbi.c
+++ b/arch/riscv/lib/sbi.c
@@ -64,3 +64,14 @@ static int sbi_init(void)
 
 }
 core_initcall(sbi_init);
+
+
+void sbi_console_putchar(int ch)
+{
+	sbi_ecall(SBI_EXT_0_1_CONSOLE_PUTCHAR, 0, ch, 0, 0, 0, 0, 0);
+}
+
+int sbi_console_getchar(void)
+{
+	return sbi_ecall(SBI_EXT_0_1_CONSOLE_GETCHAR, 0, 0, 0, 0, 0, 0, 0).error;
+}
diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
index b9750d177..002871445 100644
--- a/drivers/serial/Kconfig
+++ b/drivers/serial/Kconfig
@@ -173,4 +173,11 @@ config SERIAL_SIFIVE
 	  contains a SiFive UART IP block.  This type of UART is present on
 	  SiFive FU540 SoCs, among others.
 
+config SERIAL_SBI
+	tristate "RISCV SBI UART support"
+	depends on OFDEVICE
+	help
+	  Select this option if you are building barebox for a RISCV with SBI
+	  version 0.1.0 (legacy mode) implemented
+
 endmenu
diff --git a/drivers/serial/Makefile b/drivers/serial/Makefile
index 5120b1737..b1de436ed 100644
--- a/drivers/serial/Makefile
+++ b/drivers/serial/Makefile
@@ -24,3 +24,4 @@ obj-$(CONFIG_DRIVER_SERIAL_DIGIC)		+= serial_digic.o
 obj-$(CONFIG_DRIVER_SERIAL_LPUART)		+= serial_lpuart.o
 obj-$(CONFIG_VIRTIO_CONSOLE)			+= virtio_console.o
 obj-$(CONFIG_SERIAL_SIFIVE)			+= serial_sifive.o
+obj-$(CONFIG_SERIAL_SBI)			+= serial_sbi.o
diff --git a/drivers/serial/serial_sbi.c b/drivers/serial/serial_sbi.c
new file mode 100644
index 000000000..a7e57885f
--- /dev/null
+++ b/drivers/serial/serial_sbi.c
@@ -0,0 +1,77 @@
+#define DEBUG
+#define DBG() printf("%s:%s:%d\n", __FILE__, __func__, __LINE__)
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2018 Anup Patel <anup@brainfault.org>
+ */
+
+#include <common.h>
+#include <driver.h>
+#include <malloc.h>
+#include <io.h>
+#include <of.h>
+#include <asm/sbi.h>
+
+struct sbi_serial_priv {
+	struct console_device cdev;
+	uint8_t b[16], head, tail;
+};
+
+#define to_priv(cdev) container_of(cdev, struct sbi_serial_priv, cdev)
+
+static int sbi_serial_getc(struct console_device *cdev)
+{
+	struct sbi_serial_priv *priv = cdev->dev->priv;
+	if (priv->head == priv->tail)
+		return 0;
+	return priv->b[priv->head++ & 0xf];
+}
+
+static void sbi_serial_putc(struct console_device *cdev, const char ch)
+{
+	sbi_console_putchar(ch);
+}
+
+static int sbi_serial_tstc(struct console_device *cdev)
+{
+	struct sbi_serial_priv *priv = cdev->dev->priv;
+	int c = sbi_console_getchar();
+
+	if (c != -1)
+		priv->b[priv->tail++ & 0xf] = c;
+	return priv->head != priv->tail;
+}
+static void sbi_serial_flush(struct console_device *cdev)
+{
+}
+static int sbi_serial_setbrg(struct console_device *cdev, int _)
+{
+	return 0;
+}
+
+static int sbi_serial_probe(struct device_d *dev)
+{
+	struct sbi_serial_priv *priv;
+
+	dev->priv = 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  = sbi_serial_flush;
+	priv->cdev.setbrg = sbi_serial_setbrg;
+
+	return console_register(&priv->cdev);
+}
+
+static __maybe_unused struct of_device_id sbi_serial_dt_ids[] = {
+	{ .compatible = "ucb,htif0" },
+	{ /* sentinel */ }
+};
+
+static struct driver_d serial_sbi_driver = {
+	.name   = "serial_sbi",
+	.probe  = sbi_serial_probe,
+	.of_compatible = sbi_serial_dt_ids,
+};
+console_platform_driver(serial_sbi_driver);
-- 
2.32.0


[-- Attachment #4: Type: text/plain, Size: 149 bytes --]

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: New RISCV board (cartesi-machine)
  2021-09-16 18:01       ` Marcelo Politzer
@ 2021-09-16 21:21         ` Ahmad Fatoum
  2021-09-20 19:41           ` Marcelo Politzer
  0 siblings, 1 reply; 7+ messages in thread
From: Ahmad Fatoum @ 2021-09-16 21:21 UTC (permalink / raw)
  To: Marcelo Politzer; +Cc: barebox

Hi Marcelo,

On 16.09.21 20:01, Marcelo Politzer wrote:
>> Like this? :-)
>>
>> https://www.barebox.org/jsbarebox/
> 
> That is cool!

:>

>>> OK, I'll clean this up and send it as two patches:
>>> - serial_sbi
>>> - cartesi (board)
>>
>> Sounds good.
> 
> Patches attached, please review at your convenience.

Please resend without attachment if possible (e.g. with git send-email).
This makes it easier to review.

Some comments:

- Signed-off-by is required, just as with Linux. See https://developercertificate.org/
- A short commit message would be nice
- BOARD_CARTESI should depend on SOC_VIRT for uniformity with other boards
- Can you change device tree compatible? Generic boards should remain generic
  and not contain vendor-specific stuff.
- Please add your new Kconfig options to virt64_defconfig. That way you can build
  and use the same image for all Virt-based boards (You can still use a different
  config in your BSP of course)

Serial driver:

- remove DEBUG defines
- depends on RISCV (otherwise there is no <asm/sbi.h>)
- You don't need to implement flush and setbrg
- ucb,htif0 is an unrelated device, but there is no device tree
  node, you can bind to. You can register a device in sbi_init
  and match against that. See riscv-timer for an example
- I don't understand the point of the ring buffer. A command would
  be nice (e.g. This is needed, because SBI lacks a FIFO or such)
- to_priv unused

Cheers,
Ahmad

-- 
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-5555 |

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: New RISCV board (cartesi-machine)
  2021-09-16 21:21         ` Ahmad Fatoum
@ 2021-09-20 19:41           ` Marcelo Politzer
  0 siblings, 0 replies; 7+ messages in thread
From: Marcelo Politzer @ 2021-09-20 19:41 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

Hi Ahmad,

I Just thought I should let you know that I won't be able to act on
your feedback for a while since something else came along with a
higher priority.
I'll send the patches with corrections at a later date.

best,
Marcelo

On Thu, Sep 16, 2021 at 6:21 PM Ahmad Fatoum <a.fatoum@pengutronix.de> wrote:
>
> Hi Marcelo,
>
> On 16.09.21 20:01, Marcelo Politzer wrote:
> >> Like this? :-)
> >>
> >> https://www.barebox.org/jsbarebox/
> >
> > That is cool!
>
> :>
>
> >>> OK, I'll clean this up and send it as two patches:
> >>> - serial_sbi
> >>> - cartesi (board)
> >>
> >> Sounds good.
> >
> > Patches attached, please review at your convenience.
>
> Please resend without attachment if possible (e.g. with git send-email).
> This makes it easier to review.
>
> Some comments:
>
> - Signed-off-by is required, just as with Linux. See https://developercertificate.org/
> - A short commit message would be nice
> - BOARD_CARTESI should depend on SOC_VIRT for uniformity with other boards
> - Can you change device tree compatible? Generic boards should remain generic
>   and not contain vendor-specific stuff.
> - Please add your new Kconfig options to virt64_defconfig. That way you can build
>   and use the same image for all Virt-based boards (You can still use a different
>   config in your BSP of course)
>
> Serial driver:
>
> - remove DEBUG defines
> - depends on RISCV (otherwise there is no <asm/sbi.h>)
> - You don't need to implement flush and setbrg
> - ucb,htif0 is an unrelated device, but there is no device tree
>   node, you can bind to. You can register a device in sbi_init
>   and match against that. See riscv-timer for an example
> - I don't understand the point of the ring buffer. A command would
>   be nice (e.g. This is needed, because SBI lacks a FIFO or such)
> - to_priv unused
>
> Cheers,
> Ahmad
>
> --
> 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-5555 |

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-09-20 19:43 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-15 20:30 New RISCV board (cartesi-machine) Marcelo Politzer
2021-09-15 21:17 ` Ahmad Fatoum
2021-09-15 21:43   ` Marcelo Politzer
2021-09-15 21:58     ` Ahmad Fatoum
2021-09-16 18:01       ` Marcelo Politzer
2021-09-16 21:21         ` Ahmad Fatoum
2021-09-20 19:41           ` Marcelo Politzer

mail archive of the barebox mailing list

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://lore.barebox.org/barebox/0 barebox/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 barebox barebox/ https://lore.barebox.org/barebox \
		barebox@lists.infradead.org
	public-inbox-index barebox

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git