# Linux Kernel Module Cheat
The perfect emulation setup to study and develop the <<linux-kernel>> v5.9.2, kernel modules, <<qemu-buildroot-setup,QEMU>>, <<gem5-buildroot-setup,gem5>> and x86_64, ARMv7 and ARMv8 <<userland-assembly,userland>> and <<baremetal-setup,baremetal>> assembly, <<c,ANSI C>>, <<cpp,C++>> and <<posix,POSIX>>. <<gdb>> and <<kgdb>> just work. Powered by <<about-the-qemu-buildroot-setup,Buildroot>> and <<about-the-baremetal-setup,crosstool-NG>>. Highly automated. Thoroughly documented. Automated <<test-this-repo,tests>>.

#### 23.6.3. LEDs

TODO: broken when `arm` moved to `-M virt`, same as GPIO.

Hack QEMU’s `hw/misc/arm_sysctl.c` with a printf:

    static void arm_sysctl_write(void *opaque, hwaddr offset,
                                uint64_t val, unsigned size)
    {
        arm_sysctl_state *s = (arm_sysctl_state *)opaque;

        switch (offset) {
        case 0x08: /* LED */
            printf("LED val = %llx\n", (unsigned long long)val);

and then rebuild with:

    ./build-qemu --arch arm
    ./build-linux --arch arm --config-fragment linux_config/leds

But beware that one of the LEDs has a heartbeat trigger by default (specified on dts), so it will produce a lot of output.

And then activate it with:

    cd /sys/class/leds/versatile:0
    cat max_brightness
    echo 255 >brightness

Relevant QEMU files:

- `hw/arm/versatilepb.c`

- `hw/misc/arm_sysctl.c`

Relevant kernel files:

- `arch/arm/boot/dts/versatile-pb.dts`

- `drivers/leds/led-class.c`

- `drivers/leds/leds-sysctl.c`