meta-digi: support generation of sdcard images for ccardimx28js

https://jira.digi.com/browse/DEL-197

Signed-off-by: Javier Viguera <javier.viguera@digi.com>
This commit is contained in:
Javier Viguera 2015-01-09 19:13:33 +01:00
parent 141a8f9d5f
commit 0a5aa1c24d
4 changed files with 117 additions and 3 deletions

View File

@ -57,3 +57,88 @@ IMAGE_CMD_rootfs.initramfs() {
fi
}
IMAGE_TYPEDEP_rootfs.initramfs = "cpio.gz"
SDCARD_GENERATION_COMMAND_ccardimx28js = "generate_ccardimx28js_sdcard"
#
# 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
#
# The disk layout used is:
#
# 1M -> IMAGE_ROOTFS_ALIGNMENT - u-boot bootstream
# IMAGE_ROOTFS_ALIGNMENT -> BOOT_SPACE - kernel + devide tree blob (VFAT partition)
# BOOT_SPACE -> SDIMG_SIZE - rootfs (EXT4 partition)
#
# 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
#
generate_ccardimx28js_sdcard() {
#
# Bootstream header for u-boot at 1M offset
#
# The offset is coded in bytes 29-32 in little-endian. The
# value to set is the offset in 512 bytes blocks + 1.
#
# For 1M offset we can calculate the bytes:
#
# printf '%08x' 2049 | grep -o .. | tac | tr -d '\n'
#
BS_HDR="\x33\x22\x11\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x08\x00\x00\x00\x00\x00\x00"
# Use 'printf' command and not shell builtins because hexadecimal
# 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)
# Change partition type to 0x53 for mxs processor family
echo -n S | dd of=${SDCARD} bs=1 count=1 seek=450 conv=notrunc
${PRINTF} "${BS_HDR}" | dd of=${SDCARD} bs=512 seek=$(expr 1024 \* 2) conv=notrunc,sync
dd if=${DEPLOY_DIR_IMAGE}/u-boot-${MACHINE}.${UBOOT_SUFFIX} 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
}

View File

@ -16,6 +16,15 @@ SERIAL_CONSOLES_CHECK ?= "${SERIAL_CONSOLES}"
# Bluetooth tty
BT_TTY ?= "${@base_conditional('IS_KERNEL_2X', '1' , 'ttySP0', 'ttyAPP0', d)}"
# U-Boot script to be copied to the SD image
BOOT_SCRIPTS = "boot-sd.scr:boot.scr"
# Rootfs image for rootfs partition in sdcard image
SDCARD_ROOTFS ?= "${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.ext4"
# Build sdcard image for ccardimx28js
IMAGE_FSTYPES += "sdcard"
# FLASH parameters
MKUBIFS_ARGS ?= "-m 2048 -e 126976 -c 2047"
EXTRA_IMAGECMD_jffs2 ?= "-l -e 128 -n"

View File

@ -0,0 +1,16 @@
#
# 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 fdtimg imx28-ccardimx28js.dtb
setenv kimg uimage
setenv mmc_rpart /dev/mmcblk0p3
dboot linux mmc 0:2

View File

@ -9,15 +9,19 @@ PROVIDES += "u-boot"
LICENSE = "GPLv2+"
LIC_FILES_CHKSUM = "file://COPYING;md5=1707d6db1d42237583f50183a5651ecb"
PR = "r0"
SRC_URI += "file://boot-sd.txt"
S = "${WORKDIR}/git"
DEPENDS_mxs += "elftosb-native"
DEPENDS_ccardimx28 += "elftosb-native"
do_compile_prepend() {
${S}/tools/setlocalversion --save-scmversion ${S}
}
do_deploy_append() {
mkimage -T script -n bootscript -C none -d ${WORKDIR}/boot-sd.txt ${DEPLOYDIR}/boot-sd.scr
}
PACKAGE_ARCH = "${MACHINE_ARCH}"
COMPATIBLE_MACHINE = "(mxs)"
COMPATIBLE_MACHINE = "(ccardimx28)"