Raspberry Pi 3 support
Subsystems (2)
v2 cover Raspberry Pi 3 support
This patch series adds support for Raspberry Pi 3 as a new machine model "raspi3", which is an extension of the "raspi2" model with the following differences:
- Default CPU type is "cortex-a53"
- Firmware is at address 0x80000
- Board ID is 0xc44 and board revision is 0xa02082
The patches were written by me but I used Zoltán Baldaszti's previous work as a reference (with permission from the author):
https://github.com/bztsrc/qemu-raspi3
Also available from:
[email protected]:penberg/qemu.git raspi3/v2
Changes from v1 to v2:
- Wrap Raspberry Pi 3 machine definition with TARGET_AARCH64 (Peter Maydell)
Pekka Enberg (3):
bcm2836: Make CPU type configurable
raspi: Raspberry Pi 3 support
raspi: Add "raspi3" machine type
hw/arm/bcm2836.c | 17 ++++++++------- hw/arm/raspi.c | 57 +++++++++++++++++++++++++++++++++++++++--------- include/hw/arm/bcm2836.h | 1 + 3 files changed, 57 insertions(+), 18 deletions(-)
Signature · 1 line
2.14.3
PATCH v2 1/3 bcm2836: Make CPU type configurable
This patch adds a "cpu-type" property to BCM2836 SoC in preparation for reusing the code for the Raspberry Pi 3, which has a different processor model.
--- hw/arm/bcm2836.c | 17 +++++++++-------- hw/arm/raspi.c | 3 +++ include/hw/arm/bcm2836.h | 1 + 3 files changed, 13 insertions(+), 8 deletions(-)
hw/arm/bcm2836.c +9 -8
@@ -26,14 +26,6 @@static void bcm2836_init (Object *obj) {BCM2836State *s =BCM2836 (obj); -int n; - -for (n =0 ; n <BCM2836_NCPUS ; n++) { -object_initialize (&s->cpus[n],sizeof (s->cpus[n]), -"cortex-a15-" TYPE_ARM_CPU ); -object_property_add_child (obj,"cpu[*]" ,OBJECT (&s->cpus[n]), - &error_abort); - }object_initialize (&s->control,sizeof (s->control),TYPE_BCM2836_CONTROL );object_property_add_child (obj,"control" ,OBJECT (&s->control),NULL );
@@ -59,6 +51,14 @@ static void bcm2836_realize(DeviceState *dev, Error **errp)/* common peripherals from bcm2835 */ + obj =OBJECT (dev); +for (n =0 ; n <BCM2836_NCPUS ; n++) { +object_initialize (&s->cpus[n],sizeof (s->cpus[n]), + s->cpu_type); +object_property_add_child (obj,"cpu[*]" ,OBJECT (&s->cpus[n]), + &error_abort); + } + obj =object_property_get_link (OBJECT (dev),"ram" , &err);if (obj ==NULL ) { error_setg(errp, "%s: required ram link not found: %s",
@@ -150,6 +150,7 @@ static void bcm2836_realize(DeviceState *dev, Error **errp) }static Property bcm2836_props[] = { +DEFINE_PROP_STRING ("cpu-type" , BCM2836State, cpu_type),DEFINE_PROP_UINT32 ("enabled-cpus" , BCM2836State, enabled_cpus,BCM2836_NCPUS ),DEFINE_PROP_END_OF_LIST () };
hw/arm/raspi.c +3 -0
@@ -135,6 +135,8 @@ static void raspi2_init(MachineState *machine)/* Setup the SOC */ object_property_add_const_link (OBJECT (&s->soc),"ram" ,OBJECT (&s->ram), &error_abort); +object_property_set_str (OBJECT (&s->soc), machine->cpu_type,"cpu-type" , + &error_abort);object_property_set_int (OBJECT (&s->soc), smp_cpus,"enabled-cpus" , &error_abort); object_property_set_int(OBJECT(&s->soc), 0xa21041, "board-rev",
@@ -166,6 +168,7 @@ static void raspi2_machine_init(MachineClass *mc) mc->no_parallel =1 ; mc->no_floppy =1 ; mc->no_cdrom =1 ; + mc->default_cpu_type =ARM_CPU_TYPE_NAME ("cortex-a15" ); mc->max_cpus =BCM2836_NCPUS ; mc->min_cpus =BCM2836_NCPUS ; mc->default_cpus =BCM2836_NCPUS ;
include/hw/arm/bcm2836.h +1 -0
@@ -25,6 +25,7 @@ typedef struct BCM2836State {DeviceState parent_obj;/*< public >*/ +char *cpu_type;uint32_t enabled_cpus;ARMCPU cpus[BCM2836_NCPUS ];
Signature · 1 line
2.14.3
PATCH v2 2/3 raspi: Raspberry Pi 3 support
In reply to Pekka EnbergThis patch adds Raspberry Pi 3 support to hw/arm/raspi.c. The differences to Pi 2 are:
- Firmware address
- Board ID
- Board revision
The CPU is different too, but that's going to be configured as part of the machine default CPU when we introduce a new machine type.
The patch was written from scratch by me but the logic is similar to Zoltán Baldaszti's previous work, which I used as a reference (with permission from the author):
https://github.com/bztsrc/qemu-raspi3
--- hw/arm/raspi.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-)
hw/arm/raspi.c +21 -10
@@ -5,6 +5,9 @@* Rasperry Pi 2 emulation Copyright (c) 2015, Microsoft * Written by Andrew Baumann * +* Raspberry Pi 3 emulation Copyright (c) 2018 Zoltán Baldaszti +* Upstream code cleanup (c) 2018 Pekka Enberg +* * This code is licensed under the GNU GPLv2 and later. */
@@ -22,10 +25,11 @@#define SMPBOOT_ADDR 0x300/* this should leave enough space for ATAGS */ #define MVBAR_ADDR 0x400/* secure vectors */ #define BOARDSETUP_ADDR (MVBAR_ADDR + 0x20)/* board setup code */ -#define FIRMWARE_ADDR 0x8000/* Pi loads kernel.img here by default */ +#define FIRMWARE_ADDR_2 0x8000/* Pi 2 loads kernel.img here by default */ +#define FIRMWARE_ADDR_3 0x80000/* Pi 3 loads kernel.img here by default */ /* Table of Linux board IDs for different Pi versions */ -static const int raspi_boardid[] = {[1 ] =0xc42 , [2 ] =0xc43 }; +static const int raspi_boardid[] = {[1 ] =0xc42 , [2 ] =0xc43 , [3 ] =0xc44 }; typedef struct RasPiState { BCM2836State soc;
@@ -83,8 +87,8 @@ static void setup_boot(MachineState *machine, int version, size_t ram_size) binfo.secure_board_setup = true; binfo.secure_boot = true; -/* Pi2 requires SMP setup */ -if (version ==2 ) { +/* Pi2 and Pi3 requires SMP setup */ +if (version >=2 ) { binfo.smp_loader_start =SMPBOOT_ADDR ; binfo.write_secondary_boot = write_smpboot; binfo.secondary_cpu_reset_hook = reset_secondary;
@@ -94,15 +98,16 @@ static void setup_boot(MachineState *machine, int version, size_t ram_size)* the normal Linux boot process */ if (machine->firmware) { +hwaddr firmware_addr = version ==3 ?FIRMWARE_ADDR_3 :FIRMWARE_ADDR_2 ;/* load the firmware image (typically kernel.img) */ - r =load_image_targphys (machine->firmware,FIRMWARE_ADDR , - ram_size -FIRMWARE_ADDR ); + r =load_image_targphys (machine->firmware, firmware_addr, + ram_size - firmware_addr);if (r <0 ) {error_report ("Failed to load firmware from %s" , machine->firmware);exit (1 ); } - binfo.entry =FIRMWARE_ADDR ; + binfo.entry = firmware_addr; binfo.firmware_loaded = true; }else { binfo.kernel_filename = machine->kernel_filename;
@@ -113,7 +118,7 @@ static void setup_boot(MachineState *machine, int version, size_t ram_size)arm_load_kernel (ARM_CPU (first_cpu), &binfo); } -static void raspi2_init (MachineState *machine) +static void raspi_init (MachineState *machine,int version) {RasPiState *s =g_new0 (RasPiState,1 );uint32_t vcram_size;
@@ -139,7 +144,8 @@ static void raspi2_init(MachineState *machine) &error_abort);object_property_set_int (OBJECT (&s->soc), smp_cpus,"enabled-cpus" , &error_abort); -object_property_set_int (OBJECT (&s->soc),0xa21041 ,"board-rev" , +int board_rev = version ==3 ?0xa02082 :0xa21041 ; +object_property_set_int (OBJECT (&s->soc), board_rev,"board-rev" , &error_abort);object_property_set_bool (OBJECT (&s->soc), true,"realized" , &error_abort);
@@ -157,7 +163,12 @@ static void raspi2_init(MachineState *machine) vcram_size =object_property_get_uint (OBJECT (&s->soc),"vcram-size" , &error_abort); -setup_boot (machine,2 , machine->ram_size - vcram_size); +setup_boot (machine, version, machine->ram_size - vcram_size); +} + +static void raspi2_init (MachineState *machine) +{ +raspi_init (machine,2 ); }static void raspi2_machine_init (MachineClass *mc)
Signature · 1 line
2.14.3
Re: [Qemu-arm] [Qemu-devel] [PATCH v2 2/3] raspi: Raspberry Pi 3 support
Hi Pekka and Zoltán,
Quoted 37 lines · Pekka Enberg
This patch adds Raspberry Pi 3 support to
hw/arm/raspi.c. The differences to Pi 2 are:- Firmware address
- Board ID
- Board revisionThe CPU is different too, but that's going to be configured as part of the machine default CPU when we introduce a new machine type.
The patch was written from scratch by me but the logic is similar to Zoltán Baldaszti's previous work, which I used as a reference (with permission from the author):
https://github.com/bztsrc/qemu-raspi3
Signed-off-by Pekka Enberg <[email protected]>--- hw/arm/raspi.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-)hw/arm/raspi.c +3
-0@@ -5,6 +5,9 @@* Rasperry Pi 2 emulation Copyright (c) 2015, Microsoft * Written by Andrew Baumann * +* Raspberry Pi 3 emulation Copyright (c) 2018 Zoltán Baldaszti +* Upstream code cleanup (c) 2018 Pekka Enberg +* * This code is licensed under the GNU GPLv2 and later. */
hw/arm/raspi.c line 32
Quoted 10 lines
hw/arm/raspi.c +3
-2@@ -22,10 +25,11 @@#define SMPBOOT_ADDR 0x300/* this should leave enough space for ATAGS */ #define MVBAR_ADDR 0x400/* secure vectors */ #define BOARDSETUP_ADDR (MVBAR_ADDR + 0x20)/* board setup code */ -#define FIRMWARE_ADDR 0x8000/* Pi loads kernel.img here by default */ +#define FIRMWARE_ADDR_2 0x8000/* Pi 2 loads kernel.img here by default */ +#define FIRMWARE_ADDR_3 0x80000/* Pi 3 loads kernel.img here by default */ /* Table of Linux board IDs for different Pi versions */ -static const int raspi_boardid[] = {[1 ] =0xc42 , [2 ] =0xc43 }; +static const int raspi_boardid[] = {[1 ] =0xc42 , [2 ] =0xc43 , [3 ] =0xc44 };
Where does the value 0xc44 comes from?
I can only find 0xc42/0xc43 defined:
https://github.com/raspberrypi/linux/blob/rpi-3.18.y/arch/arm/tools/mach-types#L525
0xc43 seems controversial, see
http://lists.infradead.org/pipermail/linux-rpi-kernel/2015-February/001268.html
addition: https://github.com/raspberrypi/linux/commit/d9fac63adac#diff-6722037d79570df5b392a49e0e006573R526
Looking at the firmware source, the r1 register is always set to the BCM2708 machine id before calling the kernel:
https://github.com/raspberrypi/tools/blob/920c7ed2ee/armstubs/armstub7.S#L133
Thanks,
Phil.
Re: [Qemu-arm] [Qemu-devel] [PATCH v2 2/3] raspi: Raspberry Pi 3 support
Dear Phil,
As you can see, the board ids are quite controversial, and bcm2837 is not listed at all. Therefore 0xc44 is just a constant to identify qemu "board". Feel free to change the id if you'd like.
About the r1 register, you've liked the wrong firmware. That's for AArch32 mode, not for AArch64 mode which the raspi3 machine type uses. In AArch64 mode, the firmware
https://github.com/raspberrypi/tools/blob/920c7ed2ee/armstubs/armstub8.S
passes only the device tree pointer in x0 and only for the primary CPU, no board id of any kind.
Yes I know that the real firmware can start a hw raspi3 board in 32 bit mode, but it's better to have 64 bit as default, as raspi2 is 32 bit only anyway. Unfortunately there's no way to autodetect if the image passed to the -kernel argument was compiled for AArch32 or AArch64 mode, the instructions are way to similarly encoded and there's no magic in raw binaries. Real hw board differentiates by checking the file name of the kernel file on the boot partition (named kernel7.img vs. kernel8.img) and parsing config.txt for arm specific options. This is not an option for qemu as it does not emulate VC GPU bootcode nor does it receive an entire boot partition with the -kernel argument. Another reason to use AArch64 for raspi3 machine is if a real board finds both kernel7.img and kernel8.img on the boot partition, then it will load the AArch64 kernel.
Cheers,
bzt
Quoted 73 lines · Philippe Mathieu-Daudé
Hi Pekka and Zoltán,
Quoted 50 lines · Pekka Enberg
This patch adds Raspberry Pi 3 support to
hw/arm/raspi.c. The differences to Pi 2 are:- Firmware address
- Board ID
- Board revisionThe CPU is different too, but that's going to be configured as part of the machine default CPU when we introduce a new machine type.
The patch was written from scratch by me but the logic is similar to Zoltán Baldaszti's previous work, which I used as a reference (with permission from the author):
https://github.com/bztsrc/qemu-raspi3
Signed-off-by Pekka Enberg <[email protected]>--- hw/arm/raspi.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-)hw/arm/raspi.c +6
-2@@ -5,6 +5,9 @@* Rasperry Pi 2 emulation Copyright (c) 2015, Microsoft * Written by Andrew Baumann * +* Raspberry Pi 3 emulation Copyright (c) 2018 Zoltán Baldaszti +* Upstream code cleanup (c) 2018 Pekka Enberg +* * This code is licensed under the GNU GPLv2 and later. */ @@ -22,10 +25,11 @@#define SMPBOOT_ADDR 0x300/* this should leave enough space for ATAGS */ #define MVBAR_ADDR 0x400/* secure vectors */ #define BOARDSETUP_ADDR (MVBAR_ADDR + 0x20)/* board setup code */ -#define FIRMWARE_ADDR 0x8000/* Pi loads kernel.img here by default */ +#define FIRMWARE_ADDR_2 0x8000/* Pi 2 loads kernel.img here by default */ +#define FIRMWARE_ADDR_3 0x80000/* Pi 3 loads kernel.img here by default */ /* Table of Linux board IDs for different Pi versions */ -static const int raspi_boardid[] = {[1] = 0xc42, [2] = 0xc43}; +static const int raspi_boardid[] = {[1] = 0xc42, [2] = 0xc43, [3] =Quoted 1 line
0xc44};Where does the value
0xc44comes from?I can only find 0xc42/0xc43 defined:
https://github.com/raspberrypi/linux/blob/rpi-3.18.y/arch/arm/tools/mach-types#L525
0xc43seems controversial, see
http://lists.infradead.org/pipermail/linux-rpi-kernel/2015-February/001268.html
addition:
https://github.com/raspberrypi/linux/commit/d9fac63adac#diff-6722037d79570df5b392a49e0e006573R526Looking at the firmware source, the r1 register is always set to the BCM2708 machine id before calling the kernel:
https://github.com/raspberrypi/tools/blob/920c7ed2ee/armstubs/armstub7.S#L133Thanks,
Phil.
PATCH v2 3/3 raspi: Add "raspi3" machine type
In reply to Pekka EnbergThis patch adds a "raspi3" machine type, which can now be selected as the machine to run on by users via the "-M" command line option to QEMU.
The machine type does *not* ignore memory transaction failures so we likely need to add some dummy devices later when people run something more complicated than what I'm using for testing.
--- hw/arm/raspi.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
hw/arm/raspi.c +23 -0
@@ -187,3 +187,26 @@ static void raspi2_machine_init(MachineClass *mc) mc->ignore_memory_transaction_failures = true; }; DEFINE_MACHINE("raspi2", raspi2_machine_init) + +#ifdef TARGET_AARCH64 +static void raspi3_init (MachineState *machine) +{ +raspi_init (machine,3 ); +} + +static void raspi3_machine_init (MachineClass *mc) +{ + mc->desc ="Raspberry Pi 3" ; + mc->init = raspi3_init; + mc->block_default_type =IF_SD ; + mc->no_parallel =1 ; + mc->no_floppy =1 ; + mc->no_cdrom =1 ; + mc->default_cpu_type =ARM_CPU_TYPE_NAME ("cortex-a53" ); + mc->max_cpus =BCM2836_NCPUS ; + mc->min_cpus =BCM2836_NCPUS ; + mc->default_cpus =BCM2836_NCPUS ; + mc->default_ram_size =1024 *1024 *1024 ; +} +DEFINE_MACHINE("raspi3", raspi3_machine_init) +#endif
Signature · 1 line
2.14.3
Quoted 13 lines · Pekka Enberg
This patch series adds support for Raspberry Pi 3 as a new machine model "raspi3", which is an extension of the "raspi2" model with the following differences:
- Default CPU type is "cortex-a53"
- Firmware is at address0x80000
- Board ID is0xc44and board revision is0xa02082The patches were written by me but I used Zoltán Baldaszti's previous work as a reference (with permission from the author):
Quoted 8 lines
Also available from:
[email protected]:penberg/qemu.git raspi3/v2
Changes from v1 to v2:
- Wrap Raspberry Pi 3 machine definition with
TARGET_AARCH64(Peter Maydell)
Hi. Patches 1 and 2 for this are already in master, and I have patch 3 queued -- it's just dependent on a bugfix (patch posted) that's needed for big-endian host systems.
thanks
-- PMM