Submitter | Stefan Tauner |
---|---|
Date | 2013-07-25 15:33:06 |
Message ID | <1374766386-18473-1-git-send-email-stefan.tauner@student.tuwien.ac.at> |
Download | mbox | patch |
Permalink | /patch/3991/ |
State | New |
Headers | show |
Comments
Hmmm, that return statement seems to be getting rather unwieldy especially since we can probably expect a lot more variants. Maybe you can take this opportunity to re-factor the code a bit, make a table of known strings, and use a loop instead? You could also annotate the table entries to indicate whether the processor is known-working and print a warning if not. Alternately, perhaps it would be sufficient to use strstr() to find "GodsonV2", "Loongson-2", and "Loongson-3"? On Thu, Jul 25, 2013 at 8:33 AM, Stefan Tauner < stefan.tauner@student.tuwien.ac.at> wrote: > Also be less restrictive regarding Loongson 2, because these strings seem > to be rather volatile: > http://www.linux-mips.org/archives/linux-mips/2013-04/msg00179.html > > http://www.loongson.cn/dev/gitweb/?p=linux-loongson-all;a=history;f=arch/mips/kernel/cpu-probe.c > > Signed-off-by: Stefan Tauner <stefan.tauner@student.tuwien.ac.at> > --- > > Let's pretend I know what I am doing here... if I read the chinese > data sheets correctly then Loongson-3B has moved to use SPI primarily > for its firmware but there is always a chipset attached too... > In any case I would rather not touch it yet. 3A OTOH seems to be > more similar to Loongson-2 so this might actually work. > > This patch applies w/o conflicts to r1565 and later. > > processor_enable.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/processor_enable.c b/processor_enable.c > index 1361dd5..92c6b18 100644 > --- a/processor_enable.c > +++ b/processor_enable.c > @@ -58,8 +58,9 @@ static int is_loongson(void) > while (*ptr && isspace((unsigned char)*ptr)) > ptr++; > fclose(cpuinfo); > - return (strncmp(ptr, "ICT Loongson-2 V0.3", strlen("ICT > Loongson-2 V0.3")) == 0) || > - (strncmp(ptr, "Godson2 V0.3 FPU V0.1", > strlen("Godson2 V0.3 FPU V0.1")) == 0); > + return (strncmp(ptr, "ICT Loongson-2", strlen("ICT > Loongson-2")) == 0) || > + (strncmp(ptr, "Godson2 V0.3 FPU V0.1", > strlen("Godson2 V0.3 FPU V0.1")) == 0) || > + (strncmp(ptr, "ICT Loongson-3A", strlen("ICT > Loongson-3A")) == 0); > } > fclose(cpuinfo); > return 0; > -- > Kind regards, Stefan Tauner > > > _______________________________________________ > flashrom mailing list > flashrom@flashrom.org > http://www.flashrom.org/mailman/listinfo/flashrom >
On Fri, 26 Jul 2013 12:47:39 -0700 David Hendricks <dhendrix@google.com> wrote: > Hmmm, that return statement seems to be getting rather unwieldy especially > since we can probably expect a lot more variants. Maybe you can take this > opportunity to re-factor the code a bit, make a table of known strings, and > use a loop instead? You could also annotate the table entries to indicate > whether the processor is known-working and print a warning if not. > > Alternately, perhaps it would be sufficient to use strstr() to find > "GodsonV2", "Loongson-2", and "Loongson-3"? Yes it's awful... but I want to know if it works first and even then I think I don't care enough ATM. I had enough string handling in C this week already :)
Patch
diff --git a/processor_enable.c b/processor_enable.c index 1361dd5..92c6b18 100644 --- a/processor_enable.c +++ b/processor_enable.c @@ -58,8 +58,9 @@ static int is_loongson(void) while (*ptr && isspace((unsigned char)*ptr)) ptr++; fclose(cpuinfo); - return (strncmp(ptr, "ICT Loongson-2 V0.3", strlen("ICT Loongson-2 V0.3")) == 0) || - (strncmp(ptr, "Godson2 V0.3 FPU V0.1", strlen("Godson2 V0.3 FPU V0.1")) == 0); + return (strncmp(ptr, "ICT Loongson-2", strlen("ICT Loongson-2")) == 0) || + (strncmp(ptr, "Godson2 V0.3 FPU V0.1", strlen("Godson2 V0.3 FPU V0.1")) == 0) || + (strncmp(ptr, "ICT Loongson-3A", strlen("ICT Loongson-3A")) == 0); } fclose(cpuinfo); return 0;
Also be less restrictive regarding Loongson 2, because these strings seem to be rather volatile: http://www.linux-mips.org/archives/linux-mips/2013-04/msg00179.html http://www.loongson.cn/dev/gitweb/?p=linux-loongson-all;a=history;f=arch/mips/kernel/cpu-probe.c Signed-off-by: Stefan Tauner <stefan.tauner@student.tuwien.ac.at> --- Let's pretend I know what I am doing here... if I read the chinese data sheets correctly then Loongson-3B has moved to use SPI primarily for its firmware but there is always a chipset attached too... In any case I would rather not touch it yet. 3A OTOH seems to be more similar to Loongson-2 so this might actually work. This patch applies w/o conflicts to r1565 and later. processor_enable.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)