Skip to content

Commit 4c2662d

Browse files
committed
This closes #1.
Merge remote-tracking branch 'd3zd3z/zephyr'
2 parents bd14468 + 5153bd6 commit 4c2662d

File tree

20 files changed

+740
-7
lines changed

20 files changed

+740
-7
lines changed

boot/bootutil/src/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Makefile for Zephyr build
2+
3+
ccflags-y += -DBOOTUTIL_SIGN_RSA
4+
5+
obj-y += loader.o bootutil_misc.o image_validate.o image_rsa.o

boot/bootutil/src/loader.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -527,14 +527,8 @@ boot_write_status(struct boot_status *bs)
527527
static int
528528
boot_image_check(struct image_header *hdr, const struct flash_area *fap)
529529
{
530-
static void *tmpbuf;
530+
static uint8_t tmpbuf[BOOT_TMPBUF_SZ];
531531

532-
if (!tmpbuf) {
533-
tmpbuf = malloc(BOOT_TMPBUF_SZ);
534-
if (!tmpbuf) {
535-
return BOOT_ENOMEM;
536-
}
537-
}
538532
if (bootutil_img_validate(hdr, fap, tmpbuf, BOOT_TMPBUF_SZ,
539533
NULL, 0, NULL)) {
540534
return BOOT_EBADIMAGE;

zephyr/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
BOARD ?= qemu_x86
2+
CONF_FILE = prj.conf
3+
4+
include ${ZEPHYR_BASE}/Makefile.inc

zephyr/build_boot.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#! /bin/bash
2+
3+
source $(dirname 0)/target.sh
4+
source ../../zephyr/zephyr-env.sh
5+
6+
make BOARD=$BOARD "$@"
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
#ifndef H_UTIL_FLASH_MAP_
21+
#define H_UTIL_FLASH_MAP_
22+
23+
#ifdef __cplusplus
24+
extern "C" {
25+
#endif
26+
27+
/**
28+
*
29+
* Provides abstraction of flash regions for type of use.
30+
* I.e. dude where's my image?
31+
*
32+
* System will contain a map which contains flash areas. Every
33+
* region will contain flash identifier, offset within flash and length.
34+
*
35+
* 1. This system map could be in a file within filesystem (Initializer
36+
* must know/figure out where the filesystem is at).
37+
* 2. Map could be at fixed location for project (compiled to code)
38+
* 3. Map could be at specific place in flash (put in place at mfg time).
39+
*
40+
* Note that the map you use must be valid for BSP it's for,
41+
* match the linker scripts when platform executes from flash,
42+
* and match the target offset specified in download script.
43+
*/
44+
#include <inttypes.h>
45+
46+
struct flash_area {
47+
uint8_t fa_id;
48+
uint8_t fa_device_id;
49+
uint16_t pad16;
50+
uint32_t fa_off;
51+
uint32_t fa_size;
52+
};
53+
54+
extern const struct flash_area *flash_map;
55+
extern int flash_map_entries;
56+
57+
/*
58+
* Initializes flash map. Memory will be referenced by flash_map code
59+
* from this on.
60+
*/
61+
void flash_map_init(void);
62+
63+
/*
64+
* Start using flash area.
65+
*/
66+
int flash_area_open(uint8_t id, const struct flash_area **);
67+
68+
void flash_area_close(const struct flash_area *);
69+
70+
/*
71+
* Read/write/erase. Offset is relative from beginning of flash area.
72+
*/
73+
int flash_area_read(const struct flash_area *, uint32_t off, void *dst,
74+
uint32_t len);
75+
int flash_area_write(const struct flash_area *, uint32_t off, const void *src,
76+
uint32_t len);
77+
int flash_area_erase(const struct flash_area *, uint32_t off, uint32_t len);
78+
79+
/*
80+
* Alignment restriction for flash writes.
81+
*/
82+
uint8_t flash_area_align(const struct flash_area *);
83+
84+
/*
85+
* Given flash map index, return info about sectors within the area.
86+
*/
87+
int flash_area_to_sectors(int idx, int *cnt, struct flash_area *ret);
88+
89+
int flash_area_id_from_image_slot(int slot);
90+
int flash_area_id_to_image_slot(int area_id);
91+
92+
#ifdef __cplusplus
93+
}
94+
#endif
95+
96+
#endif /* H_UTIL_FLASH_MAP_ */

zephyr/include/hal/hal_bsp.h

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
#ifndef __HAL_BSP_H_
21+
#define __HAL_BSP_H_
22+
23+
#ifdef __cplusplus
24+
extern "C" {
25+
#endif
26+
27+
#include <inttypes.h>
28+
29+
/*
30+
* Initializes BSP; registers flash_map with the system.
31+
*/
32+
void hal_bsp_init(void);
33+
34+
/*
35+
* Return pointer to flash device structure, given BSP specific
36+
* flash id.
37+
*/
38+
struct hal_flash;
39+
const struct hal_flash *hal_bsp_flash_dev(uint8_t flash_id);
40+
41+
/*
42+
* Grows heap by given amount. XXX giving space back not implemented.
43+
*/
44+
void *_sbrk(int incr);
45+
46+
/*
47+
* Report which memory areas should be included inside a coredump.
48+
*/
49+
struct hal_bsp_mem_dump {
50+
void *hbmd_start;
51+
uint32_t hbmd_size;
52+
};
53+
54+
const struct hal_bsp_mem_dump *hal_bsp_core_dump(int *area_cnt);
55+
56+
/*
57+
* Get unique HW identifier/serial number for platform.
58+
* Returns the number of bytes filled in.
59+
*/
60+
#define HAL_BSP_MAX_ID_LEN 32
61+
int hal_bsp_hw_id(uint8_t *id, int max_len);
62+
63+
#define HAL_BSP_POWER_ON (1)
64+
#define HAL_BSP_POWER_WFI (2)
65+
#define HAL_BSP_POWER_SLEEP (3)
66+
#define HAL_BSP_POWER_DEEP_SLEEP (4)
67+
#define HAL_BSP_POWER_OFF (5)
68+
#define HAL_BSP_POWER_PERUSER (128)
69+
70+
int hal_bsp_power_state(int state);
71+
72+
/* Returns priority of given interrupt number */
73+
uint32_t hal_bsp_get_nvic_priority(int irq_num, uint32_t pri);
74+
75+
#ifdef __cplusplus
76+
}
77+
#endif
78+
79+
#endif

zephyr/include/hal/hal_flash.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
#ifndef H_HAL_FLASH_
21+
#define H_HAL_FLASH_
22+
23+
#ifdef __cplusplus
24+
extern "C" {
25+
#endif
26+
27+
#include <inttypes.h>
28+
29+
int hal_flash_read(uint8_t flash_id, uint32_t address, void *dst,
30+
uint32_t num_bytes);
31+
int hal_flash_write(uint8_t flash_id, uint32_t address, const void *src,
32+
uint32_t num_bytes);
33+
int hal_flash_erase_sector(uint8_t flash_id, uint32_t sector_address);
34+
int hal_flash_erase(uint8_t flash_id, uint32_t address, uint32_t num_bytes);
35+
uint8_t hal_flash_align(uint8_t flash_id);
36+
int hal_flash_init(void);
37+
38+
39+
#ifdef __cplusplus
40+
}
41+
#endif
42+
43+
#endif /* H_HAL_FLASH_ */

zephyr/include/os/os.h

Whitespace-only changes.

zephyr/include/os/os_heap.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
#ifndef H_OS_HEAP_
21+
#define H_OS_HEAP_
22+
23+
#include <stddef.h>
24+
25+
#ifdef __cplusplus
26+
extern "C" {
27+
#endif
28+
29+
void *os_malloc(size_t size);
30+
void os_free(void *mem);
31+
void *os_realloc(void *ptr, size_t size);
32+
33+
#ifdef __cplusplus
34+
}
35+
#endif
36+
37+
#endif
38+

zephyr/include/os/os_malloc.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
#ifndef H_OS_MALLOC_
21+
#define H_OS_MALLOC_
22+
23+
#include "os/os_heap.h"
24+
25+
#ifdef __cplusplus
26+
extern "C" {
27+
#endif
28+
29+
#undef malloc
30+
#define malloc os_malloc
31+
32+
#undef free
33+
#define free os_free
34+
35+
#undef realloc
36+
#define realloc os_realloc
37+
38+
#ifdef __cplusplus
39+
}
40+
#endif
41+
42+
#endif

0 commit comments

Comments
 (0)