kernel

package
v0.0.0-...-c5fa83f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 22, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AppliedPatchesFile = "cos-kernel-applied-patches.txt"
	PatchBaseFile      = "cos-kernel-patch-base.txt"
)

Variables

View Source
var GcloudExecutable = "gcloud"

GcloudExecutable is the path to the gcloud binary used for commands.

Functions

func ApplyPatch

func ApplyPatch(path string, writer io.Writer) error

ApplyPatch applies a patch in the current directory.

This returns an error if the patch can't be read or does not apply cleanly. Logs the output of the patch command to the provided writer.

func ApplyPatches

func ApplyPatches(paths []string, writer io.Writer) ([]string, []string, error)

ApplyPatches applies a list of patches in the current directory.

For each patch, this first checks if the patch would apply cleanly. If not, then the patch is not applied, and the function exits.

The first return value is the list of patches which applied cleanly, and the second return value is the full list of paths modified by the applied patches. Both of these values are populated correctly even if this function returns an error. This is so that callers can commit or roll back changes to the affected files.

Returns an error immediately if any patch cannot be applied.

func BuildKernelTarball

func BuildKernelTarball(conf KernelVariantConfig, extraMakeArgs []string) (string, error)

BuildKernelTarball compiles the kernel and modules in the current directory and packages them into a tarball suitable for use with cos-kernel-deploy.

This will also strip debug symbols from the modules.

func CompilerToolchainInstalled

func CompilerToolchainInstalled(toolchainDir string) bool

CompilerToolchainInstalled returns whether or not the toolchain has been installed in the target directory.

func CopyFileToGcpInstance

func CopyFileToGcpInstance(ctx context.Context, localPath string, remotePath string, gcloudArgs []string) error

CopyFileToGcpInstance copies a file from a local path to a remote path on a GCP instance.

The copy is done via `gcloud compute ssh`.

The gcloudArgs args are passed directly to `gcloud compute ssh` in order to specify the instance the file should be copied to.

func DeployKernelToGcpInstance

func DeployKernelToGcpInstance(ctx context.Context, path string, gcloudArgs []string) error

DeployKernelToGcpInstance replaces the kernel on a GCP instance with a kernel from a remote path on that instance.

The gcloudArgs args are passed directly to `gcloud compute ssh` in order to specify the instance where the kernel will be deployed.

func DeployKernelToLocalInstance

func DeployKernelToLocalInstance(path string) error

DeployKernelToLocalInstance replaces the kernel on a local instance with the kernel at the provided path.

func FilesModifiedByPatch

func FilesModifiedByPatch(path string) ([]string, error)

FilesModifiedByPatch returns the list of files that a patch would modify.

This returns an error if the patch can't be read or does not apply cleanly.

func FindPatchBaseCommit

func FindPatchBaseCommit(branch string) (string, error)

FindPatchBaseCommit finds the hash of the base commit for a branch created by PrepareBranch(..., branch).

func InstallCompilerToolchain

func InstallCompilerToolchain(ctx context.Context, downloader cos.ArtifactsDownloader, dstDir string) error

InstallCompilerToolchain installs the COS compiler toolchain in a target directory.

Once the toolchain has been installed, the toolchain tarball is removed to save space, and a toolchain-installed.txt file is created. If the installation fails for any reason, toolchain-installed.txt file will not be written, so it can be used as a reliable indicator that the installation succeeded.

func InstallCompilerToolchainAtomic

func InstallCompilerToolchainAtomic(ctx context.Context, downloader cos.ArtifactsDownloader, dstDir string) error

Installs the compiler toolchain atomically if it is not already installed. This function checks for a file which is only installed after an installation succeeds, meaning it will retry any partial installations.

func InstallKernelHeaders

func InstallKernelHeaders(ctx context.Context, downloader cos.ArtifactsDownloader, dstDir string) error

InstallKernelHeaders installs the COS kernel headers in a target directory.

Once the headers have been installed, the header tarball is removed to save space, and a kernel-headers-installed.txt file is created. If the installation fails for any reason, the kernel-headers-installed.txt file will not be written, so it can be used as a reliable indicator that the installation succeeded.

func InstallKernelHeadersAtomic

func InstallKernelHeadersAtomic(ctx context.Context, downloader cos.ArtifactsDownloader, dstDir string) error

Installs the kernel headers atomically if they are not already installed. This function checks for a file which is only installed after an installation succeeds, meaning it will retry any partial installations.

func KernelHeadersInstalled

func KernelHeadersInstalled(buildDir string) bool

KernelHeadersInstalled returns whether or not the kernel headers have been installed in the target directory.

func Kmake

func Kmake(conf KernelVariantConfig, makeArgs []string) error

Kmake will run the make command from the provided makeArgs using the default make arguments corresponding to the provided kernel variant config.

