Patchwork Patch for getpir when using input image file

login
register
about
Submitter marc bertens
Date 2010-12-28 10:47:16
Message ID <1293533236.3099.103.camel@mbertens-desktop>
Download mbox | patch
Permalink /patch/2459/
State Rejected
Headers show

Comments

marc bertens - 2010-12-28 10:47:16
Sorry, i attached the patch file.

Reading the coreboot_ram file in the build direcory gives you the check
if the checksum of the table you build has a correct checksum. i added
this functionally about 6 months ago, but found a problem when searching
a file image for the $PIR prefix.

Marc



-----Original Message-----
From: Stefan Reinauer <stepan@openbios.org>
To: coreboot@coreboot.org
Subject: Re: [coreboot] Patch for getpir when using input image file
Date: Tue, 28 Dec 2010 10:38:21 +0100

On 12/27/10 7:45 PM, Marc Bertens wrote: 

> Signed-off: Marc Bertens <mbertens@xs4all.nl>
> 
> There was a problem when using the getpir utility with the
> coreboot_ram file, basically removed the loop around the search
> function, in the coreboot_ram image the start $PIR is not on a 16 byte
> boundary. due to the search already was matching 6 bytes of the start
> of the table (including the version of the table), this was not
> necessary any more.  

There was no patch attached

The copy in the coreboot_ram image is not the one the tool should find,
usually it should even be compressed and thus not found at all. Instead
coreboot_ram will copy a PIR table to ram and that copy is the one the
tool is/should be looking for.

Stefan

Patch

Index: getpir.c
===================================================================
--- getpir.c	(revision 6218)
+++ getpir.c	(working copy)
@@ -34,7 +34,7 @@ 
  *	descriptions, it is special handy when building a PIRQ table
  *	for a board to check the checksum.
  */
