Commit Graph

1687 Commits

Author SHA1 Message Date
danh-arm d7aa7b44d6 Merge pull request #817 from antonio-nino-diaz-arm/an/timingsafe
Import constant-time bcmp() and use it where necessary
2017-01-24 16:30:55 +00:00
Antonio Nino Diaz b621fb503c tbbr: Use constant-time bcmp() to compare hashes
To avoid timing side-channel attacks, it is needed to use a constant
time memory comparison function when comparing hashes. The affected
code only cheks for equality so it isn't needed to use any variant of
memcmp(), bcmp() is enough.

Also, timingsafe_bcmp() is as fast as memcmp() when the two compared
regions are equal, so this change incurrs no performance hit in said
case. In case they are unequal, the boot sequence wouldn't continue as
normal, so performance is not an issue.

Change-Id: I1c7c70ddfa4438e6031c8814411fef79fd3bb4df
Signed-off-by: Antonio Nino Diaz <antonio.ninodiaz@arm.com>
2017-01-24 14:42:13 +00:00
Antonio Nino Diaz aa050a7bdb stdlib: Import timingsafe_bcmp() from FreeBSD
Some side-channel attacks involve an attacker inferring something from
the time taken for a memory compare operation to complete, for example
when comparing hashes during image authentication. To mitigate this,
timingsafe_bcmp() must be used for such operations instead of the
standard memcmp().

This function executes in constant time and so doesn't leak any timing
information to the caller.

Change-Id: I470a723dc3626a0ee6d5e3f7fd48d0a57b8aa5fd
Signed-off-by: dp-arm <dimitris.papastamos@arm.com>
Signed-off-by: Antonio Nino Diaz <antonio.ninodiaz@arm.com>
2017-01-24 14:42:12 +00:00
danh-arm 34438669d4 Merge pull request #818 from sandrine-bailleux-arm/sb/strnlen
Add strnlen() to local C library
2017-01-24 14:28:19 +00:00
Sandrine Bailleux d67879d311 Add strnlen() to local C library
This code has been imported and slightly adapted from FreeBSD:
6253393ad8/lib/libc/string/strnlen.c

Change-Id: Ie5ef5f92e6e904adb88f8628077fdf1d27470eb3
Signed-off-by: Sandrine Bailleux <sandrine.bailleux@arm.com>
2017-01-24 10:28:41 +00:00
danh-arm 4abd2225c2 Merge pull request #800 from masahir0y/ifdef
Correct preprocessor conditionals
2017-01-23 16:49:43 +00:00
danh-arm e02be20722 Merge pull request #815 from hzhuang1/dwmmc_v3.9
drivers: add designware emmc driver
2017-01-23 16:47:55 +00:00
Masahiro Yamada 6af03f9c45 Use #ifdef for AARCH32 instead of #if
One nasty part of ATF is some of boolean macros are always defined
as 1 or 0, and the rest of them are only defined under certain
conditions.

For the former group, "#if FOO" or "#if !FOO" must be used because
"#ifdef FOO" is always true.  (Options passed by $(call add_define,)
are the cases.)

For the latter, "#ifdef FOO" or "#ifndef FOO" should be used because
checking the value of an undefined macro is strange.

For AARCH32/AARCH64, these macros are defined in the top-level
Makefile as follows:

ifeq (${ARCH},aarch32)
        $(eval $(call add_define,AARCH32))
else
        $(eval $(call add_define,AARCH64))
endif

This means only one of the two is defined.  So, AARCH32/AARCH64
belongs to the latter group where we should use #ifdef or #ifndef.
The conditionals are mostly coded correctly, but I see some mistakes.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
2017-01-24 01:01:21 +09:00
Masahiro Yamada 3d8256b2a1 Use #ifdef for IMAGE_BL* instead of #if
One nasty part of ATF is some of boolean macros are always defined
as 1 or 0, and the rest of them are only defined under certain
conditions.

For the former group, "#if FOO" or "#if !FOO" must be used because
"#ifdef FOO" is always true.  (Options passed by $(call add_define,)
are the cases.)

For the latter, "#ifdef FOO" or "#ifndef FOO" should be used because
checking the value of an undefined macro is strange.

Here, IMAGE_BL* is handled by make_helpers/build_macro.mk like
follows:

  $(eval IMAGE := IMAGE_BL$(call uppercase,$(3)))

  $(OBJ): $(2)
          @echo "  CC      $$<"
          $$(Q)$$(CC) $$(TF_CFLAGS) $$(CFLAGS) -D$(IMAGE) -c $$< -o $$@

This means, IMAGE_BL* is defined when building the corresponding
image, but *undefined* for the other images.

So, IMAGE_BL* belongs to the latter group where we should use #ifdef
or #ifndef.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
2017-01-24 01:01:21 +09:00
danh-arm 7750990cfe Merge pull request #808 from masahir0y/build_fix
Fix parallel building
2017-01-23 14:44:27 +00:00
Haojian Zhuang 5dbdb7da1c drivers: add designware emmc driver
Support Designware eMMC driver. It's based on both IO block
and eMMC driver.

Signed-off-by: Haojian Zhuang <haojian.zhuang@linaro.org>
2017-01-23 22:08:45 +08:00
danh-arm bf6363acd4 Merge pull request #810 from masahir0y/fiptool_fix
Fix fiptool bug introduced by recent rework
2017-01-23 12:00:50 +00:00
danh-arm 7b94e4b9d2 Merge pull request #813 from antonio-nino-diaz-arm/an/libfdt
Update libfdt to version 1.4.2
2017-01-23 11:42:46 +00:00
danh-arm 23beccc9f7 Merge pull request #812 from antonio-nino-diaz-arm/an/clear-static-vars
Clear static variables in X509 parser on error
2017-01-23 11:39:17 +00:00
Masahiro Yamada d014ea6ccc Build: strip trailing slashes from directory paths more simply
Append . then strip /. seems clumsy.  Just use $(patsubst %/,%, ).

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
2017-01-19 19:36:47 +09:00
Masahiro Yamada a6ca78881f Build: Fix parallel building
Soren reports build fails if -j option is given:

  $ make -j16 CROSS_COMPILE=aarch64-linux-gnu-
  Building fvp
  make: *** No rule to make target 'build/fvp/release/bl1/',
                    needed by 'build/fvp/release/bl1/bl1.ld'.  Stop.
  make: *** Waiting for unfinished jobs....

The cause of the failure is that $(dir ) leaves a trailing / on the
directory names.   It must be ripped off to let Make create the
directory.

There are some ways to fix the issue.  Here, I chose to make MAKE_LD
look like MAKE_C and MAKE_S because bl*_dirs seems the central place
of making directories.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Reported-by: Soren Brinkmann <soren.brinkmann@xilinx.com>
Tested-by: Soren Brinkmann <soren.brinkmann@xilinx.com>
2017-01-19 19:36:29 +09:00
Antonio Nino Diaz 51c5e1a29f Clear static variables in X509 parser on error
In mbedtls_x509_parser.c there are some static arrays that are filled
during the integrity check and then read whenever an authentication
parameter is requested. However, they aren't cleared in case of an
integrity check failure, which can be problematic from a security
point of view. This patch clears these arrays in the case of failure.

Change-Id: I9d48f5bc71fa13e5a75d6c45b5e34796ef13aaa2
Signed-off-by: Antonio Nino Diaz <antonio.ninodiaz@arm.com>
2017-01-19 09:30:32 +00:00
Antonio Nino Diaz c8d64c54c9 Fix declarations of cache maintenance functions
Fix the parameter type of the maintenance functions of data cache.

Add missing declarations for AArch32 versions of dcsw_op_louis and
dcsw_op_all to match the AAch64 ones.

Change-Id: I4226e8ea4f8b2b5bc2972992c83de659ee0da52c
2017-01-19 09:29:15 +00:00
davidcunado-arm f38d93fdbf Merge pull request #801 from masahir0y/cleanup
Macro cleanups
2017-01-18 13:47:06 +00:00
davidcunado-arm faaa9453cf Merge pull request #811 from davidcunado-arm/dc/dc-scratch-pad
Correct system include order
2017-01-18 11:42:42 +00:00
danh-arm 1dd920fc75 Merge pull request #809 from paulkocialkowski/integration
mt8173: Correct SPM MCDI firmware length
2017-01-18 10:55:01 +00:00
danh-arm fc17f61251 Merge pull request #790 from masahir0y/utils
add utility macros to utils.h
2017-01-18 10:54:49 +00:00
Masahiro Yamada 7a2b35d807 qemu: remove unused BL32_SIZE
I do not see any line that references BL32_SIZE.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
2017-01-18 19:33:41 +09:00
Masahiro Yamada 4749705355 Move BL_COHERENT_RAM_BASE/END defines to common_def.h
We have lots of duplicated defines (and comment blocks too).
Move them to include/plat/common/common_def.h.

