From 83534159576f9bf35f05f0b285aec06a7d4ef737 Mon Sep 17 00:00:00 2001 From: Otavio Salvador Date: Mon, 19 Mar 2012 19:55:45 +0000 Subject: Major refactor in SDCard generation The generation of SDCard has been completely refactored to work out of box; now to use it you have to set, e.g: SDCARD_ROOTFS = "${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.ext3" SDCARD_SIZE = "128" IMAGE_TYPES += "ext3 sdcard" Now the sdcard has following layout: 0 - 1M - reserved to bootloader and other data 1M - BOOT_SPACE - kernel BOOT_SPACE - SDCARD_SIZE - rootfs All current supported machines on BSP will work out of box and generate a 2GB SDCard with an ext3 rootfs on it. Signed-off-by: Otavio Salvador --- classes/image_types_fsl.bbclass | 76 +++++++++++++++++++++++++++++++++++++++++ classes/sdcard_image.bbclass | 55 ----------------------------- 2 files changed, 76 insertions(+), 55 deletions(-) create mode 100644 classes/image_types_fsl.bbclass delete mode 100644 classes/sdcard_image.bbclass (limited to 'classes') diff --git a/classes/image_types_fsl.bbclass b/classes/image_types_fsl.bbclass new file mode 100644 index 0000000..3ae0b17 --- /dev/null +++ b/classes/image_types_fsl.bbclass @@ -0,0 +1,76 @@ +inherit image_types + +IMAGE_BOOTLOADER ?= "u-boot" + +# Handle u-boot suffixes +UBOOT_SUFFIX ?= "bin" + +# +# Create an image that can by written onto a SD card using dd. +# +# External variables needed: +# ${SDCARD_ROOTFS} - the rootfs image to incorporate +# ${IMAGE_BOOTLOADER} - bootloader to use {u-boot, barebox}x +# +# The disk layout used is: +# +# 0 - 1M - reserved to bootloader and other data +# 1M - BOOT_SPACE - kernel +# BOOT_SPACE - SDCARD_SIZE - rootfs +# + +# Default to 3.4GiB images +SDCARD_SIZE ?= "3400" + +# Boot partition volume id +BOOTDD_VOLUME_ID ?= "Boot ${MACHINE}" + +# Addional space for boot partition +BOOT_SPACE ?= "5M" + +IMAGE_DEPENDS_sdcard = "parted-native dosfstools-native mtools-native \ + virtual/kernel ${IMAGE_BOOTLOADER}" + +IMAGE_CMD_sdcard () { + if [ -z "${SDCARD_ROOTFS}" ]; then + bberror "SDCARD_ROOTFS is undefined. To use sdcard image from Freescale's BSP it needs to be defined." + exit 1 + fi + + TMP=${WORKDIR}/tmp + SDCARD=${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.sdcard + + dd if=/dev/zero of=${SDCARD} bs=$(expr 1000 \* 1000) count=${SDCARD_SIZE} + + # Create partition table + parted -s ${SDCARD} mklabel msdos + parted -s ${SDCARD} mkpart primary 0 1M + parted -s ${SDCARD} mkpart primary 1M ${BOOT_SPACE} + parted -s ${SDCARD} mkpart primary ${BOOT_SPACE} 100% + parted ${SDCARD} print + + case "${IMAGE_BOOTLOADER}" in + u-boot) + dd if=${DEPLOY_DIR_IMAGE}/u-boot-${MACHINE}.${UBOOT_SUFFIX} of=${SDCARD} conv=notrunc seek=2 bs=512 + ;; + barebox) + dd if=${DEPLOY_DIR_IMAGE}/barebox-${MACHINE}.bin of=${SDCARD} conv=notrunc seek=1 skip=1 bs=512 + dd if=${DEPLOY_DIR_IMAGE}/bareboxenv-${MACHINE}.bin of=${SDCARD} conv=notrunc seek=1 bs=512k + ;; + *) + bberror "Unkown IMAGE_BOOTLOADER value" + exit 1 + ;; + esac + + BOOT_BLOCKS=$(LC_ALL=C parted -s ${SDCARD} unit b print \ + | awk '/ 2 / { print substr($3, 1, length($3 -1)) / 512 }') + mkfs.vfat -n "${BOOTDD_VOLUME_ID}" -S 512 -C ${WORKDIR}/boot.img $BOOT_BLOCKS + mcopy -i ${WORKDIR}/boot.img -s ${DEPLOY_DIR_IMAGE}/uImage-${MACHINE}.bin ::/uImage + + dd if=${WORKDIR}/boot.img of=${SDCARD} conv=notrunc seek=1 bs=1M + dd if=${SDCARD_ROOTFS} of=${SDCARD} conv=notrunc seek=1 bs=${BOOT_SPACE} + + cd ${DEPLOY_DIR_IMAGE} + ln -sf ${IMAGE_NAME}.sdcard ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.sdcard +} diff --git a/classes/sdcard_image.bbclass b/classes/sdcard_image.bbclass deleted file mode 100644 index 96f7080..0000000 --- a/classes/sdcard_image.bbclass +++ /dev/null @@ -1,55 +0,0 @@ -# -# Create an image that can by written onto a SD card using dd. -# -# External variables needed: -# ${ROOTFS} - the rootfs image to incorporate -# ${IMAGE_BOOTLOADER} - bootloader to use {u-boot, barebox}x - -inherit image - -IMAGE_BOOTLOADER ?= "u-boot" - -do_rootfs[depends] += "parted-native:do_populate_sysroot \ - virtual/kernel:do_deploy \ - ${IMAGE_BOOTLOADER}:do_deploy" - -# Add the fstypes we need -IMAGE_FSTYPES += "sdimg" - -# Default to 3.4GiB images -SDIMG_SIZE ?= "3400" - -# Addional space for boot partition -BOOT_SPACE ?= "10M" - -IMAGE_CMD_sdimg () { - TMP=${WORKDIR}/tmp - SDIMG=${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.sdimg - - dd if=/dev/zero of=${SDIMG} bs=$(expr 1000 \* 1000) count=${SDIMG_SIZE} - - # Create partition table - parted -s ${SDIMG} mklabel msdos - parted -s ${SDIMG} mkpart primary ${BOOT_SPACE} 100% - parted ${SDIMG} print - - case "${IMAGE_BOOTLOADER}" in - u-boot) - dd if=${DEPLOY_DIR_IMAGE}/u-boot-${MACHINE}.bin of=${SDIMG} conv=notrunc seek=1 skip=1 bs=512 - dd if=${DEPLOY_DIR_IMAGE}/uImage-${MACHINE}.bin of=${SDIMG} conv=notrunc seek=1 bs=1M - ;; - barebox) - dd if=${DEPLOY_DIR_IMAGE}/barebox-${MACHINE}.bin of=${SDIMG} conv=notrunc seek=1 skip=1 bs=512 - dd if=${DEPLOY_DIR_IMAGE}/bareboxenv-${MACHINE}.bin of=${SDIMG} conv=notrunc seek=1 bs=512k - ;; - *) - bberror "Unkown IMAGE_BOOTLOADER value" - exit 1 - ;; - esac - - dd if=${ROOTFS} of=${SDIMG} conv=notrunc seek=1 bs=${BOOT_SPACE} - - cd ${DEPLOY_DIR_IMAGE} - ln -sf ${IMAGE_NAME}.sdimg ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.sdimg -} -- cgit v1.2.3-54-g00ecf