mxre / zloader

Linux EFI bootstub for x86 and AArch64 with LZ4 and ZSTD compression
BSD 2-Clause "Simplified" License
10 stars 4 forks source link

Unable to build unified kernel on Ubuntu 20.10 aarch64 #1

Open zmanji opened 3 years ago

zmanji commented 3 years ago

On the latest Ubuntu release (20.10) I did the following:

  1. Install all of the build dependencies.
  2. Built the boot stub by running:
    cmake -GNinja -DLOADER_TARGET=aarch64 ..
    ninja
  3. Tried to build the image with build_image like this:
    ./zloader/build/tools/build_image -o foo-unsigned.efi -s ./zloader/build/zloaderaa64.efi.stub -l /boot/vmlinux-5.13.0-19-generic -i /boot/initrd.img-5.13.0-19-generic -c ./cmdline.txt -O /etc/os-release 

    The above step fails with:

    build_image: /root/zloader/tools/build_image.c:468: int main(int, char **): Assertion `filesize < mem.size' failed.

The following files are located in the attached zips for your reference:

rest.zip kernel.zip initrd.zip

zmanji commented 3 years ago

Note

With the following patch:

diff --git a/src/util.h b/src/util.h
index ca6620b..d297a28 100644
--- a/src/util.h
+++ b/src/util.h
@@ -65,16 +65,12 @@ struct aligned_buffer {

 static __always_inline inline
 uint8_t* buffer_pos(simple_buffer_t buffer) {
-    assert(buffer->buffer);
-    assert(buffer->pos < buffer->allocated);

     return (uint8_t*) buffer->buffer + buffer->pos;
 }

 static __always_inline inline
 size_t buffer_len(simple_buffer_t buffer) {
-    assert(buffer->buffer);
-    assert(buffer->pos < buffer->length);

     return buffer->length - buffer->pos;
 }
diff --git a/tools/build_image.c b/tools/build_image.c
index bfc6a82..70cba94 100644
--- a/tools/build_image.c
+++ b/tools/build_image.c
@@ -465,7 +465,7 @@ int main(int argc, char* argv[]) {
         largest_vma = ALIGN_VALUE(section->virtual_address + section->virtual_size, section_alignment);
         largest_raw_address += section->size_of_raw_data;
         filesize += section->size_of_raw_data;
-        assert(filesize < mem.size);
+        assert(filesize <= mem.size);
     }

     if (!silent) {

I was able to successfully create a unified kernel. This kernel was discovered by systemd-boot and booted properly.

I had to remove the asserts in util.h otherwise the stub would fail on those asserts.