If an argument is passed in makeArgs, it will take precedence over the corresponding default arg.

func Menuconfig(conf KernelVariantConfig, makeArgs []string) error

func PatchAppliesCleanly

func PatchAppliesCleanly(path string, writer io.Writer) (bool, error)

PatchAppliesCleanly checks whether or not a patch applies cleanly to the current directory.

This returns an error if the patch file can't be read. Any nonzero exit code of the patch command is interpreted as the patch not applying cleanly, but is not considered an error. Logs the output of the patch command to the provided writer.

func Prepare

func Prepare(ctx context.Context, downloader cos.ArtifactsDownloader, cleanFailedPatches bool, conf KernelVariantConfig) error

Prepare sets up the local kernel directory for compilation.

This will first download the compiler toolchain corresponding to the provided kernel variant config, apply any patches from the variant config which are not yet applied, and prepare the .config file using the base kernel config and fragments from the variant config.

func PrepareBranch

func PrepareBranch(ctx context.Context, downloader cos.ArtifactsDownloader, cleanFailedPatches bool, conf KernelVariantConfig, branch string) error

PrepareBranch switches to a new branch and sets up the local kernel directory for compilation.

See `Prepare` for details on how the branch will be prepared.

The new branch will be marked with a `cos-kernel-branch-start.txt` file, which contains the name of the branch. This can be used as a reference when creating patches from the new branch.

func ReadPatchBase

func ReadPatchBase() (string, error)

ReadPatchBase reads the patch base file created by PrepareBranch.

func UnapplyPatch

func UnapplyPatch(path string, writer io.Writer) error

UnapplyPatch unapplies a patch in the current directory by applying it in reverse.

This returns an error if the patch can't be read or does not unapply cleanly. Logs the output of the patch command to the provided writer.

func UnapplyPatches

func UnapplyPatches(paths []string, writer io.Writer) error

UnapplyPatches unapplies a list of patches in the current directory.

Returns an error immediately if any patch fails to be unapplied.

func UnlockGCPInstance

func UnlockGCPInstance(ctx context.Context, gcloudArgs []string) error

UnlockGCPInstance unlocks a GCP COS instance by running the cos-set-dev-mode script on it and rebooting.

The gcloudArgs args are passed directly to `gcloud compute ssh` in order to specify the instance that should be unlocked.

func UnlockLocalInstance

func UnlockLocalInstance() error

UnlockGCPInstance unlocks the local COS instance by running the cos-set-dev-mode script on it and rebooting.

func UnpackCompilerToolchain

func UnpackCompilerToolchain(toolchainPath, dstDir string) error

UnpackCompilerToolchain unpacks a compiler toolchain to a target directory. This omits the rust toolchain components since they are unused by COS and use a significant amount of space.

func UnpackKernelHeaders

func UnpackKernelHeaders(headersPath, dstDir string) error

UnpackKernelHeaders unpacks kernel headers to a target directory.

Types

type FakeDownloader

type FakeDownloader struct {
}

func (*FakeDownloader) ArtifactExists

func (*FakeDownloader) ArtifactExists(context.Context, string) (bool, error)

func (*FakeDownloader) DownloadArtifact

func (*FakeDownloader) DownloadArtifact(context.Context, string, string) error

func (*FakeDownloader) DownloadGenericNvidiaDriver

func (*FakeDownloader) DownloadGenericNvidiaDriver(context.Context, string, string) (string, error)

func (*FakeDownloader) DownloadKernelHeaders

func (*FakeDownloader) DownloadKernelHeaders(ctx context.Context, destDir string) error

func (*FakeDownloader) DownloadKernelSrc

func (*FakeDownloader) DownloadKernelSrc(ctx context.Context, destDir string) error

func (*FakeDownloader) DownloadToolchain

func (*FakeDownloader) DownloadToolchain(ctx context.Context, destDir string) error

func (*FakeDownloader) DownloadToolchainEnv

func (*FakeDownloader) DownloadToolchainEnv(ctx context.Context, destDir string) error

func (*FakeDownloader) GetArtifact

func (*FakeDownloader) GetArtifact(context.Context, string) ([]byte, error)

func (*FakeDownloader) ListArtifacts

func (*FakeDownloader) ListArtifacts(ctx context.Context, prefix string) ([]string, error)

type KernelVariantConfig

type KernelVariantConfig struct {
	Build         string
	Board         string
	Arch          string
	Toolchain     string
	ToolchainArch string
	Configs       []string
	Patches       []string
}

A KernelVariantConfig is a configuration representing a COS kernel variant.

The Build must be given as a build number, e.g., 19804.0.0. If unspecified, the ToolchainArch is the same as the Arch.

func ReadConfig

func ReadConfig(path string) (KernelVariantConfig, error)

ReadConfig reads a KernelVariantConfig from a .json file.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL