diff options
| author | Dalon Westergreen <dwesterg@gmail.com> | 2016-04-18 18:55:44 -0700 |
|---|---|---|
| committer | Dalon Westergreen <dwesterg@gmail.com> | 2016-04-18 18:55:44 -0700 |
| commit | b27593878e1b9b51b4b3cb36639959d4744724bd (patch) | |
| tree | 82c7aa5c9ca5ae0d5f27f3f71f53eaa9078f3a98 | |
| parent | 049b223896ce569304e565f608c6a03bf2342aa6 (diff) | |
| download | meta-altera-b27593878e1b9b51b4b3cb36639959d4744724bd.tar.gz | |
Testing sdcard
| -rw-r--r-- | classes/image_types_socfpga.bbclass | 134 | ||||
| -rw-r--r-- | recipes-bsp/u-boot/u-boot-target-env.inc | 69 |
2 files changed, 203 insertions, 0 deletions
diff --git a/classes/image_types_socfpga.bbclass b/classes/image_types_socfpga.bbclass new file mode 100644 index 0000000..609e651 --- /dev/null +++ b/classes/image_types_socfpga.bbclass | |||
| @@ -0,0 +1,134 @@ | |||
| 1 | inherit image_types | ||
| 2 | |||
| 3 | IMAGE_BOOTLOADER ?= "u-boot-socfpga" | ||
| 4 | SDCARD_ROOTFS ?= "${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.ext3" | ||
| 5 | |||
| 6 | # Boot partition size [in KiB] | ||
| 7 | IMAGE_ROOTFS_ALIGNMENT_cyclone5 ?= "2048" | ||
| 8 | IMAGE_ROOTFS_ALIGNMENT_arria5 ?= "2048" | ||
| 9 | IMAGE_ROOTFS_ALIGNMENT_arria10 ?= "10240" | ||
| 10 | |||
| 11 | BOOT_SPACE ?= "102400" | ||
| 12 | |||
| 13 | IMAGE_DEPENDS_sdcard = "parted-native:do_populate_sysroot \ | ||
| 14 | dosfstools-native:do_populate_sysroot \ | ||
| 15 | mtools-native:do_populate_sysroot \ | ||
| 16 | virtual/kernel:do_deploy \ | ||
| 17 | ${@d.getVar('IMAGE_BOOTLOADER', True) and d.getVar('IMAGE_BOOTLOADER', True) + ':do_deploy' or ''}" | ||
| 18 | |||
| 19 | SDCARD_GENERATION_COMMAND_cyclone5 = "generate_28nm_sdcard" | ||
| 20 | SDCARD_GENERATION_COMMAND_arria5 = "generate_28nm_sdcard" | ||
| 21 | |||
| 22 | # | ||
| 23 | # Generate the boot image with the boot scripts and required Device Tree | ||
| 24 | # files | ||
| 25 | _generate_boot_image() { | ||
| 26 | local boot_part=$1 | ||
| 27 | |||
| 28 | # Create boot partition image | ||
| 29 | BOOT_BLOCKS=$(LC_ALL=C parted -s ${SDCARD} unit b print \ | ||
| 30 | | awk "/ $boot_part / { print substr(\$4, 1, length(\$4 -1)) / 1024 }") | ||
| 31 | |||
| 32 | # mkdosfs will sometimes use FAT16 when it is not appropriate, | ||
| 33 | # resulting in a boot failure from SYSLINUX. Use FAT32 for | ||
| 34 | # images larger than 512MB, otherwise let mkdosfs decide. | ||
| 35 | if [ $(expr $BOOT_BLOCKS / 1024) -gt 512 ]; then | ||
| 36 | FATSIZE="-F 32" | ||
| 37 | fi | ||
| 38 | |||
| 39 | rm -f ${WORKDIR}/boot.img | ||
| 40 | mkfs.vfat -n "${BOOTDD_VOLUME_ID}" -S 512 ${FATSIZE} -C ${WORKDIR}/boot.img $BOOT_BLOCKS | ||
| 41 | |||
| 42 | mcopy -i ${WORKDIR}/boot.img -s ${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE}-${MACHINE}.bin ::/${KERNEL_IMAGETYPE} | ||
| 43 | |||
| 44 | # Copy boot scripts | ||
| 45 | for item in ${BOOT_SCRIPTS}; do | ||
| 46 | src=`echo $item | awk -F':' '{ print $1 }'` | ||
| 47 | dst=`echo $item | awk -F':' '{ print $2 }'` | ||
| 48 | |||
| 49 | mcopy -i ${WORKDIR}/boot.img -s ${DEPLOY_DIR_IMAGE}/$src ::/$dst | ||
| 50 | done | ||
| 51 | |||
| 52 | # Copy device tree file | ||
| 53 | if test -n "${KERNEL_DEVICETREE}"; then | ||
| 54 | for DTS_FILE in ${KERNEL_DEVICETREE}; do | ||
| 55 | DTS_BASE_NAME=`basename ${DTS_FILE} | awk -F "." '{print $1}'` | ||
| 56 | if [ -e "${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE}-${DTS_BASE_NAME}.dtb" ]; then | ||
| 57 | kernel_bin="`readlink ${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE}-${MACHINE}.bin`" | ||
| 58 | kernel_bin_for_dtb="`readlink ${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE}-${DTS_BASE_NAME}.dtb | sed "s,$DTS_BASE_NAME,${MACHINE},g;s,\.dtb$,.bin,g"`" | ||
| 59 | if [ $kernel_bin = $kernel_bin_for_dtb ]; then | ||
| 60 | mcopy -i ${WORKDIR}/boot.img -s ${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE}-${DTS_BASE_NAME}.dtb ::/${DTS_BASE_NAME}.dtb | ||
| 61 | fi | ||
| 62 | else | ||
| 63 | bbfatal "${DTS_FILE} does not exist." | ||
| 64 | fi | ||
| 65 | done | ||
| 66 | fi | ||
| 67 | } | ||
| 68 | |||
| 69 | generate_28nm_sdcard () { | ||
| 70 | # Create partition table | ||
| 71 | parted -s ${SDCARD} mklabel msdos | ||
| 72 | parted -s ${SDCARD} unit KiB mkpart primary fat32 ${IMAGE_ROOTFS_ALIGNMENT} $(expr ${IMAGE_ROOTFS_ALIGNMENT} \+ ${BOOT_SPACE_ALIGNED}) | ||
| 73 | parted -s ${SDCARD} unit KiB mkpart primary $(expr ${IMAGE_ROOTFS_ALIGNMENT} \+ ${BOOT_SPACE_ALIGNED}) $(expr ${IMAGE_ROOTFS_ALIGNMENT} \+ ${BOOT_SPACE_ALIGNED} \+ $ROOTFS_SIZE) | ||
| 74 | parted -s ${SDCARD} unit KiB mkpart primary 1024 2048 | ||
| 75 | |||
| 76 | #set part 3 to type a2 for spl / uboot image | ||
| 77 | echo -ne "\xa2" | dd of=${SDCARD} bs=1 count=1 seek=482 conv=notrunc | ||
| 78 | |||
| 79 | dd if=${DEPLOY_DIR_IMAGE}/${SPL_BINARY} of=${SDCARD} conv=notrunc seek=1 bs=$(expr 1024 \* 1024) | ||
| 80 | |||
| 81 | parted ${SDCARD} print | ||
| 82 | |||
| 83 | _generate_boot_image 1 | ||
| 84 | # Burn Partition | ||
| 85 | dd if=${WORKDIR}/boot.img of=${SDCARD} conv=notrunc,fsync seek=1 bs=$(expr ${IMAGE_ROOTFS_ALIGNMENT} \* 1024) | ||
| 86 | dd if=${SDCARD_ROOTFS} of=${SDCARD} conv=notrunc,fsync seek=1 bs=$(expr ${BOOT_SPACE_ALIGNED} \* 1024 + ${IMAGE_ROOTFS_ALIGNMENT} \* 1024) | ||
| 87 | |||
| 88 | # Burn uboot env | ||
| 89 | if [ -e "${DEPLOY_DIR_IMAGE}/u-boot-envs/${CONFIG_TYPE}.bin" ] | ||
| 90 | then | ||
| 91 | dd of=${DEPLOY_DIR_IMAGE}/u-boot-envs/${CONFIG_TYPE}.bin of=${SDCARD} bs=1 count=1 seek=512 | ||
| 92 | fi | ||
| 93 | } | ||
| 94 | |||
| 95 | IMAGE_CMD_sdcard () { | ||
| 96 | if [ -z "${SDCARD_ROOTFS}" ]; then | ||
| 97 | bberror "SDCARD_ROOTFS is undefined. To use sdcard image from Freescale's BSP it needs to be defined." | ||
| 98 | exit 1 | ||
| 99 | fi | ||
| 100 | |||
| 101 | # Align boot partition and calculate total SD card image size | ||
| 102 | BOOT_SPACE_ALIGNED=$(expr ${BOOT_SPACE} + ${IMAGE_ROOTFS_ALIGNMENT} - 1) | ||
| 103 | BOOT_SPACE_ALIGNED=$(expr ${BOOT_SPACE_ALIGNED} - ${BOOT_SPACE_ALIGNED} % ${IMAGE_ROOTFS_ALIGNMENT}) | ||
| 104 | SDCARD_SIZE=$(expr ${IMAGE_ROOTFS_ALIGNMENT} + ${BOOT_SPACE_ALIGNED} + $ROOTFS_SIZE + ${IMAGE_ROOTFS_ALIGNMENT}) | ||
| 105 | |||
| 106 | # Initialize a sparse file | ||
| 107 | SDCARD="${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.sdcard" | ||
| 108 | dd if=/dev/zero of=${SDCARD} bs=1 count=0 seek=$(expr 1024 \* ${SDCARD_SIZE}) | ||
| 109 | |||
| 110 | if [ "x${UBOOT_CONFIG}" != "x" ] | ||
| 111 | then | ||
| 112 | for config in ${UBOOT_MACHINE}; do | ||
| 113 | i=`expr $i + 1`; | ||
| 114 | for type in ${UBOOT_CONFIG}; do | ||
| 115 | j=`expr $j + 1`; | ||
| 116 | if [ $j -eq $i ] | ||
| 117 | then | ||
| 118 | CONFIG_TYPE="${type}" | ||
| 119 | UBOOT_SFP_IMAGE="${SPL_IMAGE}-${MACHINE}-${type}" | ||
| 120 | ${SDCARD_GENERATION_COMMAND} | ||
| 121 | fi | ||
| 122 | done | ||
| 123 | unset j | ||
| 124 | done | ||
| 125 | unset i | ||
| 126 | else | ||
| 127 | UBOOT_SFP_IMAGE="${SPL_IMAGE}-${MACHINE}" | ||
| 128 | ${SDCARD_GENERATION_COMMAND} | ||
| 129 | fi | ||
| 130 | } | ||
| 131 | |||
| 132 | # The sdcard requires the rootfs filesystem to be built before using | ||
| 133 | # it so we must make this dependency explicit. | ||
| 134 | IMAGE_TYPEDEP_sdcard = "${@d.getVar('SDCARD_ROOTFS', 1).split('.')[-1]}" \ No newline at end of file | ||
diff --git a/recipes-bsp/u-boot/u-boot-target-env.inc b/recipes-bsp/u-boot/u-boot-target-env.inc new file mode 100644 index 0000000..c418a16 --- /dev/null +++ b/recipes-bsp/u-boot/u-boot-target-env.inc | |||
| @@ -0,0 +1,69 @@ | |||
| 1 | # Handle severals environments generation for u-boot | ||
| 2 | |||
| 3 | #Env binary size | ||
| 4 | ENV_SIZE = "0x1000" | ||
| 5 | |||
| 6 | ENV_BIN_DIR = "${WORKDIR}/target_env_bin" | ||
| 7 | |||
| 8 | # Env deploy dir is the name of directory where binary envs will be deployed | ||
| 9 | ENV_DEPLOY_DIR="u-boot-envs" | ||
| 10 | |||
| 11 | # Env deploy src dir is the name of directory where txt envs will be deployed | ||
| 12 | ENV_SRC_DEPLOY_DIR="u-boot-envs-src" | ||
| 13 | |||
| 14 | do_build_mkimage_tool () { | ||
| 15 | HOSTCC="${CC}" HOSTLD="${LD}" HOSTLDFLAGS="${LDFLAGS}" HOSTSTRIP=true oe_runmake sandbox_defconfig | ||
| 16 | HOSTCC="${CC}" HOSTLD="${LD}" HOSTLDFLAGS="${LDFLAGS}" HOSTSTRIP=true oe_runmake tools | ||
| 17 | } | ||
| 18 | |||
| 19 | python do_environment_mkimage() { | ||
| 20 | import subprocess | ||
| 21 | import shutil | ||
| 22 | # list env variant target files | ||
| 23 | target_root_dir = d.getVar('WORKDIR',True) | ||
| 24 | # env files only for UBOOT_CONFIG | ||
| 25 | env_uboot_config = d.getVar('UBOOT_CONFIG',True) | ||
| 26 | env_files = [] | ||
| 27 | for f in os.listdir(target_root_dir): | ||
| 28 | if f.endswith(".env"): | ||
| 29 | env_files.append(os.path.join(target_root_dir,f)) | ||
| 30 | env_bin_dir = d.getVar("ENV_BIN_DIR",True) | ||
| 31 | # cleans if it exists env_bin directory | ||
| 32 | shutil.rmtree(env_bin_dir, ignore_errors=True) | ||
| 33 | # create env bin directory | ||
| 34 | os.mkdir(env_bin_dir) | ||
| 35 | print 'Building binary environments in : %s' % env_bin_dir | ||
| 36 | # iterate targets list to build binary environment files | ||
| 37 | for target_env in env_files : | ||
| 38 | # get only filename without path and extension | ||
| 39 | target_filename = os.path.splitext(os.path.basename(target_env))[0] | ||
| 40 | if target_filename not in env_uboot_config: | ||
| 41 | continue | ||
| 42 | # build output file path with ext | ||
| 43 | target_bin = os.path.join(env_bin_dir, | ||
| 44 | target_filename + '.bin') | ||
| 45 | # generated mkenvimage tool command line | ||
| 46 | cmd_mkimg ='cat %s | grep -v -E "^$|^\#" |' \ | ||
| 47 | ' ./tools/mkenvimage -s %s -r -o %s -' \ | ||
| 48 | % ( target_env, | ||
| 49 | d.getVar("ENV_SIZE",True), target_bin) | ||
| 50 | print 'Building binary for %s target:' % (target_filename) | ||
| 51 | print '%s' % cmd_mkimg | ||
| 52 | # execute shell command | ||
| 53 | ret = subprocess.call(cmd_mkimg, shell=True) | ||
| 54 | if ret: return ret | ||
| 55 | return 0 | ||
| 56 | } | ||
| 57 | |||
| 58 | do_deploy_append() { | ||
| 59 | install -d ${DEPLOYDIR} | ||
| 60 | # deploy binary U-boot environments | ||
| 61 | echo "Deploying U-boot Environments binary files in ${DEPLOYDIR}/${ENV_DEPLOY_DIR}" | ||
| 62 | install -d ${DEPLOYDIR}/${ENV_DEPLOY_DIR} | ||
| 63 | |||
| 64 | |||
| 65 | cp ${ENV_BIN_DIR}/*.bin ${DEPLOYDIR}/${ENV_DEPLOY_DIR} | ||
| 66 | } | ||
| 67 | |||
| 68 | addtask build_mkimage_tool after do_compile before do_environment_mkimage | ||
| 69 | addtask environment_mkimage after do_build_mkimage_tool before do_deploy | ||
