aboutsummaryrefslogtreecommitdiff
path: root/slof/fs/nvram.fs
blob: 322d85889d8411e0ce8c526e3fedf00c056bb54b (plain)
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
\ *****************************************************************************
\ * Copyright (c) 2004, 2008 IBM Corporation
\ * All rights reserved.
\ * This program and the accompanying materials
\ * are made available under the terms of the BSD License
\ * which accompanies this distribution, and is available at
\ * http://www.opensource.org/licenses/bsd-license.php
\ *
\ * Contributors:
\ *     IBM Corporation - initial implementation
\ ****************************************************************************/

51 CONSTANT nvram-partition-type-cpulog
\ types 53-55 are omitted because they have been used for
\ storing binary tables in the past
60 CONSTANT nvram-partition-type-sas
61 CONSTANT nvram-partition-type-sms
6e CONSTANT nvram-partition-type-debug
6f CONSTANT nvram-partition-type-history
70 CONSTANT nvram-partition-type-common
7f CONSTANT nvram-partition-type-freespace
a0 CONSTANT nvram-partition-type-linux

: rztype ( str len -- ) \ stop at zero byte, read with nvram-c@
   0 DO
      dup i + nvram-c@ ?dup IF ( str char )
         emit
      ELSE                     ( str )
         drop UNLOOP EXIT
      THEN
   LOOP
;

create tmpStr 500 allot
: rzcount ( zstr -- str len )
   dup tmpStr >r BEGIN
      dup nvram-c@ dup r> dup 1+ >r c!
   WHILE
      char+
   REPEAT
   r> drop over - swap drop tmpStr swap
;

: calc-header-cksum ( offset -- cksum )
   dup nvram-c@
   10 2 DO
      over I + nvram-c@ +
   LOOP
   wbsplit + nip
;

: bad-header? ( offset -- flag )
   dup 2+ nvram-w@        ( offset length )
   0= IF                  ( offset )
      drop true EXIT      ( )
   THEN
   dup calc-header-cksum  ( offset checksum' )
   swap 1+ nvram-c@       ( checksum ' checksum )
   <>                     ( flag )
;

: .header ( offset -- )
   cr                         ( offset )
   dup bad-header? IF         ( offset )
      ."   BAD HEADER -- trying to print it anyway" cr
   THEN
   space                      ( offset )
   \ print type
   dup nvram-c@ 2 0.r         ( offset )
   space space                ( offset )
   \ print length
   dup 2+ nvram-w@ 10 * 5 .r  ( offset )
   space space                ( offset )
   \ print name
   4 + 0c rztype              ( )
;

: .headers ( -- )
   cr cr ." Type  Size  Name"
   cr ." ========================"
   0 BEGIN                      ( offset )
      dup nvram-c@              ( offset type )
   WHILE
      dup .header               ( offset )
      dup 2+ nvram-w@ 10 * +    ( offset offset' )
      dup nvram-size < IF       ( offset )
      ELSE
	 drop EXIT              ( )
      THEN
   REPEAT
   drop                         ( )
   cr cr
;

: reset-nvram ( -- )
   internal-reset-nvram
;

: dump-partition     ['] nvram-c@      1 (dump) ;

: type-no-zero ( addr len -- )
   0 DO
      dup I + dup nvram-c@ 0= IF drop ELSE nvram-c@ emit THEN
   LOOP
   drop
;

: type-no-zero-part ( from-str cnt-str addr len )
   0 DO
      dup i + dup nvram-c@ 0= IF
         drop
      ELSE
         ( from-str cnt-str addr addr+i )
         ( from-str==0 AND cnt-str > 0 )
         3 pick 0= 3 pick 0 > AND IF
            dup 1 type-no-zero
         THEN

         nvram-c@ a = IF
            2 pick 0= IF
               over 1- 0 max
               rot drop swap
            THEN
            2 pick 1- 0 max
            3 roll drop rot rot
            ( from-str-- cnt-str-- addr addr+i )
         THEN
      THEN
   LOOP
   drop
;

: (dmesg-prepare) ( base-addr -- base-addr' addr len act-off )
   10 - \ go back to header
   dup 14 + nvram-l@ dup >r
   ( base-addr act-off ) ( R: act-off )
   over over over + swap 10 + nvram-w@ + >r
   ( base-addr act-off ) ( R:  act-off nvram-act-addr )
   over 2 + nvram-w@ 10 * swap - over swap
   ( base-addr base-addr start-size ) ( R:  act-off nvram-act-addr )
   r> swap rot 10 + nvram-w@ - r>
;

: .dmesg ( base-addr -- )
   (dmesg-prepare) >r
   ( base-addr addr len )
   cr type-no-zero
   ( base-addr ) ( R: act-off )
   dup 10 + nvram-w@ + r> type-no-zero
;

: .dmesg-part ( from-str cnt-str base-addr -- )
   (dmesg-prepare) >r
   ( from-str cnt-str base-addr addr len )
   >r >r -rot r> r>
   ( base-addr from-str cnt-str addr len )
   cr type-no-zero-part rot
   ( base-addr ) ( R: act-off )
   dup 10 + nvram-w@ + r> type-no-zero-part
;

: dmesg-part ( from-str cnt-str -- left-from-str left-cnt-str )
   2dup
   s" ibm,BE0log" get-named-nvram-partition IF
      s" ibm,CPU0log" get-named-nvram-partition IF
         2drop EXIT
      THEN
   THEN
   drop .dmesg-part nip nip
;

: dmesg2 ( -- )
   s" ibm,BE1log" get-named-nvram-partition IF
      s" ibm,CPU1log" get-named-nvram-partition IF
         ." No log partition." cr EXIT
      THEN
   THEN
   drop .dmesg
;

: dmesg ( -- )
   s" ibm,BE0log" get-named-nvram-partition IF
      s" ibm,CPU0log" get-named-nvram-partition IF
         ." No log partition." cr EXIT
      THEN
   THEN
   drop .dmesg
;