Merge lp:~vorlon/goget-ubuntu-touch/uefi into lp:goget-ubuntu-touch

Proposed by Steve Langasek on 2015-04-20
Status: Merged
Approved by: Sergio Schvezov on 2015-05-01
Approved revision: 168
Merged at revision: 172
Proposed branch: lp:~vorlon/goget-ubuntu-touch/uefi
Merge into: lp:goget-ubuntu-touch
Diff against target: 109 lines (+47/-7)
2 files modified
diskimage/core_grub.go (+45/-5)
ubuntu-device-flash/core.go (+2/-2)
To merge this branch: bzr merge lp:~vorlon/goget-ubuntu-touch/uefi
Reviewer Review Type Date Requested Status
Sergio Schvezov 2015-04-20 Approve on 2015-05-01
Review via email: mp+256869@code.launchpad.net

Commit Message

UEFI support for ubuntu-device-flash.

Description of the Change

This is a preliminary MP for adding UEFI support to ubuntu-device-flash.
It's not ready for merging, because the handling needs to be conditional by
architecture.

To post a comment you must log in.
Sergio Schvezov (sergiusens) wrote :

make func NewCoreGrubImage(location string, size int64) *CoreGrubImage {

look like the u-boot one

func NewCoreUBootImage(location string, size int64, hw HardwareDescription, oem OemDescription) *CoreUBootImage {

and keep the oem (and hw) entries as members of the struct, then,

oem.Architecture() returns the arch

Steve Langasek (vorlon) wrote :

Now uses oem.Architecture() support from trunk, so I think this is ready for review.

Before merging we should verify whether writing of grub_env works from EFI, without which the a/b failover support won't work correctly.

Steve Langasek (vorlon) wrote :

I've just done a quick test setting a grub_env variable under EFI GRUB, and it appears to work fine.

Sergio Schvezov (sergiusens) wrote :

This looks good, but can you apply this please?

$ gofmt -d diskimage/core_grub.go
diff diskimage/core_grub.go gofmt/diskimage/core_grub.go
--- /tmp/gofmt586008706 2015-04-27 08:53:38.737751816 +0200
+++ /tmp/gofmt636166137 2015-04-27 08:53:38.737751816 +0200
@@ -342,7 +342,7 @@
   return fmt.Errorf("unsupported architecture for GRUB on EFI: %s", arch)
  }

- if (arch == "amd64" || arch == "i386") {
+ if arch == "amd64" || arch == "i386" {
   // install grub BIOS support
   if out, err := exec.Command("chroot", img.System(), "grub-install", "/root_dev").CombinedOutput(); err != nil {
    return fmt.Errorf("unable to install grub (BIOS): %s", out)
@@ -350,7 +350,7 @@
  }

  // install grub EFI
- if out, err := exec.Command("chroot", img.System(), "grub-install", fmt.Sprint("--target=" + grubTarget), "--no-nvram", "--removable", "--efi-directory=/boot/efi").CombinedOutput(); err != nil {
+ if out, err := exec.Command("chroot", img.System(), "grub-install", fmt.Sprint("--target="+grubTarget), "--no-nvram", "--removable", "--efi-directory=/boot/efi").CombinedOutput(); err != nil {
   return fmt.Errorf("unable to install grub (EFI): %s", out)
  }
  // tell our EFI grub where to find its full config
@@ -364,7 +364,6 @@
   return err
  }

-
  // ensure we run not into recordfail issue
  grubDir := filepath.Join(img.System(), "etc", "default", "grub.d")
  if err := os.MkdirAll(grubDir, 0755); err != nil {

lp:~vorlon/goget-ubuntu-touch/uefi updated on 2015-04-27
168. By Steve Langasek on 2015-04-27

formatting/style changes per Sergio

Sergio Schvezov (sergiusens) wrote :

Thanks for this branch!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'diskimage/core_grub.go'
2--- diskimage/core_grub.go 2015-04-16 23:06:44 +0000
3+++ diskimage/core_grub.go 2015-04-27 07:03:04 +0000
4@@ -1,7 +1,7 @@
5 //
6 // diskimage - handles ubuntu disk images
7 //
8-// Copyright (c) 2013 Canonical Ltd.
9+// Copyright (c) 2013-2015 Canonical Ltd.
10 //
11 // Written by Sergio Schvezov <sergio.schvezov@canonical.com>
12 //
13@@ -35,16 +35,20 @@
14
15 type CoreGrubImage struct {
16 CoreImage
17+ hardware HardwareDescription
18+ oem OemDescription
19 location string
20 size int64
21 baseMount string
22 parts []partition
23 }
24
25-func NewCoreGrubImage(location string, size int64) *CoreGrubImage {
26+func NewCoreGrubImage(location string, size int64, hw HardwareDescription, oem OemDescription) *CoreGrubImage {
27 return &CoreGrubImage{
28 location: location,
29 size: size,
30+ hardware: hw,
31+ oem: oem,
32 }
33 }
34
35@@ -55,6 +59,10 @@
36 GRUB_RECORDFAIL_TIMEOUT=0
37 `
38
39+const grubStubContent = `set prefix=($root)'/EFI/ubuntu/grub'
40+configfile $prefix/grub.cfg
41+`
42+
43 func (img *CoreGrubImage) Mount() error {
44 baseMount, err := mount(img.parts)
45 if err != nil {
46@@ -319,9 +327,41 @@
47 }
48 defer unmount(bootGrubDir)
49
50- // install grub
51- if out, err := exec.Command("chroot", img.System(), "grub-install", "/root_dev").CombinedOutput(); err != nil {
52- return fmt.Errorf("unable to install grub: %s", out)
53+ var grubTarget string
54+
55+ arch := img.oem.Architecture()
56+
57+ switch arch {
58+ case "armhf":
59+ grubTarget = "arm-efi"
60+ case "amd64":
61+ grubTarget = "x86_64-efi"
62+ case "i386":
63+ grubTarget = "i386-efi"
64+ default:
65+ return fmt.Errorf("unsupported architecture for GRUB on EFI: %s", arch)
66+ }
67+
68+ if arch == "amd64" || arch == "i386" {
69+ // install grub BIOS support
70+ if out, err := exec.Command("chroot", img.System(), "grub-install", "/root_dev").CombinedOutput(); err != nil {
71+ return fmt.Errorf("unable to install grub (BIOS): %s", out)
72+ }
73+ }
74+
75+ // install grub EFI
76+ if out, err := exec.Command("chroot", img.System(), "grub-install", fmt.Sprint("--target="+grubTarget), "--no-nvram", "--removable", "--efi-directory=/boot/efi").CombinedOutput(); err != nil {
77+ return fmt.Errorf("unable to install grub (EFI): %s", out)
78+ }
79+ // tell our EFI grub where to find its full config
80+ efiBootDir := filepath.Join(img.System(), "boot", "efi", "EFI", "BOOT")
81+ grubStub, err := os.Create(filepath.Join(efiBootDir, "grub.cfg"))
82+ if err != nil {
83+ return fmt.Errorf("unable to create %s file: %s", grubStub.Name(), err)
84+ }
85+ defer grubStub.Close()
86+ if _, err := io.WriteString(grubStub, grubStubContent); err != nil {
87+ return err
88 }
89
90 // ensure we run not into recordfail issue
91
92=== modified file 'ubuntu-device-flash/core.go'
93--- ubuntu-device-flash/core.go 2015-04-23 03:40:37 +0000
94+++ ubuntu-device-flash/core.go 2015-04-27 07:03:04 +0000
95@@ -235,12 +235,12 @@
96 loader := coreCmd.oem.OEM.Hardware.Bootloader
97 switch loader {
98 case "grub":
99- img = diskimage.NewCoreGrubImage(coreCmd.Output, coreCmd.Size)
100+ img = diskimage.NewCoreGrubImage(coreCmd.Output, coreCmd.Size, coreCmd.hardware, coreCmd.oem)
101 case "u-boot":
102 img = diskimage.NewCoreUBootImage(coreCmd.Output, coreCmd.Size, coreCmd.hardware, coreCmd.oem)
103 default:
104 fmt.Printf("Bootloader set to '%s' in oem hardware description, assuming grub as a fallback\n", loader)
105- img = diskimage.NewCoreGrubImage(coreCmd.Output, coreCmd.Size)
106+ img = diskimage.NewCoreGrubImage(coreCmd.Output, coreCmd.Size, coreCmd.hardware, coreCmd.oem)
107 }
108
109 printOut("Partitioning...")

Subscribers

People subscribed via source and target branches