summaryrefslogtreecommitdiffstats
path: root/lib
Commit message (Collapse)AuthorAgeFilesLines
* 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>
* | | Merge branch 'for-next/misc' into masterSascha Hauer2020-08-181-0/+4
|\ \ \
| * | | string: add sanity check to the strcmp() and strncmp()Oleksij Rempel2020-08-171-0/+4
| |/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A relatively big portion of barebox init sequence is running without configured exception vector. As result we may not detect some NULL pointer dereferences (as on iMX6) or just silently freeze (as on stm32). So, add sanity check to detect this kind of issues as early as possible. Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* / / libfile: copy_file: Fix ftruncate called on device filesSascha Hauer2020-08-181-5/+5
|/ / | | | | | | | | | | | | | | | | | | | | | | | | ftruncate may only be called on regular files. This became broken in a5f73a6dcd. Revert to the previous behaviour and pass O_TRUNC to the initial open() call instead of truncating it with ftruncate(). Also we can call ftruncate() to the final size also when the file previously didn't exist. Fixes: a5f73a6dcd ("libfile: copy_file: explicitly truncate to final size") Reported-by: Bastian Krause <bst@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | Merge branch 'for-next/ratp'Sascha Hauer2020-07-271-0/+2
|\ \
| * | ratp: Fix closing connectionsSascha Hauer2020-06-161-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When entering the LAST_ACK state we have to set the saved SN to the received SN of the current packet. With this we properly accept the final incoming packet and close the connection. Without this we interpret the final incoming packet as a duplicate of the previous packet and close the connection only after a timeout. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | | Merge branch 'for-next/ramfs'Sascha Hauer2020-07-271-9/+16
|\ \ \
| * | | libfile: copy_file: explicitly truncate to final sizeSascha Hauer2020-07-051-5/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When possible truncate the destination file to the final size explicitly. This allows for example ramfs to put the resulting file contiguously into memory. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * | | libfile: copy_file: Fix calling discard_rangeSascha Hauer2020-07-051-5/+6
| |/ / | | | | | | | | | | | | | | | | | | | | | | | | discard range is called with unitialized size argument. Call it after stat() on the source filedescriptor. Also there's no point in continuing when stat() on the source filedescriptor fails, so bail out in this case. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | | Merge branch 'for-next/misc'Sascha Hauer2020-07-271-149/+0
|\ \ \
| * | | lib: list_sort: delete dead codeAhmad Fatoum2020-07-141-149/+0
| |/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | list_sort.c's core code should only change on sync with Linux, so we don't really need separate testing code. The code doesn't compile as we neither have a CONFIG_TEST_LIST_SORT symbol nor do we have a <linux/random.h> header. Remove it. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* / / fs: fat: extend for in-PBL supportAhmad Fatoum2020-07-111-1/+1
|/ / | | | | | | | | | | | | | | | | | | | | The AT91 BootROM loads a boot.bin file from the first FAT partition into SRAM, when booting from MMC. To avoid the need for two barebox configurations for each of the bootloader stages, add PBL support for reading from FAT. This way each stage need only have a different PBL entry point. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | Merge branch 'for-next/ratp'Sascha Hauer2020-06-111-0/+2
|\ \
| * | ratp: Free buffersSascha Hauer2020-05-201-0/+2
| |/ | | | | | | | | | | recvbuf and sendbuf are never freed, free them to avoid memory holes. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | Merge branch 'for-next/misc'Sascha Hauer2020-06-111-6/+13
|\ \
| * | logo: Makefile: make it possible to use inkscape 1.0Antony Pavlov2020-06-031-6/+13
| |/ | | | | | | | | Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* / kbuild: rename pbl object pbl-*.o to *.pbl.oMasahiro Yamada2020-05-201-3/+2
|/ | | | | | | | | | | | | | | | | | Currently, pbl objects are output to: <directory-path>/pbl-<basename>.o This commit changes as follows: <directory-path>/<basename>.pbl.o The motivation is not only to get rid of the ugly code introduced by commit 257abdaa36c8 ("Do not rm the path from pbl-y target"), but also to make it easier to remove obj-dtb-y, pbl-dtb-y, lwl-dtb-y syntax in the next commit. Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/misc'Sascha Hauer2020-05-1416-48/+0
|\