Merge lp:~sergiusens/goget-ubuntu-touch/reducedSize into lp:~lool/goget-ubuntu-touch/fix-ftd-typos

Proposed by Sergio Schvezov
Status: Superseded
Proposed branch: lp:~sergiusens/goget-ubuntu-touch/reducedSize
Merge into: lp:~lool/goget-ubuntu-touch/fix-ftd-typos
Diff against target: 494 lines (+227/-53)
10 files modified
debian/changelog (+35/-0)
debian/control (+1/-0)
devices/adb.go (+5/-1)
diskimage/common.go (+14/-1)
diskimage/core_grub.go (+38/-1)
diskimage/core_uboot.go (+43/-30)
sysutils/utils.go (+3/-1)
sysutils/utils_test.go (+50/-0)
ubuntu-device-flash/core.go (+36/-5)
ubuntu-device-flash/touch.go (+2/-14)
To merge this branch: bzr merge lp:~sergiusens/goget-ubuntu-touch/reducedSize
Reviewer Review Type Date Requested Status
Michael Vogt Pending
Review via email: mp+253307@code.launchpad.net
To post a comment you must log in.

Unmerged revisions

141. By Sergio Schvezov

Making the total size 97.5% of the real total size for core and GB sized disks (not GiB)

140. By Sergio Schvezov

Releasing 0.18

139. By Sergio Schvezov

Populate both /boot/uboot/{a,b} when creating a ubuntu-core image.

138. By Sergio Schvezov

Releasing 0.17

137. By Sergio Schvezov

ubuntu-device-flash: more helpful error message on failed push.

136. By Sergio Schvezov

Releasing 0.16

* ubuntu-device-flash: oem part to allow for dtb overrides.
* debian/control: dep on fakeroot for ubuntu-device-flash.

135. By Sergio Schvezov

debian/control: u-d-f dependency on fakeroot

134. By Sergio Schvezov

Allowing oem part to contain a dtb to override the dtb provided by the device part for the platform

133. By Sergio Schvezov

Releasing 0.15

[ Loïc Minier ]
* ubuntu-device-flash: fixed ftdfile -> fdtfile typo.
[ Sergio Schvezov ]
* ubuntu-device-flash:
  - future proof efi support for grub and provisioning boot partition.
  - using test instead of load in snappy-commands.txt

132. By Sergio Schvezov

