9
0
Fork 0

Merge branch 'for-next/misc'

Conflicts:
	commands/Makefile
This commit is contained in:
Sascha Hauer 2013-10-07 08:00:25 +02:00
commit 33c56e21eb
25 changed files with 369 additions and 178 deletions

View File

@ -13,9 +13,17 @@ targets := zbarebox.lds zbarebox zbarebox.bin zbarebox.S \
# Make sure files are removed during clean
extra-y += piggy.gzip piggy.lz4 piggy.lzo piggy.lzma piggy.xzkern piggy.shipped zbarebox.map
ifeq ($(CONFIG_CPU_BIG_ENDIAN),y)
FIX_SIZE=-b
else
FIX_SIZE=
endif
$(obj)/zbarebox.bin: $(obj)/zbarebox FORCE
$(call if_changed,objcopy)
$(call cmd,check_file_size,$(CONFIG_BAREBOX_MAX_IMAGE_SIZE))
$(Q)$(kecho) ' Barebox: fix size'
$(Q)$(objtree)/scripts/fix_size -f $(objtree)/$@ -o 0x2c $(FIX_SIZE)
$(Q)$(kecho) ' Barebox: $@ is ready'
$(obj)/zbarebox.S: $(obj)/zbarebox FORCE

View File

@ -92,3 +92,4 @@ obj-$(CONFIG_CMD_BAREBOX_UPDATE)+= barebox-update.o
obj-$(CONFIG_CMD_MIITOOL) += miitool.o
obj-$(CONFIG_CMD_DETECT) += detect.o
obj-$(CONFIG_CMD_BOOT) += boot.o
obj-$(CONFIG_CMD_DEVINFO) += devinfo.o

View File

@ -82,6 +82,19 @@ out:
return ret;
}
static int crc_from_file(const char* file, ulong *crc)
{
char * buf;
buf= read_file(file, NULL);
if (!buf)
return -ENOMEM;
*crc = simple_strtoul(buf, NULL, 16);
return 0;
}
static int do_crc(int argc, char *argv[])
{
loff_t start = 0, size = ~0;
@ -92,7 +105,7 @@ static int do_crc(int argc, char *argv[])
#endif
int opt, err = 0, filegiven = 0, verify = 0;
while((opt = getopt(argc, argv, "f:F:v:")) > 0) {
while((opt = getopt(argc, argv, "f:F:v:V:")) > 0) {
switch(opt) {
case 'f':
filename = optarg;
@ -108,6 +121,10 @@ static int do_crc(int argc, char *argv[])
verify = 1;
vcrc = simple_strtoul(optarg, NULL, 0);
break;
case 'V':
if (!crc_from_file(optarg, &vcrc))
verify = 1;
break;
default:
return COMMAND_ERROR_USAGE;
}
@ -153,6 +170,7 @@ BAREBOX_CMD_HELP_OPT ("-f <file>", "Use file instead of memory.\n")
BAREBOX_CMD_HELP_OPT ("-F <file>", "Use file to compare.\n")
#endif
BAREBOX_CMD_HELP_OPT ("-v <crc>", "Verify\n")
BAREBOX_CMD_HELP_OPT ("-V <file>", "Verify with crc read from <file>\n")
BAREBOX_CMD_HELP_END
BAREBOX_CMD_START(crc32)

158
commands/devinfo.c Normal file
View File

@ -0,0 +1,158 @@
/*
* Copyright (C) 2013 Sascha Hauer, Pengutronix
*
* 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.
*
*/
#include <command.h>
#include <common.h>
#include <complete.h>
#include <driver.h>
static int do_devinfo_subtree(struct device_d *dev, int depth)
{
struct device_d *child;
struct cdev *cdev;
int i;
for (i = 0; i < depth; i++)
printf(" ");
printf("`---- %s", dev_name(dev));
if (!list_empty(&dev->cdevs)) {
printf("\n");
list_for_each_entry(cdev, &dev->cdevs, devices_list) {
for (i = 0; i < depth + 1; i++)
printf(" ");
printf("`---- 0x%08llx-0x%08llx: /dev/%s\n",
cdev->offset,
cdev->offset + cdev->size - 1,
cdev->name);
}
} else {
printf("\n");
}
if (!list_empty(&dev->children)) {
device_for_each_child(dev, child) {
do_devinfo_subtree(child, depth + 1);
}
}
return 0;
}
static int do_devinfo(int argc, char *argv[])
{
struct device_d *dev;
struct driver_d *drv;
struct param_d *param;
int i;
struct resource *res;
if (argc == 1) {
printf("devices:\n");
for_each_device(dev) {
if (!dev->parent)
do_devinfo_subtree(dev, 0);
}
printf("\ndrivers:\n");
for_each_driver(drv)
printf("%s\n",drv->name);
} else {
dev = get_device_by_name(argv[1]);
if (!dev) {
printf("no such device: %s\n",argv[1]);
return -1;
}
printf("resources:\n");
for (i = 0; i < dev->num_resources; i++) {
res = &dev->resource[i];
printf("num : %d\n", i);
if (res->name)
printf("name : %s\n", res->name);
printf("start : " PRINTF_CONVERSION_RESOURCE "\nsize : "
PRINTF_CONVERSION_RESOURCE "\n",
res->start, resource_size(res));
}
printf("driver: %s\n", dev->driver ?
dev->driver->name : "none");
printf("bus: %s\n\n", dev->bus ?
dev->bus->name : "none");
if (dev->info)
dev->info(dev);
printf("%s\n", list_empty(&dev->parameters) ?
"no parameters available" : "Parameters:");
list_for_each_entry(param, &dev->parameters, list) {
printf("%16s = %s", param->name, dev_get_param(dev, param->name));
if (param->info)
param->info(param);
printf("\n");
}
#ifdef CONFIG_OFDEVICE
if (dev->device_node) {
printf("\ndevice node: %s\n", dev->device_node->full_name);
of_print_nodes(dev->device_node, 0);
}
#endif
}
return 0;
}
BAREBOX_CMD_HELP_START(devinfo)
BAREBOX_CMD_HELP_USAGE("devinfo [DEVICE]\n")
BAREBOX_CMD_HELP_SHORT("Output device information.\n")
BAREBOX_CMD_HELP_END
/**
* @page devinfo_command
If called without arguments, devinfo shows a summary of the known
devices and drivers.
If called with a device path being the argument, devinfo shows more
default information about this device and its parameters.
Example from an MPC5200 based system:
@verbatim
barebox:/ devinfo /dev/eth0
base : 0x1002b000
size : 0x00000000
driver: fec_mpc5xxx
no info available for eth0
Parameters:
ipaddr = 192.168.23.197
ethaddr = 80:81:82:83:84:86
gateway = 192.168.23.1
netmask = 255.255.255.0
serverip = 192.168.23.2
@endverbatim
*/
BAREBOX_CMD_START(devinfo)
.cmd = do_devinfo,
.usage = "Show information about devices and drivers.",
BAREBOX_CMD_HELP(cmd_devinfo_help)
BAREBOX_CMD_COMPLETE(device_complete)
BAREBOX_CMD_END

View File

@ -58,13 +58,25 @@ BAREBOX_CMD_END
static int do_ubiattach(int argc, char *argv[])
{
int opt;
struct mtd_info_user user;
int fd, ret;
int vid_hdr_offset = 0;
if (argc != 2)
while((opt = getopt(argc, argv, "O:")) > 0) {
switch(opt) {
case 'O':
vid_hdr_offset = simple_strtoul(optarg, NULL, 0);
break;
default:
return COMMAND_ERROR_USAGE;
}
}
if (optind == argc)
return COMMAND_ERROR_USAGE;
fd = open(argv[1], O_RDWR);
fd = open(argv[optind], O_RDWR);
if (fd < 0) {
perror("open");
return 1;
@ -76,7 +88,7 @@ static int do_ubiattach(int argc, char *argv[])
goto err;
}
ret = ubi_attach_mtd_dev(user.mtd, UBI_DEV_NUM_AUTO, 0, 20);
ret = ubi_attach_mtd_dev(user.mtd, UBI_DEV_NUM_AUTO, vid_hdr_offset, 20);
if (ret < 0)
printf("failed to attach: %s\n", strerror(-ret));
else
@ -88,7 +100,7 @@ err:
}
static const __maybe_unused char cmd_ubiattach_help[] =
"Usage: ubiattach <mtddev>\n"
"Usage: ubiattach [-O vid-hdr-offset] <mtddev>\n"
"Attach <mtddev> to ubi\n";
BAREBOX_CMD_START(ubiattach)

View File

@ -72,6 +72,9 @@ int globalvar_add_simple(const char *name, const char *value)
if (ret && ret != -EEXIST)
return ret;
if (!value)
return 0;
return dev_set_param(&global_device, name, value);
}

View File

@ -123,6 +123,7 @@
#include <linux/list.h>
#include <binfmt.h>
#include <init.h>
#include <shell.h>
/*cmd_boot.c*/
extern int do_bootd(int flag, int argc, char *argv[]); /* do_bootd */
@ -226,6 +227,11 @@ static char console_buffer[CONFIG_CBSIZE]; /* console I/O buffer */
* the first three support $?, $#, and $1 */
static unsigned int last_return_code;
int shell_get_last_return_code(void)
{
return last_return_code;
}
/* "globals" within this file */
static uchar *ifs;
static char map[256];

View File

@ -1,6 +1,15 @@
#include <common.h>
#include <command.h>
#include <environment.h>
#include <shell.h>
/*
* not yet supported
*/
int shell_get_last_return_code(void)
{
return 0;
}
static int parse_line (char *line, char *argv[])
{

View File

@ -2,16 +2,23 @@
export PATH=/env/bin
global hostname=generic
global user=none
global autoboot_timeout=3
global boot.default=net
global allow_color=true
global hostname
global user
global autoboot_timeout
global boot.default
global allow_color
global linux.bootargs.base
#linux.bootargs.dyn.* will be cleared at the beginning of boot
global linux.bootargs.dyn.ip
global linux.bootargs.dyn.root
global editcmd=sedit
global editcmd
[ -z "${global.hostname}" ] && global.hostname=generic
[ -z "${global.user}" ] && global.user=none
[ -z "${global.autoboot_timeout}" ] && global.autoboot_timeout=3
[ -z "${global.boot.default}" ] && global.boot.default=net
[ -z "${global.allow_color}" ] && global.allow_color=true
[ -z "${global.editcmd}" ] && global.editcmd=sedit
[ -e /env/config-board ] && /env/config-board
/env/config

View File

@ -417,145 +417,3 @@ int dev_get_drvdata(struct device_d *dev, unsigned long *data)
return -ENODEV;
}
#ifdef CONFIG_CMD_DEVINFO
static int do_devinfo_subtree(struct device_d *dev, int depth)
{
struct device_d *child;
struct cdev *cdev;
int i;
for (i = 0; i < depth; i++)
printf(" ");
printf("`---- %s", dev_name(dev));
if (!list_empty(&dev->cdevs)) {
printf("\n");
list_for_each_entry(cdev, &dev->cdevs, devices_list) {
for (i = 0; i < depth + 1; i++)
printf(" ");
printf("`---- 0x%08llx-0x%08llx: /dev/%s\n",
cdev->offset,
cdev->offset + cdev->size - 1,
cdev->name);
}
} else {
printf("\n");
}
if (!list_empty(&dev->children)) {
device_for_each_child(dev, child) {
do_devinfo_subtree(child, depth + 1);
}
}
return 0;
}
static int do_devinfo(int argc, char *argv[])
{
struct device_d *dev;
struct driver_d *drv;
struct param_d *param;
int i;
struct resource *res;
if (argc == 1) {
printf("devices:\n");
for_each_device(dev) {
if (!dev->parent)
do_devinfo_subtree(dev, 0);
}
printf("\ndrivers:\n");
for_each_driver(drv)
printf("%s\n",drv->name);
} else {
dev = get_device_by_name(argv[1]);
if (!dev) {
printf("no such device: %s\n",argv[1]);
return -1;
}
printf("resources:\n");
for (i = 0; i < dev->num_resources; i++) {
res = &dev->resource[i];
printf("num : %d\n", i);
if (res->name)
printf("name : %s\n", res->name);
printf("start : " PRINTF_CONVERSION_RESOURCE "\nsize : "
PRINTF_CONVERSION_RESOURCE "\n",
res->start, resource_size(res));
}
printf("driver: %s\n", dev->driver ?
dev->driver->name : "none");
printf("bus: %s\n\n", dev->bus ?
dev->bus->name : "none");
if (dev->info)
dev->info(dev);
printf("%s\n", list_empty(&dev->parameters) ?
"no parameters available" : "Parameters:");
list_for_each_entry(param, &dev->parameters, list) {
printf("%16s = %s", param->name, dev_get_param(dev, param->name));
if (param->info)
param->info(param);
printf("\n");
}
#ifdef CONFIG_OFDEVICE
if (dev->device_node) {
printf("\ndevice node: %s\n", dev->device_node->full_name);
of_print_nodes(dev->device_node, 0);
}
#endif
}
return 0;
}
BAREBOX_CMD_HELP_START(devinfo)
BAREBOX_CMD_HELP_USAGE("devinfo [DEVICE]\n")
BAREBOX_CMD_HELP_SHORT("Output device information.\n")
BAREBOX_CMD_HELP_END
/**
* @page devinfo_command
If called without arguments, devinfo shows a summary of the known
devices and drivers.
If called with a device path being the argument, devinfo shows more
default information about this device and its parameters.
Example from an MPC5200 based system:
@verbatim
barebox:/ devinfo /dev/eth0
base : 0x1002b000
size : 0x00000000
driver: fec_mpc5xxx
no info available for eth0
Parameters:
ipaddr = 192.168.23.197
ethaddr = 80:81:82:83:84:86
gateway = 192.168.23.1
netmask = 255.255.255.0
serverip = 192.168.23.2
@endverbatim
*/
BAREBOX_CMD_START(devinfo)
.cmd = do_devinfo,
.usage = "Show information about devices and drivers.",
BAREBOX_CMD_HELP(cmd_devinfo_help)
BAREBOX_CMD_COMPLETE(device_complete)
BAREBOX_CMD_END
#endif

View File

@ -74,7 +74,7 @@ static LIST_HEAD(usb_device_list);
static void print_usb_device(struct usb_device *dev)
{
printf("Bus %03d Device %03d: ID %04x:%04x %s\n",
pr_info("Bus %03d Device %03d: ID %04x:%04x %s\n",
dev->host->busnum, dev->devnum,
dev->descriptor->idVendor,
dev->descriptor->idProduct,
@ -440,6 +440,8 @@ static int usb_new_device(struct usb_device *dev)
dev->dev.id = DEVICE_ID_SINGLE;
if (dev->host->hw_dev)
dev->dev.parent = dev->host->hw_dev;
register_device(&dev->dev);
/* now prode if the device is a hub */
@ -527,7 +529,7 @@ void usb_rescan(int force)
struct usb_host *host;
int ret;
printf("USB: scanning bus for devices...\n");
pr_info("USB: scanning bus for devices...\n");
dev_index = 0;
list_for_each_entry(host, &host_list, list) {
@ -536,7 +538,7 @@ void usb_rescan(int force)
continue;
}
printf("%d USB Device(s) found\n", dev_index);
pr_info("%d USB Device(s) found\n", dev_index);
}
/*

View File

@ -883,6 +883,7 @@ int ehci_register(struct device_d *dev, struct ehci_data *data)
ehci->qh_list = dma_alloc_coherent(sizeof(struct QH) * NUM_TD);
ehci->td = dma_alloc_coherent(sizeof(struct qTD) * NUM_TD);
host->hw_dev = dev;
host->init = ehci_init;
host->submit_int_msg = submit_int_msg;
host->submit_control_msg = submit_control_msg;

View File

@ -1794,6 +1794,7 @@ static int ohci_probe(struct device_d *dev)
ohci = xzalloc(sizeof(struct ohci));
host = &ohci->host;
host->hw_dev = dev;
host->init = ohci_init;
host->submit_int_msg = submit_int_msg;
host->submit_control_msg = submit_control_msg;

12
include/shell.h Normal file
View File

@ -0,0 +1,12 @@
/*
* (C) Copyright 2013 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
*
* Under GPLv2 only
*/
#ifndef __SHELL_H__
#define __SHELL_H__
int shell_get_last_return_code(void);
#endif /* __SHELL_H__ */

View File

@ -210,6 +210,7 @@ struct usb_host {
struct list_head list;
struct device_d *hw_dev;
int busnum;
int scanned;
};

View File

@ -19,6 +19,7 @@
#include <common.h>
#include <fs.h>
#include <libbb.h>
#include <shell.h>
int process_escape_sequence(const char *source, char *dest, int destlen)
{
@ -59,6 +60,12 @@ int process_escape_sequence(const char *source, char *dest, int destlen)
case 'w':
i += snprintf(dest + i, destlen - i, "%s", getcwd());
break;
case '$':
if (*(source + 2) == '?') {
i += snprintf(dest + i, destlen - i, "%d", shell_get_last_return_code());
source++;
break;
}
default:
dest[i++] = '\\';
dest[i++] = *(source + 1);

1
scripts/.gitignore vendored
View File

@ -8,5 +8,4 @@ mk-am35xx-spi-image
mkimage
mkublheader
omap_signGP
omap4_usbboot
zynq_mkimage

View File

@ -1,30 +1,28 @@
###
# scripts contains sources for various helper programs used throughout
# the kernel for the build process.
# barebox for the build process.
# ---------------------------------------------------------------------------
# kallsyms: Find all symbols in barebox
hostprogs-$(CONFIG_KALLSYMS) += kallsyms
hostprogs-y += bin2c
hostprogs-y += mkimage
hostprogs-y += fix_size
hostprogs-y += bareboxenv
hostprogs-$(CONFIG_KALLSYMS) += kallsyms
hostprogs-$(CONFIG_ARCH_MVEBU) += kwbimage kwboot
hostprogs-$(CONFIG_ARCH_NETX) += gen_netx_image
hostprogs-$(CONFIG_ARCH_OMAP) += omap_signGP mk-am35xx-spi-image
hostprogs-$(CONFIG_ARCH_S5PCxx) += s5p_cksum
hostprogs-$(CONFIG_ARCH_DAVINCI) += mkublheader
hostprogs-$(CONFIG_ARCH_ZYNQ) += zynq_mkimage
subdir-$(CONFIG_ARCH_IMX) += imx
HOSTLOADLIBES_omap4_usbboot = -lpthread
omap4_usbboot-objs := usb_linux.o omap4_usbboot.o
hostprogs-$(CONFIG_OMAP4_USBBOOT)+= omap4_usbboot
subdir-y += mod
subdir-$(CONFIG_OMAP4_USBBOOT) += omap4_usbboot
subdir-$(CONFIG_ARCH_IMX) += imx
subdir-$(CONFIG_X86) += setupmbr
subdir-$(CONFIG_DTC) += dtc
always := $(hostprogs-y) $(hostprogs-m)
subdir-y += mod
subdir-$(CONFIG_X86) += setupmbr
targetprogs-$(CONFIG_BAREBOXENV_TARGET) += bareboxenv-target
# Let clean descend into subdirs
subdir- += basic kconfig setupmbr
@ -32,9 +30,12 @@ subdir- += basic kconfig setupmbr
quiet_cmd_csingle = CC $@
cmd_csingle = $(CC) -Wp,-MD,$(depfile) $(CFLAGS) -o $@ $<
obj-$(CONFIG_BAREBOXENV_TARGET) += bareboxenv-target
__targetprogs := $(sort $(targetprogs-y) $(targetprogs-m))
target-csingle := $(foreach m,$(__targetprogs),$(if $($(m)-objs),,$(m)))
__targetprogs := $(addprefix $(obj)/,$(__targetprogs))
target-csingle := $(addprefix $(obj)/,$(target-csingle))
scripts/bareboxenv-target: scripts/bareboxenv.c FORCE
always := $(hostprogs-y) $(hostprogs-m) $(targetprogs-y)
$(target-csingle): %-target: %.c FORCE
$(call if_changed_dep,csingle)
subdir-$(CONFIG_DTC) += dtc

View File

@ -35,7 +35,7 @@
#define debug(...)
void *xmalloc(size_t size)
static void *xmalloc(size_t size)
{
void *p = NULL;
@ -47,7 +47,7 @@ void *xmalloc(size_t size)
return p;
}
void *xzalloc(size_t size)
static void *xzalloc(size_t size)
{
void *p = xmalloc(size);
memset(p, 0, size);
@ -57,7 +57,7 @@ void *xzalloc(size_t size)
/* Find out if the last character of a string matches the one given.
* Don't underrun the buffer if the string length is 0.
*/
char* last_char_is(const char *s, int c)
static char *last_char_is(const char *s, int c)
{
if (s && *s) {
size_t sz = strlen(s) - 1;
@ -85,7 +85,7 @@ int recursive_action(const char *fileName, unsigned flags,
/* concatenate path and file name to new allocation buffer,
* not adding '/' if path name already has '/'
*/
char *concat_path_file(const char *path, const char *filename)
static char *concat_path_file(const char *path, const char *filename)
{
char *lc, *str;
@ -107,7 +107,7 @@ char *concat_path_file(const char *path, const char *filename)
* and skipping "." and ".." directory entries
*/
char *concat_subpath_file(const char *path, const char *f)
static char *concat_subpath_file(const char *path, const char *f)
{
if (f && DOT_OR_DOTDOT(f))
return NULL;
@ -120,7 +120,7 @@ char *concat_subpath_file(const char *path, const char *f)
#include "../lib/make_directory.c"
#include "../common/environment.c"
void usage(char *prgname)
static void usage(char *prgname)
{
printf( "Usage : %s [OPTION] DIRECTORY FILE\n"
"Load a barebox environment sector into a directory or\n"

81
scripts/fix_size.c Normal file
View File

@ -0,0 +1,81 @@
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdint.h>
#include <fcntl.h>
#ifndef _BSD_SOURCE
#define _BSD_SOURCE /* See feature_test_macros(7) */
#endif
#include <endian.h>
int main(int argc, char**argv)
{
struct stat s;
int c;
int fd;
uint64_t offset = 0;
uint32_t size = 0;
char *file = NULL;
int ret = 1;
int is_bigendian = 0;
while ((c = getopt (argc, argv, "hf:o:b")) != -1) {
switch (c) {
case 'f':
file = optarg;
break;
case 'o':
offset = strtoul(optarg, NULL, 16);
break;
case 'b':
is_bigendian = 1;
break;
}
}
if (!file) {
fprintf(stderr, "missing file\n");
return 1;
}
if (stat(file, &s)) {
perror("stat");
return 1;
}
fd = open(file, O_WRONLY);
if (fd < 0) {
perror("open");
return 1;
}
ret = lseek(fd, offset, SEEK_SET);
if (ret < 0) {
perror("lseek");
ret = 1;
goto err;
}
size = s.st_size;
if (is_bigendian)
size = htobe32(size);
else
size = htole32(size);
ret = write(fd, &size, 4);
if (ret != 4) {
perror("write");
ret = 1;
goto err;
}
ret = 0;
err:
close(fd);
return ret;
}

1
scripts/omap4_usbboot/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
omap4_usbboot

View File

@ -0,0 +1,5 @@
HOSTLOADLIBES_omap4_usbboot = -lpthread
omap4_usbboot-objs := usb_linux.o omap4_usbboot.o
hostprogs-$(CONFIG_OMAP4_USBBOOT) += omap4_usbboot
always := $(hostprogs-y)