diff options
| -rw-r--r-- | classes/sdcard_image-rpi.bbclass | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/classes/sdcard_image-rpi.bbclass b/classes/sdcard_image-rpi.bbclass index 3774318..05087b5 100644 --- a/classes/sdcard_image-rpi.bbclass +++ b/classes/sdcard_image-rpi.bbclass | |||
| @@ -13,14 +13,14 @@ inherit image_types | |||
| 13 | # Default Free space = 1.3x | 13 | # Default Free space = 1.3x |
| 14 | # Use IMAGE_OVERHEAD_FACTOR to add more space | 14 | # Use IMAGE_OVERHEAD_FACTOR to add more space |
| 15 | # <---------> | 15 | # <---------> |
| 16 | # 4KiB 20MiB SDIMG_ROOTFS | 16 | # 4MiB 20MiB SDIMG_ROOTFS |
| 17 | # <-----------------------> <----------> <----------------------> | 17 | # <-----------------------> <----------> <----------------------> |
| 18 | # ------------------------ ------------ ------------------------ ------------------------------- | 18 | # ------------------------ ------------ ------------------------ |
| 19 | # | IMAGE_ROOTFS_ALIGNMENT | BOOT_SPACE | ROOTFS_SIZE | IMAGE_ROOTFS_ALIGNMENT | | 19 | # | IMAGE_ROOTFS_ALIGNMENT | BOOT_SPACE | ROOTFS_SIZE | |
| 20 | # ------------------------ ------------ ------------------------ ------------------------------- | 20 | # ------------------------ ------------ ------------------------ |
| 21 | # ^ ^ ^ ^ ^ | 21 | # ^ ^ ^ ^ |
| 22 | # | | | | | | 22 | # | | | | |
| 23 | # 0 4096 4KiB + 20MiB 4KiB + 20Mib + SDIMG_ROOTFS 4KiB + 20MiB + SDIMG_ROOTFS + 4KiB | 23 | # 0 4MiB 4MiB + 20MiB 4MiB + 20Mib + SDIMG_ROOTFS |
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | # Set kernel and boot loader | 26 | # Set kernel and boot loader |
| @@ -29,7 +29,7 @@ IMAGE_BOOTLOADER ?= "bcm2835-bootfiles" | |||
| 29 | # Boot partition volume id | 29 | # Boot partition volume id |
| 30 | BOOTDD_VOLUME_ID ?= "${MACHINE}" | 30 | BOOTDD_VOLUME_ID ?= "${MACHINE}" |
| 31 | 31 | ||
| 32 | # Boot partition size [in KiB] | 32 | # Boot partition size [in KiB] (will be rounded up to IMAGE_ROOTFS_ALIGNMENT) |
| 33 | BOOT_SPACE ?= "20480" | 33 | BOOT_SPACE ?= "20480" |
| 34 | 34 | ||
| 35 | # Set alignment to 4MB [in KiB] | 35 | # Set alignment to 4MB [in KiB] |
| @@ -60,18 +60,24 @@ IMAGE_CMD_rpi-sdimg () { | |||
| 60 | # Align partitions | 60 | # Align partitions |
| 61 | BOOT_SPACE_ALIGNED=$(expr ${BOOT_SPACE} + ${IMAGE_ROOTFS_ALIGNMENT} - 1) | 61 | BOOT_SPACE_ALIGNED=$(expr ${BOOT_SPACE} + ${IMAGE_ROOTFS_ALIGNMENT} - 1) |
| 62 | BOOT_SPACE_ALIGNED=$(expr ${BOOT_SPACE_ALIGNED} - ${BOOT_SPACE_ALIGNED} % ${IMAGE_ROOTFS_ALIGNMENT}) | 62 | BOOT_SPACE_ALIGNED=$(expr ${BOOT_SPACE_ALIGNED} - ${BOOT_SPACE_ALIGNED} % ${IMAGE_ROOTFS_ALIGNMENT}) |
| 63 | SDIMG_SIZE=$(expr ${IMAGE_ROOTFS_ALIGNMENT} + ${BOOT_SPACE_ALIGNED} + $ROOTFS_SIZE + ${IMAGE_ROOTFS_ALIGNMENT}) | 63 | ROOTFS_SIZE=`du -bks ${SDIMG_ROOTFS} | awk '{print $1}'` |
| 64 | # Round up RootFS size to the alignment size as well | ||
| 65 | ROOTFS_SIZE_ALIGNED=$(expr ${ROOTFS_SIZE} + ${IMAGE_ROOTFS_ALIGNMENT} - 1) | ||
| 66 | ROOTFS_SIZE_ALIGNED=$(expr ${ROOTFS_SIZE_ALIGNED} - ${ROOTFS_SIZE_ALIGNED} % ${IMAGE_ROOTFS_ALIGNMENT}) | ||
| 67 | SDIMG_SIZE=$(expr ${IMAGE_ROOTFS_ALIGNMENT} + ${BOOT_SPACE_ALIGNED} + ${ROOTFS_SIZE_ALIGNED}) | ||
| 68 | |||
| 69 | echo "Creating filesystem with Boot partition ${BOOT_SPACE_ALIGNED} KiB and RootFS ${ROOTFS_SIZE_ALIGNED} KiB" | ||
| 64 | 70 | ||
| 65 | # Initialize sdcard image file | 71 | # Initialize sdcard image file |
| 66 | dd if=/dev/zero of=${SDIMG} bs=1 count=0 seek=$(expr 1024 \* ${SDIMG_SIZE}) | 72 | dd if=/dev/zero of=${SDIMG} bs=1024 count=0 seek=${SDIMG_SIZE} |
| 67 | 73 | ||
| 68 | # Create partition table | 74 | # Create partition table |
| 69 | parted -s ${SDIMG} mklabel msdos | 75 | parted -s ${SDIMG} mklabel msdos |
| 70 | # Create boot partition and mark it as bootable | 76 | # Create boot partition and mark it as bootable |
| 71 | parted -s ${SDIMG} unit KiB mkpart primary fat32 ${IMAGE_ROOTFS_ALIGNMENT} $(expr ${BOOT_SPACE_ALIGNED} \+ ${IMAGE_ROOTFS_ALIGNMENT}) | 77 | parted -s ${SDIMG} unit KiB mkpart primary fat32 ${IMAGE_ROOTFS_ALIGNMENT} $(expr ${BOOT_SPACE_ALIGNED} \+ ${IMAGE_ROOTFS_ALIGNMENT}) |
| 72 | parted -s ${SDIMG} set 1 boot on | 78 | parted -s ${SDIMG} set 1 boot on |
| 73 | # Create rootfs partition | 79 | # Create rootfs partition to the end of disk |
| 74 | parted -s ${SDIMG} unit KiB mkpart primary ext2 $(expr ${BOOT_SPACE_ALIGNED} \+ ${IMAGE_ROOTFS_ALIGNMENT}) $(expr ${BOOT_SPACE_ALIGNED} \+ ${IMAGE_ROOTFS_ALIGNMENT} \+ ${ROOTFS_SIZE}) | 80 | parted -s ${SDIMG} -- unit KiB mkpart primary ext2 $(expr ${BOOT_SPACE_ALIGNED} \+ ${IMAGE_ROOTFS_ALIGNMENT}) -1s |
| 75 | parted ${SDIMG} print | 81 | parted ${SDIMG} print |
| 76 | 82 | ||
| 77 | # Create a vfat image with boot files | 83 | # Create a vfat image with boot files |
