Skip to content

feat(install): build for a named target kernel, not always the running one - #22

Closed
youngrok-XCENA wants to merge 1 commit into
mainfrom
youngrok/feat/target-kernel-contract
Closed

feat(install): build for a named target kernel, not always the running one#22
youngrok-XCENA wants to merge 1 commit into
mainfrom
youngrok/feat/target-kernel-contract

Conversation

@youngrok-XCENA

@youngrok-XCENA youngrok-XCENA commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

🤔 배경 및 동기 (Why)

dkms buildmake 는 러닝 커널을 타겟으로 잡습니다. 설치기가 설치 대상 머신 위에서 돌 때는 그게 정답입니다 — 실 HW 와 부팅된 게스트가 그 경우입니다.

에뮬레이터 게스트 이미지를 조립할 때는 아닙니다. 그때 러닝 커널은 이미지를 굽는 머신의 것이고, 그 커널로 빌드한 모듈은 이미지가 부팅해도 로드되지 않습니다. 지금까지 이 자리는 에뮬레이터가 자체 크로스빌드로 메워 왔고, 그래서 같은 모듈의 설치 방법이 두 곳에 존재합니다.

🏗️ 설계 변경점

설치할 커널을 밖에서 지정할 수 있게 합니다. 지정하지 않으면 러닝 커널이므로 기존 사용자 경로의 동작은 바뀌지 않습니다.

입력이 두 개인 이유는 커널 모듈 설치에 필요한 것이 두 가지이고 쓰이는 자리가 다르기 때문입니다.

필요한 것 쓰는 곳
커널 버전 DKMS 등록·설치, 설치 경로, depmod, initramfs
커널 빌드 트리 컴파일

표준 배치에서는 버전이 트리를 함의하므로(/lib/modules/<버전>/build, DKMS 자신의 기본값이자 배포판 헤더 패키지가 만드는 경로) 하나만 주면 나머지가 채워집니다.

flowchart LR
  V["커널 버전"] -->|"트리 = /lib/modules/&lt;버전&gt;/build"| R["해석된 (버전, 트리)"]
  D["커널 빌드 트리"] -->|"버전 = 트리의 kernelrelease"| R
  N["둘 다 없음"] -->|"버전 = 러닝 커널"| R
Loading

해석된 트리가 없으면 그 자리에서 실패합니다. "러닝 커널 헤더가 없으면 이 루트의 다른 빌드 트리를 쓴다" 같은 대체 탐색은 두지 않았습니다 — 커널 업그레이드 후 재부팅 전이거나 옛 헤더가 남은 상황에서 조용히 다른 커널로 빌드하게 되는데, 그것이 이 변경이 막으려는 문제 그 자체입니다.

📝 상세 구현 내용

  • XCENA_TARGET_KVER — 커널 버전. dkms build/install -k, depmod, update-initramfs -k 가 이 값을 씁니다.
  • XCENA_TARGET_KDIR — 커널 빌드 트리. BUILDSYSTEM_DIR 로 전달하고, 표준 경로 밖이면 DKMS 에 --kernelsourcedir 로 함께 넘깁니다. 표준 경로일 때는 인자를 붙이지 않아 기존 호출과 동일합니다.
  • 빌드 트리가 없으면 linux-headers-<버전> 설치와 XCENA_TARGET_KDIR 지정 두 가지를 안내하며 종료합니다.

같은 구역의 문제 두 개를 함께 고쳤습니다.

  • 소스를 /usr/src 로 복사하기 전에 도는 make clean 이 기본 빌드 트리를 썼습니다. 다른 커널을 대상으로 설치하면 그 clean 이 조용히 실패해 mx_dma.mod.c 같은 빌드 잔여물이 DKMS 소스로 복사됩니다. 해석된 트리를 쓰도록 했습니다.
  • udevadm control --reload-rules 를 best-effort 로 바꿨습니다. 이미지 조립 중에는 udevd 가 없고, reload 대상인 룰 파일은 그 시점에 이미 제거돼 있습니다.

✅ 테스트

  • 수동 테스트
  • 단위 테스트
  • 테스트 불필요 (사유: )

turin-gb1 에서 확인했습니다.

경우 결과
입력 없이 (부팅된 게스트 = 실 HW 와 같은 조건) CXL 자동판정, 러닝 커널 타겟, DKMS 설치까지 기존과 동일
이미지 조립 (커널 버전 지정) 게스트 커널로 DKMS 설치, 설치된 모듈 vermagic 이 게스트 커널과 일치, 부팅 후 자동 로드·디바이스 인식
빌드 트리 지정 트리의 kernelrelease 에서 버전 유도
없는 트리 지정 해당 메시지로 실패
헤더 없는 버전 지정 두 해결책을 안내하며 실패

🔗 관련 이슈(선택)

🌿 관련 PR(선택)

  • sdk_release: PR-2046
  • ccma: PR-25
  • cxl_emulator: PR-1708

🌿 관련 Branch(선택)

📦 Release Note (자동 생성용 / 영문 작성)

NEW

CHANGED

FIXED

IMPORTANT NOTES

…g one

dkms and make default to `uname -r`. That is the kernel the module will run on
when install.sh runs on the target machine, and the builder's kernel when it
installs into an image being assembled, where the module built that way cannot
load.

Take the target as input: XCENA_TARGET_KVER names the kernel version (DKMS
registration, install path, depmod, initramfs) and XCENA_TARGET_KDIR names the
build tree. Either one is enough -- the version resolves to
/lib/modules/<version>/build, the path DKMS and the distro header packages use,
and the tree resolves to its own kernelrelease. With neither, the running kernel
is used exactly as before. A tree outside the default path is passed on to DKMS
via --kernelsourcedir. A missing tree fails with both remedies named.

Two fixes in the same area:

- The clean that runs before staging the source into /usr/src used the default
  build tree. Installing for another kernel made it fail silently, so build
  artifacts such as mx_dma.mod.c were copied into the DKMS source.
- `udevadm control --reload-rules` is now best-effort. udevd is not running while
  an image is being assembled, and the rule file it would reload is already in
  place there.
@youngrok-XCENA

Copy link
Copy Markdown
Contributor Author

개발 PR 은 xcena-dev/mxdriver_dev 로 갑니다. 이 repo 는 Sync: 커밋만 들어오는 미러라 리뷰 자리가 아닙니다.

같은 변경을 xcena-dev/mxdriver_dev#85 로 다시 올렸습니다.

브랜치 youngrok/feat/target-kernel-contract 는 여기 남겨 둡니다. sdk_release 의 driver 서브모듈 origin 이 이 repo 라서, sdk_release PR-2046 의 CI 가 의존 형상을 합성할 때 이 브랜치를 checkout 합니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants