Address review comments from puhitaku

- image/build_image.sh: fix IMG_NAME default to sd.img, SIZE_M to 3072
- image/build_image.sh: revert START2 to original form; remove all unnecessary inline comments
- Makefile: remove 'Mount proc and sys' comment; keep the 'Keep mounting commands AFTER' note
- Makefile: remove 'Copy qemu-arm-static' comment; simplify binfmt and mmap_min_addr comments
- Makefile: replace verbose Docker target comment blocks with clean targets per reviewer suggestion
- README.md: revert all unrelated changes; keep only the macOS environment line and Docker build section

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Mingyang Li
2026-06-06 10:33:00 -07:00
parent e085059fd5
commit bf54dfbf44
3 changed files with 34 additions and 83 deletions

View File

@@ -9,8 +9,8 @@ Build a bootable image for Brainux.
Arguments:
ROOTFS Path to the root filesystem directory to include in the image (default: "rootfs").
IMG_NAME Name of the output image file (default: brainux.img).
SIZE_M Size of the output image in megabytes (default: 1024).
IMG_NAME Name of the output image file (default: sd.img).
SIZE_M Size of the output image in megabytes (default: 3072).
EOF
}
@@ -20,18 +20,14 @@ if [[ "$1" == "-h" || "$1" == "--help" || -z "$1" ]]; then
exit 0
fi
# JOBS is used to control the number of parallel jobs when building u-boot.
# By default, it uses the number of CPU cores. This can be overridden by
# setting the IMG_BUILD_JOBS environment variable before running the script,
# handy for Docker environments or when you want to limit resource usage.
JOBS=${IMG_BUILD_JOBS:-$(nproc)}
REPO=$(git rev-parse --show-toplevel)
WORK=${REPO}/image/work
LINUX=${REPO}/linux-brain
ROOTFS=${1:-rootfs} # Default to "rootfs" if not specified
IMG_NAME=${2:-brainux.img}
ROOTFS=${1:-rootfs}
IMG_NAME=${2:-sd.img}
IMG=${REPO}/image/${IMG_NAME}
SIZE_M=${3:-1024} # Default to 1GB if not specified
SIZE_M=${3:-3072}
export CROSS_COMPILE=arm-linux-gnueabi-
mkdir -p ${WORK}
@@ -41,7 +37,6 @@ for i in "a7200" "a7400" "sh1" "sh2" "sh3" "sh4" "sh5" "sh6" "sh7"; do
NUM=$(echo $i | sed -E 's/sh//g')
BUILD_DIR=${WORK}/uboot-build-${i}
# Build per-board from isolated source copies to avoid fragile clean rules.
rm -rf ${BUILD_DIR}
rsync -a --exclude '.git' ${REPO}/u-boot-brain/ ${BUILD_DIR}/
make -C ${BUILD_DIR} pw${i}_defconfig
@@ -66,17 +61,12 @@ for i in "a7200" "a7400" "sh1" "sh2" "sh3" "sh4" "sh5" "sh6" "sh7"; do
esac
done
# Create an empty image file of the specified size.
dd if=/dev/zero of=${IMG} bs=1M count=${SIZE_M}
# We want to partition the image with two partitions:
# * a 64MB FAT32 partition for the bootloader and kernel, and
# * the rest of the space as an ext4 partition for the root filesystem.
START1=2048 # Start at 1MB (2048 sectors of 512 bytes) to align with typical partitioning schemes and avoid issues with some bootloaders.
SECTORS1=$((1024 * 1024 * 64 / 512)) # 64MB in sectors (512 bytes per sector)
START2=$((START1 + SECTORS1)) # Start the second partition immediately after the first
START1=2048
SECTORS1=$((1024 * 1024 * 64 / 512))
START2=$((2048 + ${SECTORS1}))
# We use sfdisk to create the partition table. The first partition is type 'b' (W95 FAT32), and the second is type '83' (Linux).
cat <<EOF > ${WORK}/part.sfdisk
${IMG}1 : start=${START1}, size=${SECTORS1}, type=b
${IMG}2 : start=${START2}, type=83
@@ -84,11 +74,7 @@ EOF
sfdisk ${IMG} < ${WORK}/part.sfdisk
# We want to format and write to the partitions. To do so, we use kpartx to create device mappings for the partitions in the image.
KPARTX_OUTPUT=$(sudo kpartx -av ${IMG})
# Extract the loop device name from kpartx output. It looks like:
# "add map loop0p1 (252:0): 0 131072 linear /dev/loop0 2048"
# We want to extract "loop0" from this line.
LOOPDEV=$(echo "${KPARTX_OUTPUT}" | sed -n 's/^add map \(loop[0-9]\+\)p1.*/\1/p' | head -n 1)
sudo mkfs.fat -n boot -F32 -v -I /dev/mapper/${LOOPDEV}p1
@@ -105,7 +91,6 @@ sudo cp ${LINUX}/arch/arm/boot/dts/imx28-pw*.dtb ${WORK}/p1/
sudo mkdir -p ${WORK}/p1/nk
sudo cp ${WORK}/*.bin ${WORK}/p1/nk/
# Prepare the WinCE application "Launch Linux". "LILO" stands for "Linux Loader".
make -C ${REPO}/brainlilo
LILO="${WORK}/p1/アプリ/Launch Linux"
@@ -122,7 +107,6 @@ sudo cp ${WORK}/lilobin/*.bin ${WORK}/p1/loader/
sudo cp -ra ${REPO}/${ROOTFS}/* ${WORK}/p2/
# Clean up: unmount the partitions and remove the device mappings.
sudo umount ${WORK}/p1 ${WORK}/p2
sudo kpartx -d ${IMG}