nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni Tinalinux SDK Development Guide Table of Contents Overview...... 4 Purpose...... 4 Applicable scope...... 4 Related personnel...... 4 Tina System Data...... 5 nulllindeni nulllindeniOverview...... nulllindeni...... nulllindeni...... nulllindeni...... nulllindeni...... nulllindeni...... 5 nulllindeni Document list...... 5 Hardware documents...... 5 Support list...... 5 Tool documents...... 5 IC documents...... 6 System development guide...... 6 BSP document list...... 7 Tina System Overview...... 7 Overview...... 7 nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni System chart...... 8 Development Procedures...... 9 Tina Development Environment...... 10 Overview...... 10 Building of compiling environment...... 10 Development host configuration...... 10 Software package configuration...... 10

1 nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeniFirmware burnulllindenining and buildinulllindening...... nulllindeni...... nulllindeni...... nulllindeni...... 11 nulllindeni Tina System Acquisition...... 11 Overview...... 11 SDK acquisition...... 11 SDK structure...... 11 Build directory...... 11 Config directory...... 12 Docs directory...... 12 Lichee directory...... 12 Package directory...... 12 nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni Prebuilt directory...... 12 Scripts directory...... 12 Target directory...... 12 Toolchain directory...... 12 Tools directory...... 12 Out directory...... 12 SDK update...... 13 Problem feedback...... 13 Tina Compiling and Packaging...... 13 nulllindeni nulllindeniOverview...... nulllindeni...... nulllindeni...... nulllindeni...... nulllindeni...... nulllindeni...... 13 nulllindeni System compilation...... 13 Boot compilation...... 13 Compile the kernel...... 14 Application recompilation...... 14 Method I...... 14 Method II...... 14 Other commands...... 14

2 nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni Tinnulllindenia System Burninulllindening...... nulllindeni...... nulllindeni...... nulllindeni...... nulllindeni...... 15 nulllindeni Overview...... 15 Tina uboot Custom Development...... 15 Overview...... 15 Code path...... 16 uboot function...... 16 uboot configuration...... 16 defconfig mode...... 16 defconfig configuration steps...... 16 Introduction to defconfig configuration macro...... 17 nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni menuconfig mode...... 17 uboot compilation...... 18 Method I...... 18 Method II...... 18 uboot configuration...... 18 sys_config configuration...... 18 Introduction to sys_config.fex structure...... 18 Example of sys_config.fex configuration...... 19 sys_config.fex parsing process...... 19 nulllindeni nulllindeni Environmnulllindenient variable conulllindeninfiguration...... nulllindeni...... nulllindeni...... nulllindeni...... 19 nulllindeni Function of environment variable...... 20 Introduction to environment variable configuration example...... 20 sys_partition.fex partition configuration...... 21 Introduction to sys_partition.fex partition configuration...... 21 Tina kernel Custom Development...... 22 Overview...... 22 Code path...... 22

3 nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeniModule develnulllindeniopment documenulllindenints...... nulllindeni...... nulllindeni...... nulllindeni...... 22 nulllindeni Kernel configuration...... 22 Custom development of Tina system...... 23 Application porting...... 23 Makefile example...... 23 Self-boot settings...... 25 Calling of self-boot script...... 25 Script in sysV format...... 25 Script in Procd format...... 25 Application debugging...... 25 nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni Application compilation...... 27 Application compilation...... 27 Partitioning and mounting...... 27

Overview Purpose As a guide for the development of the Allwinner Tina system platform, this document aims to help software development engineers and technical support engineers to rapidly get familiar with the development and debugging process of Tina Linux system. nulllindeni Apnulllindeniplicable scnulllindeniope nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni Tina Linux v3.5 and above. Related personnel This development guide is applicable to software development engineers technical support engineers of the Tina system.

4 nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni Tinulllindenina System nulllindeniData nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni Overview The purpose of the document issued by Tina SDK is to help developers to rapidly carry out development and debugging. This document does not cover all development knowledge and issues. The document list is also updated continuously. If you have any doubt about or need for the document, contact us via the Allwinner FAE window or send an email to [email protected]. Tina SDK provides abundant documents, which are stored in the “TinaSDK/docs/” directory, including hardware reference design documents, Flash support lists, operating instructions for mass production tools, software development, development documentation, and chip development manuals. Document list nulllindeni nulllindeniHardware donulllindenicuments nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni Hardware documents are stored in the “TinaSDK/docs/hardware documents” directory, including the following documents.

1 Standard schematic diagrams Hardware Standard hardware design 2 Include schematic diagrams, and PCB and radiator specifications. documents specifications 3 PCB reference design

