summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2019-09-12 07:53:05 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2019-09-12 07:53:05 +0200
commit9b1102c02bfd39352e0d2995c733edb7be3b0601 (patch)
tree3f089c640bab75c020b69f5dcf44d744a0a7f2e4 /common
parentf48a1596f4e911d4516b986e4778f18321b39b48 (diff)
parenta10dbfc4175867c0d15f02b7f244837c5d41478e (diff)
downloadbarebox-9b1102c02bfd39352e0d2995c733edb7be3b0601.tar.gz
barebox-9b1102c02bfd39352e0d2995c733edb7be3b0601.tar.xz
Merge branch 'for-next/misc'
Diffstat (limited to 'common')
-rw-r--r--common/complete.c2
-rw-r--r--common/console.c22
-rw-r--r--common/elf.c45
-rw-r--r--common/ratp/mw.c2
-rw-r--r--common/ratp/ratp.c12
-rw-r--r--common/startup.c6
6 files changed, 44 insertions, 45 deletions
diff --git a/common/complete.c b/common/complete.c
index 2dab7d1dde..919e5abc6a 100644
--- a/common/complete.c
+++ b/common/complete.c
@@ -277,7 +277,6 @@ 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;
- char *instr_param;
int len;
char end = '=', *pos, *dot;
char *begin = "";
@@ -317,7 +316,6 @@ static int env_param_complete(struct string_list *sl, char *instr, int eval)
devname = xstrndup(instr, dot - instr);
- instr_param++;
dev = get_device_by_name(devname);
free(devname);
diff --git a/common/console.c b/common/console.c
index ee17a508ba..d04aae58f9 100644
--- a/common/console.c
+++ b/common/console.c
@@ -253,20 +253,19 @@ static void console_set_stdoutpath(struct console_device *cdev)
free(str);
}
-static int __console_puts(struct console_device *cdev, const char *s)
+static int __console_puts(struct console_device *cdev, const char *s,
+ size_t nbytes)
{
- int n = 0;
+ size_t i;
- while (*s) {
- if (*s == '\n') {
+ for (i = 0; i < nbytes; i++) {
+ if (*s == '\n')
cdev->putc(cdev, '\r');
- n++;
- }
+
cdev->putc(cdev, *s);
- n++;
s++;
}
- return n;
+ return i;
}
static int fops_open(struct cdev *cdev, unsigned long flags)
@@ -298,7 +297,7 @@ static ssize_t fops_write(struct cdev* dev, const void* buf, size_t count,
{
struct console_device *priv = dev->priv;
- priv->puts(priv, buf);
+ priv->puts(priv, buf, count);
return count;
}
@@ -324,6 +323,9 @@ int console_register(struct console_device *newcdev)
dev->parent = newcdev->dev;
platform_device_register(dev);
+ if (!newcdev->devname)
+ newcdev->devname = xstrdup(dev_name(dev));
+
newcdev->open_count = 0;
/*
@@ -545,7 +547,7 @@ int console_puts(unsigned int ch, const char *str)
if (initialized == CONSOLE_INIT_FULL) {
for_each_console(cdev) {
if (cdev->f_active & ch) {
- n = cdev->puts(cdev, str);
+ n = cdev->puts(cdev, str, strlen(str));
}
}
return n;
diff --git a/common/elf.c b/common/elf.c
index 8edf388564..4733accb05 100644
--- a/common/elf.c
+++ b/common/elf.c
@@ -45,29 +45,31 @@ static void elf_release_regions(struct elf_image *elf)
static int load_elf_phdr_segment(struct elf_image *elf, void *src,
- Elf32_Phdr *phdr)
+ void *phdr)
{
- void *dst = (void *)phdr->p_paddr;
+ void *dst = (void *) elf_phdr_p_paddr(elf, phdr);
int ret;
+ u64 p_filesz = elf_phdr_p_filesz(elf, phdr);
+ u64 p_memsz = elf_phdr_p_memsz(elf, phdr);
/* we care only about PT_LOAD segments */
- if (phdr->p_type != PT_LOAD)
+ if (elf_phdr_p_type(elf, phdr) != PT_LOAD)
return 0;
- if (!phdr->p_filesz)
+ if (!p_filesz)
return 0;
- pr_debug("Loading phdr to 0x%p (%i bytes)\n", dst, phdr->p_filesz);
+ pr_debug("Loading phdr to 0x%p (%llu bytes)\n", dst, p_filesz);
- ret = elf_request_region(elf, (resource_size_t)dst, phdr->p_filesz);
+ ret = elf_request_region(elf, (resource_size_t)dst, p_filesz);
if (ret)
return ret;
- memcpy(dst, src, phdr->p_filesz);
+ memcpy(dst, src, p_filesz);
- if (phdr->p_filesz < phdr->p_memsz)
- memset(dst + phdr->p_filesz, 0x00,
- phdr->p_memsz - phdr->p_filesz);
+ if (p_filesz < p_memsz)
+ memset(dst + p_filesz, 0x00,
+ p_memsz - p_filesz);
return 0;
}
@@ -75,14 +77,13 @@ static int load_elf_phdr_segment(struct elf_image *elf, void *src,
static int load_elf_image_phdr(struct elf_image *elf)
{
void *buf = elf->buf;
- Elf32_Ehdr *ehdr = buf;
- Elf32_Phdr *phdr = (Elf32_Phdr *)(buf + ehdr->e_phoff);
+ void *phdr = (void *) (buf + elf_hdr_e_phoff(elf, buf));
int i, ret;
- elf->entry = ehdr->e_entry;
+ elf->entry = elf_hdr_e_entry(elf, buf);
- for (i = 0; i < ehdr->e_phnum; ++i) {
- void *src = buf + phdr->p_offset;
+ for (i = 0; i < elf_hdr_e_phnum(elf, buf) ; ++i) {
+ void *src = buf + elf_phdr_p_offset(elf, phdr);
ret = load_elf_phdr_segment(elf, src, phdr);
/* in case of error elf_load_image() caller should clean up and
@@ -90,22 +91,22 @@ static int load_elf_image_phdr(struct elf_image *elf)
if (ret)
return ret;
- ++phdr;
+ phdr += elf_size_of_phdr(elf);
}
return 0;
}
-static int elf_check_image(void *buf)
+static int elf_check_image(struct elf_image *elf)
{
- Elf32_Ehdr *ehdr = (Elf32_Ehdr *)buf;
-
- if (strncmp(buf, ELFMAG, SELFMAG)) {
+ if (strncmp(elf->buf, ELFMAG, SELFMAG)) {
pr_err("ELF magic not found.\n");
return -EINVAL;
}
- if (ehdr->e_type != ET_EXEC) {
+ elf->class = ((char *) elf->buf)[EI_CLASS];
+
+ if (elf_hdr_e_type(elf, elf->buf) != ET_EXEC) {
pr_err("Non EXEC ELF image.\n");
return -ENOEXEC;
}
@@ -124,7 +125,7 @@ struct elf_image *elf_load_image(void *buf)
elf->buf = buf;
- ret = elf_check_image(buf);
+ ret = elf_check_image(elf);
if (ret)
return ERR_PTR(ret);
diff --git a/common/ratp/mw.c b/common/ratp/mw.c
index 55e79bbaf0..772910b39d 100644
--- a/common/ratp/mw.c
+++ b/common/ratp/mw.c
@@ -125,7 +125,7 @@ static int ratp_cmd_mw(const struct ratp_bb *req, int req_len,
/* Validate buffer size */
if (buffer_size < (path_size + data_size)) {
- pr_err("ignored: size mismatch (%d < %hu): path or data not be fully given\n",
+ pr_err("ignored: size mismatch (%d < %u): path or data not be fully given\n",
req_len, path_size + data_size);
ret = -EINVAL;
goto out;
diff --git a/common/ratp/ratp.c b/common/ratp/ratp.c
index 9aea1786d6..e84ad22167 100644
--- a/common/ratp/ratp.c
+++ b/common/ratp/ratp.c
@@ -259,19 +259,17 @@ static int ratp_console_tstc(struct console_device *cdev)
return kfifo_len(ctx->console_recv_fifo) ? 1 : 0;
}
-static int ratp_console_puts(struct console_device *cdev, const char *s)
+static int ratp_console_puts(struct console_device *cdev, const char *s,
+ size_t nbytes)
{
struct ratp_ctx *ctx = container_of(cdev, struct ratp_ctx, ratp_console);
- int len = 0;
-
- len = strlen(s);
if (ratp_busy(&ctx->ratp))
- return len;
+ return nbytes;
- kfifo_put(ctx->console_transmit_fifo, s, len);
+ kfifo_put(ctx->console_transmit_fifo, s, nbytes);
- return len;
+ return nbytes;
}
static void ratp_console_putc(struct console_device *cdev, char c)
diff --git a/common/startup.c b/common/startup.c
index 88eeee5e3d..c6e119966a 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -202,7 +202,7 @@ void set_autoboot_state(enum autoboot_state autoboot)
* do_autoboot_countdown - print autoboot countdown to console
*
* This prints the autoboot countdown to the console and waits for input. This
- * evaluates the global.autoboot_about_key to determine which keys are allowed
+ * evaluates the global.autoboot_abort_key to determine which keys are allowed
* to interrupt booting and also global.autoboot_timeout to determine the timeout
* for the counter. This function can be called multiple times, it is executed
* only the first time.
@@ -314,11 +314,11 @@ static int run_init(void)
autoboot = do_autoboot_countdown();
+ console_ctrlc_allow();
+
if (autoboot == AUTOBOOT_BOOT)
run_command("boot");
- console_ctrlc_allow();
-
if (autoboot == AUTOBOOT_MENU)
run_command(MENUFILE);