1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371
|
\ tag: nvram config handling
\
\ this code implements IEEE 1275-1994
\
\ Copyright (C) 2003, 2004 Samuel Rydh
\
\ See the file "COPYING" for further information about
\ the copyright and warranty status of this work.
\
struct ( config )
2 cells field >cf.name
2 cells field >cf.default \ 0 -1 if no default
/n field >cf.check-xt
/n field >cf.exec-xt
/n field >cf.next
constant config-info.size
0 value config-root
\ --------------------------------------------------------
\ config handling
\ --------------------------------------------------------
: find-config ( name-str len -- 0|configptr )
config-root
begin ?dup while
-rot
2dup 4 pick >cf.name 2@
strcmp 0= if
2drop exit
then
rot >cf.next @
repeat
2drop 0
;
: is-config-word ( configp -- )
dup >cf.name 2@ $create ,
does> @
dup >cf.name 2@
s" /options" find-dev if
get-package-property if 0 -1 then
( configp prop-str prop-len )
\ drop trailing zero
?dup if 1- then
else
2drop 0 -1
then
\ use default value if property is missing
dup 0< if 2drop dup >cf.default 2@ then
\ no default value, use empty string
dup 0< if 2drop 0 0 then
rot >cf.exec-xt @ execute
;
: new-config ( name-str name-len -- configp )
2dup find-config ?dup if
nip nip
0 0 2 pick >cf.default 2!
else
dict-strdup
here config-info.size allot
dup config-info.size 0 fill
config-root over >cf.next !
dup to config-root
dup >r >cf.name 2! r>
dup is-config-word
then
( configp )
;
: config-default ( str len configp -- )
-rot
dup 0> if dict-strdup then
rot >cf.default 2!
;
: no-conf-def ( configp -- )
0 -1
;
\ --------------------------------------------------------
\ config types
\ --------------------------------------------------------
: exec-str-conf ( str len -- str len )
\ trivial
;
: check-str-conf ( str len -- str len valid? )
\ nothing
true
;
: str-config ( def-str len name len -- configp )
new-config >r
['] exec-str-conf r@ >cf.exec-xt !
['] check-str-conf r@ >cf.check-xt !
r> config-default
;
\ ------------------------------------------------------------
: exec-int-conf ( str len -- value )
\ fixme
parse-hex
;
: check-int-conf ( str len -- str len valid? )
true
;
: int-config ( def-str len name len -- configp )
new-config >r
['] exec-int-conf r@ >cf.exec-xt !
['] check-int-conf r@ >cf.check-xt !
r> config-default
;
\ ------------------------------------------------------------
: exec-secmode-conf ( str len -- n )
2dup s" command" strcmp 0= if 2drop 1 exit then
2dup s" full" strcmp 0= if 2drop 2 exit then
2drop 0
;
: check-secmode-conf ( str len -- str len valid? )
2dup s" none" strcmp 0= if true exit then
2dup s" command" strcmp 0= if true exit then
2dup s" full" strcmp 0= if true exit then
false
;
: secmode-config ( def-str len name len -- configp )
new-config >r
['] exec-secmode-conf r@ >cf.exec-xt !
['] check-secmode-conf r@ >cf.check-xt !
r> config-default
;
\ ------------------------------------------------------------
: exec-bool-conf ( str len -- value )
2dup s" true" strcmp 0= if 2drop true exit then
2dup s" false" strcmp 0= if 2drop false exit then
2dup s" TRUE" strcmp 0= if 2drop false exit then
2dup s" FALSE" strcmp 0= if 2drop false exit then
parse-hex 0<>
;
: check-bool-conf ( name len -- str len valid? )
2dup s" true" strcmp 0= if true exit then
2dup s" false" strcmp 0= if true exit then
2dup s" TRUE" strcmp 0= if 2drop s" true" true exit then
2dup s" FALSE" strcmp 0= if 2drop s" false" true exit then
false
;
: bool-config ( configp -- configp )
new-config >r
['] exec-bool-conf r@ >cf.exec-xt !
['] check-bool-conf r@ >cf.check-xt !
r> config-default
;
\ --------------------------------------------------------
\ 7.4.4 Nonvolatile memory
\ --------------------------------------------------------
: $setenv ( data-addr data-len name-str name-len -- )
2dup find-config ?dup if
>r 2swap r>
( name len data len configptr )
>cf.check-xt @ execute
0= abort" Invalid value."
2swap
else
\ create string config type
2dup no-conf-def 2swap str-config
then
2swap encode-string 2swap
s" /options" find-package drop
encode-property
;
: setenv ( "nv-param< >new-value<eol>" -- )
parse-word
\ XXX drop blanks
dup if linefeed parse else 0 0 then
dup 0= abort" Invalid value."
2swap $setenv
;
: printenv ( "{param-name}<eol>" -- )
\ XXX temporary implementation
linefeed parse 2drop
active-package
s" /options" find-device
.properties
active-package!
;
: (set-default) ( configptr -- )
dup >cf.default 2@ dup 0>= if
rot >cf.name 2@ $setenv
else
\ no default value
3drop
then
;
: set-default ( "param-name<eol>" -- )
linefeed parse
find-config ?dup if
(set-default)
else
." No such parameter." -2 throw
then
;
: set-defaults ( -- )
config-root
begin ?dup while
dup (set-default)
>cf.next @
repeat
;
( maxlen "new-name< >" -- ) ( E: -- addr len )
: nodefault-bytes
;
\ --------------------------------------------------------
\ initialize config from nvram
\ --------------------------------------------------------
\ CHRP format (array of null-terminated strings, "variable=value")
: nvram-load-configs ( data len -- )
\ XXX: no len checking performed...
drop
begin dup c@ while
( data )
dup cstrlen 2dup + 1+ -rot
( next str len )
ascii = left-split ( next val len name str )
['] $setenv catch if
2drop 2drop
then
repeat drop
;
: (nvram-store-one) ( buf len str len -- buf len success? )
swap >r
2dup < if r> 2drop 2drop false exit then
( buf len strlen R: str )
swap over - r> swap >r -rot
( str buf strlen R: res_len )
2dup + >r move r> r> true
;
: (make-configstr) ( configptr ph -- str len )
>r
>cf.name 2@
2dup r> get-package-property if
2drop 0 0 exit
else
dup if 1- then
then
( name len value-str len )
2swap s" =" 2swap
pocket tmpstrcat tmpstrcat drop
2dup + 0 swap c!
1+
;
: nvram-store-configs ( data len -- )
2 - \ make room for two trailing zeros
s" /options" find-dev 0= if 2drop exit then
>r
config-root
( data len configptr R: phandle )
begin ?dup while
r@ over >r (make-configstr)
( buf len val len R: configptr phandle )
(nvram-store-one) drop
r> >cf.next @
repeat
\ null terminate
2 + 0 fill
r> drop
;
\ --------------------------------------------------------
\ NVRAM variables
\ --------------------------------------------------------
\ fcode-debug? input-device output-device
s" true" s" auto-boot?" bool-config \ 7.4.3.5
s" boot" s" boot-command" str-config \ 7.4.3.5
s" " s" boot-file" str-config \ 7.4.3.5
s" false" s" diag-switch?" bool-config \ 7.4.3.5
no-conf-def s" diag-device" str-config \ 7.4.3.5
no-conf-def s" diag-file" str-config \ 7.4.3.5
s" false" s" fcode-debug?" bool-config \ 7.7
s" " s" nvramrc" str-config \ 7.4.4.2
s" false" s" oem-banner?" bool-config
s" " s" oem-banner" str-config
s" false" s" oem-logo?" bool-config
no-conf-def s" oem-logo" str-config
s" false" s" use-nvramrc?" bool-config \ 7.4.4.2
s" keyboard" s" input-device" str-config \ 7.4.5
s" screen" s" output-device" str-config \ 7.4.5
s" 80" s" screen-#columns" int-config \ 7.4.5
s" 24" s" screen-#rows" int-config \ 7.4.5
s" 0" s" selftest-#megs" int-config
no-conf-def s" security-mode" secmode-config
\ --- devices ---
s" -1" s" pci-probe-mask" int-config
s" false" s" default-mac-address" bool-config
s" false" s" skip-netboot?" bool-config
s" true" s" scroll-lock" bool-config
[IFDEF] CONFIG_PPC
\ ---- PPC ----
s" disk" s" boot-device" str-config \ 7.4.3.5
s" false" s" little-endian?" bool-config
s" false" s" real-mode?" bool-config
s" -1" s" real-base" int-config
s" -1" s" real-size" int-config
s" 4000000" s" load-base" int-config
s" -1" s" virt-base" int-config
s" -1" s" virt-size" int-config
[THEN]
[IFDEF] CONFIG_X86
\ ---- X86 ----
s" disk" s" boot-device" str-config \ 7.4.3.5
s" true" s" little-endian?" bool-config
[THEN]
[IFDEF] CONFIG_SPARC32
\ ---- SPARC32 ----
s" true" s" tpe-link-test?" bool-config
s" 9600,8,n,1,-" s" ttya-mode" str-config
s" true" s" ttya-ignore-cd" bool-config
s" false" s" ttya-rts-dtr-off" bool-config
s" 9600,8,n,1,-" s" ttyb-mode" str-config
s" true" s" ttyb-ignore-cd" bool-config
s" false" s" ttyb-rts-dtr-off" bool-config
[THEN]
\ --- ??? ---
s" " s" boot-screen" str-config
s" " s" boot-script" str-config
s" false" s" use-generic?" bool-config
s" " s" boot-args" str-config \ ???
\ defers
['] fcode-debug? to _fcode-debug?
['] diag-switch? to _diag-switch?
: release-load-area
drop
;
|