1 \ *****************************************************************************
2 \ * Copyright (c) 2004, 2008 IBM Corporation
3 \ * All rights reserved.
4 \ * This program and the accompanying materials
5 \ * are made available under the terms of the BSD License
6 \ * which accompanies this distribution, and is available at
7 \ * http://www.opensource.org/licenses/bsd-license.php
10 \ * IBM Corporation - initial implementation
11 \ ****************************************************************************/
14 cell field romfs>file-header
16 cell field romfs>data-size
17 cell field romfs>flags
19 CONSTANT /romfs-lookup-control-block
21 CREATE romfs-lookup-cb /romfs-lookup-control-block allot
22 romfs-lookup-cb /romfs-lookup-control-block erase
24 : create-filename ( string -- string\0 )
29 : romfs-lookup ( fn-str fn-len -- data size | false )
30 create-filename romfs-base
31 romfs-lookup-cb romfs-lookup-entry call-c
32 0= IF romfs-lookup-cb dup romfs>data @ swap romfs>data-size @ ELSE
35 : ibm,romfs-lookup ( fn-str fn-len -- data-high data-low size | 0 0 false )
37 0= if drop 0 0 false else
38 swap dup 20 rshift swap ffffffff and then ;
40 \ FIXME For a short time ...
41 : romfs-lookup-client ibm,romfs-lookup ;
43 \ Fixme temp implementation
46 cell field romfs>next-off
48 cell field romfs>flags
49 cell field romfs>data-off
54 : romfs-map-file ( fn-str fn-len -- file-addr file-size )
56 BEGIN 2dup r@ romfs>name zcount string=ci not WHILE
57 ( fn-str fn-len ) ( R: rom-cb-file-addr )
58 r> romfs>next-off dup @ dup 0= IF 1 THROW THEN + >r REPEAT
59 ( fn-str fn-len ) ( R: rom-cb-file-addr )
60 2drop r@ romfs>data-off @ r@ + r> romfs>size @ ;
62 \ returns address of romfs-header file
63 : flash-header ( -- address | false )
64 get-flash-base 28 + \ prepare flash header file address
65 dup rx@ \ fetch "magic123"
66 6d61676963313233 <> IF \ IF flash is not valid
67 drop \ | forget address
68 false \ | return false
72 CREATE bdate-str 10 allot
73 : bdate2human ( -- addr len )
74 flash-header 40 + rx@ (.)
75 drop dup 0 + bdate-str 6 + 4 move
76 dup 4 + bdate-str 0 + 2 move
77 dup 6 + bdate-str 3 + 2 move
78 dup 8 + bdate-str b + 2 move
79 a + bdate-str e + 2 move
88 \ Look up a file in the ROM file system and evaluate it
90 : included ( fn fn-len -- )
91 2dup >r >r romfs-lookup dup IF
92 r> drop r> drop evaluate
94 drop ." Cannot open file : " r> r> type cr
98 : include ( " fn " -- )
102 : ?include ( flag " fn " -- )
103 parse-word rot IF included ELSE 2drop THEN
106 : include? ( nargs flag " fn " -- )
110 2drop 0 ?DO drop LOOP
115 \ List files in ROMfs
117 : (print-romfs-file-info) ( file-addr -- )
118 9 emit dup b 0.r 2 spaces dup 8 + @ 6 0.r 2 spaces 20 + zcount type cr
122 romfs-base 0 cr BEGIN + dup (print-romfs-file-info) dup @ dup 0= UNTIL 2drop