summaryrefslogtreecommitdiff
path: root/lib/sbi/sbi_console.c
AgeCommit message (Collapse)Author
2024-07-24lib: sbi: Introduce an early console buffer for caching early printsAnup Patel
The console device is registered by platform only in early_init() callback so any prints before this point will be lost. Introduce an early console buffer for caching prints before platform early_init(). For crashes before platform early_init(), users can simply dump the contents of the console_early_buffer[] string using a debugger. The relative address of the console_early_buffer[] string can be found using following two commands: CONSOLE_EARLY_FIFO_ADDR=`${CROSS_COMPILE}objdump -D \ build/platform/generic/firmware/fw_dynamic.elf | \ grep "<console_early_fifo>:" | awk '{print $1}'` ${CROSS_COMPILE}objdump -R build/platform/generic/firmware/fw_dynamic.elf | \ grep $CONSOLE_EARLY_FIFO_ADDR | awk '{print $3}' Signed-off-by: Anup Patel <[email protected]> Reviewed-By: Himanshu Chauhan <[email protected]>
2024-07-24lib: sbi: Remove sbi_console_init() and console_init() platform callbackAnup Patel
Now that all platforms have been updated to initialize serial console device in early_init(), the sbi_console_init() and console_init() platform callback are redundant hence remove them. Signed-off-by: Anup Patel <[email protected]> Reviewed-By: Himanshu Chauhan <[email protected]>
2024-03-19lib: tests: Move tests to a separate directoryIvan Orlov
Move all of the SBIUnit-related code into the lib/sbi/tests directory. Update 'Makefile' to index objects from the tests subdirectory. I don't think creating the full separate list of Makefile variables (libsbitests-objs-path-y, libsbitests-object-mks, etc. as it is done for libsbiutils) is necessary for the tests because: 1) `lib/sbi/tests/objects.mk` is already indexed into 'libsbi-objects-mks' since the find expression for the libsbi-object-mks variable looks for objects.mk files in the nested directories as well). 2) Tests are tightly coupled with the `lib/sbi/` sources, therefore it may be reasonable to store the list of lib/sbi and lib/sbi/tests object files together in the libsbi-objs-path-y variable. Additionally, update relative paths in the tests where necessary. Signed-off-by: Ivan Orlov <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-03-10lib: tests: Add sbi_console testIvan Orlov
Add the test suite covering some of the functions from lib/sbi/sbi_console.c: putc, puts and printf. The test covers a variety of format specifiers for printf and different strings and characters for putc and puts. In order to do that, the test "mocks" the sbi_console_device structure by setting the 'console_dev' variable to the virtual console. Signed-off-by: Ivan Orlov <[email protected]> Reviewed-by: Andrew Jones <[email protected]>
2023-11-17lib: sbi: Make console_puts/console_putc interchangeableXiang W
console_puts/console_putc should replace each other, but the previous sbi_putc can only use console_putc. This patch addresses this problem. Signed-off-by: Xiang W <[email protected]> Reviewed-by: Guo Ren <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-07-12lib: sbi: Fix missing '\0' when buffer szie equal 1Xiang W
Fix special case: sbi_snprintf(out, out_len, ...) when out_len equal 1, The previous code will not fill the buffer with any char. Signed-off-by: Xiang W <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-07-12lib: sbi: Fix timing of clearing tbufXiang W
A single scan of the format char may add multiple characters to the tbuf, causing a buffer overflow. You should check if tbuf is full in printc so that it does not cause a buffer overflow. Signed-off-by: Xiang W <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-07-12lib: sbi: Fix printcXiang W
Because *out needs to reserve a byte to hold '\0', no more characters should be added to the buffer when *out has one byte left, and the buffer size *out_len should not be modified. this patch prevents the correction of *out_len when *out_len is 1. Signed-off-by: Xiang W <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-07-12lib: sbi: Simplify printsXiang W
When doing width = width - strlen(string) in prints there is no need to consider the case that witdh may be less than 0. This is because the code to do filling needs to be executed under the condition that width > 0. Signed-off-by: Xiang W <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-07-12lib: sbi: Fix printiXiang W
Fix two bug: > printf("%#08x", 0x123); /* print 0000x123 */ > printf("%#x", 0); /* print 0x0 */ Signed-off-by: Xiang W <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-07-12lib: sbi: print add 'o' typeXiang W
Add o type for print to print octal numbers Signed-off-by: Xiang W <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-07-12lib: sbi: implifying the parameters of printiXiang W
The information of sg/b/letbase can be obtained by the type character, simplifying the parameter by passing the type directly. Signed-off-by: Xiang W <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-07-12lib: sbi: Add ' ' '\'' flags for printXiang W
The space flag is used to add a space before positive numbers, and apostrophe is used to print the thousand separator. Add code to ignore these two flags Signed-off-by: Xiang W <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-07-12lib: sbi: Add '+' flags for printXiang W
Adds + flags for print, prefixing positive numbers with + when this flags is present Signed-off-by: Xiang W <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-07-12lib: sbi: print not fill '0' when left-alignedXiang W
Left alignment and padding '0' should not exist at the same time, this patch skips padding. Signed-off-by: Xiang W <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-07-12lib: sbi: Fix how print gets flagsXiang W
The flags for print should be able to appear in any order. The previous code required the order to be fixed. Signed-off-by: Xiang W <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-05-26lib: sbi: Fix return of sbi_console_initXiang W
console is not a required peripheral. So it should return success when the console does not exist. Signed-off-by: Xiang W <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-02-10lib: sbi: Speed-up sbi_printf() and friends using nputs()Anup Patel
The sbi_printf() is slow for semihosting because it prints one character at a time. To speed-up sbi_printf() for semihosting, we use a temporary buffer and nputs(). Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Andrew Jones <[email protected]>
2023-02-10lib: sbi: Add console_puts() callback in the console deviceAnup Patel
We add console_puts() callback in the console device which allows console drivers (such as semihosting) to implement a specialized way to output character string. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Atish Patra <[email protected]> Reviewed-by: Xiang W <[email protected]> Reviewed-by: Bin Meng <[email protected]> Reviewed-by: Andrew Jones <[email protected]>
2023-02-09lib: sbi: Add sbi_ngets() functionAnup Patel
We add new sbi_ngets() which help us read characters into a physical memory location. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Atish Patra <[email protected]> Reviewed-by: Andrew Jones <[email protected]>
2023-02-09lib: sbi: Add sbi_nputs() functionAnup Patel
We add new sbi_nputs() which help us print a fixed number of characters from a physical memory location. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Atish Patra <[email protected]> Reviewed-by: Bin Meng <[email protected]> Reviewed-by: Xiang W <[email protected]>
2023-01-06treewide: Replace TRUE/FALSE with true/falseBin Meng
C language standard uses true/false for the boolean type. Let's switch to that for better language compatibility. Signed-off-by: Bin Meng <[email protected]> Reviewed-by: Anup Patel <[email protected]> Reviewed-by: Samuel Holland <[email protected]> Tested-by: Samuel Holland <[email protected]>
2022-07-30lib: sbi: Fix printf handling of long longdramforever
Read long long arguments directly using va_arg. Remove original hack for RV32 that read a long long arg as two long args. This un-breaks the case on RV64 where e.g. the long long is followed by an odd number of ints: sbi_printf("%d %lld", (int) 1, (long long) 2LL); Also remove the acnt variable, which is now unused. Signed-off-by: dramforever <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2022-07-30lib: sbi: Fix sbi_snprintfAndrew Jones
printc would happily write to 'out' even when 'out_len' was zero, potentially overflowing buffers. Rework printc to not do that and also ensure the null byte is written at the last position when necessary, as stated in the snprintf man page. Also, panic if sprintf or snprintf are called with NULL output strings (except the special case of snprintf having a NULL output string and a zero output size, allowing it to be used to get the number of characters that would have been written). Finally, rename a goto label which clashed with 'out'. Fixes: 9e8ff05cb61f ("Initial commit.") Signed-off-by: Andrew Jones <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2021-12-02lib: sbi: Improve fatal error handlingJessica Clarke
BUG and BUG_ON are not informative and are rather lazy interfaces, only telling the user that something went wrong in a given function, but not what, requiring the user to find the sources corresponding to their firmware (which may not be available) and figure out how that BUG(_ON) was hit. Even SBI_ASSERT in its current form, which does include the condition that triggered it in the output, isn't necessarily very informative. In some cases, the error may be fixable by the user, but they need to know the problem in order to have any hope of fixing it. It's also a nuisance for developers, whose development trees may have changed significantly since the release in question being used, and so line numbers can make it harder for them to understand which error case a user has hit. This patch introduces a new sbi_panic function which is printf-like, allowing detailed error messages to be printed to the console. BUG and BUG_ON are removed, since the former is just a worse form of sbi_panic and the latter is a worse version of SBI_ASSERT. Finally, SBI_ASSERT is augmented to take a set of arguments to pass to sbi_panic on failure, used like so (sbi_boot_print_hart's current error case, which currently manually calls sbi_printf and sbi_hart_hang): SBI_ASSERT(xlen >= 1, ("Error %d getting MISA XLEN\n", xlen)); The existing users of BUG are replaced with calls to sbi_panic along with informative error messages. BUG_ON and SBI_ASSERT were unused (and, in the case of SBI_ASSERT, remain unused). Many existing users of sbi_hart_hang should be converted to use either sbi_panic or SBI_ASSERT after this commit. Signed-off-by: Jessica Clarke <[email protected]> Reviewed-by: Anup Patel <[email protected]> Reviewed-by: Xiang W <[email protected]> Reviewed-by: Atish Patra <[email protected]>
2021-08-30lib: sbi: protect dprintf output with spinlockDong Du
Avoid getting messages from multiple harts (using dprintf and printf) concurrently with a spinlock serializaing calls to sbi_dprintf(), sbi_printf() and sbi_puts() Signed-off-by: Dong Du <[email protected]> Reviewed-by: Xiang W <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2021-04-28lib: sbi: Simplify console platform operationsAnup Patel
Instead of having console_putc() and console_getc() callbacks in platform operations, it will be much simpler for console driver to directly register these operations as device to the sbi_console implementation. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Alistair Francis <[email protected]> Reviewed-by: Xiang W <[email protected]>
2020-03-28include: sbi_console: Remove scratch parameter from sbi_dprintf()Anup Patel
This patch removes scratch parameter from sbi_dprintf() function because sbi_dprintf() can use sbi_scratch_thishart_ptr() to get current HART scratch space. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Atish Patra <[email protected]>
2019-08-09lib: Introduce sbi_dprintf() APIAnup Patel
This patch introduces new sbi_dprintf() API for runtime debug prints. The sbi_dprintf() will print to console for a given HART only when SBI_SCRATCH_DEBUG_PRINTS option in enabled in sbi_scratch for this HART. We can now add debug prints using sbi_dprintf() at important places in OpenSBI sources. These debug prints will only show up when previous booting stage or compile time parameter sets the SBI_SCRATCH_DEBUG_PRINTS option in scratch space. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Bin Meng <[email protected]>
2019-06-19lib: Move sbi core library to lib/sbiAtish Patra
Signed-off-by: Atish Patra <[email protected]> Acked-by: Anup Patel <[email protected]>