summaryrefslogtreecommitdiffstats
path: root/lib
Commit message (Collapse)AuthorAgeFilesLines
* Merge branch 'for-next/misc'Sascha Hauer2024-03-151-1/+1
|\
| * of: partition: Also add partitions created by addpart to the boot dtbUwe Kleine-König2024-03-131-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A partition added interactively using addpart was added in of_partition_fixup() before commit aec676b568 ("cdev: record whether partition is parsed from OF"). Restore that behaviour. To do that a new flag DEVFS_PARTITION_FOR_FIXUP is created that behaves very similar what DEVFS_PARTITION_FROM_OF did before. The only difference is that addpart makes use of it (and that stat uses a different string to describe it). Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Link: https://lore.barebox.org/20240312100918.604105-1-u.kleine-koenig@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | lib: uuid: implement uuid/guid_parseAhmad Fatoum2024-03-051-0/+63
| | | | | | | | | | | | | | | | | | We opencode this at least once in EFI code, so import the Linux definition and start using that instead. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-110-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | lib: string: import Linux strreplace helperAhmad Fatoum2024-03-051-0/+21
| | | | | | | | | | | | | | | | This helper replaces all occurrences of a given character in a string. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-93-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | vsprintf: add %pD for printing EFI device pathAhmad Fatoum2024-03-051-1/+19
| | | | | | | | | | | | | | | | | | | | We already have a few users that will want to print EFI device paths and will gain quite a few more with incoming loader support, so let's allow printing them directly with printf with the %pD format specifier. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-92-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | lib: vsprintf: align documentation with current feature setAhmad Fatoum2024-03-051-10/+15
| | | | | | | | | | | | | | | | | | | | | | The documentation lists modifiers unsupported by barebox and lacks modifiers that are actually supported. Align the documentation with the currently supported feature set and reorder it to the same order used inside the pointer() main switch statement. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-91-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | commands: time: refactor into new strjoinAhmad Fatoum2024-03-051-0/+28
| | | | | | | | | | | | | | | | | | | | | | | | time concatenates all its remaining arguments with a space in-between and then passes that to the command executor. This can be useful elsewhere as well, so factor it out into a new strjoin function. No functional change. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-49-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | libfile: factor out read_file_into_buf helperAhmad Fatoum2024-03-051-14/+30
| | | | | | | | | | | | | | | | | | | | | | We do open -> read_full -> close at a number of places. Add a function that does this all at once and start using it to implement read_file. More users can follow later. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-13-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | vsprintf: guard against NULL in UUID %pUAhmad Fatoum2024-03-051-0/+4
| | | | | | | | | | | | | | | | To make %pU more useful for debugging, have it handle NULL gracefully. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-5-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | treewide: add errno_set helper for returning positive error code in errnoAhmad Fatoum2024-03-052-24/+13
|/ | | | | | | | | | | We have this sequence at multiple places: Check a return value for being below zero and if so, turn it positive and store into errno. Instead of opencoding it everywhere, add a helper to encapsulate this. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-4-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/zstd'Sascha Hauer2024-02-218-43/+372
|\
| * uncompress: add detected file type debug printMarco Felsch2024-02-061-0/+2
| | | | | | | | | | | | | | | | This can be useful for developers. Signed-off-by: Marco Felsch <m.felsch@pengutronix.de> Link: https://lore.barebox.org/20240124134738.133782-4-m.felsch@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * bootm: add support to boot ZSTD compressed imagesMarco Felsch2024-02-063-0/+327
| | | | | | | | | | | | | | | | | | | | | | This adds the support to bootm to decompress and boot ZSTD compressed kernels. The decompress_unzstd.c was taken from Linux and slighlty adapted. Also the unzstd() function is adapted since we don't support large >2G images yet like Linux does. Signed-off-by: Marco Felsch <m.felsch@pengutronix.de> Link: https://lore.barebox.org/20240124134738.133782-3-m.felsch@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * decompress: change length arguments to longSascha Hauer2024-02-066-43/+43
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In order to support decompression of files > 2GiB Linux has changed the prototypes of decompression functions from int uncompress(unsigned char *inbuf, int len, int(*fill)(void*, unsigned int), int(*flush)(void*, unsigned int), unsigned char *output, int *pos, void(*error_fn)(char *x)); to int uncompress(unsigned char *inbuf, long len, long(*fill)(void*, unsigned long), long(*flush)(void*, unsigned long), unsigned char *output, long *pos, void(*error_fn)(char *x)); Do likewise in barebox for easier code sharing with Linux. Link: https://lore.barebox.org/20240206094838.1987246-1-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | Merge branch 'for-next/partitions'Sascha Hauer2024-02-211-0/+30
|\ \
| * | uuid: implement random uuid/guidSascha Hauer2024-02-201-0/+30
| |/ | | | | | | | | Link: https://lore.barebox.org/20240219083140.2713047-6-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | eth: replace ethaddr_to_string() with %pMSascha Hauer2024-02-051-2/+1
| | | | | | | | | | | | | | | | Now that we can print MAC addresses using the %pM format specifier we can get rid of ethaddr_to_string(). Do this treewide. Link: https://lore.barebox.org/20240202151147.226876-2-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | vsprintf: add support for printing MAC addressesSascha Hauer2024-02-051-0/+25
|/ | | | | | | | Linux can print MAC addresses using the %pM format specifier. Implement the same for barebox. Link: https://lore.barebox.org/20240202151147.226876-1-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/misc'Sascha Hauer2024-01-233-0/+79
|\
| * lib: add optional linked list debuggingAhmad Fatoum2024-01-113-0/+79
| | | | | | | | | | | | | | | | | | | | | | | | When enabled, this outputs messages like: list_del corruption, 000000005fe4a9d0->next is LIST_POISON1 (0000000000000100) which can be useful when debugging. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240103101948.2630473-2-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | cdev: export and use cdevfs_del_partitionAhmad Fatoum2024-01-081-1/+1
| | | | | | | | | | | | | | | | | | | | | | Like what's the case with cdevfs_add_partition, a couple of users already have a cdev, so it's wasteful to get its name and do a lookup only to arrive at the same cdev. Export a cdevfs_del_partition that directly works on the cdev and start using it instead. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240103101629.2629497-6-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | lib: stackprotector: adjust Kconfig text for bareboxAhmad Fatoum2024-01-031-2/+2
|/ | | | | | | | | The reference to kernel panic is taken from the original Linux Kconfig help text. Leaving it as-is may be confusing, so adjust it for barebox. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240103101324.2628829-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* uncompress: skip dentry cache in uncompress_buf_to_bufAhmad Fatoum2023-12-131-20/+16
| | | | | | | | | | | | | make_temp() creates a named temporary file, which even after deletion will keep a negative dentry cache entry that's never freed. As we don't use the file name for anything, we can just get our temporary file via open(O_TMPFILE), which won't involve the dentry cache at all and thereby avoiding leaking memory when fuzzing uncompress_buf_to_buf. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20231122170323.15175-3-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* libfile: implement read_fd counterpart to read_fileAhmad Fatoum2023-12-131-0/+50
| | | | | | | | | | Files opened with O_TMPFILE have no name, so read_file can't be used with them. Therefore add a read_fd function, which slurps all a file's contents into a buffer. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20231122170323.15175-2-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/prepare-optee'Sascha Hauer2023-11-276-1/+211
|\
| * include: linux/idr.h: implement more Linux APIAhmad Fatoum2023-11-233-0/+104
| | | | | | | | | | | | | | | | | | Upcoming sync of SCMI with the kernel will start using IDR API, which we lack in barebox, so let's retrofit it. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20231122172951.376531-14-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * string: implement strscpyAhmad Fatoum2023-11-231-0/+71
| | | | | | | | | | | | | | | | | | | | | | strscpy is meant to be a safer alternative to strscpy, which always terminates the destination string and returns an error code if truncation happens. To enable porting kernel code using it, import the definition. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20231122172951.376531-10-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * include: add linux/refcount.hAhmad Fatoum2023-11-232-0/+35
| | | | | | | | | | | | | | | | | | | | | | | | For complex interactions, especially in communication protocols, it can be beneficial to keep the reference counts used in the Linux drivers as is to avoid resource leaks or use-after-frees. Provide a simplified kref and refcount API to facilitate this. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20231122172951.376531-3-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * include: provide linux/errno.hAhmad Fatoum2023-11-231-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We don't have the historic baggage of having to support different errno definitions depending on architecture. We thus have only asm-generic/errno.h and include that from errno.h and elsewhere directly. Kernel code however includes <linux/errno.h>, so let's provide that file as well and define there the Linux-specific errno's and include <asm-generic/errno.h> for all other errnos. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20231122172951.376531-2-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | Merge branch 'for-next/misc'Sascha Hauer2023-11-275-139/+86
|\ \
| * | glob: drop needless ifdeffery in {glob,fnmatch}.hAhmad Fatoum2023-11-213-134/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The implementation of the glob and fnmatch functions is taken from glibc and it shows in the amount of #ifdefs. We don't need that in barebox and can even get the glob_t size down by dropping unused members, so let's do that. Cc: Christian Melki <christian.melki@t2data.com> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20231109122551.1486020-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * | KASan: test_kasan: hide buggy accesses from compilerAhmad Fatoum2023-11-101-0/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Once we add __alloc_size attributes to allocations, GCC will complain about violation of memory safety in test_kasan.c. That memory violation is intended though as test_kasan is meant to trigger kasan at runtime to verify correct operation. Silence the warnings by hiding the origin of ptr, so the compiler loses context about the size of the allocation. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20231109113807.1193935-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * | lib: base64: add support for base64urlAhmad Fatoum2023-11-011-5/+55
| |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | base64url has some small differences to our current base64 implementation: - Instead of encoding to `+', `-' is used - Instead of encoding to `/', `_' is used - Padding with = to reach four byte boundary is optional - Invalid characters aren't silently skipped Everything else is the same though, so let's reuse the code and have an optional url bool parameter control whether to decode base64 or base64url. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20231023143122.1760217-2-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* / lib: Add generic binary search functionSascha Hauer2023-11-062-0/+35
|/ | | | | | | Add generic binary search function based on Linux-6.5-rc3. Link: https://lore.barebox.org/20230803105003.4088205-10-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/mtd'Sascha Hauer2023-10-271-2/+1
|\
| * bootstrap: Fix partition creationSascha Hauer2023-10-121-2/+1
| | | | | | | | | | | | | | | | | | | | bootstrap_read_devfs() registers a partition with DEVFS_PARTITION_FIXED. The purpose of this flag is that the partition can't be removed later. Removing the partition is exactly what bootstrap_read_devfs() does when finished, so remove the DEVFS_PARTITION_FIXED flag which doesn't make sense here. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | decompress: xz: enable armthumb BCJ filter for Thumb-2 bareboxAhmad Fatoum2023-10-231-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The XZ decompressor in barebox has BCJ filter support for THUMB, but like Linux, it's unused and instead the ARM BCJ filter is used. Fixing that lets us save a few kilobytes, which is especially useful for legacy configuration that fit a whole barebox into limited on-chip SRAM (and not only the prebootloader). For example, with this patch applied barebox-am33xx-beaglebone-mlo.img is shrinked 3K from 109236 to 106028 bytes. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20231020180912.2914428-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | lib: stackprot: hide symbols when not applicableAhmad Fatoum2023-10-131-2/+3
| | | | | | | | | | | | | | | | | | | | Asking all users about the stacksmash command that's just there to test stack guard and protector is unnecessary noise. Likewise asking about PBL stackprotector, when we don't have any. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20231009115239.2291016-5-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | lib: stackprot: don't directly write stack protector from HWRNG driverAhmad Fatoum2023-10-131-2/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | get_crypto_bytes itself or some function it calls down to the driver may require a stack protector, so passing the address of the stack protector value down may end up tripping the stack protector during function return. To avoid this, let's write the stack protector in a function chain that eithr has stack protector disabled or that never returns. This fixes a crash using the virtio RNG driver to generate the stack protector. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20231009115239.2291016-4-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | lib: stackprot: improve error message on missing HWRNGAhmad Fatoum2023-10-131-2/+10
| | | | | | | | | | | | | | | | | | ERROR: no HWRNG available! WARNING: stackprot: proceeding without randomized stack protector Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20231009115239.2291016-3-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | lib: random: don't duplicate error/warning prefix in log messageAhmad Fatoum2023-10-131-2/+2
| | | | | | | | | | | | | | | | | | pr_err and pr_warn already print an ERROR/WARNING prefix, so no need to duplicate it. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20231009115239.2291016-2-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | lib: ubsan: disable sanitization for UBSAN implementationAhmad Fatoum2023-10-131-0/+2
| | | | | | | | | | | | | | | | | | As done in Linux, the implementation of ubsan itself should not be instrumented by KASAN and stack protector. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20231009115239.2291016-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | uncompress: make use of error_fn in uncompress_buf_to_bufAhmad Fatoum2023-10-101-1/+1
|/ | | | | | | | | | | | | uncompress_buf_to_buf already accepts an error_fn, but didn't make use of it and instead relied on the default uncompress_err_stdout. Fix this. The user-visible effect of this is that failure to decompress FIT image contents is now printed with pr_err instead of the default printf. No other upstream users of uncompress_buf_to_buf currently exist. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20231009115310.2398292-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/misc'Sascha Hauer2023-09-255-8/+115
|\
| * lib: rename json_strcpy to json_strdupAhmad Fatoum2023-09-221-1/+1
| | | | | | | | | | | | | | | | | | jsmn_strcpy is an unfortunate name for a function that allocates memory. Rename it to jsmn_strdup instead. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230921102426.1109289-4-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * lib: jsmn: add case-insensitive comparisonAhmad Fatoum2023-09-221-0/+12
| | | | | | | | | | | | | | | | | | Users may want to do a case-insensitive comparison of tokens. Add simple helpers for that. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230921102426.1109289-3-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * lib: jsmn: add helper for allocating tokensAhmad Fatoum2023-09-221-0/+36
| | | | | | | | | | | | | | | | | | | | | | jsmn_parse can be called with a NULL buffer to determine the needed allocation size beforehand. Most users will go on to dynamically allocate that buffer, so add a helper that does just that and start using it to simplify the json selftest. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230921102426.1109289-2-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * lib: jsmn: add and use new jsmn_token_size helperAhmad Fatoum2023-09-221-2/+2
| | | | | | | | | | | | | | | | | | To make code a bit more terse, add a simple helper to get a token's size and start using it in some of the existing jsmn helpers. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230921102426.1109289-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * decompressors: Update xz to include ARM64 BCJ decoderJules Maselbas2023-09-084-5/+64
| | | | | | | | | | | | | | | | | | | | | | | | | | Update lib/xz/xz_dec_bcj.c and lib/xz/xz_private.h files from xz-embedded [1], which include spelling fixes and the new ARM64 BCJ decoder which was recently introduced into .xz file format version 1.1.0 (2022-12-11) [2]. [1] https://git.tukaani.org/?p=xz-embedded.git [2] https://tukaani.org/xz/xz-file-format-1.1.0.txt Signed-off-by: Jules Maselbas <jmaselbas@zdiv.net> Link: https://lore.barebox.org/20230907152047.102747-1-jmaselbas@zdiv.net Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | Merge branch 'for-next/dump-stack-stderr'Sascha Hauer2023-09-252-13/+11
|\ \