m/p/efivarfs: import the EFI boot entry data type

This imports marshal.go from the Softmetal project.

The complete MIT license under which it was released was added at the
start of the file. It was renamed to boot.go which better reflects its
purpose in its current context. The implementation was adapted for
Metropolis.

Change-Id: I41d1b10bf5105c52fa7de7695def5b6f3a9b192e
Reviewed-on: https://review.monogon.dev/c/monogon/+/427
Reviewed-by: Lorenz Brun <lorenz@monogon.tech>
diff --git a/metropolis/pkg/efivarfs/efivarfs.go b/metropolis/pkg/efivarfs/efivarfs.go
index 90c4519..0287fc9 100644
--- a/metropolis/pkg/efivarfs/efivarfs.go
+++ b/metropolis/pkg/efivarfs/efivarfs.go
@@ -34,6 +34,11 @@
 	GlobalGuid = "8be4df61-93ca-11d2-aa0d-00e098032b8c"
 )
 
+// Encoding defines the Unicode encoding used by UEFI, which is UCS-2 Little
+// Endian. For BMP characters UTF-16 is equivalent to UCS-2. See the UEFI
+// Spec 2.9, Sections 33.2.6 and 1.8.1.
+var Encoding = unicode.UTF16(unicode.LittleEndian, unicode.IgnoreBOM)
+
 // ExtractString returns EFI variable data based on raw variable file contents.
 // It returns string-represented data, or an error.
 func ExtractString(contents []byte) (string, error) {
@@ -41,13 +46,9 @@
 	if len(contents) < 4 {
 		return "", fmt.Errorf("contents too short.")
 	}
-	// efiUnicode defines the Unicode encoding used by UEFI which is UCS-2
-	// Little Endian. For BMP characters UTF-16 is equivalent to UCS-2.
-	// See the UEFI Spec 2.9, Sections 33.2.6 and 1.8.1.
-	efiUnicode := unicode.UTF16(unicode.LittleEndian, unicode.IgnoreBOM)
 	// Skip attributes, see @linux//Documentation/filesystems:efivarfs.rst for format
 	efiVarData := contents[4:]
-	espUUIDNullTerminated, err := efiUnicode.NewDecoder().Bytes(efiVarData)
+	espUUIDNullTerminated, err := Encoding.NewDecoder().Bytes(efiVarData)
 	if err != nil {
 		// Pass the decoding error unwrapped.
 		return "", err