TinaLinux Hardware Documents Support list The support list is in the “TinaSDK/docs/support list” directory. It includes the following documents.

1 SPI Nand support list Support list 2 Nor Flash support list nulllindeni nulllindeni 3 WinulllindeniFi_BT support list nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni

TinaLinux Support List Tool documents The tool documents are in the “TinaSDK/docs/tool documents” directory, including the following documents.

1 PhoenixSuit Operating Manual 2 PhoenixPro Operating Manual Tool 3 DragonSN Operating Manual APST Tool Operating Manual documents 4 DragonMAT Operating Manual 5 DragonFace-cdr Manual 6 DragonHD Manual

5 nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni TinnulllindeniaLinux Tool Donulllindenicuments nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni IC documents The IC documents are in the “TinaSDK/docs/IC documents” directory, including the following documents.

1 IC Brief IC documents 2 IC Datasheet 3 IC User Manual

TinaLinux IC Documents System development guide The software documents are in the “TinaSDK/docs/system development documents” directory, including the following documents.

1 TinaLinux support list_CODEC_Vxx Introduce the external CODEC support list. nulllindeni nulllindeni nulllindeni nulllindeniIntroduce the applnulllindeniicable platform list of nulllindeniSDK; document index anulllindenind description; nulllindeni building of development environment; SDK installation preparation, compiling and 2 TinaLinux SDK Development Guide burning; SDK software structure; UBOOT/KERNEL/APP custom development; system debugging tools; common faults. 3 TinaLinux SDK V3.5 update document Introduce the version update. Introduce the system software configuration (Tina/kernel config); system hardware TinaLinux system configuration 4 resource configuration (sysconfig/device tree); and partition table configuration and document function; and add one chapter describing the Nor/Nand switching configuration. Introduce the OTA function, guide how to configure, enable and customize this 5 TinaLinux OTA Development Guide function, and summarize common faults. TinaLinux power management Introduce the function of power consumption management, guide how to configure, 6 development guide enable and customize this function, and summarize common faults. TinaLinux system tailoring Introduce how to tailor the system, and guide users to use and customize this 7 development guide function. TinaLinux boot optimization Introduce how to optimize the system boot, and guide users to use and customize 8 development guide this function. 9 TinaLinux WIFI development guide Introduce the wifi service, API usage and module porting guidance. TinaLinux Bluetooth Development 10 Introduce the BT service, API usage and module porting guidance. Guide Software TinaLinux Smartlink Development documents 11 Introduce the smarklink service, API usage and porting guidance. Guide Introduce the Tina Audio frame, interface, access and the like, and guide users how 12 TinaLinux Audio Development Guide nulllindeni nulllindeni nulllindeni nulllindenito configure, use annulllindenid test them. nulllindeni nulllindeni nulllindeni Introduce the Tina security function, and provide guidance in use and development 13 TinaLinux Security Development Guide of security boot, security os, selinux, network security and other functions. TinaLinux tplaycr development and Introduce the multimedia decoding function and upper interface, and guide how to 14 usage guide configure, use and test them. TinaLinux trecorder development and Introduce the multimedia coding function and upper interface, and guide how to 15 usage guide configure, use and test them. TinaLinux storage management Introduce the system mount, partition management, plug-in monitoring and 16 development guide mounting of storage device, storage management mechanism, etc. 17 Introduce common debug tools of Tina linux, and guide how to configure and use TinaLinux system debug guide them. 18 WIFI RF tool operating manual Tina WIFI RF test and usage guide 19 Tina mass production test manual Configuration and usage guide for Tina mass production test 20 Platform power consumption document Power consumption data of Tina hardware platforms 21 Flash performance document Tina FLSAH performance report 22 WIFI/BT performance document Tina WIFI/BT module performance report 23 TinaLinux SDK pressure test method Tina SDK pressure test report (CPU/DRAM bandwidth)

6 nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni 24 Voice AI engin operating manual Voice AI engin operating manual nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni Tina LED lighting configuration 25 Tina LED lighting configuration and usage guide document

TinaLinux System Development Documents BSP document list The Linux BSP development documents are in the “TinaSDK/docs/BSP development” directory, including the following documents.

