mcuboot/boot/zephyr/os.c

56 lines
1.6 KiB
C
Raw Normal View History

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
#include <zephyr.h>
#include <string.h>
#include "os/os_heap.h"
zephyr: migrate signature type to Kconfig Handle the CONFIG_BOOT_SIGNATURE_TYPE_xxx values in Zephyr's mcuboot_config.h by converting them into the platform-agnostic MCUboot definitions. This requires some changes to the way the release test Makefile is structured, since Kconfig symbols cannot be set from the command line. Instead, use the OVERLAY_CONFIG feature of the Zephyr build system, which allows specifying extra fragments to merge into the final .config. (This is an orthogonal mechanism to setting CONF_FILE; it is used by Zephyr's CI script sanitycheck to add additional fragments, so it's appropriate for use by MCUboot's testing scripts as well.) We additionally need to move to a single prj.conf file due to a dependency issue. We can no longer determine CONF_FILE from the signature type, since that is now determined from the final .config or autoconf.h, which is a build output that depends on CONF_FILE. To move to a single prj.conf: - delete prj-p256.conf and adjust prj.conf to serve both signature types - add a top-level mbedTLS configuration file which dispatches to the right sub-header depending on the key type - as a side effect, have the simulator pick the right config file depending on the case This fixes and cleans up quite a bit of the signature type handling, which had become something of a mess over time. For example, it fixes a bug in ECDSA mode's configuration that wasn't actually selecting config-asn1.h, and forces the simulator to use the same mbedTLS configuration file as builds for real hardware. Finally, we also have to move the mbedTLS vs. TinyCrypt choice into mcuboot_config.h at the same time as well, since CMakeLists.txt was making that decision based on the signature type. Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2018-04-13 01:02:38 +08:00
#ifdef CONFIG_BOOT_USE_MBEDTLS
#include <mbedtls/platform.h>
#include <mbedtls/memory_buffer_alloc.h>
/*
* This is the heap for mbed TLS. The value needed depends on the key
* size and algorithm used. For RSA-2048 signing, 6144 bytes seems to be
* enough. When using RSA-2048-OAEP encryption + RSA-2048 signing, 10240
* bytes seem to be enough.
*/
#if !defined(CONFIG_BOOT_ENCRYPT_RSA)
#define CRYPTO_HEAP_SIZE 6144
#else
#define CRYPTO_HEAP_SIZE 10240
#endif
static unsigned char mempool[CRYPTO_HEAP_SIZE];
/*
* Initialize mbedtls to be able to use the local heap.
*/
void os_heap_init(void)
{
mbedtls_memory_buffer_alloc_init(mempool, sizeof(mempool));
}
#else
void os_heap_init(void)
{
}
#endif