Skip to content

Commit

Permalink
fixed windows RAW sdcard, remove v4<>mm models changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ninoh-FOX committed Sep 26, 2024
1 parent 88dcc88 commit 26e7d21
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 76 deletions.
25 changes: 10 additions & 15 deletions base/.tmp_update/updater
Original file line number Diff line number Diff line change
Expand Up @@ -102,26 +102,36 @@ if [ ! -f "$SDCARD_PATH/RESIZED" ]; then

# Copiar fatresize y sus bibliotecas necesarias
echo "Copiando parted y dependencias..."
cp "$SDCARD_PATH/Koriki/bin/fdisk" $TMP_PATH/
cp "$SDCARD_PATH/Koriki/bin/fsck.fat" $TMP_PATH/
cp "$SDCARD_PATH/Koriki/bin/fatresize" $TMP_PATH/
cp "$SDCARD_PATH/Koriki/bin/parted" $TMP_PATH/
cp "$SDCARD_PATH/Koriki/bin/partprobe" $TMP_PATH/
cp "$SDCARD_PATH/Koriki/bin/show" $TMP_PATH/
cp "$SDCARD_PATH/Koriki/images/resize.png" $TMP_PATH/
chmod +x $TMP_PATH/fdisk
chmod +x $TMP_PATH/fsck.fat
chmod +x $TMP_PATH/fatresize
chmod +x $TMP_PATH/parted
chmod +x $TMP_PATH/partprobe
chmod +x $TMP_PATH/show
cp "$SDCARD_PATH/Koriki/lib/libfdisk.so.1" $TMP_LIB/
cp "$SDCARD_PATH/Koriki/lib/libsmartcols.so.1" $TMP_LIB/
cp "$SDCARD_PATH/Koriki/lib/libparted-fs-resize.so.0" $TMP_LIB/
cp "$SDCARD_PATH/Koriki/lib/libparted.so.2" $TMP_LIB/
cp "$SDCARD_PATH/Koriki/lib/libblkid.so.1" $TMP_LIB/
cp "$SDCARD_PATH/Koriki/lib/libuuid.so.1" $TMP_LIB/
cp "$SDCARD_PATH/Koriki/lib/libpng16.so.16" $TMP_LIB/
cp "$SDCARD_PATH/Koriki/lib/libncurses.so.6" $TMP_LIB/
cp "$SDCARD_PATH/Koriki/lib/libmsettings.so" $TMP_LIB/
chmod +x $TMP_LIB/libfdisk.so.1
chmod +x $TMP_LIB/libsmartcols.so.1
chmod +x $TMP_LIB/libparted-fs-resize.so.0
chmod +x $TMP_LIB/libparted.so.2
chmod +x $TMP_LIB/libblkid.so.1
chmod +x $TMP_LIB/libuuid.so.1
chmod +x $TMP_LIB/libpng16.so.16
chmod +x $TMP_LIB/libncurses.so.6
chmod +x $TMP_LIB/libmsettings.so