24 Audio Development instruction (configuration and usage) and debugging document 25 CLK Development instruction (configuration and usage) and debugging document 26 DDR Development instruction (configuration and usage) and debugging document 27 DEBUG Development instruction (configuration and usage) and debugging document 28 DVFS Development instruction (configuration and usage) and debugging document 29 DMA Development instruction (configuration and usage) and debugging document 30 I2C Development instruction (configuration and usage) and debugging document 31 PWM Development instruction (configuration and usage) and debugging document BSP 32 PINCTRL Development instruction (configuration and usage) and debugging document nulllindeni donulllindenicuments nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni 33 SECURITY Development instruction (configuration and usage) and debugging document 34 SPI Development instruction (configuration and usage) and debugging document 35 THERMAL Development instruction (configuration and usage) and debugging document 36 UBOOT Development instruction (configuration and usage) and debugging document 37 UART Development instruction (configuration and usage) and debugging document 38 USB Development instruction (configuration and usage) and debugging document 39 watchdog Development instruction (configuration and usage) and debugging document 40 interrupt Development instruction (configuration and usage) and debugging document

TinaLinux BSP Development Documents

Tina System Overview Overview The Tina Linux system is a software development kit based on the openwrt-14.07, which nulllindeni incnulllindeniludes the kernelnulllindenisource codes, dnulllindenirivers, tools, synulllindenistem middlewanulllindenire and applicatnulllindeniion nulllindeni packages used in Linux system development. The openwrt is an open-source embedded automatic construction framework of the Linux system. It consists of Makefile scripts and Kconfig configuration files. By configuring menuconfig, the user can compile a complete set of Linux system software that can be directly written into a machine.

7 nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni Synulllindenistem chartnulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni

nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni

Tina Linux system chart The Tina system software chart is shown in this figure, divided into four levels from bottom to top, namely, Kernel && Driver, Libraries, System Services, and Applications. The content of each level is as follows: 1. The Kernel&&Driver layer is applied mainly to implement the standards of Linux Kernel. The Linux Kernel of the Tina platform may be Linux3.4, linux3.10, linux4.4, and linux4.9 and the like (different kernel versions may be used in hardware platforms). This layer provides basic supports such as the security, memory management, process management and network protocol stack. Device hardware nulllindeni nulllindeniresources are nulllindenimanaged mainlnulllindeniy via the Linuxnulllindenikernel, e.g. CPnulllindeniU schedule, cacnulllindenihe, nulllindeni memory and I/O.

2. The Libraries layer corresponds to a general embedded system, which is equivalent to the middleware level. It contains basic libraries and third-party open-source library supports of the system, and provides API interfaces for the application layer. System customizers and application developers can develop new applications based on the API interfaces of the Libraries layer.

3. The System Services layer corresponding to the system service layer contains the system boot management, configuration management, hot plug management, storage management and multimedia middleware.

8 nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni 4. nulllindeniThe Applicatinulllindenions layer is appnulllindenilied mainly to anulllindenichieve specificnulllindeniproduct functionulllindenins and nulllindeni interaction logic. It needs some basic libraries and third-party program library support. Developer can develop the desired application programs and provide system capabilities for end users. Development Procedures The Tina Linux system is a type of SDK developed for a variety of product forms based on the Linux Kernel. This SDK can be applied for effective implementation of system customization and application porting development.

nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni

Tina Linux System Development Process Developers may rapidly build a local Tina Linux system development environment and compile codes according to the development process in the above figure. The development process is introduced briefly below. 1. Check of system requirements: Before downloading and compiling the code, make sure that the local development equipment meets the needs, including the hardware capabilities, software system and toolchain of the machine. At present, the Tina Linux system only supports compiling in the Ubuntu , and the toolchain in the Linux environment. Other systems such as MacOS and Windows are not supported temporarily.

2. Building of compiling environment: Refer to Section 4.1 “Building of code environment” for the software packages and tools to be installed in the development nulllindeni nulllindenimachine. Usenulllindenirs should knownulllindenithe verified openulllindenirating system vnulllindeniersion of TinaLnulllindeniinux, nulllindeni library files required in compiling, and the like.

3. Device selection: Before compiling the source code, developers need to first export the predefined environment variables and then select the corresponding hardware board. Refer to Section 6.1 “Compiling of complete Tina system”.

4. System customization: Developers can customize the U-Boot (see Chapter 8 “U- Boot Development”), Kernel (see Chapter 9 “Kernel Development”) and Openwrt (see Chapter 10 “System Development”) based on the applied hardware board and product definition, Refer to relevant development guides and configurations in these chapters.

9 nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni 5. nulllindeniCompiling annulllindenid packaging: Anulllindenifter the device snulllindenielection and synulllindenistem customizanulllindenition are nulllindeni completed, execute compiling commands, including overall or module compiling, and compilation cleanup. Furthermore, the generated boot/kernel binary files and root files will be packaged to form the firmware according to the format requirements. (Section 6.1 “Compiling of complete Tina system”)

6. Burning and running: How to burn images and run them in the hardware device is introduced after the generation of image files. For details, refer to Chapter 7 “System Burning”.

Tina Development Environment Overview The development process for embedded products usually involves two key steps, namely, source code compiling and firmware burning. The compiling environment should be nulllindeni prenulllindenipared before thenulllindenisource code isnulllindenicompiled. In anulllindeniddition, the mannulllindeniufacturer shoulnulllindenid nulllindeni provide special burning tools for firmware burning. This chapter mainly describes how to build an environment for compiling and burning of Tina sdk. Building of compiling environment A typical embedded development environment includes the local development host and target hardware board. • As a compiling server, the local development host should be equipped with a Linux operating environment. A cross compiling environment should be built for code update downloading and code cross-compiling during software development.

• The local development host is connected to the target hardware board via the serial port or USB, to burn the compiled image files into the target hardware board and debug the system or application. nulllindeni Denulllindenivelopment hnulllindeniost configuranulllindenition nulllindeni nulllindeni nulllindeni nulllindeni The Tina Linux SDK is developed and tested based on ubuntu14.04, so our hosts support source code compilation. For other versions that are not tested, the software package may needs to be adjusted accordingly. Software package configuration Before compiling the Tina Linux SDK, make sure that the compiling service is equipped with the gcc, binutils, bzip2, flex, python, perl, make, ia32-libs, find, grep, diff, unzip, gawk, getopt, subversion, libz-dev, and libc headers. Ubuntu can be installed by directly executing the following commands:

10 nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni Finulllindenirmware bunulllindenirning and bnulllindeniuilding nulllindeni nulllindeni nulllindeni nulllindeni The TinaLinux SDK includes firmware burning tools, which are in the “TinaSDK/tools/aw_tools/” directory. • Host: windows PhoenixSuit.zip is needed. For software configuration and use, refer to the tool document “PhoenixSuit Operating Manual”. • Host: Ubuntu Use LiveSuitV306_For_Linux64.zip for the 64bit host and LiveSuitV306_For_Linux32.zip for the 32bit host. For software configuration and use, refer to the tool document “LiveSuit Operating Manual”.

Tina System Acquisition nulllindeni Ovnulllindenierview nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni SDK acquisition The Allwinner Tina Linux SDK is released through the Allwinner code server. Customers need to apply for SDK download permissions in the Business/Technical Support window. The SSH public key should be provided along with the application for server authentication and authorization. Once the permission is authorized, codes will be synchronized. SDK structure The Tina Linux SDK mainly consists of the building system, configuration tool, toolchain, host tool kit, target device application, document, script, linux kernel and bootloader. Relevant components are introduced according to the directory sequence. Build directory nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni Tina Linux build system files are stored in the build directory. This directory structure mainly includes a series of mk files written based on the Makefile specification. Main functions: 1. Checking whether the current compiling environment meets the build requirements of Tina Linux 2. Generating compilation rules for host package 3. Generating compilation rules for toolchain 4. Generating compilation rules for target package 5. Generating compilation rules for linux kernel 6. Generating build rules for system firmware

11 nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni Conulllindeninfig directornulllindeniy nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni The config directory mainly stores the interface of the Tina Linux configuration menu and some fixed configuration items. The configuration menu is written based on the mconf format of kernel. Docs directory The docs directory mainly contains development files in the markdown format. Lichee directory The lichee directory mainly contains uboot and kernel codes. Package directory The package directory contains package source codes and compilation rules of the target machine. It is divided based on the functions of the target software package. nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni Prebuilt directory The prebuild directory contains pre-compilers and cross compilers, as shown below. Scripts directory The scripts directory is used to store some scripts used by PC or small machine. Target directory The target directory contains the configuration related to the target board, as well as the specifications generated by sdk and toolchain. Toolchain directory The toolchain directory contains the cross toolchain build configuration and rules.

nulllindeni Tonulllindeniols directorynulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni The tools directory is used to store the compilation rules for host tools. Out directory The out directory textcolor{blue}{} is generated automatically after compilation, such as the compilation scheme banjo-dh. The host directory contains host-side tools and some development-related files. The banjo-dh directory corresponds to the scheme. The structure of the scheme directory is as follows. Where:

12 nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni • nulllindeniThe boot.imgnulllindeniis the data thatnulllindeniare finally prognulllindenirammed into thnulllindenie boot partitionnulllindeni. This nulllindeni partition defaults to vfat format. • The rootfs.img is eventually burned into the system rootfs partition (default format: squashfs). • The banjo-dh-uImage is the final image of the kernel, which will be packaged into boot.img. • The compile_dir is the temporary file directory for host, target and toolchain of sdk compilation, and stores the source codes of each package. • The staging_dir is the directory where the results of each directory are store during the sdk compilation process. • The packages directory stores the finally built ipk package. • The tina_banjo-dh_card0.img is the final firmware package (system image), of which the serial port information is outputted via the tf mount. • The tina_banjo-dha_uart0.img is the final firmware package (system image), of which the serial port information is outputted via the serial port 0. nulllindeni SDnulllindeniK update nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni Developers can carry out updating via the repo sync command, according to the update instructions that are regularly released in the FAE window. Problem feedback Allwinner provides the AService BUG management system for registration of problems and solutions. This can help both parties to carry out tracking and solve problems more efficiently. Subsequent SDK issues, technical issues, technical consultations and the like may be submitted into the Bug system. The technical service personnel of Allwinner will distribute, solve and track problems in a timely manner. Note: The login account of the AService BUG management system needs to be confirmed with Allwinner. nulllindeni Tinulllindenina Compilinulllindening and Pacnulllindenikaging nulllindeni nulllindeni nulllindeni nulllindeni Overview System compilation Boot compilation Command Valid directories of commands Function mboot Tina root directory Compile boot0 and uboot. mboot0 Tina root directory Compile boot0. muboot Tina root directory Compile uboot.

13 nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni Conulllindenimpile the knulllindeniernel. nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni Command Valid directories of commands Function mkernel Tina root directory Compile the kernel. Application recompilation Make sure that the firmware has been compiled once and that the SDK base has been compiled before recompiling the application packages separately. The recompilation of application packages is usually carried out in the following scenarios: . Ensure that the Tina environment has been loaded before compiling. Method I Execute in the application package directory (including its subdirectory). Example: Assuming the package path is: tina/package/utils/rwcheck, then: nulllindeni Thenulllindenipath for savingnulllindenithe compiled anulllindenipplication instanulllindenillation packagenulllindeniis: nulllindeni nulllindeni Method II Execute in the root directory of Tina. Example: Assuming the package path is: tina/package/utils/rwcheck, then: Other commands Valid directories Command of commands Function make Tina root Compile the entire sdk. directory make menuconfig Tina root Start the package configuration interface directory make Tina root Start the kernel configuration interface nulllindeni kernulllindeninel_menuconfignulllindenidirectory nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni printfconfig Any directory Print the current SDK configuration under tina croot Any directory Quickly switch to the tina root directory. under tina cconfigs Any directory Quickly switch to the bsp configuration under tina directory of the scheme. cdevice Any directory Quickly switch to the configuration directory under tina of the scheme. cgeneric Any directory Quickly switch to the generic directory of the under tina scheme. cout Any directory Quickly switch to the output directory of the

14 nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeniunder tinanulllindeni schemnulllindenie. nulllindeni nulllindeni nulllindeni cgrep Any directory Find strings in c/c++/h files under tina minstall Tina root Compile and install the package path/to/package/ directory mclean Tina root Clean package path/to/package/ directory mm [-B] Package directory Compile the package. “-B” means that the “Clean” operation should be conducted before compilation.

Tina System Burning Overview nulllindeni Thinulllindenis chapter mainlnulllindeniy describes hownulllindenito burn a builtnulllindeniimage file andnulllindenirun it in a hardwnulllindeniare nulllindeni device. The image burning tools of Tina are listed in the table. The user can select the appropriate burning method.

Operating Tools System Description PhoenixSuit windows Tool used for upgrading in partitions and upgrading the entire firmware PhoenixSuit windows Tool used for card firmware fabrication PhoenixUSBpro windows Tool for mass production upgrading, supporting the 1-for-8 burning of USB LiveSuit Ubuntu Tool used for upgrading in partitions and upgrading the entire firmware

Refer to TinaSDK/docs/tool documents/PhoenixSuit Operating Manual.doc for the nulllindeni openulllindeniration of PhoennulllindeniixSuit, and TinnulllindeniaSDK/docs/toonulllindenil documents/LivnulllindenieSuit Operatinnulllindenig nulllindeni Manual.doc for the operation of LiveSuit.

Tina uboot Custom Development Overview This chapter briefly introduces the basic uboot configuration, function trailoring, compiling & packaging, and common command use, to help the user learn about the uboot frame of the Tina platform and provide a basis for boot custom development.

