| 147 | |
| 148 | === Building .ext4 filesystem and compressed disk image |
| 149 | |
| 150 | In the event you choose to use Buildroot but wish to avoid the drawbacks of a ramdisk you can install it to a block storage device. For this you will need to create a .ext4 filesystem image. This example will utilize the Linux-Newport branch of the mainline 4.14.4 kernel. |
| 151 | |
| 152 | Prerequisite for this procedure you will need to have: |
| 153 | |
| 154 | * Downloaded and configured the [wiki:/newport/bsp Newport BSP], many of the tools used will be provided by it. |
| 155 | * The [http://dev.gateworks.com/newport/kernel/linux-newport.tar.xz linux-newport.tar.xz] kernel tarball. |
| 156 | * The latest [http://dev.gateworks.com/newport/boot_firmware/firmware-newport.img firmware-newport.img] boot firmware if you would like to create a compressed disk image. |
| 157 | |
| 158 | With the Newport BSP installed, and Buildroot cloned, configure Buildroot in make menuconfig with the two following options: |
| 159 | {{{#!bash |
| 160 | cd buildroot |
| 161 | make menuconfig |
| 162 | }}} |
| 163 | * Target options -> Target Architecture -> AArch64 (little endian) (BR2_aarch64) |
| 164 | * Filesystem images -> tar the root filesystem -> Compression method (xz) (BR2_TARGET_ROOTFS_CPIO_XZ) |
| 165 | |
| 166 | Save the .config and exit. |
| 167 | |
| 168 | Now: |
| 169 | {{{#!bash |
| 170 | make -j8 |
| 171 | }}} |
| 172 | |
| 173 | After the build completes: |
| 174 | * Export the location of the rootfs.tar located in your buildroot/output/images folder. |
| 175 | {{{#!bash |
| 176 | ROOTFS=${PWD}/output/images/rootfs.tar |
| 177 | }}} |
| 178 | * Create a tmp_mnt directory at a location of your discression, this is your temporary mounting point for compiling the filesystem. |
| 179 | {{{#!bash |
| 180 | mkdir tmp_mnt |
| 181 | TMP_MNT=${PWD}/tmp_mnt |
| 182 | }}} |
| 183 | * Create a filesystem of a specific size. It will be expandable later using resize2fs, make it large enough to fit what you have in your current build. |
| 184 | {{{#!bash |
| 185 | OUT=buildroot-newport.ext4 |
| 186 | SIZEMB=1536 # 1.5GB |
| 187 | truncate -s ${SIZEMB}M ${OUT} |
| 188 | mkfs.ext4 -q -F -L rootfs ${OUT} |
| 189 | }}} |
| 190 | * Mount this file to your 'tmp_mnt' directory |
| 191 | {{{#!bash |
| 192 | sudo mount ${OUT} ${TMP_MNT} |
| 193 | }}} |
| 194 | * Extract the Buildroot rootfs.tar and linux-newport.tar.xz which was downloaded to this mount point. |
| 195 | {{{#!bash |
| 196 | sudo tar -C ${TMP_MNT} -xf ${ROOTFS} |
| 197 | sudo tar -C ${TMP_MNT} -xf linux-newport.tar.xz |
| 198 | }}} |
| 199 | * Convert the kernel 'Image' (uncompressed Kernel) to a fit image. For this you will need a tool from your Newport BSP directory, in this example the path to the BSP directory is named ${NEWPORT_BSP}. |
| 200 | {{{#!bash |
| 201 | mv ${TMP_MNT}/boot/Image vmlinux |
| 202 | gzip -f vmlinux |
| 203 | ${NEWPORT_BSP}/newport/mkits.sh -o kernel.its -k vmlinux.gz -C gzip -v "buldroot-newport" |
| 204 | mkimage -f kernel.its tmp_mnt/boot/kernel.itb #adds header |
| 205 | }}} |
| 206 | * Create U-Boot bootscript using the existing Ubuntu one from the Newport BSP, use mkimage to add the u-boot header. |
| 207 | {{{#!bash |
| 208 | mkimage -A arm64 -T script -C none -d ${NEWPORT_BSP}/newport/ubuntu.scr ${TMP_MNT}/boot/newport.scr |
| 209 | }}} |
| 210 | * Unmount temporary mount point, and compress the .ext4 file to be used with the u-boot command 'gzwrite'. |
| 211 | {{{#!bash |
| 212 | umount ${TMP_MNT} |
| 213 | sync |
| 214 | gzip -k -f ${OUT} |
| 215 | }}} |
| 216 | |
| 217 | To load this root file system without disturbing the existing boot firmware tftpboot can be used: |
| 218 | |
| 219 | * Boot your Newport SBC, at the prompt "Hit any key to stop autoboot" press a key. |
| 220 | * Execute the following commands. |
| 221 | {{{#!bash |
| 222 | setenv ipaddr <your boards IP> |
| 223 | setenv serverip <your TFTP server IP> |
| 224 | setenv dev 0 |
| 225 | setenv image buildroot-newport.ext4.gz |
| 226 | run update_rootfs |
| 227 | }}} |
| 228 | |
| 229 | To create a disk image from the .ext4 file: |
| 230 | |
| 231 | * Creating a disk image is useful if you would like to overwrite the existing boot firmware when the image is flashed. |
| 232 | {{{#!bash |
| 233 | # http://dev.gateworks.com/newport/boot_firmware/firmware-newport.img |
| 234 | cp firmware-newport.img buildroot-newport.img |
| 235 | # copy buildroot rootfs .ext4 filesystem to image with an offset |
| 236 | dd if=buildroot-newport.ext4 of=buildroot-newport.img bs=16M seek=1 |
| 237 | # compress it |
| 238 | gzip -k -f buildroot-newport.img |
| 239 | }}} |
| 240 | |
| 241 | |