QUESTION
board_init_f 초기화 목록 단계에서 실제로 바뀌는 상태는 무엇인가?
initcall_run_f()의 순서는 단순한 목록이 아니라 의존성 그래프를 일렬로 편 것이다. 한 호출을 옮길 때 그 함수가 읽는 gd 필드와 driver model, timer, console의 준비 여부를 먼저 확인한다.
각 initcall은 다음 호출이 읽을 상태를 성공 시 완전히 게시해야 하며, 실패를 반환하면 INITCALL이 즉시 hang()으로 진입한다. 이 문장을 기준으로 코드를 위에서 아래로 읽으면, 함수 이름을 외우는 대신 어느 시점에 어떤 상태를 신뢰할 수 있는지 판단할 수 있다.
STRUCTURE
초기화 목록과 주소 예약의 경계
board_init_f()는 initcall_run_f() 한 번을 호출한다_main초기 SP·x18=gd를 만든 뒤 호출board_init_fflags를 기록하고 지역 boardf를 연결initcall_run_fCPU·console → DRAM → 예약 → relocation 준비가 모두 목록 내부_main으로 복귀새 SP·gd 선택 뒤 조건부 relocate_codedram_init()과 reserve_*()는 initcall_run_f() 뒤에 별도로 호출되지 않는다. 항목 일부는 CONFIG 조건부다.CALL PATH
목록 내부의 데이터 의존 순서
dram_init()사용 가능한 RAM 크기를 gd에 기록setup_dest_addr() → reserve_*()주소 cursor와 새 객체 위치 계산; 본문 바이트 복사 아님setup_reloc()offset 조건부 계산, 새 gd 복사; ARM64는 C 반환 후 relocationdram_init_banksize()는 reserve_stacks() 뒤다. INITCALL 실패 시 hang()으로 들어가 다음 단계나 공통 rollback으로 진행하지 않는다.
STATE LEDGER
필드 생산과 소비 시점
ARM64 U-Boot proper를 읽는 지도다. 실제 조건부 항목은 대상 보드의 전처리 결과로 확인한다.
← 표를 좌우로 밀어 전체 열 보기 →
| 생산자 | 남기는 상태 | 첫 주요 소비자 | 경계 |
|---|---|---|---|
setup_mon_len | gd->mon_len | setup_dest_addr, reserve_uboot | image 길이; 실제 복사는 나중 |
dram_init | gd->ram_size | setup_dest_addr | RAM 크기 발견 |
setup_dest_addr | gd->ram_top, relocaddr | reserve_uboot | 주소 상한과 cursor 시작 |
reserve_uboot | relocaddr, start_addr_sp | 뒤따르는 reserve_* | SKIP_RELOCATE 조건부 본문 예약 |
reserve_global_data | gd->new_gd | setup_reloc | 위치 예약 후 gd 복사 |
reserve_stacks | 최종 stack cursor | ARM64 _main의 SP 교체 | 주소 준비와 실제 SP 변경 분리 |
setup_reloc | reloc_off, 새 gd 복사 | ARM64 _main의 x18 교체 | GD_FLG_SKIP_RELOC 분기 |
VISUAL WALKTHROUGH
여섯 구간과 실제 필드 의존성
여섯 구간은 읽기 위한 묶음이며 여섯 개의 별도 함수가 아니다.
initcall_run_f()를 여섯 구간으로 읽기모두 initcall_run_f() 내부다. dram_init_banksize()는 stack 예약 뒤의 bank 정보 기입이다.
setup_mon_len→gd->mon_len→setup_dest_addr·reserve_ubootdram_init→gd->ram_size→setup_dest_addrsetup_dest_addr→gd->relocaddr→reserve_ubootreserve_uboot→gd->start_addr_sp→뒤따르는 reserve 호출reserve_global_data→gd->new_gd→setup_reloc 복사 → ARM64 x18 전환reserve_uboot()은 목적지를 예약한다. U-Boot 본문의 실제 relocation은 ARM64 _main이 C 함수 반환 뒤 조건부로 시작한다.UPSTREAM SOURCE
원본 코드
아래 코드는 U-Boot v2026.07의 common/board_f.c에서 1007-1095줄을 그대로 가져온 것이다.
1007#endif
1008 INITCALL(reloc_bootstage);
1009 INITCALL(reloc_bloblist);
1010 INITCALL(setup_reloc);
1011#if CONFIG_IS_ENABLED(X86) || CONFIG_IS_ENABLED(ARC)
1012 INITCALL(copy_uboot_to_ram);
1013 INITCALL(do_elf_reloc_fixups);
1014#endif
1015 INITCALL(clear_bss);
1016 /*
1017 * Deregister all cyclic functions before relocation, so that
1018 * gd->cyclic_list does not contain any references to pre-relocation
1019 * devices. Drivers will register their cyclic functions anew when the
1020 * devices are probed again.
1021 *
1022 * This should happen as late as possible so that the window where a
1023 * watchdog device is not serviced is as small as possible.
1024 */
1025 INITCALL(cyclic_unregister_all);
1026#if !CONFIG_IS_ENABLED(ARM) && !CONFIG_IS_ENABLED(SANDBOX)
1027 INITCALL(jump_to_copy);
1028#endif
1029}
1030
1031void board_init_f(ulong boot_flags)
1032{
1033 struct board_f boardf;
1034
1035 gd->flags = boot_flags;
1036 gd->flags &= ~GD_FLG_HAVE_CONSOLE;
1037 gd->boardf = &boardf;
1038
1039 initcall_run_f();
1040
1041#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
1042 !defined(CONFIG_EFI_APP) && !CONFIG_IS_ENABLED(X86_64) && \
1043 !defined(CONFIG_ARC)
1044 /* NOTREACHED - jump_to_copy() does not return */
1045 hang();
1046#endif
1047}
1048
1049#if defined(CONFIG_X86) || defined(CONFIG_ARC)
1050/*
1051 * For now this code is only used on x86.
1052 *
1053 * Run init functions which are run when U-Boot is executing from Flash with a
1054 * semi-limited 'C' environment.
1055 * The following limitations must be considered when implementing an
1056 * '_f_r' function:
1057 * - 'static' variables are read-only
1058 * - Global Data (gd->xxx) is read/write
1059 *
1060 * The '_f_r' sequence must, as a minimum, copy U-Boot to RAM (if
1061 * supported). It _should_, if possible, copy global data to RAM and
1062 * initialise the CPU caches (to speed up the relocation process)
1063 *
1064 * NOTE: At present only x86 uses this route, but it is intended that
1065 * all archs will move to this when generic relocation is implemented.
1066 */
1067static void initcall_run_f_r(void)
1068{
1069#if !CONFIG_IS_ENABLED(X86_64)
1070 INITCALL(init_cache_f_r);
1071#endif
1072}
1073
1074void board_init_f_r(void)
1075{
1076 initcall_run_f_r();
1077
1078 /*
1079 * The pre-relocation drivers may be using memory that has now gone
1080 * away. Mark serial as unavailable - this will fall back to the debug
1081 * UART if available.
1082 *
1083 * Do the same with log drivers since the memory may not be available.
1084 */
1085 gd->flags &= ~(GD_FLG_SERIAL_READY | GD_FLG_LOG_READY);
1086#ifdef CONFIG_TIMER
1087 gd->timer = NULL;
1088#endif
1089
1090 /*
1091 * U-Boot has been copied into SDRAM, the BSS has been cleared etc.
1092 * Transfer execution from Flash to RAM by calculating the address
1093 * of the in-RAM copy of board_init_r() and calling it
1094 */
1095 (board_init_r + gd->reloc_off)((gd_t *)gd, gd->relocaddr);
READING CONTRACT
발췌 범위와 읽기 기준
원문 1007-1095줄에는 앞뒤 문맥이 포함됩니다. 기준 구문 void board_init_f(ulong boot_flags)은 L1031에 있습니다. 발췌 첫 줄을 함수 정의의 시작으로 해석하지 않습니다.
initcall_run_f()의 순서는 단순한 목록이 아니라 의존성 그래프를 일렬로 편 것이다. 한 호출을 옮길 때 그 함수가 읽는 gd 필드와 driver model, timer, console의 준비 여부를 먼저 확인한다.
void board_init_f(ulong boot_flags)relocation 전 C 초기화 단계의 진입점이다. ARM64에서는 초기 stack과 gd가 준비된 뒤 _main이 호출하며, 이 함수가 반환하면 architecture assembly가 실제 relocation을 계속한다.
struct board_f boardf;relocation 계산에만 쓰는 지역 객체를 현재 stack에 만든다. new_fdt, fdt_size, new_bootstage, new_bloblist를 보관하며 board_init_f()가 끝난 뒤에는 수명이 끝난다.
gd->flags = boot_flags;이전 stage가 전달한 부트 상태를 global data에 복사한다. 이후 initcall들이 공통으로 읽기 때문에 다른 필드보다 먼저 게시한다.
gd->flags &= ~GD_FLG_HAVE_CONSOLE;console core가 아직 사용 가능하지 않음을 명시한다. serial hardware의 물리 상태와 별개이며 serial_init()과 console_init_f() 전의 잘못된 출력 경로를 막는다.
gd->boardf = &boardf;여러 reserve/relocation 함수가 같은 임시 장부를 쓰도록 주소를 gd에 연결한다. 지역 객체 주소이므로 relocation 이후까지 보존해서는 안 된다.
initcall_run_f();실제 초기화 정책으로 들어간다. 이 호출 안에서 CPU·timer·console·DRAM 초기화와 top-down 예약이 순서대로 실행되며, 어느 하나라도 0이 아닌 값을 반환하면 hang()으로 끝난다.
/* NOTREACHED - jump_to_copy() does not return */목록 안에서 jump_to_copy()를 실행하는 architecture는 정상 경로가 여기로 돌아오지 않는다는 설명이다. ARM과 sandbox 등은 별도의 반환·relocation 경로를 사용하므로 전처리 조건에서 제외된다.
hang();비복귀 relocation 함수가 예상과 달리 반환했을 때 더 진행하지 않도록 정지한다. 이 줄에 도달했다면 단순 initcall 실패가 아니라 architecture handoff 계약이 깨진 것이다.
RELATED SOURCE
함께 읽어야 하는 원본 코드
첫 코드 조각만으로 동작이 완성되지 않는 경우 호출 매크로, 객체 정의와 실제 실행 목록을 같은 페이지에 묶었다. 각 조각은 같은 기준 commit에서 가져왔다.
01. INITCALL과 INITCALL_EVT의 실제 실패 처리
include/initcall.h 15-41줄이다.
15#define INITCALL(_call) \
16 do { \
17 if (_call()) { \
18 printf("%s(): initcall %s() failed\n", __func__, \
19 #_call); \
20 hang(); \
21 } \
22 } while (0)
23
24#define INITCALL_EVT(_evt) \
25 do { \
26 if (event_notify_null(_evt)) { \
27 printf("%s(): event %d/%s failed\n", __func__, _evt, \
28 event_type_name(_evt)) ; \
29 hang(); \
30 } \
31 } while (0)
32
33#if defined(CONFIG_WATCHDOG) || defined(CONFIG_HW_WATCHDOG)
34#define WATCHDOG_INIT() INITCALL(init_func_watchdog_init)
35#define WATCHDOG_RESET() INITCALL(init_func_watchdog_reset)
36#else
37#define WATCHDOG_INIT()
38#define WATCHDOG_RESET()
39#endif
40
41#endif
02. relocation 전용 struct board_f의 필드와 수명
include/board_f.h 8-35줄이다.
8#define __BOARD_F
9
10/**
11 * struct board_f: Information used only before relocation
12 *
13 * This struct is set up in board_init_f() and used to deal with relocation. It
14 * is not available after relocation.
15 */
16struct board_f {
17 /**
18 * @new_fdt: relocated device tree
19 */
20 void *new_fdt;
21 /**
22 * @fdt_size: space reserved for relocated device space
23 */
24 unsigned long fdt_size;
25 /**
26 * @new_bootstage: relocated boot stage information
27 */
28 struct bootstage_data *new_bootstage;
29 /**
30 * @new_bloblist: relocated blob list information
31 */
32 struct bloblist_hdr *new_bloblist;
33};
34
35#endif
03. initcall_run_f 전체 순서
common/board_f.c 879-1030줄이다.
879static void initcall_run_f(void)
880{
881 /*
882 * Please do not add logic to this function (variables, if (), etc.).
883 * For simplicity it should remain an ordered list of function calls.
884 */
885 INITCALL(setup_mon_len);
886#if CONFIG_IS_ENABLED(OF_CONTROL)
887 INITCALL(fdtdec_setup);
888#endif
889#if CONFIG_IS_ENABLED(TRACE_EARLY)
890 INITCALL(trace_early_init);
891#endif
892 INITCALL(initf_malloc);
893 INITCALL(initf_upl);
894 INITCALL(log_init);
895 INITCALL(initf_bootstage); /* uses its own timer, so does not need DM */
896 INITCALL(event_init);
897 INITCALL(bloblist_maybe_init);
898 INITCALL(setup_spl_handoff);
899#if CONFIG_IS_ENABLED(CONSOLE_RECORD_INIT_F)
900 INITCALL(console_record_init);
901#endif
902 INITCALL_EVT(EVT_FSP_INIT_F);
903 INITCALL(arch_cpu_init); /* basic arch cpu dependent setup */
904 INITCALL(mach_cpu_init); /* SoC/machine dependent CPU setup */
905 INITCALL(initf_dm);
906#if CONFIG_IS_ENABLED(BOARD_EARLY_INIT_F)
907 INITCALL(board_early_init_f);
908#endif
909#if defined(CONFIG_PPC) || defined(CONFIG_SYS_FSL_CLK) || defined(CONFIG_M68K)
910 /* get CPU and bus clocks according to the environment variable */
911 INITCALL(get_clocks); /* get CPU and bus clocks (etc.) */
912#endif
913#if !defined(CONFIG_M68K) || (defined(CONFIG_M68K) && !defined(CONFIG_MCFTMR))
914 INITCALL(timer_init); /* initialize timer */
915#endif
916#if CONFIG_IS_ENABLED(BOARD_POSTCLK_INIT)
917 INITCALL(board_postclk_init);
918#endif
919 INITCALL(env_init); /* initialize environment */
920 INITCALL(init_baud_rate); /* initialze baudrate settings */
921 INITCALL(serial_init); /* serial communications setup */
922 INITCALL(console_init_f); /* stage 1 init of console */
923 INITCALL(display_options); /* say that we are here */
924 INITCALL(display_text_info); /* show debugging info if required */
925 INITCALL(checkcpu);
926#if CONFIG_IS_ENABLED(SYSRESET)
927 INITCALL(print_resetinfo);
928#endif
929 /* display cpu info (and speed) */
930#if CONFIG_IS_ENABLED(DISPLAY_CPUINFO)
931 INITCALL(print_cpuinfo);
932#endif
933#if CONFIG_IS_ENABLED(DTB_RESELECT)
934 INITCALL(embedded_dtb_select);
935#endif
936#if CONFIG_IS_ENABLED(DISPLAY_BOARDINFO)
937 INITCALL(show_board_info);
938#endif
939 WATCHDOG_INIT();
940 INITCALL_EVT(EVT_MISC_INIT_F);
941 WATCHDOG_RESET();
942#if CONFIG_IS_ENABLED(SYS_I2C_LEGACY)
943 INITCALL(init_func_i2c);
944#endif
945 INITCALL(announce_dram_init);
946 INITCALL(dram_init); /* configure available RAM banks */
947#if CONFIG_IS_ENABLED(POST)
948 INITCALL(post_init_f);
949#endif
950 WATCHDOG_RESET();
951#if defined(CFG_SYS_DRAM_TEST)
952 INITCALL(testdram);
953#endif /* CFG_SYS_DRAM_TEST */
954 WATCHDOG_RESET();
955#if CONFIG_IS_ENABLED(POST)
956 INITCALL(init_post);
957#endif
958 WATCHDOG_RESET();
959 /*
960 * Now that we have DRAM mapped and working, we can
961 * relocate the code and continue running from DRAM.
962 *
963 * Reserve memory at end of RAM for (top down in that order):
964 * - area that won't get touched by U-Boot and Linux (optional)
965 * - kernel log buffer
966 * - protected RAM
967 * - LCD framebuffer
968 * - monitor code
969 * - board info struct
970 */
971 INITCALL(setup_dest_addr);
972#if CONFIG_IS_ENABLED(OF_BOARD_FIXUP) && \
973 !CONFIG_IS_ENABLED(OF_INITIAL_DTB_READONLY)
974 INITCALL(fix_fdt);
975#endif
976#ifdef CFG_PRAM
977 INITCALL(reserve_pram);
978#endif
979 INITCALL(reserve_round_4k);
980 INITCALL(setup_relocaddr_from_bloblist);
981 INITCALL(arch_reserve_mmu);
982 INITCALL(reserve_video);
983 INITCALL(reserve_trace);
984 INITCALL(reserve_uboot);
985 INITCALL(reserve_malloc);
986 INITCALL(reserve_board);
987 INITCALL(reserve_global_data);
988 INITCALL(reserve_fdt);
989#if CONFIG_IS_ENABLED(OF_BOARD_FIXUP) && \
990 CONFIG_IS_ENABLED(OF_INITIAL_DTB_READONLY)
991 INITCALL(reloc_fdt);
992 INITCALL(fix_fdt);
993#endif
994 INITCALL(reserve_bootstage);
995 INITCALL(reserve_bloblist);
996 INITCALL(reserve_arch);
997 INITCALL(reserve_stacks);
998 INITCALL(dram_init_banksize);
999 INITCALL(show_dram_config);
1000 WATCHDOG_RESET();
1001 INITCALL(setup_bdinfo);
1002 INITCALL(display_new_sp);
1003 WATCHDOG_RESET();
1004#if !CONFIG_IS_ENABLED(OF_BOARD_FIXUP) || \
1005 !CONFIG_IS_ENABLED(INITIAL_DTB_READONLY)
1006 INITCALL(reloc_fdt);
1007#endif
1008 INITCALL(reloc_bootstage);
1009 INITCALL(reloc_bloblist);
1010 INITCALL(setup_reloc);
1011#if CONFIG_IS_ENABLED(X86) || CONFIG_IS_ENABLED(ARC)
1012 INITCALL(copy_uboot_to_ram);
1013 INITCALL(do_elf_reloc_fixups);
1014#endif
1015 INITCALL(clear_bss);
1016 /*
1017 * Deregister all cyclic functions before relocation, so that
1018 * gd->cyclic_list does not contain any references to pre-relocation
1019 * devices. Drivers will register their cyclic functions anew when the
1020 * devices are probed again.
1021 *
1022 * This should happen as late as possible so that the window where a
1023 * watchdog device is not serviced is as small as possible.
1024 */
1025 INITCALL(cyclic_unregister_all);
1026#if !CONFIG_IS_ENABLED(ARM) && !CONFIG_IS_ENABLED(SANDBOX)
1027 INITCALL(jump_to_copy);
1028#endif
1029}
1030
DETAILS
목록 경계에서 확인할 것
호출 문맥
ARM64 _main은 초기 stack과 gd를 마련한 뒤 이 C 함수를 호출한다. U-Boot proper와 XPL/SPL 분기를 구분한다.
DRAM 크기와 주소 예약
dram_init() 뒤 setup_dest_addr()가 상한을 계산한다. reserve_uboot()가 처음 start_addr_sp를 설정한다.
예약과 복사
reserve_global_data()가 새 gd의 위치를 정하고 setup_reloc()이 기존 gd를 그곳에 복사한다. U-Boot 본문 이동은 ARM64에서 C 함수 반환 뒤 별도 assembly 경로다.
실패 지점
INITCALL이 실패하면 hang()에 들어간다. 마지막 완료 함수와 console 준비 여부를 분리해 계측한다.
IMPLEMENTATION NOTES
구현을 읽을 때 놓치기 쉬운 부분
board_init_f는 초기화 구현이 아니라 실행 순서를 여는 얇은 진입점이다
board_init_f() 자체에는 CPU clock, DRAM controller, serial driver를 직접 만지는 코드가 없다. 이 함수가 하는 일은 부트 플래그를 gd에 옮기고, 아직 console을 사용할 수 없음을 표시하고, relocation 전에만 필요한 struct board_f를 연결한 뒤 initcall_run_f()를 호출하는 것이다. 따라서 이 글을 함수 본문 19줄에서 끝내면 핵심을 놓친다. 실제 초기화 정책은 initcall_run_f()에 적힌 호출 순서에 있다.
호출 순서는 링크 시 수집되는 Linux initcall 표가 아니라 C 소스에 직접 나열된 목록이다. 전처리 결과에 따라 항목이 사라지므로 소스의 겉모양과 실제 binary의 순서는 다를 수 있다. 분석할 보드의 .config로 common/board_f.c를 전처리한 결과를 함께 봐야 한다.
boot_flags를 복사한 직후 console flag를 지우는 이유
gd->flags = boot_flags는 이전 stage가 넘긴 실행 조건을 보존한다. 바로 다음 줄의 gd->flags &= ~GD_FLG_HAVE_CONSOLE은 serial hardware가 반드시 꺼져 있다는 뜻이 아니라 U-Boot의 console 계층을 아직 호출 가능한 상태로 간주하지 않겠다는 선언이다. serial_init()과 console_init_f()가 끝나기 전에 이 비트를 남겨 두면 출력 함수가 준비되지 않은 console device를 따라갈 수 있다.
이 구간의 실패는 UART에 아무것도 남지 않을 수 있다. JTAG에서 PC를 보거나 GPIO 토글, SRAM trace buffer처럼 console에 의존하지 않는 관찰 수단이 필요하다. INITCALL의 오류 printf()도 console 초기화 전에는 화면에 보인다고 가정할 수 없다.
struct board_f는 relocation 전에만 유효한 임시 장부다
struct board_f boardf는 board_init_f()의 stack 지역 객체이고 gd->boardf가 그 주소를 가리킨다. 여기에는 새 FDT 주소와 예약 크기, 옮겨질 bootstage와 bloblist 주소가 들어간다. 이 정보는 DRAM 상단을 깎아 relocation 목적지를 계산하는 동안만 필요하다.
ARM 경로에서 board_init_f()가 반환하면 지역 객체의 C 수명은 끝난다. 이후 코드는 gd->boardf를 runtime 객체처럼 보관해서는 안 된다. 실제 runtime 상태는 relocation된 FDT, bootstage, bloblist와 새 gd로 넘어간다. 이 수명 경계를 어기면 relocation 전 stack 주소를 DRAM 실행 단계에서 다시 읽는 문제가 생긴다.
초기화 목록의 여섯 구간은 독해용 구분이다
첫 구간은 image 길이·early malloc·log 같은 기반이다. 둘째는 CPU·SoC·driver model, 셋째는 timer·environment·console이다. 넷째의 dram_init()이 RAM 크기를 확정한 뒤 다섯째에서 setup_dest_addr()와 예약 호출들이 목적지를 계산한다.
여섯째는 FDT·bootstage·bloblist 이동과 setup_reloc()을 거쳐 반환을 준비한다. 이 구간들은 모두 하나의 initcall_run_f() 목록 안에 있고, 각 호출의 존재는 보드 설정에 좌우된다.
DRAM 발견과 DRAM 예약은 같은 단계가 아니다
dram_init()의 보드별 구현은 DRAM controller 초기화나 크기 탐지를 포함할 수 있다. 공통 호출자만 보고 controller가 이미 준비되었다고 단정할 수 없다. 성공 뒤 gd->ram_size 등의 정보가 뒤따르는 예약 계산의 입력이 된다. 그 다음 setup_dest_addr()와 reserve_*() 함수들은 그 크기를 소비해 U-Boot가 차지할 구간을 계산한다. dram_init_banksize()는 더 뒤에서 bd->bi_dram[] 같은 bank별 정보를 채운다. 이름이 비슷해도 생산하는 필드와 호출 시점이 다르다.
예약 함수들은 allocator처럼 독립적으로 빈 공간을 찾지 않는다. 공통 cursor인 gd->start_addr_sp 또는 relocation 관련 주소를 위에서 아래로 줄인다. 한 함수의 정렬 반올림과 차감 크기가 틀리면 이후 모든 주소가 함께 밀리므로, 마지막 fault 주소만 보고 원인을 찾기 어렵다.
INITCALL의 실패 계약은 복구가 아니라 정지다
INITCALL(fn)은 fn()의 반환값이 0이 아니면 함수 이름을 출력하고 hang()을 호출한다. 여기에는 자동 rollback이나 다음 후보로 넘어가는 정책이 없다. 이 목록을 공통 자원 해제 경로로 설명해서는 안 된다. 개별 init 함수의 부작용은 해당 함수와 보드 구현에서 확인한다.
watchdog이 활성화된 보드에서는 hang()이 영구 정지로 관찰되지 않고 일정 시간 뒤 reset으로 보일 수 있다. console 준비 이전 실패, console 준비 이후 실패, watchdog reset 누락을 구분하려면 reset cause register와 마지막으로 완료된 initcall 번호를 함께 남기는 편이 낫다.
ARM과 x86/ARC의 relocation 경로를 한 문장으로 묶으면 안 된다
목록 끝의 copy_uboot_to_ram()과 do_elf_reloc_fixups()는 x86 또는 ARC에서만 포함된다. ARM은 board_init_f()가 반환한 뒤 crt0_64.S 같은 architecture 진입 코드가 relocate_code를 호출한다. 같은 board_init_f()를 읽더라도 비복귀 지점과 stack 전환 위치가 architecture마다 다르다.
디버거에서 initcall_run_f() 다음 PC를 예상할 때 현재 architecture의 전처리 결과를 기준으로 해야 한다. ARM에서 목록 안의 jump_to_copy()를 찾거나, x86에서 ARM assembly의 반환 경로를 대입하면 relocation 직전의 제어 흐름을 잘못 해석하게 된다.
OBJECT LIFETIME
객체와 수명
← 표를 좌우로 밀어 전체 열 보기 →
| 대상 | 생성 시점 | 유효 경계 | 확인점 |
|---|---|---|---|
초기 gd | ARM64 _main의 reserve 초기화 | setup_reloc()에서 새 gd로 복사하기 전후의 원본 | old/new 주소를 혼동하지 않는다 |
지역 struct board_f | board_init_f() stack | C 함수가 반환할 때까지 | gd->boardf가 가리키는 임시 장부 |
gd->new_gd 목적지 | reserve_global_data() | setup_reloc() 복사 뒤 ARM64 x18이 선택 | 예약과 복사 시점 구분 |
gd->start_addr_sp | reserve_uboot()에서 시작 | 뒤의 예약 호출과 reserve_stacks()가 조정 | ARM64 SP 교체는 C 함수 반환 뒤 |
FAILURE PATH
실패 지점과 증상
← 표를 좌우로 밀어 전체 열 보기 →
| 조건 | 보일 수 있는 증상 | 먼저 확인할 값 |
|---|---|---|
console_init_f() 전 initcall 실패 | 오류 출력 없이 정지하거나 watchdog reset | 마지막 initcall, reset cause, 초기 UART 가능 여부 |
dram_init()의 RAM 크기 오류 | 뒤의 relocaddr·stack 주소가 RAM 밖 | gd->ram_size와 board의 usable top |
| 예약 크기·정렬 오류 | 새 gd·FDT·stack 구간 중첩 | relocaddr, start_addr_sp, 예약 전후 경계 |
INITCALL 실패는 다음 항목으로 진행하지 않는다. 보드별 watchdog·reset 동작은 별도 계측이 필요하다.
EVIDENCE
빌드와 보드에서 확인할 증거
명령은 대상 보드 설정·툴체인에 맞춰 실행한다. 여기에는 실기 결과를 가정하지 않았다.
← 표를 좌우로 밀어 전체 열 보기 →
| 목적 | 명령 또는 계측 | 확인할 것 |
|---|---|---|
| 조건부 목록 | 해당 .config로 common/board_f.c 전처리 | 실제 포함된 initcall·CONFIG 분기 |
| symbol 위치 | ${CROSS_COMPILE}nm -n u-boot | grep ' board_init_f$' | 함수 주소; SPL을 살필 때는 해당 산출물 사용 |
| assembly 경계 | ${CROSS_COMPILE}objdump -drS u-boot | board_init_f 복귀 뒤 SP·x18 교체와 relocation 분기 |
| 런타임 주소 | bdinfo와 초기 로그/JTAG | ram_top·relocaddr·start_addr_sp의 실제 범위 |
LAB
직접 확인할 실험
- 01보드 설정으로 실제 initcall 목록 확인
해당
.config의 전처리 결과에서 조건부 항목을 확인하고 console 전후 마지막 완료 함수를 기록한다. - 02DRAM 발견과 주소 예약의 필드 비교
dram_init·setup_dest_addr·reserve_uboot·reserve_stacks전후의ram_size·ram_top·relocaddr·start_addr_sp를 비교한다. - 03ARM64 함수 반환 뒤 SP·gd 교체 확인
setup_reloc()에서 복사된new_gd와_main복귀 뒤의 x18·SP를 대조한다. code relocation은 skip flag 분기와 구분한다.
PRIMARY REFERENCES