meta-digi-arm: rework SD card generation class

This is needed in the context of CC6 variants 0x7 and 0x9 (EMMC-less).

Changes:

* Do not use 'meta-fsl-arm' image generation class: removed include and
  override SDCARD generation function
* Use same VFAT boot image for EMMC and SD card. The u-boot bootscript
  has been adapted to be able to boot Linux from both SD and EMMC.

Signed-off-by: Javier Viguera <javier.viguera@digi.com>
(cherry picked from commit 8b8456b8fd90facd92dfc87632effa582ca60475)
This commit is contained in:
Javier Viguera 2015-06-25 18:44:13 +02:00
parent d9b4d0731e
commit 6b31e716a5
10 changed files with 136 additions and 93 deletions

View File

@ -1,4 +1,11 @@
inherit image_types_fsl
inherit image_types
IMAGE_DEPENDS_boot.vfat = " \
dosfstools-native:do_populate_sysroot \
mtools-native:do_populate_sysroot \
u-boot:do_deploy \
virtual/kernel:do_deploy \
"
IMAGE_CMD_boot.vfat() {
#
@ -34,6 +41,13 @@ IMAGE_CMD_boot.vfat() {
mkfs.vfat -n "Boot ${MACHINE}" -S 512 -C ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.boot.vfat ${BOOTIMG_BLOCKS}
mcopy -i ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.boot.vfat ${BOOTIMG_FILES_SYMLINK} ::/
# Copy boot scripts into the VFAT image
for item in ${BOOT_SCRIPTS}; do
src=`echo $item | awk -F':' '{ print $1 }'`
dst=`echo $item | awk -F':' '{ print $2 }'`
mcopy -i ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.boot.vfat -s ${DEPLOY_DIR_IMAGE}/$src ::/$dst
done
# Truncate the image to speed up the downloading/writing to the EMMC
if [ -n "${BOARD_BOOTIMAGE_PARTITION_SIZE}" ]; then
# U-Boot writes 512 bytes sectors so truncate the image at a sector boundary
@ -58,32 +72,93 @@ IMAGE_CMD_rootfs.initramfs() {
}
IMAGE_TYPEDEP_rootfs.initramfs = "cpio.gz"
SDCARD_GENERATION_COMMAND_ccardimx28js = "generate_ccardimx28js_sdcard"
# Set alignment to 4MB [in KiB]
IMAGE_ROOTFS_ALIGNMENT = "4096"
# Boot partition size in KiB, (default 64MiB)
BOARD_BOOTIMAGE_PARTITION_SIZE ??= "65536"
# SD card image name
SDIMG = "${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.sdcard"
SDIMG_BOOTFS_TYPE ?= "boot.vfat"
SDIMG_BOOTFS = "${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.${SDIMG_BOOTFS_TYPE}"
SDIMG_ROOTFS_TYPE ?= "ext4"
SDIMG_ROOTFS = "${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.${SDIMG_ROOTFS_TYPE}"
IMAGE_DEPENDS_sdcard = " \
dosfstools-native:do_populate_sysroot \
mtools-native:do_populate_sysroot \
parted-native:do_populate_sysroot \
u-boot:do_deploy \
virtual/kernel:do_deploy \
"
#
# Create an image that can by written onto a SD card using dd for use with ccardimx28js
#
# External variables needed:
# ${SDCARD_ROOTFS} - the rootfs image to incorporate
# Create an image that can by written onto a SD card using dd.
#
# The disk layout used is:
#
# 1M -> IMAGE_ROOTFS_ALIGNMENT - u-boot bootstream
# IMAGE_ROOTFS_ALIGNMENT -> BOOT_SPACE - kernel + device tree blob (VFAT partition)
# BOOT_SPACE -> SDIMG_SIZE - rootfs (EXT4 partition)
# 1. Not partitioned : reserved for bootloader (u-boot)
# 2. BOOT PARTITION : kernel and device tree blobs
# 3. ROOTFS PARTITION : rootfs
#
# Default Free space = 1.3x
# Use IMAGE_OVERHEAD_FACTOR to add more space
# <--------->
# 4MiB 8MiB SDIMG_ROOTFS 4MiB
# <-----------------------> <-------------> <----------------------> <------------------------------>
# ---------------------------------------- ------------------------ -------------------------------
# | | | BOOT_SPACE | ROOTFS_SIZE | IMAGE_ROOTFS_ALIGNMENT |
# ---------------------------------------- ------------------------ -------------------------------
# ^ ^ ^ ^ ^ ^
# | | | | | |
# 0 1M 4M 4MiB + BOOTSPACE 4MiB + BOOTSPACE + SDIMG_ROOTFS 4MiB + BOOTSPACE + SDIMG_ROOTFS + 4MiB
# 4MiB BOOT_SPACE ROOTFS_SIZE
# <------------> <--------------------> <------------------------------>
# +--------------+----------------------+--------------------------------+
# | U-BOOT (RAW) | BOOT PARTITION (FAT) | ROOTFS PARTITION (EXT4) |
# +--------------+----------------------+--------------------------------+
# ^ ^ ^ ^
# | | | |
# 0 4MiB 4MiB + BOOT_SPACE SDIMG_SIZE
#
generate_ccardimx28js_sdcard() {
IMAGE_CMD_sdcard() {
# Align boot partition and calculate total sdcard image size
BOOT_SPACE_ALIGNED="$(expr \( \( ${BOARD_BOOTIMAGE_PARTITION_SIZE} + ${IMAGE_ROOTFS_ALIGNMENT} - 1 \) / ${IMAGE_ROOTFS_ALIGNMENT} \) \* ${IMAGE_ROOTFS_ALIGNMENT})"
SDIMG_SIZE="$(expr ${IMAGE_ROOTFS_ALIGNMENT} + ${BOOT_SPACE_ALIGNED} + $ROOTFS_SIZE)"
# Initialize sdcard image file
dd if=/dev/zero of=${SDIMG} bs=1024 count=0 seek=${SDIMG_SIZE}
# Create partition table, boot partition (with bootable flag) and rootfs partition (to the end of the disk)
parted -s ${SDIMG} mklabel msdos
parted -s ${SDIMG} unit KiB mkpart primary fat32 ${IMAGE_ROOTFS_ALIGNMENT} $(expr ${IMAGE_ROOTFS_ALIGNMENT} \+ ${BOOT_SPACE_ALIGNED})
parted -s ${SDIMG} set 1 boot on
parted -s ${SDIMG} -- unit KiB mkpart primary ext2 $(expr ${IMAGE_ROOTFS_ALIGNMENT} \+ ${BOOT_SPACE_ALIGNED}) -1s
parted -s ${SDIMG} unit KiB print
# Burn bootloader, boot and rootfs partitions
dd if=${DEPLOY_DIR_IMAGE}/${UBOOT_SYMLINK} of=${SDIMG} conv=notrunc,fsync seek=2 bs=512
dd if=${SDIMG_BOOTFS} of=${SDIMG} conv=notrunc,fsync seek=1 bs=$(expr ${IMAGE_ROOTFS_ALIGNMENT} \* 1024)
dd if=${SDIMG_ROOTFS} of=${SDIMG} conv=notrunc,fsync seek=1 bs=$(expr ${IMAGE_ROOTFS_ALIGNMENT} \* 1024 + ${BOOT_SPACE_ALIGNED} \* 1024)
}
#
# Create an image that can by written onto a SD card using dd (for ccardimx28 family)
#
# The disk layout used is:
#
# 1. Not partitioned : reserved for bootloader (u-boot at 1MiB offset)
# 2. BOOT PARTITION : kernel and device tree blobs
# 3. ROOTFS PARTITION : rootfs
#
# 4MiB BOOT_SPACE ROOTFS_SIZE
# <----------------> <--------------------> <------------------------------>
# +---+--------------+----------------------+--------------------------------+
# | | U-BOOT (RAW) | BOOT PARTITION (FAT) | ROOTFS PARTITION (EXT4) |
# +---+--------------+----------------------+--------------------------------+
# ^ ^ ^ ^ ^
# | | | | |
# 0 1MiB 4MiB 4MiB + BOOT_SPACE SDIMG_SIZE
#
IMAGE_CMD_sdcard_ccardimx28() {
# Align boot partition and calculate total sdcard image size
BOOT_SPACE_ALIGNED="$(expr \( \( ${BOARD_BOOTIMAGE_PARTITION_SIZE} + ${IMAGE_ROOTFS_ALIGNMENT} - 1 \) / ${IMAGE_ROOTFS_ALIGNMENT} \) \* ${IMAGE_ROOTFS_ALIGNMENT})"
SDIMG_SIZE="$(expr ${IMAGE_ROOTFS_ALIGNMENT} + ${BOOT_SPACE_ALIGNED} + $ROOTFS_SIZE)"
# Initialize sdcard image file
dd if=/dev/zero of=${SDIMG} bs=1024 count=0 seek=${SDIMG_SIZE}
#
# Bootstream header for u-boot at 1M offset
#
@ -100,45 +175,23 @@ generate_ccardimx28js_sdcard() {
# format does not work well with 'dash' shell
PRINTF="$(which printf)"
parted -s ${SDCARD} mklabel msdos
parted -s ${SDCARD} unit KiB mkpart primary 1024 ${IMAGE_ROOTFS_ALIGNMENT}
parted -s ${SDCARD} unit KiB mkpart primary fat32 ${IMAGE_ROOTFS_ALIGNMENT} $(expr ${IMAGE_ROOTFS_ALIGNMENT} \+ ${BOOT_SPACE_ALIGNED})
parted -s ${SDCARD} unit KiB mkpart primary $(expr ${IMAGE_ROOTFS_ALIGNMENT} \+ ${BOOT_SPACE_ALIGNED}) $(expr ${IMAGE_ROOTFS_ALIGNMENT} \+ ${BOOT_SPACE_ALIGNED} \+ $ROOTFS_SIZE)
# Create partition table, boot partition (with bootable flag) and rootfs partition (to the end of the disk)
parted -s ${SDIMG} mklabel msdos
parted -s ${SDIMG} unit KiB mkpart primary 1024 ${IMAGE_ROOTFS_ALIGNMENT}
parted -s ${SDIMG} unit KiB mkpart primary fat32 ${IMAGE_ROOTFS_ALIGNMENT} $(expr ${IMAGE_ROOTFS_ALIGNMENT} \+ ${BOOT_SPACE_ALIGNED})
parted -s ${SDIMG} set 2 boot on
parted -s ${SDIMG} -- unit KiB mkpart primary ext2 $(expr ${IMAGE_ROOTFS_ALIGNMENT} \+ ${BOOT_SPACE_ALIGNED}) -1s
parted -s ${SDIMG} unit KiB print
# Change partition type to 0x53 for mxs processor family
echo -n S | dd of=${SDCARD} bs=1 count=1 seek=450 conv=notrunc
# Change partition type to 0x53 for mxs processor family and write bootstream header
echo -n S | dd of=${SDIMG} bs=1 count=1 seek=450 conv=notrunc
${PRINTF} "${BS_HDR}" | dd of=${SDIMG} bs=512 seek=$(expr 1024 \* 2) conv=notrunc,sync
${PRINTF} "${BS_HDR}" | dd of=${SDCARD} bs=512 seek=$(expr 1024 \* 2) conv=notrunc,sync
dd if=${DEPLOY_DIR_IMAGE}/${UBOOT_SYMLINK} of=${SDCARD} bs=512 seek=$(expr 1024 \* 2 \+ 1) conv=notrunc,sync
BOOT_BLOCKS=$(LC_ALL=C parted -s ${SDCARD} unit b print \
| awk '/ 2 / { print substr($4, 1, length($4 -1)) / 1024 }')
mkfs.vfat -n "${BOOTDD_VOLUME_ID}" -S 512 -C ${WORKDIR}/boot.img $BOOT_BLOCKS
mcopy -i ${WORKDIR}/boot.img -s ${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE}-${MACHINE}.bin ::/${KERNEL_IMAGETYPE}
# Copy boot scripts
for item in ${BOOT_SCRIPTS}; do
src=`echo $item | awk -F':' '{ print $1 }'`
dst=`echo $item | awk -F':' '{ print $2 }'`
mcopy -i ${WORKDIR}/boot.img -s ${DEPLOY_DIR_IMAGE}/$src ::/$dst
done
# Copy kernel image and dtb's
if test -n "${KERNEL_DEVICETREE}"; then
for DTS_FILE in ${KERNEL_DEVICETREE}; do
DTS_BASE_NAME=`basename ${DTS_FILE} | awk -F "." '{print $1}'`
if [ -e "${KERNEL_IMAGETYPE}-${DTS_BASE_NAME}.dtb" ]; then
kernel_bin="`readlink ${KERNEL_IMAGETYPE}-${MACHINE}.bin`"
kernel_bin_for_dtb="`readlink ${KERNEL_IMAGETYPE}-${DTS_BASE_NAME}.dtb | sed "s,$DTS_BASE_NAME,${MACHINE},g;s,\.dtb$,.bin,g"`"
if [ $kernel_bin = $kernel_bin_for_dtb ]; then
mcopy -i ${WORKDIR}/boot.img -s ${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE}-${DTS_BASE_NAME}.dtb ::/${DTS_BASE_NAME}.dtb
fi
fi
done
fi
# Burn partitions
dd if=${WORKDIR}/boot.img of=${SDCARD} conv=notrunc seek=1 bs=$(expr ${IMAGE_ROOTFS_ALIGNMENT} \* 1024) && sync && sync
dd if=${SDCARD_ROOTFS} of=${SDCARD} conv=notrunc seek=1 bs=$(expr ${BOOT_SPACE_ALIGNED} \* 1024 + ${IMAGE_ROOTFS_ALIGNMENT} \* 1024) && sync && sync
# Burn bootloader, boot and rootfs partitions
dd if=${DEPLOY_DIR_IMAGE}/${UBOOT_SYMLINK} of=${SDIMG} conv=notrunc,fsync seek=$(expr 1024 \* 2 \+ 1) bs=512
dd if=${SDIMG_BOOTFS} of=${SDIMG} conv=notrunc,fsync seek=1 bs=$(expr ${IMAGE_ROOTFS_ALIGNMENT} \* 1024)
dd if=${SDIMG_ROOTFS} of=${SDIMG} conv=notrunc,fsync seek=1 bs=$(expr ${IMAGE_ROOTFS_ALIGNMENT} \* 1024 + ${BOOT_SPACE_ALIGNED} \* 1024)
}
# The sdcard image requires the boot and rootfs images to be built before
IMAGE_TYPEDEP_sdcard = "${SDIMG_BOOTFS_TYPE} ${SDIMG_ROOTFS_TYPE}"

View File

@ -27,10 +27,9 @@ BT_TTY ?= "${@base_conditional('IS_KERNEL_2X', '1' , 'ttySP0', 'ttyAPP0', d)}"
CON_TTY ?= "${@base_conditional('IS_KERNEL_2X', '1' , 'ttyAM0', 'ttyAMA0', d)}"
# U-Boot script to be copied to the SD image
BOOT_SCRIPTS = "boot-sd.scr:boot.scr"
BOOT_SCRIPTS = "boot.scr:boot.scr"
# Flash image types
SDCARD_ROOTFS ?= "${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.ext4"
IMAGE_FSTYPES ?= "jffs2.sum sdcard tar.bz2 ubifs"
# FLASH parameters

View File

@ -30,12 +30,8 @@ SERIAL_CONSOLES = "115200;ttymxc3"
# Bluetooth tty
BT_TTY ?= "ttymxc1"
# U-Boot script to be copied to the SD image
BOOT_SCRIPTS = "boot-sd.scr:boot.scr"
# Boot partition size in KiB, (default 64MiB)
BOARD_BOOTIMAGE_PARTITION_SIZE ?= "65536"
# U-Boot script to be copied to the boot image
BOOT_SCRIPTS = "boot.scr:boot.scr"
# Flash image types
SDCARD_ROOTFS ?= "${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.ext4"
IMAGE_FSTYPES ?= "boot.vfat ext4 sdcard tar.bz2"

View File

@ -1,3 +1,3 @@
setenv kimg uimage
setenv kimg uimage-ccardimx28js.bin
setenv mmc_rpart /dev/mmcblk0p3
dboot linux mmc 0:2 fat

View File

@ -10,7 +10,7 @@
# | U-BOOT (RAW) | BOOT_PARTITION (FAT) | ROOTFS_PARTITION (EXT4) |
# +--------------+----------------------+-------------------------+
#
setenv fdtimg imx28-ccardimx28js.dtb
setenv kimg uimage
setenv fdtimg uimage-imx28-ccardimx28js.dtb
setenv kimg uimage-ccardimx28js.bin
setenv mmc_rpart /dev/mmcblk0p3
dboot linux mmc 0:2

View File

@ -1,16 +0,0 @@
#
# U-Boot bootscript for SD images created by Yocto.
#
# Layout:
# * U-Boot (raw copied)
# * Boot partion (FAT) with kernel images and DTB
# * Rootfs partion (EXT4)
#
# +--------------+----------------------+-------------------------+
# | U-BOOT (RAW) | BOOT_PARTITION (FAT) | ROOTFS_PARTITION (EXT4) |
# +--------------+----------------------+-------------------------+
#
setenv mmcroot /dev/mmcblk${mmcdev}p2
setenv uimage uImage
setenv fdt_file imx6q-${board}.dtb
dboot linux mmc ${mmcdev}:${mmcpart}

View File

@ -0,0 +1,11 @@
#
# U-Boot bootscript for EMMC/SD images created by Yocto.
#
# To detect if we are booting from SD card we get the UUID of the
# boot partition and compare with the default one for the EMMC
part uuid mmc ${mmcdev}:${mmcpart} bootpart
if test "${bootpart}" != "${part1_uuid}"; then
setenv mmcroot /dev/mmcblk${mmcdev}p2
fi
dboot linux mmc ${mmcdev}:${mmcpart}

View File

@ -9,7 +9,7 @@ PROVIDES += "u-boot"
LICENSE = "GPLv2+"
LIC_FILES_CHKSUM = "file://COPYING;md5=4c6cde5df68eff615d36789dc18edd3b"
SRC_URI_append_mxs = " file://boot-sd.txt"
SRC_URI_append_mxs = " file://boot.txt"
S = "${WORKDIR}/git"
@ -19,7 +19,7 @@ EXTRA_OEMAKE += 'HOSTSTRIP=true'
EXTRA_OEMAKE_append_mxs = ' BOOTLETS_DIR=${STAGING_DIR_TARGET}/boot'
do_deploy_append_mxs() {
mkimage -T script -n bootscript -C none -d ${WORKDIR}/boot-sd.txt ${DEPLOYDIR}/boot-sd.scr
mkimage -T script -n bootscript -C none -d ${WORKDIR}/boot.txt ${DEPLOYDIR}/boot.scr
}
COMPATIBLE_MACHINE = "(mxs|mx5)"

View File

@ -9,7 +9,7 @@ PROVIDES += "u-boot"
LICENSE = "GPLv2+"
LIC_FILES_CHKSUM = "file://COPYING;md5=1707d6db1d42237583f50183a5651ecb"
SRC_URI += "file://boot-sd.txt"
SRC_URI += "file://boot.txt"
S = "${WORKDIR}/git"
@ -20,7 +20,7 @@ do_compile_prepend() {
}
do_deploy_append() {
mkimage -T script -n bootscript -C none -d ${WORKDIR}/boot-sd.txt ${DEPLOYDIR}/boot-sd.scr
mkimage -T script -n bootscript -C none -d ${WORKDIR}/boot.txt ${DEPLOYDIR}/boot.scr
}
COMPATIBLE_MACHINE = "(ccardimx28)"

View File

@ -9,7 +9,7 @@ PROVIDES += "u-boot"
LICENSE = "GPLv2+"
LIC_FILES_CHKSUM = "file://COPYING;md5=1707d6db1d42237583f50183a5651ecb"
SRC_URI += "file://boot-sd.txt"
SRC_URI += "file://boot.txt"
S = "${WORKDIR}/git"
@ -20,7 +20,7 @@ do_compile_prepend() {
}
do_deploy_append() {
mkimage -T script -n bootscript -C none -d ${WORKDIR}/boot-sd.txt ${DEPLOYDIR}/boot-sd.scr
mkimage -T script -n bootscript -C none -d ${WORKDIR}/boot.txt ${DEPLOYDIR}/boot.scr
}
COMPATIBLE_MACHINE = "(ccimx6)"