diff -Nru goget-ubuntu-touch-0.15/debian/changelog goget-ubuntu-touch-0.16/debian/changelog --- goget-ubuntu-touch-0.15/debian/changelog 2015-01-29 18:25:15.000000000 +0000 +++ goget-ubuntu-touch-0.16/debian/changelog 2015-01-29 18:25:15.000000000 +0000 @@ -1,3 +1,10 @@ +goget-ubuntu-touch (0.16-0ubuntu1) vivid; urgency=medium + + * ubuntu-device-flash: oem part to allow for dtb overrides. + * debian/control: dep on fakeroot for ubuntu-device-flash. + + -- Sergio Schvezov Thu, 29 Jan 2015 15:23:27 -0300 + goget-ubuntu-touch (0.15-0ubuntu1) vivid; urgency=medium [ Loïc Minier ] diff -Nru goget-ubuntu-touch-0.15/debian/control goget-ubuntu-touch-0.16/debian/control --- goget-ubuntu-touch-0.15/debian/control 2015-01-29 18:25:15.000000000 +0000 +++ goget-ubuntu-touch-0.16/debian/control 2015-01-29 18:25:15.000000000 +0000 @@ -19,6 +19,7 @@ Architecture: any Depends: android-tools-adb, android-tools-fastboot, + fakeroot, kpartx, qemu-user-static, ${misc:Depends}, diff -Nru goget-ubuntu-touch-0.15/diskimage/common.go goget-ubuntu-touch-0.16/diskimage/common.go --- goget-ubuntu-touch-0.15/diskimage/common.go 2015-01-28 19:52:46.000000000 +0000 +++ goget-ubuntu-touch-0.16/diskimage/common.go 2015-01-29 14:26:00.000000000 +0000 @@ -11,6 +11,7 @@ "fmt" "os" "os/exec" + "path/filepath" "strings" ) @@ -52,7 +53,7 @@ type CoreImage interface { Image SystemImage - SetupBoot() error + SetupBoot(OemDescription) error FlashExtra(string) error } @@ -64,6 +65,18 @@ Bootloader string `yaml:"bootloader"` } +type OemDescription struct { + Name string `yaml:"name"` + Version string `yaml:"version"` + Hardware struct { + Dtb string `yaml:"dtb,omitempty"` + } `yaml:"hardware,omitempty"` +} + +func (o OemDescription) InstallPath() string { + return filepath.Join("/oem", o.Name, o.Version) +} + func sectorSize(dev string) (string, error) { out, err := exec.Command("blockdev", "--getss", dev).CombinedOutput() if err != nil { diff -Nru goget-ubuntu-touch-0.15/diskimage/core_grub.go goget-ubuntu-touch-0.16/diskimage/core_grub.go --- goget-ubuntu-touch-0.15/diskimage/core_grub.go 2015-01-28 22:49:53.000000000 +0000 +++ goget-ubuntu-touch-0.16/diskimage/core_grub.go 2015-01-29 14:26:00.000000000 +0000 @@ -281,7 +281,7 @@ return img.baseMount } -func (img *CoreGrubImage) SetupBoot() error { +func (img *CoreGrubImage) SetupBoot(oem OemDescription) error { for _, dev := range []string{"dev", "proc", "sys"} { src := filepath.Join("/", dev) dst := filepath.Join(img.System(), dev) diff -Nru goget-ubuntu-touch-0.15/diskimage/core_uboot.go goget-ubuntu-touch-0.16/diskimage/core_uboot.go --- goget-ubuntu-touch-0.15/diskimage/core_uboot.go 2015-01-28 22:48:59.000000000 +0000 +++ goget-ubuntu-touch-0.16/diskimage/core_uboot.go 2015-01-29 14:26:00.000000000 +0000 @@ -290,7 +290,7 @@ return img.baseMount } -func (img CoreUBootImage) SetupBoot() error { +func (img CoreUBootImage) SetupBoot(oem OemDescription) error { // destinations bootPath := filepath.Join(img.baseMount, string(bootDir)) bootAPath := filepath.Join(bootPath, "a") @@ -313,19 +313,19 @@ return err } - if err := move(hardwareYamlPath, filepath.Join(bootAPath, "hardware.yaml")); err != nil { + if err := copyFile(hardwareYamlPath, filepath.Join(bootAPath, "hardware.yaml")); err != nil { return err } - if err := move(kernelPath, filepath.Join(bootAPath, filepath.Base(kernelPath))); err != nil { + if err := copyFile(kernelPath, filepath.Join(bootAPath, filepath.Base(kernelPath))); err != nil { return err } - if err := move(initrdPath, filepath.Join(bootAPath, filepath.Base(initrdPath))); err != nil { + if err := copyFile(initrdPath, filepath.Join(bootAPath, filepath.Base(initrdPath))); err != nil { return err } - if err := img.provisionDtbs(bootDtbPath); err != nil { + if err := img.provisionDtbs(oem, bootDtbPath); err != nil { return err } @@ -374,7 +374,7 @@ // if a uEnv.txt is provided in the flashtool-assets, use it if _, err := os.Stat(uEnvPath); err == nil { printOut("Adding uEnv.txt to", bootuEnvPath) - if err := move(uEnvPath, bootuEnvPath); err != nil { + if err := copyFile(uEnvPath, bootuEnvPath); err != nil { return err } } else { @@ -384,7 +384,7 @@ return nil } -func (img CoreUBootImage) provisionDtbs(bootDtbPath string) error { +func (img CoreUBootImage) provisionDtbs(oem OemDescription, bootDtbPath string) error { dtbsPath := filepath.Join(img.baseMount, img.hardware.Dtbs) if _, err := os.Stat(dtbsPath); os.IsNotExist(err) { @@ -401,16 +401,23 @@ dtb := filepath.Join(dtbsPath, fmt.Sprintf("%s.dtb", img.platform)) // if there is a specific dtb for the platform, copy it. - if _, err := os.Stat(dtb); err == nil { + // First look in oem and then in device. + if oem.Hardware.Dtb != "" && img.platform != "" { + oemDtb := filepath.Join(img.System(), oem.InstallPath(), oem.Hardware.Dtb) dst := filepath.Join(bootDtbPath, filepath.Base(dtb)) - if err := move(dtb, dst); err != nil { + if err := copyFile(oemDtb, dst); err != nil { + return err + } + } else if _, err := os.Stat(dtb); err == nil { + dst := filepath.Join(bootDtbPath, filepath.Base(dtb)) + if err := copyFile(dtb, dst); err != nil { return err } } else { for _, dtbFi := range dtbFis { src := filepath.Join(dtbsPath, dtbFi.Name()) dst := filepath.Join(bootDtbPath, dtbFi.Name()) - if err := move(src, dst); err != nil { + if err := copyFile(src, dst); err != nil { return err } } @@ -475,7 +482,7 @@ return nil } -func move(src, dst string) error { +func copyFile(src, dst string) error { dstFile, err := os.Create(dst) if err != nil { return err @@ -486,7 +493,6 @@ if err != nil { return err } - defer os.Remove(src) defer srcFile.Close() reader := bufio.NewReader(srcFile) diff -Nru goget-ubuntu-touch-0.15/ubuntu-device-flash/core.go goget-ubuntu-touch-0.16/ubuntu-device-flash/core.go --- goget-ubuntu-touch-0.15/ubuntu-device-flash/core.go 2015-01-28 22:44:25.000000000 +0000 +++ goget-ubuntu-touch-0.16/ubuntu-device-flash/core.go 2015-01-29 14:26:00.000000000 +0000 @@ -319,15 +319,21 @@ systemPath := img.System() - if err := img.SetupBoot(); err != nil { + if err := coreCmd.install(systemPath); err != nil { return err } - if err := coreCmd.setupKeyboardLayout(systemPath); err != nil { + // check if we installed an oem snap + oem, err := loadOem(systemPath) + if err != nil { return err } - if err := coreCmd.install(systemPath); err != nil { + if err := img.SetupBoot(oem); err != nil { + return err + } + + if err := coreCmd.setupKeyboardLayout(systemPath); err != nil { return err } @@ -494,6 +500,31 @@ return string(pubKey), err } +func loadOem(systemPath string) (oem diskimage.OemDescription, err error) { + pkgs, err := filepath.Glob(filepath.Join(systemPath, "/oem/*/*/meta/package.yaml")) + if err != nil { + return oem, err + } + + // checking for len(pkgs) > 2 due to the 'current' symlink + if len(pkgs) == 0 { + return oem, nil + } else if len(pkgs) > 2 || err != nil { + return oem, errors.New("too many oem packages installed") + } + + f, err := ioutil.ReadFile(pkgs[0]) + if err != nil { + return oem, errors.New("failed to read oem yaml") + } + + if err := goyaml.Unmarshal([]byte(f), &oem); err != nil { + return oem, errors.New("cannot decode oem yaml") + } + + return oem, nil +} + func extractHWDescription(path string) (hw diskimage.HardwareDescription, err error) { // hack to circumvent https://code.google.com/p/go/issues/detail?id=1435 if syscall.Getuid() == 0 {