Skip to content

Commit

Permalink
BTRFS file system for MAIN partition
Browse files Browse the repository at this point in the history
  • Loading branch information
tiopex committed Dec 11, 2023
1 parent 2f89873 commit 8c55071
Show file tree
Hide file tree
Showing 33 changed files with 139 additions and 170 deletions.
11 changes: 0 additions & 11 deletions board/miyoo/boot/configs/manifest

This file was deleted.

103 changes: 14 additions & 89 deletions board/miyoo/boot/firstboot
Original file line number Diff line number Diff line change
Expand Up @@ -493,76 +493,19 @@ if (dialog --clear --ok-label NO --cancel-label YES --stdout --title " License
safe_poweroff_func
fi
mount -o remount,ro "${MOUNTDIR}" | tee -a ${LOG}

#grep all partitions current size
SD_SIZE=$(cat "/sys/block/mmcblk0/size")
P1_SIZE=$(cat "/sys/block/mmcblk0/mmcblk0p1/size")
P2_SIZE=$(cat "/sys/block/mmcblk0/mmcblk0p2/size")
P3_SIZE=$(cat "/sys/block/mmcblk0/mmcblk0p3/size")
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)

#Calculate unallocated left space to expand MAIN:
SD_MAX_UNALL_SIZE="$((${SD_SIZE} - (${P1_SIZE} + ${P2_SIZE} + ${P3_SIZE} + ${P4_SIZE}) - $BOOT_SIZE))"
SD_MAX_UNALL_SIZE_IN_MiB=$((SD_MAX_UNALL_SIZE * 512 / 1024 / 1024))
SD_MAX_UNALL_SIZE_IN_GiB=$(echo "scale=1; ${SD_MAX_UNALL_SIZE} * 512 / 1024 / 1024 / 1024" | bc)

#Calculate available space for 4'th partition (MAIN):
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
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 BTRFS 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)
# roundup GB value to 0,1GB for integer calculations:
SD_MAX_AVAIL_SIZE_IN_GBx10=$(echo "$SD_MAX_AVAIL_SIZE_IN_GB" | tr -d ".")
P4_SIZE_IN_GBx10=$(echo "$P4_SIZE_IN_GB" | tr -d ".")
#Sanity checks if we don't down- or over-resize partition:
if (test "$P4_SIZE_IN_GBx10" -ge "$SD_MAX_AVAIL_SIZE_IN_GBx10" || test "$SD_MAX_UNALL_SIZE_IN_MiB" -le 15); then
echo "Your MAIN partition is greater than available space for resizing or you lack unallocated sectors space" | tee -a ${LOG}
sleep 1.5
RESIZE_ABORT=true
fi
echo "The full size of your SD is ${SD_SIZE_IN_MiB}MB large" | tee -a ${LOG}
echo "Unallocated space available for resizing equals ${SD_MAX_UNALL_SIZE_IN_GiB}GB," | tee -a ${LOG}
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}
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}
echo -n -e \\xEB\\x58\\x90 > /dev/mmcblk0p4
sync
mount -t vfat -o rw,sync,utf8 /dev/mmcblk0p4 ${HOME} | tee -a ${LOG}
else
echo "MAIN fat partition resizing was aborted!" | tee -a ${LOG}
sleep 2
fi
echo "Resizing the MAIN partition." | tee -a ${LOG}
echo "This can take few seconds." | tee -a ${LOG}
umount /dev/mmcblk0p4 | tee -a ${LOG}
parted -a optimal /dev/mmcblk0 --script rm 4 | tee -a ${LOG}
parted -a optimal /dev/mmcblk0 --script mkpart primary 546MB 100% | tee -a ${LOG}
partx -u /dev/mmcblk0 | tee -a ${LOG}
mount /dev/mmcblk0p4 ${HOME} | tee -a ${LOG}
btrfs filesystem resize max ${HOME}
RESIZE_COMMENCED=true
fi

