The world of Azure IoT that can be played on the DE10-Nano board: Ajuchika with FPGA !!?

Hello. I'm happy to join the Intel® FPGA User Community, but I'm sorry that I've been ruining the genre of tags and article lists due to my poor dexterity a.k.a. But Elixir and Nerves are good ^^;

And this time, I was invited to "Intel® FPGA Advent Calendar 2020" and nominated a major role in charge of the 22nd day. However, since I am the weakest author in the FPGA area, I cannot deliver content that will satisfy all of you.

So, I would like to introduce you to a slightly different world without any HDL or HLS code (I wonder if this Advent Calendar is okay?

It's very simple to do. Throw the FPGA circuit image through Microsoft Azure, which is a cloud service, and "Ajuchika" on the DE10-Nano board. It's "Ajuchika" because it's L-Chika over Azure. I accept the objection. (In addition, in certain NervesJP neighborhood, "Web Chika", "Phenichika", "Emnetika", etc. ^^;

By applying the method introduced here, it is possible to freely (?) Remotely update the circuit of the FPGA board that is deployed in the production environment from the development site. It's the so-called OTA (Over the Air). But this example is just L-Chika ,,, this is a waste of technology ww

** [PR] There is something good ♪ [Advertisement] ** ALGYAN

_ @ Maker Faire Tokyo 2020 "IoT ALGYAN" At the booth _

What is Azure IoT?

IoT is a mixed martial art of information science! by George: sunglasses:

Of course, we have to develop end devices, upload data to the cloud, and analyze the collected data neatly. I can't do it at all.

Microsoft Azure, which everyone loves, is a great ally in such a case. https://azure.microsoft.com

You can easily develop, maintain, and deploy end devices, and you can immediately visualize the data collected by SaaS. Statistical processing with a machine learning engine is also good.

There is "Azure IoT Hub" as a typical service. Rather than explain it in my own words, let's quote the official material ~~ pack ~~.

--Azure IoT Hub Overview | Microsoft Docs

IoT Hub is a managed service hosted in the cloud that acts as a central message hub for two-way communication between IoT applications and the devices they manage. You can use Azure IoT Hub to build IoT solutions and provide reliable, secure communication between millions of IoT devices and cloud-hosted solution backends. You can connect almost any device to the IoT Hub.

IoT Hub supports both device-to-cloud and cloud-to-device communication. IoT Hub supports multiple messaging patterns, including telemetry between the device and the cloud, uploading files from the device, and request/response methods for controlling the device from the cloud. IoT Hub monitoring helps maintain the health of your solution by tracking events such as device creation, device failures, and device connectivity.

With IoT Hub capabilities, you can build scalable, feature-rich IoT solutions such as managing industrial equipment used in manufacturing, tracking high-value medical assets, and monitoring office building usage.

Play with DE10-Nano board

Microsoft Azure offers the Azure Certified Device program. In short, this device or board is perfect for Azure services! It shows that Microsoft has accredited it.

Terasic's DE10-Nano Kit is one of these certified boards.

image.png

_ Captured from Azure Certified Device catalog (preview) _

In short, with DE10-Nano, you can easily enjoy the world of Azure IoT.

However, there is one caveat. Image of microSD card released by Terasic has kernel rootfs of Ubuntu 16.04 LTS. Since the latest Azure IoT Edge Runtime depends on Open SSL 1.1, it cannot be installed straightforwardly as it is (older versions can be installed). So, you need to upgrade rootfs to Ubuntu 18.04 LTS, or do some other work.

For those who are so dull ,,,, we have released various images corresponding to this. Please use it if you like.

Please refer to this text for the specific work you are doing.

Rewrite FPGA over the cloud! ?? ??

Now the main subject. Let's rewrite the FPGA circuit over Azure.

Karakuri looks like this.

image.png

  1. First, design the system normally. Everyone loves Quartus Prime (18.1 Lite Edition) for FPGA logic. If you want to develop the software properly, use SoC EDS. In addition, a Device Tree Blob file or preloader containing hardware information is created according to the circuit configuration of the FPGA section and the interface configuration with the HPS section.
  2. The IoT Edge module runs as a Docker container, very roughly. Deploy the container image to the Azure ready IoT board and run the container there. Here, create a Dockerfile that includes the operation of rewriting the circuit of the FPGA part, and build it as a container image.
  3. Create your own registry in a service called Azure Container Registry. This is a service equivalent to Docker Hub dedicated to Azure. In response, push the built container image.
  4. Set the operation of IoT Hub and register the target DE10-Nano board as an IoT Edege device. Then, deploy the container image registered in Azure Container Registry to the IoT Edge device.
  5. That's it! On the DE10-Nano board, the container image is executed as an IoT Edge module. Then, the circuit of the FPGA section is rewritten and the software is executed.

I will explain only a little with the example of Ajuchika.

① System design including FPGA

The circuit design was slightly rewritten using DE10_NANO_SoC_FB included in the DE10-Nano System CD as a project template (GSRD: Golden System Reference Design).

The total number of changes in the Verilog HDL code is only 12 lines, which is not included in the changed home ^^;

I haven't implemented any software. Because it's just L-Chika

② Create Dockerfile and build image

I added the Dockerfile to Like this.

#Choosing a base kernel
FROM arm32v7/ubuntu:xenial AS base
#Originally install Azure IoT device SDK
#RUN apt-get update && \
#    apt-get install -y --no-install-recommends software-properties-common && \
#    add-apt-repository -y ppa:aziotsdklinux/ppa-azureiot && \
#    apt-get update && \
#    apt-get install -y azure-iot-sdk-c-dev && \
#    rm -rf /var/lib/apt/lists/

#Build an application that originally runs in the IoT Edge module
#FROM base AS build-env
#RUN apt-get update && \
#    apt-get install -y --no-install-recommends cmake gcc g++ make && \
#    rm -rf /var/lib/apt/lists/* 
#WORKDIR /app
#COPY . ./
#RUN cmake . 
#RUN make

#Run Device Tree Overlay
FROM base
WORKDIR /overlay
#Copy the required files into the container image
COPY ./soc_system_lchika.rbf ./
COPY ./overlay_lchika.dtbo ./
COPY ./overlay_lchika.sh ./
#Run the Device Tree Overlay script
RUN chmod +x /overlay/overlay_lchika.sh
CMD ["/overlay/overlay_lchika.sh"]

#Originally runs an IoT Edge application
#FROM base
#WORKDIR /app
#COPY --from=build-env /app ./
#RUN useradd -ms /bin/bash moduleuser
#USER moduleuser
#CMD ["./main"]

I pulled the original Azure sample code as a template, but most of it is commented out, because I want to do only L Chika palm software (ry) Originally, the tool for building the IoT Edge module called Azure IoT device SDK is installed, and the application of the IoT Edge module is built. Then run the app in the container image.

This time, these three files are included in the container image as a group of files required for rewriting the FPGA circuit.

--soc_system_lchika.rbf: Circuit information --overlay_lchika.dtbo: Device tree file --overlay_lchika.sh: Circuit rewriting script

Let's take a look at the contents of the circuit rewrite script.

overlay_lchika.sh


#!/bin/bash

#Define file and directory names
DTBO="overlay_lchika.dtbo"
RBF="soc_system_lchika.rbf"
DTO_DIR="/sys/kernel/config/device-tree/overlays/socfpga"

echo 'Message : Starting Device Overlay at '$(date)

echo "Message : Checking Current Device Tree"
if [ -d ${DTO_DIR} ];then
    echo 'Message : Current Device Tree Overlay Name is '$(cat ${DTO_DIR}/path)
    
    echo "Message : Deleting ${DTO_DIR}"
    rmdir ${DTO_DIR}

    echo "Message : Successfully ${DTO_DIR} deleted"
else
    echo "Warning : ${DTO_DIR} does not exist"
fi

echo "Message : Copy dtbo & rbf file"
cp /overlay/${DTBO} /lib/firmware
cp /overlay/${RBF} /lib/firmware

echo "Message : Creating New Overlay Directory"
mkdir ${DTO_DIR}

echo "Message : Updating Overlay"
echo ${DTBO} > ${DTO_DIR}/path

echo 'Message : Checking Current Device Overlay Name is '$(cat ${DTO_DIR}/path)
echo "Message : Successfully Device Tree Overlay Done"

echo 'Message : Overlay Done at '$(date)

#The IoT Edge module automatically runs when there is no more work to do
#The container will continue to start because it will be restarted.
tail -f /dev/null
exit 0

For those who are familiar with it, I think that the seeds of wasting this technology are gradually becoming clearer. In other words, I'm just using the Linux Device Tree Overlay function over the Docker container.

In the DE10-Nano Linux kernel, / sys/kernel/config/device-tree/overlays/socfpga contains modules and various files for Device Tree Overlay operations. By putting the circuit information and device tree file in / lib/firmware and creating this directory, the circuit information and the device tree information between HPS-FPGA will be updated.

For a detailed explanation of Device Tree Overlay, see @ eofz's article here.

-FPGA Config with DeviceTree Overlay (DE10nano) --Qiita

③ Push container image

If you come this far, you're ready to go.

After all, like Microsoft, Azure has a good affinity with Visual Studio Code. By using Azure IoT Tools, which is an extension function for Azure IoT, you can build IoT Edge modules and operate IoT Hub on VS Code.

Build the IoT Edge module with Azure IoT Tools.

image.png

Then, the IoT Edge module (container image) will be registered in Azure Container Registry in no time.

image.png

④ Deploy IoT Edge module via IoT Hub

All you have to do now is operate the IoT Hub setting screen on your web browser. With this feeling, we will deploy and specify AwesomeLchika, which is an IoT Edge module for Ajuchika, to DE10-Nano registered as an IoT Edge device (Zatsu).

image.png

⑤ Module execution on IoT Edge device

After that, please enjoy the wonderful L Chika ~

https://youtu.be/C_swG0KLgDg?t=9759

~~ What a sober look orz ~~

Notes

Oh awesome! !! Well, it's okay to lie, just think about it: D

Then, when it comes to rewriting any circuit information remotely, that is not the case. It is the range that can be supported by Device Tree Overlay. Roughly speaking, the preloader cannot be rewritten, and the HPS-FPGA interface must be fixed from the beginning. Also, since the device tree is rewritten, it is necessary to temporarily stop the operation of the application that constantly accesses the FPGA from the processor. If you rewrite it during operation, the kernel will hang lightly. Then, since the device tree is operated, the Docker container needs to be executed with privileges. It's a disgusting place, and I think there is some other way.

in conclusion

So, in this article, I introduced the world of Azure IoT to FPGA people. Actually, the content of this article may be a digest version of ALGYAN Hands-on conducted on September 20, 2020 (Sun).

-Actual machine rental available![Online] Remotely rewrite FPGA circuit → Magnificent L Chika! Intel FPGA Hands-on # 1 --connpass

image.png

And all the hands-on texts and design data are available on GitHub below. https://github.com/algyan/IntelFPGA_AzureOTA

If anything, Hands-on day archive video is also available. generous! !! ??

image.png

Please follow the texts and videos and try "Ajuchika" . (However, the text seems to have a total of 111 pages. I know Kurttel: innocent:

Next time preview? ??

In Azure IoT, in addition to the IoT Hub introduced this time, it is possible to develop and manage IoT services like Saas (Software as a Service) "IoT Central", and it is possible to link like Digital Twin Plug and Play and other services are also available.

In the demo shown on Twitter at the beginning, the RFS Daugher Card with 9-axis and temperature / humidity sensors is inserted into DE10-Nano, and those values ​​are thrown into IoT Central for visualization.

At ALGYAN, play with these services on the DE10-Nano board! It's a sequel, hands-on planning or not, or it's a rajbhandari (or rather, FPGA tsuyotsuyo, please help me with the help m (_ _) m

Please join the ALGYAN community and check out the latest information. Will the number of members exceed 5,500 by 2020? ?? https://algyan.connpass.com/

image.png

Recommended Posts

The world of Azure IoT that can be played on the DE10-Nano board: Ajuchika with FPGA !!?
Four-in-a-row with gravity that can be played on the console
Summary of css selectors that can be used with Nookogiri
Firebase-Realtime Database on Android that can be used with copy
A scraping of past weather that can be seen on the Japan Meteorological Agency website
Summary of JDK that can be installed with Homebrew (as of November 2019)
Set the access load that can be changed graphically with JMeter (Part 2)
About the problem that the server can not be started with rails s
Set the access load that can be changed graphically with JMeter (Part 1)
[Rails] "pry-rails" that can be used when saving with the create method
Graph the sensor information of Raspberry Pi and prepare an environment that can be checked with a web browser
Organize methods that can be used with StringUtils
[Ruby] Methods that can be used with strings
[Book Review] Unit testing of programming sites that can be done with zero experience