15 nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni At nulllindenipresent, the ubonulllindeniot of Tina SDKnulllindenihas three versinulllindenions, namely, ubnulllindenioot-2011, uboonulllindenit-2014, nulllindeni and uboot-2018, which can be applied in different hardware platforms. The user needs to check the kernel information of SDK according to the developed hardware platform. Code path uboot function In TinaSDK, bootloader/uboot runs before the kernel. It is able to initialize hardware devices and build memory space maps, thus providing a suitable software and hardware environment for final callback of the Linux kernel. In the Tina system platform, uboot also has other functions such as burning and upgrading, in addition to the required function of boot system startup. • Boot kernel Load the kernel image from the storage medium (nand/mmc/spinor) to the specified position of DRAM, and then run it. nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni • Mass production & upgrade Include card mass production, USB mass production, private data burning, and firmware upgrading. • Power management Include the control logic and the display image in the charging mode. • Boot prompt message Display the boot logo image (BMP format). • Fastboot function Execute the standard commands of fastboot. The fastboot function can be applied for flashing. uboot configuration Take uboot-2018 as an example. Each function can be enabled or disabled via the nulllindeni defnulllindeniconfig or confignulllindeniuration menu mnulllindenienuconfig. Thenulllindenispecific confignulllindeniuration methodnulllindeniis as nulllindeni follows: defconfig mode defconfig configuration steps

A s shown above, as long as “#” in front of CONFIG_SUNXI_NAND is removed, NAND-

16 nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni relanulllindenited functions wnulllindeniill be supportednulllindeni. Other macro dnulllindeniefinitions can bnulllindenie enabled or dinulllindenisabled nulllindeni similarly.

Introduction to defconfig configuration macro Below is the introduction to the basic macro definition in sun8iw18p1_defconfig/sun8iw18p1_nor_defconfig.

Default Status (Enable / Disable) of Macro Macro Definition Function Description of Macro Definition Definition (disabled by default in Support the enabling / disabling of the nand CONFIG_SUNXI_NAHD sin8iw18p1_nor_defconfig and enabled by driver. default in sin8iw18p1_defconfig) Support the enabling / disabling of the spinor CONFIG_SUNXI_SPINOR Open driver. Support the enabling / disabling of the usb CONFIG_SUNXI_USB Open driver. Support the enabling / disabling of the usb CONFIG_SUNXI_EFEX Open burning function. Support the enabling / disabling of the key CONFIG_SUNXI_BURN Open burning function. Support the enabling / disabling of the fastboot nulllindeni CONnulllindeniFIG_SUNXI_FASTBDOnulllindeniT nulllindeni nulllindeni nulllindeni Open nulllindeni nulllindeni function. Support the enabling / disabling of the gpt CONFIG_EFI_PARTITION Open function. Support the enabling / disabling of the android CONFIG_ANDROID_BOOT_IMAGE Open firmware boot function. Support the enabling and disabling of the mass CONFIG_SUNXI_SPRITE Open production function. Support the enabling and disabling of secure CONFIG_SUNXI_SECURE_STORAGE Open storage. Support the enabling and disabling of secure CONFIG_SUNXI_SECURE_BDOT Open startup. Support the enabling and disabling of the credit CONFIG_SUNXI_KEYBDX Open link. The shell command supports the enabling and CONFIG_CMD_SUNXI_EFEX Open disabling of skip burning commands. The shell command supports the enabling and CONFIG_CMD_SUNXI_BURN Open disabling of key burning commands. The shell command supports the enabling and CONFIG_CMD_GPT Open disabling of gpt commands. The shell command supports the enabling and CONFIG_CMD_FAT Open disabling of fat commands. nulllindeni nulllindeni nulllindeni The shelnulllindenil command supports thnulllindenie enabling and nulllindeni nulllindeni nulllindeni CONFIG_CMD_FASTBOOT Open disabling of fastboot commands. The shell command supports the enabling and CONFIG_CND_SUNXI_DMA Open disabling of dma test commands. The shell command supports the enabling and CONFIG_CMD_PART disabling of viewing of partition information Open commands. The shell command supports the enabling and CONFIG_CMD_SF Open disabling of spi flash read/write commands.

Introduction to defconfig basic macro definition menuconfig mode Steps of configuration in the menuconfig mode:

17 nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni Whnulllindenien the above conulllindenimmands are exnulllindeniecuted, the mennulllindeniuconfig confignulllindeniuration menu wnulllindeniill pop nulllindeni up, as shown below. In this case, the function of each module can be configured. The configuration method is described in the menuconfig configuration menu window.

nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni

Diagram of menuconfig configuration menu uboot compilation Method I The uboot can be compiled in the tina directory. Method II uboot configuration nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni sys_config configuration The sys_config.fex is an important file for configuration of module parameters, which provides great convenience for modification and updating of important parameters of each module. The file storage path is: /TinaSDK/target/allwinner/$(BOARD)/configs/sys_config.fex.

Introduction to sys_config.fex structure The sys_config.fes mainly consists of main keys and sub-keys. Main keys are the main identifiers of one function or module, and indicated by “[]”. Sub-keys are the configuration items of each parameters of the function or module. In the figure below, dram_para is the main key, and dram_clk, dram_type, and dram_zp are sub-keys.

