Skip to content

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

Merged
merged 5 commits into from Mar 29, 2018
Merged

Added Support for Toshiba TMPM46B #5902

merged 5 commits into from Mar 29, 2018

Conversation

ghost
Copy link

@ghost ghost commented Jan 23, 2018

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

@mbed-ci
Copy link

mbed-ci commented Jan 23, 2018

Automatic CI verification build not done, please verify manually.

Copy link
Contributor

@0xc0170 0xc0170 left a 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;
Copy link
Contributor

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?

Copy link
Author

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.

Copy link
Contributor

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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why deepsleep = sleep here?

Copy link
Author

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.

Copy link
Contributor

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?

Copy link
Author

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these 2 variables static?

Copy link
Author

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;
Copy link
Contributor

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?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated as static.

@0xc0170
Copy link
Contributor

0xc0170 commented Jan 29, 2018

Can you share tests results for all 3 toolchains?

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?

@ghost
Copy link
Author

ghost commented Jan 29, 2018

I might have missed the test results shared above. The failure MBED 11 was resolved recently, should be also green !

We checked MBED 11 and result is OK.

Travis failed, this was also fixed. Can you please rebase from master, to get both fixes in?

Rebased from master.


int trng_get_bytes(trng_t *obj, uint8_t *output, size_t length, size_t *output_length)
{
uint32_t Data[length];

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);

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];

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.

Copy link

@hanno-becker hanno-becker left a 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.

@ghost
Copy link
Author

ghost commented Jan 30, 2018

Hi @hanno-arm, rewritten the entropy gathering function trng_get_bytes based on your comments.

@hanno-becker
Copy link

Hi @ganesh-ramachandran, thank you for your rework! Could you point me to the technical reference manual for the board?

@ghost
Copy link
Author

ghost commented Jan 31, 2018

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

@ciarmcom
Copy link
Member

ciarmcom commented Feb 7, 2018

ARM Internal Ref: IOTSSL-2073

@0xc0170
Copy link
Contributor

0xc0170 commented Feb 9, 2018

@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) {

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?

Copy link
Author

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
}
}

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.

Copy link
Author

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) {

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?

Copy link
Author

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++) {
Copy link

@hanno-becker hanno-becker Feb 9, 2018

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.

Copy link
Author

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.

Copy link

@hanno-becker hanno-becker left a 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)
Copy link
Contributor

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)

Copy link
Author

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,
Copy link
Contributor

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)
{
Copy link
Contributor

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)

@cmonr
Copy link
Contributor

cmonr commented Mar 23, 2018

Still waiting on @c1728p9 for feedback on @0xc0170 comment.

0xc0170
0xc0170 previously approved these changes Mar 23, 2018
@0xc0170
Copy link
Contributor

0xc0170 commented Mar 23, 2018

Still waiting on @c1728p9 for feedback on @0xc0170 comment.

Should not block this? It's more for the ongoing specification in sleep.

@0xc0170
Copy link
Contributor

0xc0170 commented Mar 28, 2018

/morph build

@mbed-ci
Copy link

mbed-ci commented Mar 28, 2018

Build : SUCCESS

Build number : 1616
Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/5902/

Triggering tests

/morph test
/morph uvisor-test
/morph export-build
/morph mbed2-build

@mazimkhan
Copy link

@ganesh-ramachandran thanks for incorporating the comments. Approved.

@mbed-ci
Copy link

mbed-ci commented Mar 28, 2018

@mbed-ci
Copy link

mbed-ci commented Mar 29, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants