Skip to content

Commit 3cbb795

Browse files
committed
fixup install scripts
- properly find boot device - properly identify emmc/sd devices - ensure special veyron emmc partitioning is used
1 parent 6cbe371 commit 3cbb795

File tree

2 files changed

+74
-40
lines changed

2 files changed

+74
-40
lines changed

kernel/resources/shared/FlashKernelPartition.sh

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,30 +27,42 @@ device_veyron_mickey="Google Mickey"
2727
device_gru_kevin="Google Kevin"
2828
device_gru_bob="Google Bob"
2929

30+
3031
get_device() {
3132
local device=$(tr -d '\0' < /sys/firmware/devicetree/base/model)
3233
echo $device
3334
}
3435

36+
37+
is_device_veyron() {
38+
local device=$(get_device)
39+
list = "${device_veyron_speedy} ${device_veyron_minnie} ${device_veyron_mickey}"
40+
for dev in $list
41+
do
42+
if [ "$device" == "$dev" ]
43+
echo "True"
44+
fi
45+
done
46+
echo "False"
47+
}
48+
3549
get_emmc_devname() {
36-
local devname=$(ls /dev/mmcblk* | grep -F boot0 | sed "s/boot0//")
50+
local devname=$(find /dev -name "mmcblk*boot0" | sed "s/boot0//")
3751
if [ -z "$devname" ]
3852
then
39-
echo "Unknown device! can't determine emmc devname. Please file an issue with the output of fdisk -l if you get this on a supported device"; exit 1;;
53+
echo "Unknown device! can't determine emmc devname. Please file an issue with the output of fdisk -l if you get this on a supported device"; exit 1;
4054
fi
4155
echo $devname
4256
}
4357

4458
get_sd_devname() {
45-
local device=$(get_device)
46-
case "$device" in
47-
$device_veyron_speedy) local devname=mmcblk0;;
48-
$device_veyron_minnie) local devname=mmcblk0;;
49-
$device_veyron_mickey) local devname="";;
50-
$device_gru_kevin) local devname=mmcblk0;;
51-
$device_gru_bob) local devname=mmcblk0;;
52-
* ) echo "Unknown device! can't determine sd card devname. Please file an issue with the output of fdisk -l if you get this on a supported device"; exit 1;;
53-
esac
59+
local emmc=$(get_emmc_devname)
60+
devname=$(find /dev -name "mmcblk*" ! -iwholename "*${emmc}*" ! -name "*mmcblk*p*")
61+
62+
if [ -z "$devname" ]
63+
then
64+
echo "Unknown device! can't determine sd devname. Please file an issue with the output of fdisk -l if you get this on a supported device"; exit 1;
65+
fi
5466
echo $devname
5567
}
5668

scripts/InstallScripts/InstallPrawnOS.sh

Lines changed: 51 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@
1818
# along with PrawnOS. If not, see <https://www.gnu.org/licenses/>.
1919

2020
# Grab the boot device, which is either /dev/sda for usb or /dev/mmcblk(0/1) for an sd card
21-
BOOT_DEVICE=$(mount | head -n 1 | cut -d '2' -f 1)
21+
# mmc and sd devices use the "p" prefix for their partitions, so add the "p" if we are booting from
22+
# one of those
23+
BOOT_DEVICE_NO_P=/dev/$(eval $(lsblk -oMOUNTPOINT,PKNAME -P | grep 'MOUNTPOINT="/"'); echo $PKNAME)
24+
BOOT_DEVICE=$BOOT_DEVICE_NO_P
25+
if [[ "$BOOT_DEVICE_NO_P" == *"mmcblk"* ]]; then
26+
BOOT_DEVICE=${BOOT_DEVICE_NO_P}p
27+
fi
2228

2329
### SHARED CONST AND VARS
2430
RESOURCES=/etc/prawnos/install/resources
@@ -31,31 +37,47 @@ device_veyron_mickey="Google Mickey"
3137
device_gru_kevin="Google Kevin"
3238
device_gru_bob="Google Bob"
3339

40+
3441
get_device() {
3542
local device=$(tr -d '\0' < /sys/firmware/devicetree/base/model)
3643
echo $device
3744
}
3845

46+
47+
is_device_veyron() {
48+
local device=$(get_device)
49+
list=("${device_veyron_speedy}"
50+
"${device_veyron_minnie}"
51+
"${device_veyron_mickey}"
52+
)
53+
local IFS=""
54+
for dev in ${list[*]}
55+
do
56+
if [[ "$device" == "$dev" ]]; then
57+
echo "true"
58+
exit 0
59+
fi
60+
done
61+
echo "false"
62+
}
63+
3964
get_emmc_devname() {
40-
local devname=$(ls /dev/mmcblk* | grep -F boot0 | sed "s/boot0//")
65+
local devname=$(find /dev -name "mmcblk*boot0" | sed "s/boot0//")
4166
if [ -z "$devname" ]
4267
then
4368
echo "Unknown device! can't determine emmc devname. Please file an issue with the output of fdisk -l if you get this on a supported device"; exit 1;
4469
fi
4570
echo $devname
4671
}
4772

48-
4973
get_sd_devname() {
50-
local device=$(get_device)
51-
case "$device" in
52-
$device_veyron_speedy) local devname=mmcblk0;;
53-
$device_veyron_minnie) local devname=mmcblk0;;
54-
$device_veyron_mickey) local devname="";;
55-
$device_gru_kevin) local devname=mmcblk0;;
56-
$device_gru_bob) local devname=mmcblk0;;
57-
* ) echo "Unknown device! can't determine sd card devname. Please file an issue with the output of fdisk -l if you get this on a supported device"; exit 1;;
58-
esac
74+
local emmc=$(get_emmc_devname)
75+
devname=$(find /dev -name "mmcblk*" ! -iwholename "*${emmc}*" ! -name "*mmcblk*p*")
76+
77+
if [ -z "$devname" ]
78+
then
79+
echo "Unknown device! can't determine sd devname. Please file an issue with the output of fdisk -l if you get this on a supported device"; exit 1;
80+
fi
5981
echo $devname
6082
}
6183

@@ -77,7 +99,7 @@ main() {
7799
echo "---------------------------------------------------------------------------------------------------------------------"
78100
echo
79101
echo "Expand or Install?: "
80-
echo "The currently booted device is ${BOOT_DEVICE}"
102+
echo "The currently booted device is ${BOOT_DEVICE_NO_P}"
81103
while true; do
82104
read -r -p "[I]nstall or [E]xpand?" IE
83105
case $IE in
@@ -91,34 +113,28 @@ main() {
91113
#Now to pick the install target: internal, sd, or usb
92114
#if target is usb, and boot device is usb, target is sdb
93115
#and whether to enable crypto
94-
#TODO the logic to get the emmc devname includes "/dev" while the logic for the sd dev name does not. fix this
95116
install() {
96117
echo "Pick an install target. This can be the Internal Emmc, an SD card, or a USB device"
97118
echo "Please ensure you have only have the booted device and the desired target device inserted."
98-
echo "The currently booted device is ${BOOT_DEVICE}"
119+
echo "The currently booted device is ${BOOT_DEVICE_NO_P}"
99120
while true; do
100121
read -r -p "[I]nternal Emmc, [S]D card, or [U]SB device?: " ISU
101122
case $ISU in
102123
[Ii]* ) TARGET=$(get_emmc_devname)p; TARGET_EMMC=true; break;;
103-
[Ss]* ) TARGET=/dev/$(get_sd_devname)p; TARGET_EMMC=false; break;;
124+
[Ss]* ) TARGET=$(get_sd_devname)p; TARGET_EMMC=false; break;;
104125
[Uu]* ) TARGET=USB; TARGET_EMMC=false; break;;
105126
* ) echo "Please answer I, S, or U";;
106127
esac
107128
done
108129
if [[ $TARGET == "USB" ]]
109130
then
110-
if [[ $BOOT_DEVICE == "/dev/sda" ]]
131+
if [[ $BOOT_DEVICE_NO_P == "/dev/sda" ]]
111132
then
112133
TARGET=/dev/sdb
113134
else
114135
TARGET=/dev/sda
115136
fi
116137
fi
117-
if [[ "$TARGET" == "$BOOT_DEVICE" ]]
118-
then
119-
echo "Can't install to booted device, please ensure you have *only* the booted device and target device inserted"
120-
exit
121-
fi
122138

