forked from balena-os/meta-artik
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
artik-sdimage.bbclass: Generate bootable artik10 SDcard images
The image class is inspired from meta-amlogic or meta-rasberrypi. While blackmagic uboot params' offsets are: 0x00080e00: artik5 (1031*512) 0x00099e00: artik10 (1231*512) And comming from this file : https://github.com/resin-os/resin-artik/blob/master/layers/meta-resin-artik/recipes-core/images/resin-image.inc Change-Id: Ib40d7cd83c92c35e864a91d38e2f01b4a032b228 Credits-to: Florin Sarbu <florin@resin.io> Bug: balena-os#9 Origin: http://github.com/TizenTeam/meta-artik Signed-off-by: Philippe Coval <philippe.coval@osg.samsung.com>
- Loading branch information
Showing
4 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
inherit image_types | ||
|
||
# | ||
# Create an image that can by written onto a SD card using dd. | ||
# | ||
# The disk layout used is: | ||
# | ||
# 0 -> IMAGE_ROOTFS_ALIGNMENT - reserved for other data | ||
# IMAGE_ROOTFS_ALIGNMENT -> BOOT_SPACE - bootloader and kernel | ||
# BOOT_SPACE -> SDIMG_SIZE - rootfs | ||
# | ||
|
||
# Default Free space = 1.3x | ||
# Use IMAGE_OVERHEAD_FACTOR to add more space | ||
# <---------> | ||
# 4MiB 20MiB SDIMG_ROOTFS | ||
# <-----------------------> <----------> <----------------------> | ||
# ------------------------ ------------ ------------------------ | ||
# | IMAGE_ROOTFS_ALIGNMENT | BOOT_SPACE | ROOTFS_SIZE | | ||
# ------------------------ ------------ ------------------------ | ||
# ^ ^ ^ ^ | ||
# | | | | | ||
# 0 4MiB 4MiB + 20MiB 4MiB + 20Mib + SDIMG_ROOTFS | ||
|
||
# This image depends on the rootfs image | ||
IMAGE_TYPEDEP_artik-sdimg = "${SDIMG_ROOTFS_TYPE}" | ||
|
||
# Set initramfs extension | ||
KERNEL_INITRAMFS ?= "" | ||
|
||
# Boot partition volume id | ||
BOOTDD_VOLUME_ID ?= "BOOT" | ||
|
||
# Boot partition size [in KiB] (will be rounded up to IMAGE_ROOTFS_ALIGNMENT) | ||
BOOT_SPACE ?= "20480" | ||
|
||
# Set alignment to 4MB [in KiB] | ||
IMAGE_ROOTFS_ALIGNMENT = "4096" | ||
|
||
# Use an uncompressed ext4 by default as rootfs | ||
SDIMG_ROOTFS_TYPE ?= "ext4" | ||
SDIMG_ROOTFS = "${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.${SDIMG_ROOTFS_TYPE}" | ||
|
||
IMAGE_DEPENDS_artik-sdimg = " \ | ||
parted-native \ | ||
mtools-native \ | ||
dosfstools-native \ | ||
e2fsprogs-native \ | ||
virtual/kernel \ | ||
u-boot \ | ||
" | ||
# Exynos Boot magic | ||
BL1_SYMLINK ?= "bl1.bin" | ||
BL2_SYMLINK ?= "bl2.bin" | ||
TZSW_SYMLINK ?= "tzsw.bin" | ||
|
||
# U-Boot | ||
UBOOT_SUFFIX ?= "bin" | ||
UBOOT_SYMLINK ?= "u-boot-${MACHINE}.${UBOOT_SUFFIX}" | ||
BL1_OFFSET ?= "1" | ||
BL2_OFFSET ?= "31" | ||
UBOOT_OFFSET ?= "63" | ||
TZSW_OFFSET ?= "719" | ||
# To be adapted by machine, here artik10 is used as reference | ||
UBOOT_PARAMS_OFFSET ?= "1231" | ||
UBOOT_PARAMS="params_sd.${UBOOT_SUFFIX}" | ||
|
||
# SD card image name | ||
SDIMG = "${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.artik-sdimg" | ||
|
||
IMAGE_CMD_artik-sdimg () { | ||
|
||
# Align partitions | ||
BOOT_SPACE_ALIGNED=$(expr ${BOOT_SPACE} + ${IMAGE_ROOTFS_ALIGNMENT} - 1) | ||
BOOT_SPACE_ALIGNED=$(expr ${BOOT_SPACE_ALIGNED} - ${BOOT_SPACE_ALIGNED} % ${IMAGE_ROOTFS_ALIGNMENT}) | ||
ROOTFS_SIZE=`du -bks ${SDIMG_ROOTFS} | awk '{print $1}'` | ||
# Round up RootFS size to the alignment size as well | ||
ROOTFS_SIZE_ALIGNED=$(expr ${ROOTFS_SIZE} + ${IMAGE_ROOTFS_ALIGNMENT} - 1) | ||
ROOTFS_SIZE_ALIGNED=$(expr ${ROOTFS_SIZE_ALIGNED} - ${ROOTFS_SIZE_ALIGNED} % ${IMAGE_ROOTFS_ALIGNMENT}) | ||
SDIMG_SIZE=$(expr ${IMAGE_ROOTFS_ALIGNMENT} + ${BOOT_SPACE_ALIGNED} + ${ROOTFS_SIZE_ALIGNED}) | ||
|
||
echo "Creating filesystem with Boot partition ${BOOT_SPACE_ALIGNED} KiB and RootFS ${ROOTFS_SIZE_ALIGNED} KiB" | ||
|
||
# Initialize sdcard image file | ||
dd if=/dev/zero of=${SDIMG} bs=1024 count=0 seek=${SDIMG_SIZE} | ||
|
||
# Create partition table | ||
parted -s ${SDIMG} mklabel msdos | ||
|
||
# Create boot partition and mark it as bootable | ||
parted -s ${SDIMG} unit KiB mkpart primary fat32 ${IMAGE_ROOTFS_ALIGNMENT} $(expr ${BOOT_SPACE_ALIGNED} \+ ${IMAGE_ROOTFS_ALIGNMENT}) | ||
parted -s ${SDIMG} set 1 boot on | ||
|
||
# Create rootfs partition to the end of disk | ||
parted -s ${SDIMG} -- unit KiB mkpart primary ext2 $(expr ${BOOT_SPACE_ALIGNED} \+ ${IMAGE_ROOTFS_ALIGNMENT}) -1s | ||
|
||
# Set boot flag | ||
parted -s ${SDIMG} set 1 boot on | ||
parted ${SDIMG} print | ||
|
||
# Create a vfat image with boot files | ||
BOOT_BLOCKS=$(LC_ALL=C parted -s ${SDIMG} unit b print | awk '/ 1 / { print substr($4, 1, length($4 -1)) / 512 /2 }') | ||
rm -f ${WORKDIR}/boot.img | ||
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} ::${KERNEL_IMAGETYPE} | ||
if test -n "${KERNEL_DEVICETREE}"; then | ||
mcopy -i ${WORKDIR}/boot.img -s ${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE}-${KERNEL_DEVICETREE} ::${KERNEL_DEVICETREE} | ||
fi | ||
|
||
if [ -n ${FATPAYLOAD} ] ; then | ||
echo "Copying payload into VFAT" | ||
for entry in ${FATPAYLOAD} ; do | ||
# add the || true to stop aborting on vfat issues like not supporting .~lock files | ||
mcopy -i ${WORKDIR}/boot.img -s -v ${IMAGE_ROOTFS}$entry :: || true | ||
done | ||
fi | ||
|
||
# Add stamp file | ||
echo "${IMAGE_NAME}-${IMAGEDATESTAMP}" > ${WORKDIR}/image-version-info | ||
mcopy -i ${WORKDIR}/boot.img -v ${WORKDIR}/image-version-info :: | ||
|
||
# Burn exynos's intial bootloader BL1 | ||
dd if=${DEPLOY_DIR_IMAGE}/${BL1_SYMLINK} of=${SDIMG} bs=512 seek=${BL1_OFFSET} conv=notrunc | ||
dd if=${DEPLOY_DIR_IMAGE}/${BL2_SYMLINK} of=${SDIMG} bs=512 seek=${BL2_OFFSET} conv=notrunc | ||
dd if=${DEPLOY_DIR_IMAGE}/${TZSW_SYMLINK} of=${SDIMG} bs=512 seek=${TZSW_OFFSET} conv=notrunc | ||
dd if=${DEPLOY_DIR_IMAGE}/${UBOOT_PARAMS} of=${SDIMG} bs=512 seek=${UBOOT_PARAMS_OFFSET} conv=notrunc | ||
|
||
# Burn u-boot | ||
dd if=${DEPLOY_DIR_IMAGE}/${UBOOT_SYMLINK} of=${SDIMG} bs=512 seek=${UBOOT_OFFSET} conv=notrunc | ||
|
||
# Burn Partitions | ||
dd if=${WORKDIR}/boot.img of=${SDIMG} conv=notrunc seek=1 bs=$(expr ${IMAGE_ROOTFS_ALIGNMENT} \* 1024) && sync && sync | ||
# If SDIMG_ROOTFS_TYPE is a .xz file use xzcat | ||
if echo "${SDIMG_ROOTFS_TYPE}" | egrep -q "*\.xz" | ||
then | ||
xzcat ${SDIMG_ROOTFS} | dd of=${SDIMG} conv=notrunc seek=1 bs=$(expr 1024 \* ${BOOT_SPACE_ALIGNED} + ${IMAGE_ROOTFS_ALIGNMENT} \* 1024) && sync && sync | ||
else | ||
dd if=${SDIMG_ROOTFS} of=${SDIMG} conv=notrunc seek=1 bs=$(expr 1024 \* ${BOOT_SPACE_ALIGNED} + ${IMAGE_ROOTFS_ALIGNMENT} \* 1024) && sync && sync | ||
fi | ||
} |
This file contains 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
This file contains 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
This file contains 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