Future proof support for efi and boot partition support.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2015-01-21 23:25:47 +0000
3+++ debian/changelog 2015-03-18 03:33:51 +0000
4@@ -1,3 +1,38 @@
5+goget-ubuntu-touch (0.18-0ubuntu1) vivid; urgency=medium
6+
7+ [ Michael Vogt ]
8+ * Populate both /boot/uboot/{a,b} when creating a ubuntu-core image.
9+ (LP: #1428640)
10+
11+ -- Sergio Schvezov <sergio.schvezov@canonical.com> Fri, 06 Mar 2015 11:21:17 -0300
12+
13+goget-ubuntu-touch (0.17-0ubuntu1) vivid; urgency=medium
14+
15+ [ Jani Monoses ]
16+ * ubuntu-device-flash: more helpful error message on failed push.
17+ (LP: #1351039)
18+
19+ -- Sergio Schvezov <sergio.schvezov@canonical.com> Tue, 03 Mar 2015 07:27:17 -0300
20+
21+goget-ubuntu-touch (0.16-0ubuntu1) vivid; urgency=medium
22+
23+ * ubuntu-device-flash: oem part to allow for dtb overrides.
24+ * debian/control: dep on fakeroot for ubuntu-device-flash.
25+
26+ -- Sergio Schvezov <sergio.schvezov@canonical.com> Thu, 29 Jan 2015 15:23:27 -0300
27+
28+goget-ubuntu-touch (0.15-0ubuntu1) vivid; urgency=medium
29+
30+ [ Loïc Minier ]
31+ * ubuntu-device-flash: fixed ftdfile -> fdtfile typo.
32+
33+ [ Sergio Schvezov ]
34+ * ubuntu-device-flash:
35+ - future proof efi support for grub and provisioning boot partition.
36+ - using test instead of load in snappy-commands.txt
37+
38+ -- Sergio Schvezov <sergio.schvezov@canonical.com> Wed, 28 Jan 2015 19:53:33 -0300
39+
40 goget-ubuntu-touch (0.14-0ubuntu1) vivid; urgency=medium
41
42 * Partition sizing multiplier matters for the emulator disk. (LP: #1412495)
43
44=== modified file 'debian/control'
45--- debian/control 2015-01-15 22:33:59 +0000
46+++ debian/control 2015-03-18 03:33:51 +0000
47@@ -19,6 +19,7 @@
48 Architecture: any
49 Depends: android-tools-adb,
50 android-tools-fastboot,
51+ fakeroot,
52 kpartx,
53 qemu-user-static,
54 ${misc:Depends},
55
56=== modified file 'devices/adb.go'
57--- devices/adb.go 2014-09-25 13:40:20 +0000
58+++ devices/adb.go 2015-03-18 03:33:51 +0000
59@@ -76,7 +76,11 @@
60 func (adb AndroidDebugBridge) Push(src, dst string) (err error) {
61 // TODO add file path verification
62 cmd := append(adb.params, []string{"push", src, dst}...)
63- return exec.Command(adbCommand, cmd...).Run()
64+ b, err := exec.Command(adbCommand, cmd...).CombinedOutput()
65+ if err != nil {
66+ return fmt.Errorf("error pushing: %s\n", b)
67+ }
68+ return nil
69 }
70
71 // Pull copies a file from src to dst over the adb server
72
73=== modified file 'diskimage/common.go'
74--- diskimage/common.go 2015-01-15 21:05:01 +0000
75+++ diskimage/common.go 2015-03-18 03:33:51 +0000
76@@ -11,6 +11,7 @@
77 "fmt"
78 "os"
79 "os/exec"
80+ "path/filepath"
81 "strings"
82 )
83
84@@ -52,7 +53,7 @@
85 type CoreImage interface {
86 Image
87 SystemImage
88- SetupBoot() error
89+ SetupBoot(OemDescription) error
90 FlashExtra(string) error
91 }
92
93@@ -64,6 +65,18 @@
94 Bootloader string `yaml:"bootloader"`
95 }
96
97+type OemDescription struct {
98+ Name string `yaml:"name"`
99+ Version string `yaml:"version"`
100+ Hardware struct {
101+ Dtb string `yaml:"dtb,omitempty"`
102+ } `yaml:"hardware,omitempty"`
103+}
104+
105+func (o OemDescription) InstallPath() string {
106+ return filepath.Join("/oem", o.Name, o.Version)
107+}
108+
109 func sectorSize(dev string) (string, error) {
110 out, err := exec.Command("blockdev", "--getss", dev).CombinedOutput()
111 if err != nil {
112
113=== modified file 'diskimage/core_grub.go'
114--- diskimage/core_grub.go 2015-01-21 23:22:53 +0000
115+++ diskimage/core_grub.go 2015-03-18 03:33:51 +0000
116@@ -247,6 +247,19 @@
117 return filepath.Join(img.baseMount, string(writableDir))
118 }
119
120+// Boot returns the system-boot path
121+func (img CoreGrubImage) Boot() string {
122+ if img.parts == nil {
123+ panic("img is not setup with partitions")
124+ }
125+
126+ if img.baseMount == "" {
127+ panic("img not mounted")
128+ }
129+
130+ return filepath.Join(img.baseMount, string(bootDir))
131+}
132+
133 //System returns the system path
134 func (img CoreGrubImage) System() string {
135 if img.parts == nil {
136@@ -268,7 +281,7 @@
137 return img.baseMount
138 }
139
140-func (img *CoreGrubImage) SetupBoot() error {
141+func (img *CoreGrubImage) SetupBoot(oem OemDescription) error {
142 for _, dev := range []string{"dev", "proc", "sys"} {
143 src := filepath.Join("/", dev)
144 dst := filepath.Join(img.System(), dev)
145@@ -303,6 +316,30 @@
146 }
147 defer unmount(rootDevPath)
148
149+ efiDir := filepath.Join(img.System(), "boot", "efi")
150+ if err := os.MkdirAll(efiDir, 0755); err != nil {
151+ return fmt.Errorf("unable to create %s dir: %s", efiDir, err)
152+ }
153+
154+ if err := bindMount(img.Boot(), efiDir); err != nil {
155+ return err
156+ }
157+ defer unmount(efiDir)
158+
159+ // create efi layout
160+ efiGrubDir := filepath.Join(img.System(), "boot", "efi", "EFI", "ubuntu", "grub")
161+ if err := os.MkdirAll(efiGrubDir, 0755); err != nil {
162+ return fmt.Errorf("unable to create %s dir: %s", efiGrubDir, err)
163+ }
164+
165+ bootGrubDir := filepath.Join(img.System(), "boot", "grub")
166+
167+ if err := bindMount(efiGrubDir, bootGrubDir); err != nil {
168+ return err
169+ }
170+ defer unmount(bootGrubDir)
171+
172+ // install grub
173 if out, err := exec.Command("chroot", img.System(), "grub-install", "/root_dev").CombinedOutput(); err != nil {
174 return fmt.Errorf("unable to install grub: %s", out)
175 }
176
177=== modified file 'diskimage/core_uboot.go'
178--- diskimage/core_uboot.go 2015-01-28 13:04:27 +0000
179+++ diskimage/core_uboot.go 2015-03-18 03:33:51 +0000
180@@ -72,7 +72,7 @@
181 snappy_mode=regular
182 # if we're trying a new version, check if stamp file is already there to revert
183 # to other version
184-snappy_boot=if test "${snappy_mode}" = "try"; then if load mmc ${bootpart} ${loadaddr} ${snappy_stamp} 0; then if test "${snappy_ab}" = "a"; then setenv snappy_ab "b"; else setenv snappy_ab "a"; fi; else fatwrite mmc ${mmcdev}:${mmcpart} 0x0 ${snappy_stamp} 0; fi; fi; run loadfiles; setenv mmcroot /dev/disk/by-label/system-${snappy_ab} ${snappy_cmdline}; run mmcargs; bootz ${loadaddr} ${initrd_addr}:${initrd_size} ${fdtaddr}
185+snappy_boot=if test "${snappy_mode}" = "try"; then if test -e mmc ${bootpart} ${snappy_stamp}; then if test "${snappy_ab}" = "a"; then setenv snappy_ab "b"; else setenv snappy_ab "a"; fi; else fatwrite mmc ${mmcdev}:${mmcpart} 0x0 ${snappy_stamp} 0; fi; fi; run loadfiles; setenv mmcroot /dev/disk/by-label/system-${snappy_ab} ${snappy_cmdline}; run mmcargs; bootz ${loadaddr} ${initrd_addr}:${initrd_size} ${fdtaddr}
186 `
187
188 type FlashInstructions struct {
189@@ -290,12 +290,11 @@
190 return img.baseMount
191 }
192
193-func (img CoreUBootImage) SetupBoot() error {
194+func (img CoreUBootImage) SetupBoot(oem OemDescription) error {
195 // destinations
196 bootPath := filepath.Join(img.baseMount, string(bootDir))
197 bootAPath := filepath.Join(bootPath, "a")
198 bootBPath := filepath.Join(bootPath, "b")
199- bootDtbPath := filepath.Join(bootAPath, "dtbs")
200 bootuEnvPath := filepath.Join(bootPath, "uEnv.txt")
201 bootSnappySystemPath := filepath.Join(bootPath, "snappy-system.txt")
202
203@@ -304,29 +303,37 @@
204 kernelPath := filepath.Join(img.baseMount, img.hardware.Kernel)
205 initrdPath := filepath.Join(img.baseMount, img.hardware.Initrd)
206
207- // create layout
208- if err := os.MkdirAll(bootDtbPath, 0755); err != nil {
209- return err
210- }
211-
212 if err := os.MkdirAll(bootBPath, 0755); err != nil {
213 return err
214 }
215
216- if err := move(hardwareYamlPath, filepath.Join(bootAPath, "hardware.yaml")); err != nil {
217- return err
218- }
219-
220- if err := move(kernelPath, filepath.Join(bootAPath, filepath.Base(kernelPath))); err != nil {
221- return err
222- }
223-
224- if err := move(initrdPath, filepath.Join(bootAPath, filepath.Base(initrdPath))); err != nil {
225- return err
226- }
227-
228- if err := img.provisionDtbs(bootDtbPath); err != nil {
229- return err
230+ // populate both A/B
231+ for _, path := range []string{bootAPath, bootBPath} {
232+ if err := os.MkdirAll(path, 0755); err != nil {
233+ return err
234+ }
235+
236+ if err := copyFile(hardwareYamlPath, filepath.Join(path, "hardware.yaml")); err != nil {
237+ return err
238+ }
239+
240+ if err := copyFile(kernelPath, filepath.Join(path, filepath.Base(kernelPath))); err != nil {
241+ return err
242+ }
243+
244+ if err := copyFile(initrdPath, filepath.Join(path, filepath.Base(initrdPath))); err != nil {
245+ return err
246+ }
247+
248+ // create layout
249+ bootDtbPath := filepath.Join(path, "dtbs")
250+ if err := os.MkdirAll(bootDtbPath, 0755); err != nil {
251+ return err
252+ }
253+
254+ if err := img.provisionDtbs(oem, bootDtbPath); err != nil {
255+ return err
256+ }
257 }
258
259 if err := img.provisionUenv(bootuEnvPath); err != nil {
260@@ -374,7 +381,7 @@
261 // if a uEnv.txt is provided in the flashtool-assets, use it
262 if _, err := os.Stat(uEnvPath); err == nil {
263 printOut("Adding uEnv.txt to", bootuEnvPath)
264- if err := move(uEnvPath, bootuEnvPath); err != nil {
265+ if err := copyFile(uEnvPath, bootuEnvPath); err != nil {
266 return err
267 }
268 } else {
269@@ -384,7 +391,7 @@
270 return nil
271 }
272
273-func (img CoreUBootImage) provisionDtbs(bootDtbPath string) error {
274+func (img CoreUBootImage) provisionDtbs(oem OemDescription, bootDtbPath string) error {
275 dtbsPath := filepath.Join(img.baseMount, img.hardware.Dtbs)
276
277 if _, err := os.Stat(dtbsPath); os.IsNotExist(err) {
278@@ -401,16 +408,23 @@
279 dtb := filepath.Join(dtbsPath, fmt.Sprintf("%s.dtb", img.platform))
280
281 // if there is a specific dtb for the platform, copy it.
282- if _, err := os.Stat(dtb); err == nil {
283- dst := filepath.Join(bootDtbPath, filepath.Base(dtb))
284- if err := move(dtb, dst); err != nil {
285+ // First look in oem and then in device.
286+ if oem.Hardware.Dtb != "" && img.platform != "" {
287+ oemDtb := filepath.Join(img.System(), oem.InstallPath(), oem.Hardware.Dtb)
288+ dst := filepath.Join(bootDtbPath, filepath.Base(dtb))
289+ if err := copyFile(oemDtb, dst); err != nil {
290+ return err
291+ }
292+ } else if _, err := os.Stat(dtb); err == nil {
293+ dst := filepath.Join(bootDtbPath, filepath.Base(dtb))
294+ if err := copyFile(dtb, dst); err != nil {
295 return err
296 }
297 } else {
298 for _, dtbFi := range dtbFis {
299 src := filepath.Join(dtbsPath, dtbFi.Name())
300 dst := filepath.Join(bootDtbPath, dtbFi.Name())
301- if err := move(src, dst); err != nil {
302+ if err := copyFile(src, dst); err != nil {
303 return err
304 }
305 }
306@@ -475,7 +489,7 @@
307 return nil
308 }
309
310-func move(src, dst string) error {
311+func copyFile(src, dst string) error {
312 dstFile, err := os.Create(dst)
313 if err != nil {
314 return err
315@@ -486,7 +500,6 @@
316 if err != nil {
317 return err
318 }
319- defer os.Remove(src)
320 defer srcFile.Close()
321
322 reader := bufio.NewReader(srcFile)
323
324=== modified file 'sysutils/utils.go'
325--- sysutils/utils.go 2015-01-21 23:22:53 +0000
326+++ sysutils/utils.go 2015-03-18 03:33:51 +0000
327@@ -50,7 +50,9 @@
328 case GiB:
329 size = size * 1024 * 1024 * 1024
330 case GB:
331- size = size * 1000 * 1000 * 1000
332+ // The image size will be reduced to fit commercial drives that are
333+ // smaller than what they claim, 975 comes from 97.5% of the total size
334+ size = size * 1000 * 1000 * 975
335 default:
336 panic("improper sizing unit used")
337 }
338
339=== added file 'sysutils/utils_test.go'
340--- sysutils/utils_test.go 1970-01-01 00:00:00 +0000
341+++ sysutils/utils_test.go 2015-03-18 03:33:51 +0000
342@@ -0,0 +1,50 @@
343+package sysutils
344+
345+import (
346+ "os"
347+ "path/filepath"
348+ "testing"
349+
350+ . "launchpad.net/gocheck"
351+)
352+
353+// Hook up gocheck into the "go test" runner.
354+func Test(t *testing.T) { TestingT(t) }
355+
356+type UtilsTestSuite struct {
357+ tmpdir string
358+}
359+
360+var _ = Suite(&UtilsTestSuite{})
361+
362+func (s *UtilsTestSuite) SetUpTest(c *C) {
363+ s.tmpdir = c.MkDir()
364+}
365+
366+func (s *UtilsTestSuite) TestCreateEmptyFileGiB(c *C) {
367+ f := filepath.Join(s.tmpdir, "gib")
368+ c.Assert(CreateEmptyFile(f, 1, GiB), IsNil)
369+
370+ fStat, err := os.Stat(f)
371+ c.Assert(err, IsNil)
372+
373+ c.Assert(fStat.Size(), Equals, int64(1024*1024*1024))
374+}
375+
376+func (s *UtilsTestSuite) TestCreateEmptyFileGB(c *C) {
377+ f1 := filepath.Join(s.tmpdir, "gb")
378+ c.Assert(CreateEmptyFile(f1, 1, GB), IsNil)
379+
380+ fStat1, err := os.Stat(f1)
381+ c.Assert(err, IsNil)
382+
383+ c.Assert(fStat1.Size(), Equals, int64(1000*1000*975))
384+
385+ f2 := filepath.Join(s.tmpdir, "gb")
386+ c.Assert(CreateEmptyFile(f2, 2, GB), IsNil)
387+
388+ fStat2, err := os.Stat(f2)
389+ c.Assert(err, IsNil)
390+
391+ c.Assert(fStat2.Size(), Equals, int64(2*1000*1000*975))
392+}
393
394=== modified file 'ubuntu-device-flash/core.go'
395--- ubuntu-device-flash/core.go 2015-01-19 21:38:25 +0000
396+++ ubuntu-device-flash/core.go 2015-03-18 03:33:51 +0000
397@@ -319,7 +319,17 @@
398
399 systemPath := img.System()
400
401- if err := img.SetupBoot(); err != nil {
402+ if err := coreCmd.install(systemPath); err != nil {
403+ return err
404+ }
405+
406+ // check if we installed an oem snap
407+ oem, err := loadOem(systemPath)
408+ if err != nil {
409+ return err
410+ }
411+
412+ if err := img.SetupBoot(oem); err != nil {
413 return err
414 }
415
416@@ -327,10 +337,6 @@
417 return err
418 }
419
420- if err := coreCmd.install(systemPath); err != nil {
421- return err
422- }
423-
424 if !coreCmd.Cloud {
425 cloudBaseDir := filepath.Join("var", "lib", "cloud")
426
427@@ -494,6 +500,31 @@
428 return string(pubKey), err
429 }
430
431+func loadOem(systemPath string) (oem diskimage.OemDescription, err error) {
432+ pkgs, err := filepath.Glob(filepath.Join(systemPath, "/oem/*/*/meta/package.yaml"))
433+ if err != nil {
434+ return oem, err
435+ }
436+
437+ // checking for len(pkgs) > 2 due to the 'current' symlink
438+ if len(pkgs) == 0 {
439+ return oem, nil
440+ } else if len(pkgs) > 2 || err != nil {
441+ return oem, errors.New("too many oem packages installed")
442+ }
443+
444+ f, err := ioutil.ReadFile(pkgs[0])
445+ if err != nil {
446+ return oem, errors.New("failed to read oem yaml")
447+ }
448+
449+ if err := goyaml.Unmarshal([]byte(f), &oem); err != nil {
450+ return oem, errors.New("cannot decode oem yaml")
451+ }
452+
453+ return oem, nil
454+}
455+
456 func extractHWDescription(path string) (hw diskimage.HardwareDescription, err error) {
457 // hack to circumvent https://code.google.com/p/go/issues/detail?id=1435
458 if syscall.Getuid() == 0 {
459
460=== modified file 'ubuntu-device-flash/touch.go'
461--- ubuntu-device-flash/touch.go 2015-01-15 13:52:31 +0000
462+++ ubuntu-device-flash/touch.go 2015-03-18 03:33:51 +0000
463@@ -304,29 +304,17 @@
464 if _, err := adb.Shell("rm -rf /cache/recovery/*.xz /cache/recovery/*.xz.asc"); err != nil {
465 log.Fatal("Cannot cleanup /cache/recovery/ to ensure clean deployment", err)
466 }
467- freeSpace := "unknown"
468- dfCacheCmd := "df -h | grep /android/cache"
469- if free, err := adb.Shell(dfCacheCmd); err != nil {
470- log.Fatal("Unable to retrieve free space on target")
471- } else {
472- //Filesystem Size Used Avail Use% Mounted on
473- free := strings.Fields(free)
474- if len(free) > 3 {
475- freeSpace = free[3]
476- }
477- }
478- errMsg := "Cannot push %s to device: free space on /cache/recovery is %s"
479 for {
480 file := <-files
481 go func() {
482 log.Printf("Start pushing %s to device", file.FilePath)
483 err := adb.Push(file.FilePath, "/cache/recovery/")
484 if err != nil {
485- log.Fatalf(errMsg, file.SigPath, freeSpace)
486+ log.Fatal(err)
487 }
488 err = adb.Push(file.SigPath, "/cache/recovery/")
489 if err != nil {
490- log.Fatalf(errMsg, file.SigPath, freeSpace)
491+ log.Fatal(err)
492 }
493 log.Printf("Done pushing %s to device", file.FilePath)
494 done <- true

Subscribers

People subscribed via source and target branches

to all changes: