How I survived to a SoC with a terrible Linux BSP

Similar documents
How I survived to a SoC with a terrible Linux BSP

D1 - Embedded Linux. Building and installing an embedded and real-time Linux platform. Objectives. Course environment.

Booting Linux Fast & Fancy. Embedded Linux Conference Europe Cambridge, Robert Schwebel

EMBEDDED LINUX ON ARM9 Weekend Workshop

Embedded Linux system development training 5-day session

D1Y - Embedded Linux with Yocto

ARM64 + FPGA and more: Linux on the Xilinx ZynqMP

Flash filesystem benchmarks

U-Boot Falcon Mode. Minimizing boot times using U-Boot "Falcon" mode. Stefano Babic / Wolfgang Denk. July 2012

ARM Powered SoCs OpenEmbedded: a framework for toolcha. generation and rootfs management

D1S - Embedded Linux with Ac6 System Workbench

Embedded Linux Conference Europe Sascha Hauer

Adding hardware support to Buildroot

IPL+UBI: Flexible and Reliable with Linux as the Bootloader

Track Two Building an Internet Radio with the TI Sitara AM3517 using LinuxLink

Lab 1. OMAP5912 Starter Kit (OSK5912)

Hands-on with the Sitara Linux SDK

Track Three Building a Rich UI Based Dual Display Video Player with the Freescale i.mx53 using LinuxLink

DevKit8000 Evaluation Kit

UFCETW-20-2 Examination Answer all questions in Section A (60 marks) and 2 questions from Section B (40 marks)

Track One Building a connected home automation device with the Digi ConnectCore Wi-i.MX51 using LinuxLink

The Right Approach to Minimal Boot Times

Patrick Doyle Principal Software Engineer, irobot 2017 Embedded Linux Conference, Portland OR

Kernel Internals. Course Duration: 5 days. Pre-Requisites : Course Objective: Course Outline

NAND/MTD support under Linux

Rootfs made easy with Buildroot

Embest SOC8200 Single Board Computer

LINUX KERNEL UPDATES FOR AUTOMOTIVE: LESSONS LEARNED

Jade IdeaBoxx. Product Manual

Linux. For BCT RE2G2. User Guide. Document Reference: BCTRE2G2 Linux User Guide. Document Issue: Associated SDK release: 1.

Supporting a new ARM platform: the Allwinner example

REAL TIME IMAGE PROCESSING BASED ON EMBEDDED LINUX

i.mx 7 - Hetereogenous Multiprocessing Architecture

ECE 471 Embedded Systems Lecture 12

Supporting a new ARM platform: the Allwinner example

Porting U-Boot and Linux on new ARM boards: a step-by-step guide

OP-TEE Using TrustZone to Protect Our Own Secrets

What is new? Page 1. Peter Korsgaard, Maintainer ELCE 2013

Getting Started with FreeRTOS BSP for i.mx 7Dual

Track Three Building a Rich UI Based Dual Display Video Player with the Freescale i.mx53 using LinuxLink

MCAM335x Linux User's Guide

First Steps. esom/sk4 esom/3517 Embedded Linux Starter Kit

ECE 471 Embedded Systems Lecture 16

Current Challenges in UBIFS

Shared Logging with the Linux Kernel!!Part Deux!!

iw-rainbow-g3 / G3V FAQs:

U-Boot Bootloader for IoT Platform?

MYD-JA5D2X Development Board

Porting FreeBSD to AArch64

1 FOSDEM like real computers - Making distributions work on single board computers André Przywara 04/02/2018

SparkGate7 Quick startup guide

Porting Linux to a new SoC

Update on boot time reduction techniques

64 bit Bare Metal Programming on RPI-3. Tristan Gingold

User Guide Linux for AT91CAP9-STK Version 1.1. User Guide LINUX FOR AT91CAP9-STK VERSION: 1.1 1/11

i.mx 6UltraLite Evaluation Kit Quick Start Guide s datasheet has been downloaded from at this pag

Linux Files and the File System

TQ2440 Development Platform Manual

MYD-IMX28X Development Board

