[coreboot] MCP55 Mac Address copying/change

Jonathan A. Kollasch jakllsch at kollasch.net
Fri Nov 5 17:48:43 CET 2010


On Thu, Nov 04, 2010 at 06:55:28PM +0100, Harald Gutmann wrote:
> Hello!
> 
> Yesterday I tried coreboot again, and it worked fine so far.
> 
> But I faced a nasty problem, like the last time I tried it with the MAC 
> address on MCP55. This is nothing serious as you can change it by editing the 
> romcache.inc from the southbridge, but it's nasty.
> 
> I was thinking about fixing this in a decent way. I'd love to see a KConfig 
> value to enter in the configure process to get this done, or even to copy the 
> mac address of the board.

Look at the romstrap of the vendor-provided firmware update image for
a nvidia board.  You'll find it doesn't contain your board's address.

IMO this issue would be best solved in the vicinity of flashrom.

It's trivial to follow the romstrap pointers and copy over
the address.

Attached is a utility to do just that.

	Jonathan Kollasch
-------------- next part --------------
/*
 * Copyright (c) 2010 Jonathan A. Kollasch
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * transfer UUID/MAC address in nvidia romstrap
 */

#include <stdint.h>
#include <stdio.h>

#ifdef __NetBSD__
#include <sys/endian.h>
#else
#warning assuming LE host
#define le32toh(x) (x)
#endif

FILE *srcrom;
FILE *dstrom;
uint32_t srcbase;
uint32_t dstbase;
uint32_t srcrsp;
uint32_t dstrsp;

uint8_t uuid[16];

int
get_rom(FILE *f, uint32_t *v)
{
	uint32_t tmp;
	size_t ret;

	ret = fread(&tmp, sizeof(tmp), 1, f) != 1;

	if (ret == 0 && v != NULL)
		*v = tmp;

	return ret;
}

int
main(int argc, char *argv[])
{
	uint32_t srctmp;
	uint32_t dsttmp;

	if (argc < 3)
		return 1;

	srcrom = fopen(argv[1], "r");
	if (srcrom == NULL)
		return 1;

	dstrom = fopen(argv[2], "r+");
	if (dstrom == NULL)
		return 1;

	/* seek to the romstrap pointer, find offset of ROM image */
	fseek(srcrom, -0x20, SEEK_END);
	srcbase = 0x100000000ULL - (ftell(srcrom) + 0x20);
	//printf("%x\n", srcbase);

	fseek(dstrom, -0x20, SEEK_END);
	dstbase = 0x100000000ULL - (ftell(dstrom) + 0x20);
	//printf("%x\n", dstbase);

	/* read romstrap pointer */
	if (get_rom(srcrom, &srcrsp))
		return 1;
	srcrsp = le32toh(srcrsp);
	//printf("srcrsp %x\n", srcrsp);

	if (get_rom(dstrom, &dstrsp))
		return 1;
	dstrsp = le32toh(dstrsp);
	//printf("dstrsp %x\n", dstrsp);

	/* move to romstrap table */
	fseek(srcrom, srcrsp - srcbase, SEEK_SET);
	fseek(dstrom, dstrsp - dstbase, SEEK_SET);

	/* check for romstrap signature */
	if (get_rom(srcrom, &srctmp))
		return 1;
	srctmp = le32toh(srctmp);
	if (srctmp != 0x2b16d065)
		return 1;

	if (get_rom(dstrom, &dsttmp))
		return 1;
	dsttmp = le32toh(dsttmp);
	if (dsttmp != 0x2b16d065)
		return 1;

	/* move to next pointer */
	fseek(srcrom, srcrsp - srcbase + 0x0c, SEEK_SET);
	fseek(dstrom, dstrsp - dstbase + 0x0c, SEEK_SET);

	/* read pointer */
	if (get_rom(srcrom, &srctmp))
		return 1;
	srctmp = le32toh(srctmp);
	if (srctmp != (srcrsp + 0x10)) {
		//printf("source list not at usual location\n");
	}

	if (get_rom(dstrom, &dsttmp))
		return 1;
	dsttmp = le32toh(dsttmp);
	if (dsttmp != (dstrsp + 0x10)) {
		//printf("dest list not at usual location\n");
	}
	// /* follow pointer */
	//fseek(srcrom, srctmp - srcbase, SEEK_SET);
	//fseek(dstrom, dsttmp - dstbase, SEEK_SET);

	//printf("sll %x\n", srctmp);
	//printf("dll %x\n", dsttmp);

	/* move to beginning of MAC/UUID */
	fseek(srcrom, srctmp - srcbase + 0x20, SEEK_SET);
	fseek(dstrom, dsttmp - dstbase + 0x20, SEEK_SET);

	/* copy */
	if (fread(uuid, sizeof(uuid), 1, srcrom) != 1)
		return 1;
	if (fwrite(uuid, sizeof(uuid), 1, dstrom) != 1)
		return 1;

	fclose(srcrom);
	fclose(dstrom);

	printf("copied address %02x:%02x:%02x:%02x:%02x:%02x\n", uuid[5], uuid[4], uuid[3], uuid[2], uuid[1], uuid[0]);

	return 0;
}


More information about the coreboot mailing list