summaryrefslogtreecommitdiffstats
path: root/classes
diff options
context:
space:
mode:
authorAndrei Gherzan <andrei@gherzan.ro>2012-09-07 15:44:46 +0300
committerAndrei Gherzan <andrei@gherzan.ro>2012-09-12 23:21:28 +0300
commitb059c59f7192cb30799e6fead125855b057283fd (patch)
tree0c53cfa4854f5b5b264c9c82fb913d56d8492382 /classes
parentce246f83d67a3ab379550f47d90a89f24bdb2ee5 (diff)
downloadmeta-raspberrypi-b059c59f7192cb30799e6fead125855b057283fd.tar.gz
sdcard_image-rpi: Align SD partition and optimize final SD image
SD image file was 4G in size but actually the rootfs partition was only 60MB (ex.: rpi-basic-image). The image file size is not fixed anymore but calculated inside this class. In this way we will setup the partition for rootfs to fit the ext file used as SDIMG_ROOTFS. By default the free space is calculated with IMAGE_OVERHEAD_FACTOR which is by default 1.3. If more free space is needed this can be overwritten. IMAGE_ROOTFS_ALIGNMENT set at 4096. This should be the best value for a SD card. [GITHUB #20] [GITHUB #59] Signed-off-by: Andrei Gherzan <andrei@gherzan.ro>
Diffstat (limited to 'classes')
-rw-r--r--classes/sdcard_image-rpi.bbclass47
1 files changed, 33 insertions, 14 deletions
diff --git a/classes/sdcard_image-rpi.bbclass b/classes/sdcard_image-rpi.bbclass
index 725355e..de96e50 100644
--- a/classes/sdcard_image-rpi.bbclass
+++ b/classes/sdcard_image-rpi.bbclass
@@ -3,22 +3,35 @@
3# 3#
4# The disk layout used is: 4# The disk layout used is:
5# 5#
6# 0 - 1M - reserved for other data 6# 0 -> IMAGE_ROOTFS_ALIGNMENT - reserved for other data
7# 1M - BOOT_SPACE - bootloader and kernel 7# IMAGE_ROOTFS_ALIGNMENT -> BOOT_SPACE - bootloader and kernel
8# BOOT_SPACE - SDIMG_SIZE - rootfs 8# BOOT_SPACE -> SDIMG_SIZE - rootfs
9# 9#
10 10
11# Default Free space = 1.3x
12# Use IMAGE_OVERHEAD_FACTOR to add more space
13# <--------->
14# 4KiB 20MiB SDIMG_ROOTFS
15# <-----------------------> <----------> <---------------------->
16# ------------------------ ------------ ------------------------ -------------------------------
17# | IMAGE_ROOTFS_ALIGNMENT | BOOT_SPACE | ROOTFS_SIZE | IMAGE_ROOTFS_ALIGNMENT |
18# ------------------------ ------------ ------------------------ -------------------------------
19# ^ ^ ^ ^ ^
20# | | | | |
21# 0 4096 4KiB + 20MiB 4KiB + 20Mib + SDIMG_ROOTFS 4KiB + 20MiB + SDIMG_ROOTFS + 4KiB
22
23
11# Set kernel and boot loader 24# Set kernel and boot loader
12IMAGE_BOOTLOADER ?= "bcm2835-bootfiles" 25IMAGE_BOOTLOADER ?= "bcm2835-bootfiles"
13 26
14# Default to 1.4GiB images
15SDIMG_SIZE ?= "4000"
16
17# Boot partition volume id 27# Boot partition volume id
18BOOTDD_VOLUME_ID ?= "${MACHINE}" 28BOOTDD_VOLUME_ID ?= "${MACHINE}"
19 29
20# Addional space for boot partition 30# Boot partition size [in KiB]
21BOOT_SPACE ?= "20MiB" 31BOOT_SPACE ?= "20480"
32
33# Set alignment to 4MB [in KiB]
34IMAGE_ROOTFS_ALIGNMENT = "4096"
22 35
23# Use an uncompressed ext3 by default as rootfs 36# Use an uncompressed ext3 by default as rootfs
24SDIMG_ROOTFS_TYPE ?= "ext3" 37SDIMG_ROOTFS_TYPE ?= "ext3"
@@ -48,16 +61,22 @@ FATPAYLOAD ?= ""
48IMAGEDATESTAMP = "${@time.strftime('%Y.%m.%d',time.gmtime())}" 61IMAGEDATESTAMP = "${@time.strftime('%Y.%m.%d',time.gmtime())}"
49 62
50IMAGE_CMD_rpi-sdimg () { 63IMAGE_CMD_rpi-sdimg () {
64
65 # Align partitions
66 BOOT_SPACE_ALIGNED=$(expr ${BOOT_SPACE} + ${IMAGE_ROOTFS_ALIGNMENT} - 1)
67 BOOT_SPACE_ALIGNED=$(expr ${BOOT_SPACE_ALIGNED} - ${BOOT_SPACE_ALIGNED} % ${IMAGE_ROOTFS_ALIGNMENT})
68 SDIMG_SIZE=$(expr ${BOOT_SPACE_ALIGNED} + $ROOTFS_SIZE + ${IMAGE_ROOTFS_ALIGNMENT})
69
51 # Initialize sdcard image file 70 # Initialize sdcard image file
52 dd if=/dev/zero of=${SDIMG} bs=1 count=0 seek=$(expr 1000 \* 1000 \* ${SDIMG_SIZE}) 71 dd if=/dev/zero of=${SDIMG} bs=1 count=0 seek=$(expr 1024 \* ${SDIMG_SIZE})
53 72
54 # Create partition table 73 # Create partition table
55 parted -s ${SDIMG} mklabel msdos 74 parted -s ${SDIMG} mklabel msdos
56 # Create boot partition and mark it as bootable 75 # Create boot partition and mark it as bootable
57 parted -s ${SDIMG} mkpart primary fat32 1MiB ${BOOT_SPACE} 76 parted -s ${SDIMG} unit KiB mkpart primary fat32 ${IMAGE_ROOTFS_ALIGNMENT} $(expr ${BOOT_SPACE_ALIGNED} \+ ${IMAGE_ROOTFS_ALIGNMENT})
58 parted -s ${SDIMG} set 1 boot on 77 parted -s ${SDIMG} set 1 boot on
59 # Create rootfs partition 78 # Create rootfs partition
60 parted -s ${SDIMG} mkpart primary ext2 ${BOOT_SPACE} 100% 79 parted -s ${SDIMG} unit KiB mkpart primary ext2 $(expr ${BOOT_SPACE_ALIGNED} \+ ${IMAGE_ROOTFS_ALIGNMENT}) 100%
61 parted ${SDIMG} print 80 parted ${SDIMG} print
62 81
63 # Create a vfat image with boot files 82 # Create a vfat image with boot files
@@ -93,13 +112,13 @@ IMAGE_CMD_rpi-sdimg () {
93 mcopy -i ${WORKDIR}/boot.img -v ${WORKDIR}//image-version-info :: 112 mcopy -i ${WORKDIR}/boot.img -v ${WORKDIR}//image-version-info ::
94 113
95 # Burn Partitions 114 # Burn Partitions
96 dd if=${WORKDIR}/boot.img of=${SDIMG} conv=notrunc seek=1 bs=1M && sync && sync 115 dd if=${WORKDIR}/boot.img of=${SDIMG} conv=notrunc seek=1 bs=$(expr ${IMAGE_ROOTFS_ALIGNMENT} \* 1024) && sync && sync
97 # If SDIMG_ROOTFS_TYPE is a .xz file use xzcat 116 # If SDIMG_ROOTFS_TYPE is a .xz file use xzcat
98 if [[ "$SDIMG_ROOTFS_TYPE" == *.xz ]] 117 if [[ "$SDIMG_ROOTFS_TYPE" == *.xz ]]
99 then 118 then
100 xzcat ${SDIMG_ROOTFS} | dd of=${SDIMG} conv=notrunc seek=1 bs=${BOOT_SPACE} && sync && sync 119 xzcat ${SDIMG_ROOTFS} | dd of=${SDIMG} conv=notrunc seek=1 bs=$(expr 1024 \* ${BOOT_SPACE_ALIGNED}) && sync && sync
101 else 120 else
102 dd if=${SDIMG_ROOTFS} of=${SDIMG} conv=notrunc seek=1 bs=${BOOT_SPACE} && sync && sync 121 dd if=${SDIMG_ROOTFS} of=${SDIMG} conv=notrunc seek=1 bs=$(expr 1024 \* ${BOOT_SPACE_ALIGNED} + ${IMAGE_ROOTFS_ALIGNMENT} \* 1024) && sync && sync
103 fi 122 fi
104} 123}
105 124