Introduction p. 1 Why Linux? p. 2 Embedded Linux Today p. 3 Open Source and the GPL p. 3 Free Versus Freedom p. 4 Standards and Relevant Bodies p.

Developing i.mx Multimedia Applications Processors with Windows Embedded CE 6.0 WinCE 6.0 on the i.mx25 and i.mx35 PDK s

using the Texas Instruments Zoom

DevKit7000 Evaluation Kit

Embedded Linux kernel and driver development training 5-day session

Yocto Project and OpenEmbedded training 3-day session

U-Boot and Linux Kernel Debug using CCSv5

Rethinking the core OS in 2015

Developing Environment for Intel Mainstone Board

FLASH Programming in Production of VS1000 Applications

ECE 598 Advanced Operating Systems Lecture 4

From One Architecture to Many: Porting OpenMandriva to AArch64, armv7hnl, RISC-V and Ryzen. OSS/ELC 2018 Bernhard Bero Rosenkränzer

BeagleLogic Documentation

ID 730L: Getting Started with Multimedia Programming on Linux on SH7724

MYD-IMX28X Development Board

Full Linux on FPGA. Sven Gregori

LS9200 User Guide LinkSprite Technologies, Inc.

UEFI Secure Boot and DRI. Kalyan Kumar N

File Systems Management and Examples

AT91SAM9RL64 Hands-on 03: Deploy an application thanks to the AT91SAM9RL64 BootROM loaders and at91bootstrap

Parallella Linux - quickstart guide. Antmicro Ltd

Oxalis Getting Started

BlazePPS (Blaze Packet Processing System) CSEE W4840 Project Design

January 28 29, 2014San Jose. Engineering Workshop

The Yocto Project. Chris Young S/W Specialist SILICA Europe. Harmonising Software Development across multiple Embedded ARM SOC targets

Linux FastBoot. Reducing Embedded Linux Boot Times. Embedded World Conference 2012

Embedded Systems. Mail: Web: Université de Nice - Sophia Antipolis

MYD-SAMA5D3X Development Board

S3C6410-TFAUbuntu Easy Guide

Building a reference IoT product with Zephyr. Ricardo Salveti Michael Scott Tyler Baker

Birds of a Feather Session - OSS Vancouver Eystein Stenberg, Mender.io

ECE 471 Embedded Systems Lecture 16

In this video, I will be covering DM385 IPNC RDK out of box demo-- Here, I'll be showing flashing the uboot using prebuilt binaries available in RDK--

Advanced Operating Systems Embedded from Scratch: System boot and hardware access. Federico Terraneo

EMBEDDED SYSTEMS WITH ROBOTICS AND SENSORS USING ERLANG

96Boards Enablement for opensuse

Computer System Management - File Systems

SBC8140 Single Board Computer

Using kgdb and the kgdb Internals

Jade IdeaBoxx. The quickstart kit to jumpstart development. Fujitsu Semiconductor America Inc.

ML410 VxWorks BSP and System Image Creation for the BSB Design Using EDK 8.2i SP1. April

Transcription:

How I survived to a SoC with a terrible Linux BSP Working with jurassic vendor kernels, missing pieces and buggy code Luca Ceresoli AIM Sportline luca@lucaceresoli.net http://lucaceresoli.net ELC-E 2017

About me Embedded Linux engineer at AIM Sportline http://www.aim-sportline.com/ Develop real products on custom hardware Kernel, bootloader, drivers Integration, build system Open source enthusiast Contributor to Buildroot and a few other projects 1

Introduction

The ideal BSP BSP = Board Support Package The ideal BSP Mainline kernel Mainline U-Boot or Barebox Good hardware documentation 2

The System on Chip Nuvoton N32926 ARM926EJ-S @ 240 MHz Peripherals: H.264 en/decoder, Ethernet MAC, USB, CMOS sensor interface, video out, LCD controller, sound, 64 MB DDR2 in package LQFP package Ideal application: low cost IP camera DDR2 SoC Source: https://www.nuvoton.com/hq/products/microprocessors/arm9-mpus/n3292-h.264-codec-series/n32926u1dn 3

My Quest

My quest Documentation Linux kernel Booting Tools Customer support 4

Documentation

