-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Atmel SAMA5 platform support #1714
Conversation
Realized the memory map in the comment needs to be updated. optee runs in
the middle of the DDR (as shown in SAMA5D2 memory map).
Long story: As you said on ARM32 linux putting optee in lower 128M means
Linux can not use that memory. However I have an additional restriction on
SAMA5D2 where memory protection works in chunks of 128MiB. Inside the
128MiB chunk the lower memory has fine resolution for configuring as secure
memory but high memory can only be configured as a single 64MiB secure
memory chunk. So to avoid unnecessarily setting aside 64MiB for secure
memory, I put op-tee at the start of a 128MiB boundary in DDR.
End of DDR memory
+ * +------------------+
+ * | Linux memory |
+ * +------------------+
+ * | SHMEM |
+ * +------------------+
+ * | | TA_RAM |
+ * + TZDRAM +---------+
+ * | | TEE_RAM |
+ * +------------------+
+ * | Linux memory |
+ * +--------+---------+
Start of DDR memory
/*
* SAMA5D2 memory map
*
* 0x4000_0000 -
* Linux/other |
* 0x30C0_0000 -
* Shared memory: 4 MiB (CFG_SHMEM_SIZE) |
* 0x3080_0000 [CFG_SHMEM_START] -
* TA RAM: 7 MiB (remaining memory) |
* 0x3010_0000 [CFG_TA_RAM_START] -
* TEE RAM: 1 MiB (CFG_TEE_RAM_VA_SIZE) |
* 0x3000_0000 [CFG_TEE_RAM_START/LOAD_ADDR] -
* Linux/other |
* 0x2000_0000 [DRAM0_BASE] -
*
*/
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
For the first commit ("plat-sam: Add support..."), please see my review comments. I suggest you add the platform description above to the commit text, and also add a
Link:
tag to link to the datasheet. -
For the second commit ("arm: pl310: Support processors without SCU"):
Acked-by: Jerome Forissier <[email protected]>
core/arch/arm/plat-sam/main.c
Outdated
return AT91C_BASE_MATRIX64; | ||
} | ||
|
||
static int matrix_configure_slave(void) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function always returns 0, so you should return void
instead
core/arch/arm/plat-sam/conf.mk
Outdated
|
||
CFG_WITH_STACK_CANARIES ?= y | ||
|
||
CFG_PL310=y |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When setting CFG_
values, please use either ?=
or $(call force, ...)
. This commit: dffb004951df explains when to use one or the other.
Same for CFG_AT91_MATRIX
below.
core/arch/arm/plat-sam/main.c
Outdated
unsigned int array_size; | ||
int ret; | ||
|
||
array_size = sizeof(security_ps_peri_id) / sizeof(unsigned int); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use ARRAY_SIZE
from <util.h>
core/arch/arm/plat-sam/tz_matrix.h
Outdated
#define MATRIX_MEIER 0x0150 /* Master Error Interrupt Enable Register */ | ||
#define MATRIX_MEIDR 0x0154 /* Master Error Interrupt Disable Register */ | ||
#define MATRIX_MEIMR 0x0158 /* Master Error Interrupt Mask Register */ | ||
#define MATRIX_MESR 0x015c /* Master Error Statue Register */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/Statue/Status/
core/arch/arm/plat-sam/matrix.c
Outdated
.matrix = MATRIX_H64MX, | ||
.security_type = SECURITY_TYPE_PS, | ||
}, | ||
/* ARM */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment (and all the others below) are kind of useless since they simply repeat what's written into .peri_id
, they don't really improve readability either IMO. But you can keep them if you prefer.
* Treats shared accesses (bit22=0, bit13=0) | ||
* Parity disabled (bit21=0) | ||
* Event monitor disabled (bit20=0) | ||
* Platform fmavor specific way config: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/fmavor/flavor/
* | ||
* I/Dcache prefetch enabled (bit29:28=2b11) | ||
* NS can access interrupts (bit27=1) | ||
* NS can lockown cache lines (bit26=1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/lockown/lockdown/
core/arch/arm/plat-sam/tz_matrix.h
Outdated
#ifndef __TZ_MATRIX_H__ | ||
#define __TZ_MATRIX_H__ | ||
|
||
#define MATRIX_MCFG(n) (0x0000 + (n) * 4)/* Master Configuration Register */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Space after )
and before /*
core/include/drivers/atmel_uart.h
Outdated
}; | ||
|
||
void atmel_uart_init(struct atmel_uart_data *pd, paddr_t base); | ||
void set_mmu_flag(void); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused? (remove)
@jforissier : Thanks for all the review comments/suggestions. All of them have been addressed in the updated pull request. |
core/arch/arm/plat-sam/tz_matrix.h
Outdated
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, | ||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
#ifndef __TZ_MATRIX_H__ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor: different styles of header guards are used through all header files (sometimes wrapped with __ __
, sometimes without them)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, fixed in latest update.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some more comments.
In the commit description, please move the Link:
tag next to the Signed-off-by:
without any blank line in between, like so:
Commit subject
Commit description
(several lines)
Link: ...
Signed-off-by: ...
core/arch/arm/plat-sam/matrix.c
Outdated
|
||
for (i = 0; i < ARRAY_SIZE(peri_security_array); i++) { | ||
if (peri_id == peri_security_array[i].peri_id) | ||
break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return &peri_security_array[i];
here and return NULL;
after the loop.
core/arch/arm/plat-sam/matrix.c
Outdated
matrix_write(matrix_base, MATRIX_SASSR(slave), srsplit_setting); | ||
} | ||
|
||
static struct peri_security *get_peri_security(unsigned int peri_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably return const struct peri_security *
core/arch/arm/plat-sam/matrix.h
Outdated
unsigned int size); | ||
|
||
extern vaddr_t matrix32_base(void); | ||
extern vaddr_t matrix64_base(void); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are those extern
needed? I don't think so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
matrix32/64_base() is being used in both matrix.c and main.c, hence it is included in the header.
I have fixed all other review comments in the updated pull request. Thanks for reviewing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, sorry for not being clear, I meant the extern
keyword is not needed, is it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, misread the original comment. no they are not needed, fixed in latest update.
core/arch/arm/plat-sam/matrix.c
Outdated
struct peri_security *periperal_sec; | ||
int ret; | ||
|
||
if ((peri_id_array == NULL) || (size == 0)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (!peri_id_array || !size)
core/arch/arm/plat-sam/matrix.c
Outdated
peri_id_p = peri_id_array; | ||
for (i = 0; i < size; i++) { | ||
periperal_sec = get_peri_security(*peri_id_p); | ||
if (periperal_sec == NULL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (!peripheral_sec)
core/arch/arm/plat-sam/matrix.c
Outdated
}, | ||
}; | ||
|
||
static inline void matrix_write(unsigned int base, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drop inline
core/arch/arm/plat-sam/matrix.c
Outdated
write32(value, offset + base); | ||
} | ||
|
||
static inline unsigned int matrix_read(int base, unsigned int offset) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drop inline
core/arch/arm/plat-sam/main.c
Outdated
AT91C_ID_CHIPID, | ||
}; | ||
|
||
static int matrix_config_periheral(void) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo, and perhaps plural is better? (matrix_config_peripherals)
core/arch/arm/plat-sam/main.c
Outdated
if (ret) | ||
return -1; | ||
|
||
return 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simplify:
static int matrix_config_peripherals(void)
{
return matrix_configure_peri_security(security_ps_peri_id,
ARRAY_SIZE(security_ps_peri_id));
}
core/arch/arm/plat-sam/main.c
Outdated
if (ret) | ||
return -1; | ||
|
||
return 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simplify: return matrix_config_peripherals();
Is this review still active? |
LGTM, @nodeax you may add my Ack to the 2nd commit, too. |
Not all processors might have a SCU unit. So conditionally include code that configures SCU. Signed-off-by: Akshay Bhat <[email protected]> Acked-by: Jerome Forissier <[email protected]>
Add basic support to get op-tee to run on SAMA5D2-XULT board. The SoC is based on single core ARM Cortex-A5 and supports: ARM TrustZone with support for configuring memory/peripherals as secure Secure RTC Secure boot On-the-fly encryption/decryption of DDR bus Tamper protection Link: http://www.atmel.com/Images/Atmel-11267-32-bit-Cortex-A5-Microcontroller-SAMA5D2_Datasheet.pdf Signed-off-by: Akshay Bhat <[email protected]> Acked-by: Jerome Forissier <[email protected]>
@jforissier : Thanks for the review, added you Ack to the 2nd commit. |
@nodeax thanks for contributing! |
Adding support for Atmel/Microchip SAMA5D2-XULT board
The processor supports:
ARM TrustZone, configuring memory and/or peripherals as secure, secure RTC, Secure boot, On-the-fly encryption/decryption of the DDR bus, Tamper protection etc. Datasheet.
Instructions to build optee_os along with bootlog, test results can be found here.