-static struct irq_routing_table *probe_table(char* ptr)
+static struct irq_routing_table *probe_table(char* ptr, int datasize)
 {
 	/**
 	 * Signature to search for $PIR<2-byte-version>
@@ -44,60 +44,55 @@ 
 	char signature[] = "$PIR\x00\x01";
 	/** cast the pointer */
 	struct irq_routing_table *rt = (struct irq_routing_table *)ptr;
-	int size = 16;
 	int checksum_result;
-	do {
-		/** find the PIRQ table */
-		rt = (struct irq_routing_table *) memmem(ptr + size, 16, signature, 6);
-		if (rt != NULL) {
-			/** found the table */
-			int i, ts = (rt->size - 32) / 16;
-			struct irq_info *se_arr;
-			se_arr = (struct irq_info *) ((char *) rt + 32);
-			/** Dump the table information to the stdout */
-			printf("Found PCI IRQ routing table signature at %p.\n", (void *) ((char *) rt - ptr + 0xf0000));
-			printf("SIGNATURE            = %s\n", (char*)&rt->signature);
-			printf("VERSION              = %04x\n", rt->version);
-			printf("SIZE                 = %i\n", rt->size);
-			printf("MAX_DEVICES_ON_BUS   = 32 + 16 * %d\n", ts);
-			printf("INT_ROUTER_BUS       = 0x%02x\n", rt->rtr_bus);
-			printf("INT_ROUTER DEVICE    = (0x%02x << 3) | 0x%01x\n", rt->rtr_devfn >> 3, rt->rtr_devfn & 7);
-			printf("IRQ_DEVOTED_TO_PCI   = %#x\n", rt->exclusive_irqs);
-			printf("VENDOR               = %#x\n", rt->rtr_vendor);
-			printf("DEVICE               = %#x\n", rt->rtr_device);
-			printf("MINIPORT             = %#x\n", rt->miniport_data);
-			printf("CHECKSUM             = %#x\n", rt->checksum);
- 			printf("\tbus , dev        | fn,   {link, bitmap}, {link, bitmap}, {link, bitmap}, {link, bitmap}, slot, rfu\n");
-			for (i = 0; i < ts; i++) {
-				printf("\t0x%02x, (0x%02x << 3) | 0x%01x, {{0x%02x, 0x%04x}, {0x%02x, 0x%04x}, {0x%02x, 0x%04x}, {0x%02x, 0x%04x}}, 0x%x, 0x%x},\n",
-					(se_arr+i)->bus, 			(se_arr+i)->devfn >> 3,
-					(se_arr+i)->devfn & 7, 		(se_arr+i)->irq[0].link,
-					(se_arr+i)->irq[0].bitmap, 	(se_arr+i)->irq[1].link,
-					(se_arr+i)->irq[1].bitmap, 	(se_arr+i)->irq[2].link,
-					(se_arr+i)->irq[2].bitmap, 	(se_arr+i)->irq[3].link,
-					(se_arr+i)->irq[3].bitmap, 	(se_arr+i)->slot,
-					(se_arr+i)->rfu);
-			}
-			/** A table should not be over 0x400 bytes */
-			if (rt->size > 0x400) {
-				return NULL;
-			}
-			printf("Validating...\n");
-			/** Calculate the checksum value */
-			checksum_result	= calc_checksum(rt);
-			/** Show the calculatedchecksum value */
-			printf("CHECKSUM             = %#x\n", 0x100-((checksum_result - rt->checksum) & 0xFF));
-			/** and the result of the calculation */
-			if (!checksum_result) {
-				printf("checksum is ok.\n");
-				break;
-			} else {
-				printf("checksum is wrong.\n");
-			}
+	/** find the PIRQ table */
+	printf( "datasize %i\n", datasize );
+	rt = (struct irq_routing_table *) memmem( ptr, datasize, signature, 6 );
+	if ( rt != NULL ) {
+		/** found the table */
+		int i, ts = (rt->size - 32) / 16;
+		struct irq_info *se_arr;
+		se_arr = (struct irq_info *) ((char *) rt + 32);
+		/** Dump the table information to the stdout */
+		printf("Found PCI IRQ routing table signature at %p.\n", (void *) ((char *) rt - ptr + 0xf0000));
+		printf("SIGNATURE            = %s\n", (char*)&rt->signature);
+		printf("VERSION              = %04x\n", rt->version);
+		printf("SIZE                 = %i\n", rt->size);
+		printf("MAX_DEVICES_ON_BUS   = 32 + 16 * %d\n", ts);
+		printf("INT_ROUTER_BUS       = 0x%02x\n", rt->rtr_bus);
+		printf("INT_ROUTER DEVICE    = (0x%02x << 3) | 0x%01x\n", rt->rtr_devfn >> 3, rt->rtr_devfn & 7);
+		printf("IRQ_DEVOTED_TO_PCI   = %#x\n", rt->exclusive_irqs);
+		printf("VENDOR               = %#x\n", rt->rtr_vendor);
+		printf("DEVICE               = %#x\n", rt->rtr_device);
+		printf("MINIPORT             = %#x\n", rt->miniport_data);
+		printf("CHECKSUM             = %#x\n", rt->checksum);
+		printf("\tbus , dev        | fn,   {link, bitmap}, {link, bitmap}, {link, bitmap}, {link, bitmap}, slot, rfu\n");
+		for (i = 0; i < ts; i++) {
+			printf("\t0x%02x, (0x%02x << 3) | 0x%01x, {{0x%02x, 0x%04x}, {0x%02x, 0x%04x}, {0x%02x, 0x%04x}, {0x%02x, 0x%04x}}, 0x%x, 0x%x},\n",
+				(se_arr+i)->bus, 			(se_arr+i)->devfn >> 3,
+				(se_arr+i)->devfn & 7, 		(se_arr+i)->irq[0].link,
+				(se_arr+i)->irq[0].bitmap, 	(se_arr+i)->irq[1].link,
+				(se_arr+i)->irq[1].bitmap, 	(se_arr+i)->irq[2].link,
+				(se_arr+i)->irq[2].bitmap, 	(se_arr+i)->irq[3].link,
+				(se_arr+i)->irq[3].bitmap, 	(se_arr+i)->slot,
+				(se_arr+i)->rfu);
 		}
-		size += 16;
-	} while (size < 0xFFFF);
-	if (size >= 0xFFFF) {
+		/** A table should not be over 0x400 bytes */
+		if (rt->size > 0x400) {
+			return NULL;
+		}
+		printf("Validating...\n");
+		/** Calculate the checksum value */
+		checksum_result	= calc_checksum(rt);
+		/** Show the calculatedchecksum value */
+		printf("CHECKSUM             = %#x\n", 0x100-((checksum_result - rt->checksum) & 0xFF));
+		/** and the result of the calculation */
+		if (!checksum_result) {
+			printf("checksum is ok.\n");
+		} else {
+			printf("checksum is wrong.\n");
+		}
+	} else {
 		/** When the functions comes here there is no PIRQ table found. */
 		printf("No PCI IRQ routing table signature found.\n");
 		return NULL;
@@ -112,22 +107,25 @@ 
 	int fd_mem = -1;
 	struct irq_routing_table* rt = NULL;
 	void* bios_image = NULL;
-	if ( argc > 1 )
-	{
+	int file_size = 0;
+	if ( argc > 1 )	{
 		/** there a paramater passed to the program, assume that it is a menory file */
 		printf("Opening memory image file '%s'\n", argv[1]);
 		/** Open the file */
 		fd_mem = open(argv[1], O_RDONLY);
 		if (fd_mem > 0) {
 			/** get tyhe size of the file */
-			int file_size = lseek(fd_mem, 0, SEEK_END);
+			file_size = lseek(fd_mem, 0, SEEK_END);
 			printf("Memory image '%i'\n", file_size);
 			/** get a memory block for it. */
 			bios_image = malloc(file_size);
 			if (bios_image) {
 				/** Fill the created buffer */
 				lseek(fd_mem, 0, SEEK_SET);
-				read(fd_mem, bios_image, file_size);
+				if ( read(fd_mem, bios_image, file_size) !=  file_size ){
+					perror("Failed to read all data of imagefile\n");
+					return (-4);;
+				}
 				/** set the pointer for the probe function */
 				ptr = (char*)bios_image;
 			} else {
@@ -141,6 +139,7 @@ 
 			return (-2);
 		}
 	} else {
+		file_size = 0x10000;
 		/** No paramaters means that the program will access the system memory */
 		printf("Accessing memory\n");
 		if (getuid()) {
@@ -155,17 +154,18 @@ 
 			exit(1);
 		}
 		printf("Probing PIRQ table in memory.\n");
-		ptr = mmap(0, 0x10000, PROT_READ, MAP_SHARED, fd_mem, (off_t)0xf0000);
+		ptr = mmap( 0, file_size, PROT_READ, MAP_SHARED, fd_mem, (off_t)0xf0000 );
 		if (ptr == MAP_FAILED) {
 			/** could not map the system memory, exit with a message */
 			perror("Mapping system memory failed: ");
 			close(fd_mem);
 			return (1);
 		}
+		
 	}
-	if (ptr) {
+	if ( ptr && file_size ) {
 		/** now do the actual probe function */
-		rt = probe_table(ptr);
+		rt = probe_table( ptr, file_size );
 		if (rt != NULL && bios_image == NULL) {
 			/** when probing system memory we write the 'irq_tables.c' code file */
 			printf("Creating irq_tables.c ...\n");