Hi,
I made a script that creates image .img with two partitions (1 GB FAT16 with bootable flag where I store MLO, u-boot.img, uImage, am335x-boneblack.dtb, and boot.scr and 3GB EXT3 for ROOTFS). I call the script with ./script “imagename” and as an output I get imagename.img.
Then I flash it to the SD card with balena or using dd comand, mount it on my host PC and I see that all files are present, partitions checked with gparted and everything seems correct.
Apart from that I use separate SD card where I create two partitions manually with gparted, and copy all files manually.
When comparing two cards with different set of commands, content looks exactly the same.
The difference is that in the first case, when I try to boot BeagleBone Black I always see just CCCCCC in the console. In the case with manually partitioned card, everything is ok, board is booting normally.
This is my script:
#!/bin/bash
# Check for the image name parameter
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <image-name>"
exit 1
fi
# Set the name of the output image file from the first script argument
IMG_NAME="$1"
IMG_FILE="${IMG_NAME}.img"
MOUNT_DIR="/mnt"
# Define the paths
RFS_TAR_PATH="../../output/images/rootfs.tar"
MLO_PATH="../../output/images/MLO"
UBOOT_IMG_PATH="../../output/images/u-boot.img"
BOOT_SCR_PATH="./bootscripts/boot.scr"
UIMAGE_PATH="../../output/images/uImage"
DTB_PATH="../../output/build/linux-v5.10.168-ti-r75/arch/arm/boot/dts/am335x-boneblack.dtb"
# Create an image of the desired size (4GB here)
echo "Creating a $IMG_SIZE image named $IMG_FILE..."
#fallocate -l 4G $IMG_FILE || exit 1
dd if=/dev/zero of=$IMG_FILE bs=1M count=$((4*1024)) # 4GB image
# Setup loop device
echo "Creating loop device..."
LOOP_DEVICE=$(sudo losetup --show -fP $IMG_FILE)
if [ -z "$LOOP_DEVICE" ]; then
echo "Failed to create loop device"
exit 1
fi
# Calculate the end sector for the second partition
END_SECTOR=$((1024 * 1024 * 4 / 512)) # 4GB image size in 512-byte sectors
# Create partitions using sfdisk
echo "Creating partitions..."
{
echo label: dos
echo start=2048, size=2097152, type=6, bootable
echo start=2099200, type=83
} | sfdisk $LOOP_DEVICE
# Wait for the kernel to recognize new partitions
sleep 10
sync
# Format partitions
echo "Formatting FAT16 boot partition..."
sudo mkfs.vfat -F 16 ${LOOP_DEVICE}p1 -n BOOT
echo "Checking and repairing FAT16 filesystem..."
sudo fsck.vfat -a -v ${LOOP_DEVICE}p1 || exit 1
echo "Formatting ext3 root filesystem..."
sudo mkfs.ext3 ${LOOP_DEVICE}p2 -L ROOTFS
echo "Checking and repairing ext3 filesystem..."
sudo e2fsck -p -f ${LOOP_DEVICE}p2 || exit 1
# Wait for the system to settle
sleep 5
# Mount the FAT16 partition and copy files
echo "Mounting boot partition..."
mkdir -p ${MOUNT_DIR}/boot
sudo mount ${LOOP_DEVICE}p1 ${MOUNT_DIR}/boot
echo "Copying bootloader files..."
sudo cp ${MLO_PATH} ${MOUNT_DIR}/boot # MLO should be copied first
sync
sleep 1
sudo cp ${UBOOT_IMG_PATH} ${UIMAGE_PATH} ${DTB_PATH} ${BOOT_SCR_PATH} ${MOUNT_DIR}/boot
sync
echo "Unmounting boot partition..."
sudo umount ${MOUNT_DIR}/boot || exit 1
sleep 5
sync
# Mount the ext3 partition and extract root filesystem
echo "Mounting root filesystem..."
mkdir -p ${MOUNT_DIR}/rootfs
sudo mount ${LOOP_DEVICE}p2 ${MOUNT_DIR}/rootfs
echo "Extracting root filesystem..."
sudo tar -xpf ${RFS_TAR_PATH} -C ${MOUNT_DIR}/rootfs
sync
echo "Unmounting root filesystem..."
sudo umount ${MOUNT_DIR}/rootfs || exit 1
sleep 5
sync
# Clean up
echo "Cleaning up..."
sudo losetup -d ${LOOP_DEVICE}
rm -rf ${MOUNT_DIR}/boot ${MOUNT_DIR}/rootfs
sleep 10
sync
# Compress the image
#echo "Compressing the image..."
#xz -z ${IMG_FILE}
echo "Image ${IMG_NAME}.img.xz created successfully"
Can someone point out where the issue can be? I have exactly same SD cards, and one is working and another is not.
Did I miss something, and can someone suggest another approach?
Thanks a lot.
Cheers!