Trusted Firmware-A · source analysis

BL2 image descriptor와 순차 적재

BL2가 플랫폼의 적재 목록을 순회하고, 별도의 실행 인계 목록을 준비하는 경로를 LTS 2.14.3 소스로 읽습니다.

표의 버전은 소스 분석 기준이며 최신 보안 버전 권고가 아닙니다. TF-A LTS 2.14.3 이후에는 보안 수정이 있습니다. 제품 적용 시 공식 변경 기록과 사용 플랫폼의 errata를 확인하세요.

Series
03 / 12
Baseline
LTS 2.14.3
Commit
f5e765a3443f
Source
bl2/bl2_main.c:18-106 (발췌 범위)

BL2는 어떤 목록을 적재하고, 무엇을 다음 단계에 넘기는가?

bl2_load_images()는 플랫폼이 제공한 bl_load_info_t의 노드를 순서대로 처리한다. 각 노드에서 사전 hook, 적재·인증 또는 SKIP_LOADING, 사후 hook을 거친다. 오류가 나면 플랫폼 오류 처리기로 간다.

적재가 끝나면 plat_get_next_bl_params()로 별도의 실행 이미지 인계 목록을 얻고 그 head의 ep_info를 반환한다. 인증은 TRUSTED_BOARD_BOOT 등 설정에 따른 경로이므로 모든 이미지가 항상 인증된다고 단정하지 않는다.

적재 목록과 실행 인계 목록은 다르다

그림 1. 공통 descriptor에서 파생될 수 있는 두 목록과 각 소비자

플랫폼 hook이 목록을 공급한다. 아래의 get_*_from_mem_params_desc()는 LTS 2.14.3의 공통 구성 helper이며, 모든 플랫폼이 반드시 이를 사용한다는 뜻은 아니다.

적재 목록 · bl_load_info_t

  1. plat_get_bl_image_load_info()가 반환
  2. bl_load_info_node_t: image_id, image_info, next_load_info
  3. bl2_load_images()가 노드마다 처리

공통 helper는 descriptor 배열 순서로 연결한다. 인증서 같은 데이터 이미지도 포함될 수 있다.

인계 목록 · bl_params_t

  1. plat_get_next_bl_params()가 반환
  2. bl_params_node_t: image_id, image_info, ep_info, next_params_info
  3. 다음 부트 단계가 실행 이미지 정보를 소비

공통 helper는 next_handoff_image_id를 따라 실행 이미지만 연결한다.

bl_mem_params_node_t의 image_info와 ep_info는 두 helper가 참조하지만, 적재 노드 자체가 인계 노드로 바뀌는 과정은 아니다.

한 노드의 처리와 전체 목록 완료

그림 2. bl2_load_images()의 실제 순회와 분기
  1. 목록 획득plat_get_bl_image_load_info(); head와 타입을 assert한 뒤 첫 노드로 이동
  2. 각 노드의 준비IMAGE_ATTRIB_PLAT_SETUP가 있으면 platform setup을 한 번 수행하고 bl2_plat_handle_pre_image_load(image_id) 호출
  3. 적재 분기IMAGE_ATTRIB_SKIP_LOADING가 없으면 load_auth_image(image_id, image_info); 있으면 이 호출을 건너뜀
  4. 각 노드의 마무리bl2_plat_handle_post_image_load(image_id) 뒤 next_load_info로 진행; pre/load/post 오류는 plat_error_handler(err)
  5. 순회 완료 뒤 인계plat_get_next_bl_params()의 head ep_info를 확인하고, arg0가 0일 때만 목록 주소를 채운 후 flush하고 ep_info 반환

SKIP_LOADING은 이 노드의 load_auth_image()를 생략한다는 뜻이다. 이미 적재되었거나 인증되었다는 보증은 이 분기 자체에 없다.

누가 목록과 이미지 상태를 생산·소비하는가

