ARM64 architecture and programming, the world’s original ARM64 experiment, stupid uncle lead team, you yo!

* * * *

ARM64 Architecture and Programming – YX Audio: 00:00./00:20 **

List of experimental equipment for the third season of running Bar video course

  1. Hardware development platform: Raspberry PI 4B (2G or 4G memory)
  2. Software simulation platform: QEMU BenOS customized version
  3. Development host: Ubuntu Linux 20.04
  4. A MicroSD card and a card reader
  5. One USB to serial cable
  6. J-link V11 emulator

Note:

  1. J-link emulator needs to be purchased. Please log on the official website of SEGGER to check the agent information in China. Students, teachers and individual fans can contact j-Link China agent to purchase J-Link EDU version.

  2. Readers are advised to download the virtual machine image made by Uncle Ben (VMware Player or VirtualBox support), which has built-in OpenOCD software and QEMU BenOS customized version. Virtual machine image download address: subscribe to the third season of the flagship video course partners please ping uncle request download address.

If you need to install Ubuntu Linux on your physical machine, you can. The deb for QEMU_BenOS is provided. Note that the deb is only available in Ubuntu 20.04. Among them:

  1. Qemu-system-arm-pi44.4.1.50-3_without_gic_amd64: indicates that only the Legacy Interrupt Controller version in Raspberry PI 4 is supported.
  2. Qemu-system-arm-pi44.2.50-3_with_gic_amd64: indicates that only GIC in Raspberry PI 4 is supported. You can install one of them first, wait until you do the interrupt related experiment, and then switch according to the video course.
  3. Openocd-benos_1-0-2_amd64: OpenOCD for Raspberry PI 4

Install raspberry PI OS and test BenOS

Small partners can refer to “Raspberry PI +JLINK experimental environment building.pdf” this document to.

When you get a brand new Raspberry PI 4 and a brand new MicroSD card, you can first burn a Raspberry PI OS, then connect the serial cable, and test whether the serial cable is connected successfully.

  1. To download the latest Raspberry Pi OS, be sure to use Raspberry Pi OS. Do not use third-party Raspberry Pi OS such as Ubuntu for Raspberry Pi. Domestic partners can be downloaded from tsinghua source.
https://mirrors.tuna.tsinghua.edu.cn/raspberry-pi-os-images/raspios_arm64/images/raspios_arm64-20
Copy the code

After downloading, use the write tool to burn the image to MircoSD. In Windows, Win32DiskImager software can be used for burning, and Linux host can use dd command. 2. Modify the config. TXT configuration file in the boot partition of the MircoSD card and add two new lines to this file.

uart_2ndstage=1
enable_uart=1
Copy the code

3. Plug MircoSD back into raspberry PI 4 and power it on. The default PI OS user name is PI and the password is Raspberry

4. Configure wifi on raspberry PI 4. You can use the configuration tool on the raspberry PI to run the following command in the serial port.

$ sudo raspi-config
Copy the code

Select Network Options to configure the WIFI password.

  1. Update the software package. We’d better have a system-wide update package, which will automatically update the SPI BootRom firmware.
sudo apt update
sudo apt full-upgrade
sudo reboot
Copy the code

After the update is complete, we reboot the machine. 5. Power off and unplug the MicroSD card. Copy the raspberry PI firmware from the lab code for this season’s class into MicroSD. The directory is armV8_trainning /tools/pi_boot_fw

Copy all the files in the pi_boot_fw directory to the MicroSD boot partition. The reference code of the experiment is shown in Baidu web disk:

Armv8_trainning_xxxxx.tar.xz in the experiment reference code directory, please read the “Experiment Reference Code Usage Guide” and the corresponding video explanation carefully before the experiment.

Then plug the MicroSD into the raspberry PI and turn it on. You should see the following print. The serial port is ready.

Elf @ 0xFec00200 partition 0 MESS:00:00:05.264585:0: arasan: arasan_EMmc_open MESS:00:00:06.125361:0: Read command line from file 'cmdline.txt': MESS:00:00:06.131256:0: 'logdev=ttyS1' MESS:00:00:07.167549:0: BRFS: File read: 13 bytes MESS:00:00:07.179048:0: BRFS: File read: / MFS /sd/benos4.bin MESS:00:00:07.181512:0: Loading 'benos4.bin' to 0x80000 size 0x4b30 mes :00:00:07.187507:0: Device tree loaded to 0x2Eff4200 (size 0xBd33) MESS:00:00:07.193841:0: uart: Set PL011 baud rate to 103448.300000 Hz MESS:00:00:07.202824:0: uart: Baud rate change done... Booting at EL2 Booting at EL1 Welcome BenOS!Copy the code

