From 54763e2c170bfb8dcd09f168f7c2cd866d380399 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Sat, 6 Oct 2012 23:01:26 +0200 Subject: driver: print error message when probe fails Signed-off-by: Sascha Hauer --- drivers/base/driver.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/base/driver.c b/drivers/base/driver.c index 6c8fd0576c..7bb3ab446e 100644 --- a/drivers/base/driver.c +++ b/drivers/base/driver.c @@ -77,6 +77,8 @@ int get_free_deviceid(const char *name_template) static int match(struct driver_d *drv, struct device_d *dev) { + int ret; + if (dev->driver) return -1; @@ -84,8 +86,11 @@ static int match(struct driver_d *drv, struct device_d *dev) if (dev->bus->match(dev, drv)) goto err_out; - if (dev->bus->probe(dev)) + ret = dev->bus->probe(dev); + if (ret) { + dev_err(dev, "probe failed: %s\n", strerror(-ret)); goto err_out; + } list_add(&dev->active, &active); -- cgit v1.2.3 From 0b494649fa46d00db9ffef75431f4ea3ed433bdb Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Sat, 6 Oct 2012 19:49:35 +0200 Subject: resource: statically initialize iomem resource This gets us rid of an initcall and also has the advantage that request_iomem_region can be called at any time now. Signed-off-by: Sascha Hauer --- common/resource.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/common/resource.c b/common/resource.c index da631d3997..ea6abe88e3 100644 --- a/common/resource.c +++ b/common/resource.c @@ -101,6 +101,8 @@ int release_region(struct resource *res) struct resource iomem_resource = { .start = 0, .end = 0xffffffff, + .name = "iomem", + .children = LIST_HEAD_INIT(iomem_resource.children), }; /* @@ -111,11 +113,3 @@ struct resource *request_iomem_region(const char *name, { return request_region(&iomem_resource, name, start, end); } - -static int iomem_init(void) -{ - init_resource(&iomem_resource, "iomem"); - - return 0; -} -postcore_initcall(iomem_init); -- cgit v1.2.3 From f562646dc801435c6cd0d693046af615f0d3577b Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Sun, 7 Oct 2012 13:34:46 +0200 Subject: startup: Print error message when initcall fails There was a time when we used to panic when initcalls failed. Then it was changed to totally ignore the return value. Instead, print an error message now so that the user can get a clue when something bad happened. So initcalls are now recommended to actually return negative error codes when something fails. Signed-off-by: Sascha Hauer --- common/startup.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/common/startup.c b/common/startup.c index b53bbef840..775f97ca87 100644 --- a/common/startup.c +++ b/common/startup.c @@ -100,7 +100,9 @@ void start_barebox (void) initcall < __barebox_initcalls_end; initcall++) { debug("initcall-> %pS\n", *initcall); result = (*initcall)(); - debug("initcall<- %pS (%d)\n", *initcall, result); + if (result) + pr_err("initcall %pS failed: %s\n", *initcall, + strerror(-result)); } debug("initcalls done\n"); -- cgit v1.2.3 From 1c0b9f395456465aeb09ec7ede95b58ce4d53e9e Mon Sep 17 00:00:00 2001 From: Jan Luebbe Date: Wed, 10 Oct 2012 12:17:08 +0200 Subject: parameter: remove unused function global_add_parameter Signed-off-by: Jan Luebbe Signed-off-by: Sascha Hauer --- include/param.h | 7 ------- 1 file changed, 7 deletions(-) diff --git a/include/param.h b/include/param.h index a855102d15..e0c415d4f8 100644 --- a/include/param.h +++ b/include/param.h @@ -38,8 +38,6 @@ int dev_param_set_generic(struct device_d *dev, struct param_d *p, /* Convenience functions to handle a parameter as an ip address */ int dev_set_param_ip(struct device_d *dev, char *name, IPaddr_t ip); IPaddr_t dev_get_param_ip(struct device_d *dev, char *name); - -int global_add_parameter(struct param_d *param); #else static inline const char *dev_get_param(struct device_d *dev, const char *name) { @@ -86,11 +84,6 @@ static inline IPaddr_t dev_get_param_ip(struct device_d *dev, char *name) { return 0; } - -static inline int global_add_parameter(struct param_d *param) -{ - return 0; -} #endif #endif /* PARAM_H */ -- cgit v1.2.3 From 247022ec920dcd9d5a9750eee71a157ce4a65ad6 Mon Sep 17 00:00:00 2001 From: Jan Luebbe Date: Wed, 10 Oct 2012 12:42:51 +0200 Subject: parameter: support removing named parameters Signed-off-by: Jan Luebbe Signed-off-by: Sascha Hauer --- include/param.h | 4 ++++ lib/parameter.c | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/include/param.h b/include/param.h index e0c415d4f8..21f4f7d832 100644 --- a/include/param.h +++ b/include/param.h @@ -30,6 +30,8 @@ int dev_add_param(struct device_d *dev, const char *name, int dev_add_param_fixed(struct device_d *dev, char *name, char *value); +void dev_remove_param(struct device_d *dev, char *name); + void dev_remove_parameters(struct device_d *dev); int dev_param_set_generic(struct device_d *dev, struct param_d *p, @@ -67,6 +69,8 @@ static inline int dev_add_param_fixed(struct device_d *dev, char *name, char *va return 0; } +static inline void dev_remove_param(struct device_d *dev, char *name) {} + static inline void dev_remove_parameters(struct device_d *dev) {} static inline int dev_param_set_generic(struct device_d *dev, struct param_d *p, diff --git a/lib/parameter.c b/lib/parameter.c index 3ecb480963..152a5dd27b 100644 --- a/lib/parameter.c +++ b/lib/parameter.c @@ -212,6 +212,24 @@ int dev_add_param_fixed(struct device_d *dev, char *name, char *value) return 0; } +/** + * dev_remove_param - remove a parameter from a device and free its + * memory + * @param dev The device + * @param name The name of the parameter + */ +void dev_remove_param(struct device_d *dev, char *name) +{ + struct param_d *p = get_param_by_name(dev, name); + + if (p) { + p->set(dev, p, NULL); + list_del(&p->list); + free(p->name); + free(p); + } +} + /** * dev_remove_parameters - remove all parameters from a device and free their * memory -- cgit v1.2.3 From e5a8c1e2324acde9740ae28febf24ec8634f9448 Mon Sep 17 00:00:00 2001 From: Franck Jullien Date: Thu, 11 Oct 2012 22:45:21 +0200 Subject: common/partitions.c: make use of is_fat_or_mbr Signed-off-by: Franck Jullien Signed-off-by: Sascha Hauer --- common/partitions.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/common/partitions.c b/common/partitions.c index cee0a6505d..5682b5119c 100644 --- a/common/partitions.c +++ b/common/partitions.c @@ -28,6 +28,7 @@ #include #include #include +#include struct partition { uint64_t first_sec; @@ -85,7 +86,7 @@ static void __maybe_unused try_dos_partition(struct block_device *blk, goto on_error; } - if ((buffer[510] != 0x55) || (buffer[511] != 0xAA)) { + if (is_fat_or_mbr(buffer, NULL) != filetype_mbr) { dev_info(blk->dev, "No partition table found\n"); goto on_error; } -- cgit v1.2.3 From 27b77dc415a941b6e13b940b8b124bdaeb7bfeba Mon Sep 17 00:00:00 2001 From: Carlo Caione Date: Fri, 12 Oct 2012 00:14:29 +0200 Subject: cosmetic: improve command list display Following from the Frank Jullien's patch, here is the same cosmetic correction when the list of commands is printed (the problem was that the commands for gpio_* were too long for the %10s alignment) Signed-off-by: Carlo Caione Signed-off-by: Sascha Hauer --- commands/help.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/commands/help.c b/commands/help.c index 72b0befecb..a12d9c3547 100644 --- a/commands/help.c +++ b/commands/help.c @@ -28,12 +28,17 @@ static int do_help(int argc, char *argv[]) { struct command *cmdtp; + int max_length = 0; if (argc == 1) { /* show list of commands */ + for_each_command(cmdtp) + if(strlen(cmdtp->name) > max_length) + max_length = strlen(cmdtp->name); + for_each_command(cmdtp) { if (!cmdtp->usage) continue; - printf("%10s - %s\n", cmdtp->name, cmdtp->usage); + printf("%*s - %s\n", max_length, cmdtp->name, cmdtp->usage); } return 0; } -- cgit v1.2.3 From 03af6cc45c52cc70532ec1e8a7b64a8b48c4f7cc Mon Sep 17 00:00:00 2001 From: Vicente Bergas Date: Mon, 15 Oct 2012 02:22:38 +0200 Subject: UIMAGE: improve transfer speed Signed-off-by: Vicente Bergas Signed-off-by: Sascha Hauer --- common/uimage.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/uimage.c b/common/uimage.c index c72db417a5..b58dff1dd2 100644 --- a/common/uimage.c +++ b/common/uimage.c @@ -373,7 +373,7 @@ static int uimage_sdram_flush(void *buf, unsigned int len) return len; } -#define BUFSIZ (PAGE_SIZE * 2) +#define BUFSIZ (PAGE_SIZE * 32) struct resource *file_to_sdram(const char *filename, unsigned long adr) { -- cgit v1.2.3 From 3a8d4e9440e99fc0e0084c3594eb4ffe2124794f Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Mon, 15 Oct 2012 19:19:16 +0200 Subject: make make -s more silent use $(kecho) instead of echo to not output messages with make -s Signed-off-by: Sascha Hauer --- Makefile | 6 +++--- arch/arm/pbl/Makefile | 2 +- arch/arm/tools/Makefile | 4 ++-- arch/nios2/Makefile | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 3e2b81fef1..98d43d4cfb 100644 --- a/Makefile +++ b/Makefile @@ -894,7 +894,7 @@ endef # directory for generated filesas used by some architectures. define create-symlink if [ ! -L include/asm ]; then \ - echo ' SYMLINK $@ -> include/asm-$(SRCARCH)'; \ + $(kecho) ' SYMLINK $@ -> include/asm-$(SRCARCH)'; \ if [ ! -d include/asm-$(SRCARCH) ]; then \ mkdir -p include/asm-$(SRCARCH); \ fi; \ @@ -907,11 +907,11 @@ include/asm: $(Q)$(create-symlink) include/config.h: include/config/auto.conf - @echo ' SYMLINK $@ -> $(BOARD)/config.h' + $(Q)$(kecho) ' SYMLINK $@ -> $(BOARD)/config.h' ifneq ($(KBUILD_SRC),) $(Q)ln -fsn $(srctree)/$(BOARD)/config.h $@ else - @ln -fsn ../$(BOARD)/config.h $@ + $(Q)ln -fsn ../$(BOARD)/config.h $@ endif # Generate some files diff --git a/arch/arm/pbl/Makefile b/arch/arm/pbl/Makefile index fe68e72eed..286f8b5923 100644 --- a/arch/arm/pbl/Makefile +++ b/arch/arm/pbl/Makefile @@ -14,7 +14,7 @@ extra-y += piggy.gzip piggy.lzo piggy.lzma piggy.xzkern $(obj)/zbarebox.bin: $(obj)/zbarebox FORCE $(call if_changed,objcopy) $(call cmd,check_file_size,$(CONFIG_BAREBOX_MAX_IMAGE_SIZE)) - @echo ' Barebox: $@ is ready' + $(Q)$(kecho) ' Barebox: $@ is ready' $(obj)/zbarebox.S: $(obj)/zbarebox FORCE $(call if_changed,disasm) diff --git a/arch/arm/tools/Makefile b/arch/arm/tools/Makefile index 635cb1865e..67ae9e701b 100644 --- a/arch/arm/tools/Makefile +++ b/arch/arm/tools/Makefile @@ -5,6 +5,6 @@ # include/generated/mach-types.h: $(src)/gen-mach-types $(src)/mach-types - @echo ' Generating $@' - @mkdir -p $(dir $@) + $(Q)$(kecho) ' Generating $@' + $(Q)mkdir -p $(dir $@) $(Q)$(AWK) -f $^ > $@ || { rm -f $@; /bin/false; } diff --git a/arch/nios2/Makefile b/arch/nios2/Makefile index b94e07465b..681944f22d 100644 --- a/arch/nios2/Makefile +++ b/arch/nios2/Makefile @@ -6,7 +6,7 @@ KALLSYMS += --symbol-prefix=_ archprepare: maketools - @echo " SYMLINK include/nios_sopc.h -> arch/nios2/boards/$(board-y)/nios_sopc.h" + @$(kecho) " SYMLINK include/nios_sopc.h -> arch/nios2/boards/$(board-y)/nios_sopc.h" @ln -fsn ../arch/nios2/boards/$(board-y)/nios_sopc.h include/nios_sopc.h PHONY += maketools -- cgit v1.2.3 From 85799053140da9c798166ee0c3b66c589845cef0 Mon Sep 17 00:00:00 2001 From: Franck Jullien Date: Tue, 16 Oct 2012 21:58:11 +0200 Subject: cosmetic: remove right alignment on driver list In order to avoid misalignment, just remove the right alignment while printing the drivers list. Signed-off-by: Franck Jullien Signed-off-by: Sascha Hauer --- drivers/base/driver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/base/driver.c b/drivers/base/driver.c index 7bb3ab446e..3ce7953dc6 100644 --- a/drivers/base/driver.c +++ b/drivers/base/driver.c @@ -408,7 +408,7 @@ static int do_devinfo(int argc, char *argv[]) printf("\ndrivers:\n"); for_each_driver(drv) - printf("%10s\n",drv->name); + printf("%s\n",drv->name); } else { dev = get_device_by_name(argv[1]); -- cgit v1.2.3 From 735775a7c425525bda130fa3db6287735e0b1843 Mon Sep 17 00:00:00 2001 From: Antony Pavlov Date: Thu, 18 Oct 2012 12:58:55 +0400 Subject: commands/Kconfig: move 'ln' to the 'file commands' section Signed-off-by: Antony Pavlov Signed-off-by: Sascha Hauer --- commands/Kconfig | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/commands/Kconfig b/commands/Kconfig index e934f29d5c..2d336384a7 100644 --- a/commands/Kconfig +++ b/commands/Kconfig @@ -57,10 +57,6 @@ config CMD_READLINE tristate prompt "readline" -config CMD_LN - tristate - prompt "ln" - config CMD_TRUE tristate default y @@ -216,6 +212,10 @@ config CMD_DIRNAME Strip last component of file name and store the result in a environment variable +config CMD_LN + tristate + prompt "ln" + config CMD_READLINK tristate prompt "readlink" -- cgit v1.2.3 From de053ed91c2b2ac05527f87acd0cfee0270a23a3 Mon Sep 17 00:00:00 2001 From: Antony Pavlov Date: Thu, 18 Oct 2012 12:54:33 +0400 Subject: add 'miitool' command to view media-independent interface status This command is based on the 'mii-diag' and 'mii-tool' Unix utilities, but it lacks routines to manipulate MII state (e.g. reset MII, restart autonegotiation or force MII mode). This version of the 'miitool' command has no GbE support, but we can upgrade it in the future. The GbE support patch for generic 'mii-tool' is here http://ftp.debian.org/debian/pool/main/n/net-tools/net-tools_1.60-24.2.diff.gz EXAMPLE: barebox:/ miitool -vv /dev/phy0 negotiated 100baseTx-FD, link ok registers for MII PHY: 3100 782d 0013 78e2 01e1 45e1 0007 2001 0000 ffff ffff ffff ffff ffff ffff ffff 0084 4780 0000 0000 0422 0000 0000 0000 0000 0000 0080 0000 ffff 0000 0000 3660 product info: Level One LXT971A rev 2 basic mode: autonegotiation enabled basic status: autonegotiation complete, link ok capabilities: 100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD advertising: 100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD link partner: 100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD flow-control Signed-off-by: Antony Pavlov Signed-off-by: Sascha Hauer --- commands/Kconfig | 11 +++ commands/Makefile | 1 + commands/miitool.c | 268 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 280 insertions(+) create mode 100644 commands/miitool.c diff --git a/commands/Kconfig b/commands/Kconfig index 2d336384a7..0ab958a5b2 100644 --- a/commands/Kconfig +++ b/commands/Kconfig @@ -620,6 +620,17 @@ config CMD_USB help The usb command allows to rescan for USB devices. +config CMD_MIITOOL + tristate + depends on PHYLIB + prompt "miitool" + help + The miitool command allows to view media-independent interface status. + The default short output reports the negotiated link speed and + link status for selected MII. The '-v' option displays more + detailed MII status information, such as MII capabilities, + current advertising mode, and link partner capabilities. + config CMD_CLK tristate depends on COMMON_CLK diff --git a/commands/Makefile b/commands/Makefile index 610be55c6a..c6416ca84b 100644 --- a/commands/Makefile +++ b/commands/Makefile @@ -76,3 +76,4 @@ obj-$(CONFIG_CMD_READLINK) += readlink.o obj-$(CONFIG_CMD_LN) += ln.o obj-$(CONFIG_CMD_CLK) += clk.o obj-$(CONFIG_CMD_TFTP) += tftp.o +obj-$(CONFIG_CMD_MIITOOL) += miitool.o diff --git a/commands/miitool.c b/commands/miitool.c new file mode 100644 index 0000000000..3a9ac45605 --- /dev/null +++ b/commands/miitool.c @@ -0,0 +1,268 @@ +/* + * Copyright (C) 2012 Antony Pavlov + * + * This file is part of barebox. + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is based on Donald Becker's "mii-diag" and + * David A. Hinds' "mii-tool". + * + * mii-tool is written/copyright 2000 by David A. Hinds + * + * + * mii-diag is written/copyright 1997-2000 by Donald Becker + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation. + * + * 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. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static u16 mdio_read(int fd, int offset) +{ + int ret; + u16 buf; + + ret = lseek(fd, offset << 1, SEEK_SET); + if (ret < 0) + return 0; + + ret = read(fd, &buf, sizeof(u16)); + if (ret < 0) + return 0; + + return buf; +} + +/* Table of known MII's */ +static const struct { + u_short id1, id2; + u_short mask1, mask2; + char *name; +} mii_id[] = { + { 0x0013, 0x78e0, 0xffff, 0xfff0, "Level One LXT971A" }, +}; +#define NMII (sizeof(mii_id)/sizeof(mii_id[0])) + +const struct { + char *name; + u_short value; +} media[] = { + /* The order through 100baseT4 matches bits in the BMSR */ + { "10baseT-HD", ADVERTISE_10HALF }, + { "10baseT-FD", ADVERTISE_10FULL }, + { "100baseTx-HD", ADVERTISE_100HALF }, + { "100baseTx-FD", ADVERTISE_100FULL }, + { "100baseT4", LPA_100BASE4 }, + { "100baseTx", ADVERTISE_100FULL | ADVERTISE_100HALF }, + { "10baseT", ADVERTISE_10FULL | ADVERTISE_10HALF }, +}; +#define NMEDIA (sizeof(media)/sizeof(media[0])) + +static char *media_list(int mask, int best) +{ + static char buf[100]; + int i; + + *buf = '\0'; + mask >>= 5; + for (i = 4; i >= 0; i--) { + if (mask & (1 << i)) { + strcat(buf, " "); + strcat(buf, media[i].name); + if (best) + break; + } + } + + if (mask & (1 << 5)) + strcat(buf, " flow-control"); + + return buf; +} + +static int show_basic_mii(int fd, int verbose) +{ + char buf[100]; + int i, mii_val[32]; + int bmcr, bmsr, advert, lkpar; + + /* Some bits in the BMSR are latched, but we can't rely on being + the only reader, so only the current values are meaningful */ + mdio_read(fd, MII_BMSR); + for (i = 0; i < ((verbose > 1) ? 32 : 8); i++) + mii_val[i] = mdio_read(fd, i); + + if (mii_val[MII_BMCR] == 0xffff) { + fprintf(stderr, " No MII transceiver present!.\n"); + return -1; + } + + /* Descriptive rename. */ + bmcr = mii_val[MII_BMCR]; + bmsr = mii_val[MII_BMSR]; + advert = mii_val[MII_ADVERTISE]; + lkpar = mii_val[MII_LPA]; + + *buf = '\0'; + if (bmcr & BMCR_ANENABLE) { + if (bmsr & BMSR_ANEGCOMPLETE) { + if (advert & lkpar) { + sprintf(buf, "%s%s, ", (lkpar & LPA_LPACK) ? + "negotiated" : "no autonegotiation,", + media_list(advert & lkpar, 1)); + } else { + sprintf(buf, "autonegotiation failed, "); + } + } else if (bmcr & BMCR_ANRESTART) { + sprintf(buf, "autonegotiation restarted, "); + } + } else { + sprintf(buf, "%s Mbit, %s duplex, ", + (bmcr & BMCR_SPEED100) ? "100" : "10", + (bmcr & BMCR_FULLDPLX) ? "full" : "half"); + } + + strcat(buf, (bmsr & BMSR_LSTATUS) ? "link ok" : "no link"); + + printf("%s\n", buf); + + if (verbose > 1) { + printf(" registers for MII PHY: "); + for (i = 0; i < 32; i++) + printf("%s %4.4x", + ((i % 8) ? "" : "\n "), mii_val[i]); + + printf("\n"); + } + + if (verbose) { + printf(" product info: "); + for (i = 0; i < NMII; i++) + if ((mii_id[i].id1 == (mii_val[2] & mii_id[i].mask1)) && + (mii_id[i].id2 == + (mii_val[3] & mii_id[i].mask2))) + break; + + if (i < NMII) + printf("%s rev %d\n", mii_id[i].name, mii_val[3]&0x0f); + else + printf("vendor %02x:%02x:%02x, model %d rev %d\n", + mii_val[2] >> 10, (mii_val[2] >> 2) & 0xff, + ((mii_val[2] << 6)|(mii_val[3] >> 10)) & 0xff, + (mii_val[3] >> 4) & 0x3f, mii_val[3] & 0x0f); + + printf(" basic mode: "); + if (bmcr & BMCR_RESET) + printf("software reset, "); + if (bmcr & BMCR_LOOPBACK) + printf("loopback, "); + if (bmcr & BMCR_ISOLATE) + printf("isolate, "); + if (bmcr & BMCR_CTST) + printf("collision test, "); + if (bmcr & BMCR_ANENABLE) { + printf("autonegotiation enabled\n"); + } else { + printf("%s Mbit, %s duplex\n", + (bmcr & BMCR_SPEED100) ? "100" : "10", + (bmcr & BMCR_FULLDPLX) ? "full" : "half"); + } + printf(" basic status: "); + if (bmsr & BMSR_ANEGCOMPLETE) + printf("autonegotiation complete, "); + else if (bmcr & BMCR_ANRESTART) + printf("autonegotiation restarted, "); + if (bmsr & BMSR_RFAULT) + printf("remote fault, "); + printf((bmsr & BMSR_LSTATUS) ? "link ok" : "no link"); + printf("\n capabilities:%s", media_list(bmsr >> 6, 0)); + printf("\n advertising: %s", media_list(advert, 0)); + +#define LPA_ABILITY_MASK (LPA_10HALF | LPA_10FULL \ + | LPA_100HALF | LPA_100FULL \ + | LPA_100BASE4 | LPA_PAUSE_CAP) + + if (lkpar & LPA_ABILITY_MASK) + printf("\n link partner:%s", media_list(lkpar, 0)); + printf("\n"); + } + + return 0; +} + +static int do_miitool(int argc, char *argv[]) +{ + char *filename; + int opt; + int argc_min; + int fd; + int verbose; + + verbose = 0; + while ((opt = getopt(argc, argv, "v")) > 0) { + switch (opt) { + case 'v': + verbose++; + break; + default: + return COMMAND_ERROR_USAGE; + } + } + + argc_min = optind + 1; + + if (argc < argc_min) + return COMMAND_ERROR_USAGE; + + filename = argv[optind]; + + fd = open(filename, O_RDONLY); + if (fd < 0) { + printf("unable to read %s\n", filename); + return COMMAND_ERROR; + } + + show_basic_mii(fd, verbose); + + close(fd); + + return COMMAND_SUCCESS; +} + +BAREBOX_CMD_HELP_START(miitool) +BAREBOX_CMD_HELP_USAGE("miitool [[[-v] -v] -v] \n") +BAREBOX_CMD_HELP_SHORT("view status for MII .\n") +BAREBOX_CMD_HELP_END + +/** + * @page miitool_command +This utility checks or sets the status of a network interface's +Media Independent Interface (MII) unit. Most fast ethernet +adapters use an MII to autonegotiate link speed and duplex setting. + */ +BAREBOX_CMD_START(miitool) + .cmd = do_miitool, + .usage = "view media-independent interface status", + BAREBOX_CMD_HELP(cmd_miitool_help) +BAREBOX_CMD_END -- cgit v1.2.3 From 4d5fa6ca5c86bccc934ac8483167aa4f93f8601f Mon Sep 17 00:00:00 2001 From: Alexander Aring Date: Sun, 21 Oct 2012 22:59:06 +0200 Subject: progressbar: use __stringify in format string Use stringify in format string for HASH_PER_LINE. Signed-off-by: Alexander Aring Signed-off-by: Sascha Hauer --- lib/show_progress.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/show_progress.c b/lib/show_progress.c index d958a4468f..bc067eac57 100644 --- a/lib/show_progress.c +++ b/lib/show_progress.c @@ -20,6 +20,7 @@ #include #include #include +#include #define HASHES_PER_LINE 65 @@ -56,7 +57,7 @@ void init_progression_bar(int max) progress_max = max; spin = 0; if (progress_max) - printf("\t[%65s]\r\t[", ""); + printf("\t[%"__stringify(HASHES_PER_LINE)"s]\r\t[", ""); else printf("\t"); } -- cgit v1.2.3 From 19bd0bc9dbe40e4953adeabd3efa2846489b1700 Mon Sep 17 00:00:00 2001 From: Jean-Christophe PLAGNIOL-VILLARD Date: Wed, 17 Oct 2012 14:57:58 +0200 Subject: spi: move the depends on SPI to if SPI and keep config alphanum ordered Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD Signed-off-by: Sascha Hauer --- drivers/spi/Kconfig | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig index dc17eadce5..b00329096d 100644 --- a/drivers/spi/Kconfig +++ b/drivers/spi/Kconfig @@ -4,10 +4,19 @@ config SPI bool "Enable SPI driver support" default y +if SPI + +config DRIVER_SPI_ALTERA + bool "Altera SPI Master driver" + depends on NIOS2 + +config DRIVER_SPI_ATMEL + bool "Atmel (AT91) SPI Master driver" + depends on ARCH_AT91 + config DRIVER_SPI_IMX bool "i.MX SPI Master driver" depends on ARCH_IMX - depends on SPI config DRIVER_SPI_IMX_0_0 bool @@ -24,20 +33,10 @@ config DRIVER_SPI_IMX_2_3 depends on ARCH_IMX51 || ARCH_IMX53 || ARCH_IMX6 default y -config DRIVER_SPI_ALTERA - bool "Altera SPI Master driver" - depends on NIOS2 - depends on SPI - -config DRIVER_SPI_ATMEL - bool "Atmel (AT91) SPI Master driver" - depends on ARCH_AT91 - depends on SPI - - config DRIVER_SPI_OMAP3 bool "OMAP3 McSPI Master driver" depends on ARCH_OMAP3 - depends on SPI + +endif endmenu -- cgit v1.2.3 From 87feda4eb17229ec10dbc919cf3ee3d39959037b Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Sun, 14 Oct 2012 13:39:10 +0200 Subject: environment variables: use linux list This switches environment variables to use linux list. This is easier to read. An additional plus is that the environment variables no longer need an initcall, so malloc is the only requirement for them. Signed-off-by: Sascha Hauer --- commands/printenv.c | 22 ++++----- common/complete.c | 12 ++--- common/env.c | 121 ++++++++++++++++++++++++++------------------------ include/environment.h | 11 ++--- 4 files changed, 85 insertions(+), 81 deletions(-) diff --git a/commands/printenv.c b/commands/printenv.c index b18c7a137e..10e882ae9f 100644 --- a/commands/printenv.c +++ b/commands/printenv.c @@ -27,8 +27,8 @@ static int do_printenv(int argc, char *argv[]) { - struct variable_d *var; - struct env_context *c, *current_c; + struct variable_d *v; + struct env_context *c; if (argc == 2) { const char *val = getenv(argv[1]); @@ -40,22 +40,16 @@ static int do_printenv(int argc, char *argv[]) return 1; } - current_c = get_current_context(); - var = current_c->local->next; + c = get_current_context(); printf("locals:\n"); - while (var) { - printf("%s=%s\n", var_name(var), var_val(var)); - var = var->next; - } + list_for_each_entry(v, &c->local, list) + printf("%s=%s\n", var_name(v), var_val(v)); printf("globals:\n"); c = get_current_context(); - while(c) { - var = c->global->next; - while (var) { - printf("%s=%s\n", var_name(var), var_val(var)); - var = var->next; - } + while (c) { + list_for_each_entry(v, &c->global, list) + printf("%s=%s\n", var_name(v), var_val(v)); c = c->parent; } diff --git a/common/complete.c b/common/complete.c index 32d0d194b7..9206ef02a5 100644 --- a/common/complete.c +++ b/common/complete.c @@ -208,7 +208,7 @@ static int env_param_complete(struct string_list *sl, char *instr, int eval) { struct device_d *dev; struct variable_d *var; - struct env_context *c, *current_c; + struct env_context *c; char *instr_param; int len; char end = '='; @@ -225,21 +225,23 @@ static int env_param_complete(struct string_list *sl, char *instr, int eval) instr_param = strchr(instr, '.'); len = strlen(instr); - current_c = get_current_context(); - for(var = current_c->local->next; var; var = var->next) { + c = get_current_context(); + list_for_each_entry(var, &c->local, list) { if (strncmp(instr, var_name(var), len)) continue; string_list_add_asprintf(sl, "%s%s%c", begin, var_name(var), end); } - for (c = get_current_context(); c; c = c->parent) { - for (var = c->global->next; var; var = var->next) { + c = get_current_context(); + while (c) { + list_for_each_entry(var, &c->global, list) { if (strncmp(instr, var_name(var), len)) continue; string_list_add_asprintf(sl, "%s%s%c", begin, var_name(var), end); } + c = c->parent; } if (instr_param) { diff --git a/common/env.c b/common/env.c index 1b2a7c25ad..33a871f7eb 100644 --- a/common/env.c +++ b/common/env.c @@ -30,23 +30,36 @@ #include #include -#define VARIABLE_D_SIZE(name, value) (sizeof(struct variable_d) + strlen(name) + strlen(value) + 2) +static struct env_context root = { + .local = LIST_HEAD_INIT(root.local), + .global = LIST_HEAD_INIT(root.global), +}; -static struct env_context *context; +static struct env_context *context = &root; /** * Remove a list of environment variables * @param[in] v Variable anchor to remove */ -static void free_variables(struct variable_d *v) +static void free_context(struct env_context *c) { - struct variable_d *next; + struct variable_d *v, *tmp; - while (v) { - next = v->next; + list_for_each_entry_safe(v, tmp, &c->local, list) { + free(v->name); + free(v->data); + list_del(&v->list); free(v); - v = next; } + + list_for_each_entry_safe(v, tmp, &c->global, list) { + free(v->name); + free(v->data); + list_del(&v->list); + free(v); + } + + free(c); } /** Read back current context */ @@ -58,19 +71,14 @@ EXPORT_SYMBOL(get_current_context); /** - * FIXME + * Create a new variable context and put it on the stack */ int env_push_context(void) { struct env_context *c = xzalloc(sizeof(struct env_context)); - c->local = xzalloc(VARIABLE_D_SIZE("", "")); - c->global = xzalloc(VARIABLE_D_SIZE("", "")); - - if (!context) { - context = c; - return 0; - } + INIT_LIST_HEAD(&c->local); + INIT_LIST_HEAD(&c->global); c->parent = context; context = c; @@ -78,10 +86,8 @@ int env_push_context(void) return 0; } -postcore_initcall(env_push_context); - /** - * FIXME + * free current variable context and restore the previous one */ int env_pop_context(void) { @@ -89,9 +95,7 @@ int env_pop_context(void) if (context->parent) { c = context->parent; - free_variables(context->local); - free_variables(context->global); - free(context); + free_context(context); context = c; return 0; } @@ -105,7 +109,7 @@ int env_pop_context(void) */ char *var_val(struct variable_d *var) { - return &var->data[strlen(var->data) + 1]; + return var->data; } /** @@ -115,16 +119,18 @@ char *var_val(struct variable_d *var) */ char *var_name(struct variable_d *var) { - return var->data; + return var->name; } -static const char *getenv_raw(struct variable_d *var, const char *name) +static const char *getenv_raw(struct list_head *l, const char *name) { - while (var) { - if (!strcmp(var_name(var), name)) - return var_val(var); - var = var->next; + struct variable_d *v; + + list_for_each_entry(v, l, list) { + if (!strcmp(var_name(v), name)) + return var_val(v); } + return NULL; } @@ -150,12 +156,12 @@ const char *getenv (const char *name) c = context; - val = getenv_raw(c->local, name); + val = getenv_raw(&c->local, name); if (val) return val; while (c) { - val = getenv_raw(c->global, name); + val = getenv_raw(&c->global, name); if (val) return val; c = c->parent; @@ -164,34 +170,35 @@ const char *getenv (const char *name) } EXPORT_SYMBOL(getenv); -static int setenv_raw(struct variable_d *var, const char *name, const char *value) +static int setenv_raw(struct list_head *l, const char *name, const char *value) { - struct variable_d *newvar = NULL; - - if (value) { - newvar = xzalloc(VARIABLE_D_SIZE(name, value)); - strcpy(&newvar->data[0], name); - strcpy(&newvar->data[strlen(name) + 1], value); - } + struct variable_d *v; - while (var->next) { - if (!strcmp(var->next->data, name)) { + list_for_each_entry(v, l, list) { + if (!strcmp(v->name, name)) { if (value) { - newvar->next = var->next->next; - free(var->next); - var->next = newvar; + free(v->data); + v->data = xstrdup(value); + return 0; } else { - struct variable_d *tmp; - tmp = var->next; - var->next = var->next->next; - free(tmp); + list_del(&v->list); + free(v->name); + free(v->data); + free(v); + return 0; } } - var = var->next; } - var->next = newvar; + + if (value) { + v = xzalloc(sizeof(*v)); + v->name = xstrdup(name); + v->data = xstrdup(value); + list_add_tail(&v->list, l); + } + return 0; } @@ -199,8 +206,8 @@ int setenv(const char *_name, const char *value) { char *name = strdup(_name); char *par; - struct variable_d *var; int ret = 0; + struct list_head *list; if (value && !*value) value = NULL; @@ -224,12 +231,12 @@ int setenv(const char *_name, const char *value) goto out; } - if (getenv_raw(context->global, name)) - var = context->global; + if (getenv_raw(&context->global, name)) + list = &context->global; else - var = context->local; + list = &context->local; - ret = setenv_raw(var, name, value); + ret = setenv_raw(list, name, value); out: free(name); @@ -239,11 +246,11 @@ EXPORT_SYMBOL(setenv); int export(const char *varname) { - const char *val = getenv_raw(context->local, varname); + const char *val = getenv_raw(&context->local, varname); if (val) { - setenv_raw(context->global, varname, val); - setenv_raw(context->local, varname, NULL); + setenv_raw(&context->global, varname, val); + setenv_raw(&context->local, varname, NULL); } return 0; } diff --git a/include/environment.h b/include/environment.h index 5cd7ecfee0..fd7735ae74 100644 --- a/include/environment.h +++ b/include/environment.h @@ -26,14 +26,15 @@ * Managment of a environment variable */ struct variable_d { - struct variable_d *next; /**< List management */ - char data[0]; /**< variable length data */ + struct list_head list; + char *name; + char *data; }; struct env_context { - struct env_context *parent; /**< FIXME */ - struct variable_d *local; /**< FIXME */ - struct variable_d *global; /**< FIXME */ + struct env_context *parent; + struct list_head local; + struct list_head global; }; struct env_context *get_current_context(void); -- cgit v1.2.3 From d54f5b1b48046a418781352d53567130edd5bcde Mon Sep 17 00:00:00 2001 From: Jean-Christophe PLAGNIOL-VILLARD Date: Wed, 17 Oct 2012 15:05:14 +0200 Subject: driver: add support for requesting resource by name this will allow to avoid issue with resource order Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD Signed-off-by: Sascha Hauer --- drivers/base/driver.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ include/driver.h | 15 +++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/drivers/base/driver.c b/drivers/base/driver.c index 3ce7953dc6..3f5f6a2a15 100644 --- a/drivers/base/driver.c +++ b/drivers/base/driver.c @@ -252,6 +252,52 @@ void *dev_get_mem_region(struct device_d *dev, int num) } EXPORT_SYMBOL(dev_get_mem_region); +struct resource *dev_get_resource_by_name(struct device_d *dev, + const char *name) +{ + int i; + + for (i = 0; i < dev->num_resources; i++) { + struct resource *res = &dev->resource[i]; + if (resource_type(res) != IORESOURCE_MEM) + continue; + if (!res->name) + continue; + if (!strcmp(name, res->name)) + return res; + } + + return NULL; +} + +void *dev_get_mem_region_by_name(struct device_d *dev, const char *name) +{ + struct resource *res; + + res = dev_get_resource_by_name(dev, name); + if (!res) + return NULL; + + return (void __force *)res->start; +} +EXPORT_SYMBOL(dev_get_mem_region_by_name); + +void __iomem *dev_request_mem_region_by_name(struct device_d *dev, const char *name) +{ + struct resource *res; + + res = dev_get_resource_by_name(dev, name); + if (!res) + return NULL; + + res = request_iomem_region(dev_name(dev), res->start, res->end); + if (!res) + return NULL; + + return (void __force __iomem *)res->start; +} +EXPORT_SYMBOL(dev_request_mem_region_by_name); + void __iomem *dev_request_mem_region(struct device_d *dev, int num) { struct resource *res; diff --git a/include/driver.h b/include/driver.h index 4918054887..f8d815c619 100644 --- a/include/driver.h +++ b/include/driver.h @@ -192,6 +192,21 @@ static inline const char *dev_name(const struct device_d *dev) return dev_id(dev); } +/* + * get resource base 'name' for a device + */ +struct resource *dev_get_resource_by_name(struct device_d *dev, + const char *name); +/* + * get register base 'name' for a device + */ +void *dev_get_mem_region_by_name(struct device_d *dev, const char *name); + +/* + * exlusively request register base 'name' for a device + */ +void __iomem *dev_request_mem_region_by_name(struct device_d *dev, + const char *name); /* * get register base 'num' for a device */ -- cgit v1.2.3 From 345299e94c196024bc288cb9b132f966cfd49538 Mon Sep 17 00:00:00 2001 From: Jean-Christophe PLAGNIOL-VILLARD Date: Wed, 17 Oct 2012 15:05:15 +0200 Subject: nomadik_nand: switch to named resource Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD Signed-off-by: Sascha Hauer --- arch/arm/boards/nhk8815/setup.c | 3 +++ drivers/mtd/nand/nomadik_nand.c | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/arch/arm/boards/nhk8815/setup.c b/arch/arm/boards/nhk8815/setup.c index 7f93ecb196..0c85b25c71 100644 --- a/arch/arm/boards/nhk8815/setup.c +++ b/arch/arm/boards/nhk8815/setup.c @@ -50,14 +50,17 @@ static struct nomadik_nand_platform_data nhk8815_nand_data = { static struct resource nhk8815_nand_resources[] = { { + .name = "nand_addr", .start = NAND_IO_ADDR, .end = NAND_IO_ADDR + 0xfff, .flags = IORESOURCE_MEM, }, { + .name = "nand_cmd", .start = NAND_IO_CMD, .end = NAND_IO_CMD + 0xfff, .flags = IORESOURCE_MEM, }, { + .name = "nand_data", .start = NAND_IO_DATA, .end = NAND_IO_DATA + 0xfff, .flags = IORESOURCE_MEM, diff --git a/drivers/mtd/nand/nomadik_nand.c b/drivers/mtd/nand/nomadik_nand.c index 6fc93984c9..b19d6c63c1 100644 --- a/drivers/mtd/nand/nomadik_nand.c +++ b/drivers/mtd/nand/nomadik_nand.c @@ -189,8 +189,8 @@ static int nomadik_nand_probe(struct device_d *dev) goto err; } - host->cmd_va = dev_request_mem_region(dev, 1); - host->addr_va = dev_request_mem_region(dev, 0); + host->cmd_va = dev_request_mem_region_by_name(dev, "nand_cmd"); + host->addr_va = dev_request_mem_region_by_name(dev, "nand_addr"); /* Link all private pointers */ mtd = &host->mtd; @@ -198,7 +198,7 @@ static int nomadik_nand_probe(struct device_d *dev) mtd->priv = nand; nand->priv = host; - nand->IO_ADDR_W = nand->IO_ADDR_R = dev_request_mem_region(dev, 2); + nand->IO_ADDR_W = nand->IO_ADDR_R = dev_request_mem_region_by_name(dev, "nand_data"); nand->cmd_ctrl = nomadik_cmd_ctrl; nand->ecc.mode = NAND_ECC_HW; -- cgit v1.2.3 From f4ca20c4d27751ee749f382cfd4949d825534fce Mon Sep 17 00:00:00 2001 From: Jean-Christophe PLAGNIOL-VILLARD Date: Sat, 3 Nov 2012 15:56:38 +0100 Subject: eth: register device a pure device as we do not need to probe them and they have no driver or bus attached Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD Signed-off-by: Sascha Hauer --- net/eth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/eth.c b/net/eth.c index f3d7bfea59..220edcfade 100644 --- a/net/eth.c +++ b/net/eth.c @@ -261,7 +261,7 @@ int eth_register(struct eth_device *edev) if (edev->parent) dev_add_child(edev->parent, &edev->dev); - platform_device_register(&edev->dev); + register_device(&edev->dev); dev_add_param(dev, "ipaddr", eth_set_ipaddr, NULL, 0); dev_add_param(dev, "ethaddr", eth_set_ethaddr, NULL, 0); -- cgit v1.2.3