Device tree cleanups
v2 cover Device tree cleanups
From: Peter Crosthwaite <[email protected]>
Fix the name stem of the devicetree API (P1 - s/qemu_devtree/qemu_fdt) and cleanup error report (P3). Trivial patch P2 fixing an arugment name along the way.
Tested using:
1: Alex's e500 test vector.
2: Xilinx Zynq (tests arm/boot.c).
I have testing using Zynq with Mem > 4gb and a bogus dts (size cells = 1) to give that particular error path some exercise.
To give some exercise to the error paths, I hacked up my libfdt to throw errors randomly:
libfdt/fdt_rw.c +11 -0
@@ -48,6 +48,8 @@* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + +#include <stdlib.h> #include "libfdt_env.h" #include <fdt.h>
@@ -279,6 +281,15 @@ int fdt_setprop(void *fdt, int nodeoffset, const char *name,FDT_RW_CHECK_HEADER (fdt); +static int seeded =0 ; +if (!seeded) { +srand (time (NULL )); + seeded =1 ; + } +if (!(rand () &0x7 )) { +return -((rand () &0x3 ) +1 ); + } +
Some sample outputs from e500 boot (Using the above tainted libfdt):
-----
qemu-system-ppc: qemu_fdt_setprop: Couldn't set /memory/reg: FDT_ERR_BADOFFSET
Aborted
-----
qemu-system-ppc: qemu_fdt_setprop_string: Couldn't set /soc@e0000000/device_type = soc: FDT_ERR_NOSPACE
Aborted
-----
qemu-system-ppc: qemu_fdt_setprop_cell: Couldn't set /soc@e0000000/#address-cells = 0x000001: FDT_ERR_NOSPACE
Aborted
-----
Peter Crosthwaite (3):
device_tree: s/qemu_devtree/qemu_fdt globally
device_tree: qemu_fdt_setprop: Rename val_array arg
device_tree: qemu_fdt_setprop: Fixup error reporting
device_tree.c | 230 +++++++++++++++++++++++++++-------------- hw/arm/boot.c | 51 ++++----- hw/arm/vexpress.c | 23 +++-- hw/microblaze/boot.c | 17 ++- hw/ppc/e500.c | 241 ++++++++++++++++++++++--------------------- hw/ppc/e500.h | 3 +- hw/ppc/e500plat.c | 9 +- hw/ppc/mpc8544ds.c | 9 +- hw/ppc/ppc440_bamboo.c | 34 ++---- hw/ppc/spapr_rtas.c | 40 ++----- hw/ppc/virtex_ml507.c | 5 +- include/sysemu/device_tree.h | 219 ++++++++++++++++++++++++++++++--------- 12 files changed, 519 insertions(+), 362 deletions(-)
Signature · 1 line
1.8.3.rc1.44.gb387c77.dirty
PATCH v2 1/3 device_tree: s/qemu_devtree/qemu_fdt globally
From: Peter Crosthwaite <[email protected]>
The qemu_devtree API is a wrapper around the fdt_ set of APIs. Rename accordingly.
---
device_tree.c | 62 ++++++------- hw/arm/boot.c | 24 ++--- hw/arm/vexpress.c | 18 ++-- hw/microblaze/boot.c | 12 +-- hw/ppc/e500.c | 213 ++++++++++++++++++++++--------------------- hw/ppc/e500plat.c | 6 +- hw/ppc/mpc8544ds.c | 6 +- hw/ppc/ppc440_bamboo.c | 24 ++--- hw/ppc/spapr_rtas.c | 16 ++-- hw/ppc/virtex_ml507.c | 2 +- include/sysemu/device_tree.h | 80 ++++++++-------- 11 files changed, 232 insertions(+), 231 deletions(-)
device_tree.c +31 -31
@@ -127,8 +127,8 @@ static int findnode_nofail(void *fdt, const char *node_path)return offset; } -int qemu_devtree_setprop (void *fdt,const char *node_path, -const char *property,const void *val_array,int size) +int qemu_fdt_setprop (void *fdt,const char *node_path, +const char *property,const void *val_array,int size) {int r;
@@ -142,8 +142,8 @@ int qemu_devtree_setprop(void *fdt, const char *node_path,return r; } -int qemu_devtree_setprop_cell (void *fdt,const char *node_path, -const char *property,uint32_t val) +int qemu_fdt_setprop_cell (void *fdt,const char *node_path, +const char *property,uint32_t val) {int r;
@@ -157,15 +157,15 @@ int qemu_devtree_setprop_cell(void *fdt, const char *node_path,return r; } -int qemu_devtree_setprop_u64 (void *fdt,const char *node_path, -const char *property,uint64_t val) +int qemu_fdt_setprop_u64 (void *fdt,const char *node_path, +const char *property,uint64_t val) { val =cpu_to_be64 (val); -return qemu_devtree_setprop (fdt, node_path, property, &val,sizeof (val)); +return qemu_fdt_setprop (fdt, node_path, property, &val,sizeof (val)); } -int qemu_devtree_setprop_string (void *fdt,const char *node_path, -const char *property,const char *string) +int qemu_fdt_setprop_string (void *fdt,const char *node_path, +const char *property,const char *string) {int r;
@@ -179,8 +179,8 @@ int qemu_devtree_setprop_string(void *fdt, const char *node_path,return r; } -const void *qemu_devtree_getprop (void *fdt,const char *node_path, -const char *property,int *lenp) +const void *qemu_fdt_getprop (void *fdt,const char *node_path, +const char *property,int *lenp) {int len;const void *r;
@@ -196,11 +196,11 @@ const void *qemu_devtree_getprop(void *fdt, const char *node_path,return r; } -uint32_t qemu_devtree_getprop_cell (void *fdt,const char *node_path, -const char *property) +uint32_t qemu_fdt_getprop_cell (void *fdt,const char *node_path, +const char *property) {int len; -const uint32_t *p =qemu_devtree_getprop (fdt, node_path, property, &len); +const uint32_t *p =qemu_fdt_getprop (fdt, node_path, property, &len);if (len !=4 ) {fprintf (stderr,"%s: %s/%s not 4 bytes long (not a cell?)\n" , __func__, node_path, property);
@@ -209,7 +209,7 @@ uint32_t qemu_devtree_getprop_cell(void *fdt, const char *node_path,return be32_to_cpu (*p); } -uint32_t qemu_devtree_get_phandle (void *fdt,const char *path) +uint32_t qemu_fdt_get_phandle (void *fdt,const char *path) {uint32_t r;
@@ -223,15 +223,15 @@ uint32_t qemu_devtree_get_phandle(void *fdt, const char *path)return r; } -int qemu_devtree_setprop_phandle (void *fdt,const char *node_path, -const char *property, -const char *target_node_path) +int qemu_fdt_setprop_phandle (void *fdt,const char *node_path, +const char *property, +const char *target_node_path) { -uint32_t phandle =qemu_devtree_get_phandle (fdt, target_node_path); -return qemu_devtree_setprop_cell (fdt, node_path, property, phandle); +uint32_t phandle =qemu_fdt_get_phandle (fdt, target_node_path); +return qemu_fdt_setprop_cell (fdt, node_path, property, phandle); } -uint32_t qemu_devtree_alloc_phandle (void *fdt) +uint32_t qemu_fdt_alloc_phandle (void *fdt) {static int phandle =0x0 ;
@@ -255,7 +255,7 @@ uint32_t qemu_devtree_alloc_phandle(void *fdt)return phandle++; } -int qemu_devtree_nop_node (void *fdt,const char *node_path) +int qemu_fdt_nop_node (void *fdt,const char *node_path) {int r;
@@ -269,7 +269,7 @@ int qemu_devtree_nop_node(void *fdt, const char *node_path)return r; } -int qemu_devtree_add_subnode (void *fdt,const char *name) +int qemu_fdt_add_subnode (void *fdt,const char *name) {char *dupname =g_strdup (name);char *basename =strrchr (dupname,'/' );
@@ -299,7 +299,7 @@ int qemu_devtree_add_subnode(void *fdt, const char *name)return retval; } -void qemu_devtree_dumpdtb (void *fdt,int size) +void qemu_fdt_dumpdtb (void *fdt,int size) {const char *dumpdtb =qemu_opt_get (qemu_get_machine_opts (),"dumpdtb" );
@@ -309,11 +309,11 @@ void qemu_devtree_dumpdtb(void *fdt, int size) } } -int qemu_devtree_setprop_sized_cells_from_array (void *fdt, -const char *node_path, -const char *property, -int numvalues, -uint64_t *values) +int qemu_fdt_setprop_sized_cells_from_array (void *fdt, +const char *node_path, +const char *property, +int numvalues, +uint64_t *values) {uint32_t *propcells;uint64_t value;
@@ -338,6 +338,6 @@ int qemu_devtree_setprop_sized_cells_from_array(void *fdt, propcells[cellnum++] =cpu_to_be32 (value); } -return qemu_devtree_setprop (fdt, node_path, property, propcells, - cellnum *sizeof (uint32_t )); +return qemu_fdt_setprop (fdt, node_path, property, propcells, + cellnum *sizeof (uint32_t )); }
hw/arm/boot.c +12 -12
@@ -246,8 +246,8 @@ static int load_dtb(hwaddr addr, const struct arm_boot_info *binfo) }g_free (filename); - acells =qemu_devtree_getprop_cell (fdt,"/" ,"#address-cells" ); - scells =qemu_devtree_getprop_cell (fdt,"/" ,"#size-cells" ); + acells =qemu_fdt_getprop_cell (fdt,"/" ,"#address-cells" ); + scells =qemu_fdt_getprop_cell (fdt,"/" ,"#size-cells" );if (acells ==0 || scells ==0 ) {fprintf (stderr,"dtb file invalid (#address-cells or #size-cells 0)\n" ); goto fail;
@@ -262,17 +262,17 @@ static int load_dtb(hwaddr addr, const struct arm_boot_info *binfo) goto fail; } - rc =qemu_devtree_setprop_sized_cells (fdt,"/memory" ,"reg" , - acells, binfo->loader_start, - scells, binfo->ram_size); + rc =qemu_fdt_setprop_sized_cells (fdt,"/memory" ,"reg" , + acells, binfo->loader_start, + scells, binfo->ram_size);if (rc <0 ) {fprintf (stderr,"couldn't set /memory/reg\n" ); goto fail; }if (binfo->kernel_cmdline && *binfo->kernel_cmdline) { - rc =qemu_devtree_setprop_string (fdt,"/chosen" ,"bootargs" , - binfo->kernel_cmdline); + rc =qemu_fdt_setprop_string (fdt,"/chosen" ,"bootargs" , + binfo->kernel_cmdline);if (rc <0 ) {fprintf (stderr,"couldn't set /chosen/bootargs\n" ); goto fail;
@@ -280,15 +280,15 @@ static int load_dtb(hwaddr addr, const struct arm_boot_info *binfo) }if (binfo->initrd_size) { - rc =qemu_devtree_setprop_cell (fdt,"/chosen" ,"linux,initrd-start" , - binfo->initrd_start); + rc =qemu_fdt_setprop_cell (fdt,"/chosen" ,"linux,initrd-start" , + binfo->initrd_start);if (rc <0 ) {fprintf (stderr,"couldn't set /chosen/linux,initrd-start\n" ); goto fail; } - rc =qemu_devtree_setprop_cell (fdt,"/chosen" ,"linux,initrd-end" , - binfo->initrd_start + binfo->initrd_size); + rc =qemu_fdt_setprop_cell (fdt,"/chosen" ,"linux,initrd-end" , + binfo->initrd_start + binfo->initrd_size);if (rc <0 ) {fprintf (stderr,"couldn't set /chosen/linux,initrd-end\n" ); goto fail;
@@ -299,7 +299,7 @@ static int load_dtb(hwaddr addr, const struct arm_boot_info *binfo) binfo->modify_dtb (binfo, fdt); } -qemu_devtree_dumpdtb (fdt, size); +qemu_fdt_dumpdtb (fdt, size);cpu_physical_memory_write (addr, fdt, size);
hw/arm/vexpress.c +9 -9
@@ -419,13 +419,13 @@ static int add_virtio_mmio_node(void *fdt, uint32_t acells, uint32_t scells,int rc;char *nodename =g_strdup_printf ("/virtio_mmio@%" PRIx64, addr); - rc =qemu_devtree_add_subnode (fdt, nodename); - rc |=qemu_devtree_setprop_string (fdt, nodename, -"compatible" ,"virtio,mmio" ); - rc |=qemu_devtree_setprop_sized_cells (fdt, nodename,"reg" , - acells, addr, scells, size); -qemu_devtree_setprop_cells (fdt, nodename,"interrupt-parent" , intc); -qemu_devtree_setprop_cells (fdt, nodename,"interrupts" ,0 , irq,1 ); + rc =qemu_fdt_add_subnode (fdt, nodename); + rc |=qemu_fdt_setprop_string (fdt, nodename, +"compatible" ,"virtio,mmio" ); + rc |=qemu_fdt_setprop_sized_cells (fdt, nodename,"reg" , + acells, addr, scells, size); +qemu_fdt_setprop_cells (fdt, nodename,"interrupt-parent" , intc); +qemu_fdt_setprop_cells (fdt, nodename,"interrupts" ,0 , irq,1 );g_free (nodename);if (rc) {return -1 ;
@@ -456,8 +456,8 @@ static void vexpress_modify_dtb(const struct arm_boot_info *info, void *fdt)uint32_t acells, scells, intc;const VEDBoardInfo *daughterboard = (const VEDBoardInfo *)info; - acells =qemu_devtree_getprop_cell (fdt,"/" ,"#address-cells" ); - scells =qemu_devtree_getprop_cell (fdt,"/" ,"#size-cells" ); + acells =qemu_fdt_getprop_cell (fdt,"/" ,"#address-cells" ); + scells =qemu_fdt_getprop_cell (fdt,"/" ,"#size-cells" ); intc =find_int_controller (fdt);if (!intc) {/* Not fatal, we just won't provide virtio. This will
hw/microblaze/boot.c +6 -6
@@ -79,19 +79,19 @@ static int microblaze_load_dtb(hwaddr addr, }if (kernel_cmdline) { - r =qemu_devtree_setprop_string (fdt,"/chosen" ,"bootargs" , - kernel_cmdline); + r =qemu_fdt_setprop_string (fdt,"/chosen" ,"bootargs" , + kernel_cmdline);if (r <0 ) {fprintf (stderr,"couldn't set /chosen/bootargs\n" ); } }if (initrd_start) { -qemu_devtree_setprop_cell (fdt,"/chosen" ,"linux,initrd-start" , - initrd_start); +qemu_fdt_setprop_cell (fdt,"/chosen" ,"linux,initrd-start" , + initrd_start); -qemu_devtree_setprop_cell (fdt,"/chosen" ,"linux,initrd-end" , - initrd_end); +qemu_fdt_setprop_cell (fdt,"/chosen" ,"linux,initrd-end" , + initrd_end); }cpu_physical_memory_write (addr, fdt, fdt_size);
hw/ppc/e500.c +107 -106
297 lines not on this page · raw message
hw/ppc/e500plat.c +3 -3
@@ -23,9 +23,9 @@ static void e500plat_fixup_devtree(PPCE500Params *params, void *fdt)const char model[] ="QEMU ppce500" ;const char compatible[] ="fsl,qemu-e500" ; -qemu_devtree_setprop (fdt,"/" ,"model" , model,sizeof (model)); -qemu_devtree_setprop (fdt,"/" ,"compatible" , compatible, -sizeof (compatible)); +qemu_fdt_setprop (fdt,"/" ,"model" , model,sizeof (model)); +qemu_fdt_setprop (fdt,"/" ,"compatible" , compatible, +sizeof (compatible)); }static void e500plat_init (QEMUMachineInitArgs *args)
hw/ppc/mpc8544ds.c +3 -3
@@ -21,9 +21,9 @@ static void mpc8544ds_fixup_devtree(PPCE500Params *params, void *fdt)const char model[] ="MPC8544DS" ;const char compatible[] ="MPC8544DS\0MPC85xxDS" ; -qemu_devtree_setprop (fdt,"/" ,"model" , model,sizeof (model)); -qemu_devtree_setprop (fdt,"/" ,"compatible" , compatible, -sizeof (compatible)); +qemu_fdt_setprop (fdt,"/" ,"model" , model,sizeof (model)); +qemu_fdt_setprop (fdt,"/" ,"compatible" , compatible, +sizeof (compatible)); }static void mpc8544ds_init (QEMUMachineInitArgs *args)
hw/ppc/ppc440_bamboo.c +12 -12
@@ -77,23 +77,23 @@ static int bamboo_load_device_tree(hwaddr addr,/* Manipulate device tree in memory. */ - ret =qemu_devtree_setprop (fdt,"/memory" ,"reg" , mem_reg_property, -sizeof (mem_reg_property)); + ret =qemu_fdt_setprop (fdt,"/memory" ,"reg" , mem_reg_property, +sizeof (mem_reg_property));if (ret <0 )fprintf (stderr,"couldn't set /memory/reg\n" ); - ret =qemu_devtree_setprop_cell (fdt,"/chosen" ,"linux,initrd-start" , - initrd_base); + ret =qemu_fdt_setprop_cell (fdt,"/chosen" ,"linux,initrd-start" , + initrd_base);if (ret <0 )fprintf (stderr,"couldn't set /chosen/linux,initrd-start\n" ); - ret =qemu_devtree_setprop_cell (fdt,"/chosen" ,"linux,initrd-end" , - (initrd_base + initrd_size)); + ret =qemu_fdt_setprop_cell (fdt,"/chosen" ,"linux,initrd-end" , + (initrd_base + initrd_size));if (ret <0 )fprintf (stderr,"couldn't set /chosen/linux,initrd-end\n" ); - ret =qemu_devtree_setprop_string (fdt,"/chosen" ,"bootargs" , - kernel_cmdline); + ret =qemu_fdt_setprop_string (fdt,"/chosen" ,"bootargs" , + kernel_cmdline);if (ret <0 )fprintf (stderr,"couldn't set /chosen/bootargs\n" );
@@ -105,10 +105,10 @@ static int bamboo_load_device_tree(hwaddr addr, clock_freq =kvmppc_get_clockfreq (); } -qemu_devtree_setprop_cell (fdt,"/cpus/cpu@0" ,"clock-frequency" , - clock_freq); -qemu_devtree_setprop_cell (fdt,"/cpus/cpu@0" ,"timebase-frequency" , - tb_freq); +qemu_fdt_setprop_cell (fdt,"/cpus/cpu@0" ,"clock-frequency" , + clock_freq); +qemu_fdt_setprop_cell (fdt,"/cpus/cpu@0" ,"timebase-frequency" , + tb_freq); ret =rom_add_blob_fixed (BINARY_DEVICE_TREE_FILE , fdt, fdt_size, addr);g_free (fdt);
hw/ppc/spapr_rtas.c +8 -8
@@ -291,24 +291,24 @@ int spapr_rtas_device_tree_setup(void *fdt, hwaddr rtas_addr,return ret; } - ret =qemu_devtree_setprop_cell (fdt,"/rtas" ,"linux,rtas-base" , - rtas_addr); + ret =qemu_fdt_setprop_cell (fdt,"/rtas" ,"linux,rtas-base" , + rtas_addr);if (ret <0 ) {fprintf (stderr,"Couldn't add linux,rtas-base property: %s\n" ,fdt_strerror (ret));return ret; } - ret =qemu_devtree_setprop_cell (fdt,"/rtas" ,"linux,rtas-entry" , - rtas_addr); + ret =qemu_fdt_setprop_cell (fdt,"/rtas" ,"linux,rtas-entry" , + rtas_addr);if (ret <0 ) {fprintf (stderr,"Couldn't add linux,rtas-entry property: %s\n" ,fdt_strerror (ret));return ret; } - ret =qemu_devtree_setprop_cell (fdt,"/rtas" ,"rtas-size" , - rtas_size); + ret =qemu_fdt_setprop_cell (fdt,"/rtas" ,"rtas-size" , + rtas_size);if (ret <0 ) {fprintf (stderr,"Couldn't add rtas-size property: %s\n" ,fdt_strerror (ret));
@@ -322,8 +322,8 @@ int spapr_rtas_device_tree_setup(void *fdt, hwaddr rtas_addr,continue ; } - ret =qemu_devtree_setprop_cell (fdt,"/rtas" , call->name, - i +TOKEN_BASE ); + ret =qemu_fdt_setprop_cell (fdt,"/rtas" , call->name, + i +TOKEN_BASE );if (ret <0 ) {fprintf (stderr,"Couldn't add rtas token for %s: %s\n" , call->name,fdt_strerror (ret));
hw/ppc/virtex_ml507.c +1 -1
@@ -166,7 +166,7 @@ static int xilinx_load_device_tree(hwaddr addr,if (!fdt) {return 0 ; } - r =qemu_devtree_setprop_string (fdt,"/chosen" ,"bootargs" , kernel_cmdline); + r =qemu_fdt_setprop_string (fdt,"/chosen" ,"bootargs" , kernel_cmdline);if (r <0 )fprintf (stderr,"couldn't set /chosen/bootargs\n" );cpu_physical_memory_write (addr, fdt, fdt_size);
include/sysemu/device_tree.h +40 -40
118 lines not on this page · raw message
Signature · 1 line
1.8.3.rc1.44.gb387c77.dirty
PATCH v2 2/3 device_tree: qemu_fdt_setprop: Rename val_array arg
In reply to [email protected]From: Peter Crosthwaite <[email protected]>
Looking at the implementation, this doesn't really have a lot to do with arrays. Its just a pointer to a buffer and is passed through to the wrapped fn (qemu_fdt_setprop) unchanged. So rename to make it consistent with libfdt, which in the wrapped function just calls it "val".
---
device_tree.c | 4 ++-- include/sysemu/device_tree.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
device_tree.c +2 -2
@@ -128,11 +128,11 @@ static int findnode_nofail(void *fdt, const char *node_path) }int qemu_fdt_setprop (void *fdt,const char *node_path, -const char *property,const void *val_array,int size) +const char *property,const void *val,int size) {int r; - r =fdt_setprop (fdt,findnode_nofail (fdt, node_path), property, val_array, size); + r =fdt_setprop (fdt,findnode_nofail (fdt, node_path), property, val, size);if (r <0 ) {fprintf (stderr,"%s: Couldn't set %s/%s: %s\n" , __func__, node_path, property,fdt_strerror (r));
include/sysemu/device_tree.h +1 -1
@@ -18,7 +18,7 @@ void *create_device_tree(int *sizep);void *load_device_tree (const char *filename_path,int *sizep);int qemu_fdt_setprop (void *fdt,const char *node_path, -const char *property,const void *val_array,int size); +const char *property,const void *val,int size);int qemu_fdt_setprop_cell (void *fdt,const char *node_path,const char *property,uint32_t val); int qemu_fdt_setprop_u64(void *fdt, const char *node_path,
Signature · 1 line
1.8.3.rc1.44.gb387c77.dirty
PATCH v2 3/3 device_tree: qemu_fdt_setprop: Fixup error reporting
In reply to [email protected]From: Peter Crosthwaite <[email protected]>
There are a mix of usages of the qemu_fdt_* API calls, some which wish to assert and abort QEMU on failure and some of which wish to do their own error handling. The latter in more correct, but the former is in the majority and more pragmatic. However the asserting clients are usually doing large numbers fdt ops and only want to assert if any one of them breaks. So the cleanest compromising solution is:
1. Require an Error ** to be passes to all fdt ops.
2. And perform no action if its already non-null (error condition).
3. If no Error ** is given report errors to stderr
Step one allows clients to do their own error handling if they wish too, which is the most flexible:
Error *err = NULL;
fdt_foo( ... , &err);
if (err) {
/* handle error my special way */
}Step two allows you to do a large number of fdt ops then check them all only the once at the end:
Error *err = NULL;
fdt_foo( ... , &err);
fdt_bar( ... , &err);
fdt_baz( ... , &err);
if (err) {
/* First encountered error will be in err */
}Step 3, handles the common case where the error is not an issue, but just needs to make noise at the user (via stderr). This seems common for bootloader code that sets chosen and initrd props etc (rather than machine description).
All error reporting is stylistically udpated to use Error ** instead of integer return codes and no more exit(1) on failures.
---
device_tree.c | 222 ++++++++++++++++++++++++++++--------------- hw/arm/boot.c | 49 ++++------ hw/arm/vexpress.c | 23 ++--- hw/microblaze/boot.c | 13 +-- hw/ppc/e500.c | 214 ++++++++++++++++++++--------------------- hw/ppc/e500.h | 3 +- hw/ppc/e500plat.c | 9 +- hw/ppc/mpc8544ds.c | 9 +- hw/ppc/ppc440_bamboo.c | 30 ++---- hw/ppc/spapr_rtas.c | 40 ++------ hw/ppc/virtex_ml507.c | 5 +- include/sysemu/device_tree.h | 193 ++++++++++++++++++++++++++++++------- 12 files changed, 483 insertions(+), 327 deletions(-)
device_tree.c +147 -75
@@ -4,8 +4,10 @@* interface. * * Copyright 2008 IBM Corporation. +* Copyright 2013 Xilinx Inc. * Authors: Jerone Young <[email protected]> * Hollis Blanchard <[email protected]> +* Peter Crosthwaite <[email protected]> * * This work is licensed under the GNU GPL license version 2 or later. *
@@ -113,122 +115,176 @@ fail:return NULL ; } -static int findnode_nofail (void *fdt,const char *node_path) +#define error_set_or_print (errp, ...) \ + do { \ + if (errp) { \ + error_setg(errp, __VA_ARGS__); \ + } else { \ + fprintf(stderr, __VA_ARGS__); \ + } \ + } while (0) + +static int findnode (void *fdt,const char *node_path,Error **errp) {int offset; offset =fdt_path_offset (fdt, node_path);if (offset <0 ) { -fprintf (stderr,"%s Couldn't find node %s: %s\n" , __func__, node_path, -fdt_strerror (offset)); -exit (1 ); +error_set_or_print (errp,"%s Couldn't find node %s: %s\n" , __func__, + node_path,fdt_strerror (offset)); }return offset; } -int qemu_fdt_setprop (void *fdt,const char *node_path, -const char *property,const void *val,int size) +void qemu_fdt_setprop (void *fdt,const char *node_path,const char *property, +const void *val,int size,Error **errp) {int r; - r =fdt_setprop (fdt,findnode_nofail (fdt, node_path), property, val, size); -if (r <0 ) { -fprintf (stderr,"%s: Couldn't set %s/%s: %s\n" , __func__, node_path, - property,fdt_strerror (r)); -exit (1 ); +if (errp && *errp) { +return ; } -return r; + r =findnode (fdt, node_path, errp); +if (r <0 ) { +return ; + } + r =fdt_setprop (fdt, r, property, val, size); +if (r <0 ) { +error_set_or_print (errp,"%s: Couldn't set %s/%s: %s\n" , __func__, + node_path, property,fdt_strerror (r)); + } } -int qemu_fdt_setprop_cell (void *fdt,const char *node_path, -const char *property,uint32_t val) +void qemu_fdt_setprop_cell (void *fdt,const char *node_path, +const char *property,uint32_t val,Error **errp) {int r; - r =fdt_setprop_cell (fdt,findnode_nofail (fdt, node_path), property, val); -if (r <0 ) { -fprintf (stderr,"%s: Couldn't set %s/%s = %#08x: %s\n" , __func__, - node_path, property, val,fdt_strerror (r)); -exit (1 ); +if (errp && *errp) { +return ; } -return r; + r =findnode (fdt, node_path, errp); +if (r <0 ) { +return ; + } + r =fdt_setprop_cell (fdt, r, property, val); +if (r <0 ) { +error_set_or_print (errp,"%s: Couldn't set %s/%s = %#08x: %s\n" , + __func__, node_path, property, val,fdt_strerror (r)); + } } -int qemu_fdt_setprop_u64 (void *fdt,const char *node_path, -const char *property,uint64_t val) +void qemu_fdt_setprop_u64 (void *fdt,const char *node_path, +const char *property,uint64_t val,Error **errp) { val =cpu_to_be64 (val); -return qemu_fdt_setprop (fdt, node_path, property, &val,sizeof (val)); +qemu_fdt_setprop (fdt, node_path, property, &val,sizeof (val), errp); } -int qemu_fdt_setprop_string (void *fdt,const char *node_path, -const char *property,const char *string) +void qemu_fdt_setprop_string (void *fdt,const char *node_path, +const char *property,const char *string, +Error **errp) {int r; - r =fdt_setprop_string (fdt,findnode_nofail (fdt, node_path), property, string); -if (r <0 ) { -fprintf (stderr,"%s: Couldn't set %s/%s = %s: %s\n" , __func__, - node_path, property, string,fdt_strerror (r)); -exit (1 ); +if (errp && *errp) { +return ; } -return r; + r =findnode (fdt, node_path, errp); +if (r <0 ) { +return ; + } + r =fdt_setprop_string (fdt, r, property, string); +if (r <0 ) { +error_set_or_print (errp,"%s: Couldn't set %s/%s = %s: %s\n" , __func__, + node_path, property, string,fdt_strerror (r)); + } }const void *qemu_fdt_getprop (void *fdt,const char *node_path, -const char *property,int *lenp) +const char *property,int *lenp,Error **errp) {int len; +int node;const void *r; + +if (errp && *errp) { +return NULL ; + } +if (!lenp) { lenp = &len; } - r =fdt_getprop (fdt,findnode_nofail (fdt, node_path), property, lenp); + + node =findnode (fdt, node_path, errp); +if (node <0 ) { +return NULL ; + } + r =fdt_getprop (fdt, node, property, lenp);if (!r) { -fprintf (stderr,"%s: Couldn't get %s/%s: %s\n" , __func__, - node_path, property,fdt_strerror (*lenp)); -exit (1 ); +error_set_or_print (errp,"%s: Couldn't get %s/%s: %s\n" , __func__, + node_path, property,fdt_strerror (*lenp)); +return NULL ; }return r; }uint32_t qemu_fdt_getprop_cell (void *fdt,const char *node_path, -const char *property) +const char *property,Error **errp) {int len; -const uint32_t *p =qemu_fdt_getprop (fdt, node_path, property, &len); +const uint32_t *p; + +if (errp && *errp) { +return 0 ; + } + + p =qemu_fdt_getprop (fdt, node_path, property, &len, errp); +if (!p) { +return 0 ; + } +if (len !=4 ) { -fprintf (stderr,"%s: %s/%s not 4 bytes long (not a cell?)\n" , - __func__, node_path, property); -exit (1 ); +error_set_or_print (errp,"%s: %s/%s not 4 bytes long (not a cell?)\n" , + __func__, node_path, property); +return 0 ; }return be32_to_cpu (*p); } -uint32_t qemu_fdt_get_phandle (void *fdt,const char *path) +uint32_t qemu_fdt_get_phandle (void *fdt,const char *path,Error **errp) { +int node;uint32_t r; - r =fdt_get_phandle (fdt,findnode_nofail (fdt, path)); +if (errp && *errp) { +return 0 ; + } + + node =findnode (fdt, path, errp); +if (node <0 ) { +return 0 ; + } + r =fdt_get_phandle (fdt, node);if (r ==0 ) { -fprintf (stderr,"%s: Couldn't get phandle for %s: %s\n" , __func__, - path,fdt_strerror (r)); -exit (1 ); +error_set_or_print (errp,"%s: Couldn't get phandle for %s: %s\n" , + __func__, path,fdt_strerror (r)); +return 0 ; }return r; } -int qemu_fdt_setprop_phandle (void *fdt,const char *node_path, -const char *property, -const char *target_node_path) +void qemu_fdt_setprop_phandle (void *fdt,const char *node_path, +const char *property, +const char *target_node_path,Error **errp) { -uint32_t phandle =qemu_fdt_get_phandle (fdt, target_node_path); -return qemu_fdt_setprop_cell (fdt, node_path, property, phandle); +uint32_t phandle =qemu_fdt_get_phandle (fdt, target_node_path, errp); +qemu_fdt_setprop_cell (fdt, node_path, property, phandle, errp); }uint32_t qemu_fdt_alloc_phandle (void *fdt)
@@ -255,48 +311,54 @@ uint32_t qemu_fdt_alloc_phandle(void *fdt)return phandle++; } -int qemu_fdt_nop_node (void *fdt,const char *node_path) +void qemu_fdt_nop_node (void *fdt,const char *node_path,Error **errp) {int r; - r =fdt_nop_node (fdt,findnode_nofail (fdt, node_path)); -if (r <0 ) { -fprintf (stderr,"%s: Couldn't nop node %s: %s\n" , __func__, node_path, -fdt_strerror (r)); -exit (1 ); +if (errp && *errp) { +return ; } -return r; + r =findnode (fdt, node_path, errp); +if (r <0 ) { +return ; + } + r =fdt_nop_node (fdt, r); +if (r <0 ) { +error_set_or_print (errp,"%s: Couldn't nop node %s: %s\n" , __func__, + node_path,fdt_strerror (r)); + } } -int qemu_fdt_add_subnode (void *fdt,const char *name) +void qemu_fdt_add_subnode (void *fdt,const char *name,Error **errp) {char *dupname =g_strdup (name);char *basename =strrchr (dupname,'/' );int retval;int parent =0 ; -if (!basename) { +if (!basename || (errp && *errp)) {g_free (dupname); -return -1 ; +return ; } basename[0 ] ='\0' ; basename++;if (dupname[0 ]) { - parent =findnode_nofail (fdt, dupname); + parent =findnode (fdt, dupname, errp); +if (parent <0 ) { +return ; + } } retval =fdt_add_subnode (fdt, parent, basename);if (retval <0 ) { -fprintf (stderr,"FDT: Failed to create subnode %s: %s\n" , name, -fdt_strerror (retval)); -exit (1 ); +error_set_or_print (errp,"FDT: Failed to create subnode %s: %s\n" , + name,fdt_strerror (retval)); }g_free (dupname); -return retval; }void qemu_fdt_dumpdtb (void *fdt,int size)
@@ -309,35 +371,45 @@ void qemu_fdt_dumpdtb(void *fdt, int size) } } -int qemu_fdt_setprop_sized_cells_from_array (void *fdt, -const char *node_path, -const char *property, -int numvalues, -uint64_t *values) +void qemu_fdt_setprop_sized_cells_from_array (void *fdt, +const char *node_path, +const char *property, +int numvalues, +uint64_t *values,Error **errp) {uint32_t *propcells;uint64_t value;int cellnum, vnum, ncells;uint32_t hival; +if (errp && *errp) { +return ; + } + propcells =g_new0 (uint32_t, numvalues *2 ); cellnum =0 ;for (vnum =0 ; vnum < numvalues; vnum++) { ncells = values[vnum *2 ];if (ncells !=1 && ncells !=2 ) { -return -1 ; +error_set_or_print (errp,"%s: Setting property %s/%s, element [%d]:" +" Unsupported number of cells:%d" , __func__, + node_path, property, vnum, ncells); +return ; } value = values[vnum *2 +1 ]; hival =cpu_to_be32 (value >>32 );if (ncells >1 ) { propcells[cellnum++] = hival; }else if (hival !=0 ) { -return -1 ; +error_set_or_print (errp,"%s: Setting property %s/%s, element [%d]:" +" Value too large for single cell: %#" PRIx64, + __func__, node_path, property, vnum, value); +return ; } propcells[cellnum++] =cpu_to_be32 (value); } -return qemu_fdt_setprop (fdt, node_path, property, propcells, - cellnum *sizeof (uint32_t )); +qemu_fdt_setprop (fdt, node_path, property, propcells, + cellnum *sizeof (uint32_t ), errp); }
hw/arm/boot.c +20 -29
83 lines not on this page · raw message
hw/arm/vexpress.c +12 -11
@@ -416,18 +416,19 @@ static int add_virtio_mmio_node(void *fdt, uint32_t acells, uint32_t scells,* interrupt controller that interrupt-parent points to; these are for * the ARM GIC and indicate an SPI interrupt, rising-edge-triggered.) */ -int rc; +Error *err =NULL ;char *nodename =g_strdup_printf ("/virtio_mmio@%" PRIx64, addr); - rc =qemu_fdt_add_subnode (fdt, nodename); - rc |=qemu_fdt_setprop_string (fdt, nodename, -"compatible" ,"virtio,mmio" ); - rc |=qemu_fdt_setprop_sized_cells (fdt, nodename,"reg" , - acells, addr, scells, size); -qemu_fdt_setprop_cells (fdt, nodename,"interrupt-parent" , intc); -qemu_fdt_setprop_cells (fdt, nodename,"interrupts" ,0 , irq,1 ); +qemu_fdt_add_subnode (fdt, nodename, &err); +qemu_fdt_setprop_string (fdt, nodename,"compatible" ,"virtio,mmio" , &err); +qemu_fdt_setprop_sized_cells (fdt, nodename,"reg" , &err, acells, addr, + scells, size); +qemu_fdt_setprop_cells (fdt, nodename,"interrupt-parent" , &err, intc); +qemu_fdt_setprop_cells (fdt, nodename,"interrupts" , &err,0 , irq,1 );g_free (nodename); -if (rc) { +if (err) { +fprintf (stderr,"%s\n" ,error_get_pretty (err)); +error_free (err);return -1 ; }return 0 ;
@@ -456,8 +457,8 @@ static void vexpress_modify_dtb(const struct arm_boot_info *info, void *fdt)uint32_t acells, scells, intc;const VEDBoardInfo *daughterboard = (const VEDBoardInfo *)info; - acells =qemu_fdt_getprop_cell (fdt,"/" ,"#address-cells" ); - scells =qemu_fdt_getprop_cell (fdt,"/" ,"#size-cells" ); + acells =qemu_fdt_getprop_cell (fdt,"/" ,"#address-cells" ,NULL ); + scells =qemu_fdt_getprop_cell (fdt,"/" ,"#size-cells" ,NULL ); intc =find_int_controller (fdt);if (!intc) {/* Not fatal, we just won't provide virtio. This will
hw/microblaze/boot.c +5 -8
@@ -69,7 +69,7 @@ static int microblaze_load_dtb(hwaddr addr, {int fdt_size;void *fdt =NULL ; -int r; +Error *err =NULL ;if (dtb_filename) { fdt =load_device_tree (dtb_filename, &fdt_size);
@@ -79,19 +79,16 @@ static int microblaze_load_dtb(hwaddr addr, }if (kernel_cmdline) { - r =qemu_fdt_setprop_string (fdt,"/chosen" ,"bootargs" , - kernel_cmdline); -if (r <0 ) { -fprintf (stderr,"couldn't set /chosen/bootargs\n" ); - } +qemu_fdt_setprop_string (fdt,"/chosen" ,"bootargs" , + kernel_cmdline, &err); }if (initrd_start) {qemu_fdt_setprop_cell (fdt,"/chosen" ,"linux,initrd-start" , - initrd_start); + initrd_start, &err);qemu_fdt_setprop_cell (fdt,"/chosen" ,"linux,initrd-end" , - initrd_end); + initrd_end, &err); }cpu_physical_memory_write (addr, fdt, fdt_size);
hw/ppc/e500.c +107 -107
319 lines not on this page · raw message
hw/ppc/e500.h +2 -1
@@ -8,7 +8,8 @@ typedef struct PPCE500Params {int pci_nr_slots;/* required -- must at least add toplevel board compatible */ -void (*fixup_devtree)(struct PPCE500Params *params,void *fdt); +void (*fixup_devtree)(struct PPCE500Params *params,void *fdt, +Error **errp);int mpic_version; } PPCE500Params;
hw/ppc/e500plat.c +5 -4
@@ -18,14 +18,15 @@#include "hw/ppc/openpic.h" #include "kvm_ppc.h" -static void e500plat_fixup_devtree (PPCE500Params *params,void *fdt) +static void e500plat_fixup_devtree (PPCE500Params *params,void *fdt, +Error **errp) {const char model[] ="QEMU ppce500" ;const char compatible[] ="fsl,qemu-e500" ; -qemu_fdt_setprop (fdt,"/" ,"model" , model,sizeof (model)); -qemu_fdt_setprop (fdt,"/" ,"compatible" , compatible, -sizeof (compatible)); +qemu_fdt_setprop (fdt,"/" ,"model" , model,sizeof (model), errp); +qemu_fdt_setprop (fdt,"/" ,"compatible" , compatible,sizeof (compatible), + errp); }static void e500plat_init (QEMUMachineInitArgs *args)
hw/ppc/mpc8544ds.c +5 -4
@@ -16,14 +16,15 @@#include "sysemu/device_tree.h" #include "hw/ppc/openpic.h" -static void mpc8544ds_fixup_devtree (PPCE500Params *params,void *fdt) +static void mpc8544ds_fixup_devtree (PPCE500Params *params,void *fdt, +Error **errp) {const char model[] ="MPC8544DS" ;const char compatible[] ="MPC8544DS\0MPC85xxDS" ; -qemu_fdt_setprop (fdt,"/" ,"model" , model,sizeof (model)); -qemu_fdt_setprop (fdt,"/" ,"compatible" , compatible, -sizeof (compatible)); +qemu_fdt_setprop (fdt,"/" ,"model" , model,sizeof (model), errp); +qemu_fdt_setprop (fdt,"/" ,"compatible" , compatible,sizeof (compatible), + errp); }static void mpc8544ds_init (QEMUMachineInitArgs *args)
hw/ppc/ppc440_bamboo.c +9 -21
@@ -77,25 +77,13 @@ static int bamboo_load_device_tree(hwaddr addr,/* Manipulate device tree in memory. */ - ret =qemu_fdt_setprop (fdt,"/memory" ,"reg" , mem_reg_property, -sizeof (mem_reg_property)); -if (ret <0 ) -fprintf (stderr,"couldn't set /memory/reg\n" ); - - ret =qemu_fdt_setprop_cell (fdt,"/chosen" ,"linux,initrd-start" , - initrd_base); -if (ret <0 ) -fprintf (stderr,"couldn't set /chosen/linux,initrd-start\n" ); - - ret =qemu_fdt_setprop_cell (fdt,"/chosen" ,"linux,initrd-end" , - (initrd_base + initrd_size)); -if (ret <0 ) -fprintf (stderr,"couldn't set /chosen/linux,initrd-end\n" ); - - ret =qemu_fdt_setprop_string (fdt,"/chosen" ,"bootargs" , - kernel_cmdline); -if (ret <0 ) -fprintf (stderr,"couldn't set /chosen/bootargs\n" ); +qemu_fdt_setprop (fdt,"/memory" ,"reg" , mem_reg_property, +sizeof (mem_reg_property),NULL ); +qemu_fdt_setprop_cell (fdt,"/chosen" ,"linux,initrd-start" , + initrd_base,NULL ); +qemu_fdt_setprop_cell (fdt,"/chosen" ,"linux,initrd-end" , + (initrd_base + initrd_size),NULL ); +qemu_fdt_setprop_string (fdt,"/chosen" ,"bootargs" , kernel_cmdline,NULL );/* Copy data from the host device tree into the guest. Since the guest can * directly access the timebase without host involvement, we must expose
@@ -106,9 +94,9 @@ static int bamboo_load_device_tree(hwaddr addr, }qemu_fdt_setprop_cell (fdt,"/cpus/cpu@0" ,"clock-frequency" , - clock_freq); + clock_freq,NULL );qemu_fdt_setprop_cell (fdt,"/cpus/cpu@0" ,"timebase-frequency" , - tb_freq); + tb_freq,NULL ); ret =rom_add_blob_fixed (BINARY_DEVICE_TREE_FILE , fdt, fdt_size, addr);g_free (fdt);
hw/ppc/spapr_rtas.c +10 -30
@@ -283,6 +283,7 @@ int spapr_rtas_device_tree_setup(void *fdt, hwaddr rtas_addr, {int ret;int i; +Error *err =NULL ; ret =fdt_add_mem_rsv (fdt, rtas_addr, rtas_size);if (ret <0 ) {
@@ -291,29 +292,9 @@ int spapr_rtas_device_tree_setup(void *fdt, hwaddr rtas_addr,return ret; } - ret =qemu_fdt_setprop_cell (fdt,"/rtas" ,"linux,rtas-base" , - rtas_addr); -if (ret <0 ) { -fprintf (stderr,"Couldn't add linux,rtas-base property: %s\n" , -fdt_strerror (ret)); -return ret; - } - - ret =qemu_fdt_setprop_cell (fdt,"/rtas" ,"linux,rtas-entry" , - rtas_addr); -if (ret <0 ) { -fprintf (stderr,"Couldn't add linux,rtas-entry property: %s\n" , -fdt_strerror (ret)); -return ret; - } - - ret =qemu_fdt_setprop_cell (fdt,"/rtas" ,"rtas-size" , - rtas_size); -if (ret <0 ) { -fprintf (stderr,"Couldn't add rtas-size property: %s\n" , -fdt_strerror (ret)); -return ret; - } +qemu_fdt_setprop_cell (fdt,"/rtas" ,"linux,rtas-base" , rtas_addr, &err); +qemu_fdt_setprop_cell (fdt,"/rtas" ,"linux,rtas-entry" , rtas_addr, &err); +qemu_fdt_setprop_cell (fdt,"/rtas" ,"rtas-size" , rtas_size, &err);for (i =0 ; i <TOKEN_MAX ; i++) {struct rtas_call *call = &rtas_table[i];
@@ -322,14 +303,13 @@ int spapr_rtas_device_tree_setup(void *fdt, hwaddr rtas_addr,continue ; } - ret =qemu_fdt_setprop_cell (fdt,"/rtas" , call->name, - i +TOKEN_BASE ); -if (ret <0 ) { -fprintf (stderr,"Couldn't add rtas token for %s: %s\n" , - call->name,fdt_strerror (ret)); -return ret; - } +qemu_fdt_setprop_cell (fdt,"/rtas" , call->name, i +TOKEN_BASE , &err); + } +if (err) { +fprintf (stderr,"%s\n" ,error_get_pretty (err)); +error_free (err); +return -1 ; }return 0 ; }
hw/ppc/virtex_ml507.c +1 -4
@@ -142,7 +142,6 @@ static int xilinx_load_device_tree(hwaddr addr,char *path;int fdt_size;void *fdt =NULL ; -int r;const char *dtb_filename; dtb_filename =qemu_opt_get (qemu_get_machine_opts (),"dtb" );
@@ -166,9 +165,7 @@ static int xilinx_load_device_tree(hwaddr addr,if (!fdt) {return 0 ; } - r =qemu_fdt_setprop_string (fdt,"/chosen" ,"bootargs" , kernel_cmdline); -if (r <0 ) -fprintf (stderr,"couldn't set /chosen/bootargs\n" ); +qemu_fdt_setprop_string (fdt,"/chosen" ,"bootargs" , kernel_cmdline,NULL );cpu_physical_memory_write (addr, fdt, fdt_size);return fdt_size; }
include/sysemu/device_tree.h +160 -33
245 lines not on this page · raw message
Signature · 1 line
1.8.3.rc1.44.gb387c77.dirty
Re: [Qemu-devel] [PATCH v2 3/3] device_tree: qemu_fdt_setprop: Fixup error reporting
Quoted 38 lines · On 11.11.2013, at 09:16, [email protected] wrote:
From: Peter Crosthwaite <[email protected]>
There are a mix of usages of the qemu_fdt_* API calls, some which wish to assert and abort QEMU on failure and some of which wish to do their own error handling. The latter in more correct, but the former is in the majority and more pragmatic. However the asserting clients are usually doing large numbers fdt ops and only want to assert if any one of them breaks. So the cleanest compromising solution is:
1. Require an Error ** to be passes to all fdt ops.
2. And perform no action if its already non-null (error condition).
3. If no Error ** is given report errors to stderrStep one allows clients to do their own error handling if they wish too, which is the most flexible:
Error *err = NULL;
fdt_foo( ... , &err);if (err) { /* handle error my special way */ }Step two allows you to do a large number of fdt ops then check them all only the once at the end:
Error *err = NULL;
fdt_foo( ... , &err);
fdt_bar( ... , &err);
fdt_baz( ... , &err);if (err) { /* First encountered error will be in err */ }Step 3, handles the common case where the error is not an issue, but just needs to make noise at the user (via stderr). This seems common for bootloader code that sets chosen and initrd props etc (rather than machine description).
Quoted 4 lines
All error reporting is stylistically udpated to use Error ** instead of integer return codes and no more exit(1) on failures.
Signed-off-by Peter Crosthwaite <[email protected]>
Thanks a lot. I've applied the first two patches to ppc-next with some adjustments to also cover hw/arm/virt.c. But this patch is too much work to rebase to current master :).
Please repost a version that also covers virt.c. I'd also like to see an Ack from Peter at least.
Alex
Re: [Qemu-devel] [PATCH v2 3/3] device_tree: qemu_fdt_setprop: Fixup error reporting
Quoted 41 lines · Alexander Graf
Quoted 38 lines · On 11.11.2013, at 09:16, [email protected] wrote:
From: Peter Crosthwaite <[email protected]>
There are a mix of usages of the qemu_fdt_* API calls, some which wish to assert and abort QEMU on failure and some of which wish to do their own error handling. The latter in more correct, but the former is in the majority and more pragmatic. However the asserting clients are usually doing large numbers fdt ops and only want to assert if any one of them breaks. So the cleanest compromising solution is:
1. Require an Error ** to be passes to all fdt ops.
2. And perform no action if its already non-null (error condition).
3. If no Error ** is given report errors to stderrStep one allows clients to do their own error handling if they wish too, which is the most flexible:
Error *err = NULL;
fdt_foo( ... , &err);if (err) { /* handle error my special way */ }Step two allows you to do a large number of fdt ops then check them all only the once at the end:
Error *err = NULL;
fdt_foo( ... , &err);
fdt_bar( ... , &err);
fdt_baz( ... , &err);if (err) { /* First encountered error will be in err */ }Step 3, handles the common case where the error is not an issue, but just needs to make noise at the user (via stderr). This seems common for bootloader code that sets chosen and initrd props etc (rather than machine description).
Quoted 6 lines
Quoted 4 lines
All error reporting is stylistically udpated to use Error ** instead of integer return codes and no more exit(1) on failures.
Signed-off-by Peter Crosthwaite <[email protected]>Thanks a lot. I've applied the first two patches to ppc-next with some adjustments to also cover
hw/arm/virt.c.
Thanks,
That make my respin of this one much easier.
Quoted 1 line
But this patch is too much work to rebase to current master :).
This patch is going to see a major change pattern once the &error_abort series goes through, as the assert_no_error scheme is now gone. This would have conflicted with the qmp queue that holds those patches (I probably should have put a note on list to retract this patch).
Quoted 3 lines
Please repost a version that also covers
virt.c. I'd also like to see an Ack from Peter at least.
I'll wait for both yours and Luiz' queues to flush and spin it.
Regards,
Peter
Quoted 4 lines
Alex
Ping!
Quoted 81 lines · On Mon, Nov 11, 2013 at 6:14 PM, <[email protected]> wrote:
From: Peter Crosthwaite <[email protected]>
Fix the name stem of the devicetree API (P1 - s/qemu_devtree/qemu_fdt) and cleanup error report (P3). Trivial patch P2 fixing an arugment name along the way.
Tested using:
1: Alex's e500 test vector.
2: Xilinx Zynq (testsarm/boot.c).I have testing using Zynq with Mem > 4gb and a bogus dts (size cells = 1) to give that particular error path some exercise.
To give some exercise to the error paths, I hacked up my libfdt to throw errors randomly:
libfdt/fdt_rw.c +11
-0@@ -48,6 +48,8 @@* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + +#include <stdlib.h> #include "libfdt_env.h" #include <fdt.h> @@ -279,6 +281,15 @@ int fdt_setprop(void *fdt, int nodeoffset, const char *name,FDT_RW_CHECK_HEADER (fdt); +static int seeded =0 ; +if (!seeded) { +srand (time (NULL )); + seeded =1 ; + } +if (!(rand () &0x7 )) { +return -((rand () &0x3 ) +1 ); + } +Some sample outputs from e500 boot (Using the above tainted libfdt):
-----
qemu-system-ppc:qemu_fdt_setprop: Couldn't set /memory/reg:FDT_ERR_BADOFFSETAborted
-----
qemu-system-ppc:qemu_fdt_setprop_string: Couldn't set /soc@e0000000/device_type = soc:FDT_ERR_NOSPACEAborted
-----
qemu-system-ppc:qemu_fdt_setprop_cell: Couldn't set /soc@e0000000/#address-cells =0x000001:FDT_ERR_NOSPACEAborted
-----Peter Crosthwaite (3):
device_tree: s/qemu_devtree/qemu_fdt globally
device_tree:qemu_fdt_setprop: Renameval_arrayarg
device_tree:qemu_fdt_setprop: Fixup error reportingdevice_tree.c | 230 +++++++++++++++++++++++++++-------------- hw/arm/boot.c | 51 ++++----- hw/arm/vexpress.c | 23 +++-- hw/microblaze/boot.c | 17 ++- hw/ppc/e500.c | 241 ++++++++++++++++++++++--------------------- hw/ppc/e500.h | 3 +- hw/ppc/e500plat.c | 9 +- hw/ppc/mpc8544ds.c | 9 +- hw/ppc/ppc440_bamboo.c | 34 ++---- hw/ppc/spapr_rtas.c | 40 ++----- hw/ppc/virtex_ml507.c | 5 +- include/sysemu/device_tree.h | 219 ++++++++++++++++++++++++++++++--------- 12 files changed, 519 insertions(+), 362 deletions(-)--
1.8.3.rc1.44.gb387c77.dirty