Created
August 29, 2024 12:02
-
-
Save shauninman/608452c3927ef1a03a9667ba69bd3986 to your computer and use it in GitHub Desktop.
simplified mkimage for the MagicX XU Mini M
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -x | |
HERE=$(dirname "$0") | |
cd "$HERE" | |
SYSTEM_SIZE=368 | |
SYSTEM_PART_START=32768 | |
BOOTLOADER="u-boot" | |
DISK_LABEL=msdos | |
UBOOT_SYSTEM="rg351v" | |
TARGET_IMG="$HERE" | |
IMAGE_NAME=MOSS | |
DISTRO_BOOTLABEL="MOSS" | |
UUID_SYSTEM=0508-2833 | |
DISK_START_PADDING=$(( (${SYSTEM_PART_START} + 2048 - 1) / 2048 )) | |
DISK_GPT_PADDING=1 | |
DISK_SIZE=$(( ${DISK_START_PADDING} + ${SYSTEM_SIZE} + ${DISK_GPT_PADDING} )) | |
DISK_BASENAME="${TARGET_IMG}/${IMAGE_NAME}" | |
DISK="${DISK_BASENAME}.img" | |
rm "$DISK" | |
LE_TMP=$(mktemp -d) | |
# create image | |
dd if=/dev/zero of="${DISK}" bs=1M count="${DISK_SIZE}" conv=fsync | |
sync | |
# set label | |
parted -s "${DISK}" mklabel ${DISK_LABEL} | |
sync | |
# create part 1 | |
SYSTEM_PART_END=$(( ${SYSTEM_PART_START} + (${SYSTEM_SIZE} * 1024 * 1024 / 512) - 1 )) | |
parted -s "${DISK}" -a min unit s mkpart primary fat32 ${SYSTEM_PART_START} ${SYSTEM_PART_END} | |
parted -s "${DISK}" set 1 boot on | |
# create fs on part 1 | |
OFFSET=$(( ${SYSTEM_PART_START} * 512 )) | |
HEADS=4 | |
TRACKS=32 | |
SECTORS=$(( ${SYSTEM_SIZE} * 1024 * 1024 / 512 / ${HEADS} / ${TRACKS} )) | |
shopt -s expand_aliases # enables alias expansion in script | |
alias mformat="mformat -i ${DISK}@@${OFFSET} -h ${HEADS} -t ${TRACKS} -s ${SECTORS}" | |
alias mcopy="mcopy -i ${DISK}@@${OFFSET}" | |
alias mmd="mmd -i ${DISK}@@${OFFSET}" | |
mformat -v "${DISTRO_BOOTLABEL}" -N "${UUID_SYSTEM//-/}" :: | |
sync | |
# add KERNEL/SYSTEM/dtb/etal | |
mcopy ${DISTRO_BOOTLABEL}/* :: | |
sync | |
# MOSS.pre is copied from stock TF1 | |
# dd if=MAGICX-STOCK.img of=MOSS.pre bs=1024 skip=32 count=16352 | |
dd if=${DISTRO_BOOTLABEL}.pre of=${DISK} bs=1024 seek=32 conv=fsync,notrunc | |
# TODO: might require a pass through gdisk to add GPT (complains about it missing) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Expects a folder named "MOSS" (change with
$IMAGE_NAME
or$DISTRO_BOOTLABEL
, those should be the same thing now that I look at it) containing the contents of the MAGICX partition of TF1, with modified KERNEL and SYSTEM images, dtbs, and extlinux confs) as well as a file named MOSS.pre ripped from the stock TF1 containing stock u-boot. eg.dd if=MAGICX-STOCK.img of=MOSS.pre bs=1024 skip=32 count=16352