github.com/david-imola/snapd@v0.0.0-20210611180407-2de8ddeece6d/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/osutil"
    28  	"github.com/snapcore/snapd/snap"
    29  )
    30  
    31  type androidboot struct {
    32  	rootdir string
    33  }
    34  
    35  // newAndroidboot creates a new Androidboot bootloader object
    36  func newAndroidBoot(rootdir string, _ *Options) Bootloader {
    37  	a := &androidboot{rootdir: rootdir}
    38  	return a
    39  }
    40  
    41  func (a *androidboot) Name() string {
    42  	return "androidboot"
    43  }
    44  
    45  func (a *androidboot) dir() string {
    46  	if a.rootdir == "" {
    47  		panic("internal error: unset rootdir")
    48  	}
    49  	return filepath.Join(a.rootdir, "/boot/androidboot")
    50  }
    51  
    52  func (a *androidboot) InstallBootConfig(gadgetDir string, opts *Options) error {
    53  	gadgetFile := filepath.Join(gadgetDir, a.Name()+".conf")
    54  	systemFile := a.configFile()
    55  	return genericInstallBootConfig(gadgetFile, systemFile)
    56  }
    57  
    58  func (a *androidboot) Present() (bool, error) {
    59  	return osutil.FileExists(a.configFile()), nil
    60  }
    61  
    62  func (a *androidboot) configFile() string {
    63  	return filepath.Join(a.dir(), "androidboot.env")
    64  }
    65  
    66  func (a *androidboot) GetBootVars(names ...string) (map[string]string, error) {
    67  	env := androidbootenv.NewEnv(a.configFile())
    68  	if err := env.Load(); err != nil {
    69  		return nil, err
    70  	}
    71  
    72  	out := make(map[string]string, len(names))
    73  	for _, name := range names {
    74  		out[name] = env.Get(name)
    75  	}
    76  
    77  	return out, nil
    78  }
    79  
    80  func (a *androidboot) SetBootVars(values map[string]string) error {
    81  	env := androidbootenv.NewEnv(a.configFile())
    82  	if err := env.Load(); err != nil && !os.IsNotExist(err) {
    83  		return err
    84  	}
    85  	for k, v := range values {
    86  		env.Set(k, v)
    87  	}
    88  	return env.Save()
    89  }
    90  
    91  func (a *androidboot) ExtractKernelAssets(s snap.PlaceInfo, snapf snap.Container) error {
    92  	return nil
    93  
    94  }
    95  
    96  func (a *androidboot) RemoveKernelAssets(s snap.PlaceInfo) error {
    97  	return nil
    98  }