]> spindle.queued.net Git - xodist/commitdiff
installer: verify install target
authorAndres Salomon <dilinger@queued.net>
Tue, 15 May 2012 09:05:32 +0000 (02:05 -0700)
committerAndres Salomon <dilinger@queued.net>
Tue, 15 May 2012 09:05:32 +0000 (02:05 -0700)
Prompt the user to ensure that they really want to install, and
also check that the device size is >= 1GB.

Signed-off-by: Andres Salomon <dilinger@queued.net>
inst.fth

index 2c6a2c73a35f70c0571ef5d02a6bc5b0285948f9..8c3e6d073e4acc20a718622328d348a17337ffe3 100644 (file)
--- a/inst.fth
+++ b/inst.fth
@@ -1,17 +1,89 @@
 \ DebXO installer script
 
+: disk-size  ( devspec$ -- #MB )
+   open-dev ?dup 0<> if                         ( ih )
+      dup " #blocks" rot $call-method           ( ih #blocks )
+      ?dup 0<> if
+         \ we're assuming a block size of 512 bytes
+         d# 512 um*                             ( ih #bytes )
+         d# 1,000,000 um/mod                    ( ih rem #MB )
+         rot close-dev swap drop                ( #MB )
+      else
+\ TODO
+         drop
+         0
+\      dup " block-size" rot $call-method        ( ih  size x )
+\      rot close-dev drop                        ( size.lo )
+\      d# 20 >>                                  ( #MB )
+      then
+   else
+      0                                         ( #MB )
+   then
+;
+
+: target-big-enough?  ( devspec$ -- flag )
+   disk-size                                    ( #MB )
+   \ we only support devices >= 1GB
+   d# 1000 u< if
+      " Installation target too small, must be at least 1GB.  Aborting..."
+      dialog-alert
+      false                                     ( flag )
+   else
+      true                                      ( flag )
+   then
+;
+
+d# 128 buffer: verifystr
+
+: user-verified?  ( tgt$ -- flag )
+   \ ensure the user *actually* wanted to reformat the device..
+   " WARNING: this will overwrite all data on " ( tgt$ str$ )
+   verifystr pack $cat
+   " .  Are you sure that you want to do this?" ( str2$ )
+   verifystr $cat
+   verifystr count                              ( finalstr$ )
+   dialog-no                                    ( flag )
+   dup invert if
+      " Installation cancelled."
+      dialog-alert
+   then                                         ( flag )
+;
+: verify-target  ( tgt$ devspec$ -- )
+   \ XXX: For some reason refresh isn't called after a dialog-alert
+   \ (or menu item callback).  This means the menu display is incorrect
+   \ until go-vertical is called.  Calling refresh manually here doesn't
+   \ work... so for now, kill the menu and restart it later.
+   menu-done                                    ( tgt$ devspec$ )
+
+   target-big-enough? -rot                      ( flag tgt$ )
+   user-verified? and if
+      true
+   else
+      \ installation cancelled/failed, redisplay menu
+      (menu)
+      false
+   then
+;
+
 : choose-nand-item
-   menu-done
+   " the internal NAND storage" " /nandflash" verify-target if
+      " installing!" dialog-alert
+   then
    ." Nand" cr
 ;
 
 : choose-emmc-item
-   menu-done
+   " the internal MMC device" " int:0" verify-target if
+      " installing!" dialog-alert
+   then
    ." EMMC" cr
 ;
 
 : choose-sd-item
-   menu-done
+   " this SD card" " ext:0" verify-target if
+      " installing!" dialog-alert
+   then
    ." SD" cr
 ;
 
    then
 ;
 
-: disk-size  ( devspec$ -- #MB )
-   open-dev ?dup 0<> if                         ( ih )
-      dup " #blocks" rot $call-method           ( ih #blocks )
-      ?dup 0<> if
-         \ we're assuming a block size of 512 bytes
-         d# 512 um*                             ( ih #bytes )
-         d# 1,000,000 um/mod                    ( ih rem #MB )
-         rot close-dev swap drop                ( #MB )
-      else
-         drop
-         0  \ TODO
-\      dup " block-size" rot $call-method        ( ih  size x )
-  \    rot close-dev drop                        ( size.lo )
-   \   d# 20 >>                                  ( #MB )
-      then
-   else
-      0                                         ( #MB )
-   then
-;
-
 \ : disk-size  ( devspec$ -- #MB )
 \   open-dev ?dup 0<> if                         ( ih )
 \      dup " size" rot $call-method              ( ih size.lo size.hi )