|
| 1 | +# Convenience methods for creating a Linux kernel |
| 2 | +# |
| 3 | +# Here we define helper methods for building the linux kernel and everything |
| 4 | +# around it. This means the kernel modules, any dtb's and dev targets like the |
| 5 | +# headers or an kmod-dist for building out-of-tree kernel modules. |
| 6 | +# |
| 7 | +# In its simplest form the usage looks something like the following. Note, that |
| 8 | +# the kernel is downloaded into the "linux" directory and that the |
| 9 | +# configuration files are put into the "conf" directory. Obviously you are free |
| 10 | +# to arrange this somehow differently. Of course you only need to implement the |
| 11 | +# targets required by your other recipes: |
| 12 | +# |
| 13 | +# inherit: [linux] |
| 14 | +# |
| 15 | +# ... |
| 16 | +# |
| 17 | +# metaEnvironment: |
| 18 | +# PKG_VERSION: 6.1.114 |
| 19 | +# |
| 20 | +# checkoutSCM: |
| 21 | +# - scm: url |
| 22 | +# url: ${KERNEL_MIRROR}/linux/kernel/v6.x/linux-${PKG_VERSION}.tar.xz |
| 23 | +# digestSHA1: 72f98a7aa831dba4d56b6c28b1a5333b04fbae35 |
| 24 | +# stripComponents: 1 |
| 25 | +# dir: linux |
| 26 | +# - scm: import |
| 27 | +# url: src/linux |
| 28 | +# dir: conf |
| 29 | +# |
| 30 | +# buildScript: | |
| 31 | +# linuxConfig $1/linux $1/conf/linux.config |
| 32 | +# |
| 33 | +# multiPackage: |
| 34 | +# "": |
| 35 | +# buildScript: linuxBuild |
| 36 | +# |
| 37 | +# multiPackage: |
| 38 | +# image: |
| 39 | +# inherit: [linux::image] |
| 40 | +# packageScript: linuxInstallImage $1 |
| 41 | +# |
| 42 | +# modules: |
| 43 | +# inherit: [linux::modules] |
| 44 | +# packageScript: linuxInstallModules $1 |
| 45 | +# |
| 46 | +# kmod-dist: |
| 47 | +# inherit: [linux::kmod-dist] |
| 48 | +# packageScript: linuxInstallKmodDist $1 |
| 49 | +# |
| 50 | +# dtbs: |
| 51 | +# inherit: [linux::dtbs] |
| 52 | +# buildScript: linuxBuildDtbs |
| 53 | +# packageScript: linuxInstallDtbs $1 |
| 54 | +# |
| 55 | +# headers: |
| 56 | +# inherit: [linux::headers] |
| 57 | +# buildScript: linuxBuildHeaders |
| 58 | +# packageScript: linuxInstallHeaders $1 |
| 59 | +# |
| 60 | +inherit: [cpackage, make, pkg-config] |
| 61 | + |
| 62 | +depends: |
| 63 | + - tools: |
| 64 | + target-toolchain: host-compat-toolchain |
| 65 | + depends: |
| 66 | + - libs::elfutils-libelf-dev |
| 67 | + - libs::openssl-dev |
| 68 | + - name: kernel::kmod |
| 69 | + use: [tools] |
| 70 | + |
| 71 | +privateEnvironment: |
| 72 | + LINUX_ARCH: "$(if-then-else,$(or,$(eq,${ARCH},i386),$(eq,${ARCH},x86_64)),x86,$(if-then-else,\ |
| 73 | + $(or,$(eq,${ARCH},sh),$(eq,${ARCH},sh64)),sh,$(if-then-else,$(or,$(eq,${ARCH},sparc32),\ |
| 74 | + $(eq,${ARCH},sparc64)),sparc,$ARCH)))" |
| 75 | + |
| 76 | +checkoutSCM: |
| 77 | + # Always download a script for extracting the files required to build |
| 78 | + # external kernel modules. If the kernel itself doesn't have one, we will |
| 79 | + # use this one. |
| 80 | + scm: url |
| 81 | + url: https://raw.githubusercontent.com/torvalds/linux/refs/tags/v6.11/scripts/package/install-extmod-build |
| 82 | + digestSHA1: 47eb760cf215cb3a15752186a18715fb04d9ab95 |
| 83 | + dir: kmod-script |
| 84 | + |
| 85 | +buildVars: [LINUX_ARCH, ARCH, CROSS_COMPILE, CC] |
| 86 | +buildTools: [m4, bison, flex, target-toolchain, host-toolchain] |
| 87 | +buildSetup: | |
| 88 | + # make sure we find our kmod-dist script in the package step |
| 89 | + ln -sf $1/kmod-script . |
| 90 | +
|
| 91 | + # Build the initial linux config. This will be used by all other steps. |
| 92 | + # |
| 93 | + # $1: linux kernel source directory |
| 94 | + # $2: defconfig (optional) |
| 95 | + # - if this is an actual file, use it as the config |
| 96 | + # - if this is not a file, check if a defconfig for the target arch by |
| 97 | + # that name exists and if yes, use that one |
| 98 | + linuxConfig() |
| 99 | + { |
| 100 | + DEF_CFG=${2:-$1/arch/${LINUX_ARCH}/configs/defconfig} |
| 101 | + if [[ -f "$1/arch/${LINUX_ARCH}/configs/${DEF_CFG}" ]] ; then |
| 102 | + DEF_CFG=$1/arch/${LINUX_ARCH}/configs/${DEF_CFG} |
| 103 | + fi |
| 104 | + # check if the defconfig file exists |
| 105 | + if [[ ! -f "$DEF_CFG" ]]; then |
| 106 | + >&2 echo "Don't know how to use '$DEF_CFG' as linux kernel config!" |
| 107 | + false |
| 108 | + fi |
| 109 | + # check if the source file is newer than .config |
| 110 | + if [[ -f .config && .config -nt $DEF_CFG ]]; then |
| 111 | + return 0 |
| 112 | + fi |
| 113 | + # redo the .config file |
| 114 | + cp -u "$DEF_CFG" .config |
| 115 | + makeSequential -C $1 O=$PWD \ |
| 116 | + olddefconfig |
| 117 | + } |
| 118 | +
|
| 119 | + # Build the actual target linux image and all configured modules |
| 120 | + linuxBuild() |
| 121 | + { |
| 122 | + makeParallel \ |
| 123 | + CC="$CC" \ |
| 124 | + $(basename $(make -s image_name)) modules |
| 125 | + } |
0 commit comments