On Jul 19, 2019, at 4:51 PM, BALATON Zoltan balaton@eik.bme.hu wrote:
Hello,
This is an attempt to port ftd.fs for FDT unflattening from SLOF to OpenBIOS. This compiles but I have not tried to feed it any fdt yet because I'm sure it won't work yet as some words are wrong. The words I had to implement for it (marked with a FIXME comment) should be reviewed and checked if they could work and the set-unit word is still missing so that needs to be implemented. Also 64bit stuff and claim usage should be clarified. Those words that are copied and do work may have better alternatives that I haven't found so could be replaced. Anyway this is a start to try to get this done. Once it works it will expect an FDT in memory at address fdt-start then the fdt-doit word at the end is an example of how to unflatten that into an OF device-tree (at least that's what SLOF does if I got that right).
Any insight or comments on this are welcome.
Regards, BALATON Zoltan
diff --git a/forth/util/build.xml b/forth/util/build.xml index 4839d2c..25e02db 100644 --- a/forth/util/build.xml +++ b/forth/util/build.xml @@ -11,6 +11,7 @@
<dictionary name="openbios" target="forth"> <object source="util.fs"/> <object source="pci.fs"/> + <object source="fdt.fs"/> <!-- We don't want/need these at the moment <object source="apic.fs"/> --> diff --git a/forth/util/fdt.fs b/forth/util/fdt.fs new file mode 100644 index 0000000..af29bba --- /dev/null +++ b/forth/util/fdt.fs @@ -0,0 +1,586 @@ +\ ***************************************************************************** +\ * Copyright (c) 2011 IBM Corporation +\ * All rights reserved. +\ * This program and the accompanying materials +\ * are made available under the terms of the BSD License +\ * which accompanies this distribution, and is available at +\ * http://www.opensource.org/licenses/bsd-license.php +\ * +\ * Contributors: +\ * IBM Corporation - initial implementation +\ ****************************************************************************/ +\ Changes for OpenBIOS: BALATON Zoltan, 2019 + +1 VALUE fdt-debug +TRUE VALUE fdt-cas-fix? +0 VALUE fdt-start + +struct + 4 field >fdth_magic + 4 field >fdth_tsize + 4 field >fdth_struct_off + 4 field >fdth_string_off + 4 field >fdth_rsvmap_off + 4 field >fdth_version + 4 field >fdth_compat_vers + 4 field >fdth_boot_cpu + 4 field >fdth_string_size + 4 field >fdth_struct_size +constant /fdth + +h# d00dfeed constant OF_DT_HEADER +h# 1 constant OF_DT_BEGIN_NODE +h# 2 constant OF_DT_END_NODE +h# 3 constant OF_DT_PROP +h# 4 constant OF_DT_NOP +h# 9 constant OF_DT_END + +\ Create some variables early +0 value fdt-start-addr +0 value fdt-struct +0 value fdt-strings + + +\ FIXME: review the following words which were added for OpenBIOS +\ some of these copied verbatim from SLOF others try to implement +\ alternatives +\ +\ definitely wrong/missing: set-unit and claim disabled further below +\ +\ may be wrong: find-node, and other related node words and 64bit stuff +\ (SLOF seems to always be in 64bit mode and not sure if that's needed +\ to parse FDT or could it be changed for 32bit as OpenBIOS does not +\ define some words in 32bit mode.) + +: get-node ?active-package ; +: set-node active-package! ; +: node>path " ?" ; \ only used for debugging and errors +: get-parent get-node parent ; +: my-#address-cells my-#acells ; +: get-property get-package-property ; +: find-node ( path len -- phandle|0 ) + find-dev 0= if \ find-dev returns ( phandle true | false ) + 0 + then +; + +\ : set-space get-node dup >r node>space ! true r> node>space? ! ; +\ : set-address +\ my-#address-cells 1 ?DO +\ get-node node>space i cells + ! LOOP +\ ; +: set-unit 3drop ; \ set-space set-address ; + +: str= ( str1 len1 str2 len2 -- equal? ) + rot over <> IF 3drop false ELSE comp 0= THEN ; + +: from-cstring ( addr - len ) + dup dup BEGIN c@ 0 <> WHILE 1 + dup REPEAT + swap -
<snip>
I know Forth is big on using the stack as a place for storing variables, but could you use local variables instead? They are so much easier to follow and use than stack manipulation.
Thank you.