diff --git a/make_netboot.sh b/make_netboot.sh index 324b0232f3..4bef5e83e3 100755 --- a/make_netboot.sh +++ b/make_netboot.sh @@ -28,6 +28,9 @@ DEFINE_string image "" "Path to the image to use" FLAGS "$@" || exit 1 eval set -- "${FLAGS_ARGV}" +. "${SCRIPT_ROOT}/build_library/build_common.sh" || exit 1 +. "${BUILD_LIBRARY_DIR}/board_options.sh" || exit 1 + switch_to_strict_mode # build_packages artifact output. SYSROOT="${GCLIENT_ROOT}/chroot/build/${FLAGS_board}" @@ -86,9 +89,50 @@ sudo mount -o loop part_3 r sudo mount -o loop part_1 s echo "Mount install shim rootfs (partition 3)" +if [ "${ARCH}" = "arm" ]; then + export MKIMAGE_ARCH="arm" +else + export MKIMAGE_ARCH="x86" # including amd64 +fi + # Get netboot kernel. -echo "Generating netboot kernel vmlinux.uimg" -cp "r/boot/vmlinux.uimg" "netboot" +if [ "${ARCH}" = "arm" ]; then + # Currently we don't use initramfs for ARM. Someday we would probably want + # initramfs for USB factory installation. + # TODO: Converge build processes of ARM and x86. + echo "Generating netboot kernel vmlinux.uimg" + cp "r/boot/vmlinux.uimg" "netboot" +else + echo "Building kernel" + + # Create temporary emerge root + temp_build_path="$(mktemp -d bk_XXXXXXXX)" + if ! [ -d "${temp_build_path}" ]; then + echo "Failed to create temporary directory." + exit 1 + fi + + # Emerge network boot kernel + # We don't want to build whole install shim everytime we run this script, + # and thus we only build kernel here. If this script is run against install + # shim with different kernel version, this might not work. But as we don't + # upgrade kernel so often, this is probably fine. + export USE='netboot' + export EMERGE_BOARD_CMD="emerge-${FLAGS_board}" + emerge_custom_kernel ${temp_build_path} + + # Generate kernel uImage + echo "Generating netboot kernel vmlinux.uimg" + + # U-boot put kernel image at 0x100000. We load it at 0x3000000 because + # 0x3000000 is safe enough not to overlap with image at 0x100000. + mkimage -A "${MKIMAGE_ARCH}" -O linux -T kernel -n "Linux kernel" -C none \ + -d "${temp_build_path}"/boot/vmlinuz \ + -a 0x03000000 -e 0x03000000 netboot/vmlinux.uimg + + # Clean up temporary emerge root + sudo rm -rf "${temp_build_path}" +fi echo "Add lsb-factory" # Copy factory config file. @@ -108,7 +152,7 @@ echo "Generating netboot rootfs initrd.uimg" # U-boot's uimg wrapper specifies where we will load the blob into memory. # tftp boot's default root address is set to 0x12008000 in legacy_image.bin, # so we want to unpack it there. -mkimage -A arm -O linux -T ramdisk -a 0x12008000 \ +mkimage -A "${MKIMAGE_ARCH}" -O linux -T ramdisk -a 0x12008000 \ -n "Factory Install RootFS" -C gzip -d ext2_rootfs.gz \ netboot/initrd.uimg