[Merge] lp:~sergiusens/goget-ubuntu-touch/bootassets into lp:goget-ubuntu-touch

Sergio Schvezov sergio.schvezov at canonical.com
Mon Mar 30 10:25:12 UTC 2015


I replied to comments inline, testing code is on it's way too.

Diff comments:

> === added file 'diskimage/bootloader.go'
> --- diskimage/bootloader.go	1970-01-01 00:00:00 +0000
> +++ diskimage/bootloader.go	2015-03-30 04:09:09 +0000
> @@ -0,0 +1,88 @@
> +//
> +// diskimage - handles ubuntu disk images
> +//
> +// Copyright (c) 2015 Canonical Ltd.
> +//
> +// Written by Sergio Schvezov <sergio.schvezov at canonical.com>
> +//
> +package diskimage
> +
> +// This program is free software: you can redistribute it and/or modify it
> +// under the terms of the GNU General Public License version 3, as published
> +// by the Free Software Foundation.
> +//
> +// This program is distributed in the hope that it will be useful, but
> +// WITHOUT ANY WARRANTY; without even the implied warranties of
> +// MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
> +// PURPOSE.  See the GNU General Public License for more details.
> +//
> +// You should have received a copy of the GNU General Public License along
> +// with this program.  If not, see <http://www.gnu.org/licenses/>.
> +
> +import (
> +	"io"
> +	"os"
> +	"path/filepath"
> +	"strconv"
> +
> +	"launchpad.net/goget-ubuntu-touch/sysutils"
> +)
> +
> +func setupBootAssetFiles(bootPath, oemRootPath string, files []BootAssetFiles) error {
> +	for _, file := range files {
> +		dst := filepath.Join(bootPath, filepath.Base(file.Path))
> +		if file.Target != "" {
> +			dst = filepath.Join(bootPath, file.Target)
> +		}
> +
> +		src := filepath.Join(oemRootPath, file.Path)
> +		if err := sysutils.CopyFile(src, dst); err != nil {
> +			return err
> +		}
> +	}
> +
> +	return nil
> +}
> +
> +func setupBootAssetRawFiles(imagePath, oemRootPath string, rawFiles []BootAssetRawFiles) error {
> +	img, err := os.OpenFile(imagePath, os.O_WRONLY, 0644)

Because os.Create truncates if it exists :-)

