2025년 3월 27일부터 AOSP를 빌드하고 기여하려면 aosp-main
대신 android-latest-release
를 사용하는 것이 좋습니다. 자세한 내용은 AOSP 변경사항을 참고하세요.
HAL 모듈 변환
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
hardware/libhardware/include/hardware
의 헤더를 변환하여 기존 HAL 모듈을 HIDL HAL 모듈로 업데이트할 수 있습니다.
c2hal 사용
c2hal
도구가 대부분의 변환 작업을 처리하므로 필요한 수동 변경 횟수가 줄어듭니다. 예를 들어 NFC HAL의 HIDL .hal
파일을 생성하려면 다음과 같이 작성합니다.
make c2hal
c2hal -r android.hardware:hardware/interfaces -randroid.hidl:system/libhidl/transport -p android.hardware.nfc@1.0 hardware/libhardware/include/hardware/nfc.h
이러한 명령어는 hardware/interfaces/nfc/1.0/
에 파일을 추가합니다. $ANDROID_BUILD_TOP
디렉터리에서 hardware/interfaces/update-makefiles.sh
를 실행하면 필요한 makefile도 HAL에 추가됩니다. 이를 직접 변경하여 HAL을 완전히 변환할 수도 있습니다.
c2hal 작업
c2hal
을 실행하는 경우 헤더 파일의 모든 내용이 .hal
파일로 전송됩니다.
c2hal
은 제공된 헤더 파일의 함수 포인터가 있는 구조체를 식별하고, 각 구조체를 별도의 인터페이스 파일로 변환합니다.
예를 들어 alloc_device_t
는 IAllocDevice
HAL 모듈로 변환됩니다(IAllocDevice.hal
파일 내).
다른 모든 데이터 유형은 types.hal
파일로 복사됩니다.
파운드 정의는 Enum으로 이동하고 HIDL에 속하지 않거나 변환할 수 없는 항목(예: 정적 함수 선언)은 텍스트로 'NOTE
'라고 표시된 댓글로 복사됩니다.
수동 작업
c2hal
도구는 특정 구조체에 대해 해야 할 작업을 알지 못합니다. 예를 들어 HIDL에는 원시 포인터 개념이 없으므로 c2hal
은 헤더 파일의 포인터를 배열로 해석해야 하는지, 다른 객체의 참조로 해석해야 하는지 알 수 없습니다. Void 포인터도 마찬가지로 불명확합니다.
int reserved[7]
와 같은 필드는 HIDL로 변환하는 동안 수동으로 제거해야 합니다. 반환 값의 이름과 같은 항목은 더 명확한 의미를 담도록 업데이트해야 합니다. 예를 들면 NFC에서 write
와 같은 메서드의 반환 매개변수를 자동 생성된 int32_t write_ret
에서 Status status
(Status
는 가능한 NFC 상태를 포함하는 새로운 Enum임)로 변환하는 것입니다.
HAL 구현
.hal
파일을 생성하여 HAL을 제공한 후에는 C++ 및 자바에서 언어 지원을 생성하는 makefile(Make 또는 Soong)을 생성해야 합니다(HAL이 자바에서 지원하지 않는 기능을 사용하지 않는 경우). ./hardware/interfaces/update-makefiles.sh
스크립트는 hardware/interfaces
디렉터리에 있는 HAL의 makefile을 자동으로 생성할 수 있습니다. 다른 위치에 있는 HAL의 경우 스크립트만 업데이트하면 됩니다.
makefile이 최신 상태이면 헤더 파일을 생성하고 메서드를 구현할 준비가 된 것입니다. 생성된 인터페이스 구현에 관한 자세한 내용은 HIDL C++(C++로 구현하는 경우) 또는 HIDL 자바(자바로 구현하는 경우)를 참조하세요.
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-07-27(UTC)
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["필요한 정보가 없음","missingTheInformationINeed","thumb-down"],["너무 복잡함/단계 수가 너무 많음","tooComplicatedTooManySteps","thumb-down"],["오래됨","outOfDate","thumb-down"],["번역 문제","translationIssue","thumb-down"],["샘플/코드 문제","samplesCodeIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-07-27(UTC)"],[],[],null,["# Convert HAL modules\n\nYou can update preexisting HAL modules to HIDL HAL modules by converting the\nheader in `hardware/libhardware/include/hardware`.\n\nUse c2hal\n---------\n\nThe\n[c2hal](https://android.googlesource.com/platform/system/tools/hidl/+/android16-release/c2hal/)\ntool handles most of the conversion work, reducing the number of required manual\nchanges. For example, to generate a HIDL `.hal` file for the NFC\nHAL: \n\n make c2hal\n c2hal -r android.hardware:hardware/interfaces -randroid.hidl:system/libhidl/transport -p android.hardware.nfc@1.0 hardware/libhardware/include/hardware/nfc.h\n\nThese commands add files in `hardware/interfaces/nfc/1.0/`. Running\n`hardware/interfaces/update-makefiles.sh` from the `$ANDROID_BUILD_TOP`\ndirectory also adds the required makefile to the HAL. From here, you can\nmake manual changes to fully convert the HAL.\n\nc2hal activities\n----------------\n\nWhen you run `c2hal`, everything in the header file is transferred\nto `.hal` files.\n\n`c2hal` identifies structs that contain function pointers in the\nprovided header file and converts each struct into a separate interface file.\nFor example, `alloc_device_t` is converted to the\n`IAllocDevice` HAL module (in the file\n`IAllocDevice.hal`).\n\nAll other data types are copied over into a `types.hal` file.\nPound-defines are moved into enums, and items not a part of HIDL or not\nconvertible (such as static-function declarations) are copied into comments\nmarked with the text \"`NOTE`\".\n\nManual activities\n-----------------\n\nThe `c2hal` tool doesn't know what to do when it encounters\ncertain constructs. For example, HIDL has no concept of raw pointers; because of\nthis, when `c2hal` encounters a pointer in header files, it doesn't\nknow whether the pointer should be interpreted as an array or as a reference to\nanother object. Void pointers are also similarly opaque.\n\nField such as `int reserved[7]` must be manually removed during\nthe transition to HIDL. Items such as the name of the return value should be\nupdated to something more meaningful; for example, converting the return\nparameter of methods such as `write` in NFC from the autogenerated\n`int32_t write_ret` to `Status status` (where\n`Status` is a new enum containing possible NFC statuses).\n\nImplement the HAL\n-----------------\n\nAfter you have created `.hal` files to represent your HAL, you\nmust generate the makefiles (Make or Soong) that create the language support in\nC++ and Java (unless the HAL uses a feature unsupported in Java). The\n`./hardware/interfaces/update-makefiles.sh` script can automatically\ngenerate makefiles for HALs located in the `hardware/interfaces`\ndirectory (for HALs in other locations, simply update the script).\n\nWhen the makefiles are up to date, you are ready to generate header files and\nimplement methods. For details on implementing the generated interface, see\n[HIDL C++](/docs/core/architecture/hidl-cpp) (for C++\nimplementations) or [HIDL\nJava](/docs/core/architecture/hidl-java) (for Java implementations)."]]