Expand All @@ -577,40 +520,22 @@ mv "${MOUNTDIR}/firstboot" "${MOUNTDIR}/firstboot.done" | tee -a ${LOG}
# copy over the config files
echo "Copying default configuration files into place..." | tee -a ${LOG}
if $BITTBOY_CONFIG; then
cp "${HOME}/gmenu2x/input_bittboy.conf" "${MOUNTDIR}/configs/input.conf"
cp "${HOME}/gmenu2x/input_bittboy.conf" "${HOME}/gmenu2x/input.conf"
elif $MIYOO_CONFIG; then
cp "${HOME}/gmenu2x/input_miyoo.conf" "${MOUNTDIR}/configs/input.conf"
cp "${HOME}/gmenu2x/input_miyoo.conf" "${HOME}/gmenu2x/input.conf"
fi
mount -o remount,ro "${MOUNTDIR}" | tee -a ${LOG}
if test -r "${BASEDIR}/configs/manifest"; then
cat "${BASEDIR}/configs/manifest" | while read -r LINE; do
if test "${LINE}" == "${LINE#!}" -a "${LINE}" != "" ; then
set -- ${LINE}
# 1 2
# source_filename target_filename/inside main/
if test -r "${BASEDIR}/configs/$1"; then
TO="$2"
if test "${TO}" == ""; then
TO="$1"
fi
echo "Copying $1 to ${HOME}/$TO..." | tee -a ${LOG}
cp -f "${BASEDIR}/configs/$1" "${HOME}/$TO" | tee -a ${LOG}
fi
fi
done
fi
echo "Renaming ${HOME}/retroarch directory to ${HOME}/.retroarch" | tee -a ${LOG}
mv "${HOME}/retroarch" "${HOME}/.retroarch" | tee -a ${LOG}

echo
echo "fix permsissions" | tee -a ${LOG}
chmod -R +x /mnt/ | tee -a ${LOG}

sync
echo "firstboot script finished." | tee -a ${LOG}
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 BTRFS 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
26 changes: 2 additions & 24 deletions board/miyoo/genimage-sdcard.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,10 @@ image bootfs.vfat {
"boot/modules.custom.sh",
"boot/normalboot.custom.sh",
}
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 +48,8 @@ image ${IMAGE_NAME:-miyoo-cfw-2.0.0.img} {
}