> +	if err != nil {
> +		return err
> +	}
> +	defer img.Close()
> +
> +	for _, asset := range rawFiles {
> +		offsetBytes, err := offsetBytes(asset.Offset)
> +		if err != nil {
> +			return err
> +		}
> +
> +		assetFile, err := os.Open(filepath.Join(oemRootPath, asset.Path))
> +		if err != nil {
> +			return err
> +		}
> +
> +		if err := rawwrite(img, assetFile, offsetBytes); err != nil {
> +			return err
> +		}
> +	}
> +
> +	return nil
> +}
> +
> +func offsetBytes(offset string) (int64, error) {
> +	// TODO add support for units
> +	return strconv.ParseInt(offset, 10, 64)
> +}
> +
> +func rawwrite(img *os.File, asset io.Reader, offset int64) error {
> +	if _, err := img.Seek(offset, 0); err != nil {
> +		return err
> +	}
> +
> +	if _, err := io.Copy(img, asset); err != nil {
> +		return err
> +	}
> +
> +	return nil
> +}
> 
> === modified file 'diskimage/common.go'
> --- diskimage/common.go	2015-03-30 04:09:09 +0000
> +++ diskimage/common.go	2015-03-30 04:09:09 +0000
> @@ -53,8 +53,8 @@
>  type CoreImage interface {
>  	Image
>  	SystemImage
> -	SetupBoot() error
> -	FlashExtra(string) error
> +	SetupBoot(oemRootPath string) error
> +	FlashExtra(oemRootPath, devicePart string) error
>  }
>  
>  type HardwareDescription struct {
> @@ -65,17 +65,33 @@
>  	Bootloader      string `yaml:"bootloader"`
>  }
>  
> +type BootAssetRawFiles struct {
> +	Path   string `yaml:"path"`
> +	Offset string `yaml:"offset"`
> +}
> +
> +type BootAssetFiles struct {
> +	Path   string `yaml:"path"`
> +	Target string `yaml:"target,omitempty"`
> +}
> +
> +type BootAssets struct {
> +	Files    []BootAssetFiles    `yaml:"files,omitempty"`
> +	RawFiles []BootAssetRawFiles `yaml:"raw-files,omitempty"`
> +}
> +
>  type OemDescription struct {
>  	Name    string `yaml:"name"`
>  	Version string `yaml:"version"`
>  
>  	OEM *struct {
>  		Hardware *struct {
> -			Bootloader      string `yaml:"bootloader"`
> -			PartitionLayout string `yaml:"partition-layout"`
> -			Dtb             string `yaml:"dtb,omitempty"`
> -			Platform        string `yaml:"platform"`
> -			Architecture    string `yaml:"architecture"`
> +			Bootloader      string      `yaml:"bootloader"`
> +			PartitionLayout string      `yaml:"partition-layout"`
> +			Dtb             string      `yaml:"dtb,omitempty"`
> +			Platform        string      `yaml:"platform"`
> +			Architecture    string      `yaml:"architecture"`
> +			BootAssets      *BootAssets `yaml:"boot-assets,omitempty"`
>  		} `yaml:"hardware,omitempty"`
>  
>  		Store *struct {
> 
> === modified file 'diskimage/core_grub.go'
> --- diskimage/core_grub.go	2015-03-30 04:09:09 +0000
> +++ diskimage/core_grub.go	2015-03-30 04:09:09 +0000
> @@ -281,7 +281,7 @@
>  	return img.baseMount
>  }
>  
> -func (img *CoreGrubImage) SetupBoot() error {
> +func (img *CoreGrubImage) SetupBoot(oemRootPath string) error {
>  	for _, dev := range []string{"dev", "proc", "sys"} {
>  		src := filepath.Join("/", dev)
>  		dst := filepath.Join(img.System(), dev)
> @@ -368,7 +368,7 @@
>  	return nil
>  }
>  
> -func (img *CoreGrubImage) FlashExtra(devicePart string) error {
> +func (img *CoreGrubImage) FlashExtra(oemRootPath, devicePart string) error {
>  	return nil
>  }
>  
> 
> === modified file 'diskimage/core_uboot.go'
> --- diskimage/core_uboot.go	2015-03-30 04:09:09 +0000
> +++ diskimage/core_uboot.go	2015-03-30 04:09:09 +0000
> @@ -289,7 +289,7 @@
>  	return img.baseMount
>  }
>  
> -func (img CoreUBootImage) SetupBoot() error {
> +func (img CoreUBootImage) SetupBoot(oemRootPath string) error {
>  	// destinations
>  	bootPath := filepath.Join(img.baseMount, string(bootDir))
>  	bootAPath := filepath.Join(bootPath, "a")
> @@ -335,8 +335,16 @@
>  		}
>  	}
>  
> -	if err := img.provisionUenv(bootuEnvPath); err != nil {
> -		return err
> +	// if the oem package provides BootAssets use it directly, if not
> +	// provisionUenv for backwards compatibility.
> +	if bootAssets := img.oem.OEM.Hardware.BootAssets; bootAssets != nil {
> +		if err := setupBootAssetFiles(bootPath, oemRootPath, bootAssets.Files); err != nil {
> +			return err
> +		}
> +	} else {
> +		if err := img.provisionUenv(bootuEnvPath); err != nil {
> +			return err
> +		}
>  	}
>  
>  	// create /boot/uboot
> @@ -434,7 +442,14 @@
>  	return nil
>  }
>  
> -func (img *CoreUBootImage) FlashExtra(devicePart string) error {
> +func (img *CoreUBootImage) FlashExtra(oemRootPath, devicePart string) error {
> +	// if the oem package has bootloader assets use this and skip the
> +	// deprecated device part setup
> +	if bootAssets := img.oem.OEM.Hardware.BootAssets; bootAssets != nil {
> +		return setupBootAssetRawFiles(img.location, oemRootPath, bootAssets.RawFiles)
> +	}
> +
> +	// this is for backwards compatibility
>  	if img.oem.Platform() == "" {
>  		return nil
>  	}
> 
> === modified file 'ubuntu-device-flash/core.go'
> --- ubuntu-device-flash/core.go	2015-03-30 04:09:09 +0000
> +++ ubuntu-device-flash/core.go	2015-03-30 04:09:09 +0000
> @@ -66,8 +66,9 @@
>  		Keyboard      string `long:"keyboard-layout" description:"Specify the keyboard layout" default:"us"`
>  	} `group:"Development"`
>  
> -	hardware diskimage.HardwareDescription
> -	oem      diskimage.OemDescription
> +	hardware        diskimage.HardwareDescription
> +	oem             diskimage.OemDescription
> +	stagingRootPath string
>  }
>  
>  var coreCmd CoreCmd
> @@ -98,9 +99,10 @@
>  	}
>  
>  	fmt.Println("Determining oem configuration")
> -	if err := coreCmd.extractOemDescription(coreCmd.Oem); err != nil {
> +	if err := coreCmd.extractOem(coreCmd.Oem); err != nil {
>  		return err
>  	}
> +	defer os.RemoveAll(coreCmd.stagingRootPath)
>  
>  	if !globalArgs.DownloadOnly {
>  		if syscall.Getuid() != 0 {
> @@ -275,7 +277,8 @@
>  		return err
>  	}
>  
> -	if err := img.FlashExtra(devicePart); err != nil {
> +	oemRootPath := filepath.Join(coreCmd.stagingRootPath, coreCmd.oem.InstallPath())
> +	if err := img.FlashExtra(oemRootPath, devicePart); err != nil {
>  		return err
>  	}
>  
> @@ -344,7 +347,8 @@
>  		return err
>  	}
>  
> -	if err := img.SetupBoot(); err != nil {
> +	oemRootPath := filepath.Join(coreCmd.stagingRootPath, coreCmd.oem.InstallPath())
> +	if err := img.SetupBoot(oemRootPath); err != nil {
>  		return err
>  	}
>  
> @@ -522,7 +526,7 @@
>  	return string(pubKey), err
>  }
>  
> -func (coreCmd *CoreCmd) extractOemDescription(oemPackage string) error {
> +func (coreCmd *CoreCmd) extractOem(oemPackage string) error {
>  	if oemPackage == "" {
>  		return nil
>  	}
> @@ -531,7 +535,13 @@
>  	if err != nil {
>  		return err
>  	}
> -	defer os.RemoveAll(tempDir)
> +
> +	// we need to fix the permissions for tempdir

sure thing!

> +	if err := os.Chmod(tempDir, 0755); err != nil {
> +		return err
> +	}
> +
> +	coreCmd.stagingRootPath = tempDir
>  
>  	snappy.SetRootDir(tempDir)
>  	defer snappy.SetRootDir("/")
> 


-- 
https://code.launchpad.net/~sergiusens/goget-ubuntu-touch/bootassets/+merge/254531
Your team Ubuntu Phablet Team is subscribed to branch lp:goget-ubuntu-touch.



More information about the Ubuntu-reviews mailing list