boot.c (c3a42358e31a7bd45e6ac12013895d2897169ca5) boot.c (d33774ee446569162a8ab8b4d43606b049207b80)
1/*
2 * ARM kernel loader.
3 *
4 * Copyright (c) 2006-2007 CodeSourcery.
5 * Written by Paul Brook
6 *
7 * This code is licensed under the GPL.
8 */

--- 935 unchanged lines hidden (view full) ---

944 *entry = mem_base + kernel_load_offset;
945 rom_add_blob_fixed_as(filename, buffer, size, *entry, as);
946
947 g_free(buffer);
948
949 return size;
950}
951
1/*
2 * ARM kernel loader.
3 *
4 * Copyright (c) 2006-2007 CodeSourcery.
5 * Written by Paul Brook
6 *
7 * This code is licensed under the GPL.
8 */

--- 935 unchanged lines hidden (view full) ---

944 *entry = mem_base + kernel_load_offset;
945 rom_add_blob_fixed_as(filename, buffer, size, *entry, as);
946
947 g_free(buffer);
948
949 return size;
950}
951
952void arm_load_kernel(ARMCPU *cpu, struct arm_boot_info *info)
952static void arm_setup_direct_kernel_boot(ARMCPU *cpu,
953 struct arm_boot_info *info)
953{
954{
955 /* Set up for a direct boot of a kernel image file. */
954 CPUState *cs;
956 CPUState *cs;
957 AddressSpace *as = arm_boot_address_space(cpu, info);
955 int kernel_size;
956 int initrd_size;
957 int is_linux = 0;
958 uint64_t elf_entry, elf_low_addr, elf_high_addr;
959 int elf_machine;
960 hwaddr entry;
961 static const ARMInsnFixup *primary_loader;
958 int kernel_size;
959 int initrd_size;
960 int is_linux = 0;
961 uint64_t elf_entry, elf_low_addr, elf_high_addr;
962 int elf_machine;
963 hwaddr entry;
964 static const ARMInsnFixup *primary_loader;
962 AddressSpace *as = arm_boot_address_space(cpu, info);
963
965
964 /*
965 * CPU objects (unlike devices) are not automatically reset on system
966 * reset, so we must always register a handler to do so. If we're
967 * actually loading a kernel, the handler is also responsible for
968 * arranging that we start it correctly.
969 */
970 for (cs = first_cpu; cs; cs = CPU_NEXT(cs)) {
971 qemu_register_reset(do_cpu_reset, ARM_CPU(cs));
972 }
973
974 /*
975 * The board code is not supposed to set secure_board_setup unless
976 * running its code in secure mode is actually possible, and KVM
977 * doesn't support secure.
978 */
979 assert(!(info->secure_board_setup && kvm_enabled()));
980
981 info->dtb_filename = qemu_opt_get(qemu_get_machine_opts(), "dtb");
982 info->dtb_limit = 0;
983
984 /* Load the kernel. */
985 if (!info->kernel_filename || info->firmware_loaded) {
986
987 if (have_dtb(info)) {
988 /*
989 * If we have a device tree blob, but no kernel to supply it to (or
990 * the kernel is supposed to be loaded by the bootloader), copy the
991 * DTB to the base of RAM for the bootloader to pick up.
992 */
993 info->dtb_start = info->loader_start;
994 }
995
996 if (info->kernel_filename) {
997 FWCfgState *fw_cfg;
998 bool try_decompressing_kernel;
999
1000 fw_cfg = fw_cfg_find();
1001 try_decompressing_kernel = arm_feature(&cpu->env,
1002 ARM_FEATURE_AARCH64);
1003
1004 /*
1005 * Expose the kernel, the command line, and the initrd in fw_cfg.
1006 * We don't process them here at all, it's all left to the
1007 * firmware.
1008 */
1009 load_image_to_fw_cfg(fw_cfg,
1010 FW_CFG_KERNEL_SIZE, FW_CFG_KERNEL_DATA,
1011 info->kernel_filename,
1012 try_decompressing_kernel);
1013 load_image_to_fw_cfg(fw_cfg,
1014 FW_CFG_INITRD_SIZE, FW_CFG_INITRD_DATA,
1015 info->initrd_filename, false);
1016
1017 if (info->kernel_cmdline) {
1018 fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE,
1019 strlen(info->kernel_cmdline) + 1);
1020 fw_cfg_add_string(fw_cfg, FW_CFG_CMDLINE_DATA,
1021 info->kernel_cmdline);
1022 }
1023 }
1024
1025 /*
1026 * We will start from address 0 (typically a boot ROM image) in the
1027 * same way as hardware.
1028 */
1029 return;
1030 }
1031
1032 if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) {
1033 primary_loader = bootloader_aarch64;
1034 elf_machine = EM_AARCH64;
1035 } else {
1036 primary_loader = bootloader;
1037 if (!info->write_board_setup) {
1038 primary_loader += BOOTLOADER_NO_BOARD_SETUP_OFFSET;
1039 }

--- 157 unchanged lines hidden (view full) ---

1197 object_child_foreach_recursive(object_get_root(),
1198 do_arm_linux_init, info);
1199 }
1200 info->is_linux = is_linux;
1201
1202 for (cs = first_cpu; cs; cs = CPU_NEXT(cs)) {
1203 ARM_CPU(cs)->env.boot_info = info;
1204 }
966 if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) {
967 primary_loader = bootloader_aarch64;
968 elf_machine = EM_AARCH64;
969 } else {
970 primary_loader = bootloader;
971 if (!info->write_board_setup) {
972 primary_loader += BOOTLOADER_NO_BOARD_SETUP_OFFSET;
973 }

--- 157 unchanged lines hidden (view full) ---

1131 object_child_foreach_recursive(object_get_root(),
1132 do_arm_linux_init, info);
1133 }
1134 info->is_linux = is_linux;
1135
1136 for (cs = first_cpu; cs; cs = CPU_NEXT(cs)) {
1137 ARM_CPU(cs)->env.boot_info = info;
1138 }
1139}
1205
1140
1141void arm_load_kernel(ARMCPU *cpu, struct arm_boot_info *info)
1142{
1143 CPUState *cs;
1144 AddressSpace *as = arm_boot_address_space(cpu, info);
1145
1146 /*
1147 * CPU objects (unlike devices) are not automatically reset on system
1148 * reset, so we must always register a handler to do so. If we're
1149 * actually loading a kernel, the handler is also responsible for
1150 * arranging that we start it correctly.
1151 */
1152 for (cs = first_cpu; cs; cs = CPU_NEXT(cs)) {
1153 qemu_register_reset(do_cpu_reset, ARM_CPU(cs));
1154 }
1155
1156 /*
1157 * The board code is not supposed to set secure_board_setup unless
1158 * running its code in secure mode is actually possible, and KVM
1159 * doesn't support secure.
1160 */
1161 assert(!(info->secure_board_setup && kvm_enabled()));
1162
1163 info->dtb_filename = qemu_opt_get(qemu_get_machine_opts(), "dtb");
1164 info->dtb_limit = 0;
1165
1166 /* Load the kernel. */
1167 if (!info->kernel_filename || info->firmware_loaded) {
1168
1169 if (have_dtb(info)) {
1170 /*
1171 * If we have a device tree blob, but no kernel to supply it to (or
1172 * the kernel is supposed to be loaded by the bootloader), copy the
1173 * DTB to the base of RAM for the bootloader to pick up.
1174 */
1175 info->dtb_start = info->loader_start;
1176 }
1177
1178 if (info->kernel_filename) {
1179 FWCfgState *fw_cfg;
1180 bool try_decompressing_kernel;
1181
1182 fw_cfg = fw_cfg_find();
1183 try_decompressing_kernel = arm_feature(&cpu->env,
1184 ARM_FEATURE_AARCH64);
1185
1186 /*
1187 * Expose the kernel, the command line, and the initrd in fw_cfg.
1188 * We don't process them here at all, it's all left to the
1189 * firmware.
1190 */
1191 load_image_to_fw_cfg(fw_cfg,
1192 FW_CFG_KERNEL_SIZE, FW_CFG_KERNEL_DATA,
1193 info->kernel_filename,
1194 try_decompressing_kernel);
1195 load_image_to_fw_cfg(fw_cfg,
1196 FW_CFG_INITRD_SIZE, FW_CFG_INITRD_DATA,
1197 info->initrd_filename, false);
1198
1199 if (info->kernel_cmdline) {
1200 fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE,
1201 strlen(info->kernel_cmdline) + 1);
1202 fw_cfg_add_string(fw_cfg, FW_CFG_CMDLINE_DATA,
1203 info->kernel_cmdline);
1204 }
1205 }
1206
1207 /*
1208 * We will start from address 0 (typically a boot ROM image) in the
1209 * same way as hardware.
1210 */
1211 return;
1212 } else {
1213 arm_setup_direct_kernel_boot(cpu, info);
1214 }
1215
1206 if (!info->skip_dtb_autoload && have_dtb(info)) {
1207 if (arm_load_dtb(info->dtb_start, info, info->dtb_limit, as) < 0) {
1208 exit(1);
1209 }
1210 }
1211}
1212
1213static const TypeInfo arm_linux_boot_if_info = {
1214 .name = TYPE_ARM_LINUX_BOOT_IF,
1215 .parent = TYPE_INTERFACE,
1216 .class_size = sizeof(ARMLinuxBootIfClass),
1217};
1218
1219static void arm_linux_boot_register_types(void)
1220{
1221 type_register_static(&arm_linux_boot_if_info);
1222}
1223
1224type_init(arm_linux_boot_register_types)
1216 if (!info->skip_dtb_autoload && have_dtb(info)) {
1217 if (arm_load_dtb(info->dtb_start, info, info->dtb_limit, as) < 0) {
1218 exit(1);
1219 }
1220 }
1221}
1222
1223static const TypeInfo arm_linux_boot_if_info = {
1224 .name = TYPE_ARM_LINUX_BOOT_IF,
1225 .parent = TYPE_INTERFACE,
1226 .class_size = sizeof(ARMLinuxBootIfClass),
1227};
1228
1229static void arm_linux_boot_register_types(void)
1230{
1231 type_register_static(&arm_linux_boot_if_info);
1232}
1233
1234type_init(arm_linux_boot_register_types)