Skip to contentSkip to conversation

niagara: fail if a firmware file is missing

PATCH Superseded Artyom Tarasenko 3 participants 6 messages Jan 23, 2017 – Jan 24, 2017

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 niagara: fail if a firmware file is missing

---
 hw/sparc64/niagara.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)
hw/sparc64/niagara.c +15 -7
index b55d4bb..e945b5a 100644
@@ -35,6 +35,7 @@
 #include "hw/timer/sun4v-rtc.h"
 #include "exec/address-spaces.h"
 #include "sysemu/block-backend.h"
+#include "qemu/error-report.h"
 
 
 typedef struct NiagaraBoardState {
@@ -85,6 +86,14 @@ typedef struct NiagaraBoardState {
 #define NIAGARA_OBP_OFFSET  0x80000ULL
 #define PROM_SIZE_MAX       (4 * 1024 * 1024)
 
+static void add_rom_or_fail(const char *file, const hwaddr addr)
+{
+    if (rom_add_file_fixed(file, addr, -1)) {
+        error_report("Unable to load a firmware for -M niagara");
+        exit(1);
+    }
+
+}
 /* Niagara hardware initialisation */
 static void niagara_init(MachineState *machine)
 {
@@ -119,14 +128,13 @@ static void niagara_init(MachineState *machine)
                                          "sun4v.prom", PROM_SIZE_MAX);
     memory_region_add_subregion(sysmem, NIAGARA_PROM_BASE, &s->prom);
 
-    rom_add_file_fixed("nvram1", NIAGARA_NVRAM_BASE, -1);
-    rom_add_file_fixed("1up-md.bin", NIAGARA_MD_ROM_BASE, -1);
-    rom_add_file_fixed("1up-hv.bin", NIAGARA_HV_ROM_BASE, -1);
+    add_rom_or_fail("nvram1", NIAGARA_NVRAM_BASE);
+    add_rom_or_fail("1up-md.bin", NIAGARA_MD_ROM_BASE);
+    add_rom_or_fail("1up-hv.bin", NIAGARA_HV_ROM_BASE);
 
-    rom_add_file_fixed("reset.bin", NIAGARA_PROM_BASE, -1);
-    rom_add_file_fixed("q.bin", NIAGARA_PROM_BASE + NIAGARA_Q_OFFSET, -1);
-    rom_add_file_fixed("openboot.bin", NIAGARA_PROM_BASE + NIAGARA_OBP_OFFSET,
-                       -1);
+    add_rom_or_fail("reset.bin", NIAGARA_PROM_BASE);
+    add_rom_or_fail("q.bin", NIAGARA_PROM_BASE + NIAGARA_Q_OFFSET);
+    add_rom_or_fail("openboot.bin", NIAGARA_PROM_BASE + NIAGARA_OBP_OFFSET);
 
     /* the virtual ramdisk is kind of initrd, but it resides
        outside of the partition RAM */
Signature · 1 line
2.7.2
#1 lore raw
Quoted 19 lines · Artyom Tarasenko
---
 hw/sparc64/niagara.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)
hw/sparc64/niagara.c +1 -0
index b55d4bb..e945b5a 100644
@@ -35,6 +35,7 @@
 #include "hw/timer/sun4v-rtc.h"
 #include "exec/address-spaces.h"
 #include "sysemu/block-backend.h"
+#include "qemu/error-report.h"
 
 
 typedef struct NiagaraBoardState {

hw/sparc64/niagara.c typedef struct NiagaraBoardState { · line 93

Quoted 8 lines
hw/sparc64/niagara.c +5 -0
@@ -85,6 +86,14 @@ typedef struct NiagaraBoardState {
 #define NIAGARA_OBP_OFFSET  0x80000ULL
 #define PROM_SIZE_MAX       (4 * 1024 * 1024)
 
+static void add_rom_or_fail(const char *file, const hwaddr addr)
+{
+    if (rom_add_file_fixed(file, addr, -1)) {
+        error_report("Unable to load a firmware for -M niagara");
+        exit(1);

It would be nice to include the name of the file in the error message -- or is that reported already inside rom_add_file_fixed() somehow?

thanks
-- PMM

#2 lore raw
Quoted 23 lines · Peter Maydell
Quoted 22 lines · Artyom Tarasenko
---
 hw/sparc64/niagara.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)
hw/sparc64/niagara.c +1 -0
index b55d4bb..e945b5a 100644
@@ -35,6 +35,7 @@
 #include "hw/timer/sun4v-rtc.h"
 #include "exec/address-spaces.h"
 #include "sysemu/block-backend.h"
+#include "qemu/error-report.h"
 
 
 typedef struct NiagaraBoardState {
@@ -85,6 +86,14 @@ typedef struct NiagaraBoardState {
 #define NIAGARA_OBP_OFFSET  0x80000ULL
 #define PROM_SIZE_MAX       (4 * 1024 * 1024)
 
Quoted 9 lines

hw/sparc64/niagara.c typedef struct NiagaraBoardState { · line 93

Quoted 5 lines
hw/sparc64/niagara.c +5 -0
+static void add_rom_or_fail(const char *file, const hwaddr addr)
+{
+    if (rom_add_file_fixed(file, addr, -1)) {
+        error_report("Unable to load a firmware for -M niagara");
+        exit(1);

It would be nice to include the name of the file in the error message -- or is that reported already inside rom_add_file_fixed() somehow?

PS: doesn't this break 'make check' if the rom files are missing?

thanks
-- PMM

#3 lore raw
Quoted 24 lines · Peter Maydell
Quoted 23 lines · Peter Maydell
Quoted 22 lines · Artyom Tarasenko
---
 hw/sparc64/niagara.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)
hw/sparc64/niagara.c +1 -0
index b55d4bb..e945b5a 100644
@@ -35,6 +35,7 @@
 #include "hw/timer/sun4v-rtc.h"
 #include "exec/address-spaces.h"
 #include "sysemu/block-backend.h"
+#include "qemu/error-report.h"
 
 
 typedef struct NiagaraBoardState {
@@ -85,6 +86,14 @@ typedef struct NiagaraBoardState {
 #define NIAGARA_OBP_OFFSET  0x80000ULL
 #define PROM_SIZE_MAX       (4 * 1024 * 1024)
 
Quoted 9 lines
Quoted 9 lines

hw/sparc64/niagara.c typedef struct NiagaraBoardState { · line 93

Quoted 5 lines
hw/sparc64/niagara.c +5 -0
+static void add_rom_or_fail(const char *file, const hwaddr addr)
+{
+    if (rom_add_file_fixed(file, addr, -1)) {
+        error_report("Unable to load a firmware for -M niagara");
+        exit(1);

It would be nice to include the name of the file in the error message -- or is that reported already inside rom_add_file_fixed() somehow?

Yes, it is, in rom_add_file():

    if (fd == -1) {
        fprintf(stderr, "Could not open option rom '%s': %s\n",
                rom->path, strerror(errno));
        goto err;
    }
Quoted 2 lines

PS: doesn't this break 'make check' if the rom files are missing?

Yes, it does. Obvious incremental fix appended. It still prints rom_add_file()'s message. Swap the operands of && to get rid of it.

hw/sparc64/niagara.c +2 -1
index a14724f..6b78394 100644
@@ -35,6 +35,7 @@
 #include "hw/timer/sun4v-rtc.h"
 #include "exec/address-spaces.h"
 #include "sysemu/block-backend.h"
+#include "sysemu/qtest.h"
 #include "qemu/error-report.h"
 
 
@@ -88,7 +89,7 @@ typedef struct NiagaraBoardState {
 
 static void add_rom_or_fail(const char *file, const hwaddr addr)
 {
-    if (rom_add_file_fixed(file, addr, -1)) {
+    if (rom_add_file_fixed(file, addr, -1) && !qtest_enabled()) {
         error_report("Unable to load a firmware for -M niagara");
         exit(1);
     }
#4 lore raw
Quoted 44 lines · Markus Armbruster
Quoted 24 lines · Peter Maydell
Quoted 23 lines · Peter Maydell
Quoted 22 lines · Artyom Tarasenko
---
 hw/sparc64/niagara.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)
hw/sparc64/niagara.c +1 -0
index b55d4bb..e945b5a 100644
@@ -35,6 +35,7 @@
 #include "hw/timer/sun4v-rtc.h"
 #include "exec/address-spaces.h"
 #include "sysemu/block-backend.h"
+#include "qemu/error-report.h"
 
 
 typedef struct NiagaraBoardState {
@@ -85,6 +86,14 @@ typedef struct NiagaraBoardState {
 #define NIAGARA_OBP_OFFSET  0x80000ULL
 #define PROM_SIZE_MAX       (4 * 1024 * 1024)
 
Quoted 9 lines
Quoted 9 lines

hw/sparc64/niagara.c typedef struct NiagaraBoardState { · line 93

Quoted 5 lines
hw/sparc64/niagara.c +5 -0
+static void add_rom_or_fail(const char *file, const hwaddr addr)
+{
+    if (rom_add_file_fixed(file, addr, -1)) {
+        error_report("Unable to load a firmware for -M niagara");
+        exit(1);

It would be nice to include the name of the file in the error message -- or is that reported already inside rom_add_file_fixed() somehow?

Yes, it is, in rom_add_file():

    if (fd == -1) {
        fprintf(stderr, "Could not open option rom '%s': %s\n",
                rom->path, strerror(errno));
        goto err;
    }
Quoted 5 lines
Quoted 2 lines

PS: doesn't this break 'make check' if the rom files are missing?

Yes, it does. Obvious incremental fix appended. It still prints rom_add_file()'s message. Swap the operands of && to get rid of it.

Thanks, Markus. Will resubmit.

Artyom

Quoted 21 lines
hw/sparc64/niagara.c +2 -1
index a14724f..6b78394 100644
@@ -35,6 +35,7 @@
 #include "hw/timer/sun4v-rtc.h"
 #include "exec/address-spaces.h"
 #include "sysemu/block-backend.h"
+#include "sysemu/qtest.h"
 #include "qemu/error-report.h"
 
 
@@ -88,7 +89,7 @@ typedef struct NiagaraBoardState {
 
 static void add_rom_or_fail(const char *file, const hwaddr addr)
 {
-    if (rom_add_file_fixed(file, addr, -1)) {
+    if (rom_add_file_fixed(file, addr, -1) && !qtest_enabled()) {
         error_report("Unable to load a firmware for -M niagara");
         exit(1);
     }
Signature · 4 lines
Regards,
Artyom Tarasenko

SPARC and PPC PReP under qemu blog: http://tyom.blogspot.com/search/label/qemu
#5 lore raw
In reply to Markus Armbruster
Quoted 6 lines · Markus Armbruster
Quoted 2 lines · Peter Maydell

PS: doesn't this break 'make check' if the rom files are missing?

Yes, it does. Obvious incremental fix appended. It still prints rom_add_file()'s message. Swap the operands of && to get rid of it.

Yes, we should do this with
(!qtest_enabled && rom_add_file_fixed(file, addr, -1))
to avoid printing the warnings in the make check output.

thanks
-- PMM