# Linux Kernel Module Cheat

#### 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`