You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by je...@apache.org on 2021/04/22 07:49:32 UTC

[mynewt-core] 05/05: mcu/nrf5340: Add combine build for app and net cores

This is an automated email from the ASF dual-hosted git repository.

jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit 8a853d0e841b48259f8c5e8c77e0cb29fa88f03c
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Fri Apr 9 10:55:40 2021 +0200

    mcu/nrf5340: Add combine build for app and net cores
    
    This adds possibility to build application core image
    along with network core one.
    Then network image is embedded inside application image.
    This will allow for newtmgr to upgrade device with just
    image for both cores.
    
    To enable this syscfg will need to have:
    NRF5340_EMBED_NET_CORE: 1
    By default this will build nimble provided nordic_pca10095-blehci
    target to be embedded. It can be change with syscfg value:
    NET_CORE_IMAGE_TARGET_NAME that can specify different target for
    net core build.
---
 hw/mcu/nordic/nrf5340/net_core_image/pkg.yml       | 28 +++++++++++++
 .../net_core_image/scripts/build_net_core.sh       | 49 ++++++++++++++++++++++
 hw/mcu/nordic/nrf5340/net_core_image/syscfg.yml    | 27 ++++++++++++
 hw/mcu/nordic/nrf5340/nrf5340.ld                   |  7 ++++
 hw/mcu/nordic/nrf5340/pkg.yml                      |  3 ++
 hw/mcu/nordic/nrf5340/syscfg.yml                   |  4 ++
 6 files changed, 118 insertions(+)

diff --git a/hw/mcu/nordic/nrf5340/net_core_image/pkg.yml b/hw/mcu/nordic/nrf5340/net_core_image/pkg.yml
new file mode 100644
index 0000000..1d4bc28
--- /dev/null
+++ b/hw/mcu/nordic/nrf5340/net_core_image/pkg.yml
@@ -0,0 +1,28 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+pkg.name: hw/mcu/nordic/nrf5340/net_core_image
+pkg.description: Package that incorporates net core build into app image
+pkg.author: "Apache Mynewt <de...@mynewt.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+    - nrf5340
+
+pkg.pre_link_cmds:
+    scripts/build_net_core.sh: 100
diff --git a/hw/mcu/nordic/nrf5340/net_core_image/scripts/build_net_core.sh b/hw/mcu/nordic/nrf5340/net_core_image/scripts/build_net_core.sh
new file mode 100755
index 0000000..eed4fa3
--- /dev/null
+++ b/hw/mcu/nordic/nrf5340/net_core_image/scripts/build_net_core.sh
@@ -0,0 +1,49 @@
+#!/bin/bash
+
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+NEWT=${MYNEWT_NEWT_PATH}
+OBJCOPY=${MYNEWT_OBJCOPY_PATH}
+AR=${MYNEWT_AR_PATH}
+NET_CORE_A=${MYNEWT_USER_SRC_DIR}/net_core_img.a
+NET_CORE_O=${MYNEWT_USER_SRC_DIR}/net_core_img.o
+
+export WORK_DIR=${MYNEWT_USER_WORK_DIR}
+
+export NEWT_CREATE_IMAGE_OUTPUT=$WORK_DIR/create_image_output
+pushd $MYNEWT_PROJECT_ROOT
+
+${NEWT} create-image ${MYNEWT_VAL_NET_CORE_IMAGE_TARGET_NAME} timestamp -o $NEWT_CREATE_IMAGE_OUTPUT
+# Extract image name from output
+export NET_CORE_IMG=`awk '/App image successfully generated:/ { print $NF }' $NEWT_CREATE_IMAGE_OUTPUT`
+
+cd ${WORK_DIR}
+if [ -n "$NET_CORE_IMG" ] ; then
+  # Copy image to local folder so objcopy creates symbols with short names instead of very long ones.
+  # Name net_core.img translates to two symbols created by objcopy:
+  # _binary_net_core_img_start, _binary_net_core_img_end those symbols are then used to reference content
+  # of net_core.img. Changing this name could lead to invalid builds.
+  cp $NET_CORE_IMG ${WORK_DIR}/net_core.img
+
+  # Make .o file from existing binary image
+  ${OBJCOPY} --rename-section .data=.net_core_img,alloc,load,readonly,data,contents -O elf32-littlearm -B armv8-m.main -I binary net_core.img ${NET_CORE_O}
+
+  # Archive .o for newt to use
+  ${AR} -rcs ${NET_CORE_A} ${NET_CORE_O}
+fi
+popd
diff --git a/hw/mcu/nordic/nrf5340/net_core_image/syscfg.yml b/hw/mcu/nordic/nrf5340/net_core_image/syscfg.yml
new file mode 100644
index 0000000..163e116
--- /dev/null
+++ b/hw/mcu/nordic/nrf5340/net_core_image/syscfg.yml
@@ -0,0 +1,27 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+syscfg.defs:
+    NET_CORE_IMAGE_TARGET_NAME:
+        description: >
+            Target name to build for NET core binary for single image build.
+            Default is set for nordic_pca10095 bsp and could be changed,
+            although right now this targets could be used for other bsp
+            that are based on NRF5340 since target build just BLE controller
+            without anything specific to pca10095 board.
+        value: "@apache-mynewt-nimble/targets/nordic_pca10095-blehci"
diff --git a/hw/mcu/nordic/nrf5340/nrf5340.ld b/hw/mcu/nordic/nrf5340/nrf5340.ld
index 4cb96dc..e5efe86 100644
--- a/hw/mcu/nordic/nrf5340/nrf5340.ld
+++ b/hw/mcu/nordic/nrf5340/nrf5340.ld
@@ -86,6 +86,13 @@ SECTIONS
     } > FLASH
 
 
+    .net_core_img :
+    {
+        PROVIDE(net_core_img_start = .);
+        KEEP(*(.net_core_img));
+        PROVIDE(net_core_img_end = .);
+    } > FLASH
+
     .ARM.extab :
     {
         *(.ARM.extab* .gnu.linkonce.armextab.*)
diff --git a/hw/mcu/nordic/nrf5340/pkg.yml b/hw/mcu/nordic/nrf5340/pkg.yml
index 80860c6..0958736 100644
--- a/hw/mcu/nordic/nrf5340/pkg.yml
+++ b/hw/mcu/nordic/nrf5340/pkg.yml
@@ -101,3 +101,6 @@ pkg.deps.I2C_2':
 
 pkg.deps.I2C_3':
     - "@apache-mynewt-core/hw/bus/drivers/i2c_nrf5340"
+
+pkg.deps.NRF5340_EMBED_NET_CORE:
+    - "@apache-mynewt-core/hw/mcu/nordic/nrf5340/net_core_image"
diff --git a/hw/mcu/nordic/nrf5340/syscfg.yml b/hw/mcu/nordic/nrf5340/syscfg.yml
index 18be972..c031f58 100644
--- a/hw/mcu/nordic/nrf5340/syscfg.yml
+++ b/hw/mcu/nordic/nrf5340/syscfg.yml
@@ -503,6 +503,10 @@ syscfg.defs:
         description: 'Frequency [kHz] for I2C_3'
         value: 100
 
+    NRF5340_EMBED_NET_CORE:
+        description: Embed net core image in application image for single image build.
+        value: 0
+
 syscfg.vals:
     OS_TICKS_PER_SEC: 128