Skip to contentSkip to conversation

dtc: Use libfdt/fdt.h instead of flat_dt.h

PATCH Applied David Gibson 2 participants 3 messages Sep 26, 2007 – Sep 27, 2007

lore
Share & tools
lore
#0 lore raw

In the dtc tree, both flat_dt.h and libfdt/fdt.h have structures and constants relating to the flattened device tree format derived from asm-powerpc/prom.h in the kernel. The former is used in dtc, the latter in libfdt.

libfdt/fdt.h is the more recent, revised version, so use that throughout, removing flat_dt.h.

flat_dt.h deleted +0 -51
Index: dtc/flat_dt.h
===================================================================
@@ -1,51 +0,0 @@
-#ifndef _FLAT_DT_H_
-#define _FLAT_DT_H_
-
-
-#define OF_DEFAULT_VERSION	17
-
-#define OF_DT_HEADER            0xd00dfeed      /* 4: version, 4: total size */
-
-#define OF_DT_BEGIN_NODE	0x1             /* Start node: full name */
-#define OF_DT_END_NODE		0x2             /* End node */
-#define OF_DT_PROP		0x3             /* Property: name off,
-						   size, content */
-#define OF_DT_NOP		0x4		/* nop */
-#define OF_DT_END               0x9
-
-struct boot_param_header {
-	uint32_t magic;                  /* magic word OF_DT_HEADER */
-	uint32_t totalsize;              /* total size of DT block */
-	uint32_t off_dt_struct;          /* offset to structure */
-	uint32_t off_dt_strings;         /* offset to strings */
-	uint32_t off_mem_rsvmap;         /* offset to memory reserve map */
-	uint32_t version;                /* format version */
-	uint32_t last_comp_version;      /* last compatible version */
-
-        /* version 2 fields below */
-	uint32_t boot_cpuid_phys;        /* Which physical CPU id we're
-					    booting on */
-	/* version 3 fields below */
-        uint32_t size_dt_strings;        /* size of the strings block */
-
-	/* version 17 fields below */
-	uint32_t size_dt_struct;         /* size of the DT structure block */
-};
-
-#define BPH_V1_SIZE	(7*sizeof(uint32_t))
-#define BPH_V2_SIZE	(BPH_V1_SIZE + sizeof(uint32_t))
-#define BPH_V3_SIZE	(BPH_V2_SIZE + sizeof(uint32_t))
-#define BPH_V17_SIZE	(BPH_V3_SIZE + sizeof(uint32_t))
-
-struct reserve_entry {
-	uint64_t address;
-	uint64_t size;
-};
-
-struct flat_dt_property {
-	uint32_t len;
-	uint32_t nameoff;
-	char data[0];
-};
-
-#endif /* _FLAT_DT_H_ */
dtc.h +4 -3
Index: dtc/dtc.h
===================================================================
@@ -34,8 +34,9 @@
 #include <endian.h>
 #include <byteswap.h>
 
-#include "flat_dt.h"
+#include <fdt.h>
 
+#define DEFAULT_FDT_VERSION	17
 /*
  * Command line options
  */
