From 6b1ec115abf096c6ea96833b0bb9efed45410e1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Kelemen=20=28vudiq=29?= Date: Sun, 12 Feb 2023 00:09:13 +0100 Subject: [PATCH 1/5] busybox: fs-resize: create exFAT partition many users request a partition, that is also accessible on operating system, that does not natively support ext4 system, to be able transfer their game files to the storage device (see #646). by reducing the size of the ext4 partition (which mostly stores configuration and setting files) to roughly 2GiB, the remaining space of the storage device can be used as exFAT partition, which is accessible on most (if not all) operating systems. the partition is mounted by udevil to /storage/roms/EXFAT. if for some reason the size of the first (FAT32) partition will be increased in the future, then also the value (4GiB) for the end of the ext4 partition needs to be adjusted. this does not break existing installations of Lakka, but it also does not add the partition to existing installation of Lakka. the partition is created only on the first boot of the freshly flashed image. --- packages/sysutils/busybox/scripts/fs-resize | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/packages/sysutils/busybox/scripts/fs-resize b/packages/sysutils/busybox/scripts/fs-resize index 6be1d3e6efb..69db2defe61 100755 --- a/packages/sysutils/busybox/scripts/fs-resize +++ b/packages/sysutils/busybox/scripts/fs-resize @@ -25,9 +25,11 @@ if [ -e /storage/.please_resize_me ] ; then case $PART in "/dev/mmcblk"*) DISK=$(echo $PART | sed s/p2$//g) + EXPART="${DISK}p3" ;; *) DISK=$(echo $PART | sed s/2$//g) + EXPART="${DISK}3" ;; esac @@ -46,13 +48,20 @@ if [ -e /storage/.please_resize_me ] ; then # identify the partition scheme, and if gpt fix minor issues such as gpt header not at end of disk SCHEME=$(blkid -s PTTYPE -o value $DISK) if [ "$SCHEME" = "gpt" ]; then - StartProgress spinner "Checking layout... " "sgdisk -e $DISK &>/dev/null" + StartProgress spinner "Checking layout... " "sgdisk -e $DISK &>/dev/null" + EXPARTTYPE="'EXFAT'" + else + EXPARTTYPE="primary" fi - StartProgress spinner "Resizing partition... " "parted -s -m $DISK resizepart 2 100% &>/dev/null" - StartProgress spinner "Checking file system... " "e2fsck -f -p $PART &>/dev/null" - StartProgress spinner "Resizing file system... " "resize2fs $PART &>/dev/null" - StartProgress countdown "Rebooting in 15s... " 15 "NOW" + StartProgress spinner "Resizing ext4 partition... " "parted -s -m $DISK resizepart 2 4GiB &>/dev/null" + StartProgress spinner "Checking file system... " "e2fsck -f -p $PART &>/dev/null" + StartProgress spinner "Resizing file system... " "resize2fs $PART &>/dev/null" + EXSTART="$(( $(parted -m ${DISK} print all | grep -m1 ^2: | awk 'BEGIN {FS=":"} {gsub ("[A-Z]",""); print $3}') + 17 ))" + StartProgress spinner "Creating exFAT partition... " "parted -s -m ${DISK} mkpart ${EXPARTTYPE} ntfs ${EXSTART}MB 100% &>/dev/null" + partprobe &>/dev/null + StartProgress spinner "Formatting exFAT partition... " "mkfs.exfat -f -L EXFAT ${EXPART} &>/dev/null" + StartProgress countdown "Rebooting in 15s... " 15 "NOW" fi fi reboot -f &>/dev/null From db854626a6cf9e9dba31c92aac20bc239caa91ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Kelemen=20=28vudiq=29?= Date: Sun, 12 Feb 2023 15:43:34 +0100 Subject: [PATCH 2/5] busybox: fs-resize: make exFAT partition optional the exFAT partition will be created only in case the user adds a file called `create_exfat` in the root of the first (FAT32) partition. so the original (no exFAT partition) behavior is default. --- packages/sysutils/busybox/scripts/fs-resize | 22 ++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/packages/sysutils/busybox/scripts/fs-resize b/packages/sysutils/busybox/scripts/fs-resize index 69db2defe61..5fca3263341 100755 --- a/packages/sysutils/busybox/scripts/fs-resize +++ b/packages/sysutils/busybox/scripts/fs-resize @@ -54,13 +54,21 @@ if [ -e /storage/.please_resize_me ] ; then EXPARTTYPE="primary" fi - StartProgress spinner "Resizing ext4 partition... " "parted -s -m $DISK resizepart 2 4GiB &>/dev/null" - StartProgress spinner "Checking file system... " "e2fsck -f -p $PART &>/dev/null" - StartProgress spinner "Resizing file system... " "resize2fs $PART &>/dev/null" - EXSTART="$(( $(parted -m ${DISK} print all | grep -m1 ^2: | awk 'BEGIN {FS=":"} {gsub ("[A-Z]",""); print $3}') + 17 ))" - StartProgress spinner "Creating exFAT partition... " "parted -s -m ${DISK} mkpart ${EXPARTTYPE} ntfs ${EXSTART}MB 100% &>/dev/null" - partprobe &>/dev/null - StartProgress spinner "Formatting exFAT partition... " "mkfs.exfat -f -L EXFAT ${EXPART} &>/dev/null" + if [ -e /flash/create_exfat ] ; then + StartProgress spinner "Getting disk information... " "parted -s -f -m $DISK print all &>/dev/null" + StartProgress spinner "Resizing ext4 partition... " "parted -s -m $DISK resizepart 2 4GiB &>/dev/null" + StartProgress spinner "Checking file system... " "e2fsck -f -p $PART &>/dev/null" + StartProgress spinner "Resizing file system... " "resize2fs $PART &>/dev/null" + StartProgress spinner "Updating disk information... " "parted -s -f -m $DISK print all &>/dev/null" + EXSTART="$(( $(parted -s -f -m $DISK print all 2>/dev/null | grep -m1 ^2: | cut -d: -f3 | sed -e s/MB//) + 17 ))" + StartProgress spinner "Creating exFAT partition... " "parted -s -f -m $DISK mkpart $EXPARTTYPE ntfs ${EXSTART}MB 100% &>/dev/null" + StartProgress spinner "Probing partitions... " "partprobe &>/dev/null" + StartProgress spinner "Formatting exFAT partition... " "mkfs.exfat -f -L EXFAT $EXPART &>/dev/null" + else + StartProgress spinner "Resizing ext4 partition... " "parted -s -m $DISK resizepart 2 100% &>/dev/null" + StartProgress spinner "Checking file system... " "e2fsck -f -p $PART &>/dev/null" + StartProgress spinner "Resizing file system... " "resize2fs $PART &>/dev/null" + fi StartProgress countdown "Rebooting in 15s... " 15 "NOW" fi fi From 6b5a5397c8798643a98ca1228cf1f18564226da4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Kelemen=20=28vudiq=29?= Date: Sun, 12 Feb 2023 15:45:23 +0100 Subject: [PATCH 3/5] retroarch: copy bios files from exFAT partition to avoid any folder remapping needs in RetroArch, user can create folder called `bios` in the root of the exFAT partition and place their bios files into this folder. during RetroArch startup this folder will be checked for any existing files/folder, copy them to the default location for system folder and back them up in folder `bios_copied` folder on the exFAT partition. a transfer log is created during this process to check for any failures. --- .../retroarch/scripts/retroarch-config | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/packages/lakka/retroarch_base/retroarch/scripts/retroarch-config b/packages/lakka/retroarch_base/retroarch/scripts/retroarch-config index de4e0615066..af2e7cbc35a 100755 --- a/packages/lakka/retroarch_base/retroarch/scripts/retroarch-config +++ b/packages/lakka/retroarch_base/retroarch/scripts/retroarch-config @@ -9,10 +9,26 @@ echo "LD_LIBRARY_PATH=\"/usr/lib:/tmp/cores\"" >> /run/libreelec/retroarch.conf # which makes the combined controller index 2, but on Nintendo Switch Lite, on first boot we need to change this to 1 # or built in gamepad needs user intervention to be used. -SERIAL_PREFIX=$(cat /sys/firmware/devicetree/base/serial-number) -SERIAL_PREFIX=${SERIAL_PREFIX:0:3} +if [ -e /sys/firmware/devicetree/base/serial-number ]; then + SERIAL_PREFIX="$(cat /sys/firmware/devicetree/base/serial-number)" + SERIAL_PREFIX="${SERIAL_PREFIX:0:3}" +else + SERIAL_PREFIX="" +fi -if [ ${SERIAL_PREFIX} = "NXV" -a ! -f /storage/.config/retroarch/retroarch.cfg ]; then +if [ "${SERIAL_PREFIX}" = "NXV" -a ! -f /storage/.config/retroarch/retroarch.cfg ]; then cp /etc/retroarch.cfg /storage/.config/retroarch/retroarch.cfg sed -i -e 's|input_player1_joypad_index = \"2\"|input_player1_joypad_index = \"0\"|' /storage/.config/retroarch/retroarch.cfg fi + +if [ -d /storage/roms/EXFAT/bios ]; then + for bios in /storage/roms/EXFAT/bios/* ; do + if [ -e "${bios}" ]; then + [ ! -d /storage/roms/EXFAT/bios_copied ] && mkdir -p /storage/roms/EXFAT/bios_copied + echo -n "Copy: " >> /storage/roms/EXFAT/bios/copied/transfer_log.txt + cp -vr "${bios}" /tmp/system >> /storage/roms/EXFAT/bios_copied/transfer_log.txt 2>&1 + echo -n "Backup: " >> /storage/roms/EXFAT/bios/copied/transfer_log.txt + mv -v "${bios}" /storage/roms/EXFAT/bios_copied >> /storage/roms/EXFAT/bios_copied/transfer_log.txt 2>&1 + fi + done +fi From 7fd2a02d8730577f3f019034d8b80c06b7270509 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Kelemen=20=28vudiq=29?= Date: Sun, 12 Feb 2023 15:53:11 +0100 Subject: [PATCH 4/5] mkimage: exFAT: create placeholder trigger for some users it might be challenging creating a blank file without an extension. this file can be renamed to 'create_exfat' after writing the image / BEFORE first boot, in order to create also an additional exFAT partition --- scripts/mkimage | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/mkimage b/scripts/mkimage index 68e5aa54418..312be3a081e 100755 --- a/scripts/mkimage +++ b/scripts/mkimage @@ -355,6 +355,12 @@ elif [ "${BOOTLOADER}" = "u-boot" ]; then exit fi # bootloader +if [ "${DISTRO}" = "Lakka" ];then + # create placeholder for exFAT partition trigger. + touch ${LE_TMP}/no_create_exfat + mcopy -s "${LE_TMP}/no_create_exfat" :: >"${SAVE_ERROR}" 2>&1 || show_error +fi + # run fsck echo "image: checking filesystem on part1..." sync From 6a30cf75250976f6a4dd5fe8b64eea3e6e09b945 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Kelemen=20=28vudiq=29?= Date: Sun, 12 Feb 2023 22:15:54 +0100 Subject: [PATCH 5/5] fs-resize: do not launch on Switch/Odin --- packages/sysutils/busybox/scripts/fs-resize | 39 +++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/packages/sysutils/busybox/scripts/fs-resize b/packages/sysutils/busybox/scripts/fs-resize index 5fca3263341..8ed256e5c3f 100755 --- a/packages/sysutils/busybox/scripts/fs-resize +++ b/packages/sysutils/busybox/scripts/fs-resize @@ -18,6 +18,45 @@ if [ -e /storage/.please_resize_me ] ; then reboot -f fi + # also not intended on Switch/Odin, which add fat32-boot to cmdline + FAT32_BOOT="no" + for arg in $(cat /proc/cmdline); do + case $arg in + fat32-boot) + FAT32_BOOT="yes" + ;; + *) + ;; + esac + done + + if [ "$FAT32_BOOT" = "yes" ]; then + rm -f /storage/.please_resize_me + sync + echo "Some Vogons" + echo " wanted to" + echo " destroy" + echo " your device." + echo "" + echo "" + echo " **** *** * * * *****" + echo " * * * * ** * * *" + echo " * * * * * * * *" + echo " * * * * * ** *" + echo " **** *** * * *" + echo "" + echo " **** *** * * *** ***" + echo " * * * * ** * * * *" + echo " **** ***** * * * * *" + echo " * * * * ** * * *" + echo " * * * * * *** ***" + echo "" + echo " and enjoy this cute little counter :-)" + echo "" + StartProgress countdown " " 42 "NOW" + reboot -f + fi + # get the disk. /storage on 2nd partition PART=$(grep "/storage " /proc/mounts | cut -d" " -f1 | grep '2$')