Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / SLOF / slof / fs / update_flash.fs
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
8 \ *
9 \ * Contributors:
10 \ *     IBM Corporation - initial implementation
11 \ ****************************************************************************/
12
13 \ Set by update-flash -f to true, preventing update-flash -c
14 false value flash-new
15
16 : update-flash-help ( -- )
17    cr ." update-flash tool to flash host FW " cr
18    ."              -f <filename>      : Flash from file (e.g. net:\boot_rom.bin)" cr
19    ."              -l                 : Flash from load-base" cr
20    ."              -d                 : Flash from old load base (used by drone)" cr
21    ."              -c                 : Flash from temp to perm" cr
22    ."              -r                 : Flash from perm to temp" cr
23 ;
24
25 : flash-read-temp ( -- success? )
26    get-flashside 1 = IF flash-addr get-load-base over flash-image-size rmove true
27    ELSE
28       false
29    THEN
30 ;
31
32 : flash-read-perm ( -- success? )
33    get-flashside 0= IF
34       flash-addr get-load-base over flash-image-size rmove true
35    ELSE
36       false
37    THEN
38 ;
39
40 : flash-switch-side ( side -- success? )
41    set-flashside 0<> IF
42       s" Cannot change flashside" type cr false
43    ELSE
44       true
45    THEN
46 ;
47
48 : flash-ensure-temp ( -- success? )
49    get-flashside 0= IF
50       cr ." Cannot flash perm! Switching to temp side!"
51       1 flash-switch-side
52    ELSE
53       true
54    THEN
55 ;
56
57 \ update-flash -f <filename>
58 \              -l
59 \              -c
60 \              -r
61
62 : update-flash ( "text" )
63    get-flashside >r                              \ Save old flashside
64    parse-word                      ( str len )   \ Parse first string
65    drop dup c@                     ( str first-char )
66    [char] - <> IF
67       update-flash-help r> 2drop EXIT
68    THEN
69
70    1+ c@                           ( second-char )
71    CASE
72       [char] f OF
73          parse-word cr s" do-load" evaluate
74          flash-ensure-temp TO flash-new
75       ENDOF
76       [char] l OF
77          flash-ensure-temp
78       ENDOF
79       [char] d OF
80          flash-load-base get-load-base 200000 move
81          flash-ensure-temp
82       ENDOF
83       [char] c OF
84          flash-read-temp 0= flash-new or IF
85             ." Cannot commit temp, need to boot on temp first " cr false
86          ELSE
87             0 flash-switch-side
88          THEN
89       ENDOF
90       [char] r OF
91          flash-read-perm 0= IF
92          ." Cannot commit perm, need to boot on perm first " cr false
93          ELSE
94          1 flash-switch-side
95          THEN
96       ENDOF
97       dup      OF
98          false
99       ENDOF
100    ENDCASE
101
102    ( true| false )
103
104    0= IF
105       update-flash-help r> drop EXIT
106    THEN
107
108    get-load-base flash-write 0= IF ." Flash write failed !! " cr THEN
109    r> set-flashside drop                           \ Restore old flashside
110 ;