oweals/u-boot.git
6 years agosandbox: Fix set_working_fdt_addr users
Alexander Graf [Wed, 26 Sep 2018 12:07:41 +0000 (14:07 +0200)]
sandbox: Fix set_working_fdt_addr users

When running sandbox with the new pointer sanitization we just recently
introduced, we're running into a case with FIT images where we end up
interpreting pointers as addresses.

What happened is that most callers of set_working_fdt_addr() simply
convert pointers into addresses without taking into account that they
might be 2 separate address spaces. Fix the callers up to map their
pointers into addresses.

This makes sandbox tests pass for me again.

Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agoefi_loader: refactor efi_setup_loaded_image()
Heinrich Schuchardt [Sun, 23 Sep 2018 15:21:51 +0000 (17:21 +0200)]
efi_loader: refactor efi_setup_loaded_image()

Create the handle of loaded images and the EFI_LOADED_IMAGE_PROTOCOL
inside efi_setup_loaded_image(). Do not use local variables.

Currently we expect the loaded image handle to point to the loaded image
protocol. Additionally we have appended private fields to the protocol.

With the patch the handle points to a loaded image object and the private
fields are added here. This matches how we handle the net and the gop
object.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agoarm: qemu-arm: enable RTC (PL031) by default
AKASHI Takahiro [Fri, 14 Sep 2018 08:06:54 +0000 (17:06 +0900)]
arm: qemu-arm: enable RTC (PL031) by default

Virtual machine provided by qemu-arm has a ARM PL031 Real Time Clock
device. With this patch, the driver is enabled by default.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agortc: pl031: convert the driver to driver model
AKASHI Takahiro [Fri, 14 Sep 2018 08:06:53 +0000 (17:06 +0900)]
rtc: pl031: convert the driver to driver model

With this patch, PL031 driver is converted to driver-model-compliant
driver. In addition, CONFIG_SYS_RTC_PL031_BASE is no longer valid.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agoefi_loader: Fix loaded_image handle passing from EL3
Alexander Graf [Sun, 23 Sep 2018 14:23:56 +0000 (16:23 +0200)]
efi_loader: Fix loaded_image handle passing from EL3

When running in EL3 mode on AArch64, we have to first drop to EL2
to execute a UEFI payload. When dropping down, the arguments to
the entry point have to stay identical to the ones for normal entry
though.

In commit ea54ad59286 ("efi_loader: pass handle of loaded image")
we incorrectly changed that logic and had the el3 entry path diverge.
Fix it up by syncing it back to what it's supposed to be.

Fixes: ea54ad59286 ("efi_loader: pass handle of loaded image")
Signed-off-by: Alexander Graf <agraf@suse.de>
Reviewed-by: Mark Kettenis <kettenis@openbsd.org>
6 years agoefi_loader: Disable efi selftest on sandbox for now
Alexander Graf [Sun, 23 Sep 2018 13:21:09 +0000 (15:21 +0200)]
efi_loader: Disable efi selftest on sandbox for now

The EFI selftest does not succeed on Sandbox yet. The network support
seems to need some love to actually make our current tests succeed.

So let's disable running the selftest on sandbox for now until "make
tests" just works. Then we can have more amazing CI than ever.

Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agoefi_loader: remove efi_exit_caches()
Heinrich Schuchardt [Sun, 23 Sep 2018 12:33:47 +0000 (14:33 +0200)]
efi_loader: remove efi_exit_caches()

Since GRUB patch d0c070179d4d ("arm/efi: Switch to arm64 linux loader",
2018-07-09) we do not need a workaround for GRUB on 32bit ARM anymore.

So let's eliminate function efi_exit_caches().

This will require Linux distributions to update grub-efi-arm to the GRUB
git HEAD (a tag containing the aforementioned GRUB patch is not available
yet).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agodm: video: check bounds for column and row
Heinrich Schuchardt [Wed, 19 Sep 2018 17:15:14 +0000 (19:15 +0200)]
dm: video: check bounds for column and row

CSI H can be used to position the cursor. The calling application may
specify a location that is beyond the limits of the screen. This may
lead to an illegal memory access.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agoefi_loader: remove redundant statement
Heinrich Schuchardt [Thu, 20 Sep 2018 17:57:54 +0000 (19:57 +0200)]
efi_loader: remove redundant statement

ascii2unicode() always ends the u16 string with '\0'.
Remove redundant assignment.

Add description for efi_str_to_u16() and ascii2unicode().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agoefi_loader: create root node
Heinrich Schuchardt [Thu, 20 Sep 2018 19:58:23 +0000 (21:58 +0200)]
efi_loader: create root node

Currently we assign a lot of protocols to loaded images though
these protocols are not related to them. Instead they should be
installed on a separate handle. Via the device path it is the
parent to the devices like the network adapter.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agoefi_loader: avoid out of bound access in efi_get_variable()
Heinrich Schuchardt [Sun, 23 Sep 2018 02:08:09 +0000 (04:08 +0200)]
efi_loader: avoid out of bound access in efi_get_variable()

