Skip to content

Support Nuvoton targets #25

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

Closed
wants to merge 1 commit into from
Closed

Support Nuvoton targets #25

wants to merge 1 commit into from

Conversation

ccli8
Copy link
Contributor

@ccli8 ccli8 commented Sep 24, 2019

This PR tries to add Nuvoton support for pelion application on the following targets:

  • NUMAKER_PFM_NUC472
  • NUMAKER_PFM_M487
  • NUMAKER_IOT_M487
  • NU_PFM_M2351_NPSA_NS
  • NUMAKER_IOT_M263A

Compare to other targets, Nuvoton support has the following major differences:

  1. Use NUSD rather than SD for external storage. NUSD is SD card in SD bus mode and is on-board on Nuvoton targets. Because Mbed OS doesn't support SDIO HAL yet, provide its dedicated driver COMPONENT_NUSD.lib instead.
  2. Configure (max) bootloader size to 64KiB from 32KiB. This leaves room for debug build.
  3. NU_PFM_M2351_NPSA_NS is non-PSA, non-secuare TZ target. The memory configuration of its pre-built secure image/lib in mbed-os cannot afford pelion application. Provide specialized version in the application instead.

Note: NU_PFM_M2351_NPSA_NS and NUMAKER_IOT_M263A require mbed-os to be 5.14.0 or afterwards.

@anttiylitokola
Copy link
Contributor

Can one of the admins verify this patch?

.gitignore Outdated

# Target-specific object files (force-include)
!targets/TARGET_NUVOTON/**

Choose a reason for hiding this comment

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

Please remove targets from .gitignore

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Continuing #25 (comment), this is necessary to guarantee the secure image/lib are added into git. Notice .o files are excluded from git version control. This make secure library cmse_lib.o not versioned without the line !targets/TARGET_NUVOTON/**.

.gitignore

# Compiled Object files
*.slo
*.lo
*.o
*.obj

Copy link
Contributor

Choose a reason for hiding this comment

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

git add -f should do it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it do and recover .gitignore

mbed-os.lib Outdated
@@ -1 +1 @@
https://github.com/ARMmbed/mbed-os/#7482462434d5cf718177653ef797547a976a7c5e
https://github.com/ARMmbed/mbed-os/#b6e5a0a8afa34dec9dae8963778aebce0c82a54b

Choose a reason for hiding this comment

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

Please don't update Mbed OS.
However, this shouldn't be a problem now as it's using the same version that has been merged to master earlier.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rebase and the resultant mbed-os.lib has been 5.14.0. So need no change.

mbed_app.json Outdated
"update-client.storage-address" : "(1024*1024*64)",
"update-client.storage-size" : "((MBED_ROM_START + MBED_ROM_SIZE - APPLICATION_ADDR) * MBED_CONF_UPDATE_CLIENT_STORAGE_LOCATIONS)",
"update-client.storage-locations" : 1,

Choose a reason for hiding this comment

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

Please remove extra blank lines

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Copy link

@MarceloSalazar MarceloSalazar left a comment

Choose a reason for hiding this comment

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

Please review feedback

@MarceloSalazar
Copy link

In addition, please move these files to Mbed OS

  • targets/TARGET_NUVOTON/TARGET_NU_PFM_M2351_NPSA_NS/NuMaker-mbed-TZ-secure-example.hex
  • targets/TARGET_NUVOTON/TARGET_NU_PFM_M2351_NPSA_NS/cmse_lib.o

@MarceloSalazar
Copy link

@teetak01 do you want to have a look and comment?

@MarceloSalazar MarceloSalazar added the WIP Work in progress label Sep 25, 2019
@ccli8
Copy link
Contributor Author

ccli8 commented Sep 26, 2019

Make modifications:

  1. Do rebase
  2. Remove change of mbed-os.lib
  3. Remove extra blank lines

@ccli8
Copy link
Contributor Author

ccli8 commented Sep 26, 2019

In addition, please move these files to Mbed OS

@MarceloSalazar In mbed-os tree, there has been one pre-built secure image/lib which has the following memory partition but cannot afford pelion application. It is for general:

  • Flash (512KiB in total): 256KiB for secure and 256KiB for nonsecure
  • SRAM (96KiB in total): 32KiB for secure and 64KiB for nonsecure

For pelion application, memory must be re-partitioned and the resultant secure image/lib must place in pelion application directory and the pre-built one in mbed-os tree must exclude:

  • Flash (512KiB in total): 64KiB for secure and 448KiB for nonsecure
  • SRAM (96KiB in total): 8KiB for secure and 88KiB for nonsecure

Anyway, the root cause is limited memory: Cannot have a memory partition to meet both general and pelion.

Copy link
Contributor

@teetak01 teetak01 left a comment

Choose a reason for hiding this comment

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

I think the .o file really belongs to Mbed OS

@@ -0,0 +1 @@
https://github.com/OpenNuvoton/NuMaker-mbed-SD-driver/#3221af84c7fd96b877ecd6d2c0863ba36eb9b1f2
Copy link
Contributor

Choose a reason for hiding this comment

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

We could use here the COMPONENT_ naming to hide the driver when not needed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@teetak01 Not clear. Would you comment more?

Copy link
Contributor

Choose a reason for hiding this comment

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

#4 for example.

So it could be COMPONENT_NUMAKER_MBED_SD_DRIVER.lib

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@teetak01 Currently, the COMPONENT_ naming has been adopted. It is COMPONENT_NUSD. Except for more verbose, change to COMPONENT_NUMAKER_MBED_SD_DRIVER from COMPONENT_NUSD? Though, COMPONENT_NUSD has been used for some time.

"NUMAKER_PFM_NUC472": {
            "target.network-default-interface-type"     : "ETHERNET",
            "target.bootloader_img"                     : "bootloader/mbed-bootloader-nuc472-block_device-kvstore-v4.1.0.bin",
            "target.header_offset"                      : "0x12000",
            "target.app_offset"                         : "0x12400",
            
            "target.components_add"                     : ["NUSD"],
            
            "nusd.provide-default-blockdevice"          : true,

Copy link
Contributor

Choose a reason for hiding this comment

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

Fine be me.

@ccli8
Copy link
Contributor Author

ccli8 commented Sep 27, 2019

I think the .o file really belongs to Mbed OS

@teetak01 Do you mean cmse_lib.o? Due to memory limit #25 (comment), we can just provide a specilaized version for pelion application.

@ccli8
Copy link
Contributor Author

ccli8 commented Sep 27, 2019

Make modifications:

  1. Recover .gitignore and force-add cmse_lib.o into git with git add -f
  2. Remove "mbed-cloud-client.external-sst-support" : 1, due to default already

@teetak01
Copy link
Contributor

teetak01 commented Sep 27, 2019

@ccli8 should we just fix the pre-build images in Mbed OS instead? What is the main usecase here? I am not sure do we want to support custom use-cases which might break with Mbed OS updates.

Is there some other use-case which requires 256 KiB RAM for secure or would it just mean that this target does not meet the minimum requirements for Pelion?

@ccli8
Copy link
Contributor Author

ccli8 commented Sep 27, 2019

should we just fix the pre-build images in Mbed OS instead? What is the main usecase here? I am not sure do we want to support custom use-cases which might break with Mbed OS updates.

OK. The thinking seems more reasonable and we will meet less compatibility issue. I will update pre-built secure image/lib in mbe-os tree.

@yogpan01
Copy link
Contributor

yogpan01 commented Oct 2, 2019

rebuild

@anttiylitokola
Copy link
Contributor

run-ci

@ccli8
Copy link
Contributor Author

ccli8 commented Oct 2, 2019

This PR waits on ARMmbed/mbed-os#11594 to update default M2351 secure program in mbed-os tree which can have supported pelion application. This PR itself also needs modification to remove M2351 secure program to just link with the default one in mbed-os tree above.

@MarceloSalazar
Copy link

@ccli8 can you please split the PR to introduce support for one platform at a time?
This will let us test and progress with platforms without having to wait for others.

@ccli8
Copy link
Contributor Author

ccli8 commented Oct 4, 2019

Make modifications:

  1. Do rebase
  2. For M2351, remove attached non-PSA secure program and rely on default one in mbed-os tree M2351: Pre-build secure image/lib to favor pelion application mbed-os#11594.

@ccli8
Copy link
Contributor Author

ccli8 commented Oct 4, 2019

Split this PR into 5:

Based on mbed-os-pelion-example master/mbed-bootloader 4.1.0/mbed-cloud-client 4.0.0,
support Nuvoton targets:
1.  Support Nuvoton targets:
    -   NUMAKER_PFM_NUC472
    -   NUMAKER_PFM_M487
    -   NUMAKER_IOT_M487 V1.3
        Compared to V1.2, V1.3 adds support for ESP8266 RTS/CTS/RST pins. V1.3 is incompatible with V1.2 on ESP8266.
    -   NU_PFM_M2351_NPSA_NS
    -   NUMAKER_IOT_M263A
2.  Support M2351
    (1) Use pre-built secure image/lib
    (2) Build by running:
        $ mbed compile -m NU_PFM_M2351_NPSA_NS -t ARMC6
3.  With RoT, bootloader and client application must match:
    (1) Insecure (fake) RoT:
        Bootloader/mbed_lib.json: mbed-bootloader.use-kvstore-rot == 0
        mbed-cloud-client/mbed_lib.json: mbed-cloud-client.external-sst-support == 0
    (2) KVStore RoT:
        Bootloader/mbed_lib.json: mbed-bootloader.use-kvstore-rot == 1
        mbed-cloud-client/mbed_lib.json: mbed-cloud-client.external-sst-support == 1
4.  Change storage to NUSD (SD card in SDIO bus mode) from SD (SD card SPI bus mode)
    (1) Add COMPONENT_NUSD.lib.
    (2) Add component NUSD (target.components_add).
    (3) Change default BlockDevice to NUSD:
        Override BlockDevice::get_default_instance (nusd.provide-default-blockdevice).
        Required since mbed-cloud-client 2.1.0 (arm_uc_blockdevice_ext) or in:
        mbed-bootloader/modules/storage/pal-blockdevice/source/arm_uc_pal_blockdevice_mbed.cpp
    (4) Enable kvstore with blockdevice type being "other".
        i)  Override get_other_blockdevice() (nusd.provide-kvstore-other-blockdevice).
        ii) Configure storage type to "FILESYSTEM".
        iii)Configure file system type to "LITTLE".
        vi) Configure block device type to "other".
        v)  Configure external size to 64MiB, which cannot overlap with update-client.
            storage-address/update-client.storage-size.
5.  Change back UARTSerial tx/rx buffer size from 1024/1024 to 256/256. This can reduce
    memory footprint by (1024 - 256) * 2 = 1.5KiB. Because this configuration influences
    both ESP8266 and default console (platfrom/mbed_retarget.cpp), memory reduction can
    achieve 1.5KiB x 2 = 3KiB.
6.  Enlarge ESP8266 'send tcp data' timeout on Nuvoton targets
    Pelion connection has some failure rate with this. Enlarging ESP8266_SEND_TIMEOUT
    can just relieve the issue. A ticket has raised to address it:
    ARMmbed/mbed-os#11544
7.  Requirements for mbed-os version:
    -   mbed-os 5.13.0 (or afterwards) to support kvstore with block device type being "other"
    -   mbed-os 5.13.1 (or afterwards) to fix 'undefined pal_plat_osEntropyInject(...)' error
    -   mbed-os 5.14.0 (or afterwards) to support NUMAKER_IOT_M263A
    -   mbed-os 5.14.0 (or afterwards) to support NU_PFM_M2351_NPSA_NS target renaming and combined build
    -   mbed-os 5.14.? (or afterwards) to support NU_PFM_M2351_NPSA_S default secure program which has partitioned memory for Pelion application
@ccli8 ccli8 closed this Oct 28, 2019
@ccli8 ccli8 deleted the nuvoton_initial_support branch November 20, 2019 10:21
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.

5 participants