summaryrefslogtreecommitdiffstats
path: root/lib
Commit message (Collapse)AuthorAgeFilesLines
* readline_simple: Fix compiler warningSascha Hauer2021-05-121-1/+1
| | | | | | | char can be an unsigned type. To test the getchar() return value against negative values we have to use a signed type. Use int instead. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/misc'Sascha Hauer2021-03-232-2/+23
|\
| * param: drop unused left-over struct membersAhmad Fatoum2021-03-161-2/+0
| | | | | | | | | | | | | | | | Both seem to be a copy-paste left-over from the int param. They are unused anywhere, so it's safe to just drop them. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * stringlist: Add adding sort uniqSascha Hauer2021-03-161-0/+23
| | | | | | | | | | | | | | Function to add an entry sorted to a string list only when it doesn't exist. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | Merge branch 'for-next/bthreads'Sascha Hauer2021-03-231-2/+2
|\ \
| * | common: poller: replace explicit calls to poller_call() with resched()Ahmad Fatoum2021-03-171-2/+2
| |/ | | | | | | | | | | | | | | | | | | | | We won't replace pollers with bthreads completely over night. To make migration easier, replace explicit calls to poller_call with a new resched() function. This can be made to call bthread_reschedule() in future and eventually replaced with bthread_reschedule() once pollers are removed. Signed-off-by: Ahmad Fatoum <ahmad@a3f.at> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* / glob: use empty globfree when compiling without CONFIG_GLOBAhmad Fatoum2021-03-221-12/+12
|/ | | | | | | | | | | | | | | | We already return an error code unconditionally when building with !CONFIG_GLOB. We need to do the same for globfree. Otherwise, we run risk of corrupting memory. This issue exists since the code was first added, but it became more acute with 90cde3b9ff46 ("startup: Execute init scripts in alphabetical order"), which added a globfree into the shell init. Configuration without CONFIG_GLOB would from then on experience memory corruption during startup. Reported-by: Antony Pavlov <antonynpavlov@gmail.com> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/ext4'Sascha Hauer2021-02-222-10/+9
|\
| * copy_file: fix progress bar for files larger than 2GAhmad Fatoum2021-02-192-10/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | Files larger than 2G cause the benign bug, that the progress bar is no longer accurate. Use loff_t to fix this. Note that printed % HASHES_PER_LINE in show_progress implies a 64-bit division. A previous commit changed the constant divisor to a power of two, so a division shouldn't be generated. The original multiplication and modulo operations are left as is for clarity. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * show_progress: change HASHES_PER_LINE from 65 to 64 to avoid divisionAhmad Fatoum2021-02-181-1/+1
| | | | | | | | | | | | | | | | | | Decreasing the progress bar length by one won't change visuals much, but will allow the compiler to optimize a multiplication and a modulo into bitwise operations. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | lib: remove duplicate __div64_32Ahmad Fatoum2021-02-193-56/+1
| | | | | | | | | | | | | | | | | | | | | | | | f933da28cf3f ("include: <linux/math64.h>: sync with upstream") imported the div64 code from Linux, which also defines __div64_32 as a weak symbol. __div64_32 was defined before in a separate file though and used from do_div. Remove this duplication. No functional change. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | treewide: include <linux/math64.h> wrapper instead of <asm-generic/div64.h>Ahmad Fatoum2021-02-193-3/+3
|/ | | | | | | | | | | <asm-generic/div64.h> isn't meant for direct usage as <asm/div64.h> may override this on a per-architecture basis. We don't do that currently, but in the future we might. Include the <linux/math64.h> instead. No functional change. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/misc'Sascha Hauer2021-01-193-0/+237
|\
| * include: <linux/math64.h>: sync with upstreamAhmad Fatoum2021-01-073-0/+237
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The header implements definitions for the 64-bit division helpers on 64-bit builds only. For 32-bit builds, it can only provide prototypes and the actual implementation will need to come from elsewhere. We didn't have any out-of-line definitions in barebox with the result that functions like div_s64_rem() were so far only usable in 64-bit barebox builds. On 32-bit builds, they would result in a linker error. Import the Linux v5.11-rc1 generic out-of-line 64-bit math on 32-bit implementation to fix this. While at it, synchronize the header to reduce diff to upstream. Signed-off-by: Ahmad Fatoum <ahmad@a3f.at> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | image-sparse: change chunk_data_sz to u64Steffen Trumtrar2021-01-131-2/+3
| | | | | | | | | | | | | | | | | | | | | | chunk_data_sz is set to the result of a __le32 * __le32 multiplication: chunk_data_sz = si->sparse.blk_sz * si->chunk.chunk_sz; This will overflow. Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | image-sparse: change retlen to size_tSteffen Trumtrar2021-01-131-1/+1
|/ | | | | | | | retlen can potentially overflow. Also, write_full() in fastboot_handle_sparse() expects size_t anyway. Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* commands: implement and use parse_assignment helperAhmad Fatoum2020-11-271-0/+11
| | | | | | | | | | | | We have the split by '=' snippet at multiple locations that parse key=value pairs. Consolidate them to a single location. This makes code a bit easier to read at the cost of an extra 8 bytes (LZO-compressed THUMB2 barebox, static inline version is bigger). No functional change. Signed-off-by: Ahmad Fatoum <ahmad@a3f.at> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/sandbox'Sascha Hauer2020-11-101-20/+0
|\
| * Revert "common: ubsan: ignore shifting one into sign bit"Ahmad Fatoum2020-10-191-20/+0
| | | | | | | | | | | | | | | | | | | | | | | | With the previous commit, we now explicitly tell GCC not to optimize constructs like (1 << 31) under assumption that they are undefined anyway. GCC >= 8.0 -fsanitize=undefined should now not warn any longer about (1 << 31) instances, so remove our work around. This reverts commit 55397b9ebe3a21a3aeb6a98131c0991bff0f7123. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | Merge branch 'for-next/mtd-nand'Sascha Hauer2020-11-101-0/+34
|\ \
| * | lib: Add match_string()Sascha Hauer2020-11-091-0/+34
| | | | | | | | | | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | | Merge branch 'for-next/misc'Sascha Hauer2020-11-101-0/+3
|\ \ \
| * | | ARM: mmu64: allow to disable null pointer trap on zero pageMichael Tretter2020-10-221-0/+3
| | |/ | |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Barebox uses the zero page to trap NULL pointer dereferences. However, if the SDRAM starts at address 0x0, this makes the first page of the SDRAM inaccessible and makes it impossible to load images to offset 0x0 in the SDRAM. Trapping NULL pointer dereferences on such systems is still desirable. Therefore, add a function to disable the traps if accessing the zero page is necessary and to re-enable the traps after the access is done. The zero_page_memcpy function simplifies copying to the SDRAM, because this is the most common required functionality, but memtest also accesses the zero page and does not use memcpy. Signed-off-by: Michael Tretter <m.tretter@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | | Merge branch 'for-next/imd-checksum'Sascha Hauer2020-11-102-5/+11
|\ \ \ | |/ / |/| |
| * | bootstrap_read_disk(): optionally inform the caller of the buffer sizeUlrich Ölmann2020-06-221-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | The size of the buffer allocated in the function is needed if it shall be inspected more closely later. Therefore optionally return it via a new pointer argument. Signed-off-by: Ulrich Ölmann <u.oelmann@pengutronix.de>
| * | bootstrap_read_devfs(): optionally inform the caller of the buffer sizeUlrich Ölmann2020-06-221-4/+7
| | | | | | | | | | | | | | | | | | | | | | | | The size of the buffer allocated in the function is needed if it shall be inspected more closely later. Therefore optionally return it via a new pointer argument. Signed-off-by: Ulrich Ölmann <u.oelmann@pengutronix.de>
* | | Merge branch 'for-next/percent_pe' into masterSascha Hauer2020-10-142-26/+45
|\ \ \
| * | | treewide: replace strerror(-PTR_ERR(errno)) with %pe format specifierAhmad Fatoum2020-09-291-4/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Using %pe instead of PTR_ERR has the benefit of being less verbose and less error-prone (no negation necessary) while potentially reducing code size. Make use of it. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * | | vsprintf: retire strerrorp in favor of %peAhmad Fatoum2020-09-291-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | strerrorp() is only used along with printf. We now have a format specifier for printing error pointers directly, so use that and remove strerrorp. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * | | vsprintf: add %pe format specifier for printing symbolic error namesAhmad Fatoum2020-09-291-12/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Starting with v5.5, Linux has a format specifier for printing error pointers. We have had strerror in barebox before that, but lets wire it into vsprintf with the same format specifier that Linux now uses. This yields less verbose call sites and makes Linux drivers more portable to barebox in future. This also has the potential to reduce code size as the previously "inlined" strerror at callsites can now be replaced by a single vsprintf. Cc: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * | | vsprintf: constify pointers where appropriateAhmad Fatoum2020-09-291-10/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | No functional change, but makes code bit more future proof when it is extended. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | | | Merge branch 'for-next/misc' into masterSascha Hauer2020-10-142-1/+14
|\ \ \ \ | |_|_|/ |/| | |
| * | | of: implement of_property_write_strings for multiple stringsAhmad Fatoum2020-10-021-0/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The current way to set a property with multiple values (e.g. compatible strings) is to have char properties[] = "st,stm32mp157c-dk2\0st,stm32mp157"; of_set_property(np, "compatible", properties, sizeof(properties), 1); Add a new helper to make this easier at the cost of one runtime reallocation: of_property_write_strings(np, "compatible, "st,stm32mp157c-dk2", "st,stm32mp157", NULL); Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * | | lib: ratp: rename now undefined use of a Kconfig symbolAhmad Fatoum2020-10-011-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The symbol used to exist, but was renamed in 6f37d9efd91 ("commands: Move /dev/mem driver to drivers/misc") and then one instance without definition was added back in cae5e14224f4 ("ratp: add more build dependencies"). Fix it. Fixes: cae5e14224f4 ("ratp: add more build dependencies") Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | | | logo: Makefile: fix indentation of LOGO.S in quiet outputAhmad Fatoum2020-10-121-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Output currently looks like this: CC commands/printenv.o LOGO.S lib/logo/barebox-logo-w64.bblogo CC arch/sandbox/board/devices.o Drop one space, so it's aligned with the usual two letter prefixes. Signed-off-by: Ahmad Fatoum <ahmad@a3f.at> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | | | logo: Makefile: fix Inkscape >= v1.0 Wayland GUI opening on LOGO.SAhmad Fatoum2020-10-121-5/+3
| |/ / |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | DISPLAY="" only affects X11 windows. Building sandbox_defconfig under Wayland will still result in annoying Inkscape windows being opened. This happens due to $(call try-run, inkscape -z,-z). Inkscape v1.0 deprecates -z and it's without an effect, so Inkscape will try to create a window, which failed under x11, but succeeded under Wayland. Fix this by always testing -z and -e together. We don't need one or the other anyway, because Inkscape v1.0, which supports neither, already uses no GUI for --export-type=png. This makes DISPLAY="" unnecessary. So just drop it. Tested working on Inkscape 1.0.1 and 0.92.4. Signed-off-by: Ahmad Fatoum <ahmad@a3f.at> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | | lib: kasan: migrate Kconfig option to Debugging menuAhmad Fatoum2020-09-291-2/+0
| | | | | | | | | | | | | | | | | | | | | | | | UBSAN and ASAN as well as other debugging aids are all in the Debugging menu. Relocate KASAN to be there as well. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | | KASan: Add missing test codeSascha Hauer2020-09-281-0/+478
|/ / | | | | | | | | | | | | Add missing test code. Fixes: 6cd9d2d600 ("Add KASan support") Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | Merge branch 'for-next/net' into masterSascha Hauer2020-09-251-5/+1
|\ \
| * | ratp: Switch to workqueuesSascha Hauer2020-08-131-5/+1
| | | | | | | | | | | | | | | | | | | | | This switches running barebox commands in ratp to a context where it's safe to do so: In a work queue. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | | Merge branch 'for-next/misc' into masterSascha Hauer2020-09-256-363/+91
|\ \ \
| * | | lib: string: retire deprecated strtok() in favor of reentrant strsep()Ahmad Fatoum2020-09-141-32/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | With the recent changes to ARCH=sandbox, there are no remaining in-tree users for strtok() anymore. Out-of-tree users are better served by using the reentrant strsep(), which has existed in-tree for as long. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * | | common: ubsan: replace pr_err with printfAhmad Fatoum2020-09-141-44/+44
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The pr_print family of functions also writes to the barebox log buffer, which we don't require for printing UBSan errors, which is a debugging aid. This also improves UBSan coverage as now undefined behavior within pr_print may be reported as well. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * | | readkey: fix buffer overflow handling longer escape sequencesAhmad Fatoum2020-09-141-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | My terminal emulator uses "\e[5;5~" (six bytes) to represent a Ctrl+PageUp, this overflows the esc buffer, which is only 5 bytes long as both UBSan and ASAN report. We have a check that should've avoided it, but it has an off-by one, which corrupts memory on sizes >= 4. Fix it. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * | | sandbox: support escaping commas in --image filenamesAhmad Fatoum2020-09-141-0/+43
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Some tools like afl-fuzz generate file names containing commas. Allow escaping the commas in the file names, so they can be passed to barebox. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * | | lib: lzo: drop unused compression codeAhmad Fatoum2020-09-143-286/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The code doesn't compile and went unused since being added 10 years ago. Remove it. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | | | Add KASan supportSascha Hauer2020-09-2210-0/+972
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | KernelAddressSANitizer (KASAN) is a dynamic memory error detector. It provides a fast and comprehensive solution for finding use-after-free and out-of-bounds bugs. This adds support for KASan to barebox. It is basically a stripped down version taken from the Linux Kernel as of v5.9-rc1. Quoting the initial Linux commit 0b24becc810d ("kasan: add kernel address sanitizer infrastructure") describes what KASan does: | KASAN uses compile-time instrumentation for checking every memory access, | therefore GCC > v4.9.2 required. v4.9.2 almost works, but has issues with | putting symbol aliases into the wrong section, which breaks kasan | instrumentation of globals. | | Basic idea: | | The main idea of KASAN is to use shadow memory to record whether each byte | of memory is safe to access or not, and use compiler's instrumentation to | check the shadow memory on each memory access. | | Address sanitizer uses 1/8 of the memory addressable in kernel for shadow | memory and uses direct mapping with a scale and offset to translate a | memory address to its corresponding shadow address. | | For every 8 bytes there is one corresponding byte of shadow memory. | The following encoding used for each shadow byte: 0 means that all 8 bytes | of the corresponding memory region are valid for access; k (1 <= k <= 7) | means that the first k bytes are valid for access, and other (8 - k) bytes | are not; Any negative value indicates that the entire 8-bytes are | inaccessible. Different negative values used to distinguish between | different kinds of inaccessible memory (redzones, freed memory) (see | mm/kasan/kasan.h). | | To be able to detect accesses to bad memory we need a special compiler. | Such compiler inserts a specific function calls (__asan_load*(addr), | __asan_store*(addr)) before each memory access of size 1, 2, 4, 8 or 16. | | These functions check whether memory region is valid to access or not by | checking corresponding shadow memory. If access is not valid an error | printed. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | | | string: Add nokasan variants of default memcpy/memsetSascha Hauer2020-09-211-3/+26
| | | | | | | | | | | | | | | | | | | | | | | | Add nokasan variants of __default_memcpy and default_memset. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | | | Add constructor supportSascha Hauer2020-09-181-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Call constructors (gcc-generated initcall-like functions) during barebox start. Constructors are e.g. used for kasan initialization. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | | | Add print_hex_dump kernel implementationSascha Hauer2020-09-181-8/+204
|/ / / | | | | | | | | | | | | | | | | | | This gives us proper support of the different DUMP_PREFIX_* flags and also the ability to print hexdumps to buffers. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>