Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions boot/bootutil/src/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Makefile for Zephyr build

ccflags-y += -DBOOTUTIL_SIGN_RSA

obj-y += loader.o bootutil_misc.o image_validate.o image_rsa.o
8 changes: 1 addition & 7 deletions boot/bootutil/src/loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -484,14 +484,8 @@ boot_write_status(struct boot_status *bs)
static int
boot_image_check(struct image_header *hdr, const struct flash_area *fap)
{
static void *tmpbuf;
static uint8_t tmpbuf[BOOT_TMPBUF_SZ];

if (!tmpbuf) {
tmpbuf = malloc(BOOT_TMPBUF_SZ);
if (!tmpbuf) {
return BOOT_ENOMEM;
}
}
if (bootutil_img_validate(hdr, fap, tmpbuf, BOOT_TMPBUF_SZ,
NULL, 0, NULL)) {
return BOOT_EBADIMAGE;
Expand Down
4 changes: 4 additions & 0 deletions zephyr/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
BOARD ?= qemu_x86
CONF_FILE = prj.conf

include ${ZEPHYR_BASE}/Makefile.inc
6 changes: 6 additions & 0 deletions zephyr/build_boot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#! /bin/bash

source $(dirname 0)/target.sh
source ../../zephyr/zephyr-env.sh

make BOARD=$BOARD "$@"
96 changes: 96 additions & 0 deletions zephyr/include/flash_map/flash_map.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* 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.
*/

#ifndef H_UTIL_FLASH_MAP_
#define H_UTIL_FLASH_MAP_

#ifdef __cplusplus
extern "C" {
#endif

/**
*
* Provides abstraction of flash regions for type of use.
* I.e. dude where's my image?
*
* System will contain a map which contains flash areas. Every
* region will contain flash identifier, offset within flash and length.
*
* 1. This system map could be in a file within filesystem (Initializer
* must know/figure out where the filesystem is at).
* 2. Map could be at fixed location for project (compiled to code)
* 3. Map could be at specific place in flash (put in place at mfg time).
*
* Note that the map you use must be valid for BSP it's for,
* match the linker scripts when platform executes from flash,
* and match the target offset specified in download script.
*/
#include <inttypes.h>

struct flash_area {
uint8_t fa_id;
uint8_t fa_device_id;
uint16_t pad16;
uint32_t fa_off;
uint32_t fa_size;
};

extern const struct flash_area *flash_map;
extern int flash_map_entries;

/*
* Initializes flash map. Memory will be referenced by flash_map code
* from this on.
*/
void flash_map_init(void);

/*
* Start using flash area.
*/
int flash_area_open(uint8_t id, const struct flash_area **);

void flash_area_close(const struct flash_area *);

/*
* Read/write/erase. Offset is relative from beginning of flash area.
*/
int flash_area_read(const struct flash_area *, uint32_t off, void *dst,
uint32_t len);
int flash_area_write(const struct flash_area *, uint32_t off, const void *src,
uint32_t len);
int flash_area_erase(const struct flash_area *, uint32_t off, uint32_t len);

/*
* Alignment restriction for flash writes.
*/
uint8_t flash_area_align(const struct flash_area *);

/*
* Given flash map index, return info about sectors within the area.
*/
int flash_area_to_sectors(int idx, int *cnt, struct flash_area *ret);

int flash_area_id_from_image_slot(int slot);
int flash_area_id_to_image_slot(int area_id);

#ifdef __cplusplus
}
#endif

#endif /* H_UTIL_FLASH_MAP_ */
79 changes: 79 additions & 0 deletions zephyr/include/hal/hal_bsp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* 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.
*/

#ifndef __HAL_BSP_H_
#define __HAL_BSP_H_

#ifdef __cplusplus
extern "C" {
#endif

#include <inttypes.h>

/*
* Initializes BSP; registers flash_map with the system.
*/
void hal_bsp_init(void);

/*
* Return pointer to flash device structure, given BSP specific
* flash id.
*/
struct hal_flash;
const struct hal_flash *hal_bsp_flash_dev(uint8_t flash_id);

/*
* Grows heap by given amount. XXX giving space back not implemented.
*/
void *_sbrk(int incr);

/*
* Report which memory areas should be included inside a coredump.
*/
struct hal_bsp_mem_dump {
void *hbmd_start;
uint32_t hbmd_size;
};

const struct hal_bsp_mem_dump *hal_bsp_core_dump(int *area_cnt);

/*
* Get unique HW identifier/serial number for platform.
* Returns the number of bytes filled in.
*/
#define HAL_BSP_MAX_ID_LEN 32
int hal_bsp_hw_id(uint8_t *id, int max_len);

#define HAL_BSP_POWER_ON (1)
#define HAL_BSP_POWER_WFI (2)
#define HAL_BSP_POWER_SLEEP (3)
#define HAL_BSP_POWER_DEEP_SLEEP (4)
#define HAL_BSP_POWER_OFF (5)
#define HAL_BSP_POWER_PERUSER (128)

int hal_bsp_power_state(int state);

/* Returns priority of given interrupt number */
uint32_t hal_bsp_get_nvic_priority(int irq_num, uint32_t pri);

#ifdef __cplusplus
}
#endif

#endif
43 changes: 43 additions & 0 deletions zephyr/include/hal/hal_flash.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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.
*/

#ifndef H_HAL_FLASH_
#define H_HAL_FLASH_

#ifdef __cplusplus
extern "C" {
#endif

#include <inttypes.h>

int hal_flash_read(uint8_t flash_id, uint32_t address, void *dst,
uint32_t num_bytes);
int hal_flash_write(uint8_t flash_id, uint32_t address, const void *src,
uint32_t num_bytes);
int hal_flash_erase_sector(uint8_t flash_id, uint32_t sector_address);
int hal_flash_erase(uint8_t flash_id, uint32_t address, uint32_t num_bytes);
uint8_t hal_flash_align(uint8_t flash_id);
int hal_flash_init(void);


#ifdef __cplusplus
}
#endif

#endif /* H_HAL_FLASH_ */
Empty file added zephyr/include/os/os.h
Empty file.
38 changes: 38 additions & 0 deletions zephyr/include/os/os_heap.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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.
*/

#ifndef H_OS_HEAP_
#define H_OS_HEAP_

#include <stddef.h>

#ifdef __cplusplus
extern "C" {
#endif

void *os_malloc(size_t size);
void os_free(void *mem);
void *os_realloc(void *ptr, size_t size);

#ifdef __cplusplus
}
#endif

#endif

42 changes: 42 additions & 0 deletions zephyr/include/os/os_malloc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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.
*/

#ifndef H_OS_MALLOC_
#define H_OS_MALLOC_

#include "os/os_heap.h"

#ifdef __cplusplus
extern "C" {
#endif

#undef malloc
#define malloc os_malloc

#undef free
#define free os_free

#undef realloc
#define realloc os_realloc

#ifdef __cplusplus
}
#endif

#endif
6 changes: 6 additions & 0 deletions zephyr/include/syscfg/syscfg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef __SYSCFG_H__
#define __SYSCFG_H__

#define MYNEWT_VAL(x) (x)

#endif /* __SYSCFG_H__ */
10 changes: 10 additions & 0 deletions zephyr/include/sysflash/sysflash.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* Manual version of auto-generated version. */

#ifndef __SYSFLASH_H__
#define __SYSFLASH_H__

#define FLASH_AREA_IMAGE_0 1
#define FLASH_AREA_IMAGE_1 2
#define FLASH_AREA_IMAGE_SCRATCH 3

#endif /* __SYSFLASH_H__ */
14 changes: 14 additions & 0 deletions zephyr/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
CONFIG_CONSOLE_HANDLER=y
CONFIG_PRINTK=y
CONFIG_DEBUG=y

CONFIG_MAIN_STACK_SIZE=10240
CONFIG_MBEDTLS=y
CONFIG_MBEDTLS_BUILTIN=y
CONFIG_MBEDTLS_CFG_FILE="config-boot.h"

### mbedTLS wants a heap
CONFIG_HEAP_MEM_POOL_SIZE=16384

CONFIG_FLASH=y
CONFIG_SOC_FLASH_STM32F4=y
8 changes: 8 additions & 0 deletions zephyr/src/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
subdir-ccflags-y += -I$(PROJECT)/../boot/bootutil/include
subdir-ccflags-y += -I$(PROJECT)/include

obj-y += main.o
obj-y += flash_map.o hal_flash.o os.o
obj-y += keys.o

obj-y += ../../boot/bootutil/src/
Loading