Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions mkapp/app/script/formatsd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ else
echo "Umounting SD Card: FAILURE"
fi

BLKDEV=/dev/mmcblk0p1
DISKDEV=/dev/mmcblk0
BLKDEV=${DISKDEV}p1
if [ ! -b "$BLKDEV" ]; then
BLKDEV=/dev/mmcblk0
BLKDEV=$DISKDEV
fi

rm -f /tmp/mkfs.result
Expand All @@ -28,6 +29,25 @@ RESULT=$?
echo "mkfs result: $RESULT" >> /tmp/mkfs.log
echo $RESULT > /tmp/mkfs.result

# mkfs.vfat only rewrites the filesystem inside the partition; the MBR
# partition type byte is left as it was. SDXC cards (>32GB) ship as exFAT
# with type 0x07 (NTFS/exFAT), so after formatting they hold FAT32 in a
# partition still labelled 0x07. Linux ignores the type byte and mounts
# fine, but macOS picks the filesystem driver from it, tries exFAT, and
# reports "The disk you attached was not readable by this computer".
# Set the type to 0x0C (FAT32 LBA) so the card mounts on every OS.
# Only the 0x07 case is touched; 0xEE (GPT protective MBR) and anything
# already FAT-typed are left alone.
if [ "$RESULT" -eq 0 ] && [ "$BLKDEV" != "$DISKDEV" ]; then
PTYPE=$(dd if="$DISKDEV" bs=1 skip=450 count=1 2>/dev/null | hexdump -v -e '1/1 "%02x"')
echo "partition type: 0x$PTYPE" >> /tmp/mkfs.log
if [ "$PTYPE" = "07" ]; then
printf '\014' | dd of="$DISKDEV" bs=1 seek=450 count=1 conv=notrunc,fsync >> /tmp/mkfs.log 2>&1
blockdev --rereadpt "$DISKDEV" >> /tmp/mkfs.log 2>&1
echo "partition type changed to 0x0c (FAT32 LBA)" >> /tmp/mkfs.log
fi
fi

echo "Mounting SD Card"
mount "$BLKDEV" /mnt/extsd
if [ $? -eq 0 ]; then
Expand Down
Loading