1 \ *****************************************************************************
2 \ * Copyright (c) 2004, 2014 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 \ ****************************************************************************/
13 51 CONSTANT nvram-partition-type-cpulog
14 \ types 53-55 are omitted because they have been used for
15 \ storing binary tables in the past
16 60 CONSTANT nvram-partition-type-sas
17 61 CONSTANT nvram-partition-type-sms
18 6e CONSTANT nvram-partition-type-debug
19 6f CONSTANT nvram-partition-type-history
20 70 CONSTANT nvram-partition-type-common
21 7f CONSTANT nvram-partition-type-freespace
22 a0 CONSTANT nvram-partition-type-linux
24 : rztype ( str len -- ) \ stop at zero byte, read with nvram-c@
26 dup i + nvram-c@ ?dup IF ( str char )
34 create tmpStr 500 allot
35 : rzcount ( zstr -- str len )
37 dup nvram-c@ dup r> dup 1+ >r c!
41 r> drop over - swap drop tmpStr swap
44 : calc-header-cksum ( offset -- cksum )
52 : bad-header? ( offset -- flag )
53 dup 2+ nvram-w@ ( offset length )
57 dup calc-header-cksum ( offset checksum' )
58 swap 1+ nvram-c@ ( checksum ' checksum )
62 : .header ( offset -- )
64 dup bad-header? IF ( offset )
65 ." BAD HEADER -- trying to print it anyway" cr
69 dup nvram-c@ 2 0.r ( offset )
70 space space ( offset )
72 dup 2+ nvram-w@ 10 * 5 .r ( offset )
73 space space ( offset )
79 cr cr ." Type Size Name"
80 cr ." ========================"
82 dup nvram-c@ ( offset type )
84 dup .header ( offset )
85 dup 2+ nvram-w@ 10 * + ( offset offset' )
86 dup nvram-size < IF ( offset )
99 : dump-partition ['] nvram-c@ 1 (dump) ;
101 : type-no-zero ( addr len -- )
103 dup I + dup nvram-c@ 0= IF drop ELSE nvram-c@ emit THEN
108 : type-no-zero-part ( from-str cnt-str addr len )
110 dup i + dup nvram-c@ 0= IF
113 ( from-str cnt-str addr addr+i )
114 ( from-str==0 AND cnt-str > 0 )
115 3 pick 0= 3 pick 0 > AND IF
126 ( from-str-- cnt-str-- addr addr+i )
133 : (dmesg-prepare) ( base-addr -- base-addr' addr len act-off )
134 10 - \ go back to header
135 dup 14 + nvram-l@ dup >r
136 ( base-addr act-off ) ( R: act-off )
137 over over over + swap 10 + nvram-w@ + >r
138 ( base-addr act-off ) ( R: act-off nvram-act-addr )
139 over 2 + nvram-w@ 10 * swap - over swap
140 ( base-addr base-addr start-size ) ( R: act-off nvram-act-addr )
141 r> swap rot 10 + nvram-w@ - r>
144 : .dmesg ( base-addr -- )
146 ( base-addr addr len )
148 ( base-addr ) ( R: act-off )
149 dup 10 + nvram-w@ + r> type-no-zero
152 : .dmesg-part ( from-str cnt-str base-addr -- )
154 ( from-str cnt-str base-addr addr len )
156 ( base-addr from-str cnt-str addr len )
157 cr type-no-zero-part rot
158 ( base-addr ) ( R: act-off )
159 dup 10 + nvram-w@ + r> type-no-zero-part
162 : dmesg-part ( from-str cnt-str -- left-from-str left-cnt-str )
164 s" ibm,CPU0log" get-named-nvram-partition IF
167 drop .dmesg-part nip nip
171 s" ibm,CPU1log" get-named-nvram-partition IF
172 ." No log partition." cr EXIT
178 s" ibm,CPU0log" get-named-nvram-partition IF
179 ." No log partition." cr EXIT