Hi Joursoir, I'm going to reply to your questions on Monday. Sorry for the delay, I'm currently not in reach of my Computer and want to look a few things up before answering.
-- Thomas On 1 April 2022 20:43:10 WEST, Joursoir <c...@joursoir.net> wrote: >Hello Thomas, > >I went ahead and started looking into shutdown functions. Almost of >them use global variables, but I already have ideas on how to rewrite >it. Now I start coding a prototype and want to implement struct >example_data. But I have run into a problem with its initialization: > >1) In theory, we can declare a static variable within each programmer's >file. It would be convenient, but this method has a big disadvantage. >We allocate private_data for every programmers but use only one. > >static struct example_data { > ... >} private_data; > >2) It's not possible to add a variable to struct programmer_entry >because the structure is read only (structures in programmer.h are >declared as const). > >3) Use a static global variable in flashrom.c. Lesser of two evils >principle as they say > >static const struct programmer_entry *programmer = NULL; >static const char *programmer_param = NULL; >static void *programmer_data = NULL; > >The next issue is the initialization of programmer_data: > >a) Do it inside programmer->init(). The problem here is the duplication >of programmer_data init code in each function. > >b) Do it outside programmer->init(). The problem here is that we can't >find out the size of example_data (it can be drkaised_data, >it85spi_data and etc) > >programmer_data = calloc(1, sizeof(EXAMPLE_DATA)); >if (!data) { > ... >} >... >ret = programmer->init(&programmer_data); > >Perhaps there is some simpler solution, but I don't notice it. > _______________________________________________ flashrom mailing list -- flashrom@flashrom.org To unsubscribe send an email to flashrom-le...@flashrom.org