1 \ tag
: nvram config handling
3 \ this
code implements
IEEE 1275-1994
5 \
Copyright (C) 2003, 2004 Samuel Rydh
7 \
See the file
"COPYING" for further information about
8 \
the copyright and warranty status
of this
work.
12 2 cells
field >cf
.name
13 2 cells
field >cf
.default \
0 -1 if no
default
17 constant
config-info
.size
21 \
--------------------------------------------------------
23 \
--------------------------------------------------------
25 : find
-config ( name
-str len
-- 0|configptr
)
29 2dup 4 pick
>cf
.name
2@
38 : is
-config-word ( configp
-- )
39 dup
>cf
.name
2@ $create
,
42 s
" /options" find
-dev
if
43 get
-package
-property
if 0 -1 then
44 ( configp prop
-str prop
-len
)
50 \
use default value
if property is
missing
51 dup
0< if 2drop dup
>cf
.default 2@ then
52 \ no
default value, use empty string
53 dup
0< if 2drop 0 0 then
55 rot
>cf
.exec
-xt
@ execute
58 : new-config ( name
-str name
-len
-- configp
)
59 2dup find
-config ?dup
if
61 0 0 2 pick
>cf
.default 2!
64 here
config-info
.size
allot
65 dup
config-info
.size
0 fill
66 config-root
over >cf
.next
!
74 : config-default ( str len configp
-- )
76 dup
0> if dict
-strdup
then
80 : no
-conf
-def
( configp
-- )
84 \
--------------------------------------------------------
86 \
--------------------------------------------------------
88 : exec
-str
-conf
( str len
-- str len
)
91 : check
-str
-conf
( str len
-- str len valid
? )
96 : str
-config ( def
-str len name
len -- configp
)
98 ['] exec-str-conf r@ >cf.exec-xt !
99 ['] check
-str
-conf r
@ >cf
.check
-xt
!
103 \
------------------------------------------------------------
105 : exec
-int-conf
( str
len -- value )
109 : check
-int-conf
( str
len -- str
len valid
? )
113 : int-config ( def
-str
len name
len -- configp
)
115 ['] exec-int-conf r@ >cf.exec-xt !
116 ['] check
-int-conf r
@ >cf
.check
-xt
!
120 \
------------------------------------------------------------
122 : exec
-secmode
-conf
( str
len -- n
)
123 2dup s
" command" strcmp
0= if 2drop 1 exit
then
124 2dup s
" full" strcmp
0= if 2drop 2 exit
then
127 : check
-secmode
-conf
( str
len -- str
len valid
? )
128 2dup s
" none" strcmp
0= if true exit then
129 2dup s
" command" strcmp
0= if true exit then
130 2dup s
" full" strcmp
0= if true exit then
134 : secmode
-config ( def
-str
len name
len -- configp
)
136 ['] exec-secmode-conf r@ >cf.exec-xt !
137 ['] check
-secmode
-conf r
@ >cf
.check
-xt
!
141 \
------------------------------------------------------------
143 : exec
-bool-conf
( str
len -- value )
144 2dup s
" true" strcmp
0= if 2drop true exit then
145 2dup s
" false" strcmp
0= if 2drop false exit then
146 2dup s
" TRUE" strcmp
0= if 2drop false exit then
147 2dup s
" FALSE" strcmp
0= if 2drop false exit then
151 : check
-bool-conf
( name
len -- str
len valid
? )
152 2dup s
" true" strcmp
0= if true exit then
153 2dup s
" false" strcmp
0= if true exit then
154 2dup s
" TRUE" strcmp
0= if 2drop s
" true" true exit then
155 2dup s
" FALSE" strcmp
0= if 2drop s
" false" true exit then
159 : bool-config ( configp
-- configp
)
161 ['] exec-bool-conf r@ >cf.exec-xt !
162 ['] check
-bool-conf r
@ >cf
.check
-xt
!
167 \
--------------------------------------------------------
168 \
7.4.4 Nonvolatile memory
169 \
--------------------------------------------------------
171 : $setenv
( data
-addr data
-len name
-str name
-len -- )
172 2dup find
-config ?dup
if
174 ( name
len data
len configptr
)
175 >cf
.check
-xt
@ execute
176 0= abort
" Invalid value."
179 \ create
string config type
180 2dup no
-conf
-def
2swap str
-config
183 2swap encode
-string 2swap
184 s
" /options" find
-package
drop
188 : setenv
( "nv-param< >new-value<eol>" -- )
191 dup
if linefeed parse
else 0 0 then
193 dup
0= abort
" Invalid value."
197 : printenv
( "{param-name}<eol>" -- )
198 \
XXX temporary implementation
202 s
" /options" find
-device
207 : (set
-default) ( configptr
-- )
208 dup
>cf
.default 2@ dup
0>= if
209 rot
>cf
.name
2@ $setenv
216 : set
-default ( "param-name<eol>" -- )
221 ." No such parameter." -2 throw
225 : set
-defaults
( -- )
233 ( maxlen
"new-name< >" -- ) ( E: -- addr
len )
238 \
--------------------------------------------------------
239 \ initialize
config from nvram
240 \
--------------------------------------------------------
242 \
CHRP format
(array
of null-terminated strings
, "variable=value")
243 : nvram
-load
-configs
( data
len -- )
244 \
XXX: no
len checking performed
...
248 dup cstrlen
2dup + 1+ -rot
250 ascii
= left
-split
( next
val len name
str )
257 : (nvram-store-one) ( buf len str len -- buf len success? )
259 2dup < if r> 2drop 2drop false exit then
260 ( buf len strlen R: str )
261 swap over - r> swap >r -rot
262 ( str buf strlen R: res_len )
263 2dup + >r move r> r> true
266 : (make-configstr) ( configptr ph -- str len )
269 2dup r> get-package-property if
274 ( name len value-str len )
276 pocket tmpstrcat tmpstrcat drop
281 : nvram-store-configs ( data len -- )
282 2 - \ make room for two trailing zeros
284 s" /options" find-dev 0= if 2drop exit then
287 ( data len configptr R: phandle )
289 r@ over >r (make-configstr)
290 ( buf len val len R: configptr phandle )
291 (nvram-store-one) drop
300 \ --------------------------------------------------------
302 \ --------------------------------------------------------
303 \ fcode-debug? input-device output-device
304 s" true" s" auto-boot?" bool-config \ 7.4.3.5
305 s" boot" s" boot-command" str-config \ 7.4.3.5
306 s" " s" boot-file" str-config \ 7.4.3.5
307 s" false" s" diag-switch?" bool-config \ 7.4.3.5
308 no-conf-def s" diag-device" str-config \ 7.4.3.5
309 no-conf-def s" diag-file" str-config \ 7.4.3.5
310 s" false" s" fcode-debug?" bool-config \ 7.7
311 s" " s" nvramrc" str-config \ 7.4.4.2
312 s" false" s" oem-banner?" bool-config
313 s" " s" oem-banner" str-config
314 s" false" s" oem-logo?" bool-config
315 no-conf-def s" oem-logo" str-config
316 s" false" s" use-nvramrc?" bool-config \ 7.4.4.2
317 s" keyboard" s" input-device" str-config \ 7.4.5
318 s" screen" s" output-device" str-config \ 7.4.5
319 s" 80" s" screen-#columns" int-config \ 7.4.5
320 s" 24" s" screen-#rows" int-config \ 7.4.5
321 s" 0" s" selftest-#megs" int-config
322 no-conf-def s" security-mode" secmode-config
325 s" -1" s" pci-probe-mask" int-config
326 s" false" s" default-mac-address" bool-config
327 s" false" s" skip-netboot?" bool-config
328 s" true" s" scroll-lock" bool-config
332 s" disk" s" boot-device" str-config \ 7.4.3.5
333 s" false" s" little-endian?" bool-config
334 s" false" s" real-mode?" bool-config
335 s" -1" s" real-base" int-config
336 s" -1" s" real-size" int-config
337 s" 4000000" s" load-base" int-config
338 s" -1" s" virt-base" int-config
339 s" -1" s" virt-size" int-config
344 s" disk" s" boot-device" str-config \ 7.4.3.5
345 s" true" s" little-endian?" bool-config
348 [IFDEF] CONFIG_SPARC32
350 s" true" s" tpe-link-test?" bool-config
351 s" 9600,8,n,1,-" s" ttya-mode" str-config
352 s" true" s" ttya-ignore-cd" bool-config
353 s" false" s" ttya-rts-dtr-off" bool-config
354 s" 9600,8,n,1,-" s" ttyb-mode" str-config
355 s" true" s" ttyb-ignore-cd" bool-config
356 s" false" s" ttyb-rts-dtr-off" bool-config
359 [IFDEF] CONFIG_SPARC64
361 s" 4000000" s" load-base" int-config
362 s" false" s" little-endian?" bool-config
366 s" " s" boot-screen" str-config
367 s" " s" boot-script" str-config
368 s" false" s" use-generic?" bool-config
369 s" " s" boot-args" str-config \ ???
372 ['] fcode
-debug
? to _fcode
-debug
?
373 ['] diag-switch? to _diag-switch?
375 \ Hack for load-base: it seems that some Sun bootloaders try
376 \ and execute "<value> to load-base" which will only work if
377 \ load-base is value. Hence we redefine load-base here as a
378 \ value using its normal default.
379 [IFDEF] CONFIG_SPARC64
380 load-base value load-base