← Documents Documentation/i2c/i2c-stub.rst GitHub 원문 ↗

Linux 6.18.37 · I2C

i2c-stub

실제 하드웨어 없이 SMBus 명령과 레지스터 값을 모사해 칩 드라이버를 시험하는 i2c-stub을 설명합니다.

Source pathDocumentation/i2c/i2c-stub.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약·해설

i2c-stub.rst:1-66

i2c-stub은 지정한 주소와 메모리 배열로 여섯 종류 SMBus 명령을 모사하며, i2cset이나 칩 덤프로 값을 준비해 대상 드라이버의 probe와 접근 동작을 커널 로그에서 시험합니다.

문서 개요
항목
SourceDocumentation/i2c/i2c-stub.rst
분량66 source lines
SMBus 명령 종류6
가상 칩 주소최대 10개

원문 분량과 핵심 검토 대상을 요약합니다.

핵심 흐름
stub과 주소 로드가상 레지스터 데이터 준비대상 칩 드라이버 로드커널 로그와 폴링 동작 관찰

문서의 주요 사용 또는 탐색 순서를 압축합니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

원문 전체 펼치기
1 ========
2 i2c-stub
3 ========
4
5 Description
6 ===========
7
8 This module is a very simple fake I2C/SMBus driver. It implements six
9 types of SMBus commands: write quick, (r/w) byte, (r/w) byte data, (r/w)
10 word data, (r/w) I2C block data, and (r/w) SMBus block data.
11
12 You need to provide chip addresses as a module parameter when loading this
13 driver, which will then only react to SMBus commands to these addresses.
14
15 No hardware is needed nor associated with this module. It will accept write
16 quick commands to the specified addresses; it will respond to the other
17 commands (also to the specified addresses) by reading from or writing to
18 arrays in memory. It will also spam the kernel logs for every command it
19 handles.
20
21 A pointer register with auto-increment is implemented for all byte
22 operations. This allows for continuous byte reads like those supported by
23 EEPROMs, among others.
24
25 SMBus block command support is disabled by default, and must be enabled
26 explicitly by setting the respective bits (0x03000000) in the functionality
27 module parameter.
28
29 SMBus block commands must be written to configure an SMBus command for
30 SMBus block operations. Writes can be partial. Block read commands always
31 return the number of bytes selected with the largest write so far.
32
33 The typical use-case is like this:
34
35 1. load this module
36 2. use i2cset (from the i2c-tools project) to pre-load some data
37 3. load the target chip driver module
38 4. observe its behavior in the kernel log
39
40 There's a script named i2c-stub-from-dump in the i2c-tools package which
41 can load register values automatically from a chip dump.
42
43 Parameters
44 ==========
45
46 int chip_addr[10]:
47 The SMBus addresses to emulate chips at.
48
49 unsigned long functionality:
50 Functionality override, to disable some commands. See I2C_FUNC_*
51 constants in <linux/i2c.h> for the suitable values. For example,
52 value 0x1f0000 would only enable the quick, byte and byte data
53 commands.
54
55 u8 bank_reg[10], u8 bank_mask[10], u8 bank_start[10], u8 bank_end[10]:
56 Optional bank settings. They tell which bits in which register
57 select the active bank, as well as the range of banked registers.
58
59 Caveats
60 =======
61
62 If your target driver polls some byte or word waiting for it to change, the
63 stub could lock it up. Use i2cset to unlock it.
64
65 If you spam it hard enough, printk can be lossy. This module really wants
66 something like relayfs.
67

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

가상 I2C/SMBus 장치의 동작

1-31

`i2c-stub` 모듈은 매우 단순한 가짜 I2C/SMBus 드라이버입니다. write quick, 읽기·쓰기 byte, 읽기·쓰기 byte data, 읽기·쓰기 word data, 읽기·쓰기 I2C block data, 읽기·쓰기 SMBus block data의 여섯 종류 SMBus 명령을 구현합니다.

드라이버를 로드할 때 모듈 매개변수로 칩 주소를 제공해야 하며, 모듈은 지정된 주소에 대한 SMBus 명령에만 반응합니다.

이 모듈에는 실제 하드웨어가 필요하지도, 연결되지도 않습니다. 지정 주소의 write quick 명령은 받아들이고, 다른 명령에는 메모리 배열을 읽거나 써서 응답합니다. 처리하는 모든 명령을 커널 로그에도 반복해서 기록합니다.

모든 바이트 연산에는 자동 증가하는 포인터 레지스터가 구현되어 있습니다. 이를 통해 EEPROM 등이 지원하는 연속 바이트 읽기를 재현할 수 있습니다.

SMBus 블록 명령 지원은 기본적으로 꺼져 있습니다. 사용하려면 `functionality` 모듈 매개변수의 해당 비트 `0x03000000`을 명시적으로 설정해야 합니다.

SMBus 블록 연산을 위한 SMBus 명령을 구성하려면 먼저 SMBus 블록 명령으로 써야 합니다. 쓰기는 일부만 수행할 수 있으며, 블록 읽기는 지금까지 수행한 쓰기 중 가장 큰 쓰기에서 선택된 바이트 수를 항상 반환합니다.

i2c-stub 지원 명령
종류지원 방향저장·응답 방식
Quick쓰기지정 주소의 명령을 수락
Byte읽기·쓰기메모리 배열과 자동 증가 포인터
Byte Data읽기·쓰기메모리 배열
Word Data읽기·쓰기메모리 배열
I2C Block Data읽기·쓰기메모리 배열
SMBus Block Data읽기·쓰기기본 비활성, `0x03000000`으로 활성화

모듈이 구현하는 여섯 종류의 SMBus 명령입니다.

