Skip to content

Commit 6fbdb3b

Browse files
committed
zybo support
1 parent 0fc2d7c commit 6fbdb3b

18 files changed

+1590
-20
lines changed

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export CROSS_COMPILE:= arm-none-eabi-
1111
export SDK_PATH = $(CURDIR)
1212

1313
#export CROSS_COMPILE = /opt/CodeSourcery/arm-xilinx-gnueabi/bin/arm-xilinx-eabi-
14+
export CROSS_COMPILE = /opt/Linaro/gcc-linaro-7.1.1-2017.08-x86_64_arm-eabi/bin/arm-eabi-
1415

1516
all:
1617
echo 'LTZVisor builds start'

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
LTZVisor_version = 0.2.0
1+
LTZVisor_version = 0.2.2

bootloader/zybo/BOOT.bin

2.26 MB
Binary file not shown.

src/boards/zedboard/zynq_ttc.c

+14-14
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ Zynq_Ttc * const Ptr_Ttc[NUM_TTC] = {(Zynq_Ttc *)TTC0_BASE, (Zynq_Ttc *)TTC1_BAS
6363
*/
6464
uint32_t ttc_init(uint32_t ttc_num, uint32_t timer_num, uint32_t mode){
6565

66-
Zynq_Ttc * ptr_ttc;
67-
uint32_t clk_cntrl;
66+
Zynq_Ttc * ptr_ttc = NULL;
67+
uint32_t clk_cntrl = 0;
6868

6969
/** Check Arguments */
7070
if( (ttc_num > TTC1) || (timer_num > TTCx_2) || (mode > FREE_RUNNING) ){
@@ -119,8 +119,8 @@ uint32_t ttc_init(uint32_t ttc_num, uint32_t timer_num, uint32_t mode){
119119
*/
120120
uint32_t ttc_enable(uint32_t ttc_num, uint32_t timer_num){
121121

122-
Zynq_Ttc * ptr_ttc;
123-
uint32_t cnt_cntrl;
122+
Zynq_Ttc * ptr_ttc = NULL;
123+
uint32_t cnt_cntrl = 0;
124124

125125
/** Check Arguments */
126126
if( (ttc_num > TTC1) || (timer_num > TTCx_2)){
@@ -150,8 +150,8 @@ uint32_t ttc_enable(uint32_t ttc_num, uint32_t timer_num){
150150
*/
151151
uint32_t ttc_disable(uint32_t ttc_num, uint32_t timer_num){
152152

153-
Zynq_Ttc * ptr_ttc;
154-
uint32_t cnt_cntrl;
153+
Zynq_Ttc * ptr_ttc = NULL;
154+
uint32_t cnt_cntrl = 0;
155155

156156
/** Check Arguments */
157157
if( (ttc_num > TTC1) || (timer_num > TTCx_2)){
@@ -180,9 +180,9 @@ uint32_t ttc_disable(uint32_t ttc_num, uint32_t timer_num){
180180
*/
181181
uint32_t ttc_request(uint32_t ttc_num, uint32_t timer_num, uint32_t useconds){
182182

183-
Zynq_Ttc * ptr_ttc;
184-
uint32_t cnt_cntrl;
185-
uint32_t clk_cntrl;
183+
Zynq_Ttc * ptr_ttc = NULL;
184+
uint32_t cnt_cntrl = 0;
185+
uint32_t clk_cntrl = 0;
186186

187187
/** Check Arguments */
188188
if( (ttc_num > TTC1) || (timer_num > TTCx_2)){
@@ -248,10 +248,10 @@ uint32_t ttc_request(uint32_t ttc_num, uint32_t timer_num, uint32_t useconds){
248248
*/
249249
uint32_t ttc_interrupt_clear(uint32_t interrupt){
250250

251-
Zynq_Ttc * ptr_ttc;
252-
uint32_t ttc_num;
253-
uint32_t interrupt_reg;
254-
uint32_t ttc_tim_num;
251+
Zynq_Ttc * ptr_ttc = NULL;
252+
uint32_t ttc_num = 0;
253+
uint32_t interrupt_reg = 0;
254+
uint32_t ttc_tim_num = 0;
255255

256256
/** Check which TTC_timer generated the Interrupt */
257257
switch (interrupt){
@@ -289,7 +289,7 @@ uint32_t ttc_interrupt_clear(uint32_t interrupt){
289289
/** Clear Interrupt Status Flag */
290290
interrupt_reg = ptr_ttc->interrupt_reg[ttc_tim_num];
291291

292-
return TRUE;
292+
return interrupt_reg;
293293
}
294294

295295

src/boards/zybo/board.c

+121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/*
2+
* LTZVisor, a Lightweight TrustZone-assisted Hypervisor
3+
*
4+
* Copyright (c) TZVisor Project (www.tzvisor.org), 2017-
5+
*
6+
* Authors:
7+
* Sandro Pinto <[email protected]>
8+
* Jorge Pereira <[email protected]>
9+
*
10+
* This file is part of LTZVisor.
11+
*
12+
* LTZVisor is free software; you can redistribute it and/or modify
13+
* it under the terms of the GNU General Public License version 2
14+
* as published by the Free Software Foundation, with a special
15+
* exception described below.
16+
*
17+
* Linking this code statically or dynamically with other modules
18+
* is making a combined work based on this code. Thus, the terms
19+
* and conditions of the GNU General Public License V2 cover the
20+
* whole combination.
21+
*
22+
* As a special exception, the copyright holders of LTZVisor give
23+
* you permission to link LTZVisor with independent modules to
24+
* produce a statically linked executable, regardless of the license
25+
* terms of these independent modules, and to copy and distribute
26+
* the resulting executable under terms of your choice, provided that
27+
* you also meet, for each linked independent module, the terms and
28+
* conditions of the license of that module. An independent module
29+
* is a module which is not derived from or based on LTZVisor.
30+
*
31+
* LTZVisor is distributed in the hope that it will be useful, but
32+
* WITHOUT ANY WARRANTY; without even the implied warranty of
33+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34+
* GNU General Public License for more details.
35+
*
36+
* You should have received a copy of the GNU General Public License
37+
* along with this program; if not, write to the Free Software
38+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
39+
* 02110-1301 USA.
40+
*
41+
* [board.c]
42+
*
43+
* This file contains board-specific initializations.
44+
*
45+
* (#) $id: board.c 15-10-2015 s_pinto & j_pereira $
46+
* (#) $id: board.c 20-09-2017 s_pinto (modified)$
47+
*/
48+
49+
#include <board.h>
50+
51+
/**
52+
* TrustZone-specific initializations
53+
*
54+
* @param
55+
*
56+
* @retval
57+
*/
58+
uint32_t board_init(void){
59+
60+
/** Unlocking SLCR register */
61+
write32( (void *)SLCR_UNLOCK, SLCR_UNLOCK_KEY);
62+
63+
/** Handling memory security */
64+
write32( (void *)TZ_OCM_RAM0, 0xffffffff);
65+
write32( (void *)TZ_OCM_RAM1, 0xffffffff);
66+
write32( (void *)TZ_OCM, 0xffffffff);
67+
/* Handling DDR memory security (first 14segments NS)l */
68+
write32( (void *)TZ_DDR_RAM, 0x0000007f);
69+
printk(" * Memory security - OK \n\t");
70+
71+
/** Handling devices security */
72+
/* SDIO0 slave security (NS) */
73+
write32( (void *)SECURITY2_SDIO0, 0x1);
74+
/* SDIO1 slave security (NS) */
75+
write32( (void *)SECURITY3_SDIO1, 0x1);
76+
/* QSPI slave security (NS) */
77+
write32( (void *)SECURITY4_QSPI, 0x1);
78+
/* APB slave security (NS) */
79+
write32( (void *) SECURITY6_APBSL, 0x00007fff);
80+
/* DMA slave security (S) */
81+
write32( (void *)TZ_DMA_NS, 0x0);
82+
write32( (void *)TZ_DMA_IRQ_NS, 0x0);
83+
/* Ethernet security */
84+
write32( (void *)TZ_GEM, 0x3);
85+
/* FPGA AFI AXI ports TrustZone */
86+
write32( (void *)SECURITY_APB, 0x3F);
87+
/* Handling more devices ... */
88+
printk(" * Devices security - OK \n\t");
89+
90+
/** Locking SLCR register */
91+
write32( (void *)SLCR_LOCK, SLCR_LOCK_KEY);
92+
93+
return TRUE;
94+
}
95+
96+
/**
97+
* Handling syscalls (SMCs)
98+
*
99+
* @param
100+
*
101+
* @retval
102+
*/
103+
uint32_t board_handler(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint32_t arg3)
104+
{
105+
switch(arg0) {
106+
case (LTZVISOR_READ_SYSCALL):{
107+
arg0 = read32((volatile void*)arg1);
108+
break;
109+
}
110+
case (LTZVISOR_WRITE_SYSCALL):{
111+
write32( (volatile void*)arg1, arg2);
112+
break;
113+
}
114+
default:
115+
116+
break;
117+
}
118+
119+
return arg0;
120+
}
121+

src/boards/zybo/inc/board.h

+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
* LTZVisor, a Lightweight TrustZone-assisted Hypervisor
3+
*
4+
* Copyright (c) TZVisor Project (www.tzvisor.org), 2017-
5+
*
6+
* Authors:
7+
* Sandro Pinto <[email protected]>
8+
* Jorge Pereira <[email protected]>
9+
*
10+
* This file is part of LTZVisor.
11+
*
12+
* LTZVisor is free software; you can redistribute it and/or modify
13+
* it under the terms of the GNU General Public License version 2
14+
* as published by the Free Software Foundation, with a special
15+
* exception described below.
16+
*
17+
* Linking this code statically or dynamically with other modules
18+
* is making a combined work based on this code. Thus, the terms
19+
* and conditions of the GNU General Public License V2 cover the
20+
* whole combination.
21+
*
22+
* As a special exception, the copyright holders of LTZVisor give
23+
* you permission to link LTZVisor with independent modules to
24+
* produce a statically linked executable, regardless of the license
25+
* terms of these independent modules, and to copy and distribute
26+
* the resulting executable under terms of your choice, provided that
27+
* you also meet, for each linked independent module, the terms and
28+
* conditions of the license of that module. An independent module
29+
* is a module which is not derived from or based on LTZVisor.
30+
*
31+
* LTZVisor is distributed in the hope that it will be useful, but
32+
* WITHOUT ANY WARRANTY; without even the implied warranty of
33+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34+
* GNU General Public License for more details.
35+
*
36+
* You should have received a copy of the GNU General Public License
37+
* along with this program; if not, write to the Free Software
38+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
39+
* 02110-1301 USA.
40+
*
41+
* [board.h]
42+
*
43+
* This file contains board-specific initializations (header).
44+
*
45+
* (#) $id: board.h 15-10-2015 s_pinto & j_pereira $
46+
* (#) $id: board.h 20-09-2017 s_pinto (modified)$
47+
*/
48+
49+
#ifndef __BOARD_H
50+
#define __BOARD_H
51+
52+
#include <types.h>
53+
#include <io.h>
54+
#include <ltzvisor.h>
55+
#include <ltzvisor_syscall_asm.h>
56+
#include <zynq_ttc.h>
57+
58+
/** TrustZone on Xilinx Zynq-7000 (UG1019) */
59+
60+
#define SECURITY_MOD2 0xE0200000
61+
#define SECURITY2_SDIO0 (SECURITY_MOD2 + 0x8)
62+
#define SECURITY3_SDIO1 (SECURITY_MOD2 + 0xC)
63+
#define SECURITY4_QSPI (SECURITY_MOD2 + 0x10)
64+
#define SECURITY5_MIOU (SECURITY_MOD2 + 0x14)
65+
#define SECURITY6_APBSL (SECURITY_MOD2 + 0x18)
66+
#define SECURITY7_SMC (SECURITY_MOD2 + 0x1C)
67+
68+
#define SLCR_BASE 0xF8000000
69+
#define SLCR_LOCK_KEY 0x767B
70+
#define SLCR_UNLOCK_KEY 0xDF0D
71+
#define SLCR_LOCK (SLCR_BASE + 0x4)
72+
#define SLCR_UNLOCK (SLCR_BASE + 0x8)
73+
#define DMAC_RST_CTRL (SLCR_BASE + 0x20C)
74+
#define TZ_OCM_RAM0 (SLCR_BASE + 0x400)
75+
#define TZ_OCM_RAM1 (SLCR_BASE + 0x404)
76+
#define TZ_OCM (SLCR_BASE + 0x408)
77+
#define TZ_DDR_RAM (SLCR_BASE + 0x430)
78+
#define TZ_DMA_NS (SLCR_BASE + 0x440)
79+
#define TZ_DMA_IRQ_NS (SLCR_BASE + 0x444)
80+
#define TZ_DMA_PERIPH_NS (SLCR_BASE + 0x448)
81+
#define TZ_GEM (SLCR_BASE + 0x450)
82+
#define TZ_SDIO (SLCR_BASE + 0x454)
83+
#define TZ_USB (SLCR_BASE + 0x458)
84+
#define TZ_FPGA_M (SLCR_BASE + 0x484)
85+
#define TZ_FPGA_AFI (SLCR_BASE + 0x488)
86+
87+
#define SECURITY_MOD3 0xF8900000
88+
#define SECURITY_FSSW_S0 (SECURITY_MOD3 + 0x1C)
89+
#define SECURITY_FSSW_S1 (SECURITY_MOD3 + 0x20)
90+
#define SECURITY_APB (SECURITY_MOD3 + 0x28)
91+
92+
/**
93+
* TrustZone-specific initializations
94+
*
95+
* @param
96+
*
97+
* @retval
98+
*/
99+
uint32_t board_init(void);
100+
101+
/**
102+
* Handling syscalls (SMCs)
103+
*
104+
* @param
105+
*
106+
* @retval
107+
*/
108+
uint32_t board_handler(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint32_t arg3);
109+
110+
#endif /* __BOARD_H */

src/boards/zybo/inc/ltzvisor_hw.h

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* LTZVisor, a Lightweight TrustZone-assisted Hypervisor
3+
*
4+
* Copyright (c) TZVisor Project (www.tzvisor.org), 2017-
5+
*
6+
* Authors:
7+
* Sandro Pinto <[email protected]>
8+
* Jorge Pereira <[email protected]>
9+
*
10+
* This file is part of LTZVisor.
11+
*
12+
* LTZVisor is free software; you can redistribute it and/or modify
13+
* it under the terms of the GNU General Public License version 2
14+
* as published by the Free Software Foundation, with a special
15+
* exception described below.
16+
*
17+
* Linking this code statically or dynamically with other modules
18+
* is making a combined work based on this code. Thus, the terms
19+
* and conditions of the GNU General Public License V2 cover the
20+
* whole combination.
21+
*
22+
* As a special exception, the copyright holders of LTZVisor give
23+
* you permission to link LTZVisor with independent modules to
24+
* produce a statically linked executable, regardless of the license
25+
* terms of these independent modules, and to copy and distribute
26+
* the resulting executable under terms of your choice, provided that
27+
* you also meet, for each linked independent module, the terms and
28+
* conditions of the license of that module. An independent module
29+
* is a module which is not derived from or based on LTZVisor.
30+
*
31+
* LTZVisor is distributed in the hope that it will be useful, but
32+
* WITHOUT ANY WARRANTY; without even the implied warranty of
33+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34+
* GNU General Public License for more details.
35+
*
36+
* You should have received a copy of the GNU General Public License
37+
* along with this program; if not, write to the Free Software
38+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
39+
* 02110-1301 USA.
40+
*
41+
* [ltzvisor_hw.h]
42+
*
43+
* This file contains the LTZVisor hardware-specific initialization.
44+
*
45+
* (#) $id: ltzvisor_hw.h 10-06-2015 s_pinto & j_pereira $
46+
* (#) $id: ltzvisor_hw.h 17-09-2017 s_pinto (modified)$
47+
*/
48+
49+
#ifndef __LTZVISOR_HW_H
50+
#define __LTZVISOR_HW_H
51+
52+
#include <types.h>
53+
#include <printk.h>
54+
#include <gic.h>
55+
#include <ltzvisor.h>
56+
#include <board.h>
57+
#include <zynq_ttc.h>
58+
59+
#define ARCH "ARMv7-A"
60+
#define CPU "Cortex-A9"
61+
#define PLATFORM "Zynq-7000"
62+
63+
#define LTZVISOR_MON_EXIT() {\
64+
asm volatile("msr cpsr_c,#(0x13 | 0x80 | 0x40)");\
65+
asm volatile("ldr r1,=_supervisor_stack");\
66+
asm volatile("add r1, r1, r0, lsl #12");\
67+
asm volatile("add sp, r1, #4096");\
68+
}
69+
70+
/**
71+
* LTZVisor hardware initialization
72+
*
73+
* @param
74+
*
75+
* @retval Return TRUE if success or False if not
76+
*/
77+
uint32_t ltzvisor_hw_init(void);
78+
79+
#endif /* __LTZVISOR_HW_H */

0 commit comments

Comments
 (0)