diff options
author | Thomas Huth <thuth@linux.vnet.ibm.com> | 2011-11-29 15:25:37 +0100 |
---|---|---|
committer | Thomas Huth <thuth@linux.vnet.ibm.com> | 2011-12-20 17:56:48 +0100 |
commit | e977f3e512684a7ed70156023c269b7f3ea01c20 (patch) | |
tree | 2d2a2d552e3364986ad8c3b375ab21f9b31d8fa8 | |
parent | af85b732926273bdb8b5e61623d0af6f988eae94 (diff) | |
download | SLOF-e977f3e512684a7ed70156023c269b7f3ea01c20.zip SLOF-e977f3e512684a7ed70156023c269b7f3ea01c20.tar.gz SLOF-e977f3e512684a7ed70156023c269b7f3ea01c20.tar.bz2 |
Encode FDT properties as string when they contain a valid ASCII string.
There are a lot of properties in the FDT that contain a string, but commands
like ".properties" only displayed them as byte array since all properties
were encoded with "encode-bytes". Now the code tries to detect valid ASCII
strings and encodes such properties with "encode-string" instead.
Signed-off-by: Thomas Huth <thuth@linux.vnet.ibm.com>
-rw-r--r-- | board-qemu/slof/fdt.fs | 21 | ||||
-rw-r--r-- | slof/fs/base.fs | 10 | ||||
-rw-r--r-- | slof/fs/envvar.fs | 10 |
3 files changed, 29 insertions, 12 deletions
diff --git a/board-qemu/slof/fdt.fs b/board-qemu/slof/fdt.fs index a6de122..850a687 100644 --- a/board-qemu/slof/fdt.fs +++ b/board-qemu/slof/fdt.fs @@ -119,6 +119,23 @@ fdt-check-header : fdt-create-dec s" decode-unit" $CREATE , DOES> @ hex-decode-unit ; : fdt-create-enc s" encode-unit" $CREATE , DOES> @ hex-encode-unit ; +\ Check whether array contains an zero-terminated ASCII string: +: fdt-prop-is-string? ( addr len -- string? ) + dup 1 < IF 2drop FALSE EXIT THEN \ Check for valid length + 1- + 2dup + c@ 0<> IF 2drop FALSE EXIT THEN \ Check zero-termination + test-string +; + +\ Encode fdt property to OF property +: fdt-encode-prop ( addr len -- ) + 2dup fdt-prop-is-string? IF + 1- encode-string + ELSE + encode-bytes + THEN +; + \ Method to unflatten a node : fdt-unflatten-node ( start -- end ) \ this can and will recurse @@ -159,8 +176,8 @@ fdt-check-header drop dup ( drop tag, dup addr : a1 a1 ) dup l@ dup rot 4 + ( fetch size, stack is : a1 s s a2) dup l@ swap 4 + ( fetch nameid, stack is : a1 s s i a3 ) - rot ( we now have: a1 s i a3 s ) - encode-bytes rot ( a1 s pa ps i) + rot ( we now have: a1 s i a3 s ) + fdt-encode-prop rot ( a1 s pa ps i) fdt-fetch-string ( a1 s pa ps na ns ) 2dup s" reg" str= IF 2swap 2dup fdt-reg-unit 2swap diff --git a/slof/fs/base.fs b/slof/fs/base.fs index 4fc8ad4..bb95b2d 100644 --- a/slof/fs/base.fs +++ b/slof/fs/base.fs @@ -121,6 +121,16 @@ CONSTANT <2constant> : str= ( str1 len1 str2 len2 -- equal? ) rot over <> IF 3drop false ELSE comp 0= THEN ; +: test-string ( param len -- true | false ) + 0 ?DO + dup i + c@ \ Get character / byte at current index + dup 20 < swap 7e > OR IF \ Is it out of range 32 to 126 (=ASCII) + drop FALSE UNLOOP EXIT \ FALSE means: No ASCII string + THEN + LOOP + drop TRUE \ Only ASCII found --> it is a string +; + : #aligned ( adr alignment -- adr' ) negate swap negate and negate ; : #join ( lo hi #bits -- x ) lshift or ; : #split ( x #bits -- lo hi ) 2dup rshift dup >r swap lshift xor r> ; diff --git a/slof/fs/envvar.fs b/slof/fs/envvar.fs index cdf9226..70223cc 100644 --- a/slof/fs/envvar.fs +++ b/slof/fs/envvar.fs @@ -73,16 +73,6 @@ wordlist CONSTANT envvars : test-int ( param len -- true | false ) drop c@ isdigit if true else false then ; -: test-string ( param len -- true | false ) - 0 ?DO - dup i + c@ \ Get character / byte at current index - dup 20 < swap 7e > OR IF \ Is it out of range 32 to 126 (=ASCII) - drop FALSE UNLOOP EXIT \ FALSE means: No ASCII string - THEN - LOOP - drop TRUE \ Only ASCII found --> it is a string -; - : findtype ( param len name len -- param len name len type ) 2dup findenv dup 0= \ try to find type of envvar IF \ no type found |