Implement monorepo layout
Implemented the nexantic monorepo.
Smalltown code was moved to `core`. From now on all code will live in top level directories named after the projects with the exception for general purpose libraries which should go to `<lang>libs`.
General build and utility folders are underscore prefixed.
The repo name will from now on be rNXT (nexantic). I think this change makes sense since components in this repo will not all be part of Smalltown, the Smalltown brand has been claimed by Signon GmbH so we need to change it anyway and the longer we wait the harder it will be to change/move it.
Test Plan: Launched Smalltown using `./scripts/bin/bazel run //core/scripts:launch`
X-Origin-Diff: phab/D210
GitOrigin-RevId: fa5a7f08143d2ead2cb7206b4c63ab641794162c
diff --git a/core/cmd/mkimage/BUILD.bazel b/core/cmd/mkimage/BUILD.bazel
new file mode 100644
index 0000000..35e162d
--- /dev/null
+++ b/core/cmd/mkimage/BUILD.bazel
@@ -0,0 +1,20 @@
+load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
+
+go_library(
+ name = "go_default_library",
+ srcs = ["main.go"],
+ importpath = "git.monogon.dev/source/nexantic.git/core/cmd/mkimage",
+ visibility = ["//visibility:private"],
+ deps = [
+ "@com_github_diskfs_go_diskfs//:go_default_library",
+ "@com_github_diskfs_go_diskfs//disk:go_default_library",
+ "@com_github_diskfs_go_diskfs//filesystem:go_default_library",
+ "@com_github_diskfs_go_diskfs//partition/gpt:go_default_library",
+ ],
+)
+
+go_binary(
+ name = "mkimage",
+ embed = [":go_default_library"],
+ visibility = ["//visibility:public"],
+)
diff --git a/core/cmd/mkimage/main.go b/core/cmd/mkimage/main.go
new file mode 100644
index 0000000..a727e8b
--- /dev/null
+++ b/core/cmd/mkimage/main.go
@@ -0,0 +1,112 @@
+// Copyright 2020 The Monogon Project Authors.
+//
+// SPDX-License-Identifier: Apache-2.0
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package main
+
+import (
+ "fmt"
+ "io/ioutil"
+ "os"
+
+ "github.com/diskfs/go-diskfs"
+ "github.com/diskfs/go-diskfs/disk"
+ "github.com/diskfs/go-diskfs/filesystem"
+ "github.com/diskfs/go-diskfs/partition/gpt"
+)
+
+var SmalltownDataPartition gpt.Type = gpt.Type("9eeec464-6885-414a-b278-4305c51f7966")
+
+func mibToSectors(size uint64) uint64 {
+ return (size * 1024 * 1024) / 512
+}
+
+func main() {
+ if len(os.Args) < 3 {
+ fmt.Println("Usage: mkimage <UEFI payload> <image path>")
+ os.Exit(2)
+ }
+ _ = os.Remove(os.Args[2])
+ diskImg, err := diskfs.Create(os.Args[2], 3*1024*1024*1024, diskfs.Raw)
+ if err != nil {
+ fmt.Printf("Failed to create disk: %v", err)
+ os.Exit(1)
+ }
+
+ table := &gpt.Table{
+ // This is appropriate at least for virtio disks. Might need to be adjusted for real ones.
+ LogicalSectorSize: 512,
+ PhysicalSectorSize: 512,
+ ProtectiveMBR: true,
+ Partitions: []*gpt.Partition{
+ {
+ Type: gpt.EFISystemPartition,
+ Name: "ESP",
+ Start: mibToSectors(1),
+ End: mibToSectors(128) - 1,
+ },
+ {
+ Type: SmalltownDataPartition,
+ Name: "SIGNOS-DATA",
+ Start: mibToSectors(128),
+ End: mibToSectors(2560) - 1,
+ },
+ },
+ }
+ if err := diskImg.Partition(table); err != nil {
+ fmt.Printf("Failed to apply partition table: %v", err)
+ os.Exit(1)
+ }
+
+ fs, err := diskImg.CreateFilesystem(disk.FilesystemSpec{Partition: 1, FSType: filesystem.TypeFat32, VolumeLabel: "ESP"})
+ if err != nil {
+ fmt.Printf("Failed to create filesystem: %v", err)
+ os.Exit(1)
+ }
+ if err := fs.Mkdir("/EFI"); err != nil {
+ panic(err)
+ }
+ if err := fs.Mkdir("/EFI/BOOT"); err != nil {
+ panic(err)
+ }
+ if err := fs.Mkdir("/EFI/smalltown"); err != nil {
+ panic(err)
+ }
+ efiPayload, err := fs.OpenFile("/EFI/BOOT/BOOTX64.EFI", os.O_CREATE|os.O_RDWR)
+ if err != nil {
+ fmt.Printf("Failed to open EFI payload for writing: %v", err)
+ os.Exit(1)
+ }
+ efiPayloadSrc, err := os.Open(os.Args[1])
+ if err != nil {
+ fmt.Printf("Failed to open EFI payload for reading: %v", err)
+ os.Exit(1)
+ }
+ defer efiPayloadSrc.Close()
+ // If this is streamed (e.g. using io.Copy) it exposes a bug in diskfs, so do it in one go.
+ efiPayloadFull, err := ioutil.ReadAll(efiPayloadSrc)
+ if err != nil {
+ panic(err)
+ }
+ if _, err := efiPayload.Write(efiPayloadFull); err != nil {
+ fmt.Printf("Failed to write EFI payload: %v", err)
+ os.Exit(1)
+ }
+ if err := diskImg.File.Close(); err != nil {
+ fmt.Printf("Failed to write image: %v", err)
+ os.Exit(1)
+ }
+ fmt.Println("Success! You can now boot smalltown.img")
+}