123139
#cut off the "p" if we are using an sd card or internal emmc, doesn't change TARGET if we are using usb
124140
TARGET_NO_P=$(echo $TARGET | cut -d 'p' -f 1)
@@ -128,6 +144,13 @@ install() {
128144
exit 1
129145
fi
130146

147+
if [[ "$TARGET_NO_P" == "$BOOT_DEVICE_NO_P" ]]
148+
then
149+
echo "Can't install to booted device, please ensure you have *only* the booted device and target device inserted"
150+
exit
151+
fi
152+
153+
131154
#Now on to the installation, basically copy InstallToInternal.sh
132155
while true; do
133156
read -r -p "This will ERASE ALL DATA ON ${TARGET_NO_P} and reboot when finished, do you want to continue? [y/N]" yn
@@ -151,7 +174,7 @@ install() {
151174
fi
152175

153176
#only use the emmc_partition function for "special cases", aka veyron devices
154-
if [[ $TARGET == "/dev/mmcblk2p" ]] && $TARGET_EMMC
177+
if $(is_device_veyron) && $TARGET_EMMC
155178
then
156179
emmc_partition
157180
else
@@ -248,17 +271,18 @@ emmc_partition() {
248271
#disable dmesg, writing the partition map tries to write the the first gpt table, which is unmodifiable
249272
dmesg -D
250273
echo Writing partition map to internal emmc
251-
DISK_SZ="$(blockdev --getsz /dev/mmcblk2)"
274+
local dev=$(get_emmc_devname)
275+
DISK_SZ="$(blockdev --getsz ${dev})"
252276
echo Total disk size is: $DISK_SZ
253277
if [ $DISK_SZ = 30785536 ]
254278
then
255279
echo Detected Emmc Type 1
256-
sfdisk /dev/mmcblk2 < $RESOURCES/mmc.partmap || true
280+
sfdisk $dev < $RESOURCES/mmc.partmap || true
257281

258282
elif [ $DISK_SZ = 30777344 ]
259283
then
260284
echo Detected Emmc Type 2
261-
sfdisk /dev/mmcblk2 < $RESOURCES/mmc_type2.partmap || true
285+
sfdisk $dev < $RESOURCES/mmc_type2.partmap || true
262286
else
263287
echo ERROR! Not a known EMMC type, please open an issue on github or send SolidHal an email with the Total disk size reported above
264288
echo Try a fallback value? This will allow installation to continue, at the cost of a very small amount of disk space. This may not work.
@@ -267,7 +291,7 @@ emmc_partition() {
267291
case $yn,$REPLY in
268292
Yes,*|*,Yes )
269293
echo Trying Emmc Type 2
270-
sfdisk /dev/mmcblk2 < $RESOURCES/mmc_type2.partmap || true
294+
sfdisk $dev < $RESOURCES/mmc_type2.partmap || true
271295
break
272296
;;
273297
* )
@@ -305,8 +329,6 @@ external_partition() {
305329

306330
#simply expand to fill the current boot device
307331
expand() {
308-
# need to strip the "p" if BOOT_DEVICE is an sd card or emmc
309-
BOOT_DEVICE_NO_P=$(echo $BOOT_DEVICE | cut -d 'p' -f 1)
310332
if [[ $BOOT_DEVICE == "/dev/$(get_emmc_devname)" ]]
311333
then
312334
echo "Can't expand to fill internal emmc, install will have done this already"

0 commit comments

Comments
 (0)