SW 개발

[Linux_kernel] 크로스 컴파일 환경에서 modules_install 경로 설정

. . . 2021. 5. 13. 09:18
반응형

호스트환경에서의 module install path 설정

커널빌드시 Makefile 은 target 에 modules 을 설치하는 modules_install 이라는 명령어가 존재한다.

해당명령어는 기본적으로 modules는 /lib/modules 디렉토리에 설치하게 된다. 만약, 호스트 환경에서 커널컴파일이나 모듈을 따로빌드 하게되면 호스트의 /lib/modules 에 설치하게되는데 호스트의 시스템에 영향을 주게된다.

크로스 컴파일환경에서는 make modules_install 할때 약간의 옵션을 줘서 우리가 원하는 디렉토리에 modules 파일들을 떨궈야 한다.

INSTALL_MOD_PATH 옵션 사용

make 할때 INSTALL_MOD_PATH 인자를 주면된다.

$ make ARCH=arm CROSS_COMPILE=arm-linux- INSTALL_MOD_PATH=${PRJROOT}/images/modules-2.6.20 modules_install

modules_install 명령어 사용시 modules.dep 파일도 생성이 되어 정상적으로 타겟보드에서 modprobe 명령도 쓸수있게 된다.

관련 레퍼런스

--- 2.3 Targets

  When building an external module, only a subset of the "make"
  targets are available.

  make -C $KDIR M=$PWD [target]

  The default will build the module(s) located in the current
  directory, so a target does not need to be specified. All
  output files will also be generated in this directory. No
  attempts are made to update the kernel source, and it is a
  precondition that a successful "make" has been executed for the
  kernel.

  modules
    The default target for external modules. It has the
    same functionality as if no target was specified. See
    description above.

  modules_install
    Install the external module(s). The default location is
    /lib/modules/<kernel_release>/extra/, but a prefix may
    be added with INSTALL_MOD_PATH (discussed in section 5).

  clean
    Remove all generated files in the module directory only.

  help
    List the available targets for external modules.

--- 5.1 INSTALL_MOD_PATH

  Above are the default directories but as always some level of
  customization is possible. A prefix can be added to the
  installation path using the variable INSTALL_MOD_PATH:

    $ make INSTALL_MOD_PATH=/frodo modules_install
    => Install dir: /frodo/lib/modules/$(KERNELRELEASE)/kernel/

  INSTALL_MOD_PATH may be set as an ordinary shell variable or,
  as shown above, can be specified on the command line when
  calling "make." This has effect when installing both in-tree
  and out-of-tree modules.

--- 5.2 INSTALL_MOD_DIR

  External modules are by default installed to a directory under
  /lib/modules/$(KERNELRELEASE)/extra/, but you may wish to
  locate modules for a specific functionality in a separate
  directory. For this purpose, use INSTALL_MOD_DIR to specify an
  alternative name to "extra."

    $ make INSTALL_MOD_DIR=gandalf -C $KDIR \
           M=$PWD modules_install
    => Install dir: /lib/modules/$(KERNELRELEASE)/gandalf/

반응형