Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
Arm Trusted Firmware
Commits
d87d524e
Unverified
Commit
d87d524e
authored
Jul 25, 2018
by
danh-arm
Committed by
GitHub
Jul 25, 2018
Browse files
Merge pull request #1466 from Yann-lms/stm32mp1
Add STMicroelectronics STM32MP1 platform support
parents
e16d459d
efb3728d
Changes
65
Hide whitespace changes
Inline
Side-by-side
plat/st/stm32mp1/stm32mp1_security.c
0 → 100644
View file @
d87d524e
/*
* Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <debug.h>
#include <dt-bindings/clock/stm32mp1-clks.h>
#include <mmio.h>
#include <stdint.h>
#include <stm32mp1_clk.h>
#include <stm32mp1_dt.h>
#include <stm32mp1_private.h>
#include <stm32mp1_rcc.h>
#include <tzc400.h>
#include "platform_def.h"
/*******************************************************************************
* Initialize the TrustZone Controller. Configure Region 0 with Secure RW access
* and allow Non-Secure masters full access.
******************************************************************************/
static
void
init_tzc400
(
void
)
{
unsigned
long
long
region_base
,
region_top
;
unsigned
long
long
ddr_base
=
STM32MP1_DDR_BASE
;
unsigned
long
long
ddr_size
=
(
unsigned
long
long
)
dt_get_ddr_size
();
tzc400_init
(
STM32MP1_TZC_BASE
);
tzc400_disable_filters
();
/* Region 1 set to cover all DRAM at 0xC000_0000. Apply the
* same configuration to all filters in the TZC.
*/
region_base
=
ddr_base
;
region_top
=
ddr_base
+
(
ddr_size
-
1U
);
tzc400_configure_region
(
STM32MP1_FILTER_BIT_ALL
,
1
,
region_base
,
region_top
,
TZC_REGION_S_RDWR
,
TZC_REGION_ACCESS_RDWR
(
STM32MP1_TZC_A7_ID
)
|
TZC_REGION_ACCESS_RDWR
(
STM32MP1_TZC_GPU_ID
)
|
TZC_REGION_ACCESS_RDWR
(
STM32MP1_TZC_LCD_ID
)
|
TZC_REGION_ACCESS_RDWR
(
STM32MP1_TZC_MDMA_ID
)
|
TZC_REGION_ACCESS_RDWR
(
STM32MP1_TZC_DMA_ID
)
|
TZC_REGION_ACCESS_RDWR
(
STM32MP1_TZC_USB_HOST_ID
)
|
TZC_REGION_ACCESS_RDWR
(
STM32MP1_TZC_USB_OTG_ID
)
|
TZC_REGION_ACCESS_RDWR
(
STM32MP1_TZC_SDMMC_ID
)
|
TZC_REGION_ACCESS_RDWR
(
STM32MP1_TZC_ETH_ID
)
|
TZC_REGION_ACCESS_RDWR
(
STM32MP1_TZC_DAP_ID
));
/* Raise an exception if a NS device tries to access secure memory */
tzc400_set_action
(
TZC_ACTION_ERR
);
tzc400_enable_filters
();
}
/*******************************************************************************
* Initialize the TrustZone Controller.
* Early initialization create only one region with full access to secure.
* This setting is used before and during DDR initialization.
******************************************************************************/
static
void
early_init_tzc400
(
void
)
{
uint32_t
rstsr
,
rst_standby
;
rstsr
=
mmio_read_32
(
RCC_BASE
+
RCC_MP_RSTSCLRR
);
/* No warning if return from (C)STANDBY */
rst_standby
=
rstsr
&
(
RCC_MP_RSTSCLRR_STDBYRSTF
|
RCC_MP_RSTSCLRR_CSTDBYRSTF
);
if
(
stm32mp1_clk_is_enabled
(
TZC1
)
&&
(
rst_standby
==
0U
))
{
WARN
(
"TZC400 port 1 clock already enable
\n
"
);
}
if
(
stm32mp1_clk_is_enabled
(
TZC2
)
&&
(
rst_standby
==
0U
))
{
WARN
(
"TZC400 port 2 clock already enable
\n
"
);
}
if
(
stm32mp1_clk_enable
(
TZC1
)
!=
0
)
{
ERROR
(
"Cannot enable TZC1 clock
\n
"
);
panic
();
}
if
(
stm32mp1_clk_enable
(
TZC2
)
!=
0
)
{
ERROR
(
"Cannot enable TZC2 clock
\n
"
);
panic
();
}
tzc400_init
(
STM32MP1_TZC_BASE
);
tzc400_disable_filters
();
/*
* Region 1 set to cover Non-Secure DRAM at 0x8000_0000. Apply the
* same configuration to all filters in the TZC.
*/
tzc400_configure_region
(
STM32MP1_FILTER_BIT_ALL
,
1
,
STM32MP1_DDR_BASE
,
STM32MP1_DDR_BASE
+
(
STM32MP1_DDR_MAX_SIZE
-
1U
),
TZC_REGION_S_RDWR
,
TZC_REGION_ACCESS_RDWR
(
STM32MP1_TZC_SDMMC_ID
));
/* Raise an exception if a NS device tries to access secure memory */
tzc400_set_action
(
TZC_ACTION_ERR
);
tzc400_enable_filters
();
}
/*******************************************************************************
* Initialize the secure environment. At this moment only the TrustZone
* Controller is initialized.
******************************************************************************/
void
stm32mp1_arch_security_setup
(
void
)
{
early_init_tzc400
();
}
/*******************************************************************************
* Initialize the secure environment. At this moment only the TrustZone
* Controller is initialized.
******************************************************************************/
void
stm32mp1_security_setup
(
void
)
{
init_tzc400
();
}
plat/st/stm32mp1/stm32mp1_stack_protector.c
0 → 100644
View file @
d87d524e
/*
* Copyright (c) 2018, ARM Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <arch_helpers.h>
#include <platform.h>
#include <stdint.h>
#define RANDOM_CANARY_VALUE 2144346116U
u_register_t
plat_get_stack_protector_canary
(
void
)
{
/*
* Ideally, a random number should be returned instead of the
* combination of a timer's value and a compile-time constant.
*/
return
RANDOM_CANARY_VALUE
^
(
u_register_t
)
read_cntpct_el0
();
}
plat/st/stm32mp1/stm32mp1_topology.c
0 → 100644
View file @
d87d524e
/*
* Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <platform_def.h>
#include <platform.h>
#include <psci.h>
/* 1 cluster, all cores into */
static
const
unsigned
char
stm32mp1_power_domain_tree_desc
[]
=
{
PLATFORM_CLUSTER_COUNT
,
PLATFORM_CORE_COUNT
,
};
/* This function returns the platform topology */
const
unsigned
char
*
plat_get_power_domain_tree_desc
(
void
)
{
return
stm32mp1_power_domain_tree_desc
;
}
/*******************************************************************************
* This function implements a part of the critical interface between the psci
* generic layer and the platform that allows the former to query the platform
* to convert an MPIDR to a unique linear index. An error code (-1) is returned
* in case the MPIDR is invalid.
******************************************************************************/
int
plat_core_pos_by_mpidr
(
u_register_t
mpidr
)
{
unsigned
int
cluster_id
,
cpu_id
;
u_register_t
mpidr_copy
=
mpidr
;
mpidr_copy
&=
MPIDR_AFFINITY_MASK
;
if
((
mpidr_copy
&
~
(
MPIDR_CLUSTER_MASK
|
MPIDR_CPU_MASK
))
!=
0U
)
{
return
-
1
;
}
cluster_id
=
(
mpidr_copy
>>
MPIDR_AFF1_SHIFT
)
&
MPIDR_AFFLVL_MASK
;
cpu_id
=
(
mpidr_copy
>>
MPIDR_AFF0_SHIFT
)
&
MPIDR_AFFLVL_MASK
;
if
(
cluster_id
>=
PLATFORM_CLUSTER_COUNT
)
{
return
-
1
;
}
/*
* Validate cpu_id by checking whether it represents a CPU in one
* of the two clusters present on the platform.
*/
if
(
cpu_id
>=
PLATFORM_CORE_COUNT
)
{
return
-
1
;
}
return
(
int
)
cpu_id
;
}
tools/stm32image/Makefile
0 → 100644
View file @
d87d524e
#
# Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
MAKE_HELPERS_DIRECTORY
:=
../../make_helpers/
include
${MAKE_HELPERS_DIRECTORY}build_macros.mk
include
${MAKE_HELPERS_DIRECTORY}build_env.mk
PROJECT
:=
stm32image
${BIN_EXT}
OBJECTS
:=
stm32image.o
V
:=
0
override
CPPFLAGS
+=
-D_GNU_SOURCE
CFLAGS
:=
-Wall
-Werror
-pedantic
-std
=
c99
ifeq
(${DEBUG},1)
CFLAGS
+=
-g
-O0
-DDEBUG
else
CFLAGS
+=
-O2
endif
ifeq
(${V},0)
Q
:=
@
else
Q
:=
endif
CC
:=
gcc
.PHONY
:
all clean distclean
all
:
${PROJECT}
${PROJECT}
:
${OBJECTS} Makefile
@
echo
" LD
$@
"
${Q}${CC}
${OBJECTS}
-o
$@
@
${ECHO_BLANK_LINE}
@
echo
"Built
$@
successfully"
@
${ECHO_BLANK_LINE}
%.o
:
%.c %.h Makefile
@
echo
" CC
$<
"
${Q}${CC}
-c
${CFLAGS}
$<
-o
$@
clean
:
$(
call
SHELL_DELETE_ALL,
${PROJECT}
${OBJECTS}
)
distclean
:
clean
tools/stm32image/stm32image.c
0 → 100644
View file @
d87d524e
/*
* Copyright (c) 2017-2018, STMicroelectronics - All Rights Reserved
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <asm/byteorder.h>
#include <errno.h>
#include <fcntl.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
/* Magic = 'S' 'T' 'M' 0x32 */
#define HEADER_MAGIC __be32_to_cpu(0x53544D32)
#define VER_MAJOR 2
#define VER_MINOR 1
#define VER_VARIANT 0
#define HEADER_VERSION_V1 0x1
#define TF_BINARY_TYPE 0x0
/* Default option : bit0 => no signature */
#define HEADER_DEFAULT_OPTION (__cpu_to_le32(0x00000001))
struct
stm32_header
{
uint32_t
magic_number
;
uint8_t
image_signature
[
64
];
uint32_t
image_checksum
;
uint8_t
header_version
[
4
];
uint32_t
image_length
;
uint32_t
image_entry_point
;
uint32_t
reserved1
;
uint32_t
load_address
;
uint32_t
reserved2
;
uint32_t
version_number
;
uint32_t
option_flags
;
uint32_t
ecdsa_algorithm
;
uint8_t
ecdsa_public_key
[
64
];
uint8_t
padding
[
83
];
uint8_t
binary_type
;
};
static
struct
stm32_header
stm32image_header
;
static
void
stm32image_default_header
(
struct
stm32_header
*
ptr
)
{
if
(
!
ptr
)
{
return
;
}
ptr
->
magic_number
=
HEADER_MAGIC
;
ptr
->
header_version
[
VER_MAJOR
]
=
HEADER_VERSION_V1
;
ptr
->
option_flags
=
HEADER_DEFAULT_OPTION
;
ptr
->
ecdsa_algorithm
=
1
;
ptr
->
version_number
=
0
;
ptr
->
binary_type
=
TF_BINARY_TYPE
;
}
static
uint32_t
stm32image_checksum
(
void
*
start
,
uint32_t
len
)
{
uint32_t
csum
=
0
;
uint32_t
hdr_len
=
sizeof
(
struct
stm32_header
);
uint8_t
*
p
;
if
(
len
<
hdr_len
)
{
return
0
;
}
p
=
(
unsigned
char
*
)
start
+
hdr_len
;
len
-=
hdr_len
;
while
(
len
>
0
)
{
csum
+=
*
p
;
p
++
;
len
--
;
}
return
csum
;
}
static
void
stm32image_print_header
(
const
void
*
ptr
)
{
struct
stm32_header
*
stm32hdr
=
(
struct
stm32_header
*
)
ptr
;
printf
(
"Image Type : ST Microelectronics STM32 V%d.%d
\n
"
,
stm32hdr
->
header_version
[
VER_MAJOR
],
stm32hdr
->
header_version
[
VER_MINOR
]);
printf
(
"Image Size : %lu bytes
\n
"
,
(
unsigned
long
)
__le32_to_cpu
(
stm32hdr
->
image_length
));
printf
(
"Image Load : 0x%08x
\n
"
,
__le32_to_cpu
(
stm32hdr
->
load_address
));
printf
(
"Entry Point : 0x%08x
\n
"
,
__le32_to_cpu
(
stm32hdr
->
image_entry_point
));
printf
(
"Checksum : 0x%08x
\n
"
,
__le32_to_cpu
(
stm32hdr
->
image_checksum
));
printf
(
"Option : 0x%08x
\n
"
,
__le32_to_cpu
(
stm32hdr
->
option_flags
));
printf
(
"Version : 0x%08x
\n
"
,
__le32_to_cpu
(
stm32hdr
->
version_number
));
}
static
void
stm32image_set_header
(
void
*
ptr
,
struct
stat
*
sbuf
,
int
ifd
,
uint32_t
loadaddr
,
uint32_t
ep
,
uint32_t
ver
)
{
struct
stm32_header
*
stm32hdr
=
(
struct
stm32_header
*
)
ptr
;
stm32image_default_header
(
stm32hdr
);
stm32hdr
->
load_address
=
__cpu_to_le32
(
loadaddr
);
stm32hdr
->
image_entry_point
=
__cpu_to_le32
(
ep
);
stm32hdr
->
image_length
=
__cpu_to_le32
((
uint32_t
)
sbuf
->
st_size
-
sizeof
(
struct
stm32_header
));
stm32hdr
->
image_checksum
=
stm32image_checksum
(
ptr
,
sbuf
->
st_size
);
stm32hdr
->
version_number
=
__cpu_to_le32
(
ver
);
}
static
int
stm32image_create_header_file
(
char
*
srcname
,
char
*
destname
,
uint32_t
loadaddr
,
uint32_t
entry
,
uint32_t
version
)
{
int
src_fd
,
dest_fd
;
struct
stat
sbuf
;
unsigned
char
*
ptr
;
dest_fd
=
open
(
destname
,
O_RDWR
|
O_CREAT
|
O_TRUNC
|
O_APPEND
,
0666
);
if
(
dest_fd
==
-
1
)
{
fprintf
(
stderr
,
"Can't open %s: %s
\n
"
,
destname
,
strerror
(
errno
));
return
-
1
;
}
src_fd
=
open
(
srcname
,
O_RDONLY
);
if
(
src_fd
==
-
1
)
{
fprintf
(
stderr
,
"Can't open %s: %s
\n
"
,
srcname
,
strerror
(
errno
));
return
-
1
;
}
if
(
fstat
(
src_fd
,
&
sbuf
)
<
0
)
{
return
-
1
;
}
ptr
=
mmap
(
NULL
,
sbuf
.
st_size
,
PROT_READ
,
MAP_SHARED
,
src_fd
,
0
);
if
(
ptr
==
MAP_FAILED
)
{
fprintf
(
stderr
,
"Can't read %s
\n
"
,
srcname
);
return
-
1
;
}
memset
(
&
stm32image_header
,
0
,
sizeof
(
struct
stm32_header
));
if
(
write
(
dest_fd
,
&
stm32image_header
,
sizeof
(
struct
stm32_header
))
!=
sizeof
(
struct
stm32_header
))
{
fprintf
(
stderr
,
"Write error %s: %s
\n
"
,
destname
,
strerror
(
errno
));
return
-
1
;
}
if
(
write
(
dest_fd
,
ptr
,
sbuf
.
st_size
)
!=
sbuf
.
st_size
)
{
fprintf
(
stderr
,
"Write error on %s: %s
\n
"
,
destname
,
strerror
(
errno
));
return
-
1
;
}
munmap
((
void
*
)
ptr
,
sbuf
.
st_size
);
close
(
src_fd
);
if
(
fstat
(
dest_fd
,
&
sbuf
)
<
0
)
{
return
-
1
;
}
ptr
=
mmap
(
0
,
sbuf
.
st_size
,
PROT_READ
|
PROT_WRITE
,
MAP_SHARED
,
dest_fd
,
0
);
if
(
ptr
==
MAP_FAILED
)
{
fprintf
(
stderr
,
"Can't read %s
\n
"
,
srcname
);
return
-
1
;
}
stm32image_set_header
(
ptr
,
&
sbuf
,
dest_fd
,
loadaddr
,
entry
,
version
);
stm32image_print_header
(
ptr
);
munmap
((
void
*
)
ptr
,
sbuf
.
st_size
);
close
(
dest_fd
);
return
0
;
}
int
main
(
int
argc
,
char
*
argv
[])
{
int
opt
,
loadaddr
=
-
1
,
entry
=
-
1
,
err
=
0
,
version
=
0
;
char
*
dest
=
NULL
,
*
src
=
NULL
;
while
((
opt
=
getopt
(
argc
,
argv
,
":s:d:l:e:v:"
))
!=
-
1
)
{
switch
(
opt
)
{
case
's'
:
src
=
optarg
;
break
;
case
'd'
:
dest
=
optarg
;
break
;
case
'l'
:
loadaddr
=
strtol
(
optarg
,
NULL
,
16
);
break
;
case
'e'
:
entry
=
strtol
(
optarg
,
NULL
,
16
);
break
;
case
'v'
:
version
=
strtol
(
optarg
,
NULL
,
10
);
break
;
default:
fprintf
(
stderr
,
"Usage : %s [-s srcfile] [-d destfile] [-l loadaddr] [-e entry_point]
\n
"
,
argv
[
0
]);
return
-
1
;
}
}
if
(
!
src
)
{
fprintf
(
stderr
,
"Missing -s option
\n
"
);
return
-
1
;
}
if
(
!
dest
)
{
fprintf
(
stderr
,
"Missing -d option
\n
"
);
return
-
1
;
}
if
(
loadaddr
==
-
1
)
{
fprintf
(
stderr
,
"Missing -l option
\n
"
);
return
-
1
;
}
if
(
entry
==
-
1
)
{
fprintf
(
stderr
,
"Missing -e option
\n
"
);
return
-
1
;
}
err
=
stm32image_create_header_file
(
src
,
dest
,
loadaddr
,
entry
,
version
);
return
err
;
}
Prev
1
2
3
4
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment