[PATCH 1/6] Change options to flag approach.
From: Daniel Lezcano That has the benefit to simplify the code. Signed-off-by: Daniel Lezcano --- powerdebug.c | 65 +++- 1 file changed, 34 insertions(+), 31 deletions(-) diff --git a/powerdebug.c b/powerdebug.c index 6cf3a1b..555beea 100644 --- a/powerdebug.c +++ b/powerdebug.c @@ -31,6 +31,17 @@ extern void sigwinch_handler(int); +#define REGULATOR_OPTION 0x01 +#define SENSOR_OPTION 0x02 +#define CLOCK_OPTION 0x04 +#define GPIO_OPTION0x08 + +#define VERBOSE_OPTION 0x10 +#define DUMP_OPTION0x20 + +#define DEFAULT_OPTION (REGULATOR_OPTION | SENSOR_OPTION | \ + CLOCK_OPTION | GPIO_OPTION) + void usage(void) { printf("Usage: powerdebug [OPTIONS]\n"); @@ -86,12 +97,7 @@ static struct option long_options[] = { }; struct powerdebug_options { - bool verbose; - bool regulators; - bool sensors; - bool clocks; - bool gpios; - bool dump; + int flags; unsigned int ticktime; int selectedwindow; char *clkname; @@ -115,39 +121,38 @@ int getoptions(int argc, char *argv[], struct powerdebug_options *options) switch (c) { case 'r': - options->regulators = true; + options->flags |= REGULATOR_OPTION; options->selectedwindow = REGULATOR; break; case 's': - options->sensors = true; + options->flags |= SENSOR_OPTION; options->selectedwindow = SENSOR; break; case 'c': - options->clocks = true; + options->flags |= CLOCK_OPTION; options->selectedwindow = CLOCK; break; case 'g': - options->gpios = true; + options->flags |= GPIO_OPTION; options->selectedwindow = GPIO; break; + case 'd': + options->flags |= DUMP_OPTION; + break; + case 'v': + options->flags |= VERBOSE_OPTION; + break; case 'p': options->clkname = strdup(optarg); if (!options->clkname) { fprintf(stderr, "failed to allocate memory"); return -1; } - options->dump = true; /* Assume -dc in case of -p */ - options->clocks = true; + options->flags |= (DUMP_OPTION | CLOCK_OPTION); break; case 't': options->ticktime = atoi(optarg); break; - case 'd': - options->dump = true; - break; - case 'v': - options->verbose = true; - break; case 'V': version(); break; @@ -160,10 +165,8 @@ int getoptions(int argc, char *argv[], struct powerdebug_options *options) } /* No system specified to be dump, let's default to all */ - if (!options->regulators && !options->clocks && - !options->sensors && !options->gpios) - options->regulators = options->clocks = - options->sensors = options->gpios = true; + if (!(options->flags & DEFAULT_OPTION)) + options->flags |= DEFAULT_OPTION; if (options->selectedwindow == -1) options->selectedwindow = CLOCK; @@ -173,16 +176,16 @@ int getoptions(int argc, char *argv[], struct powerdebug_options *options) static int powerdebug_dump(struct powerdebug_options *options) { - if (options->regulators) + if (options->flags & REGULATOR_OPTION) regulator_dump(); - if (options->clocks) + if (options->flags & CLOCK_OPTION) clock_dump(options->clkname); - if (options->sensors) + if (options->flags & SENSOR_OPTION) sensor_dump(); - if (options->gpios) + if (options->flags & GPIO_OPTION) gpio_dump(); return 0; @@ -248,25 +251,25 @@ int main(int argc, char **argv) if (regulator_init()) { printf("failed to initialize regulator\n"); - options->regulators = false; + options->flags &= ~REGULATOR_OPTION; } if (clock_init()) { printf("failed to initialize clock details (check debugfs)\n"); - options->clocks = false; + options->flags &= ~CLOCK_OPTION; }
[PATCH 3/6] Prevent to init a subsystem if it is not selected.
Signed-off-by: Daniel Lezcano --- powerdebug.c | 13 ++--- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/powerdebug.c b/powerdebug.c index 555beea..bc8fc92 100644 --- a/powerdebug.c +++ b/powerdebug.c @@ -208,13 +208,12 @@ static struct powerdebug_options *powerdebug_init(void) { struct powerdebug_options *options; + signal(SIGWINCH, sigwinch_handler); + options = malloc(sizeof(*options)); if (!options) return NULL; - memset(options, 0, sizeof(*options)); - signal(SIGWINCH, sigwinch_handler); - return options; } @@ -249,22 +248,22 @@ int main(int argc, char **argv) return 1; } - if (regulator_init()) { + if ((options->flags & REGULATOR_OPTION) && regulator_init()) { printf("failed to initialize regulator\n"); options->flags &= ~REGULATOR_OPTION; } - if (clock_init()) { + if ((options->flags & CLOCK_OPTION) && clock_init()) { printf("failed to initialize clock details (check debugfs)\n"); options->flags &= ~CLOCK_OPTION; } - if (sensor_init()) { + if ((options->flags & SENSOR_OPTION) && sensor_init()) { printf("failed to initialize sensors\n"); options->flags &= SENSOR_OPTION; } - if (gpio_init()) { + if ((options->flags & GPIO_OPTION) && gpio_init()) { printf("failed to initialize gpios\n"); options->flags &= GPIO_OPTION; } -- 1.9.1 ___ linaro-dev mailing list linaro-dev@lists.linaro.org https://lists.linaro.org/mailman/listinfo/linaro-dev
[PATCH 2/6] Fix compilation warnings.
Signed-off-by: Daniel Lezcano --- display.c | 7 ++- gpio.c| 11 ++- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/display.c b/display.c index ee9..1114366 100644 --- a/display.c +++ b/display.c @@ -198,13 +198,13 @@ static int display_prev_panel(void) static int display_next_line(void) { - int maxx, maxy; + int maxy; int cursor = windata[current_win].cursor; int nrdata = windata[current_win].nrdata; int scrolling = windata[current_win].scrolling; struct rowdata *rowdata = windata[current_win].rowdata; - getmaxyx(stdscr, maxy, maxx); + maxy = getmaxy(stdscr); if (cursor >= nrdata) return cursor; @@ -320,9 +320,6 @@ struct find_data *display_find_init(void) const size_t len = 64; regex_t *reg; char *search4; - int maxx, maxy; - - getmaxyx(stdscr, maxy, maxx); reg = malloc(sizeof(*reg)); if (!reg) diff --git a/gpio.c b/gpio.c index 3c02b8e..7b5bbb2 100644 --- a/gpio.c +++ b/gpio.c @@ -325,12 +325,13 @@ void export_free_gpios(void) FILE *fgpio, *fgpio_export; int i, gpio_max = 0; char *line = NULL; - ssize_t read, len = 0; + ssize_t read; + size_t len = 0; fgpio = fopen("/sys/kernel/debug/gpio", "r"); if (!fgpio) { printf("failed to read debugfs gpio file\n"); - goto out; + return; } fgpio_export = fopen("/sys/class/gpio/export", "w"); @@ -342,7 +343,7 @@ void export_free_gpios(void) /* export the gpios */ while ((read = getline(&line, &len, fgpio)) != -1) { if (strstr(line, "GPIOs")) - sscanf(line, "%*[^-]-%d%*", &gpio_max); + sscanf(line, "%*[^-]-%d", &gpio_max); } printf("log: total gpios = %d\n", gpio_max); @@ -355,10 +356,10 @@ void export_free_gpios(void) } free(line); -out: + if (fgpio) fclose(fgpio); - +out: if (fgpio_export) fclose(fgpio_export); -- 1.9.1 ___ linaro-dev mailing list linaro-dev@lists.linaro.org https://lists.linaro.org/mailman/listinfo/linaro-dev
[PATCH 4/6] Fix license. Linaro switched years ago to GPL.
Signed-off-by: Daniel Lezcano --- LICENSE | 567 --- clocks.c | 28 +-- clocks.h | 28 +-- display.c| 28 +-- display.h| 28 +-- gpio.c | 28 +-- gpio.h | 28 +-- mainloop.c | 26 +-- mainloop.h | 26 +-- powerdebug.c | 28 +-- powerdebug.h | 28 +-- regulator.c | 32 ++-- regulator.h | 28 +-- sensor.c | 28 +-- sensor.h | 28 +-- tree.c | 26 +-- tree.h | 26 +-- utils.c | 28 +-- utils.h | 28 +-- 19 files changed, 649 insertions(+), 418 deletions(-) diff --git a/LICENSE b/LICENSE index be6f09f..6f50a71 100644 --- a/LICENSE +++ b/LICENSE @@ -1,221 +1,348 @@ -Copyright (C) 2010 Linaro Ltd. - -License: EPL-1.0 - Eclipse Public License - v 1.0 - - THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE - PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE - PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. - - 1. DEFINITIONS - - "Contribution" means: - - a) in the case of the initial Contributor, the initial code and documentation - distributed under this Agreement, and - b) in the case of each subsequent Contributor: - - i) changes to the Program, and - - ii) additions to the Program; - - where such changes and/or additions to the Program originate from and are - distributed by that particular Contributor. A Contribution 'originates' - from a Contributor if it was added to the Program by such Contributor itself - or anyone acting on such Contributor's behalf. Contributions do not include - additions to the Program which: (i) are separate modules of software - distributed in conjunction with the Program under their own license - agreement, and (ii) are not derivative works of the Program. - - "Contributor" means any person or entity that distributes the Program. - - "Licensed Patents " mean patent claims licensable by a Contributor which are - necessarily infringed by the use or sale of its Contribution alone or when - combined with the Program. - - "Program" means the Contributions distributed in accordance with this - Agreement. - - "Recipient" means anyone who receives the Program under this Agreement, - including all Contributors. - - 2. GRANT OF RIGHTS - - a) Subject to the terms of this Agreement, each Contributor hereby grants - Recipient a non-exclusive, worldwide, royalty-free copyright license to - reproduce, prepare derivative works of, publicly display, publicly perform, - distribute and sublicense the Contribution of such Contributor, if any, - and such derivative works, in source code and object code form. - - b) Subject to the terms of this Agreement, each Contributor hereby grants - Recipient a non-exclusive, worldwide, royalty-free patent license under - Licensed Patents to make, use, sell, offer to sell, import and otherwise - transfer the Contribution of such Contributor, if any, in source code and - object code form. This patent license shall apply to the combination of - the Contribution and the Program if, at the time the Contribution is added - by the Contributor, such addition of the Contribution causes such - combination to be covered by the Licensed Patents. The patent license shall - not apply to any other combinations which include the Contribution. No - hardware per se is licensed hereunder. - - c) Recipient understands that although each Contributor grants the licenses - to its Contributions set forth herein, no assurances are provided by any - Contributor that the Program does not infringe the patent or other - intellectual property rights of any other entity. Each Contributor disclaims - any liability to Recipient for claims brought by any other entity based on - infringement of intellectual property rights or otherwise. As a condition to - exercising the rights and licenses granted hereunder, each Recipient hereby - assumes sole responsibility to secure any other intellectual property rights - needed, if any. For example, if a third party patent license is required to - allow Recipient to distribute the Program, it is Recipient's responsibility - to acquire that license before distributing the Program. - - d) Each Contributor represents that to its knowledge it has sufficient - copyright rights in its Contribution, if any, to grant the copyright license - set forth in this Agreement. - - 3. REQUIREMENTS - - A Contributor may choose to distribute the Program in object code form under - its own license agreement, provided that: - - a) it complies with the terms and conditions of this Agreement; and - - b) its license agreement: - - i) effectively disclaims on behalf of all Contributors all warranties and - conditions, express and implied, including warranties or conditions of title - and non-infringement, and implied warranties or conditions of merchantability - and fitness for a particular purpose; - - ii) effectively excludes on behalf of all Contributors all li
[PATCH 5/6] Consolidate the headers into a single one.
Signed-off-by: Daniel Lezcano --- clocks.c | 1 - clocks.h | 23 --- display.c| 1 - gpio.h | 23 --- powerdebug.c | 11 --- powerdebug.h | 19 +++ regulator.c | 3 --- regulator.h | 23 --- sensor.c | 1 - sensor.h | 23 --- 10 files changed, 19 insertions(+), 109 deletions(-) delete mode 100644 clocks.h delete mode 100644 gpio.h delete mode 100644 regulator.h delete mode 100644 sensor.h diff --git a/clocks.c b/clocks.c index 4e34e0c..c751ec1 100644 --- a/clocks.c +++ b/clocks.c @@ -34,7 +34,6 @@ #include "powerdebug.h" #include "display.h" -#include "clocks.h" #include "tree.h" #include "utils.h" diff --git a/clocks.h b/clocks.h deleted file mode 100644 index b205a28..000 --- a/clocks.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Power debug tool (powerdebug) - * - * Copyright (C) 2016, Linaro Limited. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -extern int clock_init(void); -extern int clock_dump(char *clk); diff --git a/display.c b/display.c index 8aafc32..ed010b3 100644 --- a/display.c +++ b/display.c @@ -28,7 +28,6 @@ #include #include "powerdebug.h" #include "mainloop.h" -#include "regulator.h" #include "display.h" enum { PT_COLOR_DEFAULT = 1, diff --git a/gpio.h b/gpio.h deleted file mode 100644 index 9f51386..000 --- a/gpio.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Power debug tool (powerdebug) - * - * Copyright (C) 2016, Linaro Limited. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -extern int gpio_init(void); -extern int gpio_dump(void); diff --git a/powerdebug.c b/powerdebug.c index d4ce1f6..0f5c98a 100644 --- a/powerdebug.c +++ b/powerdebug.c @@ -27,11 +27,7 @@ #include #include #include -#include "regulator.h" #include "display.h" -#include "clocks.h" -#include "sensor.h" -#include "gpio.h" #include "mainloop.h" #include "powerdebug.h" @@ -102,13 +98,6 @@ static struct option long_options[] = { { 0, 0, 0, 0 } }; -struct powerdebug_options { - int flags; - unsigned int ticktime; - int selectedwindow; - char *clkname; -}; - int getoptions(int argc, char *argv[], struct powerdebug_options *options) { int c; diff --git a/powerdebug.h b/powerdebug.h index 3603018..33463a0 100644 --- a/powerdebug.h +++ b/powerdebug.h @@ -20,3 +20,22 @@ */ #define VERSION "0.7.3" + +struct powerdebug_options { + int flags; + unsigned int ticktime; + int selectedwindow; + char *clkname; +}; + +extern int clock_init(void); +extern int clock_dump(char *clk); + +extern int regulator_init(void); +extern int regulator_dump(void); + +extern int gpio_init(void); +extern int gpio_dump(void); + +extern int sensor_dump(void); +extern int sensor_init(void); diff --git a/regulator.c b/regulator.c index dc29769..b38ddab 100644 --- a/regulator.c +++ b/regulator.c @@ -20,9 +20,6 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ - -#include "regulator.h" - #define SYSFS_REGULATOR "/sys/class/regulator" #define VALUE_MAX 16 diff --git a/regulator.h b/regulator.h deleted file mode 100644 index b4b4f78..000 --- a/regulator.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Power debug tool (powerdebug) - * - * Copyright (C) 2016, Linaro Limited. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Sof
[PATCH 6/6] Pass options to init functions.
Signed-off-by: Daniel Lezcano --- clocks.c | 5 - gpio.c | 5 - powerdebug.c | 19 --- powerdebug.h | 20 regulator.c | 5 - sensor.c | 5 - 6 files changed, 36 insertions(+), 23 deletions(-) diff --git a/clocks.c b/clocks.c index c751ec1..b57de3d 100644 --- a/clocks.c +++ b/clocks.c @@ -447,10 +447,13 @@ static struct display_ops clock_ops = { /* * Initialize the clock framework */ -int clock_init(void) +int clock_init(struct powerdebug_options *options) { char clk_dir_path[MAX+1][PATH_MAX]; + if (!(options->flags & CLOCK_OPTION)) + return 0; + if (locate_debugfs(clk_dir_path[CCF]) || locate_debugfs(clk_dir_path[OCF])) return -1; diff --git a/gpio.c b/gpio.c index 8fd3e5c..36dedd1 100644 --- a/gpio.c +++ b/gpio.c @@ -375,10 +375,13 @@ out: /* * Initialize the gpio framework */ -int gpio_init(void) +int gpio_init(struct powerdebug_options *options) { int ret = 0; + if (!(options->flags & GPIO_OPTION)) + return 0; + ret = display_register(GPIO, &gpio_ops); if (ret) printf("error: gpio display register failed"); diff --git a/powerdebug.c b/powerdebug.c index 0f5c98a..b626b05 100644 --- a/powerdebug.c +++ b/powerdebug.c @@ -33,17 +33,6 @@ extern void sigwinch_handler(int); -#define REGULATOR_OPTION 0x01 -#define SENSOR_OPTION 0x02 -#define CLOCK_OPTION 0x04 -#define GPIO_OPTION0x08 - -#define VERBOSE_OPTION 0x10 -#define DUMP_OPTION0x20 - -#define DEFAULT_OPTION (REGULATOR_OPTION | SENSOR_OPTION | \ - CLOCK_OPTION | GPIO_OPTION) - void usage(void) { printf("Usage: powerdebug [OPTIONS]\n"); @@ -243,22 +232,22 @@ int main(int argc, char **argv) return 1; } - if ((options->flags & REGULATOR_OPTION) && regulator_init()) { + if (regulator_init(options)) { printf("failed to initialize regulator\n"); options->flags &= ~REGULATOR_OPTION; } - if ((options->flags & CLOCK_OPTION) && clock_init()) { + if (clock_init(options)) { printf("failed to initialize clock details (check debugfs)\n"); options->flags &= ~CLOCK_OPTION; } - if ((options->flags & SENSOR_OPTION) && sensor_init()) { + if (sensor_init(options)) { printf("failed to initialize sensors\n"); options->flags &= SENSOR_OPTION; } - if ((options->flags & GPIO_OPTION) && gpio_init()) { + if (gpio_init(options)) { printf("failed to initialize gpios\n"); options->flags &= GPIO_OPTION; } diff --git a/powerdebug.h b/powerdebug.h index 33463a0..2df0a27 100644 --- a/powerdebug.h +++ b/powerdebug.h @@ -21,6 +21,17 @@ #define VERSION "0.7.3" +#define REGULATOR_OPTION 0x01 +#define SENSOR_OPTION 0x02 +#define CLOCK_OPTION 0x04 +#define GPIO_OPTION0x08 + +#define VERBOSE_OPTION 0x10 +#define DUMP_OPTION0x20 + +#define DEFAULT_OPTION (REGULATOR_OPTION | SENSOR_OPTION | \ + CLOCK_OPTION | GPIO_OPTION) + struct powerdebug_options { int flags; unsigned int ticktime; @@ -28,14 +39,15 @@ struct powerdebug_options { char *clkname; }; -extern int clock_init(void); +extern int clock_init(struct powerdebug_options *options); extern int clock_dump(char *clk); -extern int regulator_init(void); +extern int regulator_init(struct powerdebug_options *options); extern int regulator_dump(void); -extern int gpio_init(void); +extern int gpio_init(struct powerdebug_options *options); extern int gpio_dump(void); +extern int sensor_init(struct powerdebug_options *options); extern int sensor_dump(void); -extern int sensor_init(void); + diff --git a/regulator.c b/regulator.c index b38ddab..549a744 100644 --- a/regulator.c +++ b/regulator.c @@ -265,10 +265,13 @@ static struct display_ops regulator_ops = { .display = regulator_display, }; -int regulator_init(void) +int regulator_init(struct powerdebug_options *options) { int ret = 0; + if (!(options->flags & REGULATOR_OPTION)) + return 0; + ret = display_register(REGULATOR, ®ulator_ops); if (ret) printf("error: regulator display register failed"); diff --git a/sensor.c b/sensor.c index 008b662..3b37bc6 100644 --- a/sensor.c +++ b/sensor.c @@ -295,10 +295,13 @@ static struct display_ops sensor_ops = { .display = sensor_display, }; -int sensor_init(void) +int sensor_init(struct powerdebug_options *options) { int ret = 0; + if (!(options->flags & SENSOR_OPTION)) + return 0; + ret = display_register(SENSOR, &sensor_ops); if (ret) printf("error: sensor display r
[ACTIVITY] week6+7 2016
ILP32 Bootstrap [BB-277 20%] Started, reviewed names via cross-distro list Updated DPKG and configure patches. testing Fixup packages for arm64 [50%] Tried to get openvrml building on arm64 with dh-autoreconf. Bugs and patches updated Robot OS 10% [BB-163 leftovers] Advised on some issues with plugin paths and log-type linkage Uploaded fixed ro-ros-comm to experimental Arm64 buildd maintenance [BB-86 20%] Tested pybit as cross-buildd D. Found breakage. filed bugs Wookey -- Principal hats: Linaro, Debian, Wookware, ARM http://wookware.org/ signature.asc Description: Digital signature ___ linaro-dev mailing list linaro-dev@lists.linaro.org https://lists.linaro.org/mailman/listinfo/linaro-dev