-
Notifications
You must be signed in to change notification settings - Fork 3k
Added Support for Toshiba TMPM46B #5902
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
Conversation
Automatic CI verification build not done, please verify manually. |
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.
Can you share tests results for all 3 toolchains?
int trng_get_bytes(trng_t *obj, uint8_t *output, size_t length, size_t *output_length) | ||
{ | ||
uint32_t Data[length]; | ||
int timeout = 10; |
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.
how is t his number calculated ? why 10?
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 entropy seed generator (ESG) is a circuit that generates a 512-bit entropy seed using a ring oscillator. When the ESG core ends the operation, it outputs an interrupt. Interrupt generation can be checked by polling of the interrupt flag. Then an entropy seed can be read from 16 blocks (ESGBLK00 to 15)
Timeout 10 is used for 10 iteration to confirm the ESG operation is completed.
- Sometimes function execution completes before generating interrupts and read wrong value.
- Timeout will help to return from function, even interrupts are not generated within 10 iteration.
We will also try to change the approach.
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.
@hanno-arm Please review trng addition
|
||
void hal_deepsleep(void) | ||
{ | ||
hal_sleep(); |
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.
why deepsleep = sleep here?
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.
TMPM46BF10FG does not support the low power consumption mode configured with the SLEEPDEEP bit in the Cortex-M4 core.
Setting the bit of the system control register is prohibited.
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.
OK Thanks, if this is captured in git log or can be here in the code, so others wont be surprised?
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.
Hi @0xc0170, added the reason as code comments. Thank you.
#include "tmpm46b_tmrb.h" | ||
|
||
#define MAX_COUNTER_16B 0xFFFF | ||
TMRB_InitTypeDef m_tmrb; |
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.
these 2 variables static?
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.
Updated as static.
20, 24, 32, 48, 80, 144, 272, 528 | ||
}; // SCK Divider value table | ||
|
||
I2C_clock_setting_t clk; |
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.
why these 2 are not static
as well?
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.
Updated as static.
I might have missed the test results shared above. The failure MBED 11 was resolved recently, should be also green ! Travis failed, this was also fixed. Can you please rebase from master, to get both fixes in? |
We checked MBED 11 and result is OK.
Rebased from master. |
|
||
int trng_get_bytes(trng_t *obj, uint8_t *output, size_t length, size_t *output_length) | ||
{ | ||
uint32_t Data[length]; |
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 length
parameter is the maximum amount of entropy in bytes that may be written to output
, while Data
has four times that size.
// Get the calculation result | ||
if(CompleteFlag == 1){ | ||
CompleteFlag = 0; | ||
ESG_GetResult(Data); |
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 might overflow the Data
buffer if length < 16
.
CompleteFlag = 0; | ||
ESG_GetResult(Data); | ||
for(i = 0U; i < length; i++){ | ||
output[i] = Data[i]; |
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.
At most 16
bytes have been written to Data
, but this loop reads its entire contents of user-specified size length
, filling the remainder of output
with non-random data.
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 entropy gathering function trng_get_bytes
needs to be rewritten. The internal data buffer should have a static size of 64
bytes - the chunk size in which the TRNG returns the entropy - and only the amount of entropy gathered should be reported back to the user. Since it is not mandatory to return as many bytes as the user has requested, this leaves the option of either looping or always returning at most 16 bytes. Also, the stack buffer temporarily holding the entropy must be zeroized before the function returns.
Hi @hanno-arm, rewritten the entropy gathering function trng_get_bytes based on your comments. |
Hi @ganesh-ramachandran, thank you for your rework! Could you point me to the technical reference manual for the board? |
Hi @hanno-arm, Please find the datasheet and schematics at https://os.mbed.com/platforms/TMPM46B/#technical-reference |
ARM Internal Ref: IOTSSL-2073 |
@ganesh-ramachandran As TRNG is waiting for mbedtls approval, it might be faster to leave TRNG here and send PR adding target support separately? Or leave it as it is. |
ESG_SetLatchTiming(ESG_LATCH_TIMING_1); | ||
// Get latchtiming value | ||
latchtiming = ESG_GetLatchTiming(); | ||
if (Fintming >= 512U * (latchtiming + 1U) + 3U) { |
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.
@ganesh-ramachandran Could you explain the rationale behind this check? As far as I see, it passes if and only if latchtiming
is zero ( == ESG_LATCH_TIMING_1
), so why not check for this directly?
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.
Yes, we understood and removed the extra checking.
} else { | ||
// Do nothing | ||
} | ||
} |
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.
Unfortunately, the current API doesn't allow trng_init
to have a return value to signal failure (that has been resolved in Mbed TLS 2.7.0 and will hopefully soon be merged into Mbed OS). Still, I'd like to seek for a solution which allows to distinguish initialization failure from success, in order to not have the TRNG driver potentially output non-random data because of unnoticed failure during initialization.
Suggestion: Currently, the TRNG context trng_s
consists of an unused dummy
field only. This can be changed to a boolean flag indicating successful initialization, which is set on a successful call to trng_init
, cleared on a call to trng_free
, and checked for in trng_get_bytes
.
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.
Thank you for the suggestion. we have added the errors handling during TRNG initialization to prevent accidental output of non-random data.
*output_length = 0; | ||
(void)obj; | ||
|
||
while (TSB_ESG->ST == ESG_BUSY_SET) { |
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.
Why are we polling on TSB_ESB->ST
here instead of CompleteFlag
, which is what the ESG's IRQ handler sets?
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.
TSB_ESB->ST is the status register and it indicate the process is complete or not.
While polling IRQ handler flag(CompleteFlag), interrupt will generate only once.
Hence if application will try to call two times the trng_get_bytes() function it will freeze the application. To avoid this scenario we poll TSB_ESB->ST and reconfirm IRQ handler flag (CompleteFlag) is set or not.
Now we changed to polling on IRQ handler flag(CompleteFlag), because we confirmed the upper layer file(mbed_trng.c) always calls trng_get_bytes() function in between TRNG init and TRNG free.
CompleteFlag = 0; | ||
// Get the calculation result | ||
ESG_GetResult((uint32_t*)random); //512-bit entropy | ||
for (i = 0; (i < 64) && (*output_length < length); i++) { |
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.
Please use i < length
here instead of *output_length < length
, and set *output_length
only once at the end of the loop.
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.
Yes, modified as per your suggestion.
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.
Suggested a way of handling errors during TRNG initialization to prevent accidental output of non-random data, and requested clarification of some parts of the driver code.
} | ||
|
||
// initialize us_ticker | ||
void us_ticker_init(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.
I've noticed in the init interrupts for HAL. you are not using NVIC_SetVector - dynamic vectors?
See https://docs.mbed.com/docs/mbed-os-handbook/en/5.2/advanced/porting_guide/ (Bootstrap section)
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.
@0xc0170, Added NVIC_SetVector - dynamic vectors
const ticker_info_t* us_ticker_get_info() | ||
{ | ||
static const ticker_info_t info = { | ||
1875000,//1875000, |
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 there tabs as this line is misaligned with line below?
// Interrupt clearing | ||
ret = ESG_ClrInt(); | ||
if (ret == ERROR) | ||
{ |
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.
{
one the same line (line 74 as well here)
/morph build |
Build : SUCCESSBuild number : 1616 Triggering tests/morph test |
@ganesh-ramachandran thanks for incorporating the comments. Approved. |
Exporter Build : SUCCESSBuild number : 1245 |
Test : SUCCESSBuild number : 1398 |
Description
Add mbed support for TOSHIBA's TMPM46B board.
Status
READY
Migrations
NO
Test Status
Pass: Mbed SDK automated test suite and greentea with ARM, GCC_ARM and IAR toolchains.
M46B_GreenteaAutomated_TestResults.txt
M46B_SingleAutomated_TestResults.txt