[flashrom] [PATCH] register_shutdown for execution on programmer shutdown

Carl-Daniel Hailfinger c-d.hailfinger.devel.2006 at gmx.net
Sun Feb 14 02:45:38 CET 2010


On 13.02.2010 17:22, Anders Juel Jensen wrote:
> If i read this right i am going to need a wakeup() function too.. otherwise i 
> will be left with a system with no keyboard, mouse, power button and 
> *automatic fan control*.. i damn nearly fried my CPU when I played with this 
> :-/
>
> Correct me if there is something about this i don't understand.. the below 
> little program that can call flashrom between shutdown and wakeup, and then 
> detection works.
>   

The idea is to move all this code into board_enable.c.

Suggested code for a pure flashrom solution (no wrapper program needed)
inside board_enable.c:

void restart_ec_on_anders_board(void *dontcare)
{
	outb_p (0xfb, 0x64);
	write_wait();
	outb_p (0xff, 0x64);
	write_wait();
}

static int board_enable_for_anders_board(const char *name)
{
	unsigned char ret = 0;

	//do stuff. mostly what is in your board enable.

	/* Now put the EC to sleep. You may want to factor this
	 * out to a separate function.
	 */
	OUTB(0xb4, 0x64);
	write_wait();
	OUTB(0xff, 0x64);
	write_wait();

	while (ret != 0xfa) {
		read_wait();
		ret = INB(0x60);
	}

	/* Make sure the EC will be woken up at the end.
	 * This code will be executed unless flashrom exits
	 * in between with some error (usually out of memory).
	 */
	register_shutdown(restart_ec_on_anders_board, NULL);

	return 0;
}

void write_wait()
{
	int timer = 0;

	while (INB(0x64) & 0x2) {
		if (++timer == 40000) {
			msg_perr("KBC port 0x64 does not accept commands - \n");
			msg_perr("We may in fact have been shafted..\n");
			exit (-1);
		}
	}
}

void read_wait()
{
	int timer = 0;

	while (!(INB(0x64) & 0x1)) {
		if (++timer == 40000) {
			msg_perr("KBC port 0x64 never became ready. Faulty Exit\n");
			msg_perr("Your machine is in an unknown state.. great..\n");
			exit (-1);
		}
	}
}


I took the liberty of adapting the coding style to flashrom standards.
Please make sure to pick appropriate function names (read_wait should
probably be called nameofec_read_wait) and make sure it actually compiles.

Please check that I didn't introduce any errors or logic inversions.

Regards,
Carl-Daniel

-- 
Developer quote of the year:
"We are juggling too many chainsaws and flaming arrows and tigers."





More information about the flashrom mailing list