(Buildroot) 모듈을 자동으로 로드하는 방법

(Buildroot) 모듈을 자동으로 로드하는 방법

시작 시 추가 모듈을 로드하고 싶습니다.

이것은 명령줄에서 잘 작동합니다.

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

하지만 시작할 때 이 작업을 수행하고 싶습니다. 모듈 이름을 사용하여 /etc/modules, /etc/modprobe.conf, /etc/modprobe.d/i2c-dev.conf 등을 생성하려고 시도했지만 성공하지 못했습니다.

저는 kmod와 BusyBox init를 사용하는 buildroot-2017-08을 사용하고 있습니다.

init.d 스크립트를 생성할 수도 있지만 로드할 모듈 목록을 포함해야 하는 특정 위치가 있다고 생각합니다.

답변1

이는 사용하는 초기화 시스템에 따라 다릅니다. Busybox init 또는 SysV init를 사용하도록 Buildroot를 구성한 경우 이 문제를 처리하는 올바른 방법은 init 스크립트를 통하는 것일 수 있습니다. Systemd를 사용하도록 구성하는 경우 .conf확장명이 있는 파일을 넣거나 /etc/modules-load.d/로드 /usr/lib/modules-load.d/하려는 각 모듈과 함께 별도의 줄에 나열하면 systemd가 시작 시 해당 파일을 로드합니다.

답변2

아름답고 기성품으로 만들어진 스크립트는 많지 않습니다. LFS(Linux From Scratch)에는 보기에도 좋고 사용하기 쉬운 일부 스크립트가 있는 것으로 나타났습니다.

일반 BusyBox 초기화용 모듈을 로드하는 솔루션은 다음과 같습니다.

/etc/init.d/S02모듈

#!/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

이 LFS 스크립트를 기반으로 합니다. http://www.linuxfromscratch.org/lfs/view/6.5/scripts/apds05.html

/etc/sysconfig/함수

#!/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
}

이 LFS 스크립트를 기반으로 합니다. http://www.linuxfromscratch.org/lfs/view/6.5/scripts/apds02.html

/etc/sysconfig/모듈

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

(또는 로드하려는 모듈이 무엇이든 상관없습니다.)

BusyBox init에서 이러한 방식으로 모듈을 로드하는 데 문제가 있는 경우 아래 주석으로 끝날 것이라고 확신합니다 ;-).

답변3

@svenema의 답변은 훌륭합니다! S02modules이 작업을 수행하려면 권한을 변경하고 파일을 실행 가능하게 만들어야 한다고 덧붙이고 싶습니다 .

chmod u+x /etc/init.d/S02modules

관련 정보