-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Initial port to powerpc bare metal #5093
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thanks for the contribution. It's nice that it's a minimal port to start with, makes it easier to review! I guess MicroPython already runs on PowerPC via the unix port, and here is a real bare-metal port. I'm just wonder though if this scales to eventually add bare-metal ports to other archs like x86, or if these could all be merged into one "bare-cpu" port. It depends how much they'd have in common (probably not that much) and whether peripherals will be supported or not. Are there plans to add peripheral support (eg GPIO, SPI) to this port? What is the reason to add the |
Thanks!
The core of the port is mostly architecture specific. head.S, the nlr code, the uart, the linker script would all need to change for a different arch like x86. So I think the core code reuse would be minimal.
I'd like to but at this stage we are concentrating on microwatt which doesn't have any I/O as yet (other than the UART). The qemu port was just to make it easier to test (for you and me). FWIW There is some info on microwatt and micropython here https://lwn.net/Articles/796796/ (see "Demo time") and https://www.youtube.com/watch?v=JdMTLs7EMM0
The skiboot code was there to get going quicker and with a toolchain that doesn't have the libc libraries compiled in (which makes building cross toolchains easier). I could try to get rid of them if they are a problem. |
I only took a brief look and the main thing that stood out was licensing/copyright of these files being different from core MicroPython. We try to consolidate such files to For general points related to new ports, see also this comment: #4557 (comment) |
d1c7f57
to
ddfbf48
Compare
(sorry for the slow update)
I've updated the code to remove these using more compiler builtins now. All new files are MIT licensed.
You can either use qemu or the microwatt softcore from https://github.com/antonblanchard/microwatt I've added instructions on how to use qemu in ports/powerpc/README.md
microwatt is a softcore which can be put on numerous FPGA development boards like the Arty A7, Nexys A7, Nexys Video.
Yes, we are using GCC.
Yes. We support microwatt on various FPGA boards. We'd like to support more IO and soft IP which can be built into SOCs
Yes me! I've been working on Linux on powerpc for 10+ years:
All MIT (fixed from initial PR). Other things I've changed this the initial PR:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! I have made some minor comments that are my opinion. If you're unsure then we should defer to the micropython experts.
@dpgeorge, I will also be available to help maintain this port.
#endif | ||
//do_str("print('hello world!', list(x+1 for x in range(10)), end='eol\\n')", MP_PARSE_SINGLE_INPUT); | ||
//do_str("for i in range(10):\r\n print(i)", MP_PARSE_FILE_INPUT); | ||
#else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this commented out code be removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll remove. This was left over from the ports/minimal copy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please remove
ports/powerpc/uart_core.c
Outdated
|
||
/* | ||
* Core UART functions to implement for a port | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment could go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep thanks
ports/powerpc/uart_core.c
Outdated
* Core UART functions to implement for a port | ||
*/ | ||
|
||
#if MICROPY_MIN_USE_STM32_MCU |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks unrelated to the ppc port
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops, copy and paste from other ports
#define USART1 ((periph_uart_t*)0x40011000) | ||
#endif | ||
|
||
static int potato_console; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be clearer if the potato and the qemu uarts go in different files.
Also mention what/where the potato uart is (I think it's some IP that microwatt is using?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point.
Yeah potato uart is the uart we use for microwatt. It's from https://github.com/skordal/potato. I'll make that clearer in the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does the selection between lpc and potato need to be dynamic, or can it be configured at compile time? (in the latter case there's no need for these variables)
ddfbf48
to
8daea61
Compare
Updated branch to address @shenki comments. |
I tested this on Arch Linux which only has a powerpc toolchain in the AUR, so instead I tried using Is it possible to use It also executed correctly in Also, I think it'd be good to put in the README some notes about what toolchain to use and/or where to get it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For code style, tabs are not used, instead 4 spaces. And some other things. To make it easy, just run astyle on the files:
$ astyle --options=astyle.fmt *.?
where astyle.fmt contains:
--style=google
--indent=spaces=4
--attach-closing-while
--add-brackets
--indent-switches
--indent-after-parens
--indent-labels
--indent-preproc-define
--indent-preproc-cond
--pad-header
--unpad-paren
--add-braces
--convert-tabs
ports/powerpc/uart_core.c
Outdated
// Receive single character | ||
int mp_hal_stdin_rx_chr(void) { | ||
unsigned char c = 0; | ||
#if MICROPY_MIN_USE_STDOUT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, removing.
ports/powerpc/uart_core.c
Outdated
void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) { | ||
#if MICROPY_MIN_USE_STDOUT | ||
int r = write(1, str, len); | ||
(void)r; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can probably go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, removing
ports/powerpc/uart_potato.c
Outdated
#define POTATO_CONSOLE_STATUS_RX_FULL 0x04 | ||
#define POTATO_CONSOLE_STATUS_TX_FULL 0x08 | ||
#define POTATO_CONSOLE_CLOCK_DIV 0x18 | ||
#define POTATO_CONSOLE_IRQ_EN 0x20 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please line these up
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do.
This is a difference between the definitions of __assert_fail() between glibc and musl. It's a musl issue AFAICT https://www.openwall.com/lists/musl/2019/03/04/6
Unfortunately without adding support to exceptions, we can't do this bare metal on POWER. It's something we could add in the future.
Will do and I'll say to avoid musl for now. |
8daea61
to
ce17d88
Compare
Pushed update to address commends from @dpgeorge
|
ce17d88
to
d27e5f2
Compare
Pushed minor fix for whitespace breakage in ports/powerpc/head.S |
8ed9525
to
bb430f1
Compare
Repushed to fix the travis failure once merged. |
bb430f1
to
c9f488a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested it with the toolchain from https://toolchains.bootlin.com/ and it works well.
Just a few minor items to address, then it should be good to go in.
ports/powerpc/Makefile
Outdated
INC += -I. | ||
INC += -I$(TOP) | ||
INC += -I$(BUILD) | ||
INC += -Iskiboot |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this line can go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, thanks
ports/powerpc/README.md
Outdated
@@ -0,0 +1,40 @@ | |||
# The minimal port |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be something like "The PowerPC port"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep
@@ -0,0 +1,40 @@ | |||
# The minimal port | |||
|
|||
This port is intended to be a minimal MicroPython port that runs in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"... MicroPython port to the PowerPC architecture that runs ..."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops thanks :-)
#endif | ||
//do_str("print('hello world!', list(x+1 for x in range(10)), end='eol\\n')", MP_PARSE_SINGLE_INPUT); | ||
//do_str("for i in range(10):\r\n print(i)", MP_PARSE_FILE_INPUT); | ||
#else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please remove
KEEP(*(.head)) | ||
} | ||
|
||
. = 0x1700; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe add a comment as to why this number / what this line does?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, it for putting it right after the exception vectors. I'll add the comment in the code
#define USART1 ((periph_uart_t*)0x40011000) | ||
#endif | ||
|
||
static int potato_console; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does the selection between lpc and potato need to be dynamic, or can it be configured at compile time? (in the latter case there's no need for these variables)
py/nlrpowerpc.c
Outdated
: | ||
); | ||
|
||
assert(0); /* should never get here */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this be replaced with MP_UNREACHABLE
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep.
(github won't let me comment on the console question so commenting here)
The console is dynamically selected (not compile time), so we need those variables.
c9f488a
to
7ce0a59
Compare
Runs in microwatt (GHDL and FPGA) + qemu Port done initially by Michael Neuling, with help from Anton Blanchard and Jordan Niethe. Signed-off-by: Michael Neuling <mikey@neuling.org>
7ce0a59
to
9916104
Compare
New push to address comments from @dpgeorge and rebase to latest master
|
Thank's for updating. Merged in 079cc94 with some fixups to code style, mainly indenting. Also simplified a bit the Makefile because there's already a rule in py/mkrules.mk to build .S files. Great contribution, thank you! |
CI: Add `Print failure info`
This runs in qemu using:
$ ./qemu-system-ppc64 -M powernv -cpu POWER9 -nographic -bios build/firmware.bin
It can also run in microwatt (new POWER softcore) using GHDL or on an FGPA. Instructions on how to run in GHDL are here:
https://github.com/antonblanchard/microwatt/blob/master/README.md
Thanks to Anton Blanchard and Jordan Niethe for helping with this port.