Public documentation An 8-page datasheet (mostly a list of features) From: https://www.nuvoton.com/hq/products/microprocessors/arm9-mpus/n3292-h.264-codec-series/n32926u1dn 5

Documentation for customers Only under NDA 6

Accessible documentation A low-cost devkit is available from chinese online stores Contains a DVD-ROM with a subset of the BSP for customers Documentation and software Contains the N3292x Design Guide SoC peripherals (registers) 7

Linux kernel

Vendor kernel VS mainline kernel Base kernel: Linux 2.6.35.4 (2010) 2.6.35.4 2.6.35.14 (latest stable) 11 months 1382 bugfix commits Merged with minimal conflicts 2.6.35.14 4.13.y (latest mainline) A countless number of fixes, improvements, new features Security Device Tree New device drivers! 8

Vendor kernel additions Total: 170.000 lines changed Provided as patches: w55fa92-kernel-2.6.35-000.patch (3.6 MB) w55fa92-kernel-2.6.35-001.patch (1.4 MB) w55fa92-kernel-2.6.35-002.patch (0.4 MB) do_kernel_patch.sh 9

Vendor kernel issues 1. Bugs 2. Missing features 3. Code quality 10

Bugs Examples: Sound Processing Unit ALSA driver arecord myfile.wav kernel crash NULL pointer dereference H.264 decoder driver Works with sample streams Kernel crash on streaming packet loss Several NULL pointer dereferences 11

Missing features Examples: GPIO Basic functionality is implemented No interrupt handling Power Management Implemented with a proprietary API Also implemented the Linux standard way, but incomplete and not working 12

Code quality Average quality of additions: generally bad Trivial metric: +521 lines starting with #if 0 A few examples follow 13

Code quality: driver model drivers/video/w55fa92_fb.c: #ifdef CONFIG_GIANTPLUS_GPM1006D0_320X240 #include "w55fa92_giantplus_gpm1006d0.c" #endif #ifdef CONFIG_TOPPLY_320X240 #include "w55fa92_topply_320x240.c" #endif /*...5 more displays... */ #if 0 #ifdef CONFIG_SHARP_LQ035Q1DH02_320X240 #include "w55fa92_sharp_lq035q1dh02.c" #endif #ifdef CONFIG_WINTEK_WMF3324_320X240 #include "w55fa92_wintek_wmf3324.c" #endif /*...5 more displays... */ #endif 14

Code quality: H.264 codec memory allocation drivers/misc/codec264/favc_module.c: unsigned int get_avc_buffer_size(void) { /*...~90 lines... */ return TOTAL_VDE_BUF_SIZE; } EXPORT_SYMBOL(get_avc_buffer_size); From arch/arm/mm/mmu.c: extern unsigned int get_avc_buffer_size(void); void init reserve_node_zero(pg_data_t *pgdat) { /*... */ buffer_size = get_avc_buffer_size(); printk("avc Buffer Size: 0x%x\n",buffer_size); w55fa92_vde_v = alloc_bootmem_low_pages (buffer_size); /*... */ } 15

Booting

Bootloaders in the BSP No U-Boot No Barebox Some proprietary bootloaders Sources provided, but not open source ( All rights reserved ) Tied to the SoC 16

Vendor booting scheme (NAND example) A common booting scheme (with U-Boot) BOOT ROM SPL U-Boot env root fs (UBIFS) kernel UBI Nuvoton N32926 expose FAT as USB mass storage BOOT ROM NAND Loader NVT Loader conprog.bin Image (with initramfs) FAT1 start.sh FAT2 17

Vendor booting scheme pros Easy deployment of demos provided by vendor 1. Press a button during boot 2. Mount mass storage on PC 3. Replace files 18

Vendor booting scheme issues /1 FAT Unreliable on power loss It just cannot contain a UNIX-like rootfs NAND FTL (Flash Translation Layer) FAT-on-NAND emulation (with FTL) is in a binary module NVT Loader cannot mount UBIFS No provision for redundancy Data may be accessble to users in production 19