18 nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni

Basic structure diagram of sysconfig.fex

Example of sys_config.fex configuration [platform]: platform-related configuration item

For example, debug_mode =1 means that the debug mode of uboot is enabled and the nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni corresponding debug inforamtion will be printed in the log. next_work=2 indicates next step after burning (0x1: normal start; 0x2: restart; 0x3: OFF). For other configurations, refer to the prompts in front of the [platform].

In the above figure, the frequency of cpu can be configured by setting boot_clock.

In the above figure, uart_debug_port=0 indicates that uart0 is used. The gpio port (PA04/PA05) of uart_debug_tx/uart_debug_rx can be configured according to the corresponding GPIO DATASHEET. nulllindeni sysnulllindeni_config.fex parnulllindenising process nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni In uboot4014/2018, sys_config.fex will eventually be converted into dtb (device tree binary, i.e. linux kernel configuration), while dtb will eventually be packaged and burned into the flash, and loaded into the memory in the startup process. The parameters configured in sys_config.fex have been converted into dtb nodes, which will be parsed by the fdt_getprop_32() function. Environment variable configuration The environment variables of uboot are key-value pairs. The operation interfaces are: getenv(), setenv(), and saveenv(). Types of environment variable:

19 nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni Funulllindeninction of envirnulllindenionment variabnulllindenile nulllindeni nulllindeni nulllindeni nulllindeni Some parameters or command sequences can be defined in environment variables. To define the UBOOT command sequence in an environment variable, the function modules of UBOOT can be combined according to the sequence during execution of one important function. Example: If the command corresponding to the environment variable boot_normal is executed, Uboot will first call the sunxi_flash command to load the kernel from the boot partition of the storage medium to the 0x40007800 position of DRAM, and then call the boota command to complete the kernel boot. The environment variable is called during uboot startup, as shown below.

nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni

Mode of calling environment variable in uboot startup nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni Introduction to environment variable configuration example In TinaSDK, the environment variable configuration file is saved in the TinaSDK/target/allwinner/$(BOARD)/configs/env.cfg file. When using this file, the user may see env-4.4.cfg, env-4.9.cfg and the like. The suffix number in “env-xxx” indicates the configuration in different kernel versions. Below is an example of an opened file: • bootdelay=0: change the value of the environment variable bootdelay (i.e. the countdown delay time in the log after booting). For easy debugging, the variable value is usually not set to 0, so that the “uboot shell” can be enabled by pressing any key after the sub-unit is powered on.

20 nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni • nulllindeniboot_normal=nulllindenisunxi_flash reanulllindenid 40007800 bonulllindeniot; boota 40007nulllindeni80: set the bootnulllindenikernel nulllindeni command, i.e. read the boot partition to the memory address 0x40007800, and start the kernel at the memory address 0x40007800. • Setargs_nand=setenv bootargs earlyprintk=${earlyprink}…: Setargs_nand=setenv bootargs earlyprintk=${earlyprink}…: set the kernel-related environment variable. This variable will be printed after booting into the kernel log, i.e. cmdline as shown below:

kernel cmdline diagram • loglevel=8: set the printing level of the kernel log. sys_partition.fex partition configuration The partition configuration file is used for planning of disk partitions. In the burning nulllindeni pronulllindenicess, the data onulllindenif each partitionnulllindeniwill be burnt innulllindenito the flash basnulllindenied on this partitnulllindeniion nulllindeni configuration file. In TinaSDK, the path of the partition configuration file is TinaSDK/target/allwinner/$(BOARD)/configs/sys_partition.fex. In some schemes, sys_partition.fex and sys_partition_nor.fex may be seen. The configuration file sys_partition_linux.fex will be used during packaging of Tina non-nor firmware; and sys_partition_nor.fex will be used during packaging of nor firmware.

Introduction to sys_partition.fex partition configuration The properties of one partition include the name, size, download file and user type. Below are the properties of one partition in the file: • name: user-defined partition name. The user may set the desired character string, but its length should not exceed 16 bytes. • size: define the partition size in sectors (1 sector = 512 bytes. In the above figure, nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni 32,768 sectors are assigned to the env partition, i.e. 32,768*512/1,024/1,024 = 16 M). Note: For byte alignment, the number of assigned sectors should be exactly divisible by 128. • downloadfile: path and name of the download file. A relative path (relative to the partition where the file image.cfg is located). An absolute path may be used. • user_type: an attribute provided for the operating system. At present, while reading this partition, each operating system will check whether the current partition is suitable according to the user type. When multiple systems are applied, this design can avoid failure of the operating system B caused by misreading or miswriting of its partitions by the operating system A.

21 nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni Tinulllindenina kernel Cnulllindeniustom Devnulllindenielopment nulllindeni nulllindeni nulllindeni nulllindeni Overview This chapter briefly introduces the basic kernel configuration function tailoring and common command use, to help users learn about the Linux kernel of Tina platform and provide a basis for custom development of the kernel. At present, the Linux kernel of Tina SDK has 4 versions, namely, linux-3.4, linux-3.10, linux-4.4 and linux-4.9, which are used in different hardware platforms. Users need to check the kernel information of SDK based on the developed hardware platform. Code path Module development documents Refer to the BSP development documents, including the manuals for usage and nulllindeni devnulllindenielopment of conulllindenimmon kernel mnulllindeniodules. nulllindeni nulllindeni nulllindeni nulllindeni Kernel configuration The Linux kernel configuration needs to be changed during product customization. In TinaSDK, the kernel configuration can be enabled as follows: After execution, the configuration menu will pop up on the shell console. As shown below,

nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni

TinaLinux kernel configuration menu

22 nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni Cunulllindenistom devenulllindenilopment ofnulllindeniTina systemnulllindeni nulllindeni nulllindeni nulllindeni Application porting In the Tina Linux SDK, a package directory generally contains the following two directories and one file: Makefile example The software compilation logic is dependent on the Makefile of software. In theory, there is no substantive relationship with the Makefile (Makefile is only for execution of make commands and related parameters).

nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni

nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni

23 nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni

nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni

nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni

N ote:

24 nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni Senulllindenilf-boot settinnulllindenigs nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni Tina Linux supports two formats of initialization scripts: busybox-type or sysV initialization scripts and procd initialization scripts. Usually, initialization scripts are programmed with the shell script. The shell script as basic knowledge is not explained here. Under normal circumstances, the source codes of initialization scripts are saved in the files directory of software, with the suffix “.init”, such as: In “install” of Makefile, initialization scripts are installed in the sub-unit, such as:

Calling of self-boot script • A number of logs are generated if the self-boot script is called manually during startup, and the log information is collected by the logd daemon, which is not conducive to debugging of initialization scripts. In this case, debugging can be carried out by manually calling command lines of the sub-unit, such as: nulllindeni Scrnulllindeniipt in sysV fornulllindenimat nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni The initialization scripts in the sysV format are saved in the /etc/init.d/ directory of the sub-unit and used for self-booting. The initialization script with minimum content is taken as an example below. Its core is the start / stop function: A function template of init script is provided in rc.common, which consists of the following parts.

Name Attribute Function start Required Start a service. stop Required Stop a service. reload Optional Restart a service. enable Optional Reload a service. disable Optional Disable a service. nulllindeni In tnulllindenihe shell, relevanulllindenint services can nulllindenibe operated by tnulllindenihe following conulllindenimmands. nulllindeni nulllindeni

Script in Procd format In the following example of initialization script, the main function is: start_service. For details, refer to https://wiki.openwrt.org/inbox/procd-init-scripts. Application debugging The newly added software is disabled by default, so the Enable package needs to be configured manually. Execute “make menuconfig” in the root directory of Tina to enter the package configuration interface:

25 nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni

nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni

Main interface of application configuration The package path is associated with the definition in Makefile of the package. Take fstools as an example. Its definition in Makefile is: The fstools package can be found by entering the Basy system from the menuconfig interface.

nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni

26 nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni

nulllindeni Pacnulllindenikage interface nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni Meaning of the prefix: Supported operation: Application compilation See Section 6.5 “Application recompilation”. Application compilation 1. Get the installation package. The installation package is usually located in the directory: Format of the installation package name: 2. Install the application package. nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni Push the installation package to sub-unit via adb. Install the application package. Partitioning and mounting • Partition upgrade Subarea Function boot partition Store the kernel image. rootfs partition Basic system image partition, including /lib, /bin, /etc, etc. recovery partition Store recovery system images [only for large-capacity schemes]. • No partition upgrade

27 nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni Subnulllindeniarea nulllindeniFunction nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni private partition SN storage partition misc partition System and flash status partition UDISK partition User data partition (/mnt/UDISK) overlayfs partition Store overlayfs data. • Default mount point Subarea Mount point Remarks /dev/by-name/boot /boot /dev/by-name/boot-res /boot-res /dev/by-name/UDISK /mnt/UDISK User data partition /dev/mmcblk0 或 /dev/mmcblk0p1 /mnt/SDCARD Tf card mount point /dev/by-name/rootfs_data /overlay Store overlayfs data. nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni

nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni

28 nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni nulllindeni