]> xenbits.xensource.com Git - people/sstabellini/mojo.git/.git/commitdiff
Containerized image build
authorStefano Stabellini <sstabellini@kernel.org>
Thu, 9 Nov 2017 17:00:12 +0000 (09:00 -0800)
committerStefano Stabellini <sstabellini@kernel.org>
Mon, 13 Nov 2017 20:57:38 +0000 (12:57 -0800)
Signed-off-by: Stefano Stabellini <sstabellini@kernel.org>
Signed-off-by: Gianluca Guida <gianluca@zededa.com>
build.sh
mkimage/Dockerfile [new file with mode: 0644]
mkimage/make-efi [new file with mode: 0755]
mkimage/patches/0001-TPM-build-issue-fixing.patch [new file with mode: 0644]
mkimage/patches/0002-video-Allow-to-set-pure-text-mode-in-case-of-EFI.patch [new file with mode: 0644]

index 45abf035a2dafa3f572af47ab856cd2bd4f12f6f..bf17fd58b95705026f6ae944bc5ffb94f0a450c5 100644 (file)
--- a/build.sh
+++ b/build.sh
@@ -4,6 +4,7 @@ HOME_DIR=`pwd`
 OUT_DIR=$HOME_DIR/out
 BUILDER_LABEL="xenbuilder"
 DOM0_LABEL="dom0"
+GRUB_BUILD_LABEL="grub-build"
 
 source lib.sh
 
@@ -30,31 +31,32 @@ if test -z "$exists"
 then
     docker build -f dom0/alpine-assemble -t $DOM0_LABEL .
 fi
-if ! test -f "$DOM0_LABEL".tar
+if ! test -f mkimage/"$DOM0_LABEL".tar
 then
     # This is a workaround: find a better way
     docker run $DOM0_LABEL /root/sleep &
     sleep 1
     container_id=`docker ps | grep $DOM0_LABEL | cut -f 1 -d " "`
-    docker export $container_id > "$DOM0_LABEL".tar
+    docker export $container_id > mkimage/"$DOM0_LABEL".tar
     docker kill $container_id
 fi
 
+if ! test -f mkimage/kernel
+then
+    # XXX FIXME
+    cp /local/mojo-alpine/kernel ./mkimage
+fi
+
+exists=`docker images $GRUB_BUILD_LABEL | grep $GRUB_BUILD_LABEL`
+if test -z "$exists"
+then
+    docker build -f mkimage/Dockerfile -t $GRUB_BUILD_LABEL ./mkimage
+fi
 
 # Create system image
 if ! test -f image
 then
-    # 1GB image: make this customizable
-    allocate_disk image $((1024*1024*1024))
-    loop=`create_loop image`
-    loop_p0=`create_one_partition image`
-    mkfs.ext3 $loop_p0
-    mount $loop_p0 /mnt
-    cd /mnt
-    tar xvf $HOME_DIR/"$DOM0_LABEL".tar
-    cd $HOME_DIR
-    umount /mnt
-    losetup -d $loop_p0 $loop
+    docker run --privileged -i $GRUB_BUILD_LABEL /make-efi > image
 fi
 
 
