release: make SD card partition layout more flexible

Currently the partition layout is hardcoded to create an EFI/FAT
partition and a UFS root partition, with some logic to handle GPT/MBR
differences.

On RISC-V platforms we are seeing the emerging pattern that firmware
should be placed in a partition of a known type, rather than just a
known sector of the disk. Thus, some functionality is needed to
customize the layout for SD card images.

Add a hook, arm_create_partitions(), which can be overridden to insert
additional platform-specific partitions, possibly preceding the standard
EFI and UFS ones. A couple of new variables are added to track the
indices, e.g. ROOTFSPART_SUFFIX=p2.

In a couple places this de-duplicates the GPT/MBR logic.

Reviewed by:	manu, karels, imp
MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D43848
This commit is contained in:
Mitchell Horne 2024-02-14 11:12:29 -04:00
parent 94b86c12f1
commit 2af03ebfb8

View File

@ -67,22 +67,25 @@ arm_create_disk() {
# Create the target raw file and temporary work directory.
chroot ${CHROOTDIR} gpart create -s ${PART_SCHEME} ${mddev}
arm_create_partitions
if [ "${PART_SCHEME}" = "GPT" ]; then
chroot ${CHROOTDIR} gpart add -t efi -l efi -a 512k -s ${FAT_SIZE} ${mddev}
chroot ${CHROOTDIR} newfs_msdos -L efi -F ${FAT_TYPE} /dev/${mddev}p1
chroot ${CHROOTDIR} gpart add -t freebsd-ufs -l rootfs -a 64k ${mddev}
chroot ${CHROOTDIR} newfs -U -L rootfs /dev/${mddev}p2
fi
if [ "${PART_SCHEME}" = "MBR" ]; then
chroot ${CHROOTDIR} gpart add -t '!12' -a 512k -s ${FAT_SIZE} ${mddev}
chroot ${CHROOTDIR} gpart set -a active -i 1 ${mddev}
chroot ${CHROOTDIR} newfs_msdos -L efi -F ${FAT_TYPE} /dev/${mddev}s1
chroot ${CHROOTDIR} gpart add -t freebsd ${mddev}
chroot ${CHROOTDIR} gpart create -s bsd ${mddev}s2
chroot ${CHROOTDIR} gpart add -t freebsd-ufs -a 64k -b 64k ${mddev}s2
chroot ${CHROOTDIR} newfs -U -L rootfs /dev/${mddev}s2a
chroot ${CHROOTDIR} gpart create -s bsd ${mddev}${BSDLABEL_SUFFIX}
chroot ${CHROOTDIR} gpart add -t freebsd-ufs -a 64k -b 64k ${mddev}${BSDLABEL_SUFFIX}
fi
# Create the EFI and UFS filesystems
chroot ${CHROOTDIR} newfs_msdos -L efi -F ${FAT_TYPE} /dev/${mddev}${EFIPART_SUFFIX}
chroot ${CHROOTDIR} newfs -U -L rootfs /dev/${mddev}${ROOTFSPART_SUFFIX}
return 0
}
@ -171,12 +174,7 @@ arm_setup_minimal_loader() {
}
arm_install_base() {
if [ "${PART_SCHEME}" = "GPT" ]; then
chroot ${CHROOTDIR} mount /dev/${mddev}p2 ${DESTDIR}
fi
if [ "${PART_SCHEME}" = "MBR" ]; then
chroot ${CHROOTDIR} mount /dev/${mddev}s2a ${DESTDIR}
fi
chroot ${CHROOTDIR} mount /dev/${mddev}${ROOTFSPART_SUFFIX} ${DESTDIR}
_OSVERSION=$(chroot ${CHROOTDIR} /usr/bin/uname -U)
REVISION=$(chroot ${CHROOTDIR} make -C /usr/src/release -V REVISION)
BRANCH=$(chroot ${CHROOTDIR} make -C /usr/src/release -V BRANCH)
@ -230,14 +228,8 @@ arm_install_boot() {
FATMOUNT="${DESTDIR%${KERNEL}}/fat"
UFSMOUNT="${DESTDIR%${KERNEL}}/ufs"
chroot ${CHROOTDIR} mkdir -p "${FATMOUNT}" "${UFSMOUNT}"
if [ "${PART_SCHEME}" = "GPT" ]; then
dospart="/dev/${mddev}p1"
ufspart="/dev/${mddev}p2"
fi
if [ "${PART_SCHEME}" = "MBR" ]; then
dospart="/dev/${mddev}s1"
ufspart="/dev/${mddev}s2a"
fi
dospart="/dev/${mddev}${EFIPART_SUFFIX}"
ufspart="/dev/${mddev}${ROOTFSPART_SUFFIX}"
chroot ${CHROOTDIR} mount_msdosfs ${dospart} ${FATMOUNT}
chroot ${CHROOTDIR} mount ${ufspart} ${UFSMOUNT}
@ -271,3 +263,20 @@ arm_install_uboot() {
arm_do_quirk() {
# Override in the ${EMBEDDED_TARGET}/${BOARDNAME}.conf file.
}
arm_create_partitions() {
# Override in the ${EMBEDDED_TARGET}/${BOARDNAME}.conf file.
# Set defaults for EFIPART_SUFFIX, ROOTFSPART_SUFFIX, and
# BSDLABEL_SUFFIX (MBR only), needed elsewhere.
if [ "${PART_SCHEME}" = "GPT" ]; then
export EFIPART_SUFFIX=p1
export ROOTFSPART_SUFFIX=p2
fi
if [ "${PART_SCHEME}" = "MBR" ]; then
export EFIPART_SUFFIX=s1
export BSDLABEL_SUFFIX=s2
export ROOTFSPART_SUFFIX=s2a
fi
}