### SYM53c8xx Controller Setup Example Source: https://github.com/parrotsec/linux-parrot/blob/master/Documentation/scsi/sym53c8xx_2.rst Example of the controller setup bytes. This section includes flags, host ID, and removable media support. ```text 00 30 00 00 00 00 07 00 00 00 00 00 00 00 07 04 10 04 00 00 | | | | | | | -- host ID | | | | | --Removable Media Support | | 0x00 = none | | 0x01 = Bootable Device | | 0x02 = All with Media | | | --flag bits 2 | 0x00000001= scan order hi->low | (default 0x00 - scan low->hi) --flag bits 1 0x00000001 scam enable 0x00000010 parity enable 0x00000100 verbose boot msgs ``` -------------------------------- ### SYM53c8xx Device Setup Example Source: https://github.com/parrotsec/linux-parrot/blob/master/Documentation/scsi/sym53c8xx_2.rst Example of device setup entries, defining parameters for up to 16 devices. Each entry includes flags, bus width, sync period, and timeout. ```text 0f 00 08 08 64 00 0a 00 - id 0 0f 00 08 08 64 00 0a 00 0f 00 08 08 64 00 0a 00 0f 00 08 08 64 00 0a 00 0f 00 08 08 64 00 0a 00 0f 00 08 08 64 00 0a 00 0f 00 08 08 64 00 0a 00 0f 00 08 08 64 00 0a 00 0f 00 08 08 64 00 0a 00 0f 00 08 08 64 00 0a 00 0f 00 08 08 64 00 0a 00 0f 00 08 08 64 00 0a 00 0f 00 08 08 64 00 0a 00 0f 00 08 08 64 00 0a 00 0f 00 08 08 64 00 0a 00 0f 00 08 08 64 00 0a 00 - id 15 | | | | | | | | | | ----timeout (lsb/msb) | | | --synch period (0x?? 40 Mtrans/sec- fast 40) (probably 0x28) | | | (0x30 20 Mtrans/sec- fast 20) | | | (0x64 10 Mtrans/sec- fast ) | | | (0xc8 5 Mtrans/sec) | | | (0x00 asynchronous) | | -- ?? max sync offset (0x08 in NVRAM on 53c810a) | | (0x10 in NVRAM on 53c875) | --device bus width (0x08 narrow) | (0x10 16 bit wide) --flag bits 0x00000001 - disconnect enabled 0x00000010 - scan at boot time 0x00000100 - scan luns 0x00001000 - queue tags enabled ``` -------------------------------- ### Finalize s390 Disk Image Setup Source: https://github.com/parrotsec/linux-parrot/blob/master/Documentation/bpf/s390.rst After starting the QEMU VM for the first time, run this command inside the guest to complete the debootstrap installation process. ```bash /debootstrap/debootstrap --second-stage ``` -------------------------------- ### Start Espeakup (Package Installation) Source: https://github.com/parrotsec/linux-parrot/blob/master/Documentation/admin-guide/spkguide.txt Starts the Espeakup daemon when installed as a system package. Requires root privileges. Adapt 'init.d' to 'rc.d' if necessary for your distribution. ```bash /etc/init.d/espeakup start ``` -------------------------------- ### VFIO IOMMU Setup and DMA Mapping Example Source: https://github.com/parrotsec/linux-parrot/blob/master/Documentation/driver-api/vfio.rst Demonstrates the sequence of ioctl calls to set up a VFIO container, enable an IOMMU, map a DMA region, and get a device file descriptor. Ensure rlimits are sufficient before enabling the IOMMU. ```c struct vfio_eeh_pe_op pe_op = { .argsz = sizeof(pe_op), .flags = 0 }; ..... /* 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_SPAPR_TCE_IOMMU) /* Get addition sPAPR IOMMU info */ vfio_iommu_spapr_tce_info spapr_iommu_info; ioctl(container, VFIO_IOMMU_SPAPR_TCE_GET_INFO, &spapr_iommu_info); if (ioctl(container, VFIO_IOMMU_ENABLE)) /* Cannot enable container, may be low rlimit */ /* 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; /* Check here is .iova/.size are within DMA window from spapr_iommu_info */ 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"); .... /* Gratuitous device reset and go... */ ioctl(device, VFIO_DEVICE_RESET); ``` -------------------------------- ### Start Espeakup (Manual Installation) Source: https://github.com/parrotsec/linux-parrot/blob/master/Documentation/admin-guide/spkguide.txt Runs the Espeakup binary after manual installation. Requires root privileges. ```bash /usr/bin/espeakup ``` -------------------------------- ### Board Setup Code Example Source: https://github.com/parrotsec/linux-parrot/blob/master/Documentation/sh/new-machine.rst Provides definitions for get_system_type() and platform_setup() required for new board integration. This setup code is essential for the build system to recognize and initialize the board. ```c /* * arch/sh/boards/vapor/setup.c - Setup code for imaginary board */ #include const char *get_system_type(void) { return "FooTech Vaporboard"; } int __init platform_setup(void) { /* * If our hardware actually existed, we would do real * setup here. Though it's also sane to leave this empty * if there's no real init work that has to be done for * this board. */ /* Start-up imaginary PCI ... */ /* And whatever else ... */ return 0; } ``` -------------------------------- ### IIO HW Consumer Setup Example Source: https://github.com/parrotsec/linux-parrot/blob/master/Documentation/driver-api/iio/hw-consumer.rst Demonstrates the setup and usage of an IIO hardware consumer within a device probe and read function. Ensure the hwc variable is properly allocated before use. ```c static struct iio_hw_consumer *hwc; static const struct iio_info adc_info = { .read_raw = adc_read_raw, }; static int adc_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long mask) { ret = iio_hw_consumer_enable(hwc); /* Acquire data */ ret = iio_hw_consumer_disable(hwc); } static int adc_probe(struct platform_device *pdev) { hwc = devm_iio_hw_consumer_alloc(&iio->dev); } ``` -------------------------------- ### IIO Triggered Buffer Setup Example Source: https://github.com/parrotsec/linux-parrot/blob/master/Documentation/driver-api/iio/triggered-buffers.rst Demonstrates the typical setup for an IIO triggered buffer, including defining buffer setup operations, interrupt handlers, and the main setup call. This is usually performed in the probe function of a driver. ```c const struct iio_buffer_setup_ops sensor_buffer_setup_ops = { .preenable = sensor_buffer_preenable, .postenable = sensor_buffer_postenable, .postdisable = sensor_buffer_postdisable, .predisable = sensor_buffer_predisable, }; irqreturn_t sensor_iio_pollfunc(int irq, void *p) { pf->timestamp = iio_get_time_ns((struct indio_dev *)p); return IRQ_WAKE_THREAD; } irqreturn_t sensor_trigger_handler(int irq, void *p) { u16 buf[8]; int i = 0; /* read data for each active channel */ for_each_set_bit(bit, active_scan_mask, masklength) buf[i++] = sensor_get_data(bit) iio_push_to_buffers_with_timestamp(indio_dev, buf, timestamp); iio_trigger_notify_done(trigger); return IRQ_HANDLED; } /* setup triggered buffer, usually in probe function */ iio_triggered_buffer_setup(indio_dev, sensor_iio_polfunc, sensor_trigger_handler, sensor_buffer_setup_ops); ``` -------------------------------- ### NCR53c8xx Boot Setup Command Example Source: https://github.com/parrotsec/linux-parrot/blob/master/Documentation/scsi/ncr53c8xx.rst Example of passing configuration options to the ncr53c8xx driver at boot time using lilo. Options include tagged commands, synchronous negotiation speed, and debug flags. ```bash lilo: linux root=/dev/hda2 ncr53c8xx=tags:4,sync:10,debug:0x200 ``` -------------------------------- ### IIO Trigger Setup Example Source: https://github.com/parrotsec/linux-parrot/blob/master/Documentation/driver-api/iio/triggers.rst A C code example demonstrating how to allocate, configure, and register an IIO trigger with the IIO core. ```APIDOC ## IIO Trigger Setup Example ```c struct iio_trigger_ops trigger_ops = { .set_trigger_state = sample_trigger_state, .validate_device = sample_validate_device, }; struct iio_trigger *trig; /* first, allocate memory for our trigger */ trig = iio_trigger_alloc(dev, "trig-%s-%d", name, idx); /* setup trigger operations field */ trig->ops = &trigger_ops; /* now register the trigger with the IIO core */ iio_trigger_register(trig); ``` ``` -------------------------------- ### IIO Trigger Setup Example Source: https://github.com/parrotsec/linux-parrot/blob/master/Documentation/driver-api/iio/triggers.rst Demonstrates the steps to allocate, configure, and register an IIO trigger with the IIO core. Requires defining trigger operations. ```c struct iio_trigger_ops trigger_ops = { .set_trigger_state = sample_trigger_state, .validate_device = sample_validate_device, } struct iio_trigger *trig; /* first, allocate memory for our trigger */ trig = iio_trigger_alloc(dev, "trig-%s-%d", name, idx); /* setup trigger operations field */ trig->ops = &trigger_ops; /* now register the trigger with the IIO core */ iio_trigger_register(trig); ``` -------------------------------- ### Create and Test a Simple Initramfs Source: https://github.com/parrotsec/linux-parrot/blob/master/Documentation/filesystems/ramfs-rootfs-initramfs.rst This example demonstrates how to create a basic 'Hello World' initramfs, compile it statically, package it into a cpio.gz archive, and test it using QEMU. It's a good starting point for understanding initramfs functionality. ```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 # Testing external initramfs using the initrd loading mechanism. qemu -kernel /boot/vmlinuz -initrd test.cpio.gz /dev/zero ``` -------------------------------- ### ALSA Control Get Single Value Example Source: https://github.com/parrotsec/linux-parrot/blob/master/Documentation/sound/kernel-api/writing-an-alsa-driver.rst Example of a get callback that decodes private_value to retrieve register, shift, and mask for accessing control elements. ```c static int snd_sbmixer_get_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { int reg = kcontrol->private_value & 0xff; int shift = (kcontrol->private_value >> 16) & 0xff; int mask = (kcontrol->private_value >> 24) & 0xff; .... } ``` -------------------------------- ### Example: Pointing to SETUP_E820_EXT using setup_indirect Source: https://github.com/parrotsec/linux-parrot/blob/master/Documentation/x86/boot.rst Illustrates how to use the setup_indirect structure to point to SETUP_E820_EXT data. This pattern is useful for passing large or complex data structures during the boot process, leveraging the indirect addressing mechanism. ```c struct setup_data { __u64 next = 0 or ; __u32 type = SETUP_INDIRECT; __u32 len = sizeof(setup_indirect); __u8 data[sizeof(setup_indirect)] = struct setup_indirect { __u32 type = SETUP_INDIRECT | SETUP_E820_EXT; __u32 reserved = 0; __u64 len = ; __u64 addr = ; } } ``` -------------------------------- ### Boot Config File Syntax Example Source: https://github.com/parrotsec/linux-parrot/blob/master/Documentation/admin-guide/bootconfig.rst Demonstrates the basic key-value syntax for boot configuration files, including array values and the use of delimiters. ```plaintext KEY[.WORD[...]] = VALUE[, VALUE2[...]][;] ``` -------------------------------- ### IA64 fgettimeofday() Fast System Call Example Source: https://github.com/parrotsec/linux-parrot/blob/master/Documentation/ia64/fsys.rst This assembly code demonstrates how to make a fast system call to get the current time using `fgettimeofday()`. It shows the setup required, including obtaining the gate address and setting up the system call number. ```assembly #include GLOBAL_ENTRY(fgettimeofday) .prologue .save ar.pfs, r11 mov r11 = ar.pfs .body mov r2 = 0xa000000000020660;; // gate address mov b7 = r2 mov r15 = 1087 // gettimeofday syscall ;; br.call.sptk.many b6 = b7 ;; .restore sp mov ar.pfs = r11 br.ret.sptk.many rp;; // return to caller END(fgettimeofday) ``` -------------------------------- ### Start Guest3 with VFIO-AP Source: https://github.com/parrotsec/linux-parrot/blob/master/Documentation/s390/vfio-ap.rst Initiate Guest3 using QEMU with specific CPU flags and the vfio-ap device configured. ```bash /usr/bin/qemu-system-s390x ... -cpu host,ap=on,apqci=on,apft=on,apqi=on \ -device vfio-ap,sysfsdev=/sys/devices/vfio_ap/matrix/$uuid3 ... ``` -------------------------------- ### AoE Udev Install Rules Script Example Source: https://github.com/parrotsec/linux-parrot/blob/master/Documentation/admin-guide/aoe/examples.rst This is an example of a shell script used to install udev rules for AoE devices. It typically involves copying rule files to the appropriate system directory. ```shell #!/bin/bash # Example script to install AoE udev rules # Define the source and destination for the udev rules file UDRULE_SRC="/path/to/your/aoe.rules" UDRULE_DEST="/etc/udev/rules.d/aoe.rules" # Copy the udev rules file cp "$UDRULE_SRC" "$UDRULE_DEST" # Reload udev rules udevadm control --reload-rules udevadm trigger echo "AoE udev rules installed successfully." ``` -------------------------------- ### Start Guest1 with VFIO-AP Source: https://github.com/parrotsec/linux-parrot/blob/master/Documentation/s390/vfio-ap.rst Initiate Guest1 using QEMU with specific CPU flags and the vfio-ap device configured. ```bash /usr/bin/qemu-system-s390x ... -cpu host,ap=on,apqci=on,apft=on,apqi=on \ -device vfio-ap,sysfsdev=/sys/devices/vfio_ap/matrix/$uuid1 ... ``` -------------------------------- ### TI Divider Clock Example Source: https://github.com/parrotsec/linux-parrot/blob/master/Documentation/devicetree/bindings/clock/ti/divider.txt Example of a TI divider clock node with a maximum divisor and index starting at one. ```dts dpll_usb_m2_ck: dpll_usb_m2_ck@4a008190 { #clock-cells = <0>; compatible = "ti,divider-clock"; clocks = <&dpll_usb_ck>; ti,max-div = <127>; reg = <0x190>; ti,index-starts-at-one; }; ``` -------------------------------- ### Start Guest2 with VFIO-AP Source: https://github.com/parrotsec/linux-parrot/blob/master/Documentation/s390/vfio-ap.rst Initiate Guest2 using QEMU with specific CPU flags and the vfio-ap device configured. ```bash /usr/bin/qemu-system-s390x ... -cpu host,ap=on,apqci=on,apft=on,apqi=on \ -device vfio-ap,sysfsdev=/sys/devices/vfio_ap/matrix/$uuid2 ... ``` -------------------------------- ### Basic Kernel Compilation Source: https://github.com/parrotsec/linux-parrot/blob/master/Documentation/admin-guide/README.rst Run 'make' to create a compressed kernel image. 'make install' can be used if lilo is installed, but check your lilo setup first. Root privileges are required for installation, not for building. ```bash make ``` ```bash make install ``` -------------------------------- ### Get Interface Index and Bind Socket Source: https://github.com/parrotsec/linux-parrot/blob/master/Documentation/networking/can.rst Example of how to get the interface index for a CAN device (e.g., 'can0') using ioctl and then bind a raw CAN socket to it. ```C int s; struct sockaddr_can addr; struct ifreq ifr; s = socket(PF_CAN, SOCK_RAW, CAN_RAW); strcpy(ifr.ifr_name, "can0" ); ioctl(s, SIOCGIFINDEX, &ifr); addr.can_family = AF_CAN; addr.can_ifindex = ifr.ifr_ifindex; bind(s, (struct sockaddr *)&addr, sizeof(addr)); (..) ``` -------------------------------- ### Typical Firmware Workflow Example Source: https://github.com/parrotsec/linux-parrot/blob/master/Documentation/driver-api/firmware/request_firmware.rst This example shows the typical workflow for requesting, copying, and releasing firmware. Ensure firmware is released after use to free resources. ```c if(request_firmware(&fw_entry, $FIRMWARE, device) == 0) copy_fw_to_device(fw_entry->data, fw_entry->size); release_firmware(fw_entry); ``` -------------------------------- ### Example DMA Mask Setup Source: https://github.com/parrotsec/linux-parrot/blob/master/Documentation/core-api/dma-api-howto.rst This example demonstrates how to set the DMA mask for a 64-bit capable device. If the mask cannot be set, a warning is printed, and the device is ignored. ```c if (dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64))) { dev_warn(dev, "mydev: No suitable DMA available\n"); goto ignore_this_device; } ``` -------------------------------- ### V4L2 Capture Example Source: https://github.com/parrotsec/linux-parrot/blob/master/Documentation/userspace-api/media/v4l/capture.c.rst A basic example demonstrating V4L2 capture operations. This snippet shows how to initialize a device, set the format, request buffers, and start streaming. ```c #include #include #include #include #include #include #include #include #include #define CLEAR(x) memset(&(x), 0, sizeof(x)) static int xioctl(int fd, unsigned int request, void *arg) { int r; do { r = ioctl(fd, request, arg); } while (r == -1 && errno == EINTR); return r; } int main(int argc, char **argv) { struct v4l2_capability cap; struct v4l2_cropcap cropcap; struct v4l2_crop crop; struct v4l2_format fmt; struct v4l2_buffer buf; struct v4l2_requestbuffers req; struct v4l2_fbuffer fbuf; unsigned int i; int fd = -1; const char *dev_name = argc > 1 ? argv[1] : "/dev/video0"; fd = open(dev_name, O_RDWR | O_NONBLOCK, 0); if (fd < 0) { perror("Cannot open device"); return -1; } /* VIDIOC_QUERYCAP */ if (xioctl(fd, VIDIOC_QUERYCAP, &cap) < 0) { if (errno == ENODATA) { fprintf(stderr, "%s is not a video capture device\n", dev_name); } return -1; } if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)) { fprintf(stderr, "%s is not a video capture device\n", dev_name); return -1; } /* Check if the device supports streaming I/O */ if (!(cap.capabilities & V4L2_CAP_STREAMING)) { fprintf(stderr, "%s does not support streaming I/O\n", dev_name); return -1; } /* Errors assumed to be fatal */ CLEAR(cropcap); cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; if (xioctl(fd, VIDIOC_CROPCAP, &cropcap) == 0) { crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; crop.c = cropcap.def; if (xioctl(fd, VIDIOC_S_CROP, &crop) < 0) { /* Errors ignored */ } } CLEAR(fmt); fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; fmt.fmt.pix.width = 640; fmt.fmt.pix.height = 480; fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV; fmt.fmt.pix.field = V4L2_FIELD_INTERLACED; if (xioctl(fd, VIDIOC_S_FMT, &fmt) < 0) { return -1; } /* Request buffers */ CLEAR(req); req.count = 2; req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; req.memory = V4L2_MEMORY_MMAP; if (xioctl(fd, VIDIOC_REQBUFS, &req) < 0) { return -1; } /* Buffer information */ for (i = 0; i < req.count; ++i) { CLEAR(buf); buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; buf.memory = V4L2_MEMORY_MMAP; buf.index = i; if (xioctl(fd, VIDIOC_QUERYBUF, &buf) < 0) { return -1; } /* Map buffers */ fbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; fbuf.memory = V4L2_MEMORY_MMAP; fbuf.index = i; if (xioctl(fd, VIDIOC_MMAP, &fbuf) < 0) { return -1; } } /* Start streaming */ for (i = 0; i < req.count; ++i) { CLEAR(buf); buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; buf.memory = V4L2_MEMORY_MMAP; buf.index = i; if (xioctl(fd, VIDIOC_QBUF, &buf) < 0) { return -1; } } enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE; if (xioctl(fd, VIDIOC_STREAMON, &type) < 0) { return -1; } /* Capture loop would go here */ /* Stop streaming */ if (xioctl(fd, VIDIOC_STREAMOFF, &type) < 0) { return -1; } close(fd); return 0; ``` -------------------------------- ### AoE Status Script Example Source: https://github.com/parrotsec/linux-parrot/blob/master/Documentation/admin-guide/aoe/examples.rst This shell script provides an example of how to get the status of AoE devices. It might query system information or specific AoE tools. ```shell #!/bin/bash # Example script to get AoE device status # List all AoE devices echo "Listing AoE devices:" aoe-stat # Check status of a specific device (e.g., e0d0) echo "Checking status for e0d0:" aoe-stat e0d0 # You can add more checks here, like checking network interfaces or disk partitions ``` -------------------------------- ### Starting a UML Instance Source: https://github.com/parrotsec/linux-parrot/blob/master/Documentation/virt/uml/user_mode_linux_howto_v2.rst Run a UML instance with specified RAM, root filesystem image, tap networking, and console configurations. Console 1 is set to use standard input/output. ```bash # linux mem=2048M umid=TEST \ ubd0=Filesystem.img \ vec0:transport=tap,ifname=tap0,depth=128,gro=1 \ root=/dev/ubda con=null con0=null,fd:2 con1=fd:0,fd:1 ``` -------------------------------- ### Create Platform Setup File Source: https://github.com/parrotsec/linux-parrot/blob/master/Documentation/powerpc/booting.rst Create your main platform file as "arch/powerpc/platforms/myplatform/myboard_setup.c" and add it to the Makefile under the condition of your ``CONFIG_`` option. This file will define a structure of type "ppc_md" containing the various callbacks that the generic code will use to get to your platform specific code. ```c arch/powerpc/platforms/myplatform/myboard_setup.c ``` -------------------------------- ### SYM53c8xx NVRAM Header Example Source: https://github.com/parrotsec/linux-parrot/blob/master/Documentation/scsi/sym53c8xx_2.rst Example of the NVRAM header bytes. The first two bytes are a start marker, followed by the byte count (excluding header and trailer), and then the checksum. ```text 00 00 - ?? start marker 64 01 - byte count (lsb/msb excludes header/trailer) 8e 0b - checksum (lsb/msb excludes header/trailer) ``` -------------------------------- ### LOADLIN Boot Command Example Source: https://github.com/parrotsec/linux-parrot/blob/master/Documentation/admin-guide/initrd.rst Example of how to specify the initrd image when using LOADLIN to boot the kernel. ```bash LOADLIN C:\LINUX\BZIMAGE initrd=C:\LINUX\INITRD.GZ root=/dev/ram0 rw ``` -------------------------------- ### GPIO IRQ Chip Setup Example Source: https://github.com/parrotsec/linux-parrot/blob/master/Documentation/driver-api/gpio/driver.rst Typical example of setting up a chained cascaded interrupt handler using gpio_irq_chip. Demonstrates how mask/unmask functions interact with core gpiolib. ```c /* Typical state container */ struct my_gpio { struct gpio_chip gc; }; ``` -------------------------------- ### Maxim MAX310x Device Tree Configuration Example Source: https://github.com/parrotsec/linux-parrot/blob/master/Documentation/devicetree/bindings/serial/maxim,max310x.txt This example demonstrates the device tree configuration for a Maxim MAX14830 UART, including clocking, interrupt, and GPIO controller setup. ```devicetree / { clocks { spi_uart_clk: osc_max14830 { compatible = "fixed-clock"; #clock-cells = <0>; clock-frequency = <3686400>; }; }; }; &spi0 { max14830: max14830@0 { compatible = "maxim,max14830"; reg = <0>; clocks = <&spi_uart_clk>; clock-names = "osc"; interrupt-parent = <&gpio3>; interrupts = <7 IRQ_TYPE_LEVEL_LOW>; gpio-controller; #gpio-cells = <2>; }; }; ``` -------------------------------- ### Setup, Use, and Teardown Dynamically Allocated Multi-Instance State Source: https://github.com/parrotsec/linux-parrot/blob/master/Documentation/core-api/cpu_hotplug.rst This example shows the setup, instance addition, and teardown of a dynamically allocated multi-instance state in the ONLINE section for both online and offline operations. Ensure to check the return values of state addition functions and handle potential errors during instance removal. ```c state = cpuhp_setup_state_multi(CPUHP_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); .... ``` -------------------------------- ### Boot Config Brace Syntax Example Source: https://github.com/parrotsec/linux-parrot/blob/master/Documentation/admin-guide/bootconfig.rst Shows how to use braces for grouping and shortening boot configuration entries with nested keys. ```plaintext foo.bar { baz = value1 qux.quux = value2 } ``` ```plaintext foo.bar { baz = value1; qux.quux = value2 } ``` -------------------------------- ### UAC1 Gadget Audio Stream Example Source: https://github.com/parrotsec/linux-parrot/blob/master/Documentation/usb/gadget-testing.rst Example command to stream audio data between the device and host using the UAC1 gadget. This requires a specific hardware setup for audible output. ```bash $ arecord -f dat -t wav -D hw:2,0 | aplay -D hw:0,0 & ``` ```bash $ arecord -f dat -t wav -D hw:CARD=UAC1Gadget,DEV=0 | \ aplay -D default:CARD=OdroidU3 ``` -------------------------------- ### Example Project Structure and Build Files Source: https://github.com/parrotsec/linux-parrot/blob/master/tools/build/Documentation/Build.txt This illustrates a project structure and the corresponding 'Build' files required to define objects and libraries. The framework compiles objects, which can then be used to create binaries. ```makefile ex/Build: ex-y += a.o ex-y += b.o ex-y += b.o # duplicates in the lists are allowed libex-y += c.o libex-y += d.o libex-y += arch/ ex/arch/Build: libex-y += e.o libex-y += f.o ``` -------------------------------- ### ALSA PCM Trigger Callback Example Source: https://github.com/parrotsec/linux-parrot/blob/master/Documentation/sound/kernel-api/writing-an-alsa-driver.rst Handles PCM stream start, stop, and pause operations. Must define START and STOP commands. Optionally handles PAUSE_PUSH/RELEASE and SUSPEND/RESUME. ```c static int snd_xxx_trigger(struct snd_pcm_substream *substream, int cmd); This is called when the pcm is started, stopped or paused. Which action is specified in the second argument, ``SNDRV_PCM_TRIGGER_XXX`` in ````. At least, the ``START`` and ``STOP`` commands must be defined in this callback. :: switch (cmd) { case SNDRV_PCM_TRIGGER_START: /* do something to start the PCM engine */ break; case SNDRV_PCM_TRIGGER_STOP: /* do something to stop the PCM engine */ break; default: return -EINVAL; } When the pcm supports the pause operation (given in the info field of the hardware table), the ``PAUSE_PUSH`` and ``PAUSE_RELEASE`` commands must be handled here, too. The former is the command to pause the pcm, and the latter to restart the pcm again. When the pcm supports the suspend/resume operation, regardless of full or partial suspend/resume support, the ``SUSPEND`` and ``RESUME`` commands must be handled, too. These commands are issued when the power-management status is changed. Obviously, the ``SUSPEND`` and ``RESUME`` commands suspend and resume the pcm substream, and usually, they are identical to the ``STOP`` and ``START`` commands, respectively. See the `Power Management`_ section for details. As mentioned, this callback is atomic as default unless ``nonatomic`` flag set, and you cannot call functions which may sleep. The ``trigger`` callback should be as minimal as possible, just really triggering the DMA. The other stuff should be initialized ``hw_params`` and ``prepare`` callbacks properly beforehand. ``` -------------------------------- ### Get Pin Control and Request GPIO Source: https://github.com/parrotsec/linux-parrot/blob/master/Documentation/driver-api/pin-control.rst Example of requesting a pin state and a GPIO. It is recommended to get the pinctrl handle and select the state BEFORE requesting the GPIO to avoid electrical issues. ```c #include #include struct pinctrl *pinctrl; int gpio; pinctrl = devm_pinctrl_get_select_default(&dev); gpio = devm_gpio_request(&dev, 14, "foo"); ``` -------------------------------- ### Kernel Boot Parameter Example Source: https://github.com/parrotsec/linux-parrot/blob/master/Documentation/fb/intelfb.rst Use this format in /etc/lilo.conf to initialize the framebuffer with specific settings. Ensure options are comma-separated and values are assigned with an equals sign. ```bash append="video=intelfb:mode=800x600-32@75,accel,hwcursor,vram=8" ``` -------------------------------- ### DVBv5 Zap Background Recording Example Source: https://github.com/parrotsec/linux-parrot/blob/master/Documentation/driver-api/media/drivers/vidtv.rst This command starts dvbv5-zap in the background to record from a channel. ```bash $ dvbv5-zap -c dvb_channel.conf "beethoven" -P -r & ``` -------------------------------- ### Sample Mode Example Source: https://github.com/parrotsec/linux-parrot/blob/master/tools/perf/Documentation/perf-intel-pt.txt Example of using Intel PT in sample mode, attached to other events like branch misses. ```bash perf record --aux-sample -e intel_pt//u -e branch-misses:u ``` -------------------------------- ### Set up Android Source Tree Environment Source: https://github.com/parrotsec/linux-parrot/blob/master/tools/perf/Documentation/android.txt Source the build environment and lunch the target configuration from the Android source tree. ```bash source build/envsetup.sh lunch ``` -------------------------------- ### KGDBoc Configuration Scenarios Source: https://github.com/parrotsec/linux-parrot/blob/master/Documentation/dev-tools/kgdb.rst Examples demonstrating various kgdboc configurations for different debugging setups. ```text kgdboc=[,baud] ``` ```text kgdboc=ttyS0,115200 ``` ```text kgdboc=kbd,[,baud] ``` ```text kgdboc=kbd,ttyS0,115200 ``` ```text kgdboc=kbd ``` ```text kgdboc=kms,kbd ``` ```text kgdboc=kms,kbd,ttyS0,115200 ``` -------------------------------- ### Find Function Name and Address - C Source: https://github.com/parrotsec/linux-parrot/blob/master/tools/lib/traceevent/Documentation/libtraceevent-func_find.txt Use tep_find_function to get the function name and tep_find_function_address to get its starting address for a given memory address. Ensure tep_handle is allocated and initialized before use. ```c #include ... struct tep_handle *tep = tep_alloc(); ... void show_function( unsigned long long addr) { const char *fname = tep_find_function(tep, addr); unsigned long long fstart = tep_find_function_address(tep, addr); /* addr is in function named fname, starting at fstart address, at offset (addr - fstart) */ } ... ``` -------------------------------- ### Multiple Device-Mapper Initialization Example Source: https://github.com/parrotsec/linux-parrot/blob/master/Documentation/admin-guide/device-mapper/dm-init.rst Demonstrates the initialization of multiple device-mappers, including a dm-linear and a dm-verity device. The example is split across lines for readability. ```bash dm-linear,,1,rw, 0 32768 linear 8:1 0, 32768 1024000 linear 8:2 0; dm-verity,,3,ro, 0 1638400 verity 1 /dev/sdc1 /dev/sdc2 4096 4096 204800 1 sha256 ac87db56303c9c1da433d7209b5a6ef3e4779df141200cbd7c157dcb8dd89c42 5ebfe87f7df3235b80a117ebc4078e44f55045487ad4a96581d1adb564615b51 ``` -------------------------------- ### Quick Install Commands Source: https://github.com/parrotsec/linux-parrot/blob/master/Documentation/networking/device_drivers/ethernet/dlink/dl2k.rst Steps for a quick installation of the dl2k driver, including loading the module and bringing the interface up. ```bash 1. make all 2. insmod dl2k.ko 3. ifconfig eth0 up 10.xxx.xxx.xxx netmask 255.0.0.0 ^^^^^^^^^^^^^^^ ^^^^^^^^ IP NETMASK 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. ``` -------------------------------- ### Get Error String using tep_strerror Source: https://github.com/parrotsec/linux-parrot/blob/master/tools/lib/traceevent/Documentation/libtraceevent-strerror.txt This example demonstrates how to use tep_strerror to get a human-readable error message for a specific tep error code. Ensure the tep_handle is allocated and initialized before calling. ```c #include ... struct tep_handle *tep = tep_alloc(); ... char buf[32]; char *pool = calloc(1, 128); if (tep == NULL) { tep_strerror(tep, TEP_ERRNO__MEM_ALLOC_FAILED, buf, 32); printf ("The pool is not initialized, %s", buf); } ... ``` -------------------------------- ### Boot Config Mixed Value and Subkey Example Source: https://github.com/parrotsec/linux-parrot/blob/master/Documentation/admin-guide/bootconfig.rst Demonstrates how a raw value and subkeys can coexist under a parent key, and how the order affects parsing. ```plaintext foo = value1 foo.bar = value2 foo := value3 ``` ```plaintext foo { bar = value1 bar { baz = value2 qux = value3 } } ``` ```plaintext foo.bar = value1 foo = value2 ``` -------------------------------- ### Bring Interface Up and Configure Source: https://github.com/parrotsec/linux-parrot/blob/master/Documentation/networking/device_drivers/ethernet/dlink/dl2k.rst Commands to bring the network interface up and bind it to the protocol stack. ```bash ifconfig eth0 up ``` ```bash ifup eth0 ```