(Buildroot) Como carregar módulos automaticamente

0

Gostaria de carregar alguns módulos adicionais na inicialização.

Isso funciona bem na linha de comando:

modprobe -a i2c-dev
modprobe -a snd-soc-pcm512x
modprobe -a snd-soc-wm8804

Mas quero que isso seja feito na inicialização. Eu tentei criar / etc / modules, /etc/modprobe.conf e /etc/modprobe.d/i2c-dev.conf, etc. com o nome do módulo lá, mas sem sorte.

Estou usando um buildroot-2017-08, que acredito que usa o kmod, com um init do BusyBox.

Eu posso criar um script init.d, mas acho que há um local específico que deve conter a lista de módulos para carregar.

    
por svenema 06.10.2017 / 18:39

2 respostas

0

Não foi possível encontrar muitos scripts prontos e polidos. Acontece que o Linux From Scratch (LFS) tinha alguns scripts que parecem bons e fáceis de usar.

Minha solução para carregar módulos para um init simples do BusyBox:

/etc/init.d/S02modules

#!/bin/sh
########################################################################
#
# Description : Module auto-loading script
#
# Authors     : Zack Winkles
#
# Version     : 00.00
#
# Notes       :
#
########################################################################

. /etc/sysconfig/functions

# Assure that the kernel has module support.
[ -e /proc/ksyms -o -e /proc/modules ] || exit 0

case "${1}" in
    start)

        # Exit if there's no modules file or there are no
        # valid entries
        [ -r /etc/sysconfig/modules ] &&
            egrep -qv '^($|#)' /etc/sysconfig/modules ||
            exit 0

        boot_mesg -n "Loading modules:" ${INFO}

        # Only try to load modules if the user has actually given us
        # some modules to load.
        while read module args; do

            # Ignore comments and blank lines.
            case "$module" in
                ""|"#"*) continue ;;
            esac

            # Attempt to load the module, making
            # sure to pass any arguments provided.
            modprobe ${module} ${args} >/dev/null

            # Print the module name if successful,
            # otherwise take note.
            if [ $? -eq 0 ]; then
                boot_mesg -n " ${module}" ${NORMAL}
            else
                failedmod="${failedmod} ${module}"
            fi
        done < /etc/sysconfig/modules

        boot_mesg "" ${NORMAL}
        # Print a message about successfully loaded
        # modules on the correct line.
        echo_ok

        # Print a failure message with a list of any
        # modules that may have failed to load.
        if [ -n "${failedmod}" ]; then
            boot_mesg "Failed to load modules:${failedmod}" ${FAILURE}
            echo_failure
        fi
        ;;
    *)
        echo "Usage: ${0} {start}"
        exit 1
        ;;
esac

Baseado neste script do LFS: link

/ etc / sysconfig / functions

#!/bin/sh
#######################################################################
#
# Description : Run Level Control Functions
#
# Authors     : Gerard Beekmans - [email protected]
#
# Version     : 00.00
#
# Notes       : With code based on Matthias Benkmann's simpleinit-msb
#        http://winterdrache.de/linux/newboot/index.html
#
########################################################################

## Environmental setup
# Setup default values for environment
umask 022
export PATH="/bin:/usr/bin:/sbin:/usr/sbin"

# Signal sent to running processes to refresh their configuration
RELOADSIG="HUP"

# Number of seconds between STOPSIG and FALLBACK when stopping processes
KILLDELAY="3"

## Screen Dimensions
# Find current screen size
if [ -z "${COLUMNS}" ]; then
    COLUMNS=$(stty size)
    COLUMNS=${COLUMNS##* }
fi

# When using remote connections, such as a serial port, stty size returns 0
if [ "${COLUMNS}" = "0" ]; then
    COLUMNS=80
fi

## Measurements for positioning result messages
COL=$((${COLUMNS} - 8))
WCOL=$((${COL} - 2))

## Provide an echo that supports -e and -n
# If formatting is needed, $ECHO should be used
case "'echo -e -n test'" in
    -[en]*)
        ECHO=/bin/echo
        ;;
    *)
        ECHO=echo
        ;;
