Issue with ubuntu-image: panic: runtime error: slice bounds out of range

Issue trying to build a custom image for Jetson TK1. Any help is greatly appreciated.

$ uname -a
Linux laptop 4.10.0-35-generic #39~16.04.1-Ubuntu SMP Wed Sep 13 09:02:42 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

$ snap --version
snap 2.28.1
snapd 2.28.1
series 16
ubuntu 16.04
kernel 4.10.0-35-generic

skj@laptop:~/Documents/snap/TK1$ sudo ubuntu-image -d -c edge --extra-snaps /home/skj/Documents/snap/TK1/tk1_16-0.1_armhf.snap --extra-snaps /home/skj/Documents/snap/TK1/linux-generic-bbb_4.4.0-93-1.1_armhf.snap /home/skj/Documents/snap/TK1/tk1.model
DEBUG:ubuntu-image:-> [ 0] make_temporary_directories
DEBUG:ubuntu-image:-> [ 1] prepare_image
Fetching core
Copying “/home/skj/Documents/snap/TK1/linux-generic-bbb_4.4.0-93-1.1_armhf.snap” (linux-generic-bbb)
Copying “/home/skj/Documents/snap/TK1/tk1_16-0.1_armhf.snap” (tk1)
tk1 already prepared, skipping
linux-generic-bbb already prepared, skipping
WARNING: “linux-generic-bbb”, “tk1” were installed from local snaps disconnected from a store and cannot be refreshed subsequently!
panic: runtime error: slice bounds out of range [recovered]
panic: runtime error: slice bounds out of range

goroutine 1 [running]:
panic(0x55be08f83fa0, 0xc8200100c0)
/usr/lib/go-1.6/src/runtime/panic.go:481 +0x3ea
main.main.func1()
/build/snapd-44qGW9/snapd-2.28.1/_build/src/github.com/snapcore/snapd/cmd/snap/main.go:287 +0x7b
panic(0x55be08f83fa0, 0xc8200100c0)
/usr/lib/go-1.6/src/runtime/panic.go:443 +0x4ed
github.com/snapcore/snapd/partition/ubootenv.OpenWithFlags(0xc8204d5400, 0x32, 0x1, 0x0, 0x0, 0x0)
/build/snapd-44qGW9/snapd-2.28.1/_build/src/github.com/snapcore/snapd/partition/ubootenv/env.go:112 +0x65c
github.com/snapcore/snapd/partition.(*uboot).SetBootVars(0x55be093a3f18, 0xc8205d95f0, 0x0, 0x0)
/build/snapd-44qGW9/snapd-2.28.1/_build/src/github.com/snapcore/snapd/partition/uboot.go:59 +0x75
github.com/snapcore/snapd/image.setBootvars(0xc8205d81e0, 0x0, 0x0)
/build/snapd-44qGW9/snapd-2.28.1/_build/src/github.com/snapcore/snapd/image/image.go:483 +0x55a
github.com/snapcore/snapd/image.bootstrapToRootDir(0xc820167c00, 0xc8200b6790, 0xc8202e38f0, 0xc8202d6140, 0x0, 0x0)
/build/snapd-44qGW9/snapd-2.28.1/_build/src/github.com/snapcore/snapd/image/image.go:433 +0x212a
github.com/snapcore/snapd/image.Prepare(0xc8202e38f0, 0x0, 0x0)
/build/snapd-44qGW9/snapd-2.28.1/_build/src/github.com/snapcore/snapd/image/image.go:154 +0x38d
main.(*cmdPrepareImage).Execute(0xc82000f9a0, 0xc820186cc0, 0x0, 0x6, 0x0, 0x0)
/build/snapd-44qGW9/snapd-2.28.1/_build/src/github.com/snapcore/snapd/cmd/snap/cmd_prepare_image.go:72 +0x22f
github.com/snapcore/snapd/vendor/github.com/jessevdk/go-flags.(*Parser).ParseArgs(0xc82005f980, 0xc82000a0f0, 0x6, 0x6, 0x0, 0x0, 0x0, 0x0, 0x0)
/build/snapd-44qGW9/snapd-2.28.1/_build/src/github.com/snapcore/snapd/vendor/github.com/jessevdk/go-flags/parser.go:316 +0xa85
github.com/snapcore/snapd/vendor/github.com/jessevdk/go-flags.(*Parser).Parse(0xc82005f980, 0x0, 0x0, 0x0, 0x0, 0x0)
/build/snapd-44qGW9/snapd-2.28.1/_build/src/github.com/snapcore/snapd/vendor/github.com/jessevdk/go-flags/parser.go:186 +0x9d
main.run(0x0, 0x0)
/build/snapd-44qGW9/snapd-2.28.1/_build/src/github.com/snapcore/snapd/cmd/snap/main.go:308 +0x4a
main.main()
/build/snapd-44qGW9/snapd-2.28.1/_build/src/github.com/snapcore/snapd/cmd/snap/main.go:292 +0x834
ERROR:ubuntu-image:COMMAND FAILED: snap prepare-image --channel=edge --extra-snaps=/home/skj/Documents/snap/TK1/tk1_16-0.1_armhf.snap --extra-snaps=/home/skj/Documents/snap/TK1/linux-generic-bbb_4.4.0-93-1.1_armhf.snap /home/skj/Documents/snap/TK1/tk1.model /tmp/tmpmjyo6no7/unpack
ERROR:ubuntu-image:Full debug traceback follows
Traceback (most recent call last):
File “/usr/lib/python3/dist-packages/ubuntu_image/builder.py”, line 123, in prepare_image
self.args.channel, self.args.extra_snaps)
File “/usr/lib/python3/dist-packages/ubuntu_image/helpers.py”, line 117, in snap
run(cmd, stdout=None, stderr=None, env=os.environ)
File “/usr/lib/python3/dist-packages/ubuntu_image/helpers.py”, line 98, in run
proc.check_returncode()
File “/usr/lib/python3.5/subprocess.py”, line 659, in check_returncode
self.stderr)
subprocess.CalledProcessError: Command ‘[‘snap’, ‘prepare-image’, ‘–channel=edge’, ‘–extra-snaps=/home/skj/Documents/snap/TK1/tk1_16-0.1_armhf.snap’, ‘–extra-snaps=/home/skj/Documents/snap/TK1/linux-generic-bbb_4.4.0-93-1.1_armhf.snap’, ‘/home/skj/Documents/snap/TK1/tk1.model’, ‘/tmp/tmpmjyo6no7/unpack’]’ returned non-zero exit status 2

The panic itself is addressed in https://github.com/snapcore/snapd/pull/4074, although the actual issue was a missing or incomplete boot.env (addressed on IRC).