Vendor booting scheme issues /2 Root filesystem is an initramfs Volatile Uses RAM NVT Loader does not pass cmdline to kernel it must be hard-coded in the kernel (CONFIG_CMDLINE) NFS booting Needs cmdline parameters must rebuild and reflash the kernel Cannot load kernel via TFTP 20

Alternative booting options? 20

Option 1: add a SquashFS layer on top of FAT NAND Loader NVT Loader FAT1 conprog.bin Image (with initramfs) start.sh squashfs Keep the existing structure untouched Remove initramfs constraints Still read-only ext2 or any other rw filesystem over FAT over NAND is crazy The device cannot atomically upgrade itself 21

Option 2: jump from FAT to UBIFS NAND Loader NVT Loader FAT1 conprog.bin Image (with initramfs) UBI root fs (UBIFS) UBI and UBIFS are designed for NAND! Tweaks needed Change the initramfs /init to mount UBIFS and switch_root Tweak NVT Loader not to use all space for FAT USB mass storage can only update kernel FAT area atrophied, NVT Loader almost useless 22

Option 3: skip NVT Loader NAND Loader Image + initramfs UBI root fs (UBIFS) NAND Loader loads Image to address 0 and jumps there No more NVT Loader and FAT Kernel still on bare NAND and without cmdline Replacement for the U-Boot environment? 23

Option 4: Port U-Boot Port U-Boot or Barebox to the SoC Maybe keeping the vendor NAND Loader (SPL) Unleashes all the known advantages Environment, boot-time scripting, prompt cmdline, TFTP boot, kernel loading from rootfs Redundancy for all/most components on bare NAND Time to market? 24

Tools

Vendor tools Ideally, no vendor-specific tools are needed Flashing an empty memory is different Boot ROM protocol is not standardized Vendor-specific tools 25

Flashing tools Tool provided to write memory Quite flexible Can write NAND, SPI, SD, SDRAM (and execute) Over USB GUI, not scriptable For Windows only Proprietary, binary only Protocol to Boot ROM not documented You re locked to it NAND Windows PC USB BOOT ROM NOR SD RAM 26

NAND partition table Proprietary partition table in the NAND Loader area The proprietary tool writes only this format Not a bad idea but standard tools work differently You can t get rid of the table NAND Loader 27

Customer support

A real e-mail exchange (short form) Me The proprietary tool doesn t work 28

A real e-mail exchange (short form) Me The proprietary tool doesn t work CS Works on my PC, see screenshot 28

A real e-mail exchange (short form) Me The proprietary tool doesn t work CS Works on my PC, see screenshot Me Not on mine; can it log errors so you can diagnose it? 28

A real e-mail exchange (short form) Me The proprietary tool doesn t work CS Works on my PC, see screenshot Me Not on mine; can it log errors so you can diagnose it? CS Adding logging would not be practical 28

Concluding remarks

The result Comparison with a well-supported SoC Higher development cost Longer time-to-market Final product quality is lower The hardware would allow to do better 29

What can I do to improve things? As an embedded Linux engineer Assess potential problems early while evaluating a SoC As a hobbyist or a hacker Pick boards with good mainline support, or Improve existing support and mainline it 30

What can vendors do to ship better BSPs? Don t reinvent the wheel Write good docs, no NDA, no registration Including your Boot ROM protocol And let people write the tools they want Push your code to mainline Leverage the community Let your engineers use mailing-lists, IRC etc Make cheap, hacker-friendly boards 31

A possible idea? 32

A possible idea? All images are copyright of their respective owners ;) 32

A possible idea? Mainline Linux 4.14 All images are copyright of their respective owners ;) 32

Thank you for your attention! Questions? Luca Ceresoli luca@lucaceresoli.net http://lucaceresoli.net Copyright 2017, Luca Ceresoli Slides released under Creative Commons Attribution - Share Alike 3.0 License https://creativecommons.org/licenses/by-sa/3.0/ 33

References Stuck in 2009 How I Survived Will Sheppard, Embedded Bits Limited ELC-E 2016 https://elinux.org/elc_europe_2016_presentations How I survived to a SoC with a terrible Linux BSP Luca Ceresoli FOSDEM 2016 (Previous version of this talk) https://archive.fosdem.org/2017/schedule/event/terrible_bsp/ 34