partition main {
partition-type = 0xc
partition-type = 0x83
bootable = "false"
image = "mainfs.vfat"
image = "main.img"
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file modified board/miyoo/main/apps/arecord/audio_record.sh
100644 → 100755
Empty file.
Empty file modified board/miyoo/main/apps/ffmpeg/ffplay.man.txt
100644 → 100755
Empty file.
Empty file modified board/miyoo/main/apps/ffmpeg/ffplay_launch.sh
100644 → 100755
Empty file.
Empty file modified board/miyoo/main/apps/ffmpeg/video_record.sh
100644 → 100755
Empty file.
12 changes: 0 additions & 12 deletions board/miyoo/main/apps/fsck/fsck.sh
100644 → 100755
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
Empty file modified board/miyoo/main/apps/joymap/input_info.sh
100644 → 100755
Empty file.
Empty file modified board/miyoo/main/apps/joymap/joymap.sh
100644 → 100755
Empty file.
Empty file modified board/miyoo/main/apps/tvout/tvout.sh
100644 → 100755
Empty file.
Empty file modified board/miyoo/main/apps/usb-hid/usb-hid.man.txt
100644 → 100755
Empty file.
Empty file modified board/miyoo/main/apps/usb-hid/usb-hid.py
100644 → 100755
Empty file.
15 changes: 4 additions & 11 deletions board/miyoo/main/apps/usb-hid/usb-hid.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,13 @@ st_error_func(){
st_exec_func(){
st -k -e "/bin/sh" "-c" "${1}"
}

MUSB_MODE=$(cat /sys/devices/platform/soc/1c13000.usb/musb-hdrc.1.auto/mode)
if ! (test "${MUSB_MODE}" = "b_peripheral"); then
st_error_func "\n\n\n\n\n\n\n\n First connect handheld to device!"
exit
else
gadget-vid-pid-remove 0x1d6b:0x0104
killall umtprd
modprobe -r g_serial
mount none /sys/kernel/config -t configfs
gadget-hid

st_exec_func "\
echo -e \"\e[32m\n\n\n\n\n\n Starting USB-HID mode\e[0m\n\n\n\"; \
sleep 1; \
python /mnt/apps/usb-hid/usb-hid.py"

gadget-vid-pid-remove 0x1d6b:0x0104
gadget-ms /dev/mmcblk0p1 /dev/mmcblk0p4
fi
gadget-vid-pid-remove 0x1d6b:0x0104
Empty file modified board/miyoo/main/apps/usb-host/usb-host.sh
100644 → 100755
Empty file.
5 changes: 5 additions & 0 deletions board/miyoo/main/apps/usb-mtd/usb-mtd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/busybox sh

modprobe -r g_serial
killall umtprd
umtprd &
File renamed without changes.
3 changes: 3 additions & 0 deletions board/miyoo/main/apps/usb-serial-console/usb-serial.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/busybox sh
killall umtprd
modprobe g_serial
3 changes: 3 additions & 0 deletions board/miyoo/main/gmenu2x/sections/applications/usb-mtd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
title=USB MTD
description=USB MTD mass storage
exec=/mnt/apps/usb-mtd/usb-mtd.sh
3 changes: 3 additions & 0 deletions board/miyoo/main/gmenu2x/sections/applications/usb-peripheral
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
title=USB peripheral
description=USB peripheral mode
exec=/mnt/apps/usb-peripheral/usb-peripheral.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
title=USB serial console
description=USB Serial console
exec=/mnt/apps/usb-serial-console/usb-serial.sh

This file was deleted.

1 change: 0 additions & 1 deletion board/miyoo/main/options.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
MODULES_CUSTOM=0
FAT_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 -o discard=async,noatime,nodiratime,exec
::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
20 changes: 3 additions & 17 deletions board/miyoo/rootfs/etc/main
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ fi
# load kernel modules

# load usb gadget
mount -t configfs none /sys/kernel/config >> "${LOGS}" 2>&1
gadget-ms /dev/mmcblk0p1 /dev/mmcblk0p4 >> "${LOGS}" 2>&1

modprobe g_ffs idVendor=0x1D6B iSerialNumber=01234567 functions=mtp >> "${LOGS}" 2>&1
mkdir /dev/ffs-mtp && mount -t functionfs mtp /dev/ffs-mtp >> "${LOGS}" 2>&1
umtprd >> "${LOGS}" 2>&1 &

# Load the expected one screen driver from here with modprobe
## automatically from rootfs/lib/modules/VERSION
Expand Down Expand Up @@ -76,20 +76,6 @@ 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 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[32mCheck complete.\e[0m"
fi
fi

clear

# try to read what handheld we're on
if test -r "${BOOTDIR}/console.cfg"; then
source "${BOOTDIR}/console.cfg"
Expand Down
88 changes: 88 additions & 0 deletions board/miyoo/rootfs/etc/umtprd/umtprd.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#
# uMTP Responder config file
# Must be copied to /etc/umtprd/umtprd.conf
#

# Loop / daemon mode
# Set to 1 to don't shutdown uMTPrd when the link is disconnected.

loop_on_disconnect 1

#storage command : Create add a storage entry point. Up to 16 entry points supported
#Syntax : storage "PATH" "NAME"

storage "/" "rootfs" "ro"
storage "/mnt" "MAIN" "rw"
storage "/boot" "BOOT" "ro"

#
# Uncomment the following line if you want to
# override the system default umask value for
# the uploaded files.
#

umask 000

# Set the USB manufacturer string

manufacturer "MIyoo CFW 2.0"

# Set the USB Product string

product "handheld"

# Set the USB Serial number string

serial "01234567"

# Set the USB interface string. Should be always "MTP"

interface "MTP"

# Set the USB Vendor ID, Product ID and class

usb_vendor_id 0x1D6B # Linux Foundation
usb_product_id 0x0100 # PTP Gadget
usb_class 0x6 # Image
usb_subclass 0x1 # Still Imaging device
usb_protocol 0x1 #

# Device version

usb_dev_version 0x3008

# inotify support
# If you want disable the events support (beta), uncomment the following line :

# no_inotify 0x1

#
# Internal buffers size
#

# Internal default usb_max_rd_buffer_size and usb_max_wr_buffer_size value set to 0x10000.
# Internal default read_buffer_cache_size value set to 0x100000.
# Uncomment the following lines to reduce the buffers sizes to fix USB issues on iMX6 based systems.

usb_max_rd_buffer_size 0x10000 # MAX usb read size. Must be a multiple of 512 and be less than read_buffer_cache_size
usb_max_wr_buffer_size 0x10000 # MAX usb write size. Must be a multiple of 512.
read_buffer_cache_size 0x80000 # Read file cache buffer. Must be a 2^x value.

#
# USB gadget device driver path
#

########################################################################
#
# -- Generic FunctionFS Mode --
#
########################################################################

usb_functionfs_mode 0x1

usb_dev_path "/dev/ffs-mtp/ep0"
usb_epin_path "/dev/ffs-mtp/ep1"
usb_epout_path "/dev/ffs-mtp/ep2"
usb_epint_path "/dev/ffs-mtp/ep3"

usb_max_packet_size 0x200
Loading

0 comments on commit 8c55071

Please sign in to comment.