### Setup Static State (C) Source: https://github.com/texasinstruments/ti-linux-kernel/blob/ti-linux-6.12.y/Documentation/core-api/cpu_hotplug.rst Sets up a statically allocated CPU hotplug state, defining callbacks for starting and dying phases. Returns an error code on failure. Example usage for subsystem notifications. ```c ret = cpuhp_setup_state(CPUHP_SUBSYS_STARTING, "subsys:starting", subsys_cpu_starting, subsys_cpu_dying); if (ret < 0) return ret; .... ``` -------------------------------- ### CPU Hotplug State Setup Functions Source: https://github.com/texasinstruments/ti-linux-kernel/blob/ti-linux-6.12.y/Documentation/core-api/cpu_hotplug.rst These functions are used to install CPU hotplug callbacks and manage state setup. Some variants install callbacks only, while others also invoke the startup callback for online CPUs. Error handling involves rolling back operations and freeing allocated states. ```c cpuhp_setup_state_nocalls(state, name, startup, teardown); cpuhp_setup_state_nocalls_cpuslocked(state, name, startup, teardown); cpuhp_setup_state_multi(state, name, startup, teardown); cpuhp_setup_state(state, name, startup, teardown); cpuhp_setup_state_cpuslocked(state, name, startup, teardown); ``` -------------------------------- ### Clone Linux Kernel Mainline Repository using Git Source: https://github.com/texasinstruments/ti-linux-kernel/blob/ti-linux-6.12.y/Documentation/process/submitting-patches.rst This command uses Git to clone the mainline Linux kernel source code repository. It's the starting point for obtaining the latest kernel version for development. Ensure Git is installed and configured on your system. ```bash git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git ``` -------------------------------- ### Create and Test a Simple Initramfs 'Hello World' Example Source: https://github.com/texasinstruments/ti-linux-kernel/blob/ti-linux-6.12.y/Documentation/filesystems/ramfs-rootfs-initramfs.rst This snippet demonstrates how to create a basic 'hello world' C program, compile it statically, package it into a cpio.gz archive, and then test it using QEMU with the kernel's initrd loading mechanism. It serves as a foundational step for understanding and debugging initramfs. ```c #include #include int main(int argc, char *argv[]) { printf("Hello world!\n"); sleep(999999999); } ``` ```bash gcc -static hello.c -o init echo init | cpio -o -H newc | gzip > test.cpio.gz qemu -kernel /boot/vmlinuz -initrd test.cpio.gz /dev/zero ``` -------------------------------- ### Setup and Use Multi-Instance State (C) Source: https://github.com/texasinstruments/ti-linux-kernel/blob/ti-linux-6.12.y/Documentation/core-api/cpu_hotplug.rst Demonstrates setting up a dynamic multi-instance state for online/offline notifications, adding multiple instances, and then removing them. Includes error checking for state setup and instance operations. ```c state = cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN, "subsys:online", subsys_cpu_online, subsys_cpu_offline); if (state < 0) return state; .... ret = cpuhp_state_add_instance(state, &inst1->node); if (ret) return ret; .... ret = cpuhp_state_add_instance(state, &inst2->node); if (ret) return ret; .... cpuhp_remove_instance(state, &inst1->node); .... cpuhp_remove_instance(state, &inst2->node); .... remove_multi_state(state); ``` -------------------------------- ### Install bindgen CLI Tool Source: https://github.com/texasinstruments/ti-linux-kernel/blob/ti-linux-6.12.y/Documentation/rust/quick-start.rst Installs the bindgen-cli tool, which is used to generate bindings to the C side of the kernel at build time. This command downloads and builds the tool from source. ```bash cargo install --locked bindgen-cli ``` -------------------------------- ### Mount and Configure Cpuset (Shell) Source: https://github.com/texasinstruments/ti-linux-kernel/blob/ti-linux-6.12.y/Documentation/admin-guide/cgroup-v1/cpusets.rst Demonstrates the basic steps to mount the cpuset cgroup filesystem, create a new cpuset, define its CPU and memory nodes, and attach the current shell to it. ```shell mount -t cgroup -ocpuset cpuset /sys/fs/cgroup/cpuset cd /sys/fs/cgroup/cpuset mkdir Charlie cd Charlie /bin/echo 2-3 > cpuset.cpus /bin/echo 1 > cpuset.mems /bin/echo $$ > tasks sh cat /proc/self/cpuset ``` -------------------------------- ### Install Rust Toolchain on Arch Linux Source: https://github.com/texasinstruments/ti-linux-kernel/blob/ti-linux-6.12.y/Documentation/rust/quick-start.rst Installs the necessary Rust compiler, source, and bindgen tools on Arch Linux using pacman. This is a straightforward method for users of this distribution. ```bash pacman -S rust rust-src rust-bindgen ``` -------------------------------- ### Configure Direct Conversion Pipeline with media-ctl Source: https://github.com/texasinstruments/ti-linux-kernel/blob/ti-linux-6.12.y/Documentation/admin-guide/media/imx.rst This example sets up a complex media pipeline for direct conversion, including links, pad formats, and colorspace conversions. It demonstrates a more advanced configuration for video processing. ```none # Setup links media-ctl -l "'ov5640 1-003c':0 -> 'imx6-mipi-csi2':0[1]" media-ctl -l "'imx6-mipi-csi2':1 -> 'ipu1_csi0_mux':0[1]" media-ctl -l "'ipu1_csi0_mux':2 -> 'ipu1_csi0':0[1]" media-ctl -l "'ipu1_csi0':1 -> 'ipu1_ic_prp':0[1]" media-ctl -l "'ipu1_ic_prp':1 -> 'ipu1_ic_prpenc':0[1]" media-ctl -l "'ipu1_ic_prpenc':1 -> 'ipu1_ic_prpenc capture':0[1]" # Configure pads media-ctl -V "'ov5640 1-003c':0 [fmt:UYVY2X8/640x480]" media-ctl -V "'imx6-mipi-csi2':1 [fmt:UYVY2X8/640x480]" media-ctl -V "'ipu1_csi0_mux':2 [fmt:UYVY2X8/640x480]" media-ctl -V "'ipu1_csi0':1 [fmt:AYUV32/640x480]" media-ctl -V "'ipu1_ic_prp':1 [fmt:AYUV32/640x480]" media-ctl -V "'ipu1_ic_prpenc':1 [fmt:ARGB8888_1X32/800x600]" # Set a format at the capture interface v4l2-ctl -d /dev/video1 --set-fmt-video=pixelformat=RGB3 ``` -------------------------------- ### Install Rust Toolchain on openSUSE Source: https://github.com/texasinstruments/ti-linux-kernel/blob/ti-linux-6.12.y/Documentation/rust/quick-start.rst Installs Rust, Rust standard library source, and bindgen on openSUSE Slowroll or Tumbleweed using zypper. This ensures recent Rust releases are available. ```bash zypper install rust rust1.79-src rust-bindgen clang ``` -------------------------------- ### Install Rust Toolchain on Gentoo Linux Source: https://github.com/texasinstruments/ti-linux-kernel/blob/ti-linux-6.12.y/Documentation/rust/quick-start.rst Installs Rust and bindgen on Gentoo Linux using emerge, with USE flags for rust-src, rustfmt, and clippy. LIBCLANG_PATH may need to be set. ```bash USE='rust-src rustfmt clippy' emerge dev-lang/rust dev-util/bindgen ``` -------------------------------- ### Manually Configure Bonding with iproute2 and Init Scripts Source: https://github.com/texasinstruments/ti-linux-kernel/blob/ti-linux-6.12.y/Documentation/networking/bonding.rst This example demonstrates manual bonding configuration using iproute2 and system init scripts. It involves loading the bonding module with specific options, configuring the bond interface with an IP address, and setting up slave interfaces. This method is useful for distros without specific bonding support in their network initialization scripts. ```shell modprobe bonding mode=balance-alb miimon=100 modprobe e100 ifconfig bond0 192.168.1.1 netmask 255.255.255.0 up ip link set eth0 master bond0 ip link set eth1 master bond0 ``` -------------------------------- ### Install Rust Toolchain on Fedora Linux Source: https://github.com/texasinstruments/ti-linux-kernel/blob/ti-linux-6.12.y/Documentation/rust/quick-start.rst Installs Rust compiler, source, bindgen-cli, rustfmt, and clippy on Fedora Linux using dnf. Fedora typically provides recent Rust releases. ```bash dnf install rust rust-src bindgen-cli rustfmt clippy ``` -------------------------------- ### Sample Boot Configuration Header Fields (C) Source: https://github.com/texasinstruments/ti-linux-kernel/blob/ti-linux-6.12.y/Documentation/arch/x86/boot.rst Illustrates C code for setting header fields in a sample boot configuration. It shows how to set base_ptr, setup_sects, type_of_loader, and ramdisk_image based on protocol version and initrd loading status. ```c unsigned long base_ptr; if ( setup_sects == 0 ) { setup_sects = 4; } if ( protocol >= 0x0200 ) { type_of_loader = ; if ( loading_initrd ) { ramdisk_image = ; } ``` -------------------------------- ### Install Rust Toolchain on Debian Source: https://github.com/texasinstruments/ti-linux-kernel/blob/ti-linux-6.12.y/Documentation/rust/quick-start.rst Installs Rust compiler, source, bindgen, rustfmt, and clippy on Debian Testing or Unstable using apt. Ensure you are outside of a freeze period for recent releases. ```bash apt install rustc rust-src bindgen rustfmt rust-clippy ``` -------------------------------- ### dmsetup Create Cache Device (Basic) Source: https://github.com/texasinstruments/ti-linux-kernel/blob/ti-linux-6.12.y/Documentation/admin-guide/device-mapper/cache.rst This example demonstrates the basic creation of a cache device using 'dmsetup create'. It defines a cache device named 'my_cache' with a size of 41943040 sectors, using specified metadata, SSD, and origin devices. It configures a cache block size of 512 sectors, 1 writeback, and the 'default' policy with 0 arguments. ```bash dmsetup create my_cache --table '0 41943040 cache /dev/mapper/metadata \ /dev/mapper/ssd /dev/mapper/origin 512 1 writeback default 0' ``` -------------------------------- ### dmsetup Create Cache Device (with Policy Args) Source: https://github.com/texasinstruments/ti-linux-kernel/blob/ti-linux-6.12.y/Documentation/admin-guide/device-mapper/cache.rst This example shows how to create a cache device with specific policy arguments. It configures 'my_cache' with a block size of 1024 sectors, 1 writeback, and the 'mq' policy. It also sets policy-specific arguments: 'sequential_threshold' to 1024 and 'random_threshold' to 8. ```bash dmsetup create my_cache --table '0 41943040 cache /dev/mapper/metadata \ /dev/mapper/ssd /dev/mapper/origin 1024 1 writeback \ mq 4 sequential_threshold 1024 random_threshold 8' ``` -------------------------------- ### Build Kernel with LLVM Toolchain Source: https://github.com/texasinstruments/ti-linux-kernel/blob/ti-linux-6.12.y/Documentation/rust/quick-start.rst Builds the kernel using the LLVM toolchain. This is the best-supported setup for building a kernel with Rust support. ```bash make LLVM=1 ``` -------------------------------- ### Manually Install Rust Standard Library Source Source: https://github.com/texasinstruments/ti-linux-kernel/blob/ti-linux-6.12.y/Documentation/rust/quick-start.rst Downloads and installs the Rust standard library source manually using curl and tar. This method is an alternative if rustup is not used, and requires manual updates when the Rust compiler version changes. ```bash curl -L "https://static.rust-lang.org/dist/rust-src-$(rustc --version | cut -d' ' -f2).tar.gz" | tar -xzf - -C "$(rustc --print sysroot)/lib" \ "rust-src-$(rustc --version | cut -d' ' -f2)/rust-src/lib/" \ --strip-components=3 ``` -------------------------------- ### Setting up a Cgroup named 'Charlie' (Bash) Source: https://github.com/texasinstruments/ti-linux-kernel/blob/ti-linux-6.12.y/Documentation/admin-guide/cgroup-v1/cgroups.rst This example shows the steps to create a new cgroup named 'Charlie', configure its CPU and memory node assignments, and then attach the current shell process to it. It also demonstrates how to verify the current cgroup. ```bash cd /sys/fs/cgroup/cpuset mkdir Charlie cd Charlie /bin/echo 2-3 > cpuset.cpus /bin/echo 1 > cpuset.mems /bin/echo $$ > tasks sh # The subshell 'sh' is now running in cgroup Charlie # The next line should display '/Charlie' cat /proc/self/cgroup ``` -------------------------------- ### Example Bond Configuration in Init Script Source: https://github.com/texasinstruments/ti-linux-kernel/blob/ti-linux-6.12.y/Documentation/networking/bonding.rst This example shows how to configure a bond interface (bond0) with two e100 devices (eth0, eth1) in balance-alb mode, setting MII monitoring and making it persistent across reboots by adding commands to an init script. ```bash modprobe bonding modprobe e100 echo balance-alb > /sys/class/net/bond0/bonding/mode ifconfig bond0 192.168.1.1 netmask 255.255.255.0 up echo 100 > /sys/class/net/bond0/bonding/miimon echo +eth0 > /sys/class/net/bond0/bonding/slaves echo +eth1 > /sys/class/net/bond0/bonding/slaves ``` -------------------------------- ### Example Second Bond Configuration in Init Script Source: https://github.com/texasinstruments/ti-linux-kernel/blob/ti-linux-6.12.y/Documentation/networking/bonding.rst This example demonstrates configuring a second bond interface (bond1) with two e1000 interfaces (eth2, eth3) in active-backup mode, using ARP monitoring, and adding it to the bonding masters list within an init script. ```bash modprobe e1000 echo +bond1 > /sys/class/net/bonding_masters echo active-backup > /sys/class/net/bond1/bonding/mode ifconfig bond1 192.168.2.1 netmask 255.255.255.0 up echo +192.168.2.100 /sys/class/net/bond1/bonding/arp_ip_target echo 2000 > /sys/class/net/bond1/bonding/arp_interval echo +eth2 > /sys/class/net/bond1/bonding/slaves echo +eth3 > /sys/class/net/bond1/bonding/slaves ``` -------------------------------- ### Add rustfmt Component via rustup Source: https://github.com/texasinstruments/ti-linux-kernel/blob/ti-linux-6.12.y/Documentation/rust/quick-start.rst Installs the rustfmt component manually if not already included in the default rustup profile. rustfmt is used to automatically format Rust kernel code. ```bash rustup component add rustfmt ``` -------------------------------- ### C API for Bootconfig (C) Source: https://github.com/texasinstruments/ti-linux-kernel/blob/ti-linux-6.12.y/Documentation/admin-guide/bootconfig.rst This snippet demonstrates the usage of C APIs for interacting with boot configuration data. It shows how to find a value by key, iterate through key-value pairs, and handle array values. The example uses `xbc_find_value`, `xbc_node_is_array`, and `xbc_array_for_each_value`. ```c void *vnode = NULL; xbc_find_value("key.word", &vnode); if (vnode && xbc_node_is_array(vnode)) xbc_array_for_each_value(vnode, value) { printk("%s ", value); } ``` -------------------------------- ### Add Rust Standard Library Source with rustup Source: https://github.com/texasinstruments/ti-linux-kernel/blob/ti-linux-6.12.y/Documentation/rust/quick-start.rst Installs the Rust standard library source component for the current toolchain using rustup. This component is necessary for cross-compiling the 'core' library. ```bash rustup component add rust-src ``` -------------------------------- ### Configure Multiple Bonding Instances with Different Options Source: https://github.com/texasinstruments/ti-linux-kernel/blob/ti-linux-6.12.y/Documentation/networking/bonding.rst This example shows how to load multiple instances of the bonding module with distinct configurations. Each instance is given a unique name and specific options for mode and miimon. This is a workaround for older distributions where the second bonding instance might not pick up its options correctly. ```shell alias bond0 bonding options bond0 -o bond0 mode=balance-rr miimon=100 alias bond1 bonding options bond1 -o bond1 mode=balance-alb miimon=50 ``` -------------------------------- ### Add clippy Component via rustup Source: https://github.com/texasinstruments/ti-linux-kernel/blob/ti-linux-6.12.y/Documentation/rust/quick-start.rst Installs the clippy component manually if not already included in the default rustup profile. clippy is a Rust linter that provides extra warnings for Rust code. ```bash rustup component add clippy ``` -------------------------------- ### Format and Open LUKS Device with cryptsetup Source: https://github.com/texasinstruments/ti-linux-kernel/blob/ti-linux-6.12.y/Documentation/admin-guide/device-mapper/dm-crypt.rst This script demonstrates the standard procedure for setting up disk encryption using LUKS (Linux Unified Key Setup) with the 'cryptsetup' utility. It first formats the specified device with a LUKS header and then opens the encrypted device, making it accessible. ```shell #!/bin/sh # Create a crypt device using cryptsetup and LUKS header with default cipher cryptsetup luksFormat $1 cryptsetup luksOpen $1 crypt1 ``` -------------------------------- ### Start Espeakup Daemon (Manual Install) Source: https://github.com/texasinstruments/ti-linux-kernel/blob/ti-linux-6.12.y/Documentation/admin-guide/spkguide.txt Starts the Espeakup speech synthesizer after it has been manually compiled and installed. The binary is typically located in /usr/bin and requires root privileges to run. ```bash /usr/bin/espeakup ``` -------------------------------- ### VFIO IOMMU Group and Container Setup in C Source: https://github.com/texasinstruments/ti-linux-kernel/blob/ti-linux-6.12.y/Documentation/driver-api/vfio.rst This C code example illustrates the process of setting up a VFIO container and adding an IOMMU group to it. It includes essential ioctl calls for checking API version, verifying IOMMU support, getting group status, and enabling the IOMMU. ```c #include #include #include #include #include #include #include // ... (rest of the code) /* Create a new container */ container = open("/dev/vfio/vfio", O_RDWR); if (ioctl(container, VFIO_GET_API_VERSION) != VFIO_API_VERSION) /* Unknown API version */ if (!ioctl(container, VFIO_CHECK_EXTENSION, VFIO_TYPE1_IOMMU)) /* Doesn't support the IOMMU driver we want. */ /* Open the group */ group = open("/dev/vfio/26", O_RDWR); /* Test the group is viable and available */ ioctl(group, VFIO_GROUP_GET_STATUS, &group_status); if (!(group_status.flags & VFIO_GROUP_FLAGS_VIABLE)) /* Group is not viable (ie, not all devices bound for vfio) */ /* Add the group to the container */ ioctl(group, VFIO_GROUP_SET_CONTAINER, &container); /* Enable the IOMMU model we want */ ioctl(container, VFIO_SET_IOMMU, VFIO_TYPE1_IOMMU); /* Get addition IOMMU info */ ioctl(container, VFIO_IOMMU_GET_INFO, &iommu_info); /* Allocate some space and setup a DMA mapping */ dma_map.vaddr = mmap(0, 1024 * 1024, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); dma_map.size = 1024 * 1024; dma_map.iova = 0; /* 1MB starting at 0x0 from device view */ dma_map.flags = VFIO_DMA_MAP_FLAG_READ | VFIO_DMA_MAP_FLAG_WRITE; ioctl(container, VFIO_IOMMU_MAP_DMA, &dma_map); /* Get a file descriptor for the device */ device = ioctl(group, VFIO_GROUP_GET_DEVICE_FD, "0000:06:0d.0"); /* Test and setup the device */ // ... (rest of the code) ``` -------------------------------- ### Record Trace using CoreSight Configuration with perf Source: https://github.com/texasinstruments/ti-linux-kernel/blob/ti-linux-6.12.y/Documentation/trace/coresight/coresight-config.rst Provides examples of using the 'perf record' command to capture traces with specific CoreSight configurations like 'autofdo'. It also shows how to select a particular preset for the configuration. ```bash $ perf record -e cs_etm/autofdo/u --per-thread $ perf record -e cs_etm/autofdo,preset=1/u --per-thread ```