summaryrefslogtreecommitdiffstats
path: root/lib
Commit message (Collapse)AuthorAgeFilesLines
* Merge branch 'for-next/misc'Sascha Hauer2021-07-182-5/+1
|\
| * test: self: add tests for progress notifierAhmad Fatoum2021-06-281-1/+1
| | | | | | | | | | | | | | | | | | We don't yet have any boards upstream that make use of the progress notifier, but at least have some tests, so we know it's working. Signed-off-by: Ahmad Fatoum <ahmad@a3f.at> Link: https://lore.barebox.org/20210619054048.498826-1-ahmad@a3f.at Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * image-sparse: remove unused defineRouven Czerwinski2021-06-231-4/+0
| | | | | | | | | | | | | | | | | | | | | | | | CONFIG_FASTBOOT_FLASH_FILLBUF_SIZE is present since the very first addition of sparse image support. However its not used anywhere in the code, so remove it. Fixes: 13f649a4f960 ("Add support for fastboot sparse images") Signed-off-by: Rouven Czerwinski <r.czerwinski@pengutronix.de> Link: https://lore.barebox.org/20210621102706.586345-1-r.czerwinski@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | Merge branch 'for-next/firmware'Sascha Hauer2021-07-182-20/+61
|\ \
| * | libbb: Add find_path functionSascha Hauer2021-06-251-20/+38
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | libbb contains a find_execable() function to find an executable in a colon separated path. The code can be reused by making the environment variable name and the is-executable test parameters. Do this and add a find_path() Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Link: https://lore.barebox.org/20210624085223.14616-6-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * | libfile: Add copy_fd()Sascha Hauer2021-06-231-0/+23
| |/ | | | | | | | | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Link: https://lore.barebox.org/20210623043359.18391-3-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* / string: implement strchrnulAhmad Fatoum2021-06-281-0/+18
|/ | | | | | | | | | We have at least two places opencoding strchrnul, one of them needlessly iterating twice instead of once over the string. Replace both by calling a common single pass implementation. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20210628051934.9604-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/misc'Sascha Hauer2021-06-161-1/+2
|\
| * uncompress: use read_full to fill decompression bufferLucas Stach2021-05-271-1/+2
| | | | | | | | | | | | | | | | | | | | The decompression algorithms want all of the requested buffer size to be filled and don't cope with less bytes being returned. Use read_full to satisfy this requirement. Signed-off-by: Lucas Stach <l.stach@pengutronix.de> Link: https://lore.barebox.org/20210526090216.4003977-1-l.stach@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | lib/math/rational.c: Fix divide by zeroTrent Piepho2021-06-091-5/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If the input is out of the range of the allowed values, either larger than the largest value or closer to zero than the smallest non-zero allowed value, then a division by zero would occur. In the case of input too large, the division by zero will occur on the first iteration. The best result (largest allowed value) will be found by always choosing the semi-convergent and excluding the denominator based limit when finding it. In the case of the input too small, the division by zero will occur on the second iteration. The numerator based semi-convergent should not be calculated to avoid the division by zero. But the semi-convergent vs previous convergent test is still needed, which effectively chooses between 0 (the previous convergent) vs the smallest allowed fraction (best semi-convergent) as the result. Fixes: 323dd2c3ed0 ("lib/math/rational.c: fix possible incorrect result from rational fractions helper") Reported-by: Yiyuan Guo <yguoaz@gmail.com> Signed-off-by: Trent Piepho <tpiepho@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | Add rational_best_approximation()Sascha Hauer2021-06-072-0/+101
|/ | | | | | | | | | Import rational_best_approximation() from Linux. This is used by an upcoming update of the clk_fractional_divider code. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20210602095507.24609-12-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/usb-gadget'Sascha Hauer2021-05-176-0/+174
|\
| * param: introduce file-list parameter typeAhmad Fatoum2021-05-122-0/+118
| | | | | | | | | | | | | | | | | | | | | | | | | | | | DFU, fastboot and incoming mass storage support all use file lists as input, but individually check syntax correctness only on use. A dedicated file list parameter would improve the user experience and makes the code using it easier to handle: the struct file_list can be passed around directly instead of having to parse it first on use. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20210503114901.13095-6-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * vsprintf: introduce %m shorthand for "%s", strerror(errno)Ahmad Fatoum2021-05-031-0/+13
| | | | | | | | | | | | | | | | | | | | | | We have many places across the code base that use either do printf("%s..", errno_str()) or printf("%s..", strerror(errno). We already have %pe support for printing arbitrary errors and it's not much work to add %m to print errno as well. Do so. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20210503114901.13095-5-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * string: implement strstarts along with strendsAhmad Fatoum2021-05-031-0/+9
| | | | | | | | | | | | | | | | | | | | | | Both can be useful when parsing file paths. They are added to different files, because only one of them is available in upstream <linux/string.h>. The other we add to <string.h>, which contains more barebox-specific string functions. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20210503114901.13095-4-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * show_progress: add system wide progress stage notifierAhmad Fatoum2021-05-032-0/+34
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Use case is e.g. board code that wants to register a client to light status LEDs to indicate system state when no serial output is available. This functionality doesn't increase code size due to linker GC when CONFIG_PROGRESS_NOTIFIER is disabled. There is a generic progress notifier provided that just logs the status. This could be shared with the booted kernel via pstore or the log as a whole written to a system setup USB drive. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20210503114901.13095-2-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | 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>