]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-boot: stub - export LoaderDevicePartUUID
authorKay Sievers <kay@vrfy.org>
Wed, 29 Jul 2015 17:26:49 +0000 (19:26 +0200)
committerKay Sievers <kay@vrfy.org>
Wed, 29 Jul 2015 17:36:17 +0000 (19:36 +0200)
Makefile.am
src/boot/efi/boot.c
src/boot/efi/disk.c [new file with mode: 0644]
src/boot/efi/disk.h [new file with mode: 0644]
src/boot/efi/stub.c

index e908ca298438eb1ca2160977ebee7cfb10363fd0..4953d8d78236a98ace41a6c6f51d761381c7d688 100644 (file)
@@ -2519,13 +2519,15 @@ systemd_boot_headers = \
        src/boot/efi/util.h \
        src/boot/efi/console.h \
        src/boot/efi/graphics.h \
-       src/boot/efi/pefile.h
+       src/boot/efi/pefile.h \
+       src/boot/efi/disk.h
 
 systemd_boot_sources = \
        src/boot/efi/util.c \
        src/boot/efi/console.c \
        src/boot/efi/graphics.c \
        src/boot/efi/pefile.c \
+       src/boot/efi/disk.c \
        src/boot/efi/boot.c
 
 EXTRA_DIST += $(systemd_boot_sources) $(systemd_boot_headers)
@@ -2558,6 +2560,7 @@ endif
 stub_headers = \
        src/boot/efi/util.h \
        src/boot/efi/pefile.h \
+       src/boot/efi/disk.h \
        src/boot/efi/graphics.h \
        src/boot/efi/splash.h \
        src/boot/efi/linux.h
@@ -2565,6 +2568,7 @@ stub_headers = \
 stub_sources = \
        src/boot/efi/util.c \
        src/boot/efi/pefile.c \
+       src/boot/efi/disk.c \
        src/boot/efi/graphics.c \
        src/boot/efi/splash.c \
        src/boot/efi/linux.c \
index e8cd8abd26155e86ad4085fbd0e7eff16c4557d3..dde0c41744e27586d0a881db9c692967aa538a45 100644 (file)
@@ -22,6 +22,7 @@
 #include "console.h"
 #include "graphics.h"
 #include "pefile.h"
+#include "disk.h"
 #include "linux.h"
 
 #ifndef EFI_OS_INDICATIONS_BOOT_TO_FW_UI
@@ -1696,11 +1697,11 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) {
         EFI_LOADED_IMAGE *loaded_image;
         EFI_FILE *root_dir;
         CHAR16 *loaded_image_path;
-        EFI_DEVICE_PATH *device_path;
         EFI_STATUS err;
         Config config;
         UINT64 init_usec;
         BOOLEAN menu = FALSE;
+        CHAR16 uuid[37];
 
         InitializeLib(image, sys_table);
         init_usec = time_usec();
@@ -1722,29 +1723,8 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) {
         }
 
         /* export the device path this image is started from */
-        device_path = DevicePathFromHandle(loaded_image->DeviceHandle);
-        if (device_path) {
-                EFI_DEVICE_PATH *path, *paths;
-
-                paths = UnpackDevicePath(device_path);
-                for (path = paths; !IsDevicePathEnd(path); path = NextDevicePathNode(path)) {
-                        HARDDRIVE_DEVICE_PATH *drive;
-                        CHAR16 uuid[37];
-
-                        if (DevicePathType(path) != MEDIA_DEVICE_PATH)
-                                continue;
-                        if (DevicePathSubType(path) != MEDIA_HARDDRIVE_DP)
-                                continue;
-                        drive = (HARDDRIVE_DEVICE_PATH *)path;
-                        if (drive->SignatureType != SIGNATURE_TYPE_GUID)
-                                continue;
-
-                        GuidToString(uuid, (EFI_GUID *)&drive->Signature);
-                        efivar_set(L"LoaderDevicePartUUID", uuid, FALSE);
-                        break;
-                }
-                FreePool(paths);
-        }
+        if (disk_get_part_uuid(loaded_image->DeviceHandle, uuid) == EFI_SUCCESS)
+                efivar_set(L"LoaderDevicePartUUID", uuid, FALSE);
 
         root_dir = LibOpenRoot(loaded_image->DeviceHandle);
         if (!root_dir) {
diff --git a/src/boot/efi/disk.c b/src/boot/efi/disk.c
new file mode 100644 (file)
index 0000000..96063fb
--- /dev/null
@@ -0,0 +1,51 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/*
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * Copyright (C) 2015 Kay Sievers <kay@vrfy.org>
+ */
+
+#include <efi.h>
+#include <efilib.h>
+
+#include "util.h"
+
+EFI_STATUS disk_get_part_uuid(EFI_HANDLE *handle, CHAR16 uuid[37]) {
+        EFI_DEVICE_PATH *device_path;
+        EFI_STATUS r = EFI_NOT_FOUND;
+
+        /* export the device path this image is started from */
+        device_path = DevicePathFromHandle(handle);
+        if (device_path) {
+                EFI_DEVICE_PATH *path, *paths;
+
+                paths = UnpackDevicePath(device_path);
+                for (path = paths; !IsDevicePathEnd(path); path = NextDevicePathNode(path)) {
+                        HARDDRIVE_DEVICE_PATH *drive;
+
+                        if (DevicePathType(path) != MEDIA_DEVICE_PATH)
+                                continue;
+                        if (DevicePathSubType(path) != MEDIA_HARDDRIVE_DP)
+                                continue;
+                        drive = (HARDDRIVE_DEVICE_PATH *)path;
+                        if (drive->SignatureType != SIGNATURE_TYPE_GUID)
+                                continue;
+
+                        GuidToString(uuid, (EFI_GUID *)&drive->Signature);
+                        r = EFI_SUCCESS;
+                        break;
+                }
+                FreePool(paths);
+        }
+
+        return r;
+}
diff --git a/src/boot/efi/disk.h b/src/boot/efi/disk.h
new file mode 100644 (file)
index 0000000..1b25343
--- /dev/null
@@ -0,0 +1,21 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/*
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * Copyright (C) 2015 Kay Sievers <kay@vrfy.org>
+ */
+
+#ifndef __SDBOOT_DISK_H
+#define __SDBOOT_DISK_H
+
+EFI_STATUS disk_get_part_uuid(EFI_HANDLE *handle, CHAR16 uuid[37]);
+#endif
index 0b1bc491ed733375ae0e58e193e179dd8dc7b50a..0c5ee4e9ff5316864e6808cbaa6c51712832bd40 100644 (file)
@@ -18,6 +18,7 @@
 
 #include "util.h"
 #include "pefile.h"
+#include "disk.h"
 #include "graphics.h"
 #include "splash.h"
 #include "linux.h"
@@ -46,6 +47,7 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) {
         UINTN szs[ELEMENTSOF(sections)-1] = {};
         CHAR8 *cmdline = NULL;
         UINTN cmdline_len;
+        CHAR16 uuid[37];
         EFI_STATUS err;
 
         InitializeLib(image, sys_table);
@@ -99,6 +101,10 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) {
                 cmdline = line;
         }
 
+        /* export the device path this image is started from */
+        if (disk_get_part_uuid(loaded_image->DeviceHandle, uuid) == EFI_SUCCESS)
+                efivar_set(L"LoaderDevicePartUUID", uuid, FALSE);
+
         if (szs[3] > 0)
                 graphics_splash((UINT8 *)((UINTN)loaded_image->ImageBase + addrs[3]), szs[3], NULL);