hw/arm/raspi: Dynamically create machines based on the board revision
Subsystems (2)
v2 cover hw/arm/raspi: Dynamically create machines based on the board revision
Hi,
These patches simplify adding the raspi0/raspi1/raspi4 boards.
Igor has been working in his "refactor main RAM allocation to use hostmem backend" series, and now v4 [1] is almost reviewed.
His raspi patch [2] clashes with my work, Since it is easier for him to apply his on top of mine, I am sending these patches first.
Only the 4 first patches matter regarding Igor's refactor, to include "Extract the RAM size from the board revision" which should solve the problem he has to fix in [2].
I finally finished the SoC code, so can add the raspi0/1. Avocado tests also include to demostrate the boards work. I will probably move the raspi tests out of boot_linux_console.py, but that is another series.
Latest patches NOTFORMERGE are mostly to justify this refactor, like the raspi0 and 1, it is easy to add a new soc/board. However other bcm peripherals patches need to get merged first (on the list but old so I need to rebase/repost them).
Please review, at least up to patch 21 (before the tests).
Phil.
[1] https://www.mail-archive.com/[email protected]/msg675738.html
[2] https://www.mail-archive.com/[email protected]/msg675752.html
Supersedes: <[email protected]>
https://www.mail-archive.com/[email protected]/msg676154.html
Philippe Mathieu-Daudé (30):
hw/arm/raspi: Use BCM2708 machine type with pre Device Tree kernels hw/arm/raspi: Correct the board descriptions
hw/arm/raspi: Extract the version from the board revision hw/arm/raspi: Extract the RAM size from the board revision hw/arm/raspi: Extract the processor type from the board revision hw/arm/raspi: Trivial code movement
hw/arm/raspi: Make machines children of abstract RaspiMachineClass hw/arm/raspi: Make board_rev a field of RaspiMachineClass hw/arm/raspi: Let class_init() directly call raspi_machine_init() hw/arm/raspi: Set default RAM size to size encoded in board revision hw/arm/raspi: Extract the board model from the board revision hw/arm/raspi: Use a unique raspi_machine_class_init() method hw/arm/raspi: Extract the cores count from the board revision hw/arm/bcm2836: Restrict BCM283XClass declaration to C source hw/arm/bcm2836: QOM'ify more by adding class_init() to each SoC type hw/arm/bcm2836: Introduce BCM283XClass::core_count hw/arm/bcm2836: Only provide "enabled-cpus" property to multicore SoCs hw/arm/bcm2836: Split out common realize() code hw/arm/bcm2836: Introduce the BCM2835 SoC
hw/arm/raspi: Add the Raspberry Pi Zero machine hw/arm/raspi: Add the Raspberry Pi B+ machine tests/acceptance/boot_linux_console: Use raspi console model as key tests/acceptance/boot_linux_console: Add raspi version=2 parameter tests/acceptance/boot_linux_console: Test the raspi1 console tests/acceptance/boot_linux_console: Test the raspi0 console python/qemu/machine: Allow to use other serial consoles than default tests/acceptance/boot_linux_console: Test the raspi1 AUX console tests/acceptance: Count Raspberry Pi logos displayed on framebuffer hw/arm/bcm2836: Add the ARMv8 BCM2838
hw/arm/raspi: Add the Raspberry Pi 4
include/hw/arm/bcm2836.h | 16 +- hw/arm/bcm2836.c | 396 +++++++++++++++++++++---- hw/arm/raspi.c | 204 ++++++++++--- python/qemu/machine.py | 10 +- tests/acceptance/boot_linux_console.py | 154 +++++++++- 5 files changed, 645 insertions(+), 135 deletions(-)
Signature · 1 line
2.21.1
PATCH v2 1/30 hw/arm/raspi: Use BCM2708 machine type with pre Device Tree kernels
When booting without device tree, the Linux kernels uses the $R1 register to determine the machine type. The list of values is registered at [1].
There are two entries for the Raspberry Pi:
- https://www.arm.linux.org.uk/developer/machines/list.php?mid=3138
name: MACH_TYPE_BCM2708
value: 0xc42 (3138)
status: Active, not mainlined
date: 15 Oct 2010
- https://www.arm.linux.org.uk/developer/machines/list.php?mid=4828
name: MACH_TYPE_BCM2835
value: 4828
status: Active, mainlined
date: 6 Dec 2013
QEMU always used the non-mainlined type MACH_TYPE_BCM2708. The value 0xc43 is registered to 'MX51_GGC' (processor i.MX51), and 0xc44 to 'Western Digital Sharespace NAS' (processor Marvell 88F5182).
The Raspberry Pi foundation bootloader only sets the BCM2708 machine type, see [2] or [3]:
133 9:
134 mov r0, #0 135 ldr r1, =3138 @ BCM2708 machine id 136 ldr r2, atags @ ATAGS 137 bx r4
U-Boot only uses MACH_TYPE_BCM2708 (see [4]):
25 /*
26 * 2835 is a SKU in a series for which the 2708 is the first or primary SoC, 27 * so 2708 has historically been used rather than a dedicated 2835 ID. 28 * 29 * We don't define a machine type for bcm2709/bcm2836 since the RPi Foundation 30 * chose to use someone else's previously registered machine ID (3139, MX51_GGC) 31 * rather than obtaining a valid ID:-/ 32 * 33 * For the bcm2837, hopefully a machine type is not needed, since everything 34 * is DT. 35 */
While the definition MACH_BCM2709 with value 0xc43 was introduced in a commit described "Add 2709 platform for Raspberry Pi 2" out of the mainline Linux kernel, it does not seem used, and the platform is introduced with Device Tree support anyway (see [5] and [6]).
Remove the unused values (0xc43 introduced in commit 1df7d1f9303aef "raspi: add raspberry pi 2 machine" and 0xc44 in commit bade58166f4 "raspi: Raspberry Pi 3 support"), keeping only MACH_TYPE_BCM2708.
[1] https://www.arm.linux.org.uk/developer/machines/
[2] https://github.com/raspberrypi/tools/blob/920c7ed2e/armstubs/armstub7.S#L135
[3] https://github.com/raspberrypi/tools/blob/49719d554/armstubs/armstub7.S#L64
[4] https://gitlab.denx.de/u-boot/u-boot/blob/v2015.04/include/configs/rpi-common.h#L18
[5] https://github.com/raspberrypi/linux/commit/d9fac63adac#diff-6722037d79570df5b392a49e0e006573R526
[6] http://lists.infradead.org/pipermail/linux-rpi-kernel/2015-February/001268.html
--- hw/arm/raspi.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
hw/arm/raspi.c +2 -3
@@ -29,8 +29,7 @@#define FIRMWARE_ADDR_3 0x80000/* Pi 3 loads kernel.img here by default */ #define SPINTABLE_ADDR 0xd8/* Pi 3 bootloader spintable */ -/* Table of Linux board IDs for different Pi versions */ -static const int raspi_boardid[] = {[1 ] =0xc42 , [2 ] =0xc43 , [3 ] =0xc44 }; +#define MACH_TYPE_BCM2708 3138/* Linux board IDs */ typedef struct RasPiState { BCM283XState soc;
@@ -116,7 +115,7 @@ static void setup_boot(MachineState *machine, int version, size_t ram_size)static struct arm_boot_info binfo;int r; - binfo.board_id = raspi_boardid[version]; + binfo.board_id =MACH_TYPE_BCM2708 ; binfo.ram_size = ram_size; binfo.nb_cpus = machine->smp.cpus;
Signature · 1 line
2.21.1
Re: [PATCH v2 01/30] hw/arm/raspi: Use BCM2708 machine type with pre Device Tree kernels
Quoted 78 lines · Philippe Mathieu-Daudé
When booting without device tree, the Linux kernels uses the $R1 register to determine the machine type. The list of values is registered at [1].
There are two entries for the Raspberry Pi:
- https://www.arm.linux.org.uk/developer/machines/list.php?mid=3138
name:MACH_TYPE_BCM2708
value:0xc42(3138)
status: Active, not mainlined
date: 15 Oct 2010- https://www.arm.linux.org.uk/developer/machines/list.php?mid=4828
name:MACH_TYPE_BCM2835
value: 4828
status: Active, mainlined
date: 6 Dec 2013QEMU always used the non-mainlined type
MACH_TYPE_BCM2708. The value0xc43is registered to 'MX51_GGC' (processor i.MX51), and0xc44to 'Western Digital Sharespace NAS' (processor Marvell 88F5182).The Raspberry Pi foundation bootloader only sets the BCM2708 machine type, see [2] or [3]:
133 9:
134 mov r0, #0 135 ldr r1, =3138 @ BCM2708 machine id 136 ldr r2, atags @ ATAGS 137 bx r4U-Boot only uses
MACH_TYPE_BCM2708(see [4]):25 /*
26 * 2835 is a SKU in a series for which the 2708 is the first or primary SoC, 27 * so 2708 has historically been used rather than a dedicated 2835 ID. 28 * 29 * We don't define a machine type for bcm2709/bcm2836 since the RPi Foundation 30 * chose to use someone else's previously registered machine ID (3139, MX51_GGC) 31 * rather than obtaining a valid ID:-/ 32 * 33 * For the bcm2837, hopefully a machine type is not needed, since everything 34 * is DT. 35 */While the definition
MACH_BCM2709with value0xc43was introduced in a commit described "Add 2709 platform for Raspberry Pi 2" out of the mainline Linux kernel, it does not seem used, and the platform is introduced with Device Tree support anyway (see [5] and [6]).Remove the unused values (
0xc43introduced in commit1df7d1f9303aef"raspi: add raspberry pi 2 machine" and0xc44in commitbade58166f4"raspi: Raspberry Pi 3 support"), keeping onlyMACH_TYPE_BCM2708.[1] https://www.arm.linux.org.uk/developer/machines/
[2] https://github.com/raspberrypi/tools/blob/920c7ed2e/armstubs/armstub7.S#L135
[3] https://github.com/raspberrypi/tools/blob/49719d554/armstubs/armstub7.S#L64
[4] https://gitlab.denx.de/u-boot/u-boot/blob/v2015.04/include/configs/rpi-common.h#L18
[5] https://github.com/raspberrypi/linux/commit/d9fac63adac#diff-6722037d79570df5b392a49e0e006573R526
[6] http://lists.infradead.org/pipermail/linux-rpi-kernel/2015-February/001268.htmlCc Zoltán Baldaszti <[email protected]>Cc Pekka Enberg <[email protected]>Cc Stephen Warren <[email protected]>Cc Kshitij Soni <[email protected]>Cc Michael Chan <[email protected]>Cc Andrew Baumann <[email protected]>Reviewed-by Alistair Francis <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
hw/arm/raspi.c| 5 ++---1 file changed, 2 insertions(+), 3 deletions(-)hw/arm/raspi.c +0
-0
hw/arm/raspi.c line 33
Quoted 5 lines
hw/arm/raspi.c +0
-2@@ -29,8 +29,7 @@#define FIRMWARE_ADDR_3 0x80000/* Pi 3 loads kernel.img here by default */ #define SPINTABLE_ADDR 0xd8/* Pi 3 bootloader spintable */ -/* Table of Linux board IDs for different Pi versions */ -static const int raspi_boardid[] = {[1 ] =0xc42 , [2 ] =0xc43 , [3 ] =0xc44 };
Maybe worth a comment about why using this number (short, one line version of commit message).
Regards,
BALATON Zoltan
Quoted 14 lines
hw/arm/raspi.c +2
-1+#define MACH_TYPE_BCM2708 3138/* Linux board IDs */ typedef struct RasPiState { BCM283XState soc;@@ -116,7 +115,7 @@ static void setup_boot(MachineState *machine, int version, size_t ram_size)static struct arm_boot_info binfo;int r; - binfo.board_id = raspi_boardid[version]; + binfo.board_id =MACH_TYPE_BCM2708 ; binfo.ram_size = ram_size; binfo.nb_cpus = machine->smp.cpus;
Re: [PATCH v2 01/30] hw/arm/raspi: Use BCM2708 machine type with pre Device Tree kernels
Hi Zoltan,
Quoted 87 lines · BALATON Zoltan
Quoted 86 lines · Philippe Mathieu-Daudé
When booting without device tree, the Linux kernels uses the $R1 register to determine the machine type. The list of values is registered at [1].
There are two entries for the Raspberry Pi:
- https://www.arm.linux.org.uk/developer/machines/list.php?mid=3138
name:MACH_TYPE_BCM2708
value:0xc42(3138)
status: Active, not mainlined
date: 15 Oct 2010- https://www.arm.linux.org.uk/developer/machines/list.php?mid=4828
name:MACH_TYPE_BCM2835
value: 4828
status: Active, mainlined
date: 6 Dec 2013QEMU always used the non-mainlined type
MACH_TYPE_BCM2708. The value0xc43is registered to 'MX51_GGC' (processor i.MX51), and0xc44to 'Western Digital Sharespace NAS' (processor Marvell 88F5182).The Raspberry Pi foundation bootloader only sets the BCM2708 machine type, see [2] or [3]:
133 9:
134 mov r0, #0
135 ldr r1, =3138 @ BCM2708 machine id
136 ldr r2, atags @ ATAGS
137 bx r4U-Boot only uses
MACH_TYPE_BCM2708(see [4]):25 /*
26 * 2835 is a SKU in a series for which the 2708 is the first or primary SoC, 27 * so 2708 has historically been used rather than a dedicated 2835 ID. 28 *
29 * We don't define a machine type for bcm2709/bcm2836 since the RPi Foundation 30 * chose to use someone else's previously registered machine ID (3139,MX51_GGC) 31 * rather than obtaining a valid ID:-/
32 *
33 * For the bcm2837, hopefully a machine type is not needed, since everything 34 * is DT.
35 */While the definition
MACH_BCM2709with value0xc43was introduced in a commit described "Add 2709 platform for Raspberry Pi 2" out of the mainline Linux kernel, it does not seem used, and the platform is introduced with Device Tree support anyway (see [5] and [6]).Remove the unused values (
0xc43introduced in commit1df7d1f9303aef"raspi: add raspberry pi 2 machine" and0xc44in commitbade58166f4"raspi: Raspberry Pi 3 support"), keeping onlyMACH_TYPE_BCM2708.[1] https://www.arm.linux.org.uk/developer/machines/
[2] https://github.com/raspberrypi/tools/blob/920c7ed2e/armstubs/armstub7.S#L135[3] https://github.com/raspberrypi/tools/blob/49719d554/armstubs/armstub7.S#L64
[4] https://gitlab.denx.de/u-boot/u-boot/blob/v2015.04/include/configs/rpi-common.h#L18
[5] https://github.com/raspberrypi/linux/commit/d9fac63adac#diff-6722037d79570df5b392a49e0e006573R526
[6] http://lists.infradead.org/pipermail/linux-rpi-kernel/2015-February/001268.html
Cc Zoltán Baldaszti <[email protected]>Cc Pekka Enberg <[email protected]>Cc Stephen Warren <[email protected]>Cc Kshitij Soni <[email protected]>Cc Michael Chan <[email protected]>Cc Andrew Baumann <[email protected]>Reviewed-by Alistair Francis <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
hw/arm/raspi.c| 5 ++---1 file changed, 2 insertions(+), 3 deletions(-)hw/arm/raspi.c +0
-0@@ -29,8 +29,7 @@#define FIRMWARE_ADDR_3 0x80000/* Pi 3 loads kernel.img here by default */ #define SPINTABLE_ADDR 0xd8/* Pi 3 bootloader spintable */
Quoted 5 lines
hw/arm/raspi.c line 32
Quoted 3 lines
hw/arm/raspi.c +0
-2-/* Table of Linux board IDs for different Pi versions */ -static const int raspi_boardid[] = {[1 ] =0xc42 , [2 ] =0xc43 , [3 ] = 0xc44};Maybe worth a comment about why using this number (short, one line version of commit message).
You mean something like:
/* Registered machine type:
* https://www.arm.linux.org.uk/developer/machines/list.php?mid=3138
*/
Quoted 19 lines
Regards,
BALATON ZoltanQuoted 15 lines
hw/arm/raspi.c +1
-0+#define MACH_TYPE_BCM2708 3138/* Linux board IDs */ typedef struct RasPiState {BCM283XState soc;
hw/arm/raspi.c +1
-1@@ -116,7 +115,7 @@ static void setup_boot(MachineState *machine, int version, size_t ram_size) static struct arm_boot_info binfo; int r; - binfo.board_id = raspi_boardid[version]; + binfo.board_id = MACH_TYPE_BCM2708; binfo.ram_size = ram_size; binfo.nb_cpus = machine->smp.cpus;
Re: [PATCH v2 01/30] hw/arm/raspi: Use BCM2708 machine type with pre Device Tree kernels
Quoted 85 lines · Philippe Mathieu-Daudé
Quoted 78 lines · BALATON Zoltan
Quoted 77 lines · Philippe Mathieu-Daudé
When booting without device tree, the Linux kernels uses the $R1 register to determine the machine type. The list of values is registered at [1].
There are two entries for the Raspberry Pi:
- https://www.arm.linux.org.uk/developer/machines/list.php?mid=3138
name:MACH_TYPE_BCM2708
value:0xc42(3138)
status: Active, not mainlined
date: 15 Oct 2010- https://www.arm.linux.org.uk/developer/machines/list.php?mid=4828
name:MACH_TYPE_BCM2835
value: 4828
status: Active, mainlined
date: 6 Dec 2013QEMU always used the non-mainlined type
MACH_TYPE_BCM2708. The value0xc43is registered to 'MX51_GGC' (processor i.MX51), and0xc44to 'Western Digital Sharespace NAS' (processor Marvell 88F5182).The Raspberry Pi foundation bootloader only sets the BCM2708 machine type, see [2] or [3]:
133 9:
134 mov r0, #0
135 ldr r1, =3138 @ BCM2708 machine id
136 ldr r2, atags @ ATAGS
137 bx r4U-Boot only uses
MACH_TYPE_BCM2708(see [4]):25 /*
26 * 2835 is a SKU in a series for which the 2708 is the first or primary SoC, 27 * so 2708 has historically been used rather than a dedicated 2835 ID. 28 *
29 * We don't define a machine type for bcm2709/bcm2836 since the RPi Foundation 30 * chose to use someone else's previously registered machine ID (3139,MX51_GGC) 31 * rather than obtaining a valid ID:-/
32 *
33 * For the bcm2837, hopefully a machine type is not needed, since everything 34 * is DT.
35 */While the definition
MACH_BCM2709with value0xc43was introduced in a commit described "Add 2709 platform for Raspberry Pi 2" out of the mainline Linux kernel, it does not seem used, and the platform is introduced with Device Tree support anyway (see [5] and [6]).Remove the unused values (
0xc43introduced in commit1df7d1f9303aef"raspi: add raspberry pi 2 machine" and0xc44in commitbade58166f4"raspi: Raspberry Pi 3 support"), keeping onlyMACH_TYPE_BCM2708.[1] https://www.arm.linux.org.uk/developer/machines/
[2] https://github.com/raspberrypi/tools/blob/920c7ed2e/armstubs/armstub7.S#L135 [3] https://github.com/raspberrypi/tools/blob/49719d554/armstubs/armstub7.S#L64 [4] https://gitlab.denx.de/u-boot/u-boot/blob/v2015.04/include/configs/rpi-common.h#L18 [5] https://github.com/raspberrypi/linux/commit/d9fac63adac#diff-6722037d79570df5b392a49e0e006573R526 [6] http://lists.infradead.org/pipermail/linux-rpi-kernel/2015-February/001268.htmlCc Zoltán Baldaszti <[email protected]>Cc Pekka Enberg <[email protected]>Cc Stephen Warren <[email protected]>Cc Kshitij Soni <[email protected]>Cc Michael Chan <[email protected]>Cc Andrew Baumann <[email protected]>Reviewed-by Alistair Francis <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
hw/arm/raspi.c| 5 ++---1 file changed, 2 insertions(+), 3 deletions(-)hw/arm/raspi.c +0
-0@@ -29,8 +29,7 @@#define FIRMWARE_ADDR_3 0x80000/* Pi 3 loads kernel.img here by default */ #define SPINTABLE_ADDR 0xd8/* Pi 3 bootloader spintable */ Quoted 5 lines
hw/arm/raspi.c line 32
Quoted 3 lines
hw/arm/raspi.c +0
-2-/* Table of Linux board IDs for different Pi versions */ -static const int raspi_boardid[] = {[1 ] =0xc42 , [2 ] =0xc43 , [3 ] = 0xc44};Maybe worth a comment about why using this number (short, one line version of commit message).
Quoted 5 lines
You mean something like:
/* Registered machine type:
* https://www.arm.linux.org.uk/developer/machines/list.php?mid=3138
*/
I think a link in a comment is not very convenient (and may break if the website is ever moved) so maybe just a line to say why this particular number was chosen would be better, such as
/* This matches RPi Foundation bootloader and U-Boot */
Quoted 1 line
Quoted 1 line
+#define MACH_TYPE_BCM2708 3138 /* Linux board IDs */
The rest of the detailed explanation could be looked up in the commit message. Just suggested the comment to warn readers that this is not a mistake but a pecularity of the platform.
Regards,
BALATON Zoltan
PATCH v2 2/30 hw/arm/raspi: Correct the board descriptions
In reply to Philippe Mathieu-DaudéWe hardcode the board revision as 0xa21041 for the raspi2, and 0xa02082 for the raspi3:
166 static void raspi_init(MachineState *machine, int version)
167 {
...
194 int board_rev = version == 3 ? 0xa02082 : 0xa21041;These revision codes are for the 2B and 3B models, see:
https://www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/README.md
Correct the board description.
--- hw/arm/raspi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/arm/raspi.c +2 -2
@@ -220,7 +220,7 @@ static void raspi2_init(MachineState *machine)static void raspi2_machine_init (MachineClass *mc) { - mc->desc ="Raspberry Pi 2" ; + mc->desc ="Raspberry Pi 2B" ; mc->init = raspi2_init; mc->block_default_type =IF_SD ; mc->no_parallel =1 ;
@@ -242,7 +242,7 @@ static void raspi3_init(MachineState *machine)static void raspi3_machine_init (MachineClass *mc) { - mc->desc ="Raspberry Pi 3" ; + mc->desc ="Raspberry Pi 3B" ; mc->init = raspi3_init; mc->block_default_type =IF_SD ; mc->no_parallel =1 ;
Signature · 1 line
2.21.1
PATCH v2 3/30 hw/arm/raspi: Extract the version from the board revision
In reply to Philippe Mathieu-DaudéThe board revision encode the board version. Add a helper to extract the version, and use it.
---
Cc: Alistair Francis <[email protected]>
hw/arm/raspi.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-)
hw/arm/raspi.c +27 -4
@@ -16,6 +16,7 @@#include "qapi/error.h" #include "cpu.h" #include "hw/arm/bcm2836.h" +#include "hw/registerfields.h" #include "qemu/error-report.h" #include "hw/boards.h" #include "hw/loader.h"
@@ -36,6 +37,28 @@ typedef struct RasPiState {MemoryRegion ram; } RasPiState; +/* +* Board revision codes: +* www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/ +*/ +FIELD (REV_CODE ,REVISION ,0 ,4 ); +FIELD (REV_CODE ,TYPE ,4 ,8 ); +FIELD (REV_CODE ,PROCESSOR ,12 ,4 ); +FIELD (REV_CODE ,MANUFACTURER ,16 ,4 ); +FIELD (REV_CODE ,MEMORY_SIZE ,20 ,3 ); +FIELD (REV_CODE ,STYLE ,23 ,1 ); + +static int board_processor_id (uint32_t board_rev) +{ +assert (FIELD_EX32 (board_rev,REV_CODE ,STYLE ));/* Only new style */ +return FIELD_EX32 (board_rev,REV_CODE ,PROCESSOR ); +} + +static int board_version (uint32_t board_rev) +{ +return board_processor_id (board_rev) +1 ; +} +static void write_smpboot (ARMCPU *cpu,const struct arm_boot_info *info) {static const uint32_t smpboot[] = {
@@ -163,9 +186,10 @@ static void setup_boot(MachineState *machine, int version, size_t ram_size)arm_load_kernel (ARM_CPU (first_cpu), machine, &binfo); } -static void raspi_init (MachineState *machine,int version) +static void raspi_init (MachineState *machine,uint32_t board_rev) {RasPiState *s =g_new0 (RasPiState,1 ); +int version =board_version (board_rev);uint32_t vcram_size;DriveInfo *di;BlockBackend *blk;
@@ -191,7 +215,6 @@ static void raspi_init(MachineState *machine, int version)/* Setup the SOC */ object_property_add_const_link (OBJECT (&s->soc),"ram" ,OBJECT (&s->ram), &error_abort); -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);
@@ -215,7 +238,7 @@ static void raspi_init(MachineState *machine, int version)static void raspi2_init (MachineState *machine) { -raspi_init (machine,2 ); +raspi_init (machine,0xa21041 ); }static void raspi2_machine_init (MachineClass *mc)
@@ -237,7 +260,7 @@ DEFINE_MACHINE("raspi2", raspi2_machine_init)#ifdef TARGET_AARCH64 static void raspi3_init (MachineState *machine) { -raspi_init (machine,3 ); +raspi_init (machine,0xa02082 ); }static void raspi3_machine_init (MachineClass *mc)
Signature · 1 line
2.21.1
PATCH v2 4/30 hw/arm/raspi: Extract the RAM size from the board revision
In reply to Philippe Mathieu-DaudéThe board revision encode the amount of RAM. Add a helper to extract the RAM size, and use it.
Since the amount of RAM is fixed (it is impossible to physically modify to have more or less RAM), do not allow sizes different than the one anounced by the manufacturer.
---
Cc: Alistair Francis <[email protected]>
hw/arm/raspi.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
hw/arm/raspi.c +12 -3
@@ -13,6 +13,7 @@#include "qemu/osdep.h" #include "qemu/units.h" +#include "qemu/cutils.h" #include "qapi/error.h" #include "cpu.h" #include "hw/arm/bcm2836.h"
@@ -48,6 +49,12 @@ FIELD(REV_CODE, MANUFACTURER, 16, 4);FIELD (REV_CODE ,MEMORY_SIZE ,20 ,3 );FIELD (REV_CODE ,STYLE ,23 ,1 ); +static uint64_t board_ram_size (uint32_t board_rev) +{ +assert (FIELD_EX32 (board_rev,REV_CODE ,STYLE ));/* Only new style */ +return 256 * MiB <<FIELD_EX32 (board_rev,REV_CODE ,MEMORY_SIZE ); +} +static int board_processor_id (uint32_t board_rev) {assert (FIELD_EX32 (board_rev,REV_CODE ,STYLE ));/* Only new style */
@@ -190,15 +197,17 @@ static void raspi_init(MachineState *machine, uint32_t board_rev) {RasPiState *s =g_new0 (RasPiState,1 );int version =board_version (board_rev); +uint64_t ram_size =board_ram_size (board_rev);uint32_t vcram_size;DriveInfo *di;BlockBackend *blk;BusState *bus;DeviceState *carddev; -if (machine->ram_size >1 * GiB) { -error_report ("Requested ram size is too large for this machine: " -"maximum is 1GB" ); +if (machine->ram_size != ram_size) { +char *size_str =size_to_str (ram_size); +error_report ("This machine can only be used with %s" , size_str); +g_free (size_str);exit (1 ); }
Signature · 1 line
2.21.1
Re: [PATCH v2 04/30] hw/arm/raspi: Extract the RAM size from the board revision
Quoted 46 lines · Philippe Mathieu-Daudé
The board revision encode the amount of RAM. Add a helper to extract the RAM size, and use it.
Since the amount of RAM is fixed (it is impossible to physically modify to have more or less RAM), do not allow sizes different than the one anounced by the manufacturer.Acked-by Igor Mammedov <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
Cc: Alistair Francis <[email protected]>
hw/arm/raspi.c| 15 ++++++++++++---1 file changed, 12 insertions(+), 3 deletions(-)hw/arm/raspi.c +8
-0@@ -13,6 +13,7 @@#include "qemu/osdep.h" #include "qemu/units.h" +#include "qemu/cutils.h" #include "qapi/error.h" #include "cpu.h" #include "hw/arm/bcm2836.h" @@ -48,6 +49,12 @@ FIELD(REV_CODE, MANUFACTURER, 16, 4);FIELD (REV_CODE ,MEMORY_SIZE ,20 ,3 );FIELD (REV_CODE ,STYLE ,23 ,1 ); +static uint64_t board_ram_size (uint32_t board_rev) +{ +assert (FIELD_EX32 (board_rev,REV_CODE ,STYLE ));/* Only new style */ +return 256 * MiB <<FIELD_EX32 (board_rev,REV_CODE ,MEMORY_SIZE ); +} +static int board_processor_id (uint32_t board_rev) {assert (FIELD_EX32 (board_rev,REV_CODE ,STYLE ));/* Only new style */ @@ -190,15 +197,17 @@ static void raspi_init(MachineState *machine, uint32_t board_rev) {RasPiState *s =g_new0 (RasPiState,1 );int version =board_version (board_rev); +uint64_t ram_size =board_ram_size (board_rev);uint32_t vcram_size;DriveInfo *di;
hw/arm/raspi.c static void raspi_init(MachineState *machine, uint32_t board_rev) · line 209
Quoted 10 lines
hw/arm/raspi.c +3
-3BlockBackend *blk;BusState *bus;DeviceState *carddev; -if (machine->ram_size >1 * GiB) { -error_report ("Requested ram size is too large for this machine: " -"maximum is 1GB" ); +if (machine->ram_size != ram_size) { +char *size_str =size_to_str (ram_size); +error_report ("This machine can only be used with %s" , size_str);
Reword error message so it says it has problem with memory as this is not clear from the above and user getting it after a command line does not have context to tell what the printed number means.
Regards,
BALATON Zoltan
Quoted 5 lines
hw/arm/raspi.c +1
-0+g_free (size_str);exit (1 ); }
PATCH v2 5/30 hw/arm/raspi: Extract the processor type from the board revision
In reply to Philippe Mathieu-DaudéThe board revision encode the processor type. Add a helper to extract the type, and use it.
--- hw/arm/raspi.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
hw/arm/raspi.c +16 -2
@@ -66,6 +66,21 @@ static int board_version(uint32_t board_rev)return board_processor_id (board_rev) +1 ; } +static const char *board_soc_type (uint32_t board_rev) +{ +static const char *soc_types[] = { +NULL ,TYPE_BCM2836 ,TYPE_BCM2837 , + }; +int proc_id =board_processor_id (board_rev); + +if (proc_id >=ARRAY_SIZE (soc_types) || !soc_types[proc_id]) { +error_report ("Unsupported processor id '%d' (board revision: 0x%x)" , + proc_id, board_rev); +exit (1 ); + } +return soc_types[proc_id]; +} +static void write_smpboot (ARMCPU *cpu,const struct arm_boot_info *info) {static const uint32_t smpboot[] = {
@@ -212,8 +227,7 @@ static void raspi_init(MachineState *machine, uint32_t board_rev) }object_initialize_child (OBJECT (machine),"soc" , &s->soc,sizeof (s->soc), - version ==3 ?TYPE_BCM2837 :TYPE_BCM2836 , - &error_abort,NULL ); +board_soc_type (board_rev), &error_abort,NULL );/* Allocate and map RAM */ memory_region_allocate_system_memory(&s->ram, OBJECT(machine), "ram",
Signature · 1 line
2.21.1
PATCH v2 6/30 hw/arm/raspi: Trivial code movement
In reply to Philippe Mathieu-DaudéThere is no point in creating the SoC object before allocating the RAM. Move the call to keep all the SoC-related calls together.
--- hw/arm/raspi.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
hw/arm/raspi.c +2 -3
@@ -226,9 +226,6 @@ static void raspi_init(MachineState *machine, uint32_t board_rev)exit (1 ); } -object_initialize_child (OBJECT (machine),"soc" , &s->soc,sizeof (s->soc), -board_soc_type (board_rev), &error_abort,NULL ); -/* Allocate and map RAM */ memory_region_allocate_system_memory (&s->ram,OBJECT (machine),"ram" , machine->ram_size);
@@ -236,6 +233,8 @@ static void raspi_init(MachineState *machine, uint32_t board_rev)memory_region_add_subregion_overlap (get_system_memory (),0 , &s->ram,0 );/* Setup the SOC */ +object_initialize_child (OBJECT (machine),"soc" , &s->soc,sizeof (s->soc), +board_soc_type (board_rev), &error_abort,NULL );object_property_add_const_link (OBJECT (&s->soc),"ram" ,OBJECT (&s->ram), &error_abort); object_property_set_int(OBJECT(&s->soc), board_rev, "board-rev",
Signature · 1 line
2.21.1
PATCH v2 7/30 hw/arm/raspi: Make machines children of abstract RaspiMachineClass
In reply to Philippe Mathieu-DaudéQOM'ify RaspiMachineState. Now machines inherite of RaspiMachineClass.
--- hw/arm/raspi.c | 56 +++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 49 insertions(+), 7 deletions(-)
hw/arm/raspi.c +49 -7
@@ -33,10 +33,28 @@#define MACH_TYPE_BCM2708 3138/* Linux board IDs */ -typedef struct RasPiState { +typedef struct RaspiMachineState { +/*< private >*/ +MachineState parent_obj; +/*< public >*/ BCM283XState soc;MemoryRegion ram; -}RasPiState ; +}RaspiMachineState ; + +typedef struct RaspiMachineClass { +/*< private >*/ +MachineClass parent_obj; +/*< public >*/ +}RaspiMachineClass ; + +#define TYPE_RASPI_MACHINE MACHINE_TYPE_NAME("raspi-common") +#define RASPI_MACHINE (obj) \ + OBJECT_CHECK(RaspiMachineState, (obj), TYPE_RASPI_MACHINE) + +#define RASPI_MACHINE_CLASS (klass) \ + OBJECT_CLASS_CHECK(RaspiMachineClass, (klass), TYPE_RASPI_MACHINE) +#define RASPI_MACHINE_GET_CLASS (obj) \ + OBJECT_GET_CLASS(RaspiMachineClass, (obj), TYPE_RASPI_MACHINE)/* * Board revision codes:
@@ -210,7 +228,7 @@ static void setup_boot(MachineState *machine, int version, size_t ram_size)static void raspi_init (MachineState *machine,uint32_t board_rev) { -RasPiState *s =g_new0 (RasPiState,1 ); +RaspiMachineState *s =RASPI_MACHINE (machine);int version =board_version (board_rev);uint64_t ram_size =board_ram_size (board_rev);uint32_t vcram_size;
@@ -263,8 +281,10 @@ static void raspi2_init(MachineState *machine)raspi_init (machine,0xa21041 ); } -static void raspi2_machine_init (MachineClass *mc) +static void raspi2_machine_class_init (ObjectClass *oc,void *data) { +MachineClass *mc =MACHINE_CLASS (oc); + mc->desc ="Raspberry Pi 2B" ; mc->init = raspi2_init; mc->block_default_type =IF_SD ;
@@ -277,7 +297,6 @@ static void raspi2_machine_init(MachineClass *mc) mc->default_ram_size =1 * GiB; mc->ignore_memory_transaction_failures = true; }; -DEFINE_MACHINE("raspi2", raspi2_machine_init)#ifdef TARGET_AARCH64 static void raspi3_init (MachineState *machine)
@@ -285,8 +304,10 @@ static void raspi3_init(MachineState *machine)raspi_init (machine,0xa02082 ); } -static void raspi3_machine_init (MachineClass *mc) +static void raspi3_machine_class_init (ObjectClass *oc,void *data) { +MachineClass *mc =MACHINE_CLASS (oc); + mc->desc ="Raspberry Pi 3B" ; mc->init = raspi3_init; mc->block_default_type =IF_SD ;
@@ -298,5 +319,26 @@ static void raspi3_machine_init(MachineClass *mc) mc->default_cpus =BCM283X_NCPUS ; mc->default_ram_size =1 * GiB; } -DEFINE_MACHINE("raspi3", raspi3_machine_init)#endif + +static const TypeInfo raspi_machine_types[] = { + { + .name =MACHINE_TYPE_NAME ("raspi2" ), + .parent =TYPE_RASPI_MACHINE , + .class_init = raspi2_machine_class_init, +#ifdef TARGET_AARCH64 + }, { + .name =MACHINE_TYPE_NAME ("raspi3" ), + .parent =TYPE_RASPI_MACHINE , + .class_init = raspi3_machine_class_init, +#endif + }, { + .name =TYPE_RASPI_MACHINE , + .parent =TYPE_MACHINE , + .instance_size =sizeof (RaspiMachineState), + .class_size =sizeof (RaspiMachineClass), + .abstract = true, + } +}; + +DEFINE_TYPES (raspi_machine_types)
Signature · 1 line
2.21.1
Re: [PATCH v2 07/30] hw/arm/raspi: Make machines children of abstract RaspiMachineClass
Quoted 1 line · Philippe Mathieu-Daudé
QOM'ify RaspiMachineState. Now machines inherite of RaspiMachineClass.
Typo: inherite -> inherit
Regards,
BALATON Zoltan
Quoted 112 lines
Cc Igor Mammedov <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
hw/arm/raspi.c| 56 +++++++++++++++++++++++++++++++++++++++++++-------1 file changed, 49 insertions(+), 7 deletions(-)hw/arm/raspi.c +49
-7@@ -33,10 +33,28 @@#define MACH_TYPE_BCM2708 3138/* Linux board IDs */ -typedef struct RasPiState { +typedef struct RaspiMachineState { +/*< private >*/ +MachineState parent_obj; +/*< public >*/ BCM283XState soc;MemoryRegion ram; -}RasPiState ; +}RaspiMachineState ; + +typedef struct RaspiMachineClass { +/*< private >*/ +MachineClass parent_obj; +/*< public >*/ +}RaspiMachineClass ; + +#define TYPE_RASPI_MACHINE MACHINE_TYPE_NAME("raspi-common") +#define RASPI_MACHINE (obj) \ + OBJECT_CHECK(RaspiMachineState, (obj), TYPE_RASPI_MACHINE) + +#define RASPI_MACHINE_CLASS (klass) \ + OBJECT_CLASS_CHECK(RaspiMachineClass, (klass), TYPE_RASPI_MACHINE) +#define RASPI_MACHINE_GET_CLASS (obj) \ + OBJECT_GET_CLASS(RaspiMachineClass, (obj), TYPE_RASPI_MACHINE)/* * Board revision codes: @@ -210,7 +228,7 @@ static void setup_boot(MachineState *machine, int version, size_t ram_size)static void raspi_init (MachineState *machine,uint32_t board_rev) { -RasPiState *s =g_new0 (RasPiState,1 ); +RaspiMachineState *s =RASPI_MACHINE (machine);int version =board_version (board_rev);uint64_t ram_size =board_ram_size (board_rev);uint32_t vcram_size;@@ -263,8 +281,10 @@ static void raspi2_init(MachineState *machine)raspi_init (machine,0xa21041 ); } -static void raspi2_machine_init (MachineClass *mc) +static void raspi2_machine_class_init (ObjectClass *oc,void *data) { +MachineClass *mc =MACHINE_CLASS (oc); + mc->desc ="Raspberry Pi 2B" ; mc->init = raspi2_init; mc->block_default_type =IF_SD ;@@ -277,7 +297,6 @@ static void raspi2_machine_init(MachineClass *mc) mc->default_ram_size =1 * GiB; mc->ignore_memory_transaction_failures = true; }; -DEFINE_MACHINE("raspi2", raspi2_machine_init)#ifdef TARGET_AARCH64 static void raspi3_init (MachineState *machine)@@ -285,8 +304,10 @@ static void raspi3_init(MachineState *machine)raspi_init (machine,0xa02082 ); } -static void raspi3_machine_init (MachineClass *mc) +static void raspi3_machine_class_init (ObjectClass *oc,void *data) { +MachineClass *mc =MACHINE_CLASS (oc); + mc->desc ="Raspberry Pi 3B" ; mc->init = raspi3_init; mc->block_default_type =IF_SD ;@@ -298,5 +319,26 @@ static void raspi3_machine_init(MachineClass *mc) mc->default_cpus =BCM283X_NCPUS ; mc->default_ram_size =1 * GiB; } -DEFINE_MACHINE("raspi3", raspi3_machine_init)#endif + +static const TypeInfo raspi_machine_types[] = { + { + .name =MACHINE_TYPE_NAME ("raspi2" ), + .parent =TYPE_RASPI_MACHINE , + .class_init = raspi2_machine_class_init, +#ifdef TARGET_AARCH64 + }, { + .name =MACHINE_TYPE_NAME ("raspi3" ), + .parent =TYPE_RASPI_MACHINE , + .class_init = raspi3_machine_class_init, +#endif + }, { + .name =TYPE_RASPI_MACHINE , + .parent =TYPE_MACHINE , + .instance_size =sizeof (RaspiMachineState), + .class_size =sizeof (RaspiMachineClass), + .abstract = true, + } +}; + +DEFINE_TYPES (raspi_machine_types)
PATCH v2 8/30 hw/arm/raspi: Make board_rev a field of RaspiMachineClass
In reply to Philippe Mathieu-DaudéWe want to have a common class_init(). The only value that matters (and changes) is the board revision.
Pass the board_rev as class_data to class_init().
--- hw/arm/raspi.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
hw/arm/raspi.c +14 -3
@@ -45,6 +45,7 @@ typedef struct RaspiMachineClass {/*< private >*/ MachineClass parent_obj;/*< public >*/ +uint32_t board_rev; } RaspiMachineClass;#define TYPE_RASPI_MACHINE MACHINE_TYPE_NAME("raspi-common")
@@ -226,9 +227,11 @@ static void setup_boot(MachineState *machine, int version, size_t ram_size)arm_load_kernel (ARM_CPU (first_cpu), machine, &binfo); } -static void raspi_init (MachineState *machine,uint32_t board_rev) +static void raspi_init (MachineState *machine) { +RaspiMachineClass *mc =RASPI_MACHINE_GET_CLASS (machine);RaspiMachineState *s =RASPI_MACHINE (machine); +uint32_t board_rev = mc->board_rev;int version =board_version (board_rev);uint64_t ram_size =board_ram_size (board_rev);uint32_t vcram_size;
@@ -278,13 +281,16 @@ static void raspi_init(MachineState *machine, uint32_t board_rev)static void raspi2_init (MachineState *machine) { -raspi_init (machine,0xa21041 ); +raspi_init (machine); }static void raspi2_machine_class_init (ObjectClass *oc,void *data) {MachineClass *mc =MACHINE_CLASS (oc); +RaspiMachineClass *rmc =RASPI_MACHINE_CLASS (oc); +uint32_t board_rev = (uint32_t )(uintptr_t )data; + rmc->board_rev = board_rev; mc->desc ="Raspberry Pi 2B" ; mc->init = raspi2_init; mc->block_default_type =IF_SD ;
@@ -301,13 +307,16 @@ static void raspi2_machine_class_init(ObjectClass *oc, void *data)#ifdef TARGET_AARCH64 static void raspi3_init (MachineState *machine) { -raspi_init (machine,0xa02082 ); +raspi_init (machine); }static void raspi3_machine_class_init (ObjectClass *oc,void *data) {MachineClass *mc =MACHINE_CLASS (oc); +RaspiMachineClass *rmc =RASPI_MACHINE_CLASS (oc); +uint32_t board_rev = (uint32_t )(uintptr_t )data; + rmc->board_rev = board_rev; mc->desc ="Raspberry Pi 3B" ; mc->init = raspi3_init; mc->block_default_type =IF_SD ;
@@ -326,11 +335,13 @@ static const TypeInfo raspi_machine_types[] = { .name = MACHINE_TYPE_NAME("raspi2"), .parent = TYPE_RASPI_MACHINE, .class_init = raspi2_machine_class_init, + .class_data = (void *)0xa21041,#ifdef TARGET_AARCH64 }, { .name = MACHINE_TYPE_NAME("raspi3"), .parent = TYPE_RASPI_MACHINE, .class_init = raspi3_machine_class_init, + .class_data = (void *)0xa02082,#endif }, { .name = TYPE_RASPI_MACHINE,
Signature · 1 line
2.21.1
PATCH v2 9/30 hw/arm/raspi: Let class_init() directly call raspi_machine_init()
In reply to Philippe Mathieu-Daudéraspi_machine_init() access to board_rev via RaspiMachineClass. raspi2_init() and raspi3_init() do nothing. Call raspi_machine_init directly.
---
Squash with previous?
--- hw/arm/raspi.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-)
hw/arm/raspi.c +3 -13
@@ -227,7 +227,7 @@ static void setup_boot(MachineState *machine, int version, size_t ram_size)arm_load_kernel (ARM_CPU (first_cpu), machine, &binfo); } -static void raspi_init (MachineState *machine) +static void raspi_machine_init (MachineState *machine) {RaspiMachineClass *mc =RASPI_MACHINE_GET_CLASS (machine);RaspiMachineState *s =RASPI_MACHINE (machine);
@@ -279,11 +279,6 @@ static void raspi_init(MachineState *machine)setup_boot (machine, version, machine->ram_size - vcram_size); } -static void raspi2_init (MachineState *machine) -{ -raspi_init (machine); -} -static void raspi2_machine_class_init (ObjectClass *oc,void *data) {MachineClass *mc =MACHINE_CLASS (oc);
@@ -292,7 +287,7 @@ static void raspi2_machine_class_init(ObjectClass *oc, void *data) rmc->board_rev = board_rev; mc->desc ="Raspberry Pi 2B" ; - mc->init = raspi2_init; + mc->init = raspi_machine_init; mc->block_default_type =IF_SD ; mc->no_parallel =1 ; mc->no_floppy =1 ;
@@ -305,11 +300,6 @@ static void raspi2_machine_class_init(ObjectClass *oc, void *data) };#ifdef TARGET_AARCH64 -static void raspi3_init (MachineState *machine) -{ -raspi_init (machine); -} -static void raspi3_machine_class_init (ObjectClass *oc,void *data) {MachineClass *mc =MACHINE_CLASS (oc);
@@ -318,7 +308,7 @@ static void raspi3_machine_class_init(ObjectClass *oc, void *data) rmc->board_rev = board_rev; mc->desc ="Raspberry Pi 3B" ; - mc->init = raspi3_init; + mc->init = raspi_machine_init; mc->block_default_type =IF_SD ; mc->no_parallel =1 ; mc->no_floppy =1 ;
Signature · 1 line
2.21.1
PATCH v2 10/30 hw/arm/raspi: Set default RAM size to size encoded in board revision
In reply to Philippe Mathieu-DaudéWe added a helper to extract the RAM size from the board revision, and made board_rev a field of RaspiMachineClass. The class_init() can now use the helper to extract from the board revision the board-specific amount of RAM.
--- hw/arm/raspi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/arm/raspi.c +2 -2
@@ -295,7 +295,7 @@ static void raspi2_machine_class_init(ObjectClass *oc, void *data) mc->max_cpus =BCM283X_NCPUS ; mc->min_cpus =BCM283X_NCPUS ; mc->default_cpus =BCM283X_NCPUS ; - mc->default_ram_size =1 * GiB; + mc->default_ram_size =board_ram_size (board_rev); mc->ignore_memory_transaction_failures = true; };
@@ -316,7 +316,7 @@ static void raspi3_machine_class_init(ObjectClass *oc, void *data) mc->max_cpus =BCM283X_NCPUS ; mc->min_cpus =BCM283X_NCPUS ; mc->default_cpus =BCM283X_NCPUS ; - mc->default_ram_size = 1 * GiB; + mc->default_ram_size = board_ram_size(board_rev); }#endif
Signature · 1 line
2.21.1
PATCH v2 11/30 hw/arm/raspi: Extract the board model from the board revision
In reply to Philippe Mathieu-DaudéThe board revision encode the model type. Add a helper to extract the model, and use it.
--- hw/arm/raspi.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
hw/arm/raspi.c +16 -2
@@ -100,6 +100,20 @@ static const char *board_soc_type(uint32_t board_rev)return soc_types[proc_id]; } +static const char *board_type (uint32_t board_rev) +{ +static const char *types[] = { +"A" ,"B" ,"A+" ,"B+" ,"2B" ,"Alpha" ,"CM1" ,NULL ,"3B" ,"Zero" , +"CM3" ,NULL ,"Zero W" ,"3B+" ,"3A+" ,NULL ,"CM3+" ,"4B" , + }; +assert (FIELD_EX32 (board_rev,REV_CODE ,STYLE ));/* Only new style */ +int bt =FIELD_EX32 (board_rev,REV_CODE ,TYPE ); +if (bt >=ARRAY_SIZE (types) || !types[bt]) { +return "Unknown" ; + } +return types[bt]; +} +static void write_smpboot (ARMCPU *cpu,const struct arm_boot_info *info) {static const uint32_t smpboot[] = {
@@ -286,7 +300,7 @@ static void raspi2_machine_class_init(ObjectClass *oc, void *data)uint32_t board_rev = (uint32_t )(uintptr_t )data; rmc->board_rev = board_rev; - mc->desc ="Raspberry Pi 2B" ; + mc->desc =g_strdup_printf ("Raspberry Pi %s" ,board_type (board_rev)); mc->init = raspi_machine_init; mc->block_default_type =IF_SD ; mc->no_parallel =1 ;
@@ -307,7 +321,7 @@ static void raspi3_machine_class_init(ObjectClass *oc, void *data)uint32_t board_rev = (uint32_t )(uintptr_t )data; rmc->board_rev = board_rev; - mc->desc ="Raspberry Pi 3B" ; + mc->desc =g_strdup_printf ("Raspberry Pi %s" ,board_type (board_rev)); mc->init = raspi_machine_init; mc->block_default_type =IF_SD ; mc->no_parallel =1 ;
Signature · 1 line
2.21.1
PATCH v2 12/30 hw/arm/raspi: Use a unique raspi_machine_class_init() method
In reply to Philippe Mathieu-DaudéWith the exception of the ignore_memory_transaction_failures flag set for the raspi2, both machine_class_init() methods are now identical. Merge them to keep a unique method.
--- hw/arm/raspi.c | 31 ++++++------------------------- 1 file changed, 6 insertions(+), 25 deletions(-)
hw/arm/raspi.c +6 -25
@@ -293,7 +293,7 @@ static void raspi_machine_init(MachineState *machine)setup_boot (machine, version, machine->ram_size - vcram_size); } -static void raspi2_machine_class_init (ObjectClass *oc,void *data) +static void raspi_machine_class_init (ObjectClass *oc,void *data) {MachineClass *mc =MACHINE_CLASS (oc);RaspiMachineClass *rmc =RASPI_MACHINE_CLASS (oc);
@@ -310,41 +310,22 @@ static void raspi2_machine_class_init(ObjectClass *oc, void *data) mc->min_cpus =BCM283X_NCPUS ; mc->default_cpus =BCM283X_NCPUS ; mc->default_ram_size =board_ram_size (board_rev); - mc->ignore_memory_transaction_failures = true; +if (board_version (board_rev) ==2 ) { + mc->ignore_memory_transaction_failures = true; + } }; -#ifdef TARGET_AARCH64 -static void raspi3_machine_class_init (ObjectClass *oc,void *data) -{ -MachineClass *mc =MACHINE_CLASS (oc); -RaspiMachineClass *rmc =RASPI_MACHINE_CLASS (oc); -uint32_t board_rev = (uint32_t )(uintptr_t )data; - - rmc->board_rev = board_rev; - mc->desc =g_strdup_printf ("Raspberry Pi %s" ,board_type (board_rev)); - mc->init = raspi_machine_init; - mc->block_default_type =IF_SD ; - mc->no_parallel =1 ; - mc->no_floppy =1 ; - mc->no_cdrom =1 ; - mc->max_cpus =BCM283X_NCPUS ; - mc->min_cpus =BCM283X_NCPUS ; - mc->default_cpus =BCM283X_NCPUS ; - mc->default_ram_size =board_ram_size (board_rev); -} -#endif -static const TypeInfo raspi_machine_types[] = { { .name =MACHINE_TYPE_NAME ("raspi2" ), .parent =TYPE_RASPI_MACHINE , - .class_init = raspi2_machine_class_init, + .class_init = raspi_machine_class_init, .class_data = (void *)0xa21041 , #ifdef TARGET_AARCH64 }, { .name =MACHINE_TYPE_NAME ("raspi3" ), .parent =TYPE_RASPI_MACHINE , - .class_init = raspi3_machine_class_init, + .class_init = raspi_machine_class_init, .class_data = (void *)0xa02082 , #endif }, {
Signature · 1 line
2.21.1
PATCH v2 13/30 hw/arm/raspi: Extract the cores count from the board revision
In reply to Philippe Mathieu-DaudéThe board revision encode the count of ARM cores. Add a helper to extract the number of cores, and use it. This will be helpful when we add the Raspi0/1 that have a single core.
--- hw/arm/raspi.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-)
hw/arm/raspi.c +16 -3
@@ -100,6 +100,21 @@ static const char *board_soc_type(uint32_t board_rev)return soc_types[proc_id]; } +static int cores_count (uint32_t board_rev) +{ +static const int soc_cores_count[] = { +0 ,BCM283X_NCPUS ,BCM283X_NCPUS , + }; +int proc_id =board_processor_id (board_rev); + +if (proc_id >=ARRAY_SIZE (soc_cores_count) || !soc_cores_count[proc_id]) { +error_report ("Unsupported processor id '%d' (board revision: 0x%x)" , + proc_id, board_rev); +exit (1 ); + } +return soc_cores_count[proc_id]; +} +static const char *board_type (uint32_t board_rev) {static const char *types[] = {
@@ -306,9 +321,7 @@ static void raspi_machine_class_init(ObjectClass *oc, void *data) mc->no_parallel =1 ; mc->no_floppy =1 ; mc->no_cdrom =1 ; - mc->max_cpus =BCM283X_NCPUS ; - mc->min_cpus =BCM283X_NCPUS ; - mc->default_cpus =BCM283X_NCPUS ; + mc->default_cpus = mc->min_cpus = mc->max_cpus =cores_count (board_rev); mc->default_ram_size =board_ram_size (board_rev);if (board_version (board_rev) ==2 ) { mc->ignore_memory_transaction_failures = true;
Signature · 1 line
2.21.1
PATCH v2 14/30 hw/arm/bcm2836: Restrict BCM283XClass declaration to C source
In reply to Philippe Mathieu-DaudéNo code out of bcm2836.c uses (or requires) this declarations. Move it locally to the C source file.
--- include/hw/arm/bcm2836.h | 12 ------------ hw/arm/bcm2836.c | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 12 deletions(-)
include/hw/arm/bcm2836.h +0 -12
@@ -42,16 +42,4 @@ typedef struct BCM283XState { BCM2835PeripheralState peripherals; } BCM283XState; -typedef struct BCM283XInfo BCM283XInfo ; - -typedef struct BCM283XClass { -DeviceClass parent_class; -const BCM283XInfo *info; -}BCM283XClass ; - -#define BCM283X_CLASS (klass) \ - OBJECT_CLASS_CHECK(BCM283XClass, (klass), TYPE_BCM283X) -#define BCM283X_GET_CLASS (obj) \ - OBJECT_GET_CLASS(BCM283XClass, (obj), TYPE_BCM283X) -#endif /* BCM2836_H */
hw/arm/bcm2836.c +14 -0
@@ -16,6 +16,15 @@#include "hw/arm/raspi_platform.h" #include "hw/sysbus.h" +typedef struct BCM283XInfo BCM283XInfo ; + +typedef struct BCM283XClass { +/*< private >*/ +DeviceClass parent_class; +/*< public >*/ +const BCM283XInfo *info; +}BCM283XClass ; +struct BCM283XInfo {const char *name;const char *cpu_type;
@@ -24,6 +33,11 @@ struct BCM283XInfo {int clusterid; }; +#define BCM283X_CLASS (klass) \ + OBJECT_CLASS_CHECK(BCM283XClass, (klass), TYPE_BCM283X) +#define BCM283X_GET_CLASS (obj) \ + OBJECT_GET_CLASS(BCM283XClass, (obj), TYPE_BCM283X) +static const BCM283XInfo bcm283x_socs[] = { { .name =TYPE_BCM2836 ,
Signature · 1 line
2.21.1
PATCH v2 15/30 hw/arm/bcm2836: QOM'ify more by adding class_init() to each SoC type
In reply to Philippe Mathieu-DaudéRemove usage of TypeInfo::class_data. Instead fill the fields in the corresponding class_init().
--- hw/arm/bcm2836.c | 109 ++++++++++++++++++++++------------------------- 1 file changed, 51 insertions(+), 58 deletions(-)
hw/arm/bcm2836.c +51 -58
@@ -16,57 +16,30 @@#include "hw/arm/raspi_platform.h" #include "hw/sysbus.h" -typedef struct BCM283XInfo BCM283XInfo ; -typedef struct BCM283XClass {/*< private >*/ DeviceClass parent_class;/*< public >*/ -const BCM283XInfo *info; -}BCM283XClass ; - -struct BCM283XInfo { -const char *name;const char *cpu_type;hwaddr peri_base;/* Peripheral base address seen by the CPU */ hwaddr ctrl_base;/* Interrupt controller and mailboxes etc. */ int clusterid; -}; +}BCM283XClass ;#define BCM283X_CLASS (klass) \ OBJECT_CLASS_CHECK(BCM283XClass, (klass), TYPE_BCM283X)#define BCM283X_GET_CLASS (obj) \ OBJECT_GET_CLASS(BCM283XClass, (obj), TYPE_BCM283X) -static const BCM283XInfo bcm283x_socs[] = { - { - .name =TYPE_BCM2836 , - .cpu_type =ARM_CPU_TYPE_NAME ("cortex-a7" ), - .peri_base =0x3f000000 , - .ctrl_base =0x40000000 , - .clusterid =0xf , - }, -#ifdef TARGET_AARCH64 - { - .name =TYPE_BCM2837 , - .cpu_type =ARM_CPU_TYPE_NAME ("cortex-a53" ), - .peri_base =0x3f000000 , - .ctrl_base =0x40000000 , - .clusterid =0x0 , - }, -#endif -}; -static void bcm2836_init (Object *obj) {BCM283XState *s =BCM283X (obj);BCM283XClass *bc =BCM283X_GET_CLASS (obj); -const BCM283XInfo *info = bc->info;int n;for (n =0 ; n <BCM283X_NCPUS ; n++) {object_initialize_child (obj,"cpu[*]" , &s->cpu[n].core, -sizeof (s->cpu[n].core), info->cpu_type, +sizeof (s->cpu[n].core), bc->cpu_type, &error_abort,NULL ); }
@@ -85,7 +58,6 @@ static void bcm2836_realize(DeviceState *dev, Error **errp) {BCM283XState *s =BCM283X (dev);BCM283XClass *bc =BCM283X_GET_CLASS (dev); -const BCM283XInfo *info = bc->info;Object *obj;Error *err =NULL ;int n;
@@ -119,7 +91,7 @@ static void bcm2836_realize(DeviceState *dev, Error **errp) }sysbus_mmio_map_overlap (SYS_BUS_DEVICE (&s->peripherals),0 , - info->peri_base,1 ); + bc->peri_base,1 );/* bcm2836 interrupt controller (and mailboxes, etc.) */ object_property_set_bool (OBJECT (&s->control), true,"realized" , &err);
@@ -128,7 +100,7 @@ static void bcm2836_realize(DeviceState *dev, Error **errp)return ; } -sysbus_mmio_map (SYS_BUS_DEVICE (&s->control),0 , info->ctrl_base); +sysbus_mmio_map (SYS_BUS_DEVICE (&s->control),0 , bc->ctrl_base);sysbus_connect_irq (SYS_BUS_DEVICE (&s->peripherals),0 ,qdev_get_gpio_in_named (DEVICE (&s->control),"gpu-irq" ,0 ));
@@ -137,11 +109,11 @@ static void bcm2836_realize(DeviceState *dev, Error **errp)for (n =0 ; n <BCM283X_NCPUS ; n++) {/* TODO: this should be converted to a property of ARM_CPU */ - s->cpu[n].core.mp_affinity = (info->clusterid <<8 ) | n; + s->cpu[n].core.mp_affinity = (bc->clusterid <<8 ) | n;/* set periphbase/CBAR value for CPU-local registers */ object_property_set_int (OBJECT (&s->cpu[n].core), - info->peri_base, + bc->peri_base,"reset-cbar" , &err);if (err) {error_propagate (errp, err);
@@ -190,38 +162,59 @@ static Property bcm2836_props[] = {static void bcm283x_class_init (ObjectClass *oc,void *data) {DeviceClass *dc =DEVICE_CLASS (oc); -BCM283XClass *bc =BCM283X_CLASS (oc); - bc->info = data; - dc->realize = bcm2836_realize; -device_class_set_props (dc, bcm2836_props);/* Reason: Must be wired up in code (see raspi_init() function) */ dc->user_creatable = false; } -static const TypeInfo bcm283x_type_info = { - .name =TYPE_BCM283X , - .parent =TYPE_DEVICE , - .instance_size =sizeof (BCM283XState), - .instance_init = bcm2836_init, - .class_size =sizeof (BCM283XClass), - .abstract = true, +static void bcm2836_class_init (ObjectClass *oc,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (oc); +BCM283XClass *bc =BCM283X_CLASS (oc); + + bc->cpu_type =ARM_CPU_TYPE_NAME ("cortex-a7" ); + bc->peri_base =0x3f000000 ; + bc->ctrl_base =0x40000000 ; + bc->clusterid =0xf ; + dc->realize = bcm2836_realize; +device_class_set_props (dc, bcm2836_props); }; -static void bcm2836_register_types (void ) +#ifdef TARGET_AARCH64 +static void bcm2837_class_init (ObjectClass *oc,void *data) { -int i; +DeviceClass *dc =DEVICE_CLASS (oc); +BCM283XClass *bc =BCM283X_CLASS (oc); -type_register_static (&bcm283x_type_info); -for (i =0 ; i <ARRAY_SIZE (bcm283x_socs); i++) { -TypeInfo ti = { - .name = bcm283x_socs[i].name, - .parent =TYPE_BCM283X , - .class_init = bcm283x_class_init, - .class_data = (void *) &bcm283x_socs[i], - }; -type_register (&ti); + bc->cpu_type =ARM_CPU_TYPE_NAME ("cortex-a53" ); + bc->peri_base =0x3f000000 ; + bc->ctrl_base =0x40000000 ; + bc->clusterid =0x0 ; + dc->realize = bcm2836_realize; +device_class_set_props (dc, bcm2836_props); +}; +#endif + +static const TypeInfo bcm283x_types[] = { + { + .name =TYPE_BCM2836 , + .parent =TYPE_BCM283X , + .class_init = bcm2836_class_init, +#ifdef TARGET_AARCH64 + }, { + .name =TYPE_BCM2837 , + .parent =TYPE_BCM283X , + .class_init = bcm2837_class_init, +#endif + }, { + .name =TYPE_BCM283X , + .parent =TYPE_DEVICE , + .instance_size =sizeof (BCM283XState), + .instance_init = bcm2836_init, + .class_size =sizeof (BCM283XClass), + .class_init = bcm283x_class_init, + .abstract = true, } -} +}; -type_init (bcm2836_register_types) +DEFINE_TYPES (bcm283x_types)
Signature · 1 line
2.21.1
PATCH v2 16/30 hw/arm/bcm2836: Introduce BCM283XClass::core_count
In reply to Philippe Mathieu-DaudéThe BCM2835 has only one core. Introduce the core_count field to be able to use values different than BCM283X_NCPUS (4).
--- hw/arm/bcm2836.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
hw/arm/bcm2836.c +5 -2
@@ -21,6 +21,7 @@ typedef struct BCM283XClass {DeviceClass parent_class;/*< public >*/ const char *cpu_type; +int core_count;hwaddr peri_base;/* Peripheral base address seen by the CPU */ hwaddr ctrl_base;/* Interrupt controller and mailboxes etc. */ int clusterid;
@@ -37,7 +38,7 @@ static void bcm2836_init(Object *obj)BCM283XClass *bc =BCM283X_GET_CLASS (obj);int n; -for (n =0 ; n <BCM283X_NCPUS ; n++) { +for (n =0 ; n < bc->core_count; n++) {object_initialize_child (obj,"cpu[*]" , &s->cpu[n].core,sizeof (s->cpu[n].core), bc->cpu_type, &error_abort,NULL );
@@ -107,7 +108,7 @@ static void bcm2836_realize(DeviceState *dev, Error **errp)sysbus_connect_irq (SYS_BUS_DEVICE (&s->peripherals),1 ,qdev_get_gpio_in_named (DEVICE (&s->control),"gpu-fiq" ,0 )); -for (n =0 ; n <BCM283X_NCPUS ; n++) { +for (n =0 ; n < bc->core_count; n++) {/* TODO: this should be converted to a property of ARM_CPU */ s->cpu[n].core.mp_affinity = (bc->clusterid <<8 ) | n;
@@ -173,6 +174,7 @@ static void bcm2836_class_init(ObjectClass *oc, void *data)BCM283XClass *bc =BCM283X_CLASS (oc); bc->cpu_type =ARM_CPU_TYPE_NAME ("cortex-a7" ); + bc->core_count =BCM283X_NCPUS ; bc->peri_base =0x3f000000 ; bc->ctrl_base =0x40000000 ; bc->clusterid =0xf ;
@@ -187,6 +189,7 @@ static void bcm2837_class_init(ObjectClass *oc, void *data)BCM283XClass *bc =BCM283X_CLASS (oc); bc->cpu_type =ARM_CPU_TYPE_NAME ("cortex-a53" ); + bc->core_count =BCM283X_NCPUS ; bc->peri_base =0x3f000000 ; bc->ctrl_base =0x40000000 ; bc->clusterid =0x0 ;
Signature · 1 line
2.21.1
PATCH v2 17/30 hw/arm/bcm2836: Only provide "enabled-cpus" property to multicore SoCs
In reply to Philippe Mathieu-DaudéIt makes no sense to set enabled-cpus=0 on single core SoCs.
--- hw/arm/bcm2836.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
hw/arm/bcm2836.c +7 -8
@@ -32,6 +32,9 @@ typedef struct BCM283XClass {#define BCM283X_GET_CLASS (obj) \ OBJECT_GET_CLASS(BCM283XClass, (obj), TYPE_BCM283X) +static Property bcm2836_enabled_cores_property = +DEFINE_PROP_UINT32 ("enabled-cpus" , BCM283XState, enabled_cpus,0 ); +static void bcm2836_init (Object *obj) {BCM283XState *s =BCM283X (obj);
@@ -43,6 +46,10 @@ static void bcm2836_init(Object *obj)sizeof (s->cpu[n].core), bc->cpu_type, &error_abort, NULL); } +if (bc->core_count) { +qdev_property_add_static (DEVICE (obj), &bcm2836_enabled_cores_property); +qdev_prop_set_uint32 (DEVICE (obj),"enabled-cpus" , bc->core_count); + }sysbus_init_child_obj (obj,"control" , &s->control,sizeof (s->control),TYPE_BCM2836_CONTROL );
@@ -154,12 +161,6 @@ static void bcm2836_realize(DeviceState *dev, Error **errp) } } -static Property bcm2836_props[] = { -DEFINE_PROP_UINT32 ("enabled-cpus" , BCM283XState, enabled_cpus, -BCM283X_NCPUS ), -DEFINE_PROP_END_OF_LIST () -}; -static void bcm283x_class_init (ObjectClass *oc,void *data) {DeviceClass *dc =DEVICE_CLASS (oc);
@@ -179,7 +180,6 @@ static void bcm2836_class_init(ObjectClass *oc, void *data) bc->ctrl_base =0x40000000 ; bc->clusterid =0xf ; dc->realize = bcm2836_realize; -device_class_set_props (dc, bcm2836_props); };#ifdef TARGET_AARCH64
@@ -194,7 +194,6 @@ static void bcm2837_class_init(ObjectClass *oc, void *data) bc->ctrl_base =0x40000000 ; bc->clusterid =0x0 ; dc->realize = bcm2836_realize; - device_class_set_props(dc, bcm2836_props); };#endif
Signature · 1 line
2.21.1
PATCH v2 18/30 hw/arm/bcm2836: Split out common realize() code
In reply to Philippe Mathieu-DaudéThe realize() function is clearly composed of two parts, each described by a comment:
void realize()
{
/* common peripherals from bcm2835 */
...
/* bcm2836 interrupt controller (and mailboxes, etc.) */
...
}Split the two part, so we can reuse the common part with other SoCs from this family.
--- hw/arm/bcm2836.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-)
hw/arm/bcm2836.c +19 -4
@@ -51,8 +51,10 @@ static void bcm2836_init(Object *obj)qdev_prop_set_uint32 (DEVICE (obj),"enabled-cpus" , bc->core_count); } -sysbus_init_child_obj (obj,"control" , &s->control,sizeof (s->control), -TYPE_BCM2836_CONTROL ); +if (bc->ctrl_base) { +sysbus_init_child_obj (obj,"control" , &s->control, +sizeof (s->control),TYPE_BCM2836_CONTROL ); + }sysbus_init_child_obj (obj,"peripherals" , &s->peripherals,sizeof (s->peripherals),TYPE_BCM2835_PERIPHERALS );
@@ -62,13 +64,12 @@ static void bcm2836_init(Object *obj) "vcram-size", &error_abort); } -static void bcm2836_realize (DeviceState *dev,Error **errp) +static void bcm283x_common_realize (DeviceState *dev,Error **errp) {BCM283XState *s =BCM283X (dev);BCM283XClass *bc =BCM283X_GET_CLASS (dev);Object *obj;Error *err =NULL ; -int n;/* common peripherals from bcm2835 */
@@ -100,6 +101,20 @@ static void bcm2836_realize(DeviceState *dev, Error **errp)sysbus_mmio_map_overlap (SYS_BUS_DEVICE (&s->peripherals),0 , bc->peri_base,1 ); +} + +static void bcm2836_realize (DeviceState *dev,Error **errp) +{ +BCM283XState *s =BCM283X (dev); +BCM283XClass *bc =BCM283X_GET_CLASS (dev); +Error *err =NULL ; +int n; + +bcm283x_common_realize (dev, &err); +if (err) { +error_propagate (errp, err); +return ; + }/* bcm2836 interrupt controller (and mailboxes, etc.) */ object_property_set_bool (OBJECT (&s->control), true,"realized" , &err);
Signature · 1 line
2.21.1
PATCH v2 19/30 hw/arm/bcm2836: Introduce the BCM2835 SoC
In reply to Philippe Mathieu-Daudé--- include/hw/arm/bcm2836.h | 1 + hw/arm/bcm2836.c | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+)
include/hw/arm/bcm2836.h +1 -0
@@ -24,6 +24,7 @@* them, code using these devices should always handle them via the * BCM283x base class, so they have no BCM2836(obj) etc macros. */ +#define TYPE_BCM2835 "bcm2835"#define TYPE_BCM2836 "bcm2836"#define TYPE_BCM2837 "bcm2837"
hw/arm/bcm2836.c +40 -0
@@ -103,6 +103,31 @@ static void bcm283x_common_realize(DeviceState *dev, Error **errp) bc->peri_base, 1); } +static void bcm2835_realize (DeviceState *dev,Error **errp) +{ +BCM283XState *s =BCM283X (dev); +Error *err =NULL ; + +bcm283x_common_realize (dev, &err); +if (err) { +error_propagate (errp, err); +return ; + } + +object_property_set_bool (OBJECT (&s->cpu[0 ].core), true, +"realized" , &err); +if (err) { +error_propagate (errp, err); +return ; + } + +/* Connect irq/fiq outputs from the interrupt controller. */ +sysbus_connect_irq (SYS_BUS_DEVICE (&s->peripherals),0 , +qdev_get_gpio_in (DEVICE (&s->cpu[0 ].core),ARM_CPU_IRQ )); +sysbus_connect_irq (SYS_BUS_DEVICE (&s->peripherals),1 , +qdev_get_gpio_in (DEVICE (&s->cpu[0 ].core),ARM_CPU_FIQ )); +} +static void bcm2836_realize (DeviceState *dev,Error **errp) {BCM283XState *s =BCM283X (dev);
@@ -184,6 +209,17 @@ static void bcm283x_class_init(ObjectClass *oc, void *data) dc->user_creatable = false; } +static void bcm2835_class_init (ObjectClass *oc,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (oc); +BCM283XClass *bc =BCM283X_CLASS (oc); + + bc->cpu_type =ARM_CPU_TYPE_NAME ("arm1176" ); + bc->core_count =1 ; + bc->peri_base =0x20000000 ; + dc->realize = bcm2835_realize; +}; +static void bcm2836_class_init (ObjectClass *oc,void *data) {DeviceClass *dc =DEVICE_CLASS (oc);
@@ -214,6 +250,10 @@ static void bcm2837_class_init(ObjectClass *oc, void *data)static const TypeInfo bcm283x_types[] = { { + .name =TYPE_BCM2835 , + .parent =TYPE_BCM283X , + .class_init = bcm2835_class_init, + }, { .name =TYPE_BCM2836 , .parent =TYPE_BCM283X , .class_init = bcm2836_class_init,
Signature · 1 line
2.21.1
PATCH v2 20/30 hw/arm/raspi: Add the Raspberry Pi Zero machine
In reply to Philippe Mathieu-DaudéAdd a Raspberry Pi Zero machine.
$ qemu-system-arm -M raspi0 -serial stdio \
-kernel raspberrypi/firmware/boot/kernel.img \
-dtb raspberrypi/firmware/boot/bcm2708-rpi-zero-w.dtb \
-append 'printk.time=0 earlycon=pl011,0x20201000 console=ttyAMA0'
[ 0.000000] Booting Linux on physical CPU 0x0
[ 0.000000] Linux version 4.19.69+ (dom@buildbot) (gcc version 4.9.3 (crosstool-NG crosstool-ng-1.22.0-88-g8460611)) #1261 Tue Sep 3 20:21:01 BST 2019
[ 0.000000] CPU: ARMv6-compatible processor [410fb767] revision 7 (ARMv7), cr=00c5387d
[ 0.000000] CPU: VIPT aliasing data cache, unknown instruction cache
[ 0.000000] OF: fdt: Machine model: Raspberry Pi Zero W
[ 0.000000] earlycon: pl11 at MMIO 0x20201000 (options '')
[ 0.000000] bootconsole [pl11] enabled
[ 0.000000] Memory policy: Data cache writeback
[ 0.000000] cma: Reserved 8 MiB at 0x1b800000
[ 0.000000] random: get_random_bytes called from start_kernel+0x8c/0x49c with crng_init=0
[ 0.000000] Built 1 zonelists, mobility grouping on. Total pages: 113680
[ 0.000000] Kernel command line: printk.time=0 earlycon=pl011,0x20201000 console=ttyAMA0 root=/dev/mmcblk0 rootwait
Dentry cache hash table entries: 65536 (order: 6, 262144 bytes)
Inode-cache hash table entries: 32768 (order: 5, 131072 bytes)
Memory: 434380K/458752K available (6971K kernel code, 635K rwdata, 2080K rodata, 464K init, 797K bss, 16180K reserved, 8192K cma-reserved)
Virtual kernel memory layout:
vector : 0xffff0000 - 0xffff1000 ( 4 kB)
fixmap : 0xffc00000 - 0xfff00000 (3072 kB)
vmalloc : 0xdc800000 - 0xff800000 ( 560 MB)
lowmem : 0xc0000000 - 0xdc000000 ( 448 MB)
modules : 0xbf000000 - 0xc0000000 ( 16 MB)
.text : 0x(ptrval) - 0x(ptrval) (6973 kB)
.init : 0x(ptrval) - 0x(ptrval) ( 464 kB)
.data : 0x(ptrval) - 0x(ptrval) ( 636 kB)
.bss : 0x(ptrval) - 0x(ptrval) ( 798 kB)
SLUB: HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
ftrace: allocating 25193 entries in 74 pages
NR_IRQS: 16, nr_irqs: 16, preallocated irqs: 16
sched_clock: 32 bits at 1000kHz, resolution 1000ns, wraps every 2147483647500ns
clocksource: timer: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 1911260446275 ns
bcm2835: system timer (irq = 27)
Console: colour dummy device 80x30
...---
TODO: Add acceptance test
--- hw/arm/raspi.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
hw/arm/raspi.c +7 -2
@@ -88,7 +88,7 @@ static int board_version(uint32_t board_rev)static const char *board_soc_type (uint32_t board_rev) {static const char *soc_types[] = { -NULL ,TYPE_BCM2836 ,TYPE_BCM2837 , +TYPE_BCM2835 ,TYPE_BCM2836 ,TYPE_BCM2837 , };int proc_id =board_processor_id (board_rev);
@@ -103,7 +103,7 @@ static const char *board_soc_type(uint32_t board_rev)static int cores_count (uint32_t board_rev) {static const int soc_cores_count[] = { -0 ,BCM283X_NCPUS ,BCM283X_NCPUS , +1 ,BCM283X_NCPUS ,BCM283X_NCPUS , };int proc_id =board_processor_id (board_rev);
@@ -330,6 +330,11 @@ static void raspi_machine_class_init(ObjectClass *oc, void *data)static const TypeInfo raspi_machine_types[] = { { + .name =MACHINE_TYPE_NAME ("raspi0" ), + .parent =TYPE_RASPI_MACHINE , + .class_init = raspi_machine_class_init, + .class_data = (void *)0x9000c1 , + }, { .name =MACHINE_TYPE_NAME ("raspi2" ), .parent =TYPE_RASPI_MACHINE , .class_init = raspi_machine_class_init,
Signature · 1 line
2.21.1
PATCH v2 21/30 hw/arm/raspi: Add the Raspberry Pi B+ machine
In reply to Philippe Mathieu-Daudé $ qemu-system-arm -M raspi1 -serial stdio \
-kernel raspberrypi/firmware/boot/kernel.img \
-dtb raspberrypi/firmware/boot/bcm2708-rpi-b.dtb \
-append 'printk.time=0 earlycon=pl011,0x20201000 console=ttyAMA0'
[ 0.000000] Booting Linux on physical CPU 0x0
[ 0.000000] Linux version 4.19.69+ (dom@buildbot) (gcc version 4.9.3 (crosstool-NG crosstool-ng-1.22.0-88-g8460611)) #1261 Tue Sep 3 20:21:01 BST 2019
[ 0.000000] CPU: ARMv6-compatible processor [410fb767] revision 7 (ARMv7), cr=00c5387d
[ 0.000000] CPU: VIPT aliasing data cache, unknown instruction cache
[ 0.000000] OF: fdt: Machine model: Raspberry Pi Model B
[ 0.000000] earlycon: pl11 at MMIO 0x20201000 (options '')
[ 0.000000] bootconsole [pl11] enabled
[ 0.000000] Memory policy: Data cache writeback
[ 0.000000] cma: Reserved 8 MiB at 0x1b800000
[ 0.000000] random: get_random_bytes called from start_kernel+0x8c/0x49c with crng_init=0
[ 0.000000] Built 1 zonelists, mobility grouping on. Total pages: 113680
[ 0.000000] Kernel command line: printk.time=0 earlycon=pl011,0x20201000 console=ttyAMA0
Dentry cache hash table entries: 65536 (order: 6, 262144 bytes)
Inode-cache hash table entries: 32768 (order: 5, 131072 bytes)
Memory: 434380K/458752K available (6971K kernel code, 635K rwdata, 2080K rodata, 464K init, 797K bss, 16180K reserved, 8192K cma-reserved)
...--- hw/arm/raspi.c | 5 +++++ 1 file changed, 5 insertions(+)
hw/arm/raspi.c +5 -0
@@ -334,6 +334,11 @@ static const TypeInfo raspi_machine_types[] = { .parent = TYPE_RASPI_MACHINE, .class_init = raspi_machine_class_init, .class_data = (void *)0x9000c1, + }, { + .name = MACHINE_TYPE_NAME("raspi1"), + .parent = TYPE_RASPI_MACHINE, + .class_init = raspi_machine_class_init, + .class_data = (void *)0x900032, }, { .name = MACHINE_TYPE_NAME("raspi2"), .parent = TYPE_RASPI_MACHINE,
Signature · 1 line
2.21.1
PATCH v2 22/30 tests/acceptance/boot_linux_console: Use raspi console model as key
In reply to Philippe Mathieu-DaudéPython dictionary are not that expensive. Use a key makes the code easier to review.
--- tests/acceptance/boot_linux_console.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
tests/acceptance/boot_linux_console.py +4 -4
@@ -325,14 +325,14 @@ class BootLinuxConsole(Test): self.vm.launch() self.wait_for_console_pattern('init started: BusyBox') - def do_test_arm_raspi2(self, uart_id): + def do_test_arm_raspi2(self, uart_model): """ The kernel can be rebuilt using the kernel source referenced and following the instructions on the on: https://www.raspberrypi.org/documentation/linux/kernel/building.md """ serial_kernel_cmdline = { - 0: 'earlycon=pl011,0x3f201000 console=ttyAMA0', + 'pl011': 'earlycon=pl011,0x3f201000 console=ttyAMA0', } deb_url = ('http://archive.raspberrypi.org/debian/' 'pool/main/r/raspberrypi-firmware/'
@@ -344,7 +344,7 @@ class BootLinuxConsole(Test): self.vm.set_console() kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + - serial_kernel_cmdline[uart_id]) + serial_kernel_cmdline[uart_model]) self.vm.add_args('-kernel', kernel_path, '-dtb', dtb_path, '-append', kernel_command_line)
@@ -358,7 +358,7 @@ class BootLinuxConsole(Test): :avocado: tags=machine:raspi2 :avocado: tags=device:pl011 """ - self.do_test_arm_raspi2(0) + self.do_test_arm_raspi2('pl011') def test_arm_exynos4210_initrd(self): """
Signature · 1 line
2.21.1
PATCH v2 23/30 tests/acceptance/boot_linux_console: Add raspi version=2 parameter
In reply to Philippe Mathieu-DaudéWe want to tests different Raspberry Pi machines. Refactor to take the board version as argument.
--- tests/acceptance/boot_linux_console.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-)
tests/acceptance/boot_linux_console.py +15 -6
@@ -325,26 +325,34 @@ class BootLinuxConsole(Test): self.vm.launch() self.wait_for_console_pattern('init started: BusyBox') - def do_test_arm_raspi2(self, uart_model): + def do_test_arm_raspi(self, version, uart_model): """ The kernel can be rebuilt using the kernel source referenced and following the instructions on the on: https://www.raspberrypi.org/documentation/linux/kernel/building.md """ serial_kernel_cmdline = { - 'pl011': 'earlycon=pl011,0x3f201000 console=ttyAMA0', + 'pl011': { + 2: 'earlycon=pl011,0x3f201000 console=ttyAMA0', + }, + } + kernel = { + 2: '/boot/kernel7.img', + } + dtb = { + 2: '/boot/bcm2709-rpi-2-b.dtb', } deb_url = ('http://archive.raspberrypi.org/debian/' 'pool/main/r/raspberrypi-firmware/' 'raspberrypi-kernel_1.20190215-1_armhf.deb') deb_hash = 'cd284220b32128c5084037553db3c482426f3972' deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash) - kernel_path = self.extract_from_deb(deb_path, '/boot/kernel7.img') - dtb_path = self.extract_from_deb(deb_path, '/boot/bcm2709-rpi-2-b.dtb') + kernel_path = self.extract_from_deb(deb_path, kernel[version]) + dtb_path = self.extract_from_deb(deb_path, dtb[version]) self.vm.set_console() kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + - serial_kernel_cmdline[uart_model]) + serial_kernel_cmdline[uart_model][version]) self.vm.add_args('-kernel', kernel_path, '-dtb', dtb_path, '-append', kernel_command_line)
@@ -356,9 +364,10 @@ class BootLinuxConsole(Test): """ :avocado: tags=arch:arm :avocado: tags=machine:raspi2 + :avocado: tags=cpu:cortex-a7 :avocado: tags=device:pl011 """ - self.do_test_arm_raspi2('pl011') + self.do_test_arm_raspi(2, 'pl011') def test_arm_exynos4210_initrd(self): """
Signature · 1 line
2.21.1
PATCH v2 24/30 tests/acceptance/boot_linux_console: Test the raspi1 console
In reply to Philippe Mathieu-Daudé$ avocado --show=app,console run -t machine:raspi1 tests/acceptance/ JOB ID : c49310d4a21444f03789cd2c443d8c54a29ffd0a JOB LOG : avocado/job-results/job-2020-02-05T23.52-c49310d/job.log (1/1) tests/acceptance/boot_linux_console.py:BootLinuxConsole.test_arm_raspi1_uart0: console: [ 0.000000] Booting Linux on physical CPU 0x0 console: [ 0.000000] Linux version 4.14.98+ (dom@dom-XPS-13-9370) (gcc version 4.9.3 (crosstool-NG crosstool-ng-1.22.0-88-g8460611)) #1200 Tue Feb 12 20:11:02 GMT 2019 console: [ 0.000000] CPU: ARMv6-compatible processor [410fb767] revision 7 (ARMv7), cr=00c5387d console: [ 0.000000] CPU: VIPT aliasing data cache, unknown instruction cache console: [ 0.000000] OF: fdt: Machine model: Raspberry Pi Model B console: [ 0.000000] earlycon: pl11 at MMIO 0x20201000 (options '') console: [ 0.000000] bootconsole [pl11] enabled console: [ 0.000000] Memory policy: Data cache writeback console: [ 0.000000] cma: Reserved 8 MiB at 0x1b800000 console: [ 0.000000] Built 1 zonelists, mobility grouping on. Total pages: 113680 console: [ 0.000000] Kernel command line: printk.time=0 earlycon=pl011,0x20201000 console=ttyAMA0 PASS (12.93 s) RESULTS : PASS 1 | ERROR 0 | FAIL 0 | SKIP 0 | WARN 0 | INTERRUPT 0 | CANCEL 0 JOB TIME : 13.18 s
--- tests/acceptance/boot_linux_console.py | 12 ++++++++++++ 1 file changed, 12 insertions(+)
tests/acceptance/boot_linux_console.py +12 -0
@@ -333,13 +333,16 @@ class BootLinuxConsole(Test): """ serial_kernel_cmdline = { 'pl011': { + 1: 'earlycon=pl011,0x20201000 console=ttyAMA0', 2: 'earlycon=pl011,0x3f201000 console=ttyAMA0', }, } kernel = { + 1: '/boot/kernel.img', 2: '/boot/kernel7.img', } dtb = { + 1: '/boot/bcm2708-rpi-b.dtb', 2: '/boot/bcm2709-rpi-2-b.dtb', } deb_url = ('http://archive.raspberrypi.org/debian/'
@@ -360,6 +363,15 @@ class BootLinuxConsole(Test): console_pattern = 'Kernel command line: %s' % kernel_command_line self.wait_for_console_pattern(console_pattern) + def test_arm_raspi1_uart0(self): + """ + :avocado: tags=arch:arm + :avocado: tags=machine:raspi1 + :avocado: tags=cpu:arm1176 + :avocado: tags=device:pl011 + """ + self.do_test_arm_raspi(1, 'pl011') + def test_arm_raspi2_uart0(self): """ :avocado: tags=arch:arm
Signature · 1 line
2.21.1
PATCH v2 25/30 tests/acceptance/boot_linux_console: Test the raspi0 console
In reply to Philippe Mathieu-Daudé$ avocado --show=app,console run -t machine:raspi0 tests/acceptance/ JOB ID : af8e017486290758bff39c986934134199af3556 JOB LOG : avocado/job-results/job-2020-02-05T23.53-af8e017/job.log (1/1) tests/acceptance/boot_linux_console.py:BootLinuxConsole.test_arm_raspi0_uart0: console: [ 0.000000] Booting Linux on physical CPU 0x0 console: [ 0.000000] Linux version 4.14.98+ (dom@dom-XPS-13-9370) (gcc version 4.9.3 (crosstool-NG crosstool-ng-1.22.0-88-g8460611)) #1200 Tue Feb 12 20:11:02 GMT 2019 console: [ 0.000000] CPU: ARMv6-compatible processor [410fb767] revision 7 (ARMv7), cr=00c5387d console: [ 0.000000] CPU: VIPT aliasing data cache, unknown instruction cache console: [ 0.000000] OF: fdt: Machine model: Raspberry Pi Zero W console: [ 0.000000] earlycon: pl11 at MMIO 0x20201000 (options '') console: [ 0.000000] bootconsole [pl11] enabled console: [ 0.000000] Memory policy: Data cache writeback console: [ 0.000000] cma: Reserved 8 MiB at 0x1b800000 console: [ 0.000000] Built 1 zonelists, mobility grouping on. Total pages: 113680 console: [ 0.000000] Kernel command line: printk.time=0 earlycon=pl011,0x20201000 console=ttyAMA0 PASS (12.59 s) RESULTS : PASS 1 | ERROR 0 | FAIL 0 | SKIP 0 | WARN 0 | INTERRUPT 0 | CANCEL 0 JOB TIME : 12.88 s
--- tests/acceptance/boot_linux_console.py | 12 ++++++++++++ 1 file changed, 12 insertions(+)
tests/acceptance/boot_linux_console.py +12 -0
@@ -333,15 +333,18 @@ class BootLinuxConsole(Test): """ serial_kernel_cmdline = { 'pl011': { + 0: 'earlycon=pl011,0x20201000 console=ttyAMA0', 1: 'earlycon=pl011,0x20201000 console=ttyAMA0', 2: 'earlycon=pl011,0x3f201000 console=ttyAMA0', }, } kernel = { + 0: '/boot/kernel.img', 1: '/boot/kernel.img', 2: '/boot/kernel7.img', } dtb = { + 0: '/boot/bcm2708-rpi-0-w.dtb', 1: '/boot/bcm2708-rpi-b.dtb', 2: '/boot/bcm2709-rpi-2-b.dtb', }
@@ -363,6 +366,15 @@ class BootLinuxConsole(Test): console_pattern = 'Kernel command line: %s' % kernel_command_line self.wait_for_console_pattern(console_pattern) + def test_arm_raspi0_uart0(self): + """ + :avocado: tags=arch:arm + :avocado: tags=machine:raspi0 + :avocado: tags=cpu:arm1176 + :avocado: tags=device:pl011 + """ + self.do_test_arm_raspi(0, 'pl011') + def test_arm_raspi1_uart0(self): """ :avocado: tags=arch:arm
Signature · 1 line
2.21.1
PATCH v2 26/30 python/qemu/machine: Allow to use other serial consoles than default
In reply to Philippe Mathieu-DaudéCurrently the QEMU Python module limits the QEMUMachine class to use the first serial console.
Some machines/guest might use another console than the first one as the 'boot console'. For example the Raspberry Pi uses the second (AUX) console.
To be able to use the Nth console as default, we simply need to connect all the N - 1 consoles to the null chardev.
Add an index argument, so we can use a specific serial console as default.
Message-Id: <[email protected]>
--- python/qemu/machine.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
python/qemu/machine.py +9 -1
@@ -112,6 +112,7 @@ class QEMUMachine(object): self._sock_dir = sock_dir self._launched = False self._machine = None + self._console_index = 0 self._console_set = False self._console_device_type = None self._console_address = None
@@ -241,6 +242,8 @@ class QEMUMachine(object): 'chardev=mon,mode=control']) if self._machine is not None: args.extend(['-machine', self._machine]) + for i in range(self._console_index): + args.extend(['-serial', 'null']) if self._console_set: self._console_address = os.path.join(self._sock_dir, self._name + "-console.sock")
@@ -527,7 +530,7 @@ class QEMUMachine(object): """ self._machine = machine_type - def set_console(self, device_type=None): + def set_console(self, device_type=None, console_index=0): """ Sets the device type for a console device
@@ -548,9 +551,14 @@ class QEMUMachine(object): chardev:console" command line argument will be used instead, resorting to the machine's default device type. + @param console_index: the index of the console device to use. + If not zero, the command line will create + 'index - 1' consoles and connect them to + the 'null' backing character device. """ self._console_set = True self._console_device_type = device_type + self._console_index = console_index @property def console_socket(self):
Signature · 1 line
2.21.1
PATCH v2 27/30 tests/acceptance/boot_linux_console: Test the raspi1 AUX console
In reply to Philippe Mathieu-Daudé$ avocado --show=app,console run -t device:bcm2835_aux tests/acceptance/ JOB ID : a8846d69d52da701681b1d17f80ef299009fd078 JOB LOG : avocado/job-results/job-2020-02-05T23.44-a8846d6/job.log (1/3) tests/acceptance/boot_linux_console.py:BootLinuxConsole.test_arm_raspi0_uart1: console: [ 0.000000] Booting Linux on physical CPU 0x0 console: [ 0.000000] Linux version 4.14.98+ (dom@dom-XPS-13-9370) (gcc version 4.9.3 (crosstool-NG crosstool-ng-1.22.0-88-g8460611)) #1200 Tue Feb 12 20:11:02 GMT 2019 console: [ 0.000000] CPU: ARMv6-compatible processor [410fb767] revision 7 (ARMv7), cr=00c5387d console: [ 0.000000] CPU: VIPT aliasing data cache, unknown instruction cache console: [ 0.000000] OF: fdt: Machine model: Raspberry Pi Zero W console: [ 0.000000] earlycon: uart8250 at MMIO32 0x20215040 (options '') console: [ 0.000000] bootconsole [uart8250] enabled console: [ 0.000000] Memory policy: Data cache writeback console: [ 0.000000] cma: Reserved 8 MiB at 0x1b800000 console: [ 0.000000] Built 1 zonelists, mobility grouping on. Total pages: 113680 console: [ 0.000000] Kernel command line: printk.time=0 earlycon=uart8250,mmio32,0x20215040 console=ttyS1,115200 PASS (13.31 s) (2/3) tests/acceptance/boot_linux_console.py:BootLinuxConsole.test_arm_raspi1_uart1: console: [ 0.000000] Booting Linux on physical CPU 0x0 console: [ 0.000000] Linux version 4.14.98+ (dom@dom-XPS-13-9370) (gcc version 4.9.3 (crosstool-NG crosstool-ng-1.22.0-88-g8460611)) #1200 Tue Feb 12 20:11:02 GMT 2019 console: [ 0.000000] CPU: ARMv6-compatible processor [410fb767] revision 7 (ARMv7), cr=00c5387d console: [ 0.000000] CPU: VIPT aliasing data cache, unknown instruction cache console: [ 0.000000] OF: fdt: Machine model: Raspberry Pi Model B console: [ 0.000000] earlycon: uart8250 at MMIO32 0x20215040 (options '') console: [ 0.000000] bootconsole [uart8250] enabled console: [ 0.000000] Memory policy: Data cache writeback console: [ 0.000000] cma: Reserved 8 MiB at 0x1b800000 console: [ 0.000000] Built 1 zonelists, mobility grouping on. Total pages: 113680 console: [ 0.000000] Kernel command line: printk.time=0 earlycon=uart8250,mmio32,0x20215040 console=ttyS1,115200 PASS (13.39 s) (3/3) tests/acceptance/boot_linux_console.py:BootLinuxConsole.test_arm_raspi2_uart1: console: [ 0.000000] Booting Linux on physical CPU 0xf00 console: [ 0.000000] Linux version 4.14.98-v7+ (dom@dom-XPS-13-9370) (gcc version 4.9.3 (crosstool-NG crosstool-ng-1.22.0-88-g8460611)) #1200 SMP Tue Feb 12 20:27:48 GMT 2019 console: [ 0.000000] CPU: ARMv7 Processor [410fc075] revision 5 (ARMv7), cr=10c5387d console: [ 0.000000] CPU: div instructions available: patching division code console: [ 0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache console: [ 0.000000] OF: fdt: Machine model: Raspberry Pi 2 Model B console: [ 0.000000] earlycon: uart8250 at MMIO32 0x3f215040 (options '') console: [ 0.000000] bootconsole [uart8250] enabled console: [ 0.000000] Memory policy: Data cache writealloc console: [ 0.000000] cma: Reserved 8 MiB at 0x3b800000 console: [ 0.000000] percpu: Embedded 17 pages/cpu @baf2e000 s38720 r8192 d22720 u69632 console: [ 0.000000] Built 1 zonelists, mobility grouping on. Total pages: 243600 console: [ 0.000000] Kernel command line: printk.time=0 earlycon=uart8250,mmio32,0x3f215040 console=ttyS1,115200 PASS (12.46 s) RESULTS : PASS 3 | ERROR 0 | FAIL 0 | SKIP 0 | WARN 0 | INTERRUPT 0 | CANCEL 0 JOB TIME : 39.60 s
--- tests/acceptance/boot_linux_console.py | 37 +++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-)
tests/acceptance/boot_linux_console.py +36 -1
@@ -337,6 +337,14 @@ class BootLinuxConsole(Test): 1: 'earlycon=pl011,0x20201000 console=ttyAMA0', 2: 'earlycon=pl011,0x3f201000 console=ttyAMA0', }, + 'bcm2835_aux': { + 0: 'earlycon=uart8250,mmio32,0x20215040 console=ttyS1,115200', + 1: 'earlycon=uart8250,mmio32,0x20215040 console=ttyS1,115200', + 2: 'earlycon=uart8250,mmio32,0x3f215040 console=ttyS1,115200', + }, + } + uart_id = { + 'pl011': 0, 'bcm2835_aux': 1, } kernel = { 0: '/boot/kernel.img',
@@ -356,7 +364,7 @@ class BootLinuxConsole(Test): kernel_path = self.extract_from_deb(deb_path, kernel[version]) dtb_path = self.extract_from_deb(deb_path, dtb[version]) - self.vm.set_console() + self.vm.set_console(console_index=uart_id[uart_model]) kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + serial_kernel_cmdline[uart_model][version]) self.vm.add_args('-kernel', kernel_path,
@@ -375,6 +383,15 @@ class BootLinuxConsole(Test): """ self.do_test_arm_raspi(0, 'pl011') + def test_arm_raspi0_uart1(self): + """ + :avocado: tags=arch:arm + :avocado: tags=machine:raspi0 + :avocado: tags=cpu:arm1176 + :avocado: tags=device:bcm2835_aux + """ + self.do_test_arm_raspi(0, 'bcm2835_aux') + def test_arm_raspi1_uart0(self): """ :avocado: tags=arch:arm
@@ -384,6 +401,15 @@ class BootLinuxConsole(Test): """ self.do_test_arm_raspi(1, 'pl011') + def test_arm_raspi1_uart1(self): + """ + :avocado: tags=arch:arm + :avocado: tags=machine:raspi1 + :avocado: tags=cpu:arm1176 + :avocado: tags=device:bcm2835_aux + """ + self.do_test_arm_raspi(1, 'bcm2835_aux') + def test_arm_raspi2_uart0(self): """ :avocado: tags=arch:arm
@@ -393,6 +419,15 @@ class BootLinuxConsole(Test): """ self.do_test_arm_raspi(2, 'pl011') + def test_arm_raspi2_uart1(self): + """ + :avocado: tags=arch:arm + :avocado: tags=machine:raspi2 + :avocado: tags=cpu:cortex-a7 + :avocado: tags=device:bcm2835_aux + """ + self.do_test_arm_raspi(2, 'bcm2835_aux') + def test_arm_exynos4210_initrd(self): """ :avocado: tags=arch:arm
Signature · 1 line
2.21.1
PATCH v2 28/30 tests/acceptance: Count Raspberry Pi logos displayed on framebuffer
In reply to Philippe Mathieu-DaudéAdd a test that verifies that each core properly displays the Raspberry Pi logo on the framebuffer device.
We simply follow the OpenCV "Template Matching with Multiple Objects" tutorial, replacing Lionel Messi by a raspberrry:
https://docs.opencv.org/4.2.0/d4/dc6/tutorial_py_template_matching.html
When OpenCV and NumPy are installed, this test can be run using:
$ avocado --show=app,framebuffer run -t device:bcm2835-fb tests/acceptance/ JOB ID : 9bbbc54c0a6fa180348d0b5305507f76852b4da2 JOB LOG : avocado/job-results/job-2020-01-31T23.48-9bbbc54/job.log (1/1) tests/acceptance/boot_linux_console.py:BootLinuxConsole.test_arm_raspi2_framebuffer_logo: framebuffer: found raspberry at position (x, y) = (0, 0) framebuffer: found raspberry at position (x, y) = (71, 0) framebuffer: found raspberry at position (x, y) = (142, 0) framebuffer: found raspberry at position (x, y) = (213, 0) PASS (11.06 s) RESULTS : PASS 1 | ERROR 0 | FAIL 0 | SKIP 0 | WARN 0 | INTERRUPT 0 | CANCEL 0 JOB TIME : 11.39 s
---
The resulting match can be visualised at https://pasteboard.co/ISzNHtx.png
--- tests/acceptance/boot_linux_console.py | 62 ++++++++++++++++++++++++++ 1 file changed, 62 insertions(+)
tests/acceptance/boot_linux_console.py +62 -0
@@ -12,6 +12,7 @@ import os import lzma import gzip import shutil +import logging from avocado import skipUnless from avocado_qemu import Test
@@ -21,6 +22,19 @@ from avocado.utils import process from avocado.utils import archive +NUMPY_AVAILABLE = True +try: + import numpy as np +except ImportError: + NUMPY_AVAILABLE = False + +CV2_AVAILABLE = True +try: + import cv2 +except ImportError: + CV2_AVAILABLE = False + + class BootLinuxConsole(Test): """ Boots a Linux kernel and checks that the console is operational and the
@@ -428,6 +442,54 @@ class BootLinuxConsole(Test): """ self.do_test_arm_raspi(2, 'bcm2835_aux') + @skipUnless(NUMPY_AVAILABLE, 'Python NumPy not installed') + @skipUnless(CV2_AVAILABLE, 'Python OpenCV not installed') + def test_arm_raspi2_framebuffer_logo(self): + """ + :avocado: tags=arch:arm + :avocado: tags=machine:raspi2 + :avocado: tags=device:bcm2835-fb + """ + screendump_path = os.path.join(self.workdir, 'screendump.pbm') + rpilogo_url = ('https://github.com/raspberrypi/linux/raw/' + 'raspberrypi-kernel_1.20190517-1/' + 'drivers/video/logo/logo_linux_clut224.ppm') + rpilogo_hash = 'fff3cc20c6030acce0953147f9baac43f44ed6b0' + rpilogo_path = self.fetch_asset(rpilogo_url, asset_hash=rpilogo_hash) + deb_url = ('http://archive.raspberrypi.org/debian/' + 'pool/main/r/raspberrypi-firmware/' + 'raspberrypi-kernel_1.20190215-1_armhf.deb') + deb_hash = 'cd284220b32128c5084037553db3c482426f3972' + deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash) + kernel_path = self.extract_from_deb(deb_path, '/boot/kernel7.img') + dtb_path = self.extract_from_deb(deb_path, '/boot/bcm2709-rpi-2-b.dtb') + + self.vm.set_console() + kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + + 'earlycon=pl011,0x3f201000 console=ttyAMA0') + self.vm.add_args('-kernel', kernel_path, + '-dtb', dtb_path, + '-append', kernel_command_line) + self.vm.launch() + framebuffer_ready = 'Console: switching to colour frame buffer device' + wait_for_console_pattern(self, framebuffer_ready) + self.vm.command('human-monitor-command', command_line='stop') + self.vm.command('human-monitor-command', + command_line='screendump %s' % screendump_path) + logger = logging.getLogger('framebuffer') + + cpu_cores_count = 4 + match_threshold = 0.95 + screendump_bgr = cv2.imread(screendump_path, cv2.IMREAD_COLOR) + rpilogo_bgr = cv2.imread(rpilogo_path, cv2.IMREAD_COLOR) + result = cv2.matchTemplate(screendump_bgr, rpilogo_bgr, + cv2.TM_CCOEFF_NORMED) + loc = np.where(result >= match_threshold) + rpilogo_count = 0 + for rpilogo_count, pt in enumerate(zip(*loc[::-1]), start=1): + logger.debug('found raspberry at position (x, y) = %s', pt) + self.assertGreaterEqual(rpilogo_count, cpu_cores_count) + def test_arm_exynos4210_initrd(self): """ :avocado: tags=arch:arm
Signature · 1 line
2.21.1
PATCH v2 29/30 hw/arm/bcm2836: Add the BCM2838 (ARMv8)
In reply to Philippe Mathieu-DaudéSetup the GICv2.
--- include/hw/arm/bcm2836.h | 3 + hw/arm/bcm2836.c | 206 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 209 insertions(+)
include/hw/arm/bcm2836.h +3 -0
@@ -13,6 +13,7 @@#include "hw/arm/bcm2835_peripherals.h" #include "hw/intc/bcm2836_control.h" +#include "hw/intc/arm_gic.h" #include "target/arm/cpu.h" #define TYPE_BCM283X "bcm283x"
@@ -27,6 +28,7 @@#define TYPE_BCM2835 "bcm2835"#define TYPE_BCM2836 "bcm2836"#define TYPE_BCM2837 "bcm2837" +#define TYPE_BCM2838 "bcm2838" typedef struct BCM283XState { /*< private >*/
@@ -39,6 +41,7 @@ typedef struct BCM283XState {struct {ARMCPU core; } cpu[BCM283X_NCPUS ]; +GICState gic;BCM2836ControlState control;BCM2835PeripheralState peripherals; } BCM283XState;
hw/arm/bcm2836.c +206 -0
236 lines not on this page · raw message
Signature · 1 line
2.21.1
PATCH v2 30/30 hw/arm/raspi: Add the Raspberry Pi 4
In reply to Philippe Mathieu-Daudé--- hw/arm/raspi.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
hw/arm/raspi.c +7 -2
@@ -88,7 +88,7 @@ static int board_version(uint32_t board_rev)static const char *board_soc_type (uint32_t board_rev) {static const char *soc_types[] = { -TYPE_BCM2835 ,TYPE_BCM2836 ,TYPE_BCM2837 , +TYPE_BCM2835 ,TYPE_BCM2836 ,TYPE_BCM2837 ,TYPE_BCM2838 , };int proc_id =board_processor_id (board_rev);
@@ -103,7 +103,7 @@ static const char *board_soc_type(uint32_t board_rev)static int cores_count (uint32_t board_rev) {static const int soc_cores_count[] = { -1 ,BCM283X_NCPUS ,BCM283X_NCPUS , +1 ,BCM283X_NCPUS ,BCM283X_NCPUS ,BCM283X_NCPUS , };int proc_id =board_processor_id (board_rev);
@@ -350,6 +350,11 @@ static const TypeInfo raspi_machine_types[] = { .parent = TYPE_RASPI_MACHINE, .class_init = raspi_machine_class_init, .class_data = (void *)0xa02082, + }, { + .name = MACHINE_TYPE_NAME("raspi4"), + .parent = TYPE_RASPI_MACHINE, + .class_init = raspi_machine_class_init, + .class_data = (void *)0xa03111,#endif }, { .name = TYPE_RASPI_MACHINE,
Signature · 1 line
2.21.1