esac

## Set Cursor Position Commands, used via $ECHO
SET_COL="\033[${COL}G"      # at the $COL char
SET_WCOL="\033[${WCOL}G"    # at the $WCOL char
CURS_UP="\033[1A\033[0G"   # Up one line, at the 0'th char

## Set color commands, used via $ECHO
# Please consult 'man console_codes for more information
# under the "ECMA-48 Set Graphics Rendition" section
#
# Warning: when switching from a 8bit to a 9bit font,
# the linux console will reinterpret the bold (1;) to
# the top 256 glyphs of the 9bit font.  This does
# not affect framebuffer consoles
NORMAL="\033[0;39m"         # Standard console grey
SUCCESS="\033[1;32m"        # Success is green
WARNING="\033[1;33m"        # Warnings are yellow
FAILURE="\033[1;31m"        # Failures are red
INFO="\033[1;36m"           # Information is light cyan
BRACKET="\033[1;34m"        # Brackets are blue

STRING_LENGTH="0"   # the length of the current message

#*******************************************************************************
# Function - boot_mesg()
#
# Purpose:      Sending information from bootup scripts to the console
#
# Inputs:       $1 is the message
#               $2 is the colorcode for the console
#
# Outputs:      Standard Output
#
# Dependencies: - sed for parsing strings.
#            - grep for counting string length.
#
# Todo:
#*******************************************************************************
boot_mesg()
{
    local ECHOPARM=""

    while true
    do
        case "${1}" in
            -n)
                ECHOPARM=" -n "
                shift 1
                ;;
            -*)
                echo "Unknown Option: ${1}"
                return 1
                ;;
            *)
                break
                ;;
        esac
    done

    ## Figure out the length of what is to be printed to be used
    ## for warning messages.
    STRING_LENGTH=$((${#1} + 1))

    # Print the message to the screen
    ${ECHO} ${ECHOPARM} -e "${2}${1}"

}

boot_mesg_flush()
{
    # Reset STRING_LENGTH for next message
    STRING_LENGTH="0"
}

echo_ok()
{
    ${ECHO} -n -e "${CURS_UP}${SET_COL}${BRACKET}[${SUCCESS}  OK  ${BRACKET}]"
    ${ECHO} -e "${NORMAL}"
        boot_mesg_flush
}

echo_failure()
{
    ${ECHO} -n -e "${CURS_UP}${SET_COL}${BRACKET}[${FAILURE} FAIL ${BRACKET}]"
    ${ECHO} -e "${NORMAL}"
        boot_mesg_flush
}

echo_warning()
{
    ${ECHO} -n -e "${CURS_UP}${SET_COL}${BRACKET}[${WARNING} WARN ${BRACKET}]"
    ${ECHO} -e "${NORMAL}"
        boot_mesg_flush
}

Baseado neste script do LFS: link

/ etc / sysconfig / modules

i2c-dev
snd-soc-pcm512x
snd-soc-wm8804
snd-soc-hifiberry_dac

(ou qualquer módulo que você queira carregar, obviamente)

Se houver algum problema ou problemas com o carregamento de módulos dessa maneira em um init do BusyBox, tenho certeza que eles vão acabar nos comentários abaixo; -).

    
por 06.10.2017 / 22:13
0

Isso depende de qual sistema init você está usando. Se você tiver o Buildroot configurado para usar o Busybox init ou o SysV init, a maneira correta de lidar com isso provavelmente será por meio de um script de inicialização. Se você tiver configurado para usar o Systemd, você pode simplesmente soltar um arquivo com a extensão .conf em /etc/modules-load.d/ ou /usr/lib/modules-load.d/ com cada módulo que você deseja carregar listado em uma linha, e o systemd irá carregá-los na inicialização .

    
por 06.10.2017 / 20:28