Expand Down Expand Up @@ -561,11 +571,6 @@ if [ ! -f /customer/app/axp_test ]; then
if [ ! -d "${RETROARCH_PATH}/.retroarch/overlay/.ATC_v4" ]; then
mv "${RETROARCH_PATH}"/.retroarch/overlay/ATC "${RETROARCH_PATH}"/.retroarch/overlay/.ATC_v4
mv "${RETROARCH_PATH}"/.retroarch/overlay/.ATC_v1 "${RETROARCH_PATH}"/.retroarch/overlay/ATC
if grep -q "filter = grid2x" "${RETROARCH_PATH}"/.retroarch/filters/video/Grid3x.filt; then
mv "${RETROARCH_PATH}"/.retroarch/filters/video/Grid3x.filt "${RETROARCH_PATH}"/.retroarch/filters/video/Grid0x.filt
mv "${RETROARCH_PATH}"/.retroarch/filters/video/Grid2x.filt "${RETROARCH_PATH}"/.retroarch/filters/video/Grid3x.filt
mv "${RETROARCH_PATH}"/.retroarch/filters/video/Grid0x.filt "${RETROARCH_PATH}"/.retroarch/filters/video/Grid2x.filt
fi
fi
sync
fi
Expand All @@ -588,11 +593,6 @@ if [ ! -f /customer/app/axp_test ]; then
if [ ! -d "${RETROARCH_PATH}/.retroarch/overlay/.ATC_v1" ]; then
mv "${RETROARCH_PATH}"/.retroarch/overlay/ATC "${RETROARCH_PATH}"/.retroarch/overlay/.ATC_v1
mv "${RETROARCH_PATH}"/.retroarch/overlay/.ATC_v4 "${RETROARCH_PATH}"/.retroarch/overlay/ATC
if grep -q "filter = grid3x" "${RETROARCH_PATH}"/.retroarch/filters/video/Grid3x.filt; then
mv "${RETROARCH_PATH}"/.retroarch/filters/video/Grid3x.filt "${RETROARCH_PATH}"/.retroarch/filters/video/Grid0x.filt
mv "${RETROARCH_PATH}"/.retroarch/filters/video/Grid2x.filt "${RETROARCH_PATH}"/.retroarch/filters/video/Grid3x.filt
mv "${RETROARCH_PATH}"/.retroarch/filters/video/Grid0x.filt "${RETROARCH_PATH}"/.retroarch/filters/video/Grid2x.filt
fi
fi
sync
fi
Expand Down Expand Up @@ -629,11 +629,6 @@ else
if [ ! -d "${RETROARCH_PATH}/.retroarch/overlay/.ATC_v4" ]; then
mv "${RETROARCH_PATH}"/.retroarch/overlay/ATC "${RETROARCH_PATH}"/.retroarch/overlay/.ATC_v4
mv "${RETROARCH_PATH}"/.retroarch/overlay/.ATC_v1 "${RETROARCH_PATH}"/.retroarch/overlay/ATC
if grep -q "filter = grid2x" "${RETROARCH_PATH}"/.retroarch/filters/video/Grid3x.filt; then
mv "${RETROARCH_PATH}"/.retroarch/filters/video/Grid3x.filt "${RETROARCH_PATH}"/.retroarch/filters/video/Grid0x.filt
mv "${RETROARCH_PATH}"/.retroarch/filters/video/Grid2x.filt "${RETROARCH_PATH}"/.retroarch/filters/video/Grid3x.filt
mv "${RETROARCH_PATH}"/.retroarch/filters/video/Grid0x.filt "${RETROARCH_PATH}"/.retroarch/filters/video/Grid2x.filt
fi
fi
sync
fi
Expand Down
Binary file modified base/Koriki/bin/fatresize
100644 → 100755
Binary file not shown.
Binary file added base/Koriki/bin/fdisk
Binary file not shown.
Binary file added base/Koriki/bin/fsck.fat
Binary file not shown.
101 changes: 41 additions & 60 deletions base/Koriki/bin/resize_partition
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -53,101 +53,82 @@ if [ "$0" = "/tmp/_resize_partition" ]; then
swapoff /mnt/SDCARD/cachefile 2>/dev/null
umount -r /mnt/SDCARD 2>/dev/null
umount /mnt/SDCARD 2>/dev/null
# Prepare the environment for running fatresize

# Prepare the environment for running fatresize
echo "Preparing environment for fatresize..."
export LD_LIBRARY_PATH=$TMP_LIB:/lib:/config/lib:/customer/lib:$LD_LIBRARY_PATH

$TMP_PATH/show $TMP_PATH/resize.png

# Ensure that the fatresize binary is executable
# Ensure that the fatresize binary is executable
chmod +x $TMP_PATH

$TMP_PATH/show $TMP_PATH/resize.png

sleep 5

# Show partition information before resizing
echo "Partition information before resizing:"
fdisk -l /dev/mmcblk0

$TMP_PATH/fdisk -l /dev/mmcblk0

# Extract size in GiB from fdisk and convert to KiB

TOTAL_GIB=$($TMP_PATH/fdisk -l /dev/mmcblk0 | grep "Disk /dev/mmcblk0" | awk '{print $3}')
TOTAL_KIB=$(awk "BEGIN {printf \"%d\", ( $TOTAL_GIB * 1024 * 1024 ) - 2}")

# Try resizing to max size automatically using parted
#echo "Attempting to resize the partition to max size using parted..."
#$TMP_PATH/parted /dev/mmcblk0 --script resizepart 1 100%
echo "Total size: $TOTAL_GIB GiB"
echo "Converted size: $TOTAL_KIB KiB"

$TMP_PATH/fatresize -f -v -s ${TOTAL_KIB}ki /dev/mmcblk0p1

echo "Attempting to resize the partition to max size..."
$TMP_PATH/fatresize -f -v -s max /dev/mmcblk0p1
$TMP_PATH/fsck.fat -a -v /dev/mmcblk0p1

$TMP_PATH/parted /dev/mmcblk0 --script resizepart 1 100%

# Check if parted was successful
# Check if the resize was successful
if [ $? -ne 0 ]; then
echo "Error resizing the partition with '100%'. Attempting manual resize..."

# Calculate the total size and starting sector manually
TOTAL_SECTORS=$(cat /sys/block/mmcblk0/size)
SECTOR_SIZE=512 # Sector size in bytes

# Calculate the total size in bytes
TOTAL_BYTES=$((TOTAL_SECTORS * SECTOR_SIZE))

# Get the starting sector of the partition
PART_START=$(cat /sys/block/mmcblk0/mmcblk0p1/start)

# Calculate the available sectors for the partition
AVAILABLE_SECTORS=$((TOTAL_SECTORS - PART_START))

# Calculate the maximum size for the partition in bytes
MAX_PART_SIZE_BYTES=$((AVAILABLE_SECTORS * SECTOR_SIZE))

# Convert to megabytes (1 MB = 1,048,576 bytes)
MAX_PART_SIZE_MB=$((MAX_PART_SIZE_BYTES / 1048576))

# Subtract a minimal safety margin (e.g., 1 MB for alignment and safety)
SAFETY_MARGIN_MB=1
SAFE_PART_SIZE_MB=$((MAX_PART_SIZE_MB - SAFETY_MARGIN_MB))

echo "Total device size: $((TOTAL_BYTES / 1048576)) MB"
echo "Maximum partition size: ${MAX_PART_SIZE_MB} MB"
echo "Resizing the partition to: ${SAFE_PART_SIZE_MB} MB"

# Run fatresize with the adjusted size
echo "Resizing the FAT32 partition using calculated size..."
$TMP_PATH/fatresize -f -v -s ${SAFE_PART_SIZE_MB}M /dev/mmcblk0p1

# Check if manual resize was successful
if [ $? -ne 0 ]; then
echo "Error resizing the partition with calculated size."
# Remount the partition before exiting
mount /dev/mmcblk0p1 /mnt/SDCARD
sync
exit 1
fi
echo "Error resizing the partition."
sync
/customer/main
exit 1
fi

# Run partprobe to force partition table reload
echo "Forcing partition table reload with partprobe..."

$TMP_PATH/partprobe /dev/mmcblk0

# Fix FAT32 header RAW in windows
echo -n -e \\xEB\\x58\\x90 > /dev/mmcblk0p1
sync

# Fix FAT32 header
echo -n -e \\xEB\\x58\\x90 > /dev/mmcblk0p1
sync
$TMP_PATH/fsck.fat -a -v /dev/mmcblk0p1

# Remount the partition
# Remount the partition using system's mount command
echo "Remounting the partition..."
mount /dev/mmcblk0p1 /mnt/SDCARD

# Show partition information after resizing
echo "Partition information after resizing:"
fdisk -l /dev/mmcblk0
$TMP_PATH/fdisk -l /dev/mmcblk0

# Create a file indicating that the resize has been completed
touch /mnt/SDCARD/resized

# Sync changes before rebooting
sync


echo "Unmounting the partition..."
umount -r /mnt/SDCARD
umount /mnt/SDCARD

sync

echo "Resizing completed. Rebooting the system..."
reboot
if [ ! -f "/customer/app/axp_test" ]; then
reboot
else
poweroff
fi
fi

# Check if the script is copied to /tmp, if not, copy it
Expand Down
Binary file added base/Koriki/lib/libfdisk.so.1
Binary file not shown.
Binary file added base/Koriki/lib/libsmartcols.so.1
Binary file not shown.
8 changes: 7 additions & 1 deletion makeimg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ fi
BASE_DIR="./base"
VERSION_FILE="$BASE_DIR/Koriki/version.txt"
CLUSTER_SIZE=32768 # 32 KB (32 * 1024)
MIN_SIZE_MB=1024 # 1 GB en MiB (1024 * 1)

# Leer la versión desde el archivo version.txt
if [ -f "$VERSION_FILE" ]; then
Expand Down Expand Up @@ -41,7 +42,7 @@ done

# Paso 4: Calcular el número total de clústeres necesarios
CLUSTER_NEEDED=$((SIZE_FILES / CLUSTER_SIZE + NUM_FILES)) # Dividir el tamaño total por clúster y sumar por cada archivo
TOTAL_CLUSTER_SPACE=$((CLUSTER_NEEDED * CLUSTER_SIZE)) # Espacio total necesario para los clústeres en FAT32
TOTAL_CLUSTER_SPACE=$((CLUSTER_NEEDED * CLUSTER_SIZE + OVERHEAD)) # Incluir la sobrecarga de clústeres

# Mostrar los detalles
echo "Número de archivos y carpetas: $NUM_FILES"
Expand All @@ -51,6 +52,11 @@ echo "Tamaño total con sobrecarga de clústeres: $TOTAL_CLUSTER_SPACE bytes"
# Asegurarse de que el tamaño total sea múltiplo de 1 MiB para la creación de la imagen
SIZE_MB=$(( (TOTAL_CLUSTER_SPACE + 1048576 - 1) / 1048576 ))

# Verificar si el tamaño es menor a 2.01 GB y ajustarlo
if [ $SIZE_MB -lt $MIN_SIZE_MB ]; then
SIZE_MB=$MIN_SIZE_MB
fi

echo "Versión: $VERSION"
echo "Nombre de la imagen: $IMAGE_NAME"
echo "Tamaño total ajustado a MiB: $SIZE_MB MiB"
Expand Down

0 comments on commit 26e7d21

Please sign in to comment.