Esempio n. 1
0
def enable_spi():
    # FIXME: instead of rebooting, add a reboot_required property to
    # Changed/Unchanged and allow chaining these.
    #
    # e.g.
    #
    # c = some_operation()
    # c = c.chain(another_operation, msg=....)
    #
    # return c
    #
    # at any point in time, c.reboot_required can be resolved, either
    # in a plan/operation or by the driver ("reboot_if_needed()")

    # FIXME: check for /etc/modprobe.d/raspi-blacklist.conf
    #        mentioned at https://www.raspberrypi.org/documentation/
    #                             hardware/raspberrypi/spi/README.md

    with fs.edit('/boot/config.txt', create=False) as boot:
        boot.insert_line('dtparam=spi=on')
        boot.insert_line('dtoverlay=spi-bcm2835-overlay')

    if boot.changed:
        linux.enable_module('spi_bcm2835', load=False)
        return Changed('Enabled SPI, need to reboot now')

    if linux.enable_module('spi_bcm2835').changed:
        return Changed('SPI kernel module enabled')

    return Unchanged('SPI already enabled')
Esempio n. 2
0
def enable_hwrng():
    c = linux.enable_module('bcm2708_rng').changed
    c |= apt.install_packages(['rng-tools']).changed
    c |= systemd.enable_unit('rng-tools.service').changed
    c |= systemd.start_unit('rng-tools.service').changed

    return c