diff --git a/mkimage/Dockerfile b/mkimage/Dockerfile
new file mode 100644 (file)
index 0000000..dec8a30
--- /dev/null
@@ -0,0 +1,69 @@
+FROM alpine AS grub-build
+
+ADD dom0.tar /root
+COPY kernel /root/boot
+
+RUN apk update && apk add \
+  automake \
+  make \
+  bison \
+  gettext \
+  flex \
+  gcc \
+  git \
+  libtool \
+  libc-dev \
+  linux-headers \
+  python3 \
+  autoconf
+
+# because python is not available
+RUN ln -s python3 /usr/bin/python
+
+ENV GRUB_MODULES="part_gpt fat ext2 iso9660 gzio linux acpi normal cpio crypto disk boot crc64 gpt \
+search_disk_uuid tftp verify xzio xfs video multiboot2 gfxterm efi_gop efi_uga"
+ENV GRUB_COMMIT=6782f6d431d22b4e9ab14e94d263795c7991e160
+
+COPY patches/* /patches/
+RUN mkdir /grub-lib && \
+  set -e && \
+  git clone https://github.com/coreos/grub.git && \
+  cd grub && \
+  git checkout -b grub-build ${GRUB_COMMIT} && \
+  for patch in /patches/*.patch; do \
+    echo "Applying $patch"; \
+    patch -p1 < "$patch"; \
+  done && \
+  ./autogen.sh && \
+  ./configure --libdir=/grub-lib --with-platform=efi CFLAGS="-Os -Wno-unused-value" && \
+  make -j "$(getconf _NPROCESSORS_ONLN)" && \
+  make install && \
+# create the grub core image
+  case $(uname -m) in \
+  x86_64) \
+    ./grub-mkimage -O x86_64-efi -d /grub-lib/grub/x86_64-efi -o /grub-lib/BOOTX64.EFI -p /EFI/BOOT ${GRUB_MODULES} linuxefi; \
+    ;; \
+  aarch64) \
+    ./grub-mkimage -O arm64-efi -d /grub-lib/grub/arm64-efi -o /grub-lib/BOOTAA64.EFI -p /EFI/BOOT ${GRUB_MODULES}; \
+    ;; \
+  esac
+
+RUN \
+  apk update && apk upgrade && \
+  apk add --no-cache \
+  dosfstools \
+  libarchive-tools \
+  binutils \
+  mtools \
+  sfdisk \
+  sgdisk \
+  xfsprogs \
+  e2fsprogs \
+  util-linux \
+  coreutils \
+  multipath-tools \
+  && true
+
+COPY make-efi /
+
+ENTRYPOINT [ "/bin/sh" ]
diff --git a/mkimage/make-efi b/mkimage/make-efi
new file mode 100755 (executable)
index 0000000..af743e1
--- /dev/null
@@ -0,0 +1,132 @@
+#!/bin/sh
+
+set -e
+
+IMGFILE=$PWD/disk.img
+ESP_FILE=$PWD/boot.img
+ROOTFS_FILE=$PWD/rootfs.img
+
+( exec 1>&2;
+
+# get the GRUB2 boot file name
+ARCH=`uname -m`
+case $ARCH in
+x86_64)
+  BOOTFILE=BOOTX64.EFI
+  LINUX_ENTRY=linuxefi
+  ;;
+aarch64)
+  BOOTFILE=BOOTAA64.EFI
+  LINUX_ENTRY=linux
+  ;;
+esac
+
+mkdir -p /tmp/efi
+cd /tmp/efi
+
+KERNEL="/root/boot/kernel"
+XEN="/root/boot/xen-4.10.0-rc.gz"
+
+# PARTUUID for root
+PARTUUID=$(cat /proc/sys/kernel/random/uuid)
+
+cp /grub-lib/$BOOTFILE .
+
+mkdir -p EFI/BOOT
+cat >> EFI/BOOT/grub.cfg <<EOF
+set timeout=5
+set gfxpayload=text
+menuentry 'LinuxKit Image' {
+       multiboot2 /xen-4.10.0-rc.gz
+       module2 /kernel console=tty0 root=/dev/sda2
+}
+
+menuentry 'LinuxKit Image on QEMU' {
+       multiboot2 /xen-4.10.0-rc.gz clocksource=pit console=com1
+       module2 /kernel console=hvc0 clocksource=jiffies root=/dev/vda2
+}
+EOF
+
+#
+# calculate sizes
+ls -l /root > /dev/stderr
+KERNEL_FILE_SIZE=$(stat -c %s "$KERNEL")
+XEN_FILE_SIZE=$(stat -c %s "$XEN")
+EFI_FILE_SIZE=$(stat -c %s "$BOOTFILE")
+
+# minimum headroom needed in ESP, in bytes
+# 511KiB headroom seems to be enough
+ESP_HEADROOM=$(( 1024 * 1024 ))
+
+# this is the minimum size of our EFI System Partition
+ESP_FILE_SIZE=$(( $KERNEL_FILE_SIZE + $XEN_FILE_SIZE + $EFI_FILE_SIZE + $ESP_HEADROOM ))
+
+# (x+1024)/1024*1024 rounds up to multiple of 1024KB, or 2048 sectors
+# some firmwares get confused if the partitions are not aligned on 2048 blocks
+# we will round up to the nearest multiple of 2048 blocks
+# since each block is 512 bytes, we want the size to be a multiple of
+# 2048 blocks * 512 bytes = 1048576 bytes = 1024KB
+ESP_FILE_SIZE_KB=$(( ( ($ESP_FILE_SIZE+1024) / 1024 ) / 1024 * 1024 ))
+# and for sectors
+ESP_FILE_SIZE_SECTORS=$(( $ESP_FILE_SIZE_KB * 2 ))
+
+ROOTFS_FILE_SIZE_KB=$(du -sk /root | awk '{print $1}')
+
+ROOTFS_BLOCKSZ=4096
+ROOTFS_PART_HEADROOM_BLOCKS=16000
+ROOTFS_PART_BLOCKS=$(( $ROOTFS_FILE_SIZE_KB / 4 + $ROOTFS_PART_HEADROOM_BLOCKS ))
+ROOTFS_PART_SIZE=$(( $ROOTFS_PART_BLOCKS * $ROOTFS_BLOCKSZ ))
+ROOTFS_PART_SIZE_KB=$(( ( ($ROOTFS_PART_SIZE + 1024) / 1024 ) / 1024 * 1024 ))
+ROOTFS_PART_SECTORS=$(( $ROOTFS_PART_SIZE_KB * 2 ))
+
+
+# create a raw disk with an EFI boot partition
+# Stuff it into a FAT filesystem, making it as small as possible.
+mkfs.vfat -v -C $ESP_FILE $(( $ESP_FILE_SIZE_KB )) > /dev/null
+echo "mtools_skip_check=1" >> /etc/mtools.conf && \
+mmd -i $ESP_FILE ::/EFI
+mmd -i $ESP_FILE ::/EFI/BOOT
+mcopy -i $ESP_FILE $BOOTFILE ::/EFI/BOOT/
+mcopy -i $ESP_FILE EFI/BOOT/grub.cfg ::/EFI/BOOT/
+mcopy -i $ESP_FILE $KERNEL ::/
+mcopy -i $ESP_FILE $XEN ::/
+
+dd if=/dev/zero of=$ROOTFS_FILE bs=1024 count=$(( $ROOTFS_PART_SIZE_KB ))
+mkfs.ext4 -b 4096 -L mojo_rootfs -v $ROOTFS_FILE
+mount -o loop $ROOTFS_FILE /mnt
+cp -R . /mnt
+umount /mnt
+
+# now make our actual filesystem image
+# how big an image do we want?
+# it should be the size of our ESP file+1MB for BIOS boot + 1MB for MBR + 1MB for GPT
+ONEMB=$(( 1024 * 1024 ))
+SIZE_IN_BYTES=$(( $(stat -c %s "$ESP_FILE") + 4*$ONEMB + $ROOTFS_PART_SIZE_KB * 1024 ))
+
+# and make sure the ESP is bootable for BIOS mode
+# settings
+BLKSIZE=512
+MB_BLOCKS=$(( $SIZE_IN_BYTES / $ONEMB ))
+
+# make the image
+dd if=/dev/zero of=$IMGFILE bs=1M count=$MB_BLOCKS
+
+ESP_SECTOR_START=2048
+ESP_SECTOR_END=$(( $ESP_SECTOR_START + $ESP_FILE_SIZE_SECTORS - 1 ))
+ROOTFS_SECTOR_START=$(( $ESP_SECTOR_END + 1 ))
+ROOTFS_SECTOR_END=$(( $ROOTFS_SECTOR_START + $ROOTFS_PART_SECTORS - 1))
+
+# create the partitions - size of the ESP must match our image
+# and make sure the ESP is bootable for BIOS mode
+sgdisk --clear \
+       --new 1:$ESP_SECTOR_START:$ESP_SECTOR_END --typecode=1:ef00 --change-name=1:'EFI System' --partition-guid=1:$PARTUUID \
+       --new 2:$ROOTFS_SECTOR_START:$ROOTFS_SECTOR_END --typecode=2:fe00 --change-name=2:'rootfs' \
+    --attributes 1:set:2 \
+     $IMGFILE
+
+# copy in our EFI System Partition image
+dd if=$ESP_FILE of=$IMGFILE bs=$BLKSIZE count=$ESP_FILE_SIZE_SECTORS conv=notrunc seek=$ESP_SECTOR_START
+dd if=$ROOTFS_FILE of=$IMGFILE bs=$BLKSIZE count=$ROOTFS_PART_SECTORS conv=notrunc seek=$ROOTFS_SECTOR_START
+
+)
+cat $IMGFILE
diff --git a/mkimage/patches/0001-TPM-build-issue-fixing.patch b/mkimage/patches/0001-TPM-build-issue-fixing.patch
new file mode 100644 (file)
index 0000000..1a17a57
--- /dev/null
@@ -0,0 +1,72 @@
+From 617b08377dbaa9ea3876b5585fe0ba36286fbed6 Mon Sep 17 00:00:00 2001
+From: Dennis Chen <dennis.chen@arm.com>
+Date: Thu, 17 Aug 2017 05:47:55 +0000
+Subject: [PATCH] TPM: build issue fixing
+
+Fix the build issue on arm64 and amd64.
+
+Signed-off-by: Dennis Chen <dennis.chen@arm.com>
+---
+ grub-core/kern/efi/tpm.c | 12 ++++++------
+ include/grub/efi/tpm.h   |  4 ++--
+ 2 files changed, 8 insertions(+), 8 deletions(-)
+
+diff --git a/grub-core/kern/efi/tpm.c b/grub-core/kern/efi/tpm.c
+index c9fb3c1..ed40f98 100644
+--- a/grub-core/kern/efi/tpm.c
++++ b/grub-core/kern/efi/tpm.c
+@@ -175,7 +175,7 @@ grub_tpm1_log_event(grub_efi_handle_t tpm_handle, unsigned char *buf,
+                   grub_size_t size, grub_uint8_t pcr,
+                   const char *description)
+ {
+-  Event *event;
++  TCG_PCR_EVENT *event;
+   grub_efi_status_t status;
+   grub_efi_tpm_protocol_t *tpm;
+   grub_efi_physical_address_t lastevent;
+@@ -188,15 +188,15 @@ grub_tpm1_log_event(grub_efi_handle_t tpm_handle, unsigned char *buf,
+   if (!grub_tpm_present(tpm))
+     return 0;
+-  event = grub_zalloc(sizeof (Event) + grub_strlen(description) + 1);
++  event = grub_zalloc(sizeof (TCG_PCR_EVENT) + grub_strlen(description) + 1);
+   if (!event)
+     return grub_error (GRUB_ERR_OUT_OF_MEMORY,
+                      N_("cannot allocate TPM event buffer"));
+-  event->pcrindex = pcr;
+-  event->eventtype = EV_IPL;
+-  event->eventsize = grub_strlen(description) + 1;
+-  grub_memcpy(event->event, description, event->eventsize);
++  event->PCRIndex = pcr;
++  event->EventType = EV_IPL;
++  event->EventSize = grub_strlen(description) + 1;
++  grub_memcpy(event->Event, description, event->EventSize);
+   algorithm = TCG_ALG_SHA;
+   status = efi_call_7 (tpm->log_extend_event, tpm, buf, (grub_uint64_t) size,
+diff --git a/include/grub/efi/tpm.h b/include/grub/efi/tpm.h
+index e2aff4a..fb3bb0e 100644
+--- a/include/grub/efi/tpm.h
++++ b/include/grub/efi/tpm.h
+@@ -69,7 +69,7 @@ struct grub_efi_tpm_protocol
+                                           grub_efi_uint32_t TpmOutputParameterBlockSize,
+                                           grub_efi_uint8_t *TpmOutputParameterBlock);
+   grub_efi_status_t (*log_extend_event) (struct grub_efi_tpm_protocol *this,
+-                                       grub_efi_physical_address_t HashData,
++                                       grub_efi_uint8_t *HashData,
+                                        grub_efi_uint64_t HashDataLen,
+                                        grub_efi_uint32_t AlgorithmId,
+                                        TCG_PCR_EVENT *TCGLogData,
+@@ -129,7 +129,7 @@ struct grub_efi_tpm2_protocol
+                                     grub_efi_boolean_t *EventLogTruncated);
+   grub_efi_status_t (*hash_log_extend_event) (struct grub_efi_tpm2_protocol *this,
+                                             grub_efi_uint64_t Flags,
+-                                            grub_efi_physical_address_t *DataToHash,
++                                            grub_efi_uint8_t *DataToHash,
+                                             grub_efi_uint64_t DataToHashLen,
+                                             EFI_TCG2_EVENT *EfiTcgEvent);
+   grub_efi_status_t (*submit_command) (struct grub_efi_tpm2_protocol *this,
+-- 
+2.7.4
+
diff --git a/mkimage/patches/0002-video-Allow-to-set-pure-text-mode-in-case-of-EFI.patch b/mkimage/patches/0002-video-Allow-to-set-pure-text-mode-in-case-of-EFI.patch
new file mode 100644 (file)
index 0000000..8cc747b
--- /dev/null
@@ -0,0 +1,33 @@
+From ac7afa666cb2b7b133b6e27bcf22c9cd90a2936a Mon Sep 17 00:00:00 2001
+From: Dennis Chen <dennis.chen@arm.com>
+Date: Wed, 6 Sep 2017 09:06:54 +0000
+Subject: [PATCH] video: Allow to set pure 'text' mode in case of EFI
+
+Current code doesn't accept a pure text mode when booting
+from UEFI firmware on i386 platform, this will result in
+below error message even we already have 'set gfxpayload=text'
+configured: "no suitable video mode found". This often happens
+when we boot a VM which UEFI firmware doesn't include 'suitable'
+video modes.
+
+Signed-off-by: Dennis Chen <dennis.chen@arm.com>
+---
+ grub-core/loader/i386/linux.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c
+index 5fdfea3..8cf1086 100644
+--- a/grub-core/loader/i386/linux.c
++++ b/grub-core/loader/i386/linux.c
+@@ -49,7 +49,7 @@ GRUB_MOD_LICENSE ("GPLv3+");
+ #include <grub/efi/efi.h>
+ #define HAS_VGA_TEXT 0
+ #define DEFAULT_VIDEO_MODE "auto"
+-#define ACCEPTS_PURE_TEXT 0
++#define ACCEPTS_PURE_TEXT 1
+ #elif defined (GRUB_MACHINE_IEEE1275)
+ #include <grub/ieee1275/ieee1275.h>
+ #define HAS_VGA_TEXT 0
+-- 
+2.7.4
+