### Starting Espeakup (Manual Installation) Source: https://github.com/torvalds/linux/blob/master/Documentation/admin-guide/spkguide.txt This command starts the Espeakup daemon when it has been compiled and installed manually from source. It assumes the binary is located in /usr/bin. ```bash /usr/bin/espeakup ``` -------------------------------- ### Starting Espeakup (Package Installation) Source: https://github.com/torvalds/linux/blob/master/Documentation/admin-guide/spkguide.txt This command starts the Espeakup daemon when it has been installed as a package on the Linux distribution. It assumes a standard init script location. ```bash /etc/init.d/espeakup start ``` -------------------------------- ### Example Board Setup Code (C) Source: https://github.com/torvalds/linux/blob/master/Documentation/arch/sh/new-machine.rst Provides a C code example for a new board's setup file, including the required get_system_type and platform_setup functions. ```c /*\n * arch/sh/boards/vapor/setup.c - Setup code for imaginary board\n */\n#include \n\nconst char *get_system_type(void)\n{\n return "FooTech Vaporboard";\n}\n\nint __init platform_setup(void)\n{\n /*\n * If our hardware actually existed, we would do real\n * setup here. Though it's also sane to leave this empty\n * if there's no real init work that has to be done for\n * this board.\n */\n\n /* Start-up imaginary PCI ... */\n\n /* And whatever else ... */\n\n return 0;\n} ``` -------------------------------- ### KDB Quick Start Example Source: https://github.com/torvalds/linux/blob/master/Documentation/process/debugging/kgdb.rst Provides a quick start guide for using KDB on a serial port, including kernel parameter configuration and manual debugger entry methods. ```APIDOC Using kdb ======== Quick start for kdb on a serial port ------------------------------------ This is a quick example of how to use kdb. 1. Configure kgdboc at boot using kernel parameters:: console=ttyS0,115200 kgdboc=ttyS0,115200 nokaslr OR Configure kgdboc after the kernel has booted; assuming you are using a serial port console:: echo ttyS0 > /sys/module/kgdboc/parameters/kgdboc 2. Enter the kernel debugger manually or by waiting for an oops or fault. There are several ways you can enter the kernel debugger manually; all involve using the `SysRq-G`, which means you must have enabled ``CONFIG_MAGIC_SYSRQ=y`` in your kernel config. ``` -------------------------------- ### KUnit Build Output Example Source: https://github.com/torvalds/linux/blob/master/Documentation/dev-tools/kunit/start.rst Example output indicating the successful configuration, building, and starting of the KUnit kernel tests. ```text Configuring KUnit Kernel ... Building KUnit Kernel ... Starting KUnit Kernel ... ``` -------------------------------- ### Clang/LLVM Getting Started Source: https://github.com/torvalds/linux/blob/master/Documentation/process/changes.rst Provides a reference to documentation on how to get started with LLVM, a compiler infrastructure project. Clang is the C/C++/Objective-C frontend for LLVM. ```ref Getting LLVM ``` -------------------------------- ### Configuration Script Sample Source: https://github.com/torvalds/linux/blob/master/Documentation/networking/device_drivers/ethernet/dlink/dl2k.rst An example of a configuration script entry for the DL2K driver, used for automatic loading and network configuration. ```text alias eth0 dl2k ``` -------------------------------- ### Install Documentation Build Environment Source: https://github.com/torvalds/linux/blob/master/Documentation/translations/zh_CN/how-to.rst This snippet shows how to install the necessary packages and Sphinx for building the documentation. It includes commands for system package installation and Python virtual environment setup for Sphinx. ```bash cd linux ./scripts/sphinx-pre-install ``` ```bash sudo dnf install -y dejavu-sans-fonts dejavu-sans-mono-fonts \ dejavu-serif-fonts google-noto-sans-cjk-fonts graphviz-gd \ latexmk librsvg2-tools texlive-anyfontsize texlive-capt-of \ texlive-collection-fontsrecommended texlive-ctex \ texlive-eqparbox texlive-fncychap texlive-framed \ texlive-luatex85 texlive-multirow texlive-needspace \ texlive-tabulary texlive-threeparttable texlive-upquote \ texlive-wrapfig texlive-xecjk ``` ```bash /usr/bin/python3 -m venv sphinx_latest . sphinx_latest/bin/activate pip install -r ./Documentation/sphinx/requirements.txt ``` ```bash deactivate ``` -------------------------------- ### Sphinx Installation and Usage Source: https://github.com/torvalds/linux/blob/master/Documentation/translations/zh_CN/doc-guide/sphinx.rst Instructions for installing Sphinx and its dependencies, including using virtual environments and installing the Read the Docs theme. Also covers building HTML and PDF documentation and cleaning generated files. ```rst .. _sphinx_install_zh: 安装Sphinx ========== Documentation/ 下的ReST文件现在使用sphinx1.7或更高版本构建。 这有一个脚本可以检查Sphinx的依赖项。更多详细信息见 :ref:`sphinx-pre-install_zh` 。 大多数发行版都附带了Sphinx,但是它的工具链比较脆弱,而且在您的机器上升级它 或其他一些Python包导致文档构建中断的情况并不少见。 避免此情况的一种方法是使用与发行版附带的不同的版本。因此,建议使用 ``virtualenv-3`` 或 ``virtualenv`` 在虚拟环境中安装Sphinx,具体取决于发行版 如何打包Python3。 .. note:: #) html输出建议使用RTD主题。根据Sphinx版本的不同,它应该用 ``pip install sphinx_rtd_theme`` 单独安装。 #) 一些ReST页面包含数学表达式。由于Sphinx的工作方式,这些表达式是使用 LaTeX 编写的。它需要安装amsfonts和amsmath宏包,以便显示。 总之,如您要安装Sphinx 2.4.4版本,应执行:: $ virtualenv sphinx_2.4.4 $ . sphinx_2.4.4/bin/activate (sphinx_2.4.4) $ pip install -r Documentation/sphinx/requirements.txt 在运行 ``. sphinx_2.4.4/bin/activate`` 之后,提示符将变化,以指示您正在使用新 环境。如果您打开了一个新的shell,那么在构建文档之前,您需要重新运行此命令以再 次进入虚拟环境中。 Sphinx构建 ========== 生成文档的常用方法是运行 ``make htmldocs`` 或 ``make pdfdocs`` 。还有其它可用 的格式:请参阅 ``make help`` 的文档部分。生成的文档放在 ``Documentation/output`` 下相应格式的子目录中。 要生成文档,显然必须安装Sphinx( ``sphinx-build`` )。要让HTML输出更漂亮,可以 使用Read the Docs Sphinx主题( ``sphinx_rtd_theme`` )。对于PDF输出,您还需要 ``XeLaTeX`` 和来自ImageMagick(https://www.imagemagick.org)的 ``convert(1)`` 。 所有这些软件在大多发行版中都可用或已打包。 要传递额外的选项给Sphinx,可以使用make变量 ``SPHINXOPTS`` 。例如,使用 ``make SPHINXOPTS=-v htmldocs`` 获得更详细的输出。 要删除生成的文档,请运行 ``make cleandocs`` 。 ``` -------------------------------- ### Quick Install Commands Source: https://github.com/torvalds/linux/blob/master/Documentation/networking/device_drivers/ethernet/dlink/dl2k.rst Commands to quickly install the DL2K driver. This includes compiling, loading the module, configuring the network interface, and setting up automatic loading on boot. ```bash 1. make all 2. insmod dl2k.ko 3. ifconfig eth0 up 10.xxx.xxx.xxx netmask 255.0.0.0 4. cp dl2k.ko /lib/modules/`uname -r`/kernel/drivers/net 5. Add the following line to /etc/modprobe.d/dl2k.conf:: alias eth0 dl2k 6. Run depmod to updated module indexes. 7. Run netconfig or netconf to create configuration script ifcfg-eth0 located at /etc/sysconfig/network-scripts or create it manually. ``` -------------------------------- ### Build and Install intel-speed-select Tool Source: https://github.com/torvalds/linux/blob/master/Documentation/admin-guide/pm/intel-speed-select.rst Instructions to build and install the intel-speed-select tool from the Linux kernel source tree. This process involves navigating to the tool's directory, compiling it using 'make', and then installing it. ```bash cd tools/power/x86/intel-speed-select/ make make install ``` -------------------------------- ### Gadget Driver Setup Function Example (Conceptual) Source: https://github.com/torvalds/linux/blob/master/Documentation/driver-api/usb/gadget.rst A conceptual representation of what a gadget driver's setup() function might do, focusing on returning USB descriptors based on hardware capabilities and implemented functionality. ```C struct usb_descriptor_header *my_gadget_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) { // Logic to determine and return appropriate USB descriptors // based on hardware capabilities and the implemented function. // This might involve selecting alternate settings or configurations. // For OTG, an OTG descriptor would be included here. return &my_descriptors[0]; } ``` -------------------------------- ### Kernel Compilation and Installation Source: https://github.com/torvalds/linux/blob/master/Documentation/translations/zh_TW/admin-guide/README.rst This section outlines the steps required to compile and install a Linux kernel. It covers prerequisites like GCC version, the compilation command, installing modules, and enabling verbose output during the build process. ```bash # Ensure you have at least gcc 5.1 available. # Refer to Documentation/process/changes.rst for more information. make # Creates a compressed kernel image. # If lilo is installed, 'make install' can also be used, but check lilo setup. make modules_install # Required if any part of the kernel is configured as modules. make V=1 all # Enables verbose build mode to see compilation, linking, etc. make V=2 all # Enables even more verbose output, showing the reason for rebuilding targets. ``` -------------------------------- ### Driver Installation Steps Source: https://github.com/torvalds/linux/blob/master/Documentation/networking/device_drivers/ethernet/dlink/dl2k.rst Steps to install the dl2k driver, including copying the object file, configuring modprobe, and creating network interface scripts. ```bash cp dl2k.o /lib/modules/2.x.x-xx/net # or cp dl2k.o /lib/modules/2.x.x/kernel/drivers/net ``` ```bash echo "alias ethx dl2k" >> /etc/modprobe.d/dl2k.conf echo "options dl2k " >> /etc/modprobe.d/dl2k.conf ``` ```bash DEVICE=eth0 USERCTL=no ONBOOT=yes POOTPROTO=none BROADCAST=207.200.5.255 NETWORK=207.200.5.0 NETMASK=255.255.255.0 IPADDR=207.200.5.2 ``` -------------------------------- ### Initrd /etc/fstab Example Source: https://github.com/torvalds/linux/blob/master/Documentation/power/swsusp-dmcrypt.rst An example /etc/fstab file for an initrd, showing how to mount the necessary file systems, including a read-only mount for a PCMCIA flash disk containing crypto setup data. ```text /dev/hda1 /mnt ext3 ro 0 0 none /proc proc defaults,noatime,nodiratime 0 0 none /sys sysfs defaults,noatime,nodiratime 0 0 ``` -------------------------------- ### ndctl Namespace Setup Example Source: https://github.com/torvalds/linux/blob/master/Documentation/driver-api/nvdimm/btt.rst Provides an example of using the 'ndctl' utility to set up a BTT namespace with a specified sector size. ```APIDOC ndctl create-namespace -f -e namespace0.0 -m sector -l 4k This command sets up a BTT namespace with a 4k sector size. Refer to 'ndctl create-namespace --help' for more options. ``` -------------------------------- ### dm-verity Setup Example Source: https://github.com/torvalds/linux/blob/master/Documentation/admin-guide/device-mapper/verity.rst An example of how to set up a dm-verity device using the dmsetup command. This includes specifying the device, its readonly status, the table format, and various parameters like block size, hash algorithm, and the root hash signature. ```bash # dmsetup create vroot --readonly --table \ "0 2097152 verity 1 /dev/sda1 /dev/sda2 4096 4096 262144 1 sha256 "\ "4392712ba01368efdf14b05c76f9e4df0d53664630b5d48632ed17a137f39076 " ``` -------------------------------- ### KUnit Configuration File Example Source: https://github.com/torvalds/linux/blob/master/Documentation/dev-tools/kunit/start.rst An example of a `.kunit/.kunitconfig` file, specifying the build configurations for the 'My example' module and its KUnit tests, setting them to be enabled. ```none CONFIG_MISC_EXAMPLE=y CONFIG_MISC_EXAMPLE_TEST=y ``` -------------------------------- ### 通過補丁升級 Linux 內核 Source: https://github.com/torvalds/linux/blob/master/Documentation/translations/zh_TW/admin-guide/README.rst 通過應用補丁升級內核的詳細信息。它涵蓋了順序打補丁、處理備份文件以及使用 patch-kernel 腳本進行自動化。它還解釋了如何處理穩定版發布的補丁。 ```bash xz -cd ../patch-6.x.xz | patch -p1 ``` ```bash linux/scripts/patch-kernel linux ``` -------------------------------- ### Clang/LLVM Getting Started Source: https://github.com/torvalds/linux/blob/master/Documentation/translations/it_IT/process/changes.rst Link to instructions on how to obtain LLVM, which includes Clang. ```APIDOC Clang/LLVM: Get started with: :ref:`Getting LLVM `. ``` -------------------------------- ### Start Streaming with GStreamer (Complex Pipeline) Source: https://github.com/torvalds/linux/blob/master/Documentation/admin-guide/media/imx.rst Starts a GStreamer pipeline to capture from /dev/video1 and output to the display, similar to the basic example but for the complex pipeline setup. ```shell gst-launch-1.0 v4l2src device=/dev/video1 ! kmssink ``` -------------------------------- ### Linux Boot Process Steps Source: https://github.com/torvalds/linux/blob/master/Documentation/admin-guide/initrd.rst Outlines the sequence of events during a Linux system boot, starting from loading the kernel and initrd to installing and configuring the boot loader. ```APIDOC 1. System boots from minimal kernel with initrd support. 2. /sbin/init determines real root FS and distribution media requirements. 3. /sbin/init loads necessary kernel modules. 4. /sbin/init creates and populates the root file system. 5. /sbin/init uses pivot_root to change the root file system and executes the final init. 6. Boot loader is installed. 7. Boot loader is configured to load initrd with appropriate modules. ``` -------------------------------- ### Obtaining and Installing Sparse Source: https://github.com/torvalds/linux/blob/master/Documentation/translations/zh_TW/dev-tools/sparse.rst Provides instructions on how to get the latest version of the sparse tool from its official website or via git. It also outlines the simple build and installation process. ```bash git clone git://git.kernel.org/pub/scm/devel/sparse/sparse.git # After downloading source code: make make install ``` -------------------------------- ### Mount UBI Volume Example Source: https://github.com/torvalds/linux/blob/master/Documentation/filesystems/ubifs.rst Demonstrates mounting a UBI volume to a specified mount point using the `mount` command. It shows how to specify the UBI device and volume, and the target mount directory. ```bash $ mount -t ubifs ubi0_0 /mnt/ubifs ``` ```bash $ mount -t ubifs ubi0:rootfs /mnt/ubifs ``` -------------------------------- ### Install bindgen CLI Source: https://github.com/torvalds/linux/blob/master/Documentation/translations/zh_CN/rust/quick-start.rst Installs the `bindgen-cli` tool, which is used to generate C bindings for the kernel's Rust code. This command downloads and builds the tool from source and requires a specific version. ```shell cargo install --locked --version $(scripts/min-tool-version.sh bindgen) bindgen-cli ``` -------------------------------- ### C Example: Using setup_indirect for SETUP_E820_EXT Source: https://github.com/torvalds/linux/blob/master/Documentation/arch/x86/boot.rst Illustrates how to configure a setup_data entry to use setup_indirect for pointing to SETUP_E820_EXT data. This example demonstrates the structure and values required for indirect data referencing in the boot protocol. ```C struct setup_data { .next = 0, /* or */ .type = SETUP_INDIRECT, .len = sizeof(setup_indirect), .data[sizeof(setup_indirect)] = (struct setup_indirect) { .type = SETUP_INDIRECT | SETUP_E820_EXT, .reserved = 0, .len = , .addr = , }, } ``` -------------------------------- ### Perf Record Control Script Example Source: https://github.com/torvalds/linux/blob/master/tools/perf/Documentation/perf-record.txt An example bash script demonstrating how to control 'perf record' measurements using FIFOs for enabling and disabling events. It includes setup for control and acknowledgment FIFOs, starting 'perf record' with control file descriptors, and sending commands to enable/disable events. ```bash #!/bin/bash ctl_dir=/tmp/ ctl_fifo=${ctl_dir}perf_ctl.fifo test -p ${ctl_fifo} && unlink ${ctl_fifo} mkfifo ${ctl_fifo} exec {ctl_fd}<>${ctl_fifo} ctl_ack_fifo=${ctl_dir}perf_ctl_ack.fifo test -p ${ctl_ack_fifo} && unlink ${ctl_ack_fifo} mkfifo ${ctl_ack_fifo} exec {ctl_fd_ack}<>${ctl_ack_fifo} perf record -D -1 -e cpu-cycles -a \ --control fd:${ctl_fd},${ctl_fd_ack} \ -- sleep 30 & perf_pid=$! sleep 5 && echo 'enable' >&${ctl_fd} && read -u ${ctl_fd_ack} e1 && echo "enabled(${e1})" sleep 10 && echo 'disable' >&${ctl_fd} && read -u ${ctl_fd_ack} d1 && echo "disabled(${d1})" exec {ctl_fd_ack}>&- unlink ${ctl_ack_fifo} exec {ctl_fd}>&- unlink ${ctl_fifo} wait -n ${perf_pid} exit $? ``` -------------------------------- ### Cgroup Freezer Usage Examples Source: https://github.com/torvalds/linux/blob/master/Documentation/admin-guide/cgroup-v1/freezer-subsystem.rst Provides practical examples of how to set up and use the cgroup freezer. This includes mounting the freezer subsystem, creating cgroups, assigning tasks, and checking/modifying the freezer state. ```bash # Setup: # mkdir /sys/fs/cgroup/freezer # mount -t cgroup -ofreezer freezer /sys/fs/cgroup/freezer # mkdir /sys/fs/cgroup/freezer/0 # echo $some_pid > /sys/fs/cgroup/freezer/0/tasks # Get status: # cat /sys/fs/cgroup/freezer/0/freezer.state THAWED # Freeze tasks: # echo FROZEN > /sys/fs/cgroup/freezer/0/freezer.state # cat /sys/fs/cgroup/freezer/0/freezer.state FREEZING # cat /sys/fs/cgroup/freezer/0/freezer.state FROZEN # Unfreeze tasks: # echo THAWED > /sys/fs/cgroup/freezer/0/freezer.state # cat /sys/fs/cgroup/freezer/0/freezer.state THAWED ``` -------------------------------- ### Setup DMA Receive Buffer (Linux Kernel C Pseudo-code) Source: https://github.com/torvalds/linux/blob/master/Documentation/core-api/dma-api-howto.rst A pseudo-code example demonstrating the setup of a receive buffer using dma_map_single. It includes error handling for DMA mapping failures and prepares the buffer for the hardware. ```C my_card_setup_receive_buffer(struct my_card *cp, char *buffer, int len) { dma_addr_t mapping; mapping = dma_map_single(cp->dev, buffer, len, DMA_FROM_DEVICE); if (dma_mapping_error(cp->dev, mapping)) { /* * reduce current DMA mapping usage, * delay and try again later or * reset driver. */ goto map_error_handling; } cp->rx_buf = buffer; cp->rx_len = len; cp->rx_dma = mapping; give_rx_buf_to_card(cp); } ``` -------------------------------- ### Insert hvcs Kernel Module with Parameter Source: https://github.com/torvalds/linux/blob/master/Documentation/arch/powerpc/hvcs.rst Shows how to insert the hvcs kernel module with a parameter to override the default number of tty devices, requesting 4 devices as an example. ```bash insmod hvcs.ko hvcs_parm_num_devs=4 ``` -------------------------------- ### ISL12057 Device Tree Node Examples Source: https://github.com/torvalds/linux/blob/master/Documentation/devicetree/bindings/rtc/isil,isl12057.txt Provides examples of how to define an ISL12057 device tree node. It includes configurations for a basic setup, a setup with an IRQ line connected to the SoC, and a setup where the chip acts as a wakeup source by connecting to a PMIC. ```APIDOC ISL12057 Device Tree Node Examples: 1. Basic node without IRQ#2 pin connected (no alarm support): isl12057: isl12057@68 { compatible = "isil,isl12057"; reg = <0x68>; }; 2. Node with IRQ#2 pin connected to main SoC via MPP6: pinctrl { ... rtc_alarm_pin: rtc_alarm_pin { marvell,pins = "mpp6"; marvell,function = "gpio"; }; ... }; ... isl12057: isl12057@68 { compatible = "isil,isl12057"; reg = <0x68>; pinctrl-0 = <&rtc_alarm_pin>; pinctrl-names = "default"; interrupt-parent = <&gpio0>; interrupts = <6 IRQ_TYPE_EDGE_FALLING>; }; 3. Node without IRQ#2 pin connected to the SoC but to a PMIC (wakeup source): isl12057: isl12057@68 { compatible = "isil,isl12057"; reg = <0x68>; wakeup-source; }; ``` -------------------------------- ### Creating and Testing a Simple Initramfs Source: https://github.com/torvalds/linux/blob/master/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 test it as an external initramfs using QEMU. It highlights the process of setting up a minimal root filesystem for early userspace execution. ```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 ``` -------------------------------- ### ALSA Get Callback Example Source: https://github.com/torvalds/linux/blob/master/Documentation/sound/kernel-api/writing-an-alsa-driver.rst Provides an example of a get callback function, which is responsible for reading the current value of an ALSA control element and returning it to user-space. It shows how to access chip-specific data and retrieve control values. ```c static int snd_myctl_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct mychip *chip = snd_kcontrol_chip(kcontrol); ucontrol->value.integer.value[0] = get_some_value(chip); return 0; } ``` -------------------------------- ### Setting up a Cpuset Source: https://github.com/torvalds/linux/blob/master/Documentation/admin-guide/cgroup-v1/cpusets.rst Demonstrates the steps to create and configure a new cpuset, assign CPUs and memory nodes, and launch a task within it. ```bash 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 ``` -------------------------------- ### Get Feature Command Example (C) Source: https://github.com/torvalds/linux/blob/master/Documentation/userspace-api/fwctl/fwctl-cxl.rst Provides a C code example demonstrating how to send a 'Get Feature' command to the CXL driver using `ioctl(FWCTL_RPC)`. It includes memory allocation, structure population, and the `send_command` call. ```c static int cxl_fwctl_rpc_get_test_feature(int fd, struct test_feature *feat_ctx, const uint32_t expected_data) { struct cxl_mbox_get_feat_in *feat_in; struct fwctl_rpc_cxl_out *out; struct fwctl_rpc rpc = {0}; struct fwctl_rpc_cxl *in; size_t out_size, in_size; uint32_t val; void *data; int rc; in_size = sizeof(*in) + sizeof(*feat_in); rc = posix_memalign((void **)&in, 16, in_size); if (rc) return -ENOMEM; memset(in, 0, in_size); feat_in = &in->get_feat_in; uuid_copy(feat_in->uuid, feat_ctx->uuid); feat_in->count = feat_ctx->get_size; out_size = sizeof(*out) + feat_ctx->get_size; rc = posix_memalign((void **)&out, 16, out_size); if (rc) goto free_in; memset(out, 0, out_size); in->opcode = CXL_MBOX_OPCODE_GET_FEATURE; in->op_size = sizeof(*feat_in); rpc.size = sizeof(rpc); rpc.scope = FWCTL_RPC_CONFIGURATION; rpc.in_len = in_size; rpc.out_len = out_size; rpc.in = (uint64_t)(uint64_t *)in; rpc.out = (uint64_t)(uint64_t *)out; rc = send_command(fd, &rpc, out); if (rc) goto free_all; ``` -------------------------------- ### Creating and Navigating Cpusets Source: https://github.com/torvalds/linux/blob/master/Documentation/admin-guide/cgroup-v1/cpusets.rst Illustrates the process of creating a new cpuset directory and navigating into it. This is done using standard filesystem commands. ```bash # cd /sys/fs/cgroup/cpuset # mkdir my_cpuset # cd my_cpuset ``` -------------------------------- ### Getting and Installing Sparse Source: https://github.com/torvalds/linux/blob/master/Documentation/dev-tools/sparse.rst Provides instructions for obtaining and installing the Sparse tool. Users can download released tarballs or clone the latest development version using Git. Installation involves running 'make' and 'make install'. ```bash git clone git://git.kernel.org/pub/scm/devel/sparse/sparse.git cd sparse make make install ``` -------------------------------- ### Example: dm-linear Configuration (Multiple Partitions) Source: https://github.com/torvalds/linux/blob/master/Documentation/admin-guide/device-mapper/dm-init.rst Demonstrates a `dm-linear` setup spanning multiple partitions of a block device. ```APIDOC dm-linear,,,rw, 0 32768 linear /dev/sda1 0, 32768 1024000 linear /dev/sda2 0, 1056768 204800 linear /dev/sda3 0, 1261568 512000 linear /dev/sda4 0 ``` -------------------------------- ### bpftool Program Show Examples Source: https://github.com/torvalds/linux/blob/master/tools/bpf/bpftool/Documentation/bpftool-prog.rst Demonstrates how to display BPF program information using `bpftool prog show`, both in a human-readable format and as JSON. ```bash # bpftool prog show :: 10: xdp name some_prog tag 005a3d2123620c8b gpl run_time_ns 81632 run_cnt 10 loaded_at 2017-09-29T20:11:00+0000 uid 0 xlated 528B jited 370B memlock 4096B map_ids 10 pids systemd(1) # bpftool --json --pretty prog show :: [{ "id": 10, "type": "xdp", "tag": "005a3d2123620c8b", "gpl_compatible": true, "run_time_ns": 81632, "run_cnt": 10, "loaded_at": 1506715860, "uid": 0, "bytes_xlated": 528, "jited": true, "bytes_jited": 370, "bytes_memlock": 4096, "map_ids": [ 10 ], "pids": [ { "pid": 1, "comm": "systemd" } ] } ] ``` -------------------------------- ### Start dmatest Source: https://github.com/torvalds/linux/blob/master/Documentation/driver-api/dmaengine/dmatest.rst Command to start the dmatest module. If no channels are configured, it will proceed with any available channels. ```bash % echo 1 > /sys/module/dmatest/parameters/run dmatest: No channels configured, continue with any ``` -------------------------------- ### 使用輸出目錄構建內核 Source: https://github.com/torvalds/linux/blob/master/Documentation/translations/zh_TW/admin-guide/README.rst 演示如何使用 make 命令的 O= 選項為構建產物(包括 .config 文件)指定替代輸出目錄。 ```bash make O=output/dir menuconfig make O=output/dir sudo make O=output/dir modules_install install ``` -------------------------------- ### OverlayFS Mount Examples Source: https://github.com/torvalds/linux/blob/master/Documentation/filesystems/overlayfs.rst Demonstrates different ways to mount the OverlayFS filesystem, including single and multiple lower directories, and the use of 'upperdir' and 'workdir'. ```bash mount -t overlay overlay -olowerdir=/lower,upperdir=/upper,... /merged ``` ```bash mount -t overlay overlay -olowerdir=/lower1:/lower2:/lower3 /merged ``` ```bash mount -t overlay overlay -olowerdir=/a\:lower\:\:dir /merged ``` ```bash mount -t overlay overlay -olowerdir=/l1:/l2:/l3::/do1::/do2 /merged ``` -------------------------------- ### 查找初始化二进制的库依赖项 Source: https://github.com/torvalds/linux/blob/master/Documentation/translations/zh_CN/admin-guide/init.rst 使用 `readelf -d |grep NEEDED` 命令可以找出初始化二进制文件所需的库依赖项。这有助于诊断“Binary exists but dependencies not available”的错误。 ```bash readelf -d |grep NEEDED ``` -------------------------------- ### vivid Module Configuration Example Source: https://github.com/torvalds/linux/blob/master/Documentation/admin-guide/media/vivid.rst Example of how to configure the vivid module with specific device and input/output types for multiple instances. ```none n_devs=4 node_types=0x1,0x1,0x100,0x100 ``` -------------------------------- ### EP93xx Framebuffer Setup Platform Callback Source: https://github.com/torvalds/linux/blob/master/Documentation/fb/ep93xx-fb.rst Example of the setup platform callback function for the EP93xx framebuffer driver. ```c static int some_board_fb_setup(struct platform_device *pdev) { struct ep93xxfb_mach_info *mach_info = pdev->dev.platform_data; struct fb_info *fb_info = platform_get_drvdata(pdev); /* Board specific framebuffer setup */ } ``` -------------------------------- ### Starting cachefilesd Daemon Source: https://github.com/torvalds/linux/blob/master/Documentation/filesystems/caching/cachefiles.rst Demonstrates how to start the cachefilesd daemon with various command-line options for debugging, output redirection, and configuration file specification. ```bash /sbin/cachefilesd [-d]* [-s] [-n] [-f ] ``` -------------------------------- ### Kselftest Output Example Source: https://github.com/torvalds/linux/blob/master/Documentation/PCI/endpoint/pci-test-howto.rst Example output from running the 'pci_endpoint_test' utility. It shows the test cases being executed and their results (OK/FAIL). ```text # pci_endpoint_test TAP version 13 1..16 # Starting 16 tests from 9 test cases. # RUN pci_ep_bar.BAR0.BAR_TEST ... # OK pci_ep_bar.BAR0.BAR_TEST ok 1 pci_ep_bar.BAR0.BAR_TEST # RUN pci_ep_bar.BAR1.BAR_TEST ... # OK pci_ep_bar.BAR1.BAR_TEST ok 2 pci_ep_bar.BAR1.BAR_TEST # RUN pci_ep_bar.BAR2.BAR_TEST ... # OK pci_ep_bar.BAR2.BAR_TEST ok 3 pci_ep_bar.BAR2.BAR_TEST # RUN pci_ep_bar.BAR3.BAR_TEST ... # OK pci_ep_bar.BAR3.BAR_TEST ok 4 pci_ep_bar.BAR3.BAR_TEST # RUN pci_ep_bar.BAR4.BAR_TEST ... # OK pci_ep_bar.BAR4.BAR_TEST ok 5 pci_ep_bar.BAR4.BAR_TEST # RUN pci_ep_bar.BAR5.BAR_TEST ... # OK pci_ep_bar.BAR5.BAR_TEST ok 6 pci_ep_bar.BAR5.BAR_TEST # RUN pci_ep_basic.CONSECUTIVE_BAR_TEST ... # OK pci_ep_basic.CONSECUTIVE_BAR_TEST ok 7 pci_ep_basic.CONSECUTIVE_BAR_TEST # RUN pci_ep_basic.LEGACY_IRQ_TEST ... ``` -------------------------------- ### Listing Speakup Parameters Source: https://github.com/torvalds/linux/blob/master/Documentation/admin-guide/spkguide.txt Demonstrates how to list all available Speakup configuration parameters by listing the contents of the /speakup directory. ```bash ls -1 /speakup/* ``` -------------------------------- ### Install Rust Standard Library Source Source: https://github.com/torvalds/linux/blob/master/Documentation/translations/zh_CN/rust/quick-start.rst Installs the Rust standard library source code, which is necessary for cross-compiling `core` and `alloc`. This command is for users who are not using `rustup` and are installing standalone. ```shell curl -L "https://static.rust-lang.org/dist/rust-src-$(scripts/min-tool-version.sh rustc).tar.gz" \ | tar -xzf - -C "$(rustc --print sysroot)/lib" \ "rust-src-$(scripts/min-tool-version.sh rustc)/rust-src/lib/" \ --strip-components=3 ``` -------------------------------- ### Install Linux Kernel Source Code Source: https://github.com/torvalds/linux/blob/master/Documentation/translations/zh_TW/admin-guide/README.rst Instructions for installing the Linux kernel source code using tar archives. It emphasizes avoiding the /usr/src/linux directory for header files. ```bash xz -cd linux-6.x.tar.xz | tar xvf - ``` -------------------------------- ### Basic Configfs Setup for USB Gadget Source: https://github.com/torvalds/linux/blob/master/Documentation/usb/gadget_configfs.rst This snippet demonstrates the initial steps to set up a USB gadget using configfs. It involves loading the libcomposite module and mounting the configfs filesystem. ```bash $ modprobe libcomposite $ mount none $CONFIGFS_HOME -t configfs ``` -------------------------------- ### Creating and Mounting initrd File System Source: https://github.com/torvalds/linux/blob/master/Documentation/admin-guide/initrd.rst This snippet demonstrates the steps to create an empty file system for an initrd using dd and mke2fs, and then mount it for further configuration. It highlights the use of loopback devices for mounting. ```bash # dd if=/dev/zero of=initrd bs=300k count=1 # mke2fs -F -m0 initrd # mount -t ext2 -o loop initrd /mnt ``` -------------------------------- ### Benchmark Execution Example Source: https://github.com/torvalds/linux/blob/master/Documentation/admin-guide/pm/intel-speed-select.rst Example of executing a 'sched pipe' benchmark on high priority CPUs (5 and 6) after enabling Intel(R) SST-BF. This demonstrates the performance improvement in terms of operations per second and latency. ```bash #taskset -c 5,6 perf bench -r 100 sched pipe # Running 'sched/pipe' benchmark: # Executed 1000000 pipe operations between two processes Total time: 5.627 [sec] 5.627922 usecs/op 177685 ops/sec ``` -------------------------------- ### Boot Configuration API Usage Example Source: https://github.com/torvalds/linux/blob/master/Documentation/translations/zh_TW/admin-guide/bootconfig.rst Demonstrates how to use the boot configuration API functions like `xbc_find_value` and `xbc_array_for_each_value` to retrieve and iterate over key-value pairs and array elements. ```c 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); } ``` -------------------------------- ### Starting Speech Dispatcher with speechd-up Source: https://github.com/torvalds/linux/blob/master/Documentation/admin-guide/spkguide.txt This command starts the speechd-up utility, which bridges Speech Dispatcher with Speakup. The '&' runs the command in the background. ```bash speechd_up & ``` -------------------------------- ### 清理內核構建目錄 Source: https://github.com/torvalds/linux/blob/master/Documentation/translations/zh_TW/admin-guide/README.rst 在構建之前清理內核源代碼目錄中過時的對象文件和依賴項的命令。 ```bash cd linux make mrproper ``` -------------------------------- ### Configure Kernel for Built-in Tests Source: https://github.com/torvalds/linux/blob/master/Documentation/dev-tools/kunit/running_tips.rst Enables KUnit and a specific example test within the kernel configuration. When the kernel boots, these tests will run and print results in TAP format to dmesg. ```none CONFIG_KUNIT=y CONFIG_KUNIT_EXAMPLE_TEST=y ``` -------------------------------- ### Install hvcs Kernel Module using modprobe Source: https://github.com/torvalds/linux/blob/master/Documentation/arch/powerpc/hvcs.rst Demonstrates the recommended method for installing the hvcs driver as a module using `modprobe`, which respects module dependencies defined in modules.dep. ```bash modprobe hvcs hvcs_parm_num_devs=4 ``` -------------------------------- ### KUnit Test Setup and Teardown Source: https://github.com/torvalds/linux/blob/master/Documentation/dev-tools/kunit/usage.rst Demonstrates the basic structure of a KUnit test case, including initialization (`eeprom_buffer_test_init`) and cleanup (`eeprom_buffer_test_exit`) functions. It shows how to allocate and initialize test context using `kunit_kzalloc` and manage resources like the fake EEPROM and EEPROM buffer. ```c static int eeprom_buffer_test_init(struct kunit *test) { struct eeprom_buffer_test *ctx; ctx = kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx); ctx->fake_eeprom = kunit_kzalloc(test, sizeof(*ctx->fake_eeprom), GFP_KERNEL); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx->fake_eeprom); fake_eeprom_init(ctx->fake_eeprom); ctx->eeprom_buffer = new_eeprom_buffer(&ctx->fake_eeprom->parent); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx->eeprom_buffer); test->priv = ctx; return 0; } static void eeprom_buffer_test_exit(struct kunit *test) { struct eeprom_buffer_test *ctx = test->priv; destroy_eeprom_buffer(ctx->eeprom_buffer); } ``` -------------------------------- ### Start NTB Link Source: https://github.com/torvalds/linux/blob/master/Documentation/PCI/endpoint/pci-ntb-howto.rst Shows how to initiate the NTB link by writing '1' to the 'start' field of the PCI endpoint controller devices. Both controllers must be started for the link to establish. ```bash # echo 1 > controllers/2900000.pcie-ep/start # echo 1 > controllers/2910000.pcie-ep/start ``` -------------------------------- ### KUnit Tool Command-Line Arguments Source: https://github.com/torvalds/linux/blob/master/Documentation/dev-tools/kunit/run_wrapper.rst Provides examples of common command-line arguments for the kunit_tool, including filtering, QEMU execution, and configuration options. ```APIDOC kunit.py run [OPTIONS] [TEST_FILTER] Filter tests using bash-style glob patterns. Example: ./tools/testing/kunit/kunit.py run 'kunit-resource*' Run tests on QEMU: --arch= Selects a configs collection for running tests on a specified architecture in QEMU. Example: --arch=x86_64 Use '--arch help' to list valid values. --cross_compile= Specifies the Kbuild toolchain prefix for cross-compilation. Example: --cross_compile=sparc64-linux-gnu- --qemu_config= Specifies a custom QEMU configuration file, replacing --arch. Example: --qemu_config=./tools/testing/kunit/qemu_configs/x86_64.py Common command-line arguments: --help Lists all available options. Place before or after command for specific help. --build_dir= Specifies the kunit_tool build directory. --make_options= Passes additional options to make during kernel compilation. Example: --make_options W=1 --alltests Enables a predefined set of options to build as many tests as possible. --kunitconfig= Specifies the path or directory of the .kunitconfig file. --kconfig_add= Appends additional configuration options to the .kunitconfig file. Example: --kconfig_add CONFIG_KASAN=y ``` -------------------------------- ### Review Boot Messages Source: https://github.com/torvalds/linux/blob/master/Documentation/admin-guide/spkguide.txt This command allows you to review all kernel boot-up messages after the system has started. It pipes the output of `dmesg` to `more` for paginated viewing. ```bash dmesg | more ```