From a4e614ae5b39848e08e8e644ba71dd69e2bf3be3 Mon Sep 17 00:00:00 2001 From: Andres Salomon Date: Tue, 15 May 2012 02:05:32 -0700 Subject: [PATCH] installer: verify install target 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 --- inst.fth | 98 +++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 75 insertions(+), 23 deletions(-) diff --git a/inst.fth b/inst.fth index 2c6a2c7..8c3e6d0 100644 --- 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 ; @@ -50,26 +122,6 @@ 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 ) -- 2.39.2