From 8bb2021d77c8ee213b53d671687b7a1179335522 Mon Sep 17 00:00:00 2001 From: David Hendricks Date: Tue, 14 Jun 2011 01:35:36 +0000 Subject: Use shutdown callback mechanism to shutdown programmers This patch attempts to resolve some programmer shutdown ordering issues by having the programmer init functions register shutdown callbacks explicitly wherever it makes most sense. Before, assumptions were made that could lead to the internal programmer's state changing before the external programmer could be shut down properly. Now, each programmer cleans up after itself and (hopefully) performs each operation in the correct order. As a side-effect, this patch gives us a better usage model for reverse operations such as rpci_* and rmmio_*. In the long-run, this should make reversing the initialization process easier to understand, less tedious, and less error-prone. In short, this patch does the following: - Registers a shutdown callback during initialization for each programmer. - Kills the .shutdown function pointer from programmer_entry struct. Also, make most shutdown functions static. - Adds a few minor clean-ups and corrections (e.g. missing physunmap() calls). TODO: Remove forward declaration of serprog_shutdown() (added to simplify diff) Corresponding to flashrom svn r1338. Signed-off-by: David Hendricks Acked-by: Carl-Daniel Hailfinger --- dummyflasher.c | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) (limited to 'dummyflasher.c') diff --git a/dummyflasher.c b/dummyflasher.c index fdb4f2a..fca228c 100644 --- a/dummyflasher.c +++ b/dummyflasher.c @@ -73,6 +73,23 @@ static const struct spi_programmer spi_programmer_dummyflasher = { .read = default_spi_read, .write_256 = dummy_spi_write_256, }; + +static int dummy_shutdown(void *data) +{ + msg_pspew("%s\n", __func__); +#if EMULATE_CHIP + if (emu_chip != EMULATE_NONE) { + if (emu_persistent_image) { + msg_pdbg("Writing %s\n", emu_persistent_image); + write_buf_to_file(flashchip_contents, emu_chip_size, + emu_persistent_image); + } + free(flashchip_contents); + } +#endif + return 0; +} + int dummy_init(void) { char *bustext = NULL; @@ -126,7 +143,7 @@ int dummy_init(void) if (!tmp) { msg_pdbg("Not emulating any flash chip.\n"); /* Nothing else to do. */ - return 0; + goto dummy_init_out; } #if EMULATE_SPI_CHIP if (!strcmp(tmp, "M25P10.RES")) { @@ -180,13 +197,14 @@ int dummy_init(void) msg_perr("Out of memory!\n"); return 1; } + msg_pdbg("Filling fake flash chip with 0xff, size %i\n", emu_chip_size); memset(flashchip_contents, 0xff, emu_chip_size); emu_persistent_image = extract_programmer_param("image"); if (!emu_persistent_image) { /* Nothing else to do. */ - return 0; + goto dummy_init_out; } if (!stat(emu_persistent_image, &image_stat)) { msg_pdbg("Found persistent image %s, size %li ", @@ -201,22 +219,12 @@ int dummy_init(void) } } #endif - return 0; -} -int dummy_shutdown(void) -{ - msg_pspew("%s\n", __func__); -#if EMULATE_CHIP - if (emu_chip != EMULATE_NONE) { - if (emu_persistent_image) { - msg_pdbg("Writing %s\n", emu_persistent_image); - write_buf_to_file(flashchip_contents, emu_chip_size, - emu_persistent_image); - } +dummy_init_out: + if (register_shutdown(dummy_shutdown, NULL)) { free(flashchip_contents); + return 1; } -#endif return 0; } -- cgit v1.1