가상 장치 명령 처리
모듈 로드 시 칩 주소 등록SMBus 명령과 대상 주소 수신등록 주소가 아니면 반응하지 않음Quick은 수락, 나머지는 메모리 배열 읽기·쓰기처리한 명령을 커널 로그에 기록

지정 주소에만 반응하고 메모리 배열로 값을 모사합니다.

========
i2c-stub
========

Description
===========

This module is a very simple fake I2C/SMBus driver.  It implements six
types of SMBus commands: write quick, (r/w) byte, (r/w) byte data, (r/w)
word data, (r/w) I2C block data, and (r/w) SMBus block data.

You need to provide chip addresses as a module parameter when loading this
driver, which will then only react to SMBus commands to these addresses.

No hardware is needed nor associated with this module.  It will accept write
quick commands to the specified addresses; it will respond to the other
commands (also to the specified addresses) by reading from or writing to
arrays in memory.  It will also spam the kernel logs for every command it
handles.

A pointer register with auto-increment is implemented for all byte
operations.  This allows for continuous byte reads like those supported by
EEPROMs, among others.

SMBus block command support is disabled by default, and must be enabled
explicitly by setting the respective bits (0x03000000) in the functionality
module parameter.

SMBus block commands must be written to configure an SMBus command for
SMBus block operations. Writes can be partial. Block read commands always
return the number of bytes selected with the largest write so far.

일반 사용 절차와 모듈 매개변수

32-58

전형적인 사용 순서는 먼저 이 모듈을 로드하고, i2c-tools 프로젝트의 `i2cset`으로 시험 데이터를 미리 채운 다음, 시험할 칩 드라이버 모듈을 로드해 커널 로그에서 동작을 관찰하는 것입니다.

i2c-tools 패키지의 `i2c-stub-from-dump` 스크립트는 실제 칩 덤프에서 레지스터 값을 자동으로 불러올 수 있습니다.

`int chip_addr[10]`은 가상 칩을 에뮬레이션할 SMBus 주소 배열입니다. 최대 열 개의 주소를 지정할 수 있습니다.

`unsigned long functionality`는 일부 명령을 끄기 위한 기능 재정의 값입니다. 적절한 비트 값은 `<linux/i2c.h>`의 `I2C_FUNC_*` 상수를 따릅니다. 예를 들어 `0x1f0000`은 quick, byte, byte data 명령만 활성화합니다.

`u8 bank_reg[10]`, `u8 bank_mask[10]`, `u8 bank_start[10]`, `u8 bank_end[10]`은 선택적인 뱅크 설정입니다. 활성 뱅크를 선택하는 레지스터와 비트, 그리고 뱅크 방식 레지스터 범위를 지정합니다.

i2c-stub 모듈 매개변수
매개변수형식의미
`chip_addr``int[10]`에뮬레이션할 SMBus 주소
`functionality``unsigned long``I2C_FUNC_*` 기능 비트 재정의
`bank_reg``u8[10]`뱅크 선택 레지스터
`bank_mask``u8[10]`활성 뱅크 선택 비트
`bank_start``u8[10]`뱅크 레지스터 범위 시작
`bank_end``u8[10]`뱅크 레지스터 범위 끝

주소, 기능 마스크, 선택적 뱅크 구성을 정리합니다.

칩 드라이버 시험
`i2c-stub` 모듈과 칩 주소 로드`i2cset` 또는 `i2c-stub-from-dump`로 데이터 준비대상 칩 드라이버 모듈 로드드라이버가 가상 주소와 레지스터 접근커널 로그에서 동작 확인

데이터를 먼저 준비한 뒤 대상 드라이버의 probe와 접근을 관찰합니다.


The typical use-case is like this:

        1. load this module
        2. use i2cset (from the i2c-tools project) to pre-load some data
        3. load the target chip driver module
        4. observe its behavior in the kernel log

There's a script named i2c-stub-from-dump in the i2c-tools package which
can load register values automatically from a chip dump.

Parameters
==========

int chip_addr[10]:
        The SMBus addresses to emulate chips at.

unsigned long functionality:
        Functionality override, to disable some commands. See I2C_FUNC_*
        constants in <linux/i2c.h> for the suitable values. For example,
        value 0x1f0000 would only enable the quick, byte and byte data
        commands.

u8 bank_reg[10], u8 bank_mask[10], u8 bank_start[10], u8 bank_end[10]:
        Optional bank settings. They tell which bits in which register
        select the active bank, as well as the range of banked registers.

폴링과 로그 손실 주의사항

59-66

시험 대상 드라이버가 어떤 바이트나 워드가 바뀌기를 기다리며 계속 폴링한다면, 값이 저절로 변하지 않는 stub 때문에 드라이버가 멈출 수 있습니다. 이때 `i2cset`으로 기다리는 값을 바꾸어 잠금을 풀어야 합니다.

명령을 지나치게 빠르게 많이 보내면 `printk` 로그가 손실될 수 있습니다. 이 모듈의 대량 이벤트 기록에는 원문이 언급한 relayfs 같은 방식이 더 적합합니다.

시험 시 주의사항
문제원인대응
대상 드라이버 폴링 정지stub 값이 자동으로 변하지 않음`i2cset`으로 값을 변경
커널 로그 누락과도한 명령으로 `printk` 손실명령 빈도를 낮추고 별도 이벤트 전달 방식 고려

가상 장치의 정적 상태와 로그 대역폭 한계입니다.

Caveats
=======

If your target driver polls some byte or word waiting for it to change, the
stub could lock it up.  Use i2cset to unlock it.

If you spam it hard enough, printk can be lossy.  This module really wants
something like relayfs.