In efi_get_variable() a string is longer than the allocated space which
results in overwriting the linked list of malloc().

The prefixes used for variables are 41 characters long, e.g.
efi_67029eb5-0af2-f6b1-da53-fcb566dd1ce6_

Change PREFIX_LEN to 41.

Fixes: faff21556748 ("efi_loader: remove limit on variable length")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agoefi_selftest: test qemu-arm(64)_defconfig
Heinrich Schuchardt [Sun, 23 Sep 2018 02:25:12 +0000 (04:25 +0200)]
efi_selftest: test qemu-arm(64)_defconfig

We should run the EFI selftest on both a 32bit and a 64bit ARM platform on
Travis to catch possible errors.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agoefi_driver: convert function descriptions to Sphinx style
Heinrich Schuchardt [Tue, 18 Sep 2018 16:52:46 +0000 (18:52 +0200)]
efi_driver: convert function descriptions to Sphinx style

Convert the function descriptions to Sphinx style.
efi_driver_init() is cCalled by efi_init_obj_list().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agoefi_loader: query serial console size reliably
Heinrich Schuchardt [Sat, 15 Sep 2018 21:52:07 +0000 (23:52 +0200)]
efi_loader: query serial console size reliably

Not all terminals understand CSI [18t for querying the console size.
We should adhere to escape sequences documented in the console_codes
manpage and the ECMA-48 standard.

So here we follow a different approach. We position the cursor to the
bottom right and query its position. Before leaving the function we
restore the original cursor position.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agoefi_loader: Merge memory map entries
Alexander Graf [Sun, 16 Sep 2018 15:05:29 +0000 (17:05 +0200)]
efi_loader: Merge memory map entries

We currently do not combine memory entries that are adjacent and have
the same attributes. The problem with that is that our memory map can
easily grow multiple hundreds of entries in a simple UEFI Shell
environment.

So let's make sure we always combine all entries to make the memory
map as small as possible. That way every other piece of code that
loops through it should also gain some nice speed ups.

Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agoefi_loader: memory leak in efi_set_bootdev()
Heinrich Schuchardt [Sun, 16 Sep 2018 05:20:21 +0000 (07:20 +0200)]
efi_loader: memory leak in efi_set_bootdev()

efi_set_bootdev() may be called repeatedly.
Free the memory allocated for device paths in previous calls.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agoefi_loader: do not use local variable for handle
Heinrich Schuchardt [Sun, 16 Sep 2018 05:19:48 +0000 (07:19 +0200)]
efi_loader: do not use local variable for handle

Do not use a local variable for the handle backing the memory device path.
Adjust relate comments.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agoefi_selftest: missing braces in efi_selftest_textinputex.c
Heinrich Schuchardt [Sat, 15 Sep 2018 19:00:52 +0000 (21:00 +0200)]
efi_selftest: missing braces in efi_selftest_textinputex.c

gcc 4.8.4 wants to see all levels of braces when initializing a
structure to zeros.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agoefi_loader: check parameter new_handle of efi_file_open()
Heinrich Schuchardt [Sat, 15 Sep 2018 18:43:46 +0000 (20:43 +0200)]
efi_loader: check parameter new_handle of efi_file_open()

We should not check parameter file twice.
We should check parameter new_handle.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agosandbox: Allow to execute from RAM
Alexander Graf [Fri, 22 Jun 2018 12:44:13 +0000 (14:44 +0200)]
sandbox: Allow to execute from RAM

With efi_loader, we may want to execute payloads from RAM. By default,
permissions on the RAM region don't allow us to execute from there though.

So let's change the default allocation scheme for RAM to also allow
execution from it. That way payloads that live in U-Boot RAM can be
directly executed.

Signed-off-by: Alexander Graf <agraf@suse.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agosandbox: Fix setjmp/longjmp
Alexander Graf [Fri, 22 Jun 2018 12:44:12 +0000 (14:44 +0200)]
sandbox: Fix setjmp/longjmp

In sandbox, longjmp returns to itself in an endless loop because
os_longjmp() calls into longjmp() which is provided by U-Boot which
again calls os_longjmp().

Setjmp on the other hand must not return because otherwise the
return freees up stack elements that we need during longjmp().

The only straight forward fix that doesn't involve nasty hacks I
could find is to directly link against the system setjmp/longjmp
implementations. That means we just provide the compiler with
hints that the symbol will be available and actually fill them
out with versions from libc.

This approach should be reasonably platform agnostic

Signed-off-by: Alexander Graf <agraf@suse.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agoefi_loader: terminal left upper corner is [1, 1]
Heinrich Schuchardt [Fri, 14 Sep 2018 16:49:26 +0000 (18:49 +0200)]
efi_loader: terminal left upper corner is [1, 1]

For the VT102 and the Linux console the left upper corner is [1, 1].
EFI uses [0, 0] as left upper corner.

Check parameters of the SetCursorPosition() service.

Use CSI H like EDK2 for positioning.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agoefi_loader: more debug info for efi_file_getinfo()
Heinrich Schuchardt [Fri, 14 Sep 2018 20:46:34 +0000 (22:46 +0200)]
efi_loader: more debug info for efi_file_getinfo()

efi_file_getinfo() is called with a GUID. In EFI_ENTRY use %pUl as
format type. This way the GUID is printed in debug mode.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agoefi: sandbox: Enable selftest command
Simon Glass [Sat, 15 Sep 2018 06:51:01 +0000 (00:51 -0600)]
efi: sandbox: Enable selftest command

Enable this for sandbox since it almost passes now.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agoefi: Correct the operation of efi_file_write()
Simon Glass [Sat, 15 Sep 2018 06:51:00 +0000 (00:51 -0600)]
efi: Correct the operation of efi_file_write()

We should not directly cast between pointers and addresses since it breaks
sandbox. Fix this and simplify the code in file_read().

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agosandbox: Enhance map_to_sysmem() to handle foreign pointers
Simon Glass [Sat, 15 Sep 2018 06:50:56 +0000 (00:50 -0600)]
sandbox: Enhance map_to_sysmem() to handle foreign pointers

At present map_sysmem() maps an address into the sandbox RAM buffer,
return a pointer, while map_to_sysmem() goes the other way.

The mapping is currently just 1:1 since a case was not found where a more
flexible mapping was needed. PCI does have a separate and more complex
mapping, but uses its own mechanism.

However this arrange cannot handle one important case, which is where a
test declares a stack variable and passes a pointer to it into a U-Boot
function which uses map_to_sysmem() to turn it into a address. Since the
pointer is not inside emulated DRAM, this will fail.

Add a mapping feature which can handle any such pointer, mapping it to a
simple tag value which can be passed around in U-Boot as an address.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agosandbox: Add support for calling abort()
Simon Glass [Sat, 15 Sep 2018 06:50:55 +0000 (00:50 -0600)]
sandbox: Add support for calling abort()

This function is useful to signal that the application needs to exit
immediate. It can be caught with a debugger (e.g. gdb). Add a stub for it
so that it can be called from within sandbox when an internal error
occurs.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agosandbox: Align RAM buffer to the machine page size
Simon Glass [Sat, 15 Sep 2018 06:50:54 +0000 (00:50 -0600)]
sandbox: Align RAM buffer to the machine page size

At present the sandbox RAM buffer is not aligned to any particular
address boundary. This makes the internal pointers somewhat random with
respect to the associated RAM buffer addresses.

Align the buffer to the page size of the machine to help with this. Note
that there is a header at the start of the allocated pointer. To avoid
returning a pointer which is not aligned to a page boundary, we waste
almost an entire page of memory for each allocation.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agoefi: sandbox: Enable EFI loader build for sandbox
Simon Glass [Sat, 15 Sep 2018 06:50:53 +0000 (00:50 -0600)]
efi: sandbox: Enable EFI loader build for sandbox

This allows this feature to build within sandbox. This is useful for
testing.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agoefi: sandbox: Add distroboot support
Simon Glass [Sat, 15 Sep 2018 06:50:52 +0000 (00:50 -0600)]
efi: sandbox: Add distroboot support

With sandbox these values depend on the host system. Let's assume that it
is x86_64 for now.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agoefi_loader: loosen check of parameters of efi_file_open()
Heinrich Schuchardt [Thu, 13 Sep 2018 19:31:49 +0000 (21:31 +0200)]
efi_loader: loosen check of parameters of efi_file_open()

The UEFI spec requires that attributes are only set for when
EFI_FILE_MODE_CREATE is set in open_mode.

The SCT tries to read a directory with EFI_FILE_DIRECTORY.

As EDK2 allows this we should not be more strict.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agofs: fat: unaligned buffers are not an error
Heinrich Schuchardt [Thu, 13 Sep 2018 17:42:47 +0000 (19:42 +0200)]
fs: fat: unaligned buffers are not an error

The FAT driver supports unaligned reads and writes and EFI applications
will make use of these. So a misaligned buffer is only worth a debug
message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agoefi_loader: provide description of file_open()
Heinrich Schuchardt [Wed, 12 Sep 2018 17:00:02 +0000 (19:00 +0200)]
efi_loader: provide description of file_open()

Replace urban slang by proper description.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agoefi_loader: check parameters of efi_file_open()
Heinrich Schuchardt [Wed, 12 Sep 2018 16:43:58 +0000 (18:43 +0200)]
efi_loader: check parameters of efi_file_open()

Check the parameters of efi_file_open().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agoefi_loader: unset CONFIG_EFI_UNICODE_CAPITALIZATION
Heinrich Schuchardt [Tue, 11 Sep 2018 20:38:14 +0000 (22:38 +0200)]
efi_loader: unset CONFIG_EFI_UNICODE_CAPITALIZATION

Unset CONFIG_EFI_UNICODE_CAPITALIZATION on boards with tough size
restrictions.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agoefi_selftest: test key notification functions
Heinrich Schuchardt [Tue, 11 Sep 2018 20:38:13 +0000 (22:38 +0200)]
efi_selftest: test key notification functions

Use a key notification function to leave the
EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL test.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agoefi_loader: implement key notify functions
Heinrich Schuchardt [Tue, 11 Sep 2018 20:38:12 +0000 (22:38 +0200)]
efi_loader: implement key notify functions

Implement registering and unregistreing key notify functions in the
EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agotest/py: test EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
Heinrich Schuchardt [Tue, 11 Sep 2018 20:38:11 +0000 (22:38 +0200)]
test/py: test EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL

Add a unit test for the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agoefi_selftest: test EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
Heinrich Schuchardt [Tue, 11 Sep 2018 20:38:10 +0000 (22:38 +0200)]
efi_selftest: test EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL

Provide a unit test for the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agoefi_loader: support modifiers for F1 - F4
Heinrich Schuchardt [Tue, 11 Sep 2018 20:38:09 +0000 (22:38 +0200)]
efi_loader: support modifiers for F1 - F4

Support modifiers for F1 - F4.
Add support for letters with ALT key.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agoefi_loader: EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
Heinrich Schuchardt [Tue, 11 Sep 2018 20:38:08 +0000 (22:38 +0200)]
efi_loader: EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL

This patch implements the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL.

The implementation of notification functions is postponed to a later
patch.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agotest/py: rework test_efi_selftest_text_input()
Heinrich Schuchardt [Tue, 11 Sep 2018 20:38:07 +0000 (22:38 +0200)]
test/py: rework test_efi_selftest_text_input()

Use more precise regular expressions.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agoefi_selftest: use WaitForKey to test text input
Heinrich Schuchardt [Tue, 11 Sep 2018 20:38:06 +0000 (22:38 +0200)]
efi_selftest: use WaitForKey to test text input

We should test the WaitForKey event.
Testing for EFI_NOT_READY can be done after resetting the console.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agoefi_loader: rework event handling for console
Heinrich Schuchardt [Tue, 11 Sep 2018 20:38:05 +0000 (22:38 +0200)]
efi_loader: rework event handling for console

Preread the next key in the console timer event.

The EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL requires to trigger registered key
notification functions based on the prefetched key.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agoefi_selftest: refactor text input test
Heinrich Schuchardt [Tue, 11 Sep 2018 20:38:04 +0000 (22:38 +0200)]
efi_selftest: refactor text input test

Move reusable utility functions to efi_selftest_util.c.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agotest/py: Unicode w/ EFI_SIMPLE_TEXT_INPUT_PROTOCOL
Heinrich Schuchardt [Tue, 11 Sep 2018 20:38:03 +0000 (22:38 +0200)]
test/py: Unicode w/ EFI_SIMPLE_TEXT_INPUT_PROTOCOL

Test that the Euro sign is correctly retrieved from the console via the
EFI_SIMPLE_TEXT_INPUT_PROTOCOL.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agoefi_loader: support Unicode text input
Heinrich Schuchardt [Tue, 11 Sep 2018 22:05:32 +0000 (00:05 +0200)]
efi_loader: support Unicode text input

Up to now the EFI_TEXT_INPUT_PROTOCOL only supported ASCII characters.
With the patch it can consume UTF-8 from the console.

Currently only the serial console and the console can deliver UTF-8.
Local consoles are restricted to ASCII.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agotest/py: fs: add fstest/unlink test
Akashi, Takahiro [Tue, 11 Sep 2018 07:06:03 +0000 (16:06 +0900)]
test/py: fs: add fstest/unlink test

In this commit, test cases for unlink interfaces are added as part of
"test_fs" test suite.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agotest/py: fs: add fstest/mkdir test
AKASHI Takahiro [Tue, 11 Sep 2018 06:59:21 +0000 (15:59 +0900)]
test/py: fs: add fstest/mkdir test

In this commit, test cases for mkdir interfaces are added as part of
"test_fs" test suite.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agotest/py: fs: add extended write operation test
AKASHI Takahiro [Tue, 11 Sep 2018 06:59:20 +0000 (15:59 +0900)]
test/py: fs: add extended write operation test

In this commit and the following, test scripts for new filesystem
functionalities introduced by my patch set, "fs: fat: extend FAT write
operations," are provided.

In particular, this patch adds test cases for sub-directory write
and write with non-zero offset.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agotest/py: convert fs-test.sh to pytest
AKASHI Takahiro [Tue, 11 Sep 2018 06:59:19 +0000 (15:59 +0900)]
test/py: convert fs-test.sh to pytest

In this commit, the same set of test cases as in test/fs/fs-test.sh
is provided using pytest framework.
Actually, fs-test.sh provides three variants:"sb" (sb command), "nonfs"
(fatxx and etc.) and "fs" (hostfs), and this patch currently supports
only "nonfs" variant; So it is not a replacement of fs-test.sh for now.

Simple usage:
  $ py.test test/py/tests/test_fs [<other options>]

You may also specify filesystem types to be tested:
  $ py.test test/py/tests/test_fs --fs-type fat32 [<other options>]

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agofs-test: update the test result as of v2018.09
AKASHI Takahiro [Tue, 11 Sep 2018 06:59:18 +0000 (15:59 +0900)]
fs-test: update the test result as of v2018.09

As far as this patch series has been applied, all the tests should
pass. So update the test result summary.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agofs-test: fix false positive error at Test Case 12
AKASHI Takahiro [Tue, 11 Sep 2018 06:59:17 +0000 (15:59 +0900)]
fs-test: fix false positive error at Test Case 12

The error message to be matched is wrong. Fix it.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agoefi_loader: implement a file delete
AKASHI Takahiro [Tue, 11 Sep 2018 06:59:16 +0000 (15:59 +0900)]
efi_loader: implement a file delete

'Delete' will be implemented here by calling fs_unlink() which relies on
underlying file system's implementation.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agocmd: fat: add fatrm command
AKASHI Takahiro [Tue, 11 Sep 2018 06:59:15 +0000 (15:59 +0900)]
cmd: fat: add fatrm command

In this patch, a new command, fatrm, is added so as to delete a file
or directory.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agofs: fat: support unlink
AKASHI Takahiro [Tue, 11 Sep 2018 06:59:14 +0000 (15:59 +0900)]
fs: fat: support unlink

In this patch, unlink support is added to FAT file system.
A directory can be deleted only if it is empty.

In this implementation, only a directory entry for a short file name
will be removed. So entries for a long file name can and should be
reclaimed with fsck.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agofs: add unlink interface
AKASHI Takahiro [Tue, 11 Sep 2018 06:59:13 +0000 (15:59 +0900)]
fs: add unlink interface

"unlink" interface is added to file operations.
This is a preparatory change as unlink support for FAT file system
will be added in next patch.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agoefi_loader: file: support creating a directory
AKASHI Takahiro [Tue, 11 Sep 2018 06:59:12 +0000 (15:59 +0900)]
efi_loader: file: support creating a directory

In efi world, there is no obvious "mkdir" interface, instead, Open()
with EFI_FILE_MODE_CREATE in mode parameter and EFI_FILE_DIRECTORY
in attributes parameter creates a directory.

In this patch, efi_file_open() is extended so as to accept such
a combination of parameters and call u-boot's mkdir interface for
expected action.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agocmd: fat: add fatmkdir command
AKASHI Takahiro [Tue, 11 Sep 2018 06:59:11 +0000 (15:59 +0900)]
cmd: fat: add fatmkdir command

In this patch, a new command, fatmkdir, is added.

Please note that, as there is no notion of "current directory" on u-boot,
a directory name specified must contains an absolute directory path as
a parent directory. Otherwise, "/" (root directory) is assumed.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agofs: fat: support mkdir
AKASHI Takahiro [Tue, 11 Sep 2018 06:59:10 +0000 (15:59 +0900)]
fs: fat: support mkdir

In this patch, mkdir support is added to FAT file system.
A newly created directory contains only "." and ".." entries.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agofs: fat: remember the starting cluster number of directory
AKASHI Takahiro [Tue, 11 Sep 2018 06:59:09 +0000 (15:59 +0900)]
fs: fat: remember the starting cluster number of directory

The starting cluster number of directory is needed to initialize ".."
(parent directory) entry when creating a new directory.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agofs: add mkdir interface
AKASHI Takahiro [Tue, 11 Sep 2018 06:59:08 +0000 (15:59 +0900)]
fs: add mkdir interface

"mkdir" interface is added to file operations.
This is a preparatory change as mkdir support for FAT file system
will be added in next patch.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agocmd: fat: add offset parameter to fatwrite
AKASHI Takahiro [Tue, 11 Sep 2018 06:59:07 +0000 (15:59 +0900)]
cmd: fat: add offset parameter to fatwrite

In this patch, fatwrite command is extended so as to accept an additional
parameter of file offset.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agofs: fat: support write with non-zero offset
AKASHI Takahiro [Tue, 11 Sep 2018 06:59:06 +0000 (15:59 +0900)]
fs: fat: support write with non-zero offset

In this patch, all the necessary code for allowing for a file offset
at write is implemented. What plays a major roll here is get_set_cluster(),
which, in contrast to its counterpart, set_cluster(), only operates on
already-allocated clusters, overwriting with data.

So, with a file offset specified, set_contents() seeks and writes data
with set_get_cluster() until the end of a file, and, once it reaches
there, continues writing with set_cluster() for the rest.

Please note that a file will be trimmed as a result of write operation if
write ends before reaching file's end. This is an intended behavior
in order to maintain compatibility with the current interface.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agofs: fat: refactor write interface for a file offset
AKASHI Takahiro [Tue, 11 Sep 2018 06:59:05 +0000 (15:59 +0900)]
fs: fat: refactor write interface for a file offset

The current write implementation is quite simple: remove existing clusters
and then allocating new ones and filling them with data. This, inevitably,
enforces always writing from the beginning of a file.

As the first step to lift this restriction, fat_file_write() and
set_contents() are modified to accept an additional parameter, file offset
and further re-factored so that, in the next patch, all the necessary code
will be put into set_contents().

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agofs: fat: support write with sub-directory path
AKASHI Takahiro [Tue, 11 Sep 2018 06:59:04 +0000 (15:59 +0900)]
fs: fat: support write with sub-directory path

In this patch, write implementation is overhauled and rewritten by
making full use of directory iterator. The obvious bonus is that we are
now able to write to a file with a directory path, like /A/B/C/FILE.

Please note that, as there is no notion of "current directory" on u-boot,
a file name specified must contain an absolute directory path. Otherwise,
"/" (root directory) is assumed.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agofs: fat: write returns error code instead of -1
AKASHI Takahiro [Tue, 11 Sep 2018 06:59:03 +0000 (15:59 +0900)]
fs: fat: write returns error code instead of -1

It would be good that FAT write function return error code instead of
just returning -1 as fat_read_file() does.
This patch attempts to address this issue although it is 'best effort
(or estimate)' for now.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agofs: fat: check and normalize file name
AKASHI Takahiro [Tue, 11 Sep 2018 06:59:02 +0000 (15:59 +0900)]
fs: fat: check and normalize file name

FAT file system's long file name support is a bit complicated and has some
restrictions on its naming. We should be careful about it especially for
write as it may easily end up with wrong file system.

normalize_longname() check for the rules and normalize a file name
if necessary. Please note, however, that this function is yet to be
extended to fully comply with the standard.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agoRevert "fs: fat: cannot write to subdirectories"
AKASHI Takahiro [Tue, 11 Sep 2018 06:59:01 +0000 (15:59 +0900)]
Revert "fs: fat: cannot write to subdirectories"

This reverts commit 0dc1bfb7302d220a48364263d5632d6d572b069b.
The succeeding patch series will supersede it.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agofs: fat: assure iterator's ->dent belongs to ->clust
AKASHI Takahiro [Tue, 11 Sep 2018 06:59:00 +0000 (15:59 +0900)]
fs: fat: assure iterator's ->dent belongs to ->clust

In my attempt to re-work write operation, it was revealed that iterator's
"clust" does not always point to a cluster to which a current directory
entry ("dent") belongs.
This patch assures that it is always true by adding "next_clust" which is
used solely for dereferencing a cluster chain.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agofs: fat: handle "." and ".." of root dir correctly with fat_itr_resolve()
AKASHI Takahiro [Tue, 11 Sep 2018 06:58:59 +0000 (15:58 +0900)]
fs: fat: handle "." and ".." of root dir correctly with fat_itr_resolve()

FAT's root directory does not have "." nor ".."
So care must be taken when scanning root directory with fat_itr_resolve().
Without this patch, any file path starting with "." or ".." will not be
resolved at all.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agofs: fat: extend get_fs_info() for write use
AKASHI Takahiro [Tue, 11 Sep 2018 06:58:58 +0000 (15:58 +0900)]
fs: fat: extend get_fs_info() for write use

get_fs_info() was introduced in major re-work of read operation by Rob.
We want to reuse this function in write operation by extending it with
additional members in fsdata structure.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agoefi_loader: typos in efi_console.c
Heinrich Schuchardt [Sat, 8 Sep 2018 17:57:24 +0000 (19:57 +0200)]
efi_loader: typos in efi_console.c

Fix a few typos.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agoefi_loader: SPDX-License-Identifier for efi.h
Heinrich Schuchardt [Sat, 8 Sep 2018 08:57:59 +0000 (10:57 +0200)]
efi_loader: SPDX-License-Identifier for efi.h

Add the missing SPDX-License-Identifier based on Linux kernel commit
b24413180f56 ("License cleanup: add SPDX GPL-2.0 license identifier to
files with no license").

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agoefi_loader: SPDX-License-Identifier for efi_api.h
Heinrich Schuchardt [Sat, 8 Sep 2018 08:50:40 +0000 (10:50 +0200)]
efi_loader: SPDX-License-Identifier for efi_api.h

Add the missing SPDX-License-Identifier based on Linux kernel commit
b24413180f56 ("License cleanup: add SPDX GPL-2.0 license identifier to
files with no license").

Correct formatting errors.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agoefi_loader: struct efi_simple_text_input_protocol
Heinrich Schuchardt [Sat, 8 Sep 2018 08:20:10 +0000 (10:20 +0200)]
efi_loader: struct efi_simple_text_input_protocol

%s/efi_simple_input_interface/efi_simple_text_input_protocol/

We should be consistent in the naming of the EFI protocol interface
structures. The protocol is called EFI_SIMPLE_TEXT_INPUT_PROTOCOL.

%s/ExtendedVerification/extended_verification/

Use consistent naming of function parameters. Do not use CamelCase.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agotest/py: typo occured
Heinrich Schuchardt [Thu, 6 Sep 2018 18:29:50 +0000 (20:29 +0200)]
test/py: typo occured

%s/occured/occurred/

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agotest/py: test EFI_SIMPLE_TEXT_INPUT_PROTOCOL
Heinrich Schuchardt [Thu, 6 Sep 2018 18:19:31 +0000 (20:19 +0200)]
test/py: test EFI_SIMPLE_TEXT_INPUT_PROTOCOL

Execute the EFI selftest for the EFI_SIMPLE_TEXT_INPUT_PROTOCOL.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agoefi_selftest: EFI_UNICODE_COLLATION_PROTOCOL
Heinrich Schuchardt [Tue, 4 Sep 2018 17:34:59 +0000 (19:34 +0200)]
efi_selftest: EFI_UNICODE_COLLATION_PROTOCOL

Provide a unit test for the EFI_UNICODE_COLLATION_PROTOCOL.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agoefi_loader: EFI_UNICODE_COLLATION_PROTOCOL
Heinrich Schuchardt [Tue, 4 Sep 2018 17:34:58 +0000 (19:34 +0200)]
efi_loader: EFI_UNICODE_COLLATION_PROTOCOL

The patch implements the EFI_UNICODE_COLLATION_PROTOCOL.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agotest: tests for utf_to_lower() utf_to_upper().
Heinrich Schuchardt [Tue, 4 Sep 2018 17:34:57 +0000 (19:34 +0200)]
test: tests for utf_to_lower() utf_to_upper().

Provide unit tests for utf_to_lower() utf_to_upper().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agolib: charset: upper/lower case conversion
Heinrich Schuchardt [Tue, 4 Sep 2018 17:34:56 +0000 (19:34 +0200)]
lib: charset: upper/lower case conversion

Provide functions for upper and lower case conversion.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agoefi_loader: capitalization table
Heinrich Schuchardt [Tue, 4 Sep 2018 17:34:55 +0000 (19:34 +0200)]
efi_loader: capitalization table

This patch provides a define to initialize a table that maps lower to
capital letters for Unicode code point 0x0000 - 0xffff.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agoefi_loader: Add console handle references to in/out/err
Alexander Graf [Tue, 4 Sep 2018 12:59:11 +0000 (14:59 +0200)]
efi_loader: Add console handle references to in/out/err

We register the console in/out protocol on the loaded image handle, but
never tell anyone about it in the systab.

Because of this Shell.efi can not find the input protocol. So let's add
a proper reference.

Signed-off-by: Alexander Graf <agraf@suse.de>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
6 years agoefi_loader: use correct documentation style
Heinrich Schuchardt [Mon, 3 Sep 2018 03:00:43 +0000 (05:00 +0200)]
efi_loader: use correct documentation style

We have moved generating html documentation with Sphinx.

%s/Return Value/Return/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agoefi_loader: description efi_update_capsule()
Heinrich Schuchardt [Mon, 3 Sep 2018 18:59:25 +0000 (20:59 +0200)]
efi_loader: description efi_update_capsule()

Correct the description of efi_update_capsule().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agoefi_loader: fix typos in efi_runtime.c
Heinrich Schuchardt [Mon, 3 Sep 2018 17:29:41 +0000 (19:29 +0200)]
efi_loader: fix typos in efi_runtime.c

Fix multiple typos

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agoefi_loader: fix typos in efi_boottime.c
Heinrich Schuchardt [Mon, 3 Sep 2018 17:12:24 +0000 (19:12 +0200)]
efi_loader: fix typos in efi_boottime.c

Fix numerous typos.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agoRevert "Revert "efi_loader: efi_allocate_pages is too restrictive""
Stephen Warren [Thu, 30 Aug 2018 21:43:45 +0000 (15:43 -0600)]
Revert "Revert "efi_loader: efi_allocate_pages is too restrictive""

This reverts commit ccfc78b820e5e431c5bd73b072e7536a972e1710.

Now that the underlying issue is fixed, we can revert the revert and hence
restore the original EFI code.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agoARM: tegra: reserve unmapped RAM so EFI doesn't use it
Stephen Warren [Thu, 30 Aug 2018 21:43:44 +0000 (15:43 -0600)]
ARM: tegra: reserve unmapped RAM so EFI doesn't use it

Tegra U-Boot ensures that board_get_usable_ram_top() never returns a value
over 4GB, since some peripherals can't access such addresses. However, on
systems with more than 2GB of RAM, RAM bank 1 does describe this extra
RAM, so that Linux (or whatever OS) can use it, subject to DMA
limitations. Since board_get_usable_ram_top() points at the top of RAM
bank 0, the memory locations describes by RAM bank 1 are not mapped by
U-Boot's MMU configuration, and so cannot be used for anything.

For some completely inexplicable reason, U-Boot's EFI support ignores the
value returned by board_get_usable_ram_top(), and EFI memory allocation
routines will return values above U-Boot's RAM top. This causes U-Boot to
crash when it accesses that RAM, since it isn't mapped by the MMU. One
use-case where this happens is TFTP download of a file on Jetson TX1
(p2371-2180).

This change explicitly tells the EFI code that this extra RAM should not
be used, thus avoiding the crash.

A previous attempt to make EFI honor board_get_usable_ram_top() was
rejected. So, this patch will need to be replicated for any board that
implements board_get_usable_ram_top().

Fixes: aa909462d018 ("efi_loader: efi_allocate_pages is too restrictive")
Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agoefi_loader: simplify ifdefs
Stephen Warren [Thu, 30 Aug 2018 21:43:43 +0000 (15:43 -0600)]
efi_loader: simplify ifdefs

Use CONFIG_IS_ENABLED(EFI_LOADER) to avoid explicitly checking CONFIG_SPL
too. This simplifies the conditional.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agolib: charset: remove obsolete functions
Heinrich Schuchardt [Fri, 31 Aug 2018 19:31:34 +0000 (21:31 +0200)]
lib: charset: remove obsolete functions

Remove functions:
- utf8_to_utf16()
- utf16_strcpy()
- utf16_strdup()

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agoefi_loader: buffer size for load options
Heinrich Schuchardt [Fri, 31 Aug 2018 19:31:33 +0000 (21:31 +0200)]
efi_loader: buffer size for load options

The number of bytes in an utf-8 string is an upper limit for the number of
words in the equivalent utf-16 string. In so far the inumbant coding works
correctly. For non-ASCII characters the utf-16 string is shorter. With the
patch only the necessary buffer size is allocated for the load options.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agoefi_loader: don't use unlimited stack as buffer
Heinrich Schuchardt [Fri, 31 Aug 2018 19:31:32 +0000 (21:31 +0200)]
efi_loader: don't use unlimited stack as buffer

The length of a string printed to the console by the
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL is not limited by the UEFI spec.
Hence should not allocate a buffer for it on the stack.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agoefi_loader: remove limit on variable length
Heinrich Schuchardt [Fri, 31 Aug 2018 19:31:31 +0000 (21:31 +0200)]
efi_loader: remove limit on variable length

The EFI spec does not provide a length limit for variables.

Reviewed-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agotest: test printing Unicode
Heinrich Schuchardt [Fri, 31 Aug 2018 19:31:30 +0000 (21:31 +0200)]
test: test printing Unicode

Test printing of Unicode strings

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agolib: vsprintf: correct printing of Unicode strings
Heinrich Schuchardt [Fri, 31 Aug 2018 19:31:29 +0000 (21:31 +0200)]
lib: vsprintf: correct printing of Unicode strings

The width and precision of the printf() function refer to the number of
characters not to the number of bytes printed.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agotest: unit tests for Unicode functions
Heinrich Schuchardt [Fri, 31 Aug 2018 19:31:28 +0000 (21:31 +0200)]
test: unit tests for Unicode functions

Provide unit tests for Unicode functions.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agolib: charset: utility functions for Unicode
Heinrich Schuchardt [Fri, 31 Aug 2018 19:31:27 +0000 (21:31 +0200)]
lib: charset: utility functions for Unicode

utf8_get() - get next UTF-8 code point from buffer
utf8_put() - write UTF-8 code point to buffer
utf8_utf16_strnlen() - length of a utf-8 string after conversion to utf-16
utf8_utf16_strncpy() - copy a utf-8 string to utf-16
utf16_get() - get next UTF-16 code point from buffer
utf16_put() - write UTF-16 code point to buffer
utf16_strnlen() - number of codes points in a utf-16 string
utf16_utf8_strnlen() - length of a utf-16 string after conversion to utf-8
utf16_utf8_strncpy() - copy a utf-16 string to utf-8

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
6 years agoefi_loader: rename utf16_strlen, utf16_strnlen
Heinrich Schuchardt [Fri, 31 Aug 2018 19:31:26 +0000 (21:31 +0200)]
efi_loader: rename utf16_strlen, utf16_strnlen

The function names utf16_strlen() and utf16_strnlen() are misnomers.
The functions do not count utf-16 characters but non-zero words.
So let's rename them to u16_strlen and u16_strnlen().

In utf16_dup() avoid assignment in if clause.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>