extern "C" int start_raw(int argc, const char **argv) { stage2_args args; clear_bss(); // call C++ constructors before doing anything else call_ctors(); args.heap_size = HEAP_SIZE; args.arguments = NULL; args.platform.boot_tgz_data = NULL; args.platform.boot_tgz_size = 0; args.platform.fdt_data = NULL; args.platform.fdt_size = 0; // if we get passed a uimage, try to find the third blob only if we do not have FDT data yet if (gUImage != NULL && !gFDT && image_multi_getimg(gUImage, 2, (uint32*)&args.platform.fdt_data, &args.platform.fdt_size)) { // found a blob, assume it is FDT data, when working on a platform // which does not have an FDT enabled U-Boot gFDT = args.platform.fdt_data; } serial_init(gFDT); console_init(); cpu_init(); if (args.platform.fdt_data) { dprintf("Found FDT from uimage @ %p, %" B_PRIu32 " bytes\n", args.platform.fdt_data, args.platform.fdt_size); } else if (gFDT) { /* Fixup args so we can pass the gFDT on to the kernel */ args.platform.fdt_data = gFDT; args.platform.fdt_size = fdt_totalsize(gFDT); } // if we get passed an FDT, check /chosen for initrd if (gFDT != NULL) { int node = fdt_path_offset(gFDT, "/chosen"); const void *prop; int len; phys_addr_t initrd_start = 0, initrd_end = 0; if (node >= 0) { prop = fdt_getprop(gFDT, node, "linux,initrd-start", &len); if (prop && len == 4) initrd_start = fdt32_to_cpu(*(uint32_t *)prop); prop = fdt_getprop(gFDT, node, "linux,initrd-end", &len); if (prop && len == 4) initrd_end = fdt32_to_cpu(*(uint32_t *)prop); if (initrd_end > initrd_start) { args.platform.boot_tgz_data = (void *)initrd_start; args.platform.boot_tgz_size = initrd_end - initrd_start; dprintf("Found boot tgz from FDT @ %p, %" B_PRIu32 " bytes\n", args.platform.boot_tgz_data, args.platform.boot_tgz_size); } } } // if we get passed a uimage, try to find the second blob if (gUImage != NULL && image_multi_getimg(gUImage, 1, (uint32*)&args.platform.boot_tgz_data, &args.platform.boot_tgz_size)) { dprintf("Found boot tgz from uimage @ %p, %" B_PRIu32 " bytes\n", args.platform.boot_tgz_data, args.platform.boot_tgz_size); } { //DEBUG: int i; dprintf("argc = %d\n", argc); for (i = 0; i < argc; i++) dprintf("argv[%d] @%lx = '%s'\n", i, (uint32)argv[i], argv[i]); dprintf("os: %d\n", (int)gUBootOS); dprintf("gd @ %p\n", gUBootGlobalData); if (gUBootGlobalData) dprintf("gd->bd @ %p\n", gUBootGlobalData->bd); //dprintf("fb_base %p\n", (void*)gUBootGlobalData->fb_base); if (gUImage) dump_uimage(gUImage); if (gFDT) dump_fdt(gFDT); } mmu_init(); // wait a bit to give the user the opportunity to press a key // spin(750000); // reading the keyboard doesn't seem to work in graphics mode // (maybe a bochs problem) // sBootOptions = check_for_boot_keys(); //if (sBootOptions & BOOT_OPTION_DEBUG_OUTPUT) serial_enable(); main(&args); return 0; }
extern "C" int start_gen(int argc, const char **argv, struct image_header *uimage, void *fdt) { stage2_args args; clear_bss(); // call C++ constructors before doing anything else call_ctors(); args.heap_size = HEAP_SIZE; args.arguments = NULL; args.arguments_count = 0; args.platform.boot_tgz_data = NULL; args.platform.boot_tgz_size = 0; args.platform.fdt_data = NULL; args.platform.fdt_size = 0; gUImage = uimage; gFDT = fdt; //XXX: make a copy? // TODO: check for atags instead and convert them if (argv) { // skip the kernel name ++argv; --argc; } // TODO: Ensure cmdline is mapped into memory by MMU before usage. // if we get passed a uimage, try to find the third blob // only if we do not have FDT data yet if (gUImage != NULL && !gFDT && image_multi_getimg(gUImage, 2, (uint32*)&args.platform.fdt_data, &args.platform.fdt_size)) { // found a blob, assume it is FDT data, when working on a platform // which does not have an FDT enabled U-Boot gFDT = args.platform.fdt_data; } // We have to cpu_init *before* calling FDT functions cpu_init(); serial_init(gFDT); #if defined(__ARM__) arch_mailbox_init(); #endif // initialize the OpenFirmware wrapper of_init(NULL); console_init(); // if we get passed an FDT, check /chosen for initrd and bootargs if (gFDT != NULL) { int node = fdt_path_offset(gFDT, "/chosen"); const void *prop; int len; phys_addr_t initrd_start = 0, initrd_end = 0; if (node >= 0) { prop = fdt_getprop(gFDT, node, "linux,initrd-start", &len); if (prop && len == 4) initrd_start = fdt32_to_cpu(*(uint32_t *)prop); prop = fdt_getprop(gFDT, node, "linux,initrd-end", &len); if (prop && len == 4) initrd_end = fdt32_to_cpu(*(uint32_t *)prop); if (initrd_end > initrd_start) { args.platform.boot_tgz_data = (void *)initrd_start; args.platform.boot_tgz_size = initrd_end - initrd_start; dprintf("Found boot tgz from FDT @ %p, %" B_PRIu32 " bytes\n", args.platform.boot_tgz_data, args.platform.boot_tgz_size); } // we check for bootargs after remapping the FDT } } // if we get passed a uimage, try to find the second blob if (gUImage != NULL && image_multi_getimg(gUImage, 1, (uint32*)&args.platform.boot_tgz_data, &args.platform.boot_tgz_size)) { dprintf("Found boot tgz from uimage @ %p, %" B_PRIu32 " bytes\n", args.platform.boot_tgz_data, args.platform.boot_tgz_size); } { //DEBUG: int i; dprintf("argc = %d\n", argc); for (i = 0; i < argc; i++) dprintf("argv[%d] @%lx = '%s'\n", i, (uint32)argv[i], argv[i]); dprintf("os: %d\n", (int)gUBootOS); dprintf("gd @ %p\n", gUBootGlobalData); if (gUBootGlobalData) { dprintf("gd->bd @ %p\n", gUBootGlobalData->bd); dprintf("gd->fb_base @ %p\n", (void*)gUBootGlobalData->fb_base); } if (gUImage) dump_uimage(gUImage); if (gFDT) dump_fdt(gFDT); } if (args.platform.boot_tgz_size > 0) { insert_physical_allocated_range((addr_t)args.platform.boot_tgz_data, args.platform.boot_tgz_size); } // save the size of the FDT so we can map it easily after mmu_init size_t fdtSize = gFDT ? fdt_totalsize(gFDT) : 0; dprintf("fdtSize: 0x%" B_PRIxSIZE "\n", fdtSize); mmu_init(); // Handle our tarFS post-mmu if (args.platform.boot_tgz_size > 0) { args.platform.boot_tgz_data = (void*)mmu_map_physical_memory((addr_t) args.platform.boot_tgz_data, args.platform.boot_tgz_size, kDefaultPageFlags); } // .. and our FDT if (gFDT != NULL) gFDT = (void*)mmu_map_physical_memory((addr_t)gFDT, fdtSize, kDefaultPageFlags); // if we get passed an FDT, check /chosen for bootargs now // to avoid having to copy them. if (gFDT != NULL) { int node = fdt_path_offset(gFDT, "/chosen"); const void *prop; int len; if (node >= 0) { prop = fdt_getprop(gFDT, node, "bootargs", &len); if (prop) { dprintf("Found bootargs: %s\n", (const char *)prop); static const char *sArgs[] = { NULL, NULL }; sArgs[0] = (const char *)prop; // override main() args args.arguments = sArgs; args.arguments_count = 1; } } dprintf("args.arguments_count = %" B_PRId32 "\n", args.arguments_count); for (int i = 0; i < args.arguments_count; i++) dprintf("args.arguments[%d] @%lx = '%s'\n", i, (uint32)args.arguments[i], args.arguments[i]); } // wait a bit to give the user the opportunity to press a key // spin(750000); // reading the keyboard doesn't seem to work in graphics mode // (maybe a bochs problem) // sBootOptions = check_for_boot_keys(); //if (sBootOptions & BOOT_OPTION_DEBUG_OUTPUT) serial_enable(); main(&args); return 0; }
static int setup_fdt(struct kvm *kvm) { struct device_header *dev_hdr; u8 staging_fdt[FDT_MAX_SIZE]; u32 gic_phandle = fdt__alloc_phandle(); u64 mem_reg_prop[] = { cpu_to_fdt64(kvm->arch.memory_guest_start), cpu_to_fdt64(kvm->ram_size), }; void *fdt = staging_fdt; void *fdt_dest = guest_flat_to_host(kvm, kvm->arch.dtb_guest_start); void (*generate_mmio_fdt_nodes)(void *, struct device_header *, void (*)(void *, u8)); void (*generate_cpu_peripheral_fdt_nodes)(void *, struct kvm *, u32) = kvm->cpus[0]->generate_fdt_nodes; /* Create new tree without a reserve map */ _FDT(fdt_create(fdt, FDT_MAX_SIZE)); _FDT(fdt_finish_reservemap(fdt)); /* Header */ _FDT(fdt_begin_node(fdt, "")); _FDT(fdt_property_cell(fdt, "interrupt-parent", gic_phandle)); _FDT(fdt_property_string(fdt, "compatible", "linux,dummy-virt")); _FDT(fdt_property_cell(fdt, "#address-cells", 0x2)); _FDT(fdt_property_cell(fdt, "#size-cells", 0x2)); /* /chosen */ _FDT(fdt_begin_node(fdt, "chosen")); _FDT(fdt_property_cell(fdt, "linux,pci-probe-only", 1)); _FDT(fdt_property_string(fdt, "bootargs", kern_cmdline)); /* Initrd */ if (kvm->arch.initrd_size != 0) { u32 ird_st_prop = cpu_to_fdt64(kvm->arch.initrd_guest_start); u32 ird_end_prop = cpu_to_fdt64(kvm->arch.initrd_guest_start + kvm->arch.initrd_size); _FDT(fdt_property(fdt, "linux,initrd-start", &ird_st_prop, sizeof(ird_st_prop))); _FDT(fdt_property(fdt, "linux,initrd-end", &ird_end_prop, sizeof(ird_end_prop))); } _FDT(fdt_end_node(fdt)); /* Memory */ _FDT(fdt_begin_node(fdt, "memory")); _FDT(fdt_property_string(fdt, "device_type", "memory")); _FDT(fdt_property(fdt, "reg", mem_reg_prop, sizeof(mem_reg_prop))); _FDT(fdt_end_node(fdt)); /* CPU and peripherals (interrupt controller, timers, etc) */ generate_cpu_nodes(fdt, kvm); if (generate_cpu_peripheral_fdt_nodes) generate_cpu_peripheral_fdt_nodes(fdt, kvm, gic_phandle); /* Virtio MMIO devices */ dev_hdr = device__first_dev(DEVICE_BUS_MMIO); while (dev_hdr) { generate_mmio_fdt_nodes = dev_hdr->data; generate_mmio_fdt_nodes(fdt, dev_hdr, generate_irq_prop); dev_hdr = device__next_dev(dev_hdr); } /* IOPORT devices (!) */ dev_hdr = device__first_dev(DEVICE_BUS_IOPORT); while (dev_hdr) { generate_mmio_fdt_nodes = dev_hdr->data; generate_mmio_fdt_nodes(fdt, dev_hdr, generate_irq_prop); dev_hdr = device__next_dev(dev_hdr); } /* PCI host controller */ pci__generate_fdt_nodes(fdt, gic_phandle); /* PSCI firmware */ _FDT(fdt_begin_node(fdt, "psci")); _FDT(fdt_property_string(fdt, "compatible", "arm,psci")); _FDT(fdt_property_string(fdt, "method", "hvc")); _FDT(fdt_property_cell(fdt, "cpu_suspend", KVM_PSCI_FN_CPU_SUSPEND)); _FDT(fdt_property_cell(fdt, "cpu_off", KVM_PSCI_FN_CPU_OFF)); _FDT(fdt_property_cell(fdt, "cpu_on", KVM_PSCI_FN_CPU_ON)); _FDT(fdt_property_cell(fdt, "migrate", KVM_PSCI_FN_MIGRATE)); _FDT(fdt_end_node(fdt)); /* Finalise. */ _FDT(fdt_end_node(fdt)); _FDT(fdt_finish(fdt)); _FDT(fdt_open_into(fdt, fdt_dest, FDT_MAX_SIZE)); _FDT(fdt_pack(fdt_dest)); if (kvm->cfg.arch.dump_dtb_filename) dump_fdt(kvm->cfg.arch.dump_dtb_filename, fdt_dest); return 0; }