summaryrefslogtreecommitdiffstats
path: root/lib
Commit message (Collapse)AuthorAgeFilesLines
* parameter: strip leading and trailing whitespacesMarco Felsch2019-11-041-1/+4
| | | | | | | | | | | | | | | | | My initial bug was the following: I set the global.boot.default="boot1 boot2 " and executed the 'boot' command. If both targets are not bootable barebox starts to execute the boot scripts found under /env/boot. This is because of the command/boot.c implementation and the leading whitespace. Without the whitespace only the two desired boot targets are tried. IMHO leading and trailing whitespaces are error-prone in many cases. If someone wants to concatenate strings he/she should add spaces on purpose. So I fixed the bug above globally by always stripping leading and trailing whitespaces. Signed-off-by: Marco Felsch <m.felsch@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* libfile: copy_file: fix error handlingRobert Karszniewicz2019-10-231-5/+12
| | | | | | | | Before this, ret was falsely polluted, which caused a misleading error message if the function bailed out at a later point. Signed-off-by: Robert Karszniewicz <r.karszniewicz@phytec.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* readline: make ctrl-u to work like linux consoleDU HUANPENG2019-10-181-0/+8
| | | | | | | | | currtly, the ctrl-u discards the whole line, in most linux boxes, ctrl-u just erase characters before cursor to the begginning of the line. this patch make ctrl-u to do this. Signed-off-by: DU HUANPENG <u74147@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: ubsan: ignore shifting one into sign bitAhmad Fatoum2019-10-141-0/+20
| | | | | | | | | | | | | The __ubsan_handle_shift_out_of_bounds handler would be called for code shifting a one into the sign bit like (1 << 31), which is all too common in barebox. It's technically UB, but it's so prevalent that it's highly unlikely to be treated by a compiler as anything else than the standard-compliant (1U << 31). Check for this case here and ignore it selectively. Signed-off-by: Ahmad Fatoum <ahmad@a3f.at> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* trivial: fix typo lenght -> lengthUwe Kleine-König2019-10-141-8/+8
| | | | | | | | | | | | Generated by perl -p -i -e 's/lenghte?/length/' arch/arm/boards/chumby_falconwing/falconwing.c arch/arm/mach-samsung/mem-s3c64xx.c fs/ext4/ext_common.h lib/gui/lodepng.c include/jtag.h There is another instance in dts/Bindings/usb/s3c2410-usb.txt, this is fixed in Linux v5.3-rc1 so supposed to be fixed soon in barebox, too. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Convert latin1 files to utf-8Uwe Kleine-König2019-10-143-384/+384
| | | | | | | | | | | The source files are parsed by $(make docs). Currently this is done using python2 (actually 'python' which is still python2 on most machines). When using python3 however (which has a stricter encoding handling) it is easier if all input is in utf-8 encoding. So convert the few remaining latin1 encoded files to utf-8. This only affects code comments. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
* libfile: Document that read_file() returns a terminated bufferSascha Hauer2019-10-141-1/+3
| | | | | | | | read_file() and read_file_2() return a '\0' terminated buffer to make sure the buffer is usable as a string. Other code like read_file_line() depends on this behaviour, so document it explicitly. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/qemu'Sascha Hauer2019-09-129-0/+26
|\
| * Compile libfdt for bareboxSascha Hauer2019-08-199-0/+27
| | | | | | | | | | | | | | | | | | libfdt can be useful for very early device tree parsing, so compile it for barobox aswell. This is done the same way as done in the Kernel: we put C files with the same name as in libfdt into lib/ and just include the libfdt files from there. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | Merge branch 'for-next/misc'Sascha Hauer2019-09-122-10/+12
|\ \
| * | libfile: fix typosMichael Tretter2019-09-061-2/+2
| | | | | | | | | | | | | | | Signed-off-by: Michael Tretter <m.tretter@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * | libfile: have write_full return a descriptive error codeAhmad Fatoum2019-08-301-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | So far (p|)write_full has been returning -1 on error. Some callers of write_full like imx_bbu_write_device print out the function's return value on error, effectively rendering every printed error message to be due to EPERM. On the other hand, some callers like do_memcpy, use it correctly and use errno. Sidestep the issue by having the function return -errno on errors as well. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * | gui: png_lode: fix freeing of uninitialized pointerAhmad Fatoum2019-08-301-6/+7
| |/ | | | | | | | | | | | | | | | | If either calloc or png_uncompress_init fails, free(png) will free the uninitialized png pointer. Avoid this and while at it postpone the img allocation till after the early exit. Signed-off-by: Ahmad Fatoum <ahmad@a3f.at> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | common: add generic CONFIG_UBSAN plumbingAhmad Fatoum2019-09-094-0/+569
| | | | | | | | | | | | | | | | | | | | | | | | | | | | -fsanitize=undefined allows compile-time instrumentation of code to detect some classes of runtime undefined behavior. In preparation for allowing arches to provide infrastructure in support of this feature, add some generic UBSAN options and associated plumbing. These are only shown in the debug menu when the arch selects the appropriate symbol. The option is named equally to their Linux counterparts. Signed-off-by: Ahmad Fatoum <ahmad@a3f.at> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | lib: add HAVE_EFFICIENT_UNALIGNED_ACCESS Kconfig optionAhmad Fatoum2019-08-301-0/+3
| | | | | | | | | | | | | | | | | | | | The LZO, LZ4, DEFLATE implementations in lib/ already check against CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS. Define this symbol defaulting to 0. This makes porting Kconfig symbols depending on it easier and in future, we could select it from different arches. Signed-off-by: Ahmad Fatoum <ahmad@a3f.at> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | Kconfig: create Kconfig symbol for ARCH_HAS_DATA_ABORT_MASKAhmad Fatoum2019-08-301-0/+3
| | | | | | | | | | | | | | | | Other arch-specific features are exposed in Kconfig too, so do here likewise. Signed-off-by: Ahmad Fatoum <ahmad@a3f.at> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | Kconfig: create Kconfig symbol for ARCH_HAS_STACK_DUMPAhmad Fatoum2019-08-301-0/+3
|/ | | | | | | | Other arch-specific features are exposed in Kconfig too, so do here likewise. Signed-off-by: Ahmad Fatoum <ahmad@a3f.at> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* lib: Add missing arguments to memcpy_parse_options()Andrey Smirnov2019-07-091-3/+4
| | | | | | | | | | | | | Memcpy use-case differs from that of memcmp in default access type and destination file mode. This was missed in original commit that introduced memcpy_parse_options(). Add said parameters to memcpy_parse_options(), so the can be correctly specified depending on the use-case. Fixes: ddf4cca339 ("commands: Introduce memcpy_parse_options()") Reported-by: Peter Mamonov <pmamonov@gmail.com> Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/misc'Sascha Hauer2019-06-113-20/+61
|\
| * commands: Introduce memcpy_parse_options()Andrey Smirnov2019-05-281-0/+49
| | | | | | | | | | | | | | | | | | Both memcpy and memcmp have identical options, so in order to share code between them, introduce memcpy_parse_options() and change both tools to use it. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * libbb: Drop simple_itoa()Andrey Smirnov2019-05-281-14/+0
| | | | | | | | | | | | | | | | | | Hush is the only one user of simple_itoa() and the code there can be re-implemented using snprintf(). Change the code to get rid of simple_itoa(). Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * libfile: Do not return 0 from write_full()Andrey Smirnov2019-05-281-2/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | None of the callers of write_full() expect a zero return value. Given how the documentation explicitly states that either all of the buffer is going to be written out or an error generated, treat 0 retrun from write() as a error, set errno to ENOSPC and return -1. Same logic applies to pwrite_full() as well, so make the change there while at it. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * libfile: Simplify read_full()Andrey Smirnov2019-05-281-4/+2
| | | | | | | | | | | | | | | | We can figure out the amount of written data by substracting 'insize' from 'size' so there is no need to keep a separate counter for that. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | lib: select BASE64 if BLOBGEN is selectedRouven Czerwinski2019-05-241-0/+1
|/ | | | | | | | Blobgen requires the BASE64 libraries, select them to provide them if BLOBGEN is selected. Signed-off-by: Rouven Czerwinski <r.czerwinski@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* lib: add blobgen frameworkSteffen Trumtrar2019-04-123-0/+227
| | | | | | | | | | | This adds a framework for en/decrypting data blobs. Some SoCs have support for hardware crypto engines that can en/decrypt using keys that a tied to the SoC and are visible for the crypto hardware only. With this patch it's possible to encrypt confidential data using these keys and to decrypt it later for usage. Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* lib: add base64 helpersSteffen Trumtrar2019-04-123-0/+158
| | | | | | | Import the busybox-1.23.1 uuencode/base64 helper functions. Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/misc'Sascha Hauer2019-04-092-17/+11
|\
| * treewide: surround Kconfig file paths with double quotesMasahiro Yamada2019-03-211-5/+5
| | | | | | | | | | | | | | | | | | Based on Linux commit 8636a1f9677db4f883f29a072f401303acfc2edd This will be needed when you sync Kconfig with Linux 5.0 or later. Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * libfile: Make use of write_full() in copy_file()Andrey Smirnov2019-03-131-12/+6
| | | | | | | | | | | | | | | | Change copy_file() to rely on write_full() instead of re-implementing it locally. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | Merge branch 'for-next/lseek'Sascha Hauer2019-04-081-14/+12
|\ \
| * | libfile: Make failure path of open_and_lseek() consistentAndrey Smirnov2019-03-111-14/+12
| |/ | | | | | | | | | | | | | | | | | | Change the code of open_and_lseek() to make sure that opened file is closed in every failure path as well. While at it make sure we don't mix returning function return code and returning errno by opting to always return the former. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* / Add Freescale QUICC Engine firmware supportSascha Hauer2019-03-133-0/+69
|/ | | | | | | The Freescale QUICC Engine found on Layerscape SoCs needs firmware loaded. This adds support for loading such a firmware. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/spd'Sascha Hauer2019-03-073-5/+5
|\
| * crc: import crc_itu_t() from kernelSascha Hauer2019-03-043-5/+5
| | | | | | | | | | | | | | | | Our cyc_crc16() function is the same function as crc_itu_t() in the Linux kernel. Import and use crc_itu_t() from the Kernel for consistency. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | lib: Port basic Linux kernel NLS functionsAndrey Smirnov2019-02-223-0/+135
|/ | | | | | | | | Port basic Linux kernel NLS functions: utf8_to_utf32() and utf8s_to_utf16s() in order to support porting kernel code that uses them. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/misc'Sascha Hauer2019-02-134-75/+57
|\
| * readline: add ctrl-u (unix-line-discard)Robert Karszniewicz2019-02-051-0/+1
| | | | | | | | | | Signed-off-by: Robert Karszniewicz <r.karszniewicz@phytec.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * lib: image-sparse: Mark sparse_seek() as staticAndrey Smirnov2019-01-281-1/+1
| | | | | | | | | | | | | | Mark sparse_seek() as static to avoid -Wmissing-prototypes warnings Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * unlink_recursive: Drop struct dataAndrey Smirnov2019-01-241-20/+7
| | | | | | | | | | | | | | | | Drop struct data which doesn't seem to serve any purpose in the code and looks like a leftover. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * lib: strtox: Use plumbing from kstrtox.cAndrey Smirnov2019-01-211-54/+48
| | | | | | | | | | | | | | | | | | Sync up implemenations of simple_str*() functions with their kernel counterparts in order to convert the code to use plumbing from kstrtox.c Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | libfile: Fix incorrect lseek check in open_and_lseek()Andrey Smirnov2019-02-061-2/+1
| | | | | | | | | | | | | | | | | | | | | | We can't use "int" to capture output of lseek which is "loff_t", since former does not cover all of the range of the values of the latter and any pos >= 0xffff_ffff will result in a false positive "failure". To avoid that replace the check to check that new position matches what was requested. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | commands: Move mem_parse_options() to lib/misc.cAndrey Smirnov2019-01-291-0/+42
|/ | | | | | | | | | | | | | | | As a first step of de-cluttering /dev/mem related code, move mem_parse_options() out of commands/mem.c into lib/misc.c where it seem to fit better. With this change we no longer explicitly turn this code off using CONFIG_COMPILE_MEMORY and instead rely on LTO to get rid of it when it's not being used. While at it, also fix return value by replacing COMMAND_ERROR_USAGE with -EINVAL. All of the callers of mem_parse_options() expect negative error code as a sign of failure and COMMAND_ERROR_USAGE is not negative. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/misc'Sascha Hauer2019-01-155-2/+81
|\
| * Add generic implementation for muldi3Martin Hofmann2019-01-073-0/+77
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Since version v2018.08.0 some shared copies of gcc routines got added to barebox so that archs don't need to have their own copy inside their lib. The arch I am working on atm also needs support for muldi3 which is not present as a generic version right now. This patch adds the generic version from latest linux v4.20 to barebox and lets the archs select it in their Kconfig so they don't need to provide it themself. Signed-off-by: Martin Hofmann <martin.hofmann_at_mni.thm.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * 2d-primitives: fix no previous prototype warningSam Ravnborg2019-01-031-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fix the following warnings: lib/gui/2d-primitives.c:88:6: warning: no previous prototype for ‘gu_draw_line’ [-Wmissing-prototypes] void gu_draw_line(struct screen *sc, ^~~~~~~~~~~~ lib/gui/2d-primitives.c:174:6: warning: no previous prototype for ‘gu_draw_circle’ [-Wmissing-prototypes] void gu_draw_circle(struct screen *sc, ^~~~~~~~~~~~~~ Signed-off-by: Sam Ravnborg <sam@ravnborg.org> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * lib/parameter: Fix typecases to match corresponding PARAM_TYPE_*Andrey Smirnov2018-12-101-2/+2
| | | | | | | | | | | | | | | | | | This change should be a no-op in terms of behavior, but it makes code less confusing when PARAM_TYPE_* matches the type used in the type cast. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | recursive_action: add ACTION_SORT flagBaeuerle, Florian2019-01-082-10/+64
|/ | | | | | | | | | | Add a flag to sort directory entries before recursing into them. Since this part of lib/ is used inside barebox as well as in scripts/bareboxenv.c, we cannot easily use stringlists from lib/, which would have made the code a bit nicer. Signed-off-by: Florian Bäuerle <florian.baeuerle@allegion.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/missing-prototypes'Sascha Hauer2018-12-072-41/+29
|\
| * gui: lodepng: Avoid missing prototypes warningSascha Hauer2018-11-122-41/+29
| | | | | | | | | | | | | | | | - move prototypes to header file - remove some unused functions - make locally used functions static. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | lib: bootstrap: fix instance of possibly mismatched pointer sizesAhmad Fatoum2018-12-051-1/+1
| | | | | | | | | | | | | | | | len was int but &len is passed to read_file(..., size_t *size), Fix this. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>