Skip to content

Commit

Permalink
NTFS file system for MAIN partition
Browse files Browse the repository at this point in the history
  • Loading branch information
tiopex committed Dec 10, 2023
1 parent 2f89873 commit 9f5e16f
Show file tree
Hide file tree
Showing 15 changed files with 51 additions and 71 deletions.
4 changes: 0 additions & 4 deletions board/miyoo/boot/configs/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
! format: each line corresponds to one file to be copied over
! from_file(as_appears_in_this_directory) to_file(relative_to_root_of_main_partition)
! to_file is optional; if missing will use from_file
.backlight.conf
.volume.conf
.buttons.conf
.batterylow.conf
gmenu2x.conf gmenu2x/gmenu2x.conf
input.conf gmenu2x/input.conf
! leave this last line here
39 changes: 14 additions & 25 deletions board/miyoo/boot/firstboot
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ P4_SIZE=$(cat "/sys/block/mmcblk0/mmcblk0p4/size")
SD_SIZE_IN_MiB=$((SD_SIZE * 512 / 1024 / 1024))
SD_SIZE_IN_GiB=$((SD_SIZE * 512 / 1024 / 1024 / 1024))
BOOT_SIZE=$(((1016+1) * 1024 / 512)) #bootloader partition=1016K (see `genimage` script in buildroot)
## boot_size calculated to 512 byte sector size blocks, adding +1K as a safety measure for roundups (at fatresize we use KibiBits)
## boot_size calculated to 512 byte sector size blocks, adding +1K as a safety measure for roundups (at ntfsresize we use KibiBits)

#Calculate unallocated left space to expand MAIN:
SD_MAX_UNALL_SIZE="$((${SD_SIZE} - (${P1_SIZE} + ${P2_SIZE} + ${P3_SIZE} + ${P4_SIZE}) - $BOOT_SIZE))"
Expand All @@ -514,25 +514,14 @@ SD_MAX_UNALL_SIZE_IN_GiB=$(echo "scale=1; ${SD_MAX_UNALL_SIZE} * 512 / 1024 / 10
SD_MAX_AVAIL_SIZE="$((${SD_SIZE} - (${P1_SIZE} + ${P2_SIZE} + ${P3_SIZE}) - $BOOT_SIZE))"
SD_MAX_AVAIL_SIZE_IN_KiB=$((SD_MAX_AVAIL_SIZE * 512 / 1024))

# Expand_MAIN_Partition-prompt for fatresize the p4 partition if requested
# Expand_MAIN_Partition-prompt for ntfsresize the p4 partition if requested
RESIZE_COMMENCED=false
if (dialog --clear --stdout --ok-label YES --cancel-label NO --title " AUTO-RESIZE" \
--colors --pause "\n\n \ZuExpand MAIN partition?\Zn\n\n Select an option & press START
\n\n \ZbWARNING:\Zn\n After 10s auto-resize\n of FAT32 partition will begin." 15 60 10); then
\n\n \ZbWARNING:\Zn\n After 10s auto-resize\n of NTFS partition will begin." 15 60 10); then
clear
RESIZE_ABORT=false
if test "$SD_SIZE_IN_GiB" -gt 128; then
if (dialog --clear --stdout --ok-label NO --cancel-label YES --title " \Zb\Z1WARNING!\Zn" \
--colors --pause "\nYour SD card exceeds max. size for auto-resizing!
\n\nWe could however expand it to 118GB. \n\n \ZuDo you AGREE?\Zn
\n\n\ZbINFO: For microSD >128GB big we\n recommend to use your PC!\Zn" 0 0 30 || test $? -eq 255); then
dialog --clear --colors --timeout 2 --msgbox " FAT resizing \ZuABORTED!\Zn" 5 27
clear
RESIZE_ABORT=true
else
SD_MAX_AVAIL_SIZE_IN_KiB=123731968
fi
fi

SD_MAX_AVAIL_SIZE_IN_GiB=$(echo "scale=1; ${SD_MAX_AVAIL_SIZE_IN_KiB} / 1024 / 1024" | bc) #only to inform user about end point for resize
SD_MAX_AVAIL_SIZE_IN_GB=$(echo "scale=1; ${SD_MAX_AVAIL_SIZE_IN_KiB} * 1024 / 1000 / 1000 / 1000" | bc)
P4_SIZE_IN_GB=$(echo "scale=1; ${P4_SIZE} * 512 / 1000 / 1000 / 1000" | bc)
Expand All @@ -550,17 +539,19 @@ if (dialog --clear --stdout --ok-label YES --cancel-label NO --title " AUTO-RE
echo "and more precisely it's ${SD_MAX_UNALL_SIZE_IN_MiB}MB big" | tee -a ${LOG}
if ! $RESIZE_ABORT; then
echo "Resizing the MAIN partition to ${SD_MAX_AVAIL_SIZE_IN_GiB}GB." | tee -a ${LOG}
echo "This can take A LONG TIME, so be patient." | tee -a ${LOG}
echo "This can take few seconds." | tee -a ${LOG}
umount /dev/mmcblk0p4 | tee -a ${LOG}
fsck.fat -y /dev/mmcblk0p4 | tee -a ${LOG}
#TODO: fix outputting logs from fatresize stdout
fatresize --size="${SD_MAX_AVAIL_SIZE_IN_KiB}"ki -v -p /dev/mmcblk0p4 -n4 | tee -a ${LOG}
fsck.fat -y /dev/mmcblk0p4 | tee -a ${LOG}
ntfsfix -d /dev/mmcblk0p4 | tee -a ${LOG}
parted -a optimal /dev/mmcblk0 --script rm 4 | tee -a ${LOG}
parted -a optimal /dev/mmcblk0 --script mkpart primary ntfs 546MB 100% | tee -a ${LOG}
partx -u /dev/mmcblk0 | tee -a ${LOG}
echo Y | ntfsresize --size="${SD_MAX_AVAIL_SIZE_IN_KiB}"k -v /dev/mmcblk0p4 | tee -a ${LOG}
ntfsfix -d /dev/mmcblk0p4 | tee -a ${LOG}
echo -n -e \\xEB\\x58\\x90 > /dev/mmcblk0p4
sync
mount -t vfat -o rw,sync,utf8 /dev/mmcblk0p4 ${HOME} | tee -a ${LOG}
mount -t ntfs3 /dev/mmcblk0p4 ${HOME} | tee -a ${LOG}
else
echo "MAIN fat partition resizing was aborted!" | tee -a ${LOG}
echo "MAIN ntfs partition resizing was aborted!" | tee -a ${LOG}
sleep 2
fi
RESIZE_COMMENCED=true
Expand Down Expand Up @@ -599,8 +590,6 @@ if test -r "${BASEDIR}/configs/manifest"; then
fi
done
fi
echo "Renaming ${HOME}/retroarch directory to ${HOME}/.retroarch" | tee -a ${LOG}
mv "${HOME}/retroarch" "${HOME}/.retroarch" | tee -a ${LOG}

echo

Expand All @@ -610,7 +599,7 @@ touch ${HOME}/firstboot.completed
echo

# Reboot device if CONSOLE_VARIANT was overwritten from $CHOICE so that it could be applied in u-boot by readID
## or resizing FAT partition has completed / found firstboot custom script
## or resizing NTFS partition has completed / found firstboot custom script
if ($CONSOLE_OVERWRITE || $RESIZE_COMMENCED || test -r "${BASEDIR}/firstboot.custom.sh"); then
safe_reboot_func
else
Expand Down
23 changes: 2 additions & 21 deletions board/miyoo/genimage-sdcard.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,10 @@ image bootfs.vfat {
file configs/manifest {
image = "boot/configs/manifest"
}
file configs/.volume.conf {
image = "boot/configs/.volume.conf"
}
file configs/.buttons.conf {
image = "boot/configs/.buttons.conf"
}
file configs/.batterylow.conf {
image = "boot/configs/.batterylow.conf"
}
file configs/.backlight.conf {
image = "boot/configs/.backlight.conf"
}
}
size = 8M
}

image mainfs.vfat {
vfat {
label = "MAIN"
}
mountpoint = "../../../images/main/"
size = 640M
}


image ${IMAGE_NAME:-miyoo-cfw-2.0.0.img} {
Expand Down Expand Up @@ -70,8 +51,8 @@ image ${IMAGE_NAME:-miyoo-cfw-2.0.0.img} {
}

partition main {
partition-type = 0xc
partition-type = 0x7
bootable = "false"
image = "mainfs.vfat"
image = "main.img"
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 0 additions & 12 deletions board/miyoo/main/apps/fsck/fsck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,6 @@ echo -e "\e[32mChecking FAT32 (BOOT) partition...\e[0m"
fsck.vfat -a /dev/mmcblk0p1
fi

if dmesg | grep "mmcblk0p4"; then
echo -e "\e[31mUnclean shutdown detected.\e[0m"
echo -e "\e[32mChecking FAT32 (MAIN) partition...\e[0m"
fsck.vfat -a /dev/mmcblk0p4
echo " "
echo "Rebooting device, please wait..."
echo " "
sleep 2
sync
reboot
fi

echo "Finished!"
echo " "
echo " "
Expand Down
2 changes: 1 addition & 1 deletion board/miyoo/main/options.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
MODULES_CUSTOM=0
FAT_CHECK=1
NTFS_CHECK=1
BOOT_LOGO=1
FLIP= (put 0 or 1 to overwrite)
INVERT= (put 0 or 1 to overwrite)
Expand Down
2 changes: 1 addition & 1 deletion board/miyoo/rootfs/etc/inittab
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
::sysinit:/bin/mkdir -p /dev/shm
::sysinit:/bin/mount -a
::sysinit:/bin/hostname -F /etc/hostname
::sysinit:/bin/mount /dev/mmcblk0p4 /mnt -t vfat -o rw,sync,utf8
::sysinit:/bin/mount /dev/mmcblk0p4 /mnt -t ntfs3
::sysinit:/bin/mount /dev/mmcblk0p1 /boot -t vfat -o ro,exec,sync,utf8
::sysinit:/sbin/mkswap /dev/mmcblk0p3
::sysinit:/sbin/swapon /dev/mmcblk0p3
Expand Down
15 changes: 9 additions & 6 deletions board/miyoo/rootfs/etc/main
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,17 @@ elif test -r "${HOME}/firstboot.completed"; then
rm "${HOME}/firstboot.completed"
fi

if !(grep -q FAT_CHECK\=\0 "${HOME}/options.cfg"); then
##Check if fat32 is flagged as "dirty", and if so unmount, repair, remount
if !(grep -q NTFS_CHECK\=\0 "${HOME}/options.cfg"); then
##Check if ntfs is flagged as "dirty", and if so unmount, repair, remount
if dmesg | grep "mmcblk0p4" > /dev/null; then
echo -e "\e[31mUnclean shutdown detected.\e[0m"
echo -e "\e[32mChecking FAT32 partition...\e[0m"
umount /dev/mmcblk0p4
fsck.vfat -y /dev/mmcblk0p4 > /dev/null;
mount /dev/mmcblk0p4 "${HOME}" -t vfat -o rw,sync,utf8
echo -e "\e[32mChecking NTFS partition...\e[0m"
ntfsfix -d /dev/mmcblk0p4 > /dev/null;
mount /dev/mmcblk0p4 "${HOME}" -t ntfs3
if [ $? -ne 0 ]; then
sync
reboot
fi
echo -e "\e[32mCheck complete.\e[0m"
fi
fi
Expand Down
5 changes: 4 additions & 1 deletion board/miyoo/scripts/genimage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ cp -r board/miyoo/main "${BINARIES_DIR}"
test -d "${BINARIES_DIR}/gmenu2x" && cp -r "${BINARIES_DIR}/gmenu2x/" "${BINARIES_DIR}/main/"
test -d "${BINARIES_DIR}/emus" && cp -r "${BINARIES_DIR}/emus/" "${BINARIES_DIR}/main/"
if test -d "${BINARIES_DIR}/retroarch";then
cp -r "${BINARIES_DIR}/retroarch/" "${BINARIES_DIR}/main/"
rsync -avzh "${BINARIES_DIR}/retroarch/" "${BINARIES_DIR}/main/.retroarch/"
## Generate list of cores to be used
CORES_DIR="${BINARIES_DIR}/retroarch/cores"
for file in $CORES_DIR/*; do
Expand Down Expand Up @@ -47,4 +47,7 @@ fi
# Write CFW version to splash image
convert board/miyoo/miyoo-boot.png -pointsize 12 -fill white -annotate +10+230 "v${CFW_RELEASE} ${CFW_VERSION} (${LIBC}) ${STATUS}" -alpha off -type truecolor -strip -define bmp:format=bmp4 -define bmp:subtype=RGB565 "${BINARIES_DIR}"/boot/miyoo-boot.bmp

# Generate MAIN NTFS partition
board/miyoo/scripts/ntfs.sh

support/scripts/genimage.sh ${1} -c board/miyoo/genimage-sdcard.cfg
14 changes: 14 additions & 0 deletions board/miyoo/scripts/ntfs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

image="${BINARIES_DIR}/main.img"
label="MAIN"
mntdir=`mktemp -d`

dd status=progress if=/dev/zero of=$image bs=5M count=128 && sync

LOOPMOUNT=`sudo losetup --show --find ${image}`
mkfs.btrfs -v -L ${label} ${image}
sudo mount ${LOOPMOUNT} ${mntdir}
rsync -avzh "${BINARIES_DIR}/main/" ${mntdir}
sudo umount ${mntdir}
sudo losetup -d ${LOOPMOUNT}
3 changes: 3 additions & 0 deletions configs/miyoo_musl_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ BR2_PACKAGE_DOSFSTOOLS=y
BR2_PACKAGE_DOSFSTOOLS_FATLABEL=y
BR2_PACKAGE_DOSFSTOOLS_FSCK_FAT=y
BR2_PACKAGE_DOSFSTOOLS_MKFS_FAT=y
BR2_PACKAGE_NTFS_3G=y
BR2_PACKAGE_NTFS_3G_NTFSPROGS=y
BR2_PACKAGE_FATRESIZE=y
BR2_PACKAGE_RETROARCH=y
BR2_PACKAGE_LIBRETRO_CORE_INFO=y
Expand Down Expand Up @@ -228,6 +230,7 @@ BR2_PACKAGE_OPKG=y
BR2_PACKAGE_OPKG_UTILS=y
BR2_PACKAGE_DIALOG=y
BR2_PACKAGE_UTIL_LINUX_LIBMOUNT=y
BR2_PACKAGE_UTIL_LINUX_PARTX=y
BR2_PACKAGE_NANO=y
BR2_TARGET_ROOTFS_EXT2=y
BR2_TARGET_ROOTFS_EXT2_4=y
Expand Down
3 changes: 3 additions & 0 deletions configs/miyoo_uclibc_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ BR2_PACKAGE_DOSFSTOOLS=y
BR2_PACKAGE_DOSFSTOOLS_FATLABEL=y
BR2_PACKAGE_DOSFSTOOLS_FSCK_FAT=y
BR2_PACKAGE_DOSFSTOOLS_MKFS_FAT=y
BR2_PACKAGE_NTFS_3G=y
BR2_PACKAGE_NTFS_3G_NTFSPROGS=y
BR2_PACKAGE_FATRESIZE=y
BR2_PACKAGE_RETROARCH=y
BR2_PACKAGE_LIBRETRO_CORE_INFO=y
Expand Down Expand Up @@ -205,6 +207,7 @@ BR2_PACKAGE_OPKG=y
BR2_PACKAGE_OPKG_UTILS=y
BR2_PACKAGE_DIALOG=y
BR2_PACKAGE_UTIL_LINUX_LIBMOUNT=y
BR2_PACKAGE_UTIL_LINUX_PARTX=y
BR2_PACKAGE_NANO=y
BR2_TARGET_ROOTFS_EXT2=y
BR2_TARGET_ROOTFS_EXT2_4=y
Expand Down

0 comments on commit 9f5e16f

Please sign in to comment.