Merge lp:~mvo/snappy/15.04-snappy-bootsuccess-env2 into lp:~snappy-dev/snappy/15.04-deprecated

Proposed by Michael Vogt
Status: Merged
Approved by: John Lenton
Approved revision: 462
Merged at revision: 461
Proposed branch: lp:~mvo/snappy/15.04-snappy-bootsuccess-env2
Merge into: lp:~snappy-dev/snappy/15.04-deprecated
Diff against target: 307 lines (+158/-27)
7 files modified
debian/control (+1/-0)
dependencies.tsv (+1/-0)
partition/bootloader.go (+2/-0)
partition/bootloader_grub.go (+6/-8)
partition/bootloader_uboot.go (+91/-19)
partition/bootloader_uboot_test.go (+56/-0)
partition/partition_test.go (+1/-0)
To merge this branch: bzr merge lp:~mvo/snappy/15.04-snappy-bootsuccess-env2
Reviewer Review Type Date Requested Status
John Lenton (community) Approve
Review via email: mp+265510@code.launchpad.net

Commit message

Backports of the uboot.env changes from trunk.

Description of the change

This branch backports the uboot.env changes from trunk to 15.04

To post a comment you must log in.
462. By Michael Vogt

merge remaining revisions

Revision history for this message
John Lenton (chipaca) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'debian/control'
--- debian/control 2015-04-21 22:02:02 +0000
+++ debian/control 2015-07-22 12:17:55 +0000
@@ -15,6 +15,7 @@
15 golang-goconfigparser-dev,15 golang-goconfigparser-dev,
16 golang-juju-loggo-dev,16 golang-juju-loggo-dev,
17 golang-pb-dev,17 golang-pb-dev,
18 golang-uboot-go-dev,
18 golang-yaml.v2-dev19 golang-yaml.v2-dev
19Standards-Version: 3.9.620Standards-Version: 3.9.6
20Homepage: https://launchpad.net/snappy21Homepage: https://launchpad.net/snappy
2122
=== modified file 'dependencies.tsv'
--- dependencies.tsv 2015-03-19 09:33:48 +0000
+++ dependencies.tsv 2015-07-22 12:17:55 +0000
@@ -4,5 +4,6 @@
4github.com/jessevdk/go-flags git 15347ef417a300349807983f15af9e65cd2e1b3a 2015-01-25T08:53:51Z4github.com/jessevdk/go-flags git 15347ef417a300349807983f15af9e65cd2e1b3a 2015-01-25T08:53:51Z
5github.com/juju/loggo git 4c7cbce140ca070eeb59a28f4bf9507e511711f9 2015-02-26T05:51:10Z5github.com/juju/loggo git 4c7cbce140ca070eeb59a28f4bf9507e511711f9 2015-02-26T05:51:10Z
6github.com/mvo5/goconfigparser git 26426272dda20cc76aa1fa44286dc743d2972fe8 2015-02-12T09:37:50Z6github.com/mvo5/goconfigparser git 26426272dda20cc76aa1fa44286dc743d2972fe8 2015-02-12T09:37:50Z
7github.com/mvo5/uboot-go git 361f6ebcbb54f389d15dc9faefa000e996ba3e37 2015-07-22T06:53:46Z
7gopkg.in/yaml.v2 git 49c95bdc21843256fb6c4e0d370a05f24a0bf213 2015-02-24T22:57:58Z8gopkg.in/yaml.v2 git 49c95bdc21843256fb6c4e0d370a05f24a0bf213 2015-02-24T22:57:58Z
8launchpad.net/gocheck bzr gustavo@niemeyer.net-20140225173054-xu9zlkf9kxhvow02 879launchpad.net/gocheck bzr gustavo@niemeyer.net-20140225173054-xu9zlkf9kxhvow02 87
910
=== modified file 'partition/bootloader.go'
--- partition/bootloader.go 2015-04-14 20:37:54 +0000
+++ partition/bootloader.go 2015-07-22 12:17:55 +0000
@@ -27,6 +27,8 @@
27 // that the boot of the new rootfs was successful).27 // that the boot of the new rootfs was successful).
28 bootloaderBootmodeVar = "snappy_mode"28 bootloaderBootmodeVar = "snappy_mode"
2929
30 bootloaderTrialBootVar = "snappy_trial_boot"
31
30 // Initial and final values32 // Initial and final values
31 bootloaderBootmodeTry = "try"33 bootloaderBootmodeTry = "try"
32 bootloaderBootmodeSuccess = "regular"34 bootloaderBootmodeSuccess = "regular"
3335
=== modified file 'partition/bootloader_grub.go'
--- partition/bootloader_grub.go 2015-04-30 11:28:39 +0000
+++ partition/bootloader_grub.go 2015-07-22 12:17:55 +0000
@@ -30,17 +30,15 @@
30 bootloaderGrubConfigFileReal = "/boot/grub/grub.cfg"30 bootloaderGrubConfigFileReal = "/boot/grub/grub.cfg"
31 bootloaderGrubEnvFileReal = "/boot/grub/grubenv"31 bootloaderGrubEnvFileReal = "/boot/grub/grubenv"
3232
33 bootloaderGrubEnvCmdReal = "/usr/bin/grub-editenv"33 bootloaderGrubEnvCmdReal = "/usr/bin/grub-editenv"
34 bootloaderGrubUpdateCmdReal = "/usr/sbin/update-grub"34 bootloaderGrubUpdateCmdReal = "/usr/sbin/update-grub"
35 bootloaderGrubTrialBootVarReal = "snappy_trial_boot"
36)35)
3736
38// var to make it testable37// var to make it testable
39var (38var (
40 bootloaderGrubDir = bootloaderGrubDirReal39 bootloaderGrubDir = bootloaderGrubDirReal
41 bootloaderGrubConfigFile = bootloaderGrubConfigFileReal40 bootloaderGrubConfigFile = bootloaderGrubConfigFileReal
42 bootloaderGrubTrialBootVar = bootloaderGrubTrialBootVarReal41 bootloaderGrubEnvFile = bootloaderGrubEnvFileReal
43 bootloaderGrubEnvFile = bootloaderGrubEnvFileReal
4442
45 bootloaderGrubEnvCmd = bootloaderGrubEnvCmdReal43 bootloaderGrubEnvCmd = bootloaderGrubEnvCmdReal
46 bootloaderGrubUpdateCmd = bootloaderGrubUpdateCmdReal44 bootloaderGrubUpdateCmd = bootloaderGrubUpdateCmdReal
@@ -136,7 +134,7 @@
136func (g *grub) MarkCurrentBootSuccessful() (err error) {134func (g *grub) MarkCurrentBootSuccessful() (err error) {
137 // Clear the variable set by grub on boot to denote a good135 // Clear the variable set by grub on boot to denote a good
138 // boot.136 // boot.
139 if err := g.unsetBootVar(bootloaderGrubTrialBootVar); err != nil {137 if err := g.unsetBootVar(bootloaderTrialBootVar); err != nil {
140 return err138 return err
141 }139 }
142140
143141
=== modified file 'partition/bootloader_uboot.go'
--- partition/bootloader_uboot.go 2015-06-03 12:12:13 +0000
+++ partition/bootloader_uboot.go 2015-07-22 12:17:55 +0000
@@ -28,6 +28,7 @@
28 "launchpad.net/snappy/helpers"28 "launchpad.net/snappy/helpers"
2929
30 "github.com/mvo5/goconfigparser"30 "github.com/mvo5/goconfigparser"
31 "github.com/mvo5/uboot-go/uenv"
31)32)
3233
33const (34const (
@@ -40,9 +41,11 @@
40 // this partition is "good".41 // this partition is "good".
41 bootloaderUbootStampFileReal = "/boot/uboot/snappy-stamp.txt"42 bootloaderUbootStampFileReal = "/boot/uboot/snappy-stamp.txt"
4243
43 // the main uEnv.txt u-boot config file sources this snappy44 // DEPRECATED:
44 // boot-specific config file.
45 bootloaderUbootEnvFileReal = "/boot/uboot/snappy-system.txt"45 bootloaderUbootEnvFileReal = "/boot/uboot/snappy-system.txt"
46
47 // the real uboot env
48 bootloaderUbootFwEnvFileReal = "/boot/uboot/uboot.env"
46)49)
4750
48// var to make it testable51// var to make it testable
@@ -51,6 +54,7 @@
51 bootloaderUbootConfigFile = bootloaderUbootConfigFileReal54 bootloaderUbootConfigFile = bootloaderUbootConfigFileReal
52 bootloaderUbootStampFile = bootloaderUbootStampFileReal55 bootloaderUbootStampFile = bootloaderUbootStampFileReal
53 bootloaderUbootEnvFile = bootloaderUbootEnvFileReal56 bootloaderUbootEnvFile = bootloaderUbootEnvFileReal
57 bootloaderUbootFwEnvFile = bootloaderUbootFwEnvFileReal
54 atomicFileUpdate = atomicFileUpdateImpl58 atomicFileUpdate = atomicFileUpdateImpl
55)59)
5660
@@ -199,23 +203,6 @@
199 return file.Sync()203 return file.Sync()
200}204}
201205
202func (u *uboot) MarkCurrentBootSuccessful() (err error) {
203 changes := []configFileChange{
204 configFileChange{Name: bootloaderBootmodeVar,
205 Value: bootloaderBootmodeSuccess,
206 },
207 configFileChange{Name: bootloaderRootfsVar,
208 Value: string(u.currentRootfs),
209 },
210 }
211
212 if err := modifyNameValueFile(bootloaderUbootEnvFile, changes); err != nil {
213 return err
214 }
215
216 return os.RemoveAll(bootloaderUbootStampFile)
217}
218
219func (u *uboot) SyncBootFiles() (err error) {206func (u *uboot) SyncBootFiles() (err error) {
220 srcDir := u.currentBootPath207 srcDir := u.currentBootPath
221 destDir := u.otherBootPath208 destDir := u.otherBootPath
@@ -317,6 +304,91 @@
317 return err304 return err
318}305}
319306
307func (u *uboot) unsetBootVar(name string) error {
308 hasBootVar, err := u.hasBootVar(name)
309 if err != nil {
310 return err
311 }
312
313 // already unset, nothing to do
314 if !hasBootVar {
315 return nil
316 }
317
318 return u.setBootVar(name, "")
319}
320
321func (u *uboot) setBootVar(name, value string) error {
322 env, err := uenv.Open(bootloaderUbootFwEnvFile)
323 if err != nil {
324 return err
325 }
326
327 // already set, nothing to do
328 if env.Get(name) == value {
329 return nil
330 }
331
332 env.Set(name, value)
333 return env.Save()
334}
335
336func (u *uboot) hasBootVar(name string) (bool, error) {
337 v, err := u.getBootVar(name)
338 return v != "", err
339}
340
341func (u *uboot) getBootVar(name string) (string, error) {
342 env, err := uenv.Open(bootloaderUbootFwEnvFile)
343 if err != nil {
344 return "", err
345 }
346
347 return env.Get(name), nil
348}
349
350// FIXME: this is super similar to grub now, refactor to extract the
351// common code
352func (u *uboot) markCurrentBootSuccessfulFwEnv(currentRootfs string) error {
353 // Clear the variable set on boot to denote a good boot.
354 if err := u.unsetBootVar(bootloaderTrialBootVar); err != nil {
355 return err
356 }
357
358 if err := u.setBootVar(bootloaderRootfsVar, currentRootfs); err != nil {
359 return err
360 }
361
362 return u.setBootVar(bootloaderBootmodeVar, bootloaderBootmodeSuccess)
363}
364
365func (u *uboot) markCurrentBootSuccessfulLegacy(currentRootfs string) error {
366 changes := []configFileChange{
367 configFileChange{Name: bootloaderBootmodeVar,
368 Value: bootloaderBootmodeSuccess,
369 },
370 configFileChange{Name: bootloaderRootfsVar,
371 Value: string(u.currentRootfs),
372 },
373 }
374
375 if err := modifyNameValueFile(bootloaderUbootEnvFile, changes); err != nil {
376 return err
377 }
378
379 return os.RemoveAll(bootloaderUbootStampFile)
380}
381
382func (u *uboot) MarkCurrentBootSuccessful() error {
383 // modern system
384 if helpers.FileExists(bootloaderUbootFwEnvFile) {
385 return u.markCurrentBootSuccessfulFwEnv(u.currentRootfs)
386 }
387
388 // legacy
389 return u.markCurrentBootSuccessfulLegacy(u.currentRootfs)
390}
391
320// Write lines to file atomically. File does not have to preexist.392// Write lines to file atomically. File does not have to preexist.
321// FIXME: put into utils package393// FIXME: put into utils package
322func atomicFileUpdateImpl(file string, lines []string) (err error) {394func atomicFileUpdateImpl(file string, lines []string) (err error) {
323395
=== modified file 'partition/bootloader_uboot_test.go'
--- partition/bootloader_uboot_test.go 2015-06-02 20:23:20 +0000
+++ partition/bootloader_uboot_test.go 2015-07-22 12:17:55 +0000
@@ -22,9 +22,12 @@
22 "os"22 "os"
23 "path/filepath"23 "path/filepath"
24 "strings"24 "strings"
25 "time"
2526
26 . "launchpad.net/gocheck"27 . "launchpad.net/gocheck"
27 "launchpad.net/snappy/helpers"28 "launchpad.net/snappy/helpers"
29
30 "github.com/mvo5/uboot-go/uenv"
28)31)
2932
30// TODO move to uboot specific test suite.33// TODO move to uboot specific test suite.
@@ -328,3 +331,56 @@
328 c.Check(strings.Contains(string(bytes), "snappy_mode=regular"), Equals, true)331 c.Check(strings.Contains(string(bytes), "snappy_mode=regular"), Equals, true)
329 c.Check(strings.Contains(string(bytes), "snappy_ab=a"), Equals, true)332 c.Check(strings.Contains(string(bytes), "snappy_ab=a"), Equals, true)
330}333}
334
335func (s *PartitionTestSuite) TestUbootMarkCurrentBootSuccessfulFwEnv(c *C) {
336 s.makeFakeUbootEnv(c)
337
338 env, err := uenv.Create(bootloaderUbootFwEnvFile, 4096)
339 c.Assert(err, IsNil)
340 env.Set("snappy_ab", "a")
341 env.Set("snappy_mode", "try")
342 env.Set("snappy_trial_boot", "1")
343 err = env.Save()
344 c.Assert(err, IsNil)
345
346 partition := New()
347 u := newUboot(partition)
348 c.Assert(u, NotNil)
349
350 err = u.MarkCurrentBootSuccessful()
351 c.Assert(err, IsNil)
352
353 env, err = uenv.Open(bootloaderUbootFwEnvFile)
354 c.Assert(err, IsNil)
355 c.Assert(env.String(), Equals, "snappy_ab=a\nsnappy_mode=regular\n")
356}
357
358func (s *PartitionTestSuite) TestUbootSetEnvNoUselessWrites(c *C) {
359 s.makeFakeUbootEnv(c)
360
361 env, err := uenv.Create(bootloaderUbootFwEnvFile, 4096)
362 c.Assert(err, IsNil)
363 env.Set("snappy_ab", "a")
364 env.Set("snappy_mode", "regular")
365 err = env.Save()
366 c.Assert(err, IsNil)
367
368 st, err := os.Stat(bootloaderUbootFwEnvFile)
369 c.Assert(err, IsNil)
370 time.Sleep(100 * time.Millisecond)
371
372 partition := New()
373 u := newUboot(partition)
374 c.Assert(u, NotNil)
375
376 err = u.(*uboot).setBootVar(bootloaderRootfsVar, "a")
377 c.Assert(err, IsNil)
378
379 env, err = uenv.Open(bootloaderUbootFwEnvFile)
380 c.Assert(err, IsNil)
381 c.Assert(env.String(), Equals, "snappy_ab=a\nsnappy_mode=regular\n")
382
383 st2, err := os.Stat(bootloaderUbootFwEnvFile)
384 c.Assert(err, IsNil)
385 c.Assert(st.ModTime(), Equals, st2.ModTime())
386}
331387
=== modified file 'partition/partition_test.go'
--- partition/partition_test.go 2015-03-30 14:42:31 +0000
+++ partition/partition_test.go 2015-07-22 12:17:55 +0000
@@ -60,6 +60,7 @@
60 bootloaderUbootDir = filepath.Join(s.tempdir, "boot", "uboot")60 bootloaderUbootDir = filepath.Join(s.tempdir, "boot", "uboot")
61 bootloaderUbootConfigFile = filepath.Join(bootloaderUbootDir, "uEnv.txt")61 bootloaderUbootConfigFile = filepath.Join(bootloaderUbootDir, "uEnv.txt")
62 bootloaderUbootEnvFile = filepath.Join(bootloaderUbootDir, "uEnv.txt")62 bootloaderUbootEnvFile = filepath.Join(bootloaderUbootDir, "uEnv.txt")
63 bootloaderUbootFwEnvFile = filepath.Join(bootloaderUbootDir, "uboot.env")
63 bootloaderUbootStampFile = filepath.Join(bootloaderUbootDir, "snappy-stamp.txt")64 bootloaderUbootStampFile = filepath.Join(bootloaderUbootDir, "snappy-stamp.txt")
6465
65 c.Assert(mounts, DeepEquals, mountEntryArray(nil))66 c.Assert(mounts, DeepEquals, mountEntryArray(nil))

Subscribers

People subscribed via source and target branches