Extra Slides

Kernel code quality Extra examples

Kernel code quality example 1 Changes to Makefile: -ARCH?= $(SUBARCH) -CROSS_COMPILE?= -CROSS_COMPILE?= $(CONFIG_CROSS_COMPILE:''%''=%) +#ARCH?= $(SUBARCH) +ARCH= arm +#CROSS_COMPILE?= +#CROSS_COMPILE?= $(CONFIG_CROSS_COMPILE:''%''=%) +CROSS_COMPILE= arm-linux- Prevents using toolchains with a different prefix Any advantage?

Kernel code quality example 2 Changes to arch/arm/boot/makefile: $(obj)/image: vmlinux FORCE $(call if_changed,objcopy) @echo ' Kernel: $@ is ready' +ifeq ($(CONFIG_ARCH_W55FA92),y) + cp $@../image/conprog.bin +endif../image/ does not make sense in any buildsystem

Kernel code quality example 3 sound/soc/w55fa92/w55fa92_spu.c: if (nchannels ==1) { DrvSPU_EnableInt(_u8Channel0, DRVSPU_ENDADDRESS_INT); DrvSPU_EnableInt(_u8Channel0, DRVSPU_THADDRESS_INT); } else { /* just open one channel interrupt */ DrvSPU_EnableInt(_u8Channel0, DRVSPU_ENDADDRESS_INT); DrvSPU_EnableInt(_u8Channel0, DRVSPU_THADDRESS_INT); } Find the differences between the then and the else branch

Kernel code quality example 4 sound/soc/w55fa92/w55fa92_spu.c: static int DrvSPU_EnableInt(u32 u32channel, u32 u32interruptflag) { if ( (u32channel >=edrvspu_channel_0) && (u32channel <=edrvspu_channel_31) ) { /*... */ if (u32interruptflag & DRVSPU_USER_INT) { AUDIO_WRITE(REG_SPU_CH_EVENT, AUDIO_READ(REG_SPU_CH_EVENT) EV_USR_EN); } if (u32interruptflag & DRVSPU_SILENT_INT) { AUDIO_WRITE(REG_SPU_CH_EVENT, AUDIO_READ(REG_SPU_CH_EVENT) EV_SLN_EN); } /*...a few more times... */ /*... */ return E_SUCCESS; } else return E_DRVSPU_WRONG_CHANNEL; }

Kernel code quality example 5 arch/arm/mach-w55fa92/include/mach/w55fa92_gpio.h: static inline int w55fa92_gpio_configure(int group, int num) { /*... */ case GPIO_GROUP_B: if(num <= 7) writel(readl(reg_gpbfun0) &~ (0xF << (num<<2)), REG_GPBFUN0); else writel(readl(reg_gpbfun1) &~ (0xF << ((num%8)<<2)), REG_GPBFUN1); break; case GPIO_GROUP_C: if(num <= 7) writel(readl(reg_gpcfun0) &~ (0xF << (num<<2)), REG_GPCFUN0); else writel(readl(reg_gpcfun1) &~ (0xF << ((num%8)<<2)), REG_GPCFUN1); break; /*...similarly fo other GPIO ports... */ } A little refactoring would help

Toolchain

Vendor toolchain The BSP provides a toolchain. Why? What s inside gcc 4.2.1 (July 2007) No C++11 support gcc 4.2.x got fixes until 4.2.4 (May 2008) uclibc 0.9.29 (2007) What if I need glibc or musl? Bugfixes and improvements in later versions? A few other libraries (libcurl, libpng ) A hand-crafted script to install it at a hard-coded location

Toolchain selection Don t use the provided toolchain You could use a pre-built toolchain If it has been built with kernel headers <= 2.6.35 So it s probably quite old itself Build your own crosstool-ng, Buildroot, Openembedded

Using an old gcc an example A C++ program using libconfuse 3.0 #include <confuse.h> //... cfg_opt_t opts[] = { CFG_STR("my-param", "defval", CFGF_NONE), CFG_END() }; With gcc <= 4.8 fails building due to designated initializers not being implemented: error: expected primary-expression before '.' token