Skip to content

jdreaver/kernel-dev

Repository files navigation

Kernel Dev Tools

This is a repo I use to support my own Linux kernel development. I put scripts/tools here instead of inside the actual kernel tree. It is expected that this repo will live on my machine, and any kernel trees will live under this directory, but won't be committed to this repo.

Usage

Here is a typical workflow with bells and whistles:

  1. (Optional) Update the kernel source tree or get a new one

    $ cd linux && git pull upstream master
    # or
    $ ./scripts/fetch-kernel-tarball.sh 5.18.6
  2. Configure the kernel, using a QEMU configuration with ./qemu/minimal-qemu-kernel-config.sh linux

  3. Create a QEMU image using ./qemu/create-qemu-image.sh <debian|nixos>

  4. Compile the kernel with cd linux/ && make -j32

  5. Run the kernel with QEMU image using something like:

    $ ./qemu/run-qemu-kernel.sh linux nixos.img /path/to/shared-files

    /path/to/shared-files here is a directory that will be packaged up into the QEMU .img file and mounted at /shared in the VM. This arg is optional, but it is useful for e.g. adding compiled, out-of-tree kernel modules.

Linux Kernel Language Server Protocol (LSP) Configuration

The kernel has a script to generate a compile-commands.json usable with LSP:

$ cd linux/
# Make a config and build the kernel
$ make mrproper
$ make defconfig
# Build just for good measure
$ make -j14
# Generate compile-commands.json
$ ./scripts/clang-tools/gen_compile_commands.py

Linux Kernel Rust

$ make mrproper
$ make CC=clang allnoconfig defconfig rust.config
$ make CC=clang -j14

Note: when I use LLVM=1 instead of CC=clang, I get this error when linking, even when I don't enable Rust:

  LD      arch/x86/boot/setup.elf
ld.lld: error: section .bsdata file range overlaps with .header
>>> .bsdata range is [0x1092, 0x122B]
>>> .header range is [0x11EF, 0x126B]

Maybe the problem is my LLVM env for nix in general? NixOS/nixpkgs#217724

Rust resources

Buildroot

Raspberry Pi using external directory

  1. Set up some stupid symlinks that buildroot expects (well, really the problem is libtool and autotools I think. buildroot can't use host libraries and pretty much compiles everything from scratch).

    $ sudo ln -s /run/current-system/sw/bin/file /usr/bin/file
    $ sudo ln -s /run/current-system/sw/bin/true /bin/true
    $ sudo ln -s /run/current-system/sw/bin/awk /usr/bin/awk
    $ sudo ln -s /run/current-system/sw/bin/bash /bin/bash
    $ sudo ln -s /run/current-system/sw/bin/install /usr/bin/install
    $ sudo ln -s /run/current-system/sw/bin/openssl /usr/bin/openssl
  2. Use the external config

    $ cd buildroot
    $ make BR2_EXTERNAL=../buildroot-rpi reaver_rpi_defconfig menuconfig
  3. Build $ make (no need for -j since buildroot uses parallelism internally, not for top level targets)

  4. Copy image to SD card (see below for generic instructions)

Raspberry Pi Generic

(These were the instructions I used before I set up the buildroot-rpi external infra)

Getting buildroot working is not too onerous, at least since I figured out some nix quirks. Here is a general procedure:

  1. Set up some stupid symlinks that buildroot expects (well, really the problem is libtool and autotools I think. buildroot can't use host libraries and pretty much compiles everything from scratch).

    $ sudo ln -s (which file) /usr/bin/file
    $ sudo ln -s (which true) /bin/true
    $ sudo ln -s (which awk) /usr/bin/awk
    $ sudo ln -s (which bash) /bin/bash
  2. git clone git://git.buildroot.net/buildroot

  3. cd buildroot

  4. make raspberrypi4_64_defconfig

  5. make -j32

  6. Copy output/images/sdcard.img to an SD card (MAKE SURE TO VERIFY DEVICE NAME, REPLACE sdz)

    $ sudo dd if=output/images/sdcard.img of=/dev/sdz status=progress
  7. Connect Pi serial port to USB serial port connector, use dmesg to find tty device name

    dmesg | grep 'cp210x converter now attached'
    [48407.800462] usb 1-4: cp210x converter now attached to ttyUSB0
    
  8. Connect with GNU screen

    $ sudo screen /dev/ttyUSB0 115200
  9. Boot the Pi! Log in with root and no password.

Cool links:

Misc resources

TODO Check out this repo for kernel dev with nix https://github.com/jordanisaacs/kernel-module-flake

QEMU dev env:

Email:

First time contributions:

Getting started, things to do

TODO

Embedded:

  • Dev setup
    • Get booting with NFS or TFTP
      • See the bootlin labs or the Mastering Embedded Linux Book
      • NFS mounting seems to work with # mount -v -t nfs 10.42.0.1:/nfs-export /nfs-mnt -o nolock,vers=3
    • Consider using buildroot or nix for just a barebones setup to bootstrap NFS and/or SSH, and thereafter just syncing to board
  • Buildroot

About

Scripts/tools for developing the Linux kernel

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published