Raspberry PI and JLINK

Small partners can refer to “Raspberry PI +JLINK experimental environment building.pdf” this document to.

1. Hardware Connection To use the J-Link emulator on the Raspberry PI, first connect the JTAG interface of the J-Link emulator to the expansion board of the Raspberry PI. The Raspberry PI extension has a JTAG interface built into it. We can use dupont wire to connect. The J-Link emulator provides a 20-pin JTAG interface, as shown in the figure.

Small partners must distinguish clearly, which is the JTAG in JLINK simulator pin 1. The awkward row of pins near the JTAG interface, of which the rightmost one is pin 1.

The connection between raspberry PI and J-Link emulator requires 8 wires, as shown in the table. Table Raspberry PI connects to j-Link emulator

JTAG interface Raspberry PI pin number Name of raspberry PI pin
VTref 01 3.3 v
TRST 15 GPIO22
TDI 37 GPIO26
TMS 13 GPIO27
TCK 22 GPIO25
RTCK 16 GPIO23
TDO 18 GPIO24
GND 39 GND

The finished connection is shown as follows. It is strongly recommended that you use 8 DuPont wires of different colors to connect, so that it is not easy to connect wrong wires.

When you practiced metalworking in the freshman year, you even made a complicated hammer. Even these 8 wires are a piece of cake for you. When the connection is complete, check it again carefully.

Copy the loop.bin program to the microSD card. You also need to modify the config.txt configuration file to enable support for the RASPberry Party JTAG interface. Loop.bin and modified config. TXT are stored in the armV8_trainning /tools/jlink directory and can be copied to an SD card. Note that the original start4.elf files in SD should still be retained. The complete config.txt file is as follows.

# BenOS for JLINK debug
[pi4]
kernel=loop.bin
[pi3]
kernel=loop.bin
[all]
arm_64bit=1 
enable_uart=1 
uart_2ndstage=1 

enable_jtag_gpio=1
gpio=22-27=a4
init_uart_clock=48000000
init_uart_baud=115200
Copy the code

The armV8_trainning /tools/jlink directory is displayed. The following command connects to the J-Link emulator via openocd, using the “-f” option to specify a configuration file.

$sudo openocd-f jlink. CFG Open on-chip Debugger 0.10.0+ dev-01266-GD8AC0086-dirty (2020-05-30-17:23) Licensed under GNU  GPL v2 For bug reports, read http://openocd.org/doc/doxygen/bugs.html Info : Listening on port 6666 for tcl connections Info : Listening on port 4444 for telnet connections Info : J-link V11 Compiled Jan 7 2020 16:52:13 Info: Hardware Version: 11.00 Info: VTarget = 3.341 VCopy the code

It can be seen from the above log that OpenOCD has detected j-Link emulator, version V11.

Use the following command to connect the raspberry PI, as shown.

$sudo  openocd -f jlink.cfg -f raspi4.cfg
Copy the code

JLINK is now connected. Watch the third part of the video course to learn how to debug BenOS using the JLINK emulator. \

Note:

If openOCD connection to raspberry PI is not successful, please check JTAG connection for several times. Also, check that the loop.bin and config.txt files are correct.

Answering questions

Q: Will it be possible to complete season 3 experiments without the Raspberry PI 4B and JLINK simulator? A: We can use QEMU to do 80-90% of the experiments in this season’s course, but some of the experiments need to be done on the Raspberry PI 4B because QEMU can’t simulate hardware behavior 100%. We recommend getting a development board for the Raspberry PI 4B.

Q: Will the absence of a JLINK simulator affect the experiments in this season’s class? A: When debugging programs on raspberry PI 4B, especially assembly code, if there is A crash, we are often at A loss. At best, we can use serial ports to assist debugging. Using a hardware emulator, such as JLINK, we can easily find out why outages occur.

Q: How to buy a JLINK emulator? A: We recommend that you buy the genuine JLINK emulator. You can contact the agent of SEGGER in China. In addition, students and students as well as individual enthusiasts can purchase JLINK EDU version of the emulator through agents.

Q: How do you study this course? A: It is suggested to watch the video carefully, read the MANUAL of ARMv8 chip carefully, complete the experiment carefully, and summarize.

Q: What should I do if I can’t do the experiment? A: We provide reference codes for all experiments. We suggest that you complete the experiment independently. If you really can’t do it, you can refer to the reference code we provide, but you still need to think about what you haven’t done and make a summary in time.

Copyright statement

Buying patterns

Video courses address: taobao: shop115683645.taobao.com/ micro store: weidian.com/?userid=169…