Error building pi4 system image with ubuntu-image

I’m trying to build an ubuntu core system image for pi4 arm64, using the ubuntu-image tool.
I already have this working for pi3 arm32.

However, when trying to build the pi4 image, I get this error:

$ ./buildimage_pi4.sh
Fetching snapd
Fetching pi-kernel
Fetching core20
Fetching pi
Fetching core18
Fetching capturegrid4
panic: runtime error: slice bounds out of range [recovered]
        panic: runtime error: slice bounds out of range

goroutine 1 [running]:
main.main.func1()
        /build/snapd/parts/snapd-deb/build/_build/src/github.com/snapcore/snapd/cmd/snap/main.go:477 +0x84
panic(0xaaaad27c9280, 0xaaaad2b934b0)
        /usr/lib/go-1.10/src/runtime/panic.go:502 +0x1e8
github.com/snapcore/snapd/bootloader/ubootenv.OpenWithFlags(0x4420112900, 0x32, 0x1, 0x0, 0x0, 0x0)
        /build/snapd/parts/snapd-deb/build/_build/src/github.com/snapcore/snapd/bootloader/ubootenv/env.go:105 +0x3b4
github.com/snapcore/snapd/bootloader.(*uboot).SetBootVars(0x4420496020, 0x442034a1b0, 0x44200384b0, 0x49)
        /build/snapd/parts/snapd-deb/build/_build/src/github.com/snapcore/snapd/bootloader/uboot.go:98 +0x3c
github.com/snapcore/snapd/boot.makeBootable16(0x44202de700, 0x4420149440, 0x1d, 0x44206318c8, 0x0, 0x44200dc0f0)
        /build/snapd/parts/snapd-deb/build/_build/src/github.com/snapcore/snapd/boot/makebootable.go:136 +0x538
github.com/snapcore/snapd/boot.MakeBootable(0x44202de700, 0x4420149440, 0x1d, 0x44206318c8, 0x0, 0x0)
        /build/snapd/parts/snapd-deb/build/_build/src/github.com/snapcore/snapd/boot/makebootable.go:57 +0xf8
github.com/snapcore/snapd/image.setupSeed(0x4420372060, 0x44202de700, 0x442035bc70, 0x1, 0x44201d1968)
        /build/snapd/parts/snapd-deb/build/_build/src/github.com/snapcore/snapd/image/image.go:423 +0x1334
github.com/snapcore/snapd/image.Prepare(0x442035bc70, 0xaaaad2bf6888, 0x0)
        /build/snapd/parts/snapd-deb/build/_build/src/github.com/snapcore/snapd/image/image.go:104 +0x2e8
main.(*cmdPrepareImage).Execute(0x442031ae00, 0x4420360a50, 0x0, 0x3, 0x442031ae00, 0x1)
        /build/snapd/parts/snapd-deb/build/_build/src/github.com/snapcore/snapd/cmd/snap/cmd_prepare_image.go:116 +0x408
github.com/snapcore/snapd/vendor/github.com/jessevdk/go-flags.(*Parser).ParseArgs(0x44202fd180, 0x44200c0050, 0x3, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0)
        /build/snapd/parts/snapd-deb/build/_build/src/github.com/snapcore/snapd/vendor/github.com/jessevdk/go-flags/parser.go:333 +0x678
github.com/snapcore/snapd/vendor/github.com/jessevdk/go-flags.(*Parser).Parse(0x44202fd180, 0x44202fd180, 0xaaaad2bd99a0, 0xffff9dcf66c8, 0x0, 0x442010f8f8)
        /build/snapd/parts/snapd-deb/build/_build/src/github.com/snapcore/snapd/vendor/github.com/jessevdk/go-flags/parser.go:190 +0x70
main.run(0x4400000000, 0xaaaad28972c0)
        /build/snapd/parts/snapd-deb/build/_build/src/github.com/snapcore/snapd/cmd/snap/main.go:515 +0x3c
main.main()
        /build/snapd/parts/snapd-deb/build/_build/src/github.com/snapcore/snapd/cmd/snap/main.go:482 +0x2a0
COMMAND FAILED: snap prepare-image /home/francis/code/repo/smartshooter4/smartshooter/installer/snap/image/capturegrid4-pi4-arm64.model /tmp/tmpv5yai8et/unpack

Here is the model I’m using for the image:

{
    "type": "model",
    "authority-id": "...",
    "brand-id": "...",
    "series": "16",
    "model": "capturegrid4-pi4-arm64",
    "architecture": "arm64",
    "base": "core20",
    "gadget": "pi=20",
    "kernel": "pi-kernel=20",
    "timestamp": "2020-05-05T10:20:00+00:00",
    "required-snaps": ["core18", "capturegrid4"]
}

I’m not really sure where to begin trying to fix this.
Can anyone give me some guidance?

core20 was completely re-designed and might work completely different to all former UC versions, the new build process for local builds does not seem to be documented yet …

also UC20 is still in early beta stage, i’d stick to base: core18 for now …

The reason I’ve been trying core20 instead of core18 is for pi4 64bit support.
As far as I know core18 does not support that (yet?).

ubuntu-core-18-arm64+raspi4.img.xz

(though unless you have an 8GB Pi4 using 64bit is rather just a waste of ram (binaries allocate about twice the ram at runtime in 64bit mode (even 32bit ones which is the majority)) for no actual benefit …

That code needs better error handling but the underlying issue is that the pi gadget for core 20 is very different, and the snapd used is too old to deal with it. Even in that case the syntax for the model assertion to have a working UC20 system has changed.

There will be more information about this with snapd 2.45.

https://github.com/snapcore/snapd/pull/8771 should turn that panic into an error