]> spindle.queued.net Git - xodist/blob - inst.fth
installer: fill in inst.fth's backup size check
[xodist] / inst.fth
1 \ DebXO installer script
2
3 : disk-size  ( devspec$ -- #MB )
4    open-dev ?dup 0<> if                         ( ih )
5       dup " #blocks" rot $call-method           ( ih #blocks )
6       ?dup 0<> if
7          \ we're assuming a block size of 512 bytes
8          d# 512 um*                             ( ih bytes.lo bytes.hi )
9       else
10          dup " size" rot $call-method           ( ih size.lo size.hi )
11       then
12       d# 1,000,000 um/mod                       ( ih rem #MB )
13       rot close-dev nip                         ( #MB )
14    else
15       0                                         ( #MB )
16    then
17 ;
18
19 : target-big-enough?  ( devspec$ -- flag )
20    disk-size                                    ( #MB )
21    \ we only support devices >= 1GB
22    d# 1000 u< if
23       " Installation target too small, must be at least 1GB.  Aborting..."
24       dialog-alert
25       false                                     ( flag )
26    else
27       true                                      ( flag )
28    then
29 ;
30
31 d# 128 buffer: verifystr
32
33 : user-verified?  ( tgt$ -- flag )
34    \ ensure the user *actually* wanted to reformat the device..
35    " WARNING: this will overwrite all data on " ( tgt$ str$ )
36    verifystr pack $cat
37    " .  Are you sure that you want to do this?" ( str2$ )
38    verifystr $cat
39    verifystr count                              ( finalstr$ )
40    dialog-no                                    ( flag )
41    dup invert if
42       " Installation cancelled."
43       dialog-alert
44    then                                         ( flag )
45 ;
46  
47 : verify-target  ( tgt$ devspec$ -- )
48    \ XXX: For some reason refresh isn't called after a dialog-alert
49    \ (or menu item callback).  This means the menu display is incorrect
50    \ until go-vertical is called.  Calling refresh manually here doesn't
51    \ work... so for now, kill the menu and restart it later.
52    menu-done                                    ( tgt$ devspec$ )
53
54    target-big-enough? -rot                      ( flag tgt$ )
55    user-verified? and if
56       true
57    else
58       \ installation cancelled/failed, redisplay menu
59       (menu)
60       false
61    then
62 ;
63
64 : choose-nand-item
65    " the internal NAND storage" " /nandflash" verify-target if
66       " installing!" dialog-alert
67    then
68    ." Nand" cr
69 ;
70
71 : choose-emmc-item
72    " the internal MMC device" " int:0" verify-target if
73       " installing!" dialog-alert
74    then
75    ." EMMC" cr
76 ;
77
78 : choose-sd-item
79    " this SD card" " ext:0" verify-target if
80       " installing!" dialog-alert
81    then
82    ." SD" cr
83 ;
84
85 : choose-usb-item
86    menu-done
87    ." USB" cr
88 ;
89
90 : choose-usb-item-0
91    menu-done
92    ." USB #1" cr
93 ;
94 : choose-usb-item-1
95    menu-done
96    ." USB #2" cr
97 ;
98 : choose-usb-item-2
99    menu-done
100    ." USB #3" cr
101 ;
102 : choose-usb-item-3
103    menu-done
104    ." USB #4" cr
105 ;
106
107 0 value nr-targets
108
109 : has-target?  ( devspec$ -- flag )
110    open-dev                                     ( ih )
111    ?dup 0<> if
112       close-dev
113       nr-targets 1+ to nr-targets
114       true
115    else
116       false
117    then
118 ;
119
120 : debxo-find-targets  ( -- help0$ 'func0 'icon0 ... helpk$ 'funck 'iconk )
121    0 to nr-targets
122
123    \ check for the existence of nandflash (XO-1)
124    " /nandflash" has-target? if
125       " Internal NAND"
126       ['] choose-nand-item spi.icon
127    else
128       \ check for internal EMMC (XO-1.5, XO-1.75)
129       " int:0" has-target? if
130          64 alloc-mem >r
131          " int:0" disk-size decimal             ( #MB )
132          <# "  MB)" hold$ u#s " Internal MMC (" hold$ u#>
133          r> pack count
134          \ " Internal MMC"
135          ['] choose-emmc-item spi.icon
136       then
137    then
138
139    " ext:0" has-target? if
140        64 alloc-mem >r
141        " ext:0" disk-size decimal               ( #MB )
142        <# "  MB)" hold$ u#s " SD Card (" hold$ u#>
143        r> pack count
144 \      " SD Card"
145       ['] choose-sd-item sdcard.icon
146    then
147
148    \ check for up to 4 USB drives
149    4 0  do
150       i <# " /disk" hold$ u# " /usb/scsi@" hold$ u#>  string2 pack
151       count has-target? if
152          \ create description
153          i 1+                                   ( i )
154          64 alloc-mem >r                        ( i )
155          <# u# " USB Disk #" hold$ u#>  r@ place
156          string2 count disk-size decimal        ( #MB )
157          <# "  MB)" hold$ u#s "  (" hold$ u#> r@ $cat
158
159          r> count                               ( desc$ )
160          i <# u# " ['] choose-usb-item-" hold$ u#> evaluate usb.icon
161       then
162    loop
163
164 \ TODO: multiple usb disks?
165 \ differentiate between installer disk & extra disk..
166 ;
167
168
169 : debxo-installer-menu  ( -- )
170    \ populate stack w/ icon/target list
171    debxo-find-targets      
172
173    \ last entry on the list
174    " Abort installation"
175    ['] quit-item quit.icon
176
177    \ generate the menu
178    d# 1 to rows
179    nr-targets 1+ to cols
180
181    clear-menu
182
183    0 nr-targets  do
184       0 i install-icon
185    -1 +loop
186 ;
187
188 : instmenu
189    ['] debxo-installer-menu to root-menu
190    (menu)
191 ;