github.com/kubiko/snapd@v0.0.0-20201013125620-d4f3094d9ddf/bootloader/androidboot.go (about) 1 // -*- Mode: Go; indent-tabs-mode: t -*- 2 3 /* 4 * Copyright (C) 2017 Canonical Ltd 5 * 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License version 3 as 8 * published by the Free Software Foundation. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 * 18 */ 19 20 package bootloader 21 22 import ( 23 "os" 24 "path/filepath" 25 26 "github.com/snapcore/snapd/bootloader/androidbootenv" 27 "github.com/snapcore/snapd/snap" 28 ) 29 30 type androidboot struct { 31 rootdir string 32 } 33 34 // newAndroidboot creates a new Androidboot bootloader object 35 func newAndroidBoot(rootdir string, _ *Options) Bootloader { 36 a := &androidboot{rootdir: rootdir} 37 return a 38 } 39 40 func (a *androidboot) Name() string { 41 return "androidboot" 42 } 43 44 func (a *androidboot) setRootDir(rootdir string) { 45 a.rootdir = rootdir 46 } 47 48 func (a *androidboot) dir() string { 49 if a.rootdir == "" { 50 panic("internal error: unset rootdir") 51 } 52 return filepath.Join(a.rootdir, "/boot/androidboot") 53 } 54 55 func (a *androidboot) InstallBootConfig(gadgetDir string, opts *Options) (bool, error) { 56 gadgetFile := filepath.Join(gadgetDir, a.Name()+".conf") 57 systemFile := a.ConfigFile() 58 return genericInstallBootConfig(gadgetFile, systemFile) 59 } 60 61 func (a *androidboot) ConfigFile() string { 62 return filepath.Join(a.dir(), "androidboot.env") 63 } 64 65 func (a *androidboot) GetBootVars(names ...string) (map[string]string, error) { 66 env := androidbootenv.NewEnv(a.ConfigFile()) 67 if err := env.Load(); err != nil { 68 return nil, err 69 } 70 71 out := make(map[string]string, len(names)) 72 for _, name := range names { 73 out[name] = env.Get(name) 74 } 75 76 return out, nil 77 } 78 79 func (a *androidboot) SetBootVars(values map[string]string) error { 80 env := androidbootenv.NewEnv(a.ConfigFile()) 81 if err := env.Load(); err != nil && !os.IsNotExist(err) { 82 return err 83 } 84 for k, v := range values { 85 env.Set(k, v) 86 } 87 return env.Save() 88 } 89 90 func (a *androidboot) ExtractKernelAssets(s snap.PlaceInfo, snapf snap.Container) error { 91 return nil 92 93 } 94 95 func (a *androidboot) RemoveKernelAssets(s snap.PlaceInfo) error { 96 return nil 97 }