This corresponds to kernel commit 72cf90124e87d975d0b
This fix ensures that we never meet an integer overflow while adding
255 while parsing a variable length encoding. It works differently from
commit 206a81c ("lzo: properly check for overruns") because instead of
ensuring that we don't overrun the input, which is tricky to guarantee
due to many assumptions in the code, it simply checks that the cumulated
number of 255 read cannot overflow by bounding this number.
The MAX_255_COUNT is the maximum number of times we can add 255 to a base
count without overflowing an integer. The multiply will overflow when
multiplying 255 by more than MAXINT/255. The sum will overflow earlier
depending on the base count. Since the base count is taken from a u8
and a few bits, it is safe to assume that it will always be lower than
or equal to 2*255, thus we can always prevent any overflow by accepting
two less 255 steps.
This patch also reduces the CPU overhead and actually increases performance
by 1.1% compared to the initial code, while the previous fix costs 3.1%
(measured on x86_64).
The fix needs to be backported to all currently supported stable kernels.
Reported-by: Willem Pinckaers <willem@lekkertech.net>
Cc: "Don A. Bailey" <donb@securitymouse.com>
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Willy Tarreau <w@1wt.eu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Stefan Müller-Klieser <s.mueller-klieser@phytec.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This reverts barebox commit ecb1dc0b1e
This corresponds to kernel commit af958a38a60c7ca3d8
As analysed by Willem Pinckaers, this fix is still incomplete on
certain rare corner cases, and it is easier to restart from the
original code.
Reported-by: Willem Pinckaers <willem@lekkertech.net>
Cc: "Don A. Bailey" <donb@securitymouse.com>
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Willy Tarreau <w@1wt.eu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Stefan Müller-Klieser <s.mueller-klieser@phytec.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Taken from the Kernel, put into the same place as in the kernel,
although the hexdump.c does not actually contain hexdum functions.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This adds a function to parse a full cmdline partition string. The
addpart command is switched to use this function.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
The return size should be loff_t to support partitions bigger
than 4G. Also use const for the devname and endp.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
If strdup() fails with out-of-memory, __dev_add_param() should fail
with -ENOMEM.
(Note strdup() is always given with a non-NULL pointer. If the
argument name is given with NULL, the system would already have
crashed in the get_param_by_name() function.)
Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
The function dev_param_set_generic() may fail because of
out of memory. If so, return -ENOMEM.
Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
lib/decompress_bunzip2.c includes <common.h> and INT_MAX is already
defined there. The definition in this file is redundant.
Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This file originates in Linux. Linux has it under include/linux/
directory since commit dccd2304cc90.
Let's move it to the same place as well in barebox.
This commit was generated by the following commands:
find -name '*.[chS]' | xargs sed -i -e 's:<sizes.h>:<linux/sizes.h>:'
git mv include/sizes.h include/linux/
Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This adds simple console support to the PBL which makes it
possible to print more complex messages in the PBL than just
strings or hex numbers. For now puts_ll is used to print the
messages, so it depends on CONFIG_DEBUG_LL which makes it
more a debugging option. However, this could be extended later
to get regular output from the PBL if desired.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
To be independent of the _ctype array. This makes it possible
to add printf support to the PBL without adding _ctype aswell.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
panic() is not really a printf like function, so move it to common/misc.c.
This is done because we want to have printf support in the PBL, but PBL
has it's own panic() implementation.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This adds xz decompression support from the kernel. Both compressing
the barebox binary with xz and decompressing xz files on the commandline
is supported.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Long time ago all ".ip" parameters have been replaced with ".ipaddr".
Signed-off-by: Rolf Evers-Fischer <embedded24@evers-fischer.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
dev_add_param creates a new parameter so it makes more sense to
return it than to return an error code. Since the return value
is hardly ever checked this is only a small patch.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Set return value correct in error case.
This prevents barebox from crashing in some conditions.
Signed-off-by: Teresa Gámez <t.gamez@phytec.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
We cannot use list_entry() on an empty list. Without history
we have to return an empty line. This fixes a crash when the
cursor up button is pressed and no command has been entered
previously. Broken since:
commit ada160a34a
Author: Sascha Hauer <s.hauer@pengutronix.de>
Date: Tue Jul 29 11:54:26 2014 +0200
readline: reimplement history functions
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Reported-by: Teresa Gamez <t.gamez@phytec.de>
read_file has some limitations:
- It is not possible to check the error code since read_file returns
NULL for failure
- It is not possible to limit the buffer size to sensible limits.
This patch introduces read_file_2 which doesn't have these limitations.
read_file becomes a wrapper around read_file_2.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
We have our file helper functions in several places. Move them
all to lib/libfile.c.
With this we no longer have file helpers in fs/fs.c which contains
the core fs functions and no functions in lib/libbb.c which are
not from busybox.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This reimplements the history functions in readline.
- Use regular lists instead of homegrown list implementation
- Allocate history strings dynamically instead of copying strings
to fixed buffers without checking the size
- saves us an initcall
- slightly smaller
- no longer add duplicates to the history
- when moving past the last history entry print an empty line
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This function allows drivers to create a string parameter and
provides access to it via a pointer. Using regular dev_add_param
only allows access via dev_get_param().
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
EFI uses 16 bit character strings. Add beginning support for this.
Since barebox uses 8 bit strings internally we need conversion functions
to convert between 16 bit and 8 bit strings.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
With EFI 16byte UUIDs/GUIDs are common. Add support for printing them.
This needs to be selected via Kconfig since most architectures have
no use for this functionality.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Note: this is the same as 4148c1f67abf823099b2d7db6851e4aea407f5ee in
linux-git.
There is one other possible overrun in the lz4 code as implemented by
Linux at this point in time (which differs from the upstream lz4
codebase, but will get synced at in a future kernel release.) As
pointed out by Don, we also need to check the overflow in the data
itself.
While we are at it, replace the odd error return value with just a
"simple" -1 value as the return value is never used for anything other
than a basic "did this work or not" check.
Reported-by: "Don A. Bailey" <donb@securitymouse.com>
Reported-by: Willy Tarreau <w@1wt.eu>
Signed-off-by: Holger Schurig <holgerschurig@gmail.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Note: this is the same as 206204a1162b995e2185275167b22468c00d6b36 in
linux-git.
Given some pathologically compressed data, lz4 could possibly decide to
wrap a few internal variables, causing unknown things to happen. Catch
this before the wrapping happens and abort the decompression.
Reported-by: "Don A. Bailey" <donb@securitymouse.com>
Signed-off-by: Holger Schurig <holgerschurig@gmail.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Note: this is the same as 206a81c18401c0cde6e579164f752c4b147324ce in
linux-git.
The lzo decompressor can, if given some really crazy data, possibly
overrun some variable types. Modify the checking logic to properly
detect overruns before they happen.
Reported-by: "Don A. Bailey" <donb@securitymouse.com>
Tested-by: "Don A. Bailey" <donb@securitymouse.com>
Signed-off-by: Holger Schurig <holgerschurig@gmail.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Image renderer may not be particularly useful without framebuffer
support, but technically it does not depend on VIDEO. Fixes:
warning: (CMD_SPLASH) selects IMAGE_RENDERER which has unmet direct dependencies (VIDEO)
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Enumeration values will only be shown if there are at least two of them.
With only one enumeration, it was just repeating what was previously printed
anyway.
Signed-off-by: Holger Schurig <holgerschurig@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This most likely doesn't fix any real bugs, but it's the
right thing to do and reduces the noise level with static
checkers.
Signed-off-by: Lucas Stach <dev@lynxeye.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This adds a convenience function to register a MAC address device
parameter. The only current user is converted to use it.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
the splash command silently fails when no renderer is found for
an image type. Print an error message in this case.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
MTD internal API presently uses 32-bit values to represent device
size. This patch updates them to 64-bits but leaves the external API
unchanged.
In general, changing from 32-bit to 64-bit values cause little
or no changes to the majority of the code with the following
exceptions:
- printk message formats;
- division and modulus of 64-bit values (mtd_div_by_wb,
mtd_div_by_eb may be used in some of such cases).
Was tested on phyFLEX i.MX6.
Signed-off-by: Dmitry Lavnikevich <d.lavnikevich@sam-solutions.com>
Signed-off-by: Grigory Milev <g.milev@sam-solutions.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Similar to mount(8) the barebox command mount now supports passing a string
to the file system driver via -o.
This is used in the next commit to let the user specify port numbers for
nfs mounts.
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
We assume it to be non NULL in other places, so
we are in much greater trouble if it actually is.
Signed-off-by: Lucas Stach <dev@lynxeye.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
free() already checks the pointer to be non
NULL. No need to do it again.
Signed-off-by: Lucas Stach <dev@lynxeye.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
A compile error appears in libubigen on PXA architecture, because of a
division of an long long by a int :
/home/rj/mio_linux/barebox/lib/libubigen.c:105: undefined reference to
`__aeabi_ldivmod' arm-linux-gnueabi-ld: BFD (GNU Binutils for Debian)
2.20.1.20100303 assertion fail ../../bfd/elf32-arm.c:12497
Fix it by using div_u64 instead.
Signed-off-by: Robert Jarzmik <robert.jarzmik@free.fr>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
ubiformat needs the subpagesize to work correctly. The kernel uses
sysfs to pass the subpagesize, but in barebox we have the possibility
to extend struct mtd_info_user. Add a corresponding field and use it
in ubiformat.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
"%u" in format string requires a unsigned integer.
Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
A lot of files rely on include/driver.h including include/of.h (and
this including include/errno.h. include the files explicitly so we can
eventually get rid of including of.h from driver.h
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Often small files are used to store the value od a variable. This
adds a function to easily read such a variable.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Without it, when copying a smaller file over a larger file the
resulting file still has the remaining space from the larger file.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Using tftp command does not work proper when files
have FILESIZE_MAX, as copy_file and show_progress
can not handle it. Check the file size for FILESIZE_MAX
and handle it as file size = 0.
Signed-off-by: Teresa Gámez <t.gamez@phytec.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
take from linux next-20130227
same version as v3.11
before
-rwxr-xr-x 1 root root 123001 Feb 28 01:04 build/highbank/arch/arm/pbl/zbarebox.bin
after
-rwxr-xr-x 1 root root 122226 Feb 28 01:02 build/highbank/arch/arm/pbl/zbarebox.bin
smaller and faster
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
With this all code uses barebox_get_model() and no longer
a compile time generated string.
Also this renames barebox_boardinfo() to barebox_get_model()
since we are going to add the corresponding _set_ function
and 'model' corresponds to the devicetree notion.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This patch provides a global cleanup barebox Kconfig files. This includes
replacing spaces to tabs, formatting in accordance format.
No functional changes.
Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This is a fresh UBI import from Linux v3.10
This is done mainly to get fastmap support.
This was tested with the i.MX nand driver, the MXS nand driver and
on CFI NOR flash.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
MXS specific devices have some common infrastructure in the kernel
known as STMP devices. We have the same in barebox, but with a
mxs_ prefix instead of a stmp_ prefix. As some STMP devices are
also found on i.MX6 move the common infrastructure out of MXS
specific files and use the stmp_ prefix.
This is done in preparation for i.MX6 NAND support.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This patch adds support for extracting LZ4-compressed kernel images,
as well as LZ4-compressed ramdisk images in the kernel boot process.
This depends on the patch below
decompressor: Add LZ4 decompressor module
Signed-off-by: Kyungsik Lee <kyungsik.lee@lge.com>
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This patch adds support for LZ4 decompression in the Linux Kernel.
LZ4 Decompression APIs for kernel are based on LZ4 implementation
by Yann Collet.
LZ4 homepage : http://fastcompression.blogspot.com/p/lz4.html
LZ4 source repository : http://code.google.com/p/lz4/
Signed-off-by: Kyungsik Lee <kyungsik.lee@lge.com>
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
When using devicetrees the boardinfo (or model) can be obtained
from the devicetree. Add a function to get the boardinfo so that
we have a chance to add information from the devicetree.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
We recently gained helper functions for different types of
device parameters. One thing missing was a helper for an
enum type parameter. This patch adds this.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This adds convenience functions for directly registering integers
and bools as device parameter. This way driver no longer have to
fiddle with string handling. The format used to print the parameter
is passed to the functions to be able to print parameters in a
flexible way.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Let __dev_add_param take a previously allocated struct param_d. This
helps when later other users wish to embed a struct param_d in a bigger
struct.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
The kernel nowadays has mtd_read/write and other functions. In
barebox we also have these functions, but with a different prototype,
namely they correspond to the libmtd userspace functions. Rename
these functions to libmtd_* to avoid name clashes with future mtd
updates.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Change getopt optstring parameter type to const char *.
Also change type to const char * of tmp variable which
pointed to optstring. This will only handle readonly.
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Here's the error message:
LD arch/mips/pbl/zbarebox
pbl/built-in-pbl.o: In function `decompress_unlzo':
/home/antony/barebox.git.rebased.isp/pbl/decomp.c:35: undefined reference to `free'
pbl/built-in-pbl.o: In function `pbl_barebox_uncompress':
(.text.pbl_barebox_uncompress+0x6d0): relocation truncated to fit: R_MIPS_26 against `free'
pbl/built-in-pbl.o: In function `pbl_barebox_uncompress':
(.text.pbl_barebox_uncompress+0x6e0): undefined reference to `free'
pbl/built-in-pbl.o: In function `pbl_barebox_uncompress':
(.text.pbl_barebox_uncompress+0x6e0): relocation truncated to fit: R_MIPS_26 against `free'
make[1]: *** [arch/mips/pbl/zbarebox] Error 1
make: *** [zbarebox.bin] Error 2
Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This will allow to have a generic code to create different bootstrap
As example
Barebox as TI Xloader
Barebox as AT91 Bootstrap
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This command works like the corresponding Unix shell command and
is used for adding, multiplying and much more.
Signed-off-by: Jan Luebbe <jlu@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Based on mtd-utils and stripped down to needed functionality and
reworked to barebox interfaces.
Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Imported from mtd-utils and stripped down to needed functionality.
Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Imported from mtd-utils and stripped down to needed functionality.
Add prefix to functions so we have a clean namespace.
Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Copy over the latest version from u-boot which handles bigger sizes now
and does arithmetic with shifts instead of divisions.
Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Since this is the 'official' notation, we should support it.
Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>