qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Aurelien Jarno <aurelien@aurel32.net>
To: Yoshinori Sato <ysato@users.sourceforge.jp>
Cc: Magnus Damm <magnus.damm@gmail.com>, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] hw/sh4: Add dtb support
Date: Mon, 27 Jun 2016 02:04:22 +0200	[thread overview]
Message-ID: <20160627000422.GA31264@aurel32.net> (raw)
In-Reply-To: <1466314457-19920-1-git-send-email-ysato@users.sourceforge.jp>

On 2016-06-19 14:34, Yoshinori Sato wrote:
> New SH kernel use dtb.

Do you have a pointer to the corresponding kernel code? I can't find in
linus' tree.

> This patch add dtb support for R2D board emulation.
> 
> Signed-off-by: Yoshinori Sato <ysato@users.sourceforge.jp>
> ---
>  hw/sh4/r2d.c | 52 +++++++++++++++++++++++++++++++++++++++++++---------
>  1 file changed, 43 insertions(+), 9 deletions(-)
> 
> diff --git a/hw/sh4/r2d.c b/hw/sh4/r2d.c
> index f2547ed..203c117 100644
> --- a/hw/sh4/r2d.c
> +++ b/hw/sh4/r2d.c
> @@ -41,6 +41,7 @@
>  #include "hw/usb.h"
>  #include "hw/block/flash.h"
>  #include "sysemu/block-backend.h"
> +#include "sysemu/device_tree.h"
>  #include "exec/address-spaces.h"
>  
>  #define FLASH_BASE 0x00000000
> @@ -51,7 +52,7 @@
>  
>  #define SM501_VRAM_SIZE 0x800000
>  
> -#define BOOT_PARAMS_OFFSET 0x0001000
> +#define BOOT_PARAMS_OFFSET 0x0010000

Hmm, the current code already contains the value 0x0010000

>  /* CONFIG_BOOT_LINK_OFFSET of Linux kernel */
>  #define LINUX_LOAD_OFFSET  0x0800000
>  #define INITRD_LOAD_OFFSET 0x1800000
> @@ -198,6 +199,7 @@ static qemu_irq *r2d_fpga_init(MemoryRegion *sysmem,
>  typedef struct ResetData {
>      SuperHCPU *cpu;
>      uint32_t vector;
> +    uint32_t dtb;
>  } ResetData;
>  
>  static void main_cpu_reset(void *opaque)
> @@ -207,6 +209,8 @@ static void main_cpu_reset(void *opaque)
>  
>      cpu_reset(CPU(s->cpu));
>      env->pc = s->vector;
> +    /* r4_bank1 is DTB address */
> +    env->gregs[4 + 16] = s->dtb;
>  }
>  
>  static struct QEMU_PACKED
> @@ -225,10 +229,12 @@ static struct QEMU_PACKED
>  
>  static void r2d_init(MachineState *machine)
>  {
> +    QemuOpts *machine_opts;
>      const char *cpu_model = machine->cpu_model;
> -    const char *kernel_filename = machine->kernel_filename;
> -    const char *kernel_cmdline = machine->kernel_cmdline;
> -    const char *initrd_filename = machine->initrd_filename;
> +    const char *kernel_filename;
> +    const char *kernel_cmdline;
> +    const char *initrd_filename;
> +    const char *dtb_filename;
>      SuperHCPU *cpu;
>      CPUSH4State *env;
>      ResetData *reset_info;
> @@ -258,6 +264,12 @@ static void r2d_init(MachineState *machine)
>      reset_info->vector = env->pc;
>      qemu_register_reset(main_cpu_reset, reset_info);
>  
> +    machine_opts = qemu_get_machine_opts();
> +    kernel_filename = qemu_opt_get(machine_opts, "kernel");
> +    kernel_cmdline = qemu_opt_get(machine_opts, "append");
> +    initrd_filename = qemu_opt_get(machine_opts, "initrd");
> +    dtb_filename = qemu_opt_get(machine_opts, "dtb");
> +
>      /* Allocate memory space */
>      memory_region_init_ram(sdram, NULL, "r2d.sdram", SDRAM_SIZE, &error_fatal);
>      vmstate_register_ram_global(sdram);
> @@ -347,11 +359,33 @@ static void r2d_init(MachineState *machine)
>          boot_params.initrd_size = tswap32(initrd_size);
>      }
>  
> -    if (kernel_cmdline) {
> -        /* I see no evidence that this .kernel_cmdline buffer requires
> -           NUL-termination, so using strncpy should be ok. */
> -        strncpy(boot_params.kernel_cmdline, kernel_cmdline,
> -                sizeof(boot_params.kernel_cmdline));
> +    if (!dtb_filename) {
> +        if (kernel_cmdline) {
> +            /* I see no evidence that this .kernel_cmdline buffer requires
> +               NUL-termination, so using strncpy should be ok. */
> +            strncpy(boot_params.kernel_cmdline, kernel_cmdline,
> +                    sizeof(boot_params.kernel_cmdline));
> +        }
> +    } else {
> +        void *fdt;
> +        int r = 0;
> +        uint32_t addr;
> +        int fdt_size;
> +
> +        fdt = load_device_tree(dtb_filename, &fdt_size);
> +        if (!fdt) {
> +            return;
> +        }

If the user explicitly passed a dtb file, the error should not be
silently ignore if the file can't be loaded. It should print an error
message and bail out, just like it's done when the kernel image can't be
loaded.

> +        if (kernel_cmdline) {
> +            r = qemu_fdt_setprop_string(fdt, "/chosen", "bootargs",
> +                                        kernel_cmdline);
> +            if (r < 0) {
> +                fprintf(stderr, "couldn't set /chosen/bootargs\n");
> +            }
> +        }
> +        addr = (SDRAM_BASE + SDRAM_SIZE - fdt_size) & ~0xfff;
> +        cpu_physical_memory_write(addr, fdt, fdt_size);
> +        reset_info->dtb = addr;
>      }
>  
>      rom_add_blob_fixed("boot_params", &boot_params, sizeof(boot_params),

When a dtb file is passed, this memory area is initialized. Either the
command line should also be copied there, or this blob should not be
added in the dtb case.

Aurelien

-- 
Aurelien Jarno                          GPG: 4096R/1DDD8C9B
aurelien@aurel32.net                 http://www.aurel32.net

      reply	other threads:[~2016-06-27  0:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-19  5:34 [Qemu-devel] [PATCH] hw/sh4: Add dtb support Yoshinori Sato
2016-06-27  0:04 ` Aurelien Jarno [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160627000422.GA31264@aurel32.net \
    --to=aurelien@aurel32.net \
    --cc=magnus.damm@gmail.com \
    --cc=qemu-devel@nongnu.org \
    --cc=ysato@users.sourceforge.jp \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).