While we are here, suffix the end address with _END instead of
_LIMIT.  The _END is a better fit to indicate the linker-derived
real end address.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
2017-01-18 19:33:41 +09:00
Masahiro Yamada ecdc898da3 Use *_END instead of *_LIMIT for linker derived end addresses
The usage of _LIMIT seems odd here, so rename as follows:
  BL_CODE_LIMIT     --> BL_CODE_END
  BL_RO_DATA_LIMIT  --> BL_RO_DATA_END
  BL1_CODE_LIMIT    --> BL1_CODE_END
  BL1_RO_DATA_LIMIT --> BL1_RO_DATA_END

Basically, we want to use _LIMIT and _END properly as follows:
  *_SIZE + *_MAX_SIZE = *_LIMIT
  *_SIZE + *_SIZE     = *_END

The _LIMIT is generally defined by platform_def.h to indicate the
platform-dependent memory constraint.  So, its typical usage is
  ASSERT(. <= BL31_LIMIT, "BL31 image has exceeded its limit.")
in a linker script.

On the other hand, _END is used to indicate the end address of the
compiled image, i.e. we do not know it until the image is linked.

Here, all of these macros belong to the latter, so should be
suffixed with _END.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
2017-01-18 19:33:28 +09:00
David Cunado 55c70cb752 Correct system include order
NOTE - this is patch does not address all occurrences of system
includes not being in alphabetical order, just this one case.

Change-Id: I3cd23702d69b1f60a4a9dd7fd4ae27418f15b7a3
2017-01-17 14:40:15 +00:00
Antonio Nino Diaz 29440c1986 libfdt: Replace v1.4.1 by v1.4.2
Delete old version of libfdt at lib/libfdt. Move new libfdt API
headers to include/lib/libfdt and all other files to lib/libfdt.

Change-Id: I32b7888f1f20d62205310e363accbef169ad7b1b
Signed-off-by: Antonio Nino Diaz <antonio.ninodiaz@arm.com>
2017-01-16 17:26:04 +00:00
Antonio Nino Diaz a78676b105 libfdt: Minor changes to enable TF integration
* Add libfdt.mk helper makefile
* Remove unused libfdt files
* Minor changes to fdt.h and libfdt.h to make them C99 compliant

Adapted from 754d78b1b3.

Change-Id: I0847f1c2e6e11f0c899b0b7ecc522c0ad7de210c
Signed-off-by: Antonio Nino Diaz <antonio.ninodiaz@arm.com>
2017-01-16 17:26:04 +00:00
Antonio Nino Diaz cffc9ced68 libfdt: Import libfdt v1.4.2
Import libfdt code from https://git.kernel.org/cgit/utils/dtc/dtc.git
tag "v1.4.2" commit ec02b34c05be04f249ffaaca4b666f5246877dea.

This version includes commit d0b3ab0a0f46ac929b4713da46f7fdcd893dd3bd,
which fixes a buffer overflow in fdt_offset_ptr().

Change-Id: I05a30511ea68417ee7ff26477da3f99e0bd4e06b
Signed-off-by: Antonio Nino Diaz <antonio.ninodiaz@arm.com>
2017-01-16 17:26:04 +00:00
Antonio Nino Diaz 55cdcf75df checkpatch: Fix regular expressions
When generating the list of files to check by checkpatch.pl, the list
generated by `git ls-files` is filtered by a regular expression with
grep. Due to a malformed regex, the dot of `.md` was considered a
wildcard instead of a dot. This patch fixes this so that it matches
only dots, thus allowing the two following files to be checked:

* tools/cert_create/include/cmd_opt.h
* tools/cert_create/src/cmd_opt.c

Also extended the list of library directories to check by checkpatch
to exclude any folder starting with libfdt.

Change-Id: Ie7bf18efe4df29e364e5d67ba1118515304ed9a4
Signed-off-by: Antonio Nino Diaz <antonio.ninodiaz@arm.com>
2017-01-16 17:21:39 +00:00
Masahiro Yamada 11c0a4ff08 fiptool: fix add_image() and add_image_desc() implementation
The "make fip" shows the content of the generated FIP at the end of
the build.  (This is shown by "fiptool info" command.)

Prior to commit e0f083a09b ("fiptool: Prepare ground for expanding
the set of images at runtime"), the last part of the build log of
 make CROSS_COMPILE=aarch64-linux-gnu- BL33=../u-boot/u-boot.bin fip
was like follows:

 Trusted Boot Firmware BL2: offset=0xB0, size=0x4188, cmdline="--tb-fw"
 EL3 Runtime Firmware BL31: offset=0x4238, size=0x6090, cmdline="--soc-fw"
 Non-Trusted Firmware BL33: offset=0xA2C8, size=0x58B51, cmdline="--nt-fw"

With that commit, now it is displayed like follows:

 Non-Trusted Firmware BL33: offset=0xB0, size=0x58B51, cmdline="--nt-fw"
 EL3 Runtime Firmware BL31: offset=0x58C01, size=0x6090, cmdline="--soc-fw"
 Trusted Boot Firmware BL2: offset=0x5EC91, size=0x4188, cmdline="--tb-fw"

You will notice two differences:
  - the contents are displayed in BL33, BL31, BL2 order
  - the offset values are wrong

The latter is more serious, and means "fiptool info" is broken.

Another interesting change is "fiptool update" every time reverses
the image order.  For example, if you input FIP with BL2, BL31, BL33
in this order, the command will pack BL33, BL31, BL2 into FIP, in
this order.  Of course, the order of components is not a big deal
except that users will have poor impression about this.

The root cause is in the implementation of add_image(); the
image_head points to the last added image.  For example, if you call
add_image() for BL2, BL31, BL33 in this order, the resulted image
chain is:

  image_head -> BL33 -> BL31 -> BL2

Then, they are processed from the image_head in "for" loops:

  for (image = image_head; image != NULL; image = image->next) {

This means images are handled in Last-In First-Out manner.

Interestingly, "fiptool create" is still correct because
add_image_desc() also reverses the descriptor order and the command
works as before due to the double reverse.

The implementation of add_image() is efficient, but it made the
situation too complicated.

Let's make image_head point to the first added image.  This will
add_image() inefficient because every call of add_image() follows
the ->next chain to get the tail.  We can solve it by adopting a
nicer linked list structure, but I am not doing as far as that
because we handle only limited number of images anyway.

Do likewise for add_image_desc().

Fixes: e0f083a09b ("fiptool: Prepare ground for expanding the set of images at runtime")
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
2017-01-15 02:58:03 +09:00
Paul Kocialkowski 03be4806fd mt8173: Correct SPM MCDI firmware length
The actual length of the firmware is 1001 32 bit words.

Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
2017-01-14 17:11:12 +01:00
Masahiro Yamada 696ccba690 fiptool: introduce xzalloc() helper function
We often want to zero out allocated memory.

My main motivation for this commit is to set image::next and
image_desc::next to NULL automatically in the next commit.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
2017-01-15 01:07:20 +09:00
davidcunado-arm 44f1c0bded Merge pull request #807 from nmenon/upstream/fix-16650-rx
uart: 16550: Fix getc
2017-01-13 17:18:59 +00:00
davidcunado-arm fc7c870bbf Merge pull request #797 from dp-arm/dp/fiptool-improvements
fiptool: Add support for operating on binary blobs using the UUID
2017-01-13 15:52:49 +00:00
Masahiro Yamada 152c8c11b7 utils: move BIT(n) macro to utils.h
We are duplicating this macro define, and it is useful enough
to be placed in the common place.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
2017-01-13 04:34:24 +09:00
danh-arm 9eb4d4dd93 Merge pull request #796 from masahir0y/build
Improve dependency file generation
2017-01-11 14:54:29 +00:00
Nishanth Menon 861ac52a7e uart: 16550: Fix getc
tbz check for RDR status is to check for a bit being zero.
Unfortunately, we are using a mask rather than the bit position.

Further as per http://www.ti.com/lit/ds/symlink/pc16550d.pdf (page 17),
LSR register bit 0 is Data ready status (RDR), not bit position 2.

Update the same to match the specification.

Reported-by: Sekhar Nori <nsekhar@ti.com>
Signed-off-by: Nishanth Menon <nm@ti.com>
2017-01-10 09:36:44 -06:00
danh-arm 236c27d21f Merge pull request #805 from Xilinx/zynqmp/addr_space_size
zynqmp: Migrate to new address space macros
2017-01-10 11:12:08 +00:00
danh-arm 3140d960c6 Merge pull request #803 from masahir0y/tbb
TBB: fix comment about MBEDTLS_KEY_ALG default
2017-01-10 11:11:54 +00:00
danh-arm 85dfa594ad Merge pull request #802 from pgeorgi/rk3399m0
rockchip: Build m0 firmware without standard libraries
2017-01-10 11:11:44 +00:00
Soren Brinkmann 7b2a268e53 zynqmp: Migrate to new address space macros
Commit 0029624fe2 ("Add
PLAT_xxx_ADDR_SPACE_SIZE definition") deprecates 'ADDR_SPACE_SIZE' in
favor of PLAT_(PHY|VIRT)_ADDRESS_SPACE_SIZE. Migrate the zynqmp platform
to use the new interface.

Signed-off-by: Soren Brinkmann <soren.brinkmann@xilinx.com>
2017-01-06 11:07:00 -08:00
Masahiro Yamada a56f87c8b9 TBB: fix comment about MBEDTLS_KEY_ALG default
This comment block says the default algorithm is ESDSA, while the
code obviously sets the default to RSA:

  ifeq (${MBEDTLS_KEY_ALG},)
      MBEDTLS_KEY_ALG            :=      rsa
  endif

The git log of commit 7d37aa1711 ("TBB: add mbedTLS authentication
related libraries") states available options are:

  * 'rsa' (for RSA-2048) (default option)
  * 'ecdsa' (for ECDSA-SECP256R1)

So, my best guess is the comment block is wrong.

The mismatch between the code and the comment is confusing. Fix it.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
2017-01-06 16:58:34 +09:00
Masahiro Yamada 1d274ab00f Build: add -MP option to add dummy rules to *.d files
This adds a phony target for each dependency other than the main
file, causing each to depend on nothing.

Without this, the incremental build will fail when a header file
is removed.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
2017-01-05 11:39:19 +09:00
Masahiro Yamada 710ea1d01a Build: generate .d file at the same time as object is created
Currently, .d files are generated before any objects are built.
So, IS_ANYTHING_TO_BUILD flag is needed to avoid such processing for
non-build targets.

There is a cleverer way; just create a .d file simultaneously when
the corresponding object is created.  No need to have separate rules
for .d files.

This commit will also fix a bug; -D$(IMAGE) is defined for $(OBJ),
but not for $(PREREQUISITES).  So, .d files are generated with
different macro sets from those for .o files, then wrong .d files
are generated.

For example, in lib/cpus/aarch64/cpu_helpers.S

  #if IMAGE_BL31
  #include <cpu_data.h>
  #endif

<cpu_data.h> is parsed for the object when built for BL31, but the
.d file does not pick up that dependency.

With this commit, the compiler will generate .o and .d at the same
time, guaranteeing they are generated under the same circumstances.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
2017-01-05 11:39:16 +09:00
Masahiro Yamada 59de50963c Build: use CPP just for pre-processing
Using AS for pre-processing looks a bit weird, and some assembly
specific options are given for nothing.  Rather, use CPP.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
2017-01-05 11:35:59 +09:00
Masahiro Yamada f2e1d57e43 Build: exclude -c flag from TF_CFLAGS
The -c flag should not be included in the global variable TF_CFLAGS;
it should be specified in the build rule only when its target is a
*.o file.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
2017-01-05 11:25:13 +09:00
Patrick Georgi 742df4f614 rockchip: Build m0 firmware without standard libraries
Depending on the compiler used, it might try to link in libc even though
it's not required. Stop it from doing that.

Signed-off-by: Patrick Georgi <pgeorgi@google.com>
2017-01-04 19:06:14 +01:00
dp-arm d02fcebeb0 fiptool: Factor out setting of image descriptor action
An image descriptor contains an action and an argument.  The action
indicates the intended operation, as requested by the user.  It can be
pack, unpack or remove.  Factor out setting those fields to a separate
function to minimize code duplication across the various commands that
modify these fields.

Change-Id: I1682958e8e83c4884e435cff6d0833c67726461f
Signed-off-by: dp-arm <dimitris.papastamos@arm.com>
2016-12-30 14:22:10 +00:00
dp-arm b63f970e8e fiptool: Remove unreferenced variable `toc_entries_len`
Change-Id: If279680a71e7fa1f801d79b8bc2cd47cd9905d33
Signed-off-by: dp-arm <dimitris.papastamos@arm.com>
2016-12-30 09:23:38 +00:00