summaryrefslogtreecommitdiffstats
path: root/lib
Commit message (Collapse)AuthorAgeFilesLines
* 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>
* | getopt: Add pr_fmtSascha Hauer2018-11-271-0/+1
| | | | | | | | | | | | To give the debug output more context. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | lib: lodepng: remove useless testOleksij Rempel2018-11-211-7/+1
|/ | | | | | | | | | | | | | Either the condition 'code_ll==(unsigned int)(-1)' is redundant or the array 'LENGTHBASE[29]' is accessed at index 4294967038, which is out of bounds. On other hand this condition is tested within other scope: "if(code_ll >= FIRST_LENGTH_CODE_INDEX && code_ll <= LAST_LENGTH_CODE_INDEX)" with is already limited to (code_ll >= 257 && code_ll <= 285), so it can't be -1 any way. Signed-off-by: Oleksij Rempel <linux@rempel-privat.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/net-switch-mv88e6xxx'Sascha Hauer2018-11-091-14/+2
|\
| * linux: string: Port kbasename()Andrey Smirnov2018-10-181-14/+2
| | | | | | | | | | | | | | | | Port kbasename() from Linux and use it to implement basename() we already have. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | Merge branch 'for-next/malloc'Sascha Hauer2018-11-091-1/+5
|\ \
| * | libfile: Error out if out of memory in read_file_2()Andrey Smirnov2018-10-161-1/+5
| |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | All other error cases in read_file_2() are handled gracefully, so there shouldn't be any reason not do so for the case of trying to allocate too much memory. This error path can be easily triggered with: barebox_update file-bigger-than-availible-ram.img Currently this would result in a crash which is not really desirable from user experience. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | Merge branch 'for-next/imx'Sascha Hauer2018-11-093-0/+90
|\ \
| * | lib: Port CRC8 implementation from Linux kernelAndrey Smirnov2018-11-063-0/+90
| |/ | | | | | | | | Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* / lib: Port kstrtox.c from Linux kernelAndrey Smirnov2018-10-293-0/+376
|/ | | | | Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/ubifs'Sascha Hauer2018-10-091-0/+15
|\
| * vsprintf: implement %pVSascha Hauer2018-10-081-0/+15
| | | | | | | | | | | | | | %pV allows to pass in a struct va_format as a pointer. UBIFS uses this for its logging functions, but it may be useful in other places aswell. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | kfifo: roundup fifo size to next power of twoSascha Hauer2018-09-211-0/+10
|/ | | | | | | | | | | Comments in include/kfifo.h state that the FIFO size will be rounded up to the next power of two, but so far we haven't actually done this, probably because we didn't have roundup_pow_of_two() back then when kfifo support was added. Fix that now and do what the comments state. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/misc'Sascha Hauer2018-09-111-2/+4
|\
| * ratp: fix sending data that won't fit in a single RATP packetAleksander Morgado2018-08-311-2/+4
| | | | | | | | | | | | | | | | We need to advance the input buffer used to create messages when the data doesn't fit in a single RATP packet. Signed-off-by: Aleksander Morgado <aleksander@aleksander.es> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | libfile: Introduce pwrite_full()Andrey Smirnov2018-08-311-0/+24
|/ | | | | | | | | | Analogous to what we have with write()/write_full(), introduce a lightweight wrapper around pwrite() that guarantees the either all data is going to be written or a negative error code would be returned. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* libfile: open_and_lseek: enlarge small files enough to make lseek possibleUwe Kleine-König2018-08-101-0/+18
| | | | | | | | | | | | | | | | | This makes the following do the expected thing: barebox@barebox sandbox:/ ls -l lala -rwxrwxrwx 4 lala barebox@barebox sandbox:/ mw -d lala 72 0 Without this patch mw dies with lseek: Invalid argument memset, memcpy and probably others benefit in the same way. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* libfile: open_and_lseek: don't imply O_RDONLYUwe Kleine-König2018-08-101-1/+1
| | | | | | | | | | There are several users that pass O_RDWR or O_WRONLY in mode to open_and_lseek() and use the resulting file descriptor for writing. This is no real issue becauce O_RDONLY is 0 and so can be dropped without any side effects. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* cmdlinepart: Allow empty stringSascha Hauer2018-07-091-0/+3
| | | | | | | | | | | | Currently when cmdlinepart_do_parse() is called with an empty partitions string then an unnamed partition with size 0 is created. This is wrong of course and instead no partition should be created. With this barebox no longer crashes while booting when all partitions are deleted on the commandline using "nand0.partitions=" Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* lib: Add shared copies of some GCC library routinesAntony Pavlov2018-06-295-0/+151
| | | | | | | | | | | | | | | | | | | This commit is based on these linux kernel commits: | commit b35cd9884fa5d81c9d5e7f57c9d03264ae2bd835 | Author: Palmer Dabbelt <palmer@dabbelt.com> | Date: Tue May 23 10:28:26 2017 -0700 | | lib: Add shared copies of some GCC library routines | | commit e3d5980568fdf83c15a5a3c8ddca1590551ab7a2 | Author: Matt Redfearn <matt.redfearn@mips.com> | Date: Wed Apr 11 08:50:17 2018 +0100 | | lib: Rename compiler intrinsic selects to GENERIC_LIB_* Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/mvebu'Sascha Hauer2018-06-111-0/+33
|\
| * libfile: implement new helper write_file_flash()Uwe Kleine-König2018-06-081-0/+33
| | | | | | | | | | | | | | | | Compared to write_file() this new function also calls erase() to be suitable for flash devices. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | ARM: lib64: Make string functions aware of MMU configurationAndrey Smirnov2018-06-111-6/+12
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Optimized version of memset() in memset.S if called as: memset(foo, 0, size) will try to explicitly zero out data cache with: dc zva, dst which will result in Alignement Exception (DABT) if MMU is not enabled. For more info see: - C4.4.8 "DC ZVA, Data Cache Zero by VA" - D5.2.8 "The effects of disabling a stage of address translation" in "ARM Architecture Reference Manual. ARMv8, for ARMv8-A architecture profile" In similar vein, using optimized version of memcpy() could lead to a unaligned 16-byte write (using 'stp'), which is not allowed for Device-nGnRnE type of memory (see D5.2.8) and would liead to Alignement Exception. To fix both problems expose non-optimized and optimzied versions of the function and created a wrapper to dispatch the call to either one based on if MMU is enabled or not. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* console: Introduce console_drain()Andrey Smirnov2018-04-171-25/+5
| | | | | | | | | | | | | | Generalize high baud rate UART polling code found in lib/xmodem.c and expose it as a generic function in console API. The usecase for this -- besides X/Y-mode data transfers where the code originated -- is command/reply type of serial exchages at high baud rates (~1Mbaud) with payloads exceeding inernal UART FIFOs in size. Such interactions are not uncommon in serdev device and this patch is done in preparation for serdev support code that will follow. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/misc'Sascha Hauer2018-04-063-0/+133
|\
| * lib: Port CRC-CCITT functions from Linux kernelAndrey Smirnov2018-04-033-0/+133
| | | | | | | | | | | | | | | | Port CRC-CCITT implemenation in order to support porting MFD driver for RAVE SP. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | glob: do not unnecessarily opendir() a directorySascha Hauer2018-04-061-7/+8
|/ | | | | | | opendir() can trigger automounts, so do not use it when the pattern we examine doesn't have any wildcards. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/ratp'Sascha Hauer2018-03-052-2/+2
|\
| * ratp: allow building without full console supportAleksander Morgado2018-03-012-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | Make CONFIG_RATP a selectable config option, so that the user can enable RATP support without explicitly needing to enable the full console support over RATP (e.g. only for RATP FS or built-in command support). The full console can still be explicitly enabled with CONFIG_CONSOLE_RATP. Signed-off-by: Aleksander Morgado <aleksander@aleksander.es> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | lib: add weak clz/ctz functionsLucas Stach2018-02-212-0/+60
|/ | | | | | | | | | | | This is a copy of the Linux kernel implementation. This adds weak functions for the clz and ctz gcc builtins. Normally GCC will map those builtins to CPU instructions directly, but for CPUs where those are unavailable, we need to provide a fallback implementation. Fixes build of the zlib decompressor on ARMv4 CPUs. Signed-off-by: Lucas Stach <l.stach@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/zstd'Sascha Hauer2018-02-0816-0/+7296
|\
| * lib: Add zstd decompression modulePhilipp Zabel2018-02-0515-0/+6792
| | | | | | | | | | | | | | Based on kernel commit 73f3d1b48f50 ("lib: Add zstd modules"). Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * lib: Add xxhash modulePhilipp Zabel2018-02-053-0/+504
| | | | | | | | | | | | | | Based on kernel commit 5d2405227a9e ("lib: Add xxhash module"). Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>