On Tue, Apr 05, 2016 at 07:11:28PM +0200, Antonio Borneo wrote: > With "-dtb" on command-line: > - append the device tree blob to the kernel image; > - pass the blob's pointer to the kernel through setup_data, as > requested by upstream kernel commit da6b737b9ab7 ("x86: Add > device tree support"). > > The device tree blob is passed as-is to the guest; none of its > fields is modified nor updated. This is not an issue; the kernel > commit above uses the device tree only as an extension to the > traditional kernel configuration. > > To: "Michael S. Tsirkin" <m...@redhat.com> > To: Paolo Bonzini <pbonz...@redhat.com> > To: Richard Henderson <r...@twiddle.net> > To: Eduardo Habkost <ehabk...@redhat.com> > Cc: qemu-devel@nongnu.org > Cc: Sebastian Andrzej Siewior <bige...@linutronix.de> > Signed-off-by: Antonio Borneo <borneo.anto...@gmail.com> > --- > > Hi, > > I'm not expert on the x86 memory map at boot and during kernel > boot; I found easy to just append the dtb to the kernel image. > From my tests this patch is working fine. > If you have any hint for a different loading address for dtb, I > would be glad to modify this code.
I was worried that changing FW_CFG_KERNEL_SIZE could break something, but this seems to be OK because: * The only user of FW_CFG_KERNEL_* seems to be read_fw_blob_addr32(), used by linuxboot.S and multiboot.S just for reading data from fw_cfg into RAM; * multiboot code already does something similar: it uses FW_CFG_KERNEL_SIZE not just for the kernel image size, but for the kernel image plus the extra data loaded after it. One small comment below: [...] > @@ -989,6 +1006,35 @@ static void load_linux(PCMachineState *pcms, > exit(1); > } > fclose(f); > + > + /* append dtb to kernel */ > + if (dtb_filename) { > + if (protocol < 0x209) { > + fprintf(stderr, "qemu: Linux kernel too old to load a dtb\n"); > + exit(1); > + } > + > + dtb_size = get_image_size(dtb_filename); > + if (dtb_size <= 0) { > + fprintf(stderr, "qemu: error reading dtb %s: %s\n", > + dtb_filename, strerror(errno)); > + exit(1); > + } > + > + setup_data_offset = QEMU_ALIGN_UP(kernel_size, 16); > + kernel_size = setup_data_offset + sizeof(struct setup_data) + > dtb_size; > + kernel = g_realloc(kernel, kernel_size); > + > + stq_p(header+0x250, prot_addr + setup_data_offset); > + > + setup_data = (struct setup_data *)(kernel + setup_data_offset); > + setup_data->next = 0; > + setup_data->type = cpu_to_le32(SETUP_DTB); > + setup_data->len = cpu_to_le32(dtb_size); > + > + load_image(dtb_filename, setup_data->data); load_image() is deprecated, please use load_image_size(dtb_filename, setup_data->data, dtb_size) instead. > + } > + > memcpy(setup, header, MIN(sizeof(header), setup_size)); > > fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, prot_addr); > -- > 2.8.0 > -- Eduardo