|
Zbigniew Jędrzejewski-Szmek |
1d782f |
From 80a7043f12ffe6985ef3ce5bd9aac6c1c2ae2219 Mon Sep 17 00:00:00 2001
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
Date: Sat, 10 Feb 2018 18:24:52 +0100
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
Subject: [PATCH] Check architecture lazily
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
Before this patch, mkosi wouldn't even run --help on a platform that
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
wasn't amd64 or arm64. That's unnecessarily harsh, a lot of functionality
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
is platform-independent and will work anywhere.
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
---
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
mkosi | 33 +++++++++++++++++++++------------
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
1 file changed, 21 insertions(+), 12 deletions(-)
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
diff --git a/mkosi b/mkosi
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
index 4ef608bc68..3ecc1a7dd0 100755
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
--- a/mkosi
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
+++ b/mkosi
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
@@ -5,6 +5,7 @@
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
import argparse
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
import configparser
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
import contextlib
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
+import collections
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
import crypt
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
import ctypes, ctypes.util
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
import errno
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
@@ -84,15 +85,6 @@ GPT_ROOT_ARM_VERITY = uuid.UUID("7386cdf2203c47a9a498f2ecce45a2d6")
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
GPT_ROOT_ARM_64_VERITY = uuid.UUID("df3300ced69f4c92978c9bfb0f38d820")
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
GPT_ROOT_IA64_VERITY = uuid.UUID("86ed10d5b60745bb8957d350f23d0571")
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
-if platform.machine() == "x86_64":
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
- GPT_ROOT_NATIVE = GPT_ROOT_X86_64
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
- GPT_ROOT_NATIVE_VERITY = GPT_ROOT_X86_64_VERITY
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
-elif platform.machine() == "aarch64":
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
- GPT_ROOT_NATIVE = GPT_ROOT_ARM_64
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
- GPT_ROOT_NATIVE_VERITY = GPT_ROOT_ARM_64_VERITY
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
-else:
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
- die("Don't know the %s architecture." % platform.machine())
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
-
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
CLONE_NEWNS = 0x00020000
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
FEDORA_KEYS_MAP = {
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
@@ -109,6 +101,21 @@ FEDORA_KEYS_MAP = {
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
GPT_HEADER_SIZE = 1024*1024
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
GPT_FOOTER_SIZE = 1024*1024
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
+GPTRootTypePair = collections.namedtuple('GPTRootTypePair', 'root verity')
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
+
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
+def gpt_root_native():
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
+ """The tag for the native GPT root partition
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
+
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
+ Returns a tuple of two tags: for the root partition and for the
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
+ matching verity partition.
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
+ """
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
+ if platform.machine() == "x86_64":
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
+ return GPTRootTypePair(GPT_ROOT_X86_64, GPT_ROOT_X86_64_VERITY)
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
+ elif platform.machine() == "aarch64":
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
+ return GPTRootTypePair(GPT_ROOT_ARM_64, GPT_ROOT_ARM_64_VERITY)
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
+ else:
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
+ die("Unknown architecture {}.".format(platform.machine()))
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
+
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
def unshare(flags):
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
libc = ctypes.CDLL(ctypes.util.find_library("c"), use_errno=True)
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
@@ -367,7 +374,9 @@ def determine_partition_table(args):
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
run_sfdisk = True
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
if args.output_format != OutputFormat.raw_squashfs:
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
- table += 'type={}, attrs={}, name="Root Partition"\n'.format(GPT_ROOT_NATIVE, "GUID:60" if args.read_only and args.output_format != OutputFormat.raw_btrfs else "")
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
+ table += 'type={}, attrs={}, name="Root Partition"\n'.format(
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
+ gpt_root_native().root,
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
+ "GUID:60" if args.read_only and args.output_format != OutputFormat.raw_btrfs else "")
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
run_sfdisk = True
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
args.root_partno = pn
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
@@ -1930,7 +1939,7 @@ def insert_squashfs(args, workspace, raw, loopdev, squashfs, for_cache):
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
with complete_step('Inserting squashfs root partition'):
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
args.root_size = insert_partition(args, workspace, raw, loopdev, args.root_partno, squashfs,
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
- "Root Partition", GPT_ROOT_NATIVE)
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
+ "Root Partition", gpt_root_native().root)
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
def make_verity(args, workspace, dev, run_build_script, for_cache):
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
@@ -1962,7 +1971,7 @@ def insert_verity(args, workspace, raw, loopdev, verity, root_hash, for_cache):
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
with complete_step('Inserting verity partition'):
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
insert_partition(args, workspace, raw, loopdev, args.verity_partno, verity,
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
- "Verity Partition", GPT_ROOT_NATIVE_VERITY, u)
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
+ "Verity Partition", gpt_root_native().verity, u)
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
def patch_root_uuid(args, loopdev, root_hash, for_cache):
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
--
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
2.14.3
|
|
Zbigniew Jędrzejewski-Szmek |
1d782f |
|