시점생산자새로 유효해지는 값소비자·경계
목록 획득plat_get_bl_image_load_info()적재 노드 head와 next_load_info 연결bl2_load_images() 순회
노드 준비pre-image-load hook플랫폼별 적재 사전 상태해당 노드의 적재 또는 skip 분기
읽기·검증load_auth_image() 경로읽은 image_size; 설정에 따라 인증 결과post-image-load hook; 실패 시 오류 처리
인계 목록plat_get_next_bl_params()실행 이미지 노드 head와 ep_infobl2_load_images()가 head의 ep_info 반환
최종 전달bl2_main()next_bl_ep_info!BL2_RUNS_AT_EL3: BL1 SMC; 그 외: 직접 bl2_run_next_image()

BL2 진입과 인계의 구성 분기

적재 loop는 같은 함수지만, 그 앞의 초기화와 그 뒤의 인계는 빌드 옵션에 따라 다르다. 실제 주소와 이미지 크기는 플랫폼 descriptor, linker map, BL2 로그와 저장 이미지로 대조한다.

그림 3. bl2_main()에서 적재 전후에 갈라지는 경로

RESET_TO_BL2와 BL2_RUNS_AT_EL3는 서로 다른 결정 지점이다.

01RESET_TO_BL2? EL3 setup : BL1 인계 setup
02crypto/auth·preload 초기화
03bl2_load_images()
04후처리·crypto 종료
05BL1 SMC 또는 직접 다음 이미지 실행
그림 4. 적재·인증·인계 관계에서 혼동하기 쉬운 경계
01image_id플랫폼 I/O source 선택load_image()
02TRUSTED_BOARD_BOOT설정·정책에 따른 parent 재귀 인증load_auth_image()
03SKIP_LOADING이 노드의 적재·인증 호출 생략post-image-load hook
04next_handoff_image_id실행 이미지 노드 연결bl_params_t

원본 코드

아래 코드는 Trusted Firmware-A LTS 2.14.3의 bl2/bl2_main.c에서 18-106줄을 그대로 가져온 것이다.

commitf5e765a3443fe21154aa908228e75ee2600085f6anchor · L42void __no_pauth bl2_main(
18#include <drivers/console.h>
19#include <drivers/fwu/fwu.h>
20#include <lib/bootmarker_capture.h>
21#include <lib/extensions/pauth.h>
22#include <lib/pmf/pmf.h>
23#include <plat/common/platform.h>
24
25#include "bl2_private.h"
26
27#ifdef __aarch64__
28#define NEXT_IMAGE	"BL31"
29#else
30#define NEXT_IMAGE	"BL32"
31#endif
32
33#if ENABLE_RUNTIME_INSTRUMENTATION
34	PMF_REGISTER_SERVICE(bl_svc, PMF_RT_INSTR_SVC_ID,
35		BL_TOTAL_IDS, PMF_DUMP_ENABLE);
36#endif
37
38/*******************************************************************************
39 * The only thing to do in BL2 is to load further images and pass control to
40 * next BL. The memory occupied by BL2 will be reclaimed by BL3x stages.
41 ******************************************************************************/
42void __no_pauth bl2_main(u_register_t arg0, u_register_t arg1, u_register_t arg2,
43	       u_register_t arg3)
44{
45	entry_point_info_t *next_bl_ep_info;
46
47	/* Enable early console if EARLY_CONSOLE flag is enabled */
48	plat_setup_early_console();
49#if RESET_TO_BL2
50
51	/* Perform early platform-specific setup */
52	bl2_el3_early_platform_setup(arg0, arg1, arg2, arg3);
53
54	/* Perform late platform-specific setup */
55	bl2_el3_plat_arch_setup();
56#else /* RESET_TO_BL2 */
57	/* Perform early platform-specific setup */
58	bl2_early_platform_setup2(arg0, arg1, arg2, arg3);
59
60	/* Perform late platform-specific setup */
61	bl2_plat_arch_setup();
62#endif /* RESET_TO_BL2 */
63
64	if (is_feat_pauth_supported()) {
65#if BL2_RUNS_AT_EL3
66		pauth_init_enable_el3();
67#else
68		pauth_init_enable_el1();
69#endif
70	}
71
72#if ENABLE_RUNTIME_INSTRUMENTATION
73	PMF_CAPTURE_TIMESTAMP(bl_svc, BL2_ENTRY, PMF_CACHE_MAINT);
74#endif
75
76	NOTICE("BL2: %s\n", build_version_string);
77	NOTICE("BL2: %s\n", build_message);
78
79	/* Perform remaining generic architectural setup in S-EL1 */
80	bl2_arch_setup();
81
82#if PSA_FWU_SUPPORT
83	fwu_init();
84#endif /* PSA_FWU_SUPPORT */
85
86	crypto_mod_init();
87
88	/* Initialize authentication module */
89	auth_mod_init();
90
91	/* Initialize the Measured Boot backend */
92	bl2_plat_mboot_init();
93
94	/* Initialize boot source */
95	bl2_plat_preload_setup();
96
97	/* Load the subsequent bootloader images. */
98	next_bl_ep_info = bl2_load_images();
99
100	/* Teardown the Measured Boot backend */
101	bl2_plat_mboot_finish();
102
103	crypto_mod_finish();
104
105#if !BL2_RUNS_AT_EL3
106#ifndef __aarch64__

발췌 범위와 읽기 기준

첫 원문은 bl2/bl2_main.c L18–106이며 void __no_pauth bl2_main(은 L42에 있다. L106은 !BL2_RUNS_AT_EL3 인계 분기 도중이다. 완결 경로는 같은 버전 원문의 이후 줄과 bl2/bl2_image_load_v2.c를 함께 읽어야 한다.

관련 코드 발췌 두 개는 load_auth_image() wrapper와 descriptor 기반 인계 목록 helper를 보여 준다. 실제 노드 순회는 이 페이지의 발췌 코드 안에 없으며 고정 버전 bl2_image_load_v2.c에 있다.

함께 읽어야 하는 원본 코드

아래 두 발췌는 적재·인증 wrapper와 실행 인계 목록 구성 helper를 보여 준다. 실제 적재 노드 순회는 위에 링크한 bl2_image_load_v2.c를 참조한다. 모두 같은 기준 commit의 코드다.

01. 설정에 따라 parent까지 재귀적으로 적재·인증

common/bl_common.c 205-275줄이다.

filecommon/bl_common.canchor · L217int load_auth_image(unsigned int image_id
205#endif
206
207	return load_image(image_id, image_data);
208}
209
210/*******************************************************************************
211 * Generic function to load and authenticate an image. The image is actually
212 * loaded by calling the 'load_image()' function. Therefore, it returns the
213 * same error codes if the loading operation failed, or -EAUTH if the
214 * authentication failed. In addition, this function uses recursion to
215 * authenticate the parent images up to the root of trust (if TBB is enabled).
216 ******************************************************************************/
217int load_auth_image(unsigned int image_id, image_info_t *image_data)
218{
219	int err;
220
221	if ((plat_try_img_ops == NULL) || (plat_try_img_ops->next_instance == NULL)) {
222		err = load_auth_image_internal(image_id, image_data);
223	} else {
224		do {
225			err = load_auth_image_internal(image_id, image_data);
226			if (err != 0) {
227				if (plat_try_img_ops->next_instance(image_id) != 0) {
228					return err;
229				}
230			}
231		} while (err != 0);
232	}
233
234	if (err == 0) {
235		/*
236		 * If loading of the image gets passed (along with its
237		 * authentication in case of Trusted-Boot flow) then measure
238		 * it (if MEASURED_BOOT flag is enabled).
239		 */
240		err = plat_mboot_measure_image(image_id, image_data);
241		if (err != 0) {
242			return err;
243		}
244
245		/*
246		 * Flush the image to main memory so that it can be executed
247		 * later by any CPU, regardless of cache and MMU state.
248		 */
249		flush_dcache_range(image_data->image_base,
250				   image_data->image_size);
251	}
252
253	return err;
254}
255
256/*******************************************************************************
257 * Print the content of an entry_point_info_t structure.
258 ******************************************************************************/
259void print_entry_point_info(const entry_point_info_t *ep_info)
260{
261	INFO("Entry point address = 0x%lx\n", ep_info->pc);
262	INFO("SPSR = 0x%x\n", ep_info->spsr);
263
264#define PRINT_IMAGE_ARG(n)					\
265	VERBOSE("Argument #" #n " = 0x%llx\n",			\
266		(unsigned long long) ep_info->args.arg##n)
267
268	PRINT_IMAGE_ARG(0);
269	PRINT_IMAGE_ARG(1);
270	PRINT_IMAGE_ARG(2);
271	PRINT_IMAGE_ARG(3);
272#ifdef __aarch64__
273	PRINT_IMAGE_ARG(4);
274	PRINT_IMAGE_ARG(5);
275	PRINT_IMAGE_ARG(6);

02. memory descriptor에서 다음 실행 이미지 인계 목록 구성

common/desc_image_load.c 122-226줄이다.

filecommon/desc_image_load.canchor · L132bl_params_t *get_next_bl_params_from_mem_params_desc(void)
122	return &bl_load_info;
123}
124
125/*******************************************************************************
126 * This function creates the list of executable images, by populating and
127 * linking each `bl_params_node_t` type node, using the internal array of
128 * image descriptor provided by bl_mem_params_desc_ptr. It also populates
129 * and returns `bl_params_t` type structure that contains head of the list
130 * of executable images.
131 ******************************************************************************/
132bl_params_t *get_next_bl_params_from_mem_params_desc(void)
133{
134	unsigned int count;
135	unsigned int img_id = 0U;
136	unsigned int link_index = 0U;
137	bl_params_node_t *bl_current_exec_node = NULL;
138	bl_params_node_t *bl_last_exec_node = NULL;
139	bl_mem_params_node_t *desc_ptr;
140
141	/* If there is no image to start with, return NULL */
142	if (bl_mem_params_desc_num == 0U)
143		return NULL;
144
145	/* Get the list HEAD */
146	for (count = 0U; count < bl_mem_params_desc_num; count++) {
147
148		desc_ptr = &bl_mem_params_desc_ptr[count];
149
150		if ((EP_GET_EXE(desc_ptr->ep_info.h.attr) == EXECUTABLE) &&
151			(EP_GET_FIRST_EXE(desc_ptr->ep_info.h.attr) == EP_FIRST_EXE)) {
152			next_bl_params.head = &desc_ptr->params_node_mem;
153			link_index = count;
154			break;
155		}
156	}
157
158	/* Make sure we have a HEAD node */
159	assert(next_bl_params.head != NULL);
160
161	/* Populate the HEAD information */
162	SET_PARAM_HEAD(&next_bl_params, PARAM_BL_PARAMS, VERSION_2, 0U);
163
164	/*
165	 * Go through the image descriptor array and create the list.
166	 * This bounded loop is to make sure that we are not looping forever.
167	 */
168	for (count = 0U; count < bl_mem_params_desc_num; count++) {
169
170		desc_ptr = &bl_mem_params_desc_ptr[link_index];
171
172		/* Make sure the image is executable */
173		assert(EP_GET_EXE(desc_ptr->ep_info.h.attr) == EXECUTABLE);
174
175		/* Get the memory for current node */
176		bl_current_exec_node = &desc_ptr->params_node_mem;
177
178		/* Populate the image information */
179		bl_current_exec_node->image_id = desc_ptr->image_id;
180		bl_current_exec_node->image_info = &desc_ptr->image_info;
181		bl_current_exec_node->ep_info = &desc_ptr->ep_info;
182
183		if (bl_last_exec_node != NULL) {
184			/* Assert if loop detected */
185			assert(bl_last_exec_node->next_params_info == NULL);
186
187			/* Link the previous node to the current one */
188			bl_last_exec_node->next_params_info = bl_current_exec_node;
189		}
190
191		/* Update the last node */
192		bl_last_exec_node = bl_current_exec_node;
193
194		/* If no next hand-off image then break out */
195		img_id = desc_ptr->next_handoff_image_id;
196		if (img_id == INVALID_IMAGE_ID)
197			break;
198
199		/* Get the index for the next hand-off image */
200		link_index = get_bl_params_node_index(img_id);
201		assert((link_index > 0U) &&
202			(link_index < bl_mem_params_desc_num));
203	}
204
205	/* Invalid image is expected to terminate the loop */
206	assert(img_id == INVALID_IMAGE_ID);
207
208	return &next_bl_params;
209}
210
211/*******************************************************************************
212 * This function populates the entry point information with the corresponding
213 * config file for all executable BL images described in bl_params.
214 ******************************************************************************/
215void populate_next_bl_params_config(bl_params_t *bl2_to_next_bl_params)
216{
217	/*
218	 * With Firmware Handoff configuration data is shared dynamically, most of
219	 * the *_CONFIG files will be deprecated. Avoid populating the entry point
220	 * arguments with their information as they're discarded anyway.
221	 */
222#if !TRANSFER_LIST
223	bl_params_node_t *params_node;
224	unsigned int fw_config_id;
225	uintptr_t fw_config_base;
226	bl_mem_params_node_t *mem_params;

고정 코드에서 확인되는 내부 동작

01

초기화 분기를 확인한다

RESET_TO_BL2에서는 EL3 조기·아키텍처 setup을, 그 밖에는 BL1 인계형 setup을 호출한다. 이어 crypto/auth 모듈과 preload를 준비한 뒤 bl2_load_images()로 들어간다.

02

적재와 인계는 다른 목록이다

플랫폼의 적재 노드를 순회한 뒤 별도의 bl_params_t를 얻는다. 공통 descriptor helper를 쓰는 경우 적재 목록은 descriptor 배열 순서, 인계 목록은 next_handoff_image_id 순서다.

03

읽기 실패와 크기 초과를 구별한다

load_image()는 플랫폼 I/O source를 열고 크기를 읽어 0이 아니며 image_max_size 이하인지 확인한다. 그 뒤 io_read()의 실제 길이를 검사한다. 이 함수에 목적지 간 중첩 검사까지 있다고 해석하면 안 된다.

04

인증과 skip의 조건을 확인한다

TRUSTED_BOARD_BOOT가 활성이고 dynamic auth가 꺼져 있지 않으면 parent를 재귀적으로 처리한다. 반면 SKIP_LOADING 노드에서는 load_auth_image() 호출 자체를 건너뛴다.

05

최종 인계 분기를 확인한다

반환된 next_bl_ep_info는 BL2_RUNS_AT_EL3가 false이면 BL1 SMC에 전달되고, true이면 bl2_run_next_image()에 직접 전달된다. AArch64와 AArch32의 다음 이미지 이름도 다르다.

구현 경계에서 확인할 세 가지

01

목록 순서와 인증 의존 관계

적재 목록의 next_load_info는 순회 순서다. 인증 parent의 재귀 적재는 load_auth_image() 내부에서 별도로 일어나며, 인계 목록의 next_handoff_image_id도 또 다른 연결이다. 셋을 같은 순서로 가정하지 않는다.

02

크기와 주소의 책임 분리

load_image()는 입력 image의 크기가 image_max_size를 넘는지 막고 short read를 확인한다. descriptor들이 목적지 영역을 겹치지 않게 배치했는지, 보안 메모리 속성과 preloaded 데이터가 타당한지는 플랫폼 구성과 실기기에서 따로 검증해야 한다.

03

인계 목록의 소비

bl2_load_images()는 인계 목록 head의 ep_info를 반환한다. arg0가 비어 있을 때만 목록 포인터를 넣고 plat_flush_next_bl_params()를 호출한다. 다음 이미지가 그 목록을 어떻게 사용하는지는 해당 플랫폼과 BL31 또는 BL32 경로에서 확인한다.

코드로 확정할 수 있는 계약과 플랫폼의 책임

bl2_load_images()는 플랫폼 목록을 순회하는 실행부다. descriptor helper가 만들 수 있는 적재·인계 목록, 저장소 I/O 정책, 인증 정책을 하나의 무조건적 흐름으로 합치지 않는다.

그림 5. 실패가 멈추는 위치와 뒤에 남는 경계
01플랫폼 목록

head와 버전 타입을 확인한다.

02pre hook

오류면 plat_error_handler().

03load 또는 skip

load 실패면 오류 처리. skip이면 이 호출 생략.

04post hook

오류면 오류 처리, 성공이면 다음 노드.

05인계 목록

head의 ep_info와 목록을 flush.

화살표는 모든 노드가 성공한 경우의 진행이다. 플랫폼 hook과 I/O·인증 정책의 세부 동작은 이 공통 함수만으로 확정되지 않는다.

자료구조의 생산자와 소비자

객체생산소비확인할 조건
bl_load_info_t플랫폼 hook 또는 descriptor helperbl2_load_images()head, 타입, 다음 노드 연결
image_info_t플랫폼 descriptorload_image()와 hookbase, max_size, 읽은 image_size
bl_params_t플랫폼 hook 또는 descriptor helper다음 부트 단계실행 이미지 head와 ep_info, 접근 가능성
next_handoff_image_id플랫폼 descriptor공통 인계 helper실행 이미지 연결·종료 조건

load_auth_image() 아래에서 달라지는 경로

  1. 01

    load_image()는 plat_get_image_source()로 I/O source를 얻고 크기가 0보다 크고 image_max_size 이하인지 검사한 뒤 읽는다.

  2. 02

    trusted board boot가 활성이고 dynamic auth가 허용되면 parent 재귀 적재와 auth_mod_verify_img()가 포함된다. 인증 실패 이미지의 버퍼는 지우고 cache를 flush한 뒤 오류를 반환한다.

  3. 03

    wrapper는 플랫폼이 제공하면 다른 I/O instance로 재시도할 수 있고, 성공 뒤 measured boot 측정과 해당 image 범위의 cache flush를 수행한다. 이 조건부 동작은 SKIP_LOADING에서는 호출되지 않는다.

빌드·플랫폼에 따라 달라지는 지점

설정 또는 hook영향
RESET_TO_BL2bl2_main()의 초기 setup 계열 선택
BL2_RUNS_AT_EL3BL1 SMC 복귀 또는 직접 다음 이미지 실행
TRUSTED_BOARD_BOOT 및 dynamic auth재귀 인증 또는 평문 적재 경로
IMAGE_ATTRIB_SKIP_LOADING해당 노드의 load_auth_image() 생략
플랫폼의 목록·I/O hook어떤 이미지가 포함되고 어디서 읽는지 결정

오류를 좁히는 관측점

증상관측점기록할 값판정
이미지를 찾지 못함plat_get_image_source() 직후image ID, I/O device/spec, 반환 코드플랫폼 I/O 정책과 실제 저장 이미지 대조
크기 초과·short readload_image()storage size, max_size, read length그 함수의 명시적 검사와 대조
인증 실패auth_mod_verify_img()image ID, parent ID, 반환 코드CoT 정책·인증서와 대조
인계 이미지 누락plat_get_next_bl_params() 직후head ID, 각 next ID, ep_info적재 목록과 구별해 인계 연결 확인

측정 로그와 부팅 인증은 다른 증거입니다

이 글의 코드 기준은 LTS 2.14.3이고, 다음 설명은 조회 시 2.15.0으로 표시된 TF-A Measured Boot 문서와 구분합니다. Trusted Boot가 활성화되어 있다면 이미지 인증 후 측정합니다. 해시를 로그에 남겼다는 사실만으로 실행 허용이나 서명 검증 성공을 대신할 수는 없습니다. 현재 발췌의 load_auth_image()도 인증 경로 성공 뒤 plat_mboot_measure_image()를 호출하며, 측정 오류를 호출자에게 돌려줍니다.

문서의 일반 부팅 경로에서는 이미지를 적재하는 BL1·BL2가 측정하고 BL31은 측정 대상 이미지를 적재하지 않습니다. 불변 BL1은 신뢰의 시작점이라는 가정 아래 자체 측정하지 않습니다. 초기화·이미지 측정·종료 처리를 구분하고, Event Log의 위치와 크기가 다음 실행 환경에 어떻게 전달되는지 플랫폼 구현에서 확인합니다.

Event Log는 측정 이력이며 보호된 PCR이나 RSE 같은 측정 저장소 자체가 아닙니다. 로그의 전달만 확인하고 신뢰된 저장소 갱신까지 완료됐다고 판단하지 않습니다. FVP의 설정 전달 방식과 critical-data 측정도 모든 보드의 공통 기능으로 일반화하지 않습니다. 여기서는 보드 측정이나 attestation을 실행하지 않았습니다. TF-A Measured Boot · 현재 버전의 적재·측정 호출 코드

이 글의 실제 객체와 소비자

대상공급자소비자수명 경계
bl_mem_params_desc플랫폼 descriptor 등록공통 적재·인계 helper두 목록이 참조하는 image/entry 필드가 다음 단계까지 유효해야 한다.
bl_load_info_t 노드플랫폼 목록 hookbl2_load_images()적재 순회가 끝날 때까지 연결과 필드가 유효해야 한다.
읽은 image bufferload_image()인증·post-load hook·다음 stageimage별 적재 주소와 실제 크기를 플랫폼 메모리 배치와 대조한다.
bl_params_t 노드플랫폼 인계 hook다음 실행 이미지flush 후 다음 단계가 읽을 때까지 주소·내용이 유지되어야 한다.
next_bl_ep_info인계 목록 headBL1 SMC 또는 bl2_run_next_image()제어권 전환까지 유효해야 한다.

짧은 read 감지와 반환 오류는 같지 않습니다

LTS 2.14.3의 load_image()는 bytes_read < image_size이면 경고를 남기고 정리 경로로 갑니다. 그러나 그 분기에서 io_result를 별도 오류 값으로 바꾸지 않고 그대로 반환합니다. 따라서 I/O backend가 0을 반환하면서 읽은 길이만 짧게 보고하면 공통 loader도 0을 반환할 수 있습니다. 크기 0의 -EIO, 최대 크기 초과의 -EFBIG와 이 경우를 구분해야 합니다.

인증 활성 경로의 후속 검증과 별개로, 이 버전의 길이 비교만으로 모든 짧은 읽기가 오류 반환된다고 보증하지 않습니다. 실제 backend의 반환 코드·읽은 길이와 사용 버전의 수정 상태를 함께 대조합니다. 고정 버전의 읽기·정리·반환 코드

실패 지점과 코드의 반응

조건코드에서 확인되는 반응추가로 확인할 책임
pre/load/post hook 오류plat_error_handler(err) 호출플랫폼 handler의 reset·halt 정책
size 0 또는 max_size 초과load_image()가 각각 -EIO 또는 -EFBIG 반환실제 저장 이미지와 descriptor 한계
trusted boot 인증 실패image buffer zero+flush 후 인증 오류CoT와 인증서·서명 입력
SKIP_LOADING의 잘못된 사용공통 loop는 load/auth를 호출하지 않음이미지 유효성·주소 보장은 플랫폼이 확인

빌드와 보드에서 확인할 증거

다음 명령은 이미 만들어진 산출물이 있을 때의 예다. 플랫폼의 실제 BL2 ELF·저장 형식·툴체인에 맞춰 경로를 바꾼다.

목적명령 또는 계측판정 기준
BL2 심볼${CROSS_COMPILE}nm -n build/<platform>/debug/bl2/bl2.elf | grep ' bl2_main$'BL2 안의 실제 bl2_main 심볼을 찾는다.
BL2 명령${CROSS_COMPILE}objdump -drS build/<platform>/debug/bl2/bl2.elf설정된 초기화·인계 분기가 BL2 산출물에 있는지 확인한다.
FIP 사용 플랫폼tools/fiptool/fiptool info build/<platform>/debug/fip.binFIP가 실제 입력이면 저장 이미지 ID와 크기를 대조한다. 다른 I/O source면 그 source를 본다.
실행 경로BL2 DEBUG log에 image ID, skip flag, pre/load/post 반환값, next params head 기록실제 순회 순서와 인계 목록을 별도로 확인한다.

플랫폼에서 직접 확인할 실험

  1. 01
    두 목록의 순서를 따로 출력

    plat_get_bl_image_load_info()의 next_load_info와 plat_get_next_bl_params()의 next_params_info를 각각 image ID로 기록해 순서를 비교한다.

  2. 02
    크기 경계 확인

    시험 이미지의 크기를 image_max_size보다 크게 만들어 load_image()가 적재 전에 오류를 반환하는지 안전한 개발 보드에서 확인한다.

  3. 03
    skip 노드의 책임 확인

    SKIP_LOADING 노드에서 load_auth_image()가 호출되지 않고 post hook은 호출되는지 계측한다. 이미지 내용의 타당성은 플랫폼의 preload 정책과 별도로 대조한다.

원문과 다음 글