summaryrefslogtreecommitdiffstats
path: root/qemu/roms/SLOF/slof/fs/update_flash.fs
blob: e04869d774b99d352bd9fc4450ff6655c696855e (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
\ *****************************************************************************
\ * 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
\ ****************************************************************************/

\ Set by update-flash -f to true, preventing update-flash -c
false value flash-new

: update-flash-help ( -- )
   cr ." update-flash tool to flash host FW " cr
   ."              -f <filename>      : Flash from file (e.g. net:\boot_rom.bin)" cr
   ."              -l                 : Flash from load-base" cr
   ."              -d                 : Flash from old load base (used by drone)" cr
   ."              -c                 : Flash from temp to perm" cr
   ."              -r                 : Flash from perm to temp" cr
;

: flash-read-temp ( -- success? )
   get-flashside 1 = IF flash-addr get-load-base over flash-image-size rmove true
   ELSE
      false
   THEN
;

: flash-read-perm ( -- success? )
   get-flashside 0= IF
      flash-addr get-load-base over flash-image-size rmove true
   ELSE
      false
   THEN
;

: flash-switch-side ( side -- success? )
   set-flashside 0<> IF
      s" Cannot change flashside" type cr false
   ELSE
      true
   THEN
;

: flash-ensure-temp ( -- success? )
   get-flashside 0= IF
      cr ." Cannot flash perm! Switching to temp side!"
      1 flash-switch-side
   ELSE
      true
   THEN
;

\ update-flash -f <filename>
\              -l
\              -c
\              -r

: update-flash ( "text" )
   get-flashside >r                              \ Save old flashside
   parse-word                      ( str len )   \ Parse first string
   drop dup c@                     ( str first-char )
   [char] - <> IF
      update-flash-help r> 2drop EXIT
   THEN

   1+ c@                           ( second-char )
   CASE
      [char] f OF
         parse-word cr s" do-load" evaluate
         flash-ensure-temp TO flash-new
      ENDOF
      [char] l OF
         flash-ensure-temp
      ENDOF
      [char] d OF
         flash-load-base get-load-base 200000 move
         flash-ensure-temp
      ENDOF
      [char] c OF
         flash-read-temp 0= flash-new or IF
            ." Cannot commit temp, need to boot on temp first " cr false
         ELSE
            0 flash-switch-side
         THEN
      ENDOF
      [char] r OF
         flash-read-perm 0= IF
         ." Cannot commit perm, need to boot on perm first " cr false
         ELSE
         1 flash-switch-side
         THEN
      ENDOF
      dup      OF
         false
      ENDOF
   ENDCASE

   ( true| false )

   0= IF
      update-flash-help r> drop EXIT
   THEN

   get-load-base flash-write 0= IF ." Flash write failed !! " cr THEN
   r> set-flashside drop                           \ Restore old flashside
;