2016-11-01 10:21:29 +01:00
|
|
|
// -*- Mode: Go; indent-tabs-mode: t -*-
|
|
|
|
|
|
|
|
|
|
/*
|
2017-05-17 14:56:55 +02:00
|
|
|
* Copyright (C) 2017 Canonical Ltd
|
2016-11-01 10:21:29 +01:00
|
|
|
*
|
|
|
|
|
* 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 warranty of
|
|
|
|
|
* MERCHANTABILITY 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/>.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2019-03-19 12:00:37 +01:00
|
|
|
package bootloader
|
2016-11-01 10:21:29 +01:00
|
|
|
|
|
|
|
|
import (
|
2017-04-27 11:08:54 +02:00
|
|
|
"os"
|
2016-11-01 10:21:29 +01:00
|
|
|
"path/filepath"
|
|
|
|
|
|
2019-03-19 12:00:37 +01:00
|
|
|
"github.com/snapcore/snapd/bootloader/androidbootenv"
|
2020-11-19 15:26:47 -06:00
|
|
|
"github.com/snapcore/snapd/osutil"
|
2019-04-01 09:56:46 +01:00
|
|
|
"github.com/snapcore/snapd/snap"
|
2016-11-01 10:21:29 +01:00
|
|
|
)
|
|
|
|
|
|
2019-09-05 19:32:04 +02:00
|
|
|
type androidboot struct {
|
|
|
|
|
rootdir string
|
|
|
|
|
}
|
2016-11-01 10:21:29 +01:00
|
|
|
|
2017-04-26 14:35:04 +02:00
|
|
|
// newAndroidboot creates a new Androidboot bootloader object
|
2020-08-12 12:52:25 +02:00
|
|
|
func newAndroidBoot(rootdir string, _ *Options) Bootloader {
|
2019-09-05 19:32:04 +02:00
|
|
|
a := &androidboot{rootdir: rootdir}
|
2017-04-26 14:35:04 +02:00
|
|
|
return a
|
2016-11-01 10:21:29 +01:00
|
|
|
}
|
|
|
|
|
|
2017-04-26 14:35:04 +02:00
|
|
|
func (a *androidboot) Name() string {
|
|
|
|
|
return "androidboot"
|
2016-11-01 10:21:29 +01:00
|
|
|
}
|
|
|
|
|
|
2019-07-18 10:16:43 +02:00
|
|
|
func (a *androidboot) dir() string {
|
2019-09-05 19:32:04 +02:00
|
|
|
if a.rootdir == "" {
|
|
|
|
|
panic("internal error: unset rootdir")
|
|
|
|
|
}
|
|
|
|
|
return filepath.Join(a.rootdir, "/boot/androidboot")
|
2016-11-01 10:21:29 +01:00
|
|
|
}
|
|
|
|
|
|
2020-11-13 14:30:38 +01:00
|
|
|
func (a *androidboot) InstallBootConfig(gadgetDir string, opts *Options) error {
|
2019-11-20 13:20:45 +01:00
|
|
|
gadgetFile := filepath.Join(gadgetDir, a.Name()+".conf")
|
2020-11-19 15:26:47 -06:00
|
|
|
systemFile := a.configFile()
|
2019-11-20 13:20:45 +01:00
|
|
|
return genericInstallBootConfig(gadgetFile, systemFile)
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-19 15:26:47 -06:00
|
|
|
func (a *androidboot) Present() (bool, error) {
|
|
|
|
|
return osutil.FileExists(a.configFile()), nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *androidboot) configFile() string {
|
2019-07-18 10:16:43 +02:00
|
|
|
return filepath.Join(a.dir(), "androidboot.env")
|
2016-11-01 10:21:29 +01:00
|
|
|
}
|
|
|
|
|
|
2017-04-26 14:35:04 +02:00
|
|
|
func (a *androidboot) GetBootVars(names ...string) (map[string]string, error) {
|
2020-11-19 15:26:47 -06:00
|
|
|
env := androidbootenv.NewEnv(a.configFile())
|
2017-04-27 11:08:54 +02:00
|
|
|
if err := env.Load(); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-17 14:56:55 +02:00
|
|
|
out := make(map[string]string, len(names))
|
2017-04-27 11:08:54 +02:00
|
|
|
for _, name := range names {
|
|
|
|
|
out[name] = env.Get(name)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return out, nil
|
2016-11-01 10:21:29 +01:00
|
|
|
}
|
|
|
|
|
|
2017-04-26 14:35:04 +02:00
|
|
|
func (a *androidboot) SetBootVars(values map[string]string) error {
|
2020-11-19 15:26:47 -06:00
|
|
|
env := androidbootenv.NewEnv(a.configFile())
|
2017-04-27 11:08:54 +02:00
|
|
|
if err := env.Load(); err != nil && !os.IsNotExist(err) {
|
|
|
|
|
return err
|
2016-11-01 10:21:29 +01:00
|
|
|
}
|
2017-04-27 11:08:54 +02:00
|
|
|
for k, v := range values {
|
|
|
|
|
env.Set(k, v)
|
|
|
|
|
}
|
|
|
|
|
return env.Save()
|
2016-11-01 10:21:29 +01:00
|
|
|
}
|
2019-04-01 09:56:46 +01:00
|
|
|
|
2019-07-29 10:11:37 +01:00
|
|
|
func (a *androidboot) ExtractKernelAssets(s snap.PlaceInfo, snapf snap.Container) error {
|
2019-04-01 09:56:46 +01:00
|
|
|
return nil
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *androidboot) RemoveKernelAssets(s snap.PlaceInfo) error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|