@@ -128,7 +129,7 @@ struct data data_copy_file(FILE *f, size
 struct data data_append_data(struct data d, void *p, int len);
 struct data data_merge(struct data d1, struct data d2);
 struct data data_append_cell(struct data d, cell_t word);
-struct data data_append_re(struct data d, struct reserve_entry *re);
+struct data data_append_re(struct data d, struct fdt_reserve_entry *re);
 struct data data_append_addr(struct data d, u64 addr);
 struct data data_append_byte(struct data d, uint8_t byte);
 struct data data_append_zeroes(struct data d, int len);
@@ -192,7 +193,7 @@ int check_device_tree(struct node *dt, i
 /* Boot info (tree plus memreserve information */
 
 struct reserve_info {
-	struct reserve_entry re;
+	struct fdt_reserve_entry re;
 
 	struct reserve_info *next;
 
dtc.c +2 -2
Index: dtc/dtc.c
===================================================================
@@ -92,7 +92,7 @@ static void  __attribute__ ((noreturn)) 
 	fprintf(stderr, "\t\t\tdtb - device tree blob\n");
 	fprintf(stderr, "\t\t\tasm - assembler source\n");
 	fprintf(stderr, "\t-V <output version>\n");
-	fprintf(stderr, "\t\tBlob version to produce, defaults to %d (relevant for dtb\n\t\tand asm output only)\n", OF_DEFAULT_VERSION);
+	fprintf(stderr, "\t\tBlob version to produce, defaults to %d (relevant for dtb\n\t\tand asm output only)\n", DEFAULT_FDT_VERSION);
 	fprintf(stderr, "\t-R <number>\n");
 	fprintf(stderr, "\t\tMake space for <number> reserve map entries (relevant for \n\t\tdtb and asm output only)\n");
 	fprintf(stderr, "\t-S <bytes>\n");
@@ -117,7 +117,7 @@ int main(int argc, char *argv[])
 	int opt;
 	FILE *inf = NULL;
 	FILE *outf = NULL;
-	int outversion = OF_DEFAULT_VERSION;
+	int outversion = DEFAULT_FDT_VERSION;
 	int boot_cpuid_phys = 0xfeedbeef;
 
 	quiet      = 0;
ftdump.c +10 -10
Index: dtc/ftdump.c
===================================================================
@@ -9,7 +9,7 @@
 #include <netinet/in.h>
 #include <byteswap.h>
 
-#include "flat_dt.h"
+#include <fdt.h>
 
 #define cpu_to_be16(x)	htons(x)
 #define be16_to_cpu(x)	ntohs(x)
@@ -80,10 +80,10 @@ static void print_data(const void *data,
 
 static void dump_blob(void *blob)
 {
-	struct boot_param_header *bph = blob;
-	struct reserve_entry *p_rsvmap =
-		(struct reserve_entry *)(blob
-					 + be32_to_cpu(bph->off_mem_rsvmap));
+	struct fdt_header *bph = blob;
+	struct fdt_reserve_entry *p_rsvmap =
+		(struct fdt_reserve_entry *)(blob
+					     + be32_to_cpu(bph->off_mem_rsvmap));
 	char *p_struct = blob + be32_to_cpu(bph->off_dt_struct);
 	char *p_strings = blob + be32_to_cpu(bph->off_dt_strings);
 	uint32_t version = be32_to_cpu(bph->version);
@@ -109,11 +109,11 @@ static void dump_blob(void *blob)
 	}
 
 	p = p_struct;
-	while ((tag = be32_to_cpu(GET_CELL(p))) != OF_DT_END) {
+	while ((tag = be32_to_cpu(GET_CELL(p))) != FDT_END) {
 
 		/* printf("tag: 0x%08x (%d)\n", tag, p - p_struct); */
 
-		if (tag == OF_DT_BEGIN_NODE) {
+		if (tag == FDT_BEGIN_NODE) {
 			s = p;
 			p = PALIGN(p + strlen(s) + 1, 4);
 
@@ -126,19 +126,19 @@ static void dump_blob(void *blob)
 			continue;
 		}
 
-		if (tag == OF_DT_END_NODE) {
+		if (tag == FDT_END_NODE) {
 			depth--;
 
 			printf("%*s};\n", depth * shift, "");
 			continue;
 		}
 
-		if (tag == OF_DT_NOP) {
+		if (tag == FDT_NOP) {
 			printf("%*s// [NOP]\n", depth * shift, "");
 			continue;
 		}
 
-		if (tag != OF_DT_PROP) {
+		if (tag != FDT_PROP) {
 			fprintf(stderr, "%*s ** Unknown tag 0x%08x\n", depth * shift, "", tag);
 			break;
 		}
flattree.c +71 -72

364 lines not on this page · raw message

data.c +2 -2
Index: dtc/data.c
===================================================================
@@ -246,9 +246,9 @@ struct data data_append_cell(struct data
 	return data_append_data(d, &beword, sizeof(beword));
 }
 
-struct data data_append_re(struct data d, struct reserve_entry *re)
+struct data data_append_re(struct data d, struct fdt_reserve_entry *re)
 {
-	struct reserve_entry bere;
+	struct fdt_reserve_entry bere;
 
 	bere.address = cpu_to_be64(re->address);
 	bere.size = cpu_to_be64(re->size);
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
Applied
#1 lore raw

So, like, the other day David Gibson mumbled:

Quoted 9 lines

In the dtc tree, both flat_dt.h and libfdt/fdt.h have structures and constants relating to the flattened device tree format derived from asm-powerpc/prom.h in the kernel. The former is used in dtc, the latter in libfdt.

libfdt/fdt.h is the more recent, revised version, so use that throughout, removing flat_dt.h.

Applied.

As instructed, I also ignored this patch:
dtc: Use a custom name for lexer output

Thanks,
jdl

#2 lore raw
Quoted 9 lines · Jon Loeliger

So, like, the other day David Gibson mumbled:

Quoted 8 lines

In the dtc tree, both flat_dt.h and libfdt/fdt.h have structures and constants relating to the flattened device tree format derived from asm-powerpc/prom.h in the kernel. The former is used in dtc, the latter in libfdt.

libfdt/fdt.h is the more recent, revised version, so use that throughout, removing flat_dt.h.

Quoted 6 lines
Quoted 1 line

Applied.

As instructed, I also ignored this patch:
dtc: Use a custom name for lexer output

Ta.

In not too long, I expect to have a series of patches getting libfdt ready for use in the kernel. A new patch with various makefile cleanups including the lexer name patch will be part of that.

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson