SlideShare uma empresa Scribd logo
1 de 73
Baixar para ler offline
1
Confidential
Linux Kernel Platform Development:
Challenges and Insights
Sam Protsenko
Software Engineer
February 10, 2018
2
Confidential
Agenda
1. Role Overview
2. War Stories and Learnings
• Story #1: Board bring-up
• Story #2: Migration to a new kernel
• Story #3: Hardware fixing
3
Confidential
3
Role Overview
4
Confidential
Tasks
• Board bring-up
• Porting kernel (and bootloader) to a new board
- Writing the BSP
- Drivers development
• Migrating to a new kernel version
• Bug fixing
• Boot time optimizations
• Upstreaming
• Sometimes:
- Bootloader related work
- Low-level work in rootfs (Android, OpenEmbedded, etc.)
- Hardware debugging
5
Confidential
Tasks
Make board minimally functional,
step by step, for all required
components. Make sure it works.
• Check power and reset lines
• Check clock signals
• Debug SoC issues (caches, etc.)
• Configure pin muxes
• Bring-up RAM (DDR), serial
console (UART), peripheral
(eMMC, USB, LCD, etc.)
Board bring-up
6
Confidential
Tasks
Make kernel and bootloader fully
functional on a new board.
• Bootloader bring-up
• Device Tree file
• Configuration file
• SoC support
• Write missing peripheral drivers
Porting kernel to a new board
7
Confidential
Tasks
Modify board related files to work in
a new kernel version.
• Sometimes company doesn’t
want to upstream its kernel
• Migration work:
- board files -> device tree
- new API for kernel frameworks
- config options
- sometimes back-porting is needed
• Automated approach exists: see
“Prequel” by Julia Lawall
Migrating to a new kernel version
8
Confidential
Components and Tools
• Linux kernel
• Bootloader (U-Boot, UEFI/edk2)
• RootFS (Android, Debian, OpenEmbedded,
BusyBox)
• C language
• OS principles
• Microcontrollers basics (+schematics)
• Linux user experience
Components
• Software
- toolchain (ARM GCC): gcc, gdb, ld, as
- binutils (add2line, strings, objdump, nm)
- Git
- Linux CLI tools
- board specific and task specific tools
(fastboot, dfu-util, omapconf, minicom, adb)
• Hardware
- JTAG
- logical analyzer
- oscilloscope
- soldering iron
Tools
Knowledge
99
Confidential
War Stories and Learnings
10
Confidential
10
Story #1: NOR flash support + XIP
boot
11
Confidential
Story #1: NOR flash support and XIP boot
Task highlights:
• Provide NOR flash chip support:
- in kernel
- in U-Boot
• Provide XIP boot:
- for U-Boot
- for kernel
12
Confidential
Overview: NOR flash
• NOR flash is XIP capable (eXecution In Place)
• XIP from NOR is often used for reducing the boot time
• Can be useful in automotive and mobile areas
• It’s possible to run U-Boot and kernel from NOR flash
(Android or Linux rootfs is stored on eMMC)
• Concerns:
- drivers (GPMC, MTD, CFI, ELM)
- Device Tree definition
- timings
- U-Boot/kernel configuration for XIP
13
Confidential
Overview: NAND flash wiring
14
Confidential
Overview: NOR flash wiring
15
Confidential
Overview: NOR and NAND flash comparison
Parameter NOR NAND
Capacity Small (64 KB - 512 MB) Huge (16 MB - 1 TB)
XIP (code execution) Yes No
Block erase time Very slow (1 sec) Fast (500 μsec)
Write time Slow (10 μsec / word) Fast (200 μsec / page)
Read time Fast (100 nsec / word) Fast (50 μsec / page)
Erase cycle range 10,000 to 100,000 1,000,000 with ECC
Access method Random Sequential
Price High (4x / MB) Very low (x / MB)
16
Confidential
Overview: Connection to SoC
17
Confidential
Sub-task 1: Timings
● GPMC controller must be programmed with correct timings
● Timings must be calculated from NOR chip characteristics
● There are a lot of them
● Usually board manufacturer should provide you with correct timings
● If NOR flash hangs - most likely timings are wrong
18
Confidential
Sub-task 1: Timings
• cs-on
• cs-rd-off
• cs-wr-off
• oe-on
• oe-off
• we-on
• we-off
• rd-access
And much more else timings...
GPMC: Timings and parameters
19
Confidential
Sub-task 1: Timings
• CONFIG1
• CONFIG2
• CONFIG3
• CONFIG4
• CONFIG5
• CONFIG6
GPMC: Registers
Register example:
20
Confidential
Sub-task 1: Timings
● Conversion tool was developed:
https://gitlab.com/joeskb7/gpmc-timings
Usage:
./gpmc-timings -p CONFIG1..CONFIG6
./gpmc-timings -y <file>
-y file - yield registers values from file
-p registers - parse and print registers values
Conversion tool
21
Confidential
Sub-task 1: Timings
&gpmc {
nor@0,0 {
gpmc,cs-on-ns = <0>;
gpmc,cs-rd-off-ns = <50>;
gpmc,cs-wr-off-ns = <57>;
gpmc,oe-on-ns = <0>;
gpmc,oe-off-ns = <50>;
...
};
};
Timings in Device Tree
22
Confidential
Sub-task 2: Clocks and DPLLs
● GPMC clock must be enabled and be of correct frequency
● Check correct value (calculated for NOR timings)
● Check actual value (from kernel DebugFS)
● Fix clock if needed
● Clock derivation path can be seen from SoC TRM
23
Confidential
Sub-task 2: Clocks and DPLLs
GPMC_FCLK
24
Confidential
Sub-task 2: Clocks and DPLLs
L3MAIN1_L3_GICLK = L3_ICLK
25
Confidential
Sub-task 2: Clocks and DPLLs
L3_ICLK
26
Confidential
Sub-task 2: Clocks and DPLLs
CORE_X2_CLK
27
Confidential
Sub-task 2: Clocks and DPLLs
● Enable CONFIG_COMMON_CLK_DEBUG
● Mount DebugFS (in example below, it’s mounted to /d)
● Print clocks frequencies:
/d/clk/.../dpll_core_x2_ck/dpll_core_h12x2_ck # cat clk_rate
532000000
/d/clk/.../dpll_core_x2_ck/dpll_core_h12x2_ck/l3_iclk_div # cat clk_rate
532000000
But we see from TRM that L3_ICLK must be CORE_X2_CLK / 2
Check clock freq in DebugFS
28
Confidential
Sub-task 2: Clocks and DPLLs
l3_iclk_div: l3_iclk_div {
#clock-cells = <0>;
- compatible = "fixed-factor-clock";
+ compatible = "ti,divider-clock";
+ ti,max-div = <2>;
};
Fix the clock
29
Confidential
Sub-task 2: Clocks and DPLLs
● Print clocks frequencies:
/d/clk/.../dpll_core_x2_ck/dpll_core_h12x2_ck # cat clk_rate
532000000
/d/clk/.../dpll_core_x2_ck/dpll_core_h12x2_ck/l3_iclk_div # cat clk_rate
266000000
So GPMC functional clock frequency now is 266 MHz, which is a desired frequency.
Check clock freq in DebugFS after fix
30
Confidential
Sub-task 3: Kernel support
● NOR flash and eMMC were sharing the lines (found from schematic)
● So there was only 512 KiB of NOR flash accessible in kernel
● Means no kernel XIP
● But we can still:
○ read/write NOR from kernel
○ do U-Boot XIP
● NOR support wasn’t ready in our kernel at the time (k3.8)
● But it was ready in mainline kernel (3.11)
31
Confidential
Sub-task 3: Kernel support
● Patches often have dependencies
● It’s hard to find all actual dependencies between branches
● Kernel maintainers have dedicated trees/branches for features like GPMC
● Use smart cherry-picking
Backporting patches
32
Confidential
Sub-task 3: Kernel support
Cherry-pick like a pro
33
Confidential
Sub-task 3: Kernel support
nor@0,0 {
/* We can only access 512 KiB from kernel */
partition@0 {
label = "boot"; /* u-boot.bin */
reg = <0x00000000 0x00060000>; /* 384 KiB */
};
partition@1 {
label = "env"; /* U-Boot environment */
reg = <0x00060000 0x00020000>; /* 128 KiB */
};
};
NOR partitions
34
Confidential
Sub-task 3: Kernel support
# flash_erase /dev/mtd/mtd0 0 0
# cat mtd0-to.img >/dev/mtd/mtd0
# cat /dev/mtd/mtd0 >mtd0-from.img
MTD utils and MTD char devices read/write
35
Confidential
Sub-task 4: U-Boot XIP
● For XIP boot we don’t need MLO (U-Boot SPL), only u-boot.bin
● Boot sequence:
○ U-Boot is started by ROM code
○ U-Boot copies all files needed to RAM (dtb, kernel, ramdisk)
○ U-Boot switches to eMMC (e.g. via GPIO line)
○ U-Boot starts kernel from RAM; now we are not in XIP boot anymore
● Problem: U-Boot hangs when running XIP from NOR
36
Confidential
Sub-task 4: U-Boot XIP
● U-Boot is too big to figure out why it’s not working
● We can’t even be sure XIP can work at all
● Let’s shrink U-Boot to minimal code and see if it works
● XIP “Hello world” baremetal firmware was implemented:
○ start assembler code (shrinked)
○ linker script (minimal: text/rodata/data/bss, all in SRAM)
○ BSS clear
○ enable UART clock + dependency clocks
○ pin muxes
○ naiive UART driver
○ print “Hello world” to UART (serial console)
https://gitlab.com/joeskb7/dra7xx-hello
Approach the problem
37
Confidential
Sub-task 4: U-Boot XIP
● Minimal app worked, but U-Boot won’t work
● Now we know NOR flash + XIP is functional and there is
some bug in U-Boot
● Use JTAG to investigate the issue
Investigation
38
Confidential
Sub-task 4: U-Boot XIP
Root cause
39
Confidential
Sub-task 4: U-Boot XIP
● git bisect-ing helped to find the actual bug
● We were given modified U-Boot with code like this
(in drivers/mmc/Makefile):
CFLAGS := $(subst -Os, -O0, $(CFLAGS)) -fPIC
Root cause (2)
40
Confidential
Sub-task 4: U-Boot XIP
41
Confidential
Sub-task 4: U-Boot XIP
● So only MMC related files were built with -O0 -fPIC
● But other U-Boot files were build with -Os
● That led to NULL pointer dereference
● Removing that line fixed the problem
Fix
42
Confidential
Learnings:
● Always check mainline kernel and mailing lists for existing patch
● Git is your friend:
○ cherry-pick thoughtfully
○ bisect often helps to find the regression
● If some task is repeated often -- develop some tool or script
○ Share it if possible
● Isolating the problem helps to find the root cause
● JTAG is an ultimate tool for debugging
43
Confidential
43
Story #2: Updating MAX732x
driver
44
Confidential
Story #2: Updating MAX732x driver
Task highlights:
• Update MAX732x driver to use Device Tree
• Provide bindings documentation
• Make it functional and bug-free
• Upstream changes
45
Confidential
Overview: Chip description
• I2C I/O Expander
• Often used in automotive
• Have one-directional and
bidirectional ports
• Sends interrupt to SoC when input
event occurred
46
Confidential
Sub-task 1: Device tree support
#ifdef CONFIG_OF
static const struct of_device_id max732x_of_table[] = {
...
{ .compatible = "maxim,max7325" },
...
{ }
};
MODULE_DEVICE_TABLE(of, max732x_of_table);
#endif
OF Table
47
Confidential
Sub-task 1: Device tree support
static struct i2c_driver max732x_driver = {
.driver = {
.name = "max732x",
.owner = THIS_MODULE,
.of_match_table = of_match_ptr(max732x_of_table),
},
...
}
I2C driver struct
48
Confidential
Sub-task 1: Device tree support
Platform data doesn’t exist in case of OF provider.
- chip->irq_base = pdata->irq_base;
+ if (pdata)
+ chip->irq_base =
pdata->irq_base;
Check pdata
49
Confidential
Sub-task 2: Interrupt controller
50
Confidential
Sub-task 2: Interrupt controller
● GPIO framework is capable of handling IRQ controller code for you
● Remove IRQ domain code / manual IRQ calculation and use gpiochip_* API
config GPIO_MAX732X_IRQ
select GPIOLIB_IRQCHIP
#include <linux/gpio/driver.h>
gpiochip_add()
gpiochip_remove()
gpiochip_irqchip_add()
gpiochip_set_chained_irqchip()
GPIOLIB_IRQCHIP
51
Confidential
Sub-task 3: DT definition and bindings
● We want to I2C address of MAX7325 to be 0x5d
● As per datasheet:
Pin Line
----------
AD2 V+
AD0 V+
Check I2C address on schematics
52
Confidential
Sub-task 3: DT definition and bindings
&i2c0 {
expander: max7325@5d {
compatible = "maxim,max7325";
reg = <0x5d>;
gpio-controller;
#gpio-cells = <2>;
};
};
DT Definition: disabled interrupts
53
Confidential
Sub-task 3: DT definition and bindings
&i2c0 {
expander: max7325@5d {
compatible = "maxim,max7325";
reg = <0x5d>;
gpio-controller;
#gpio-cells = <2>;
interrupt-controller;
#interrupt-cells = <2>;
interrupt-parent = <&gpio4>;
interrupts = <29 IRQ_TYPE_EDGE_FALLING>;
};
};
DT Definition: enabled interrupts
54
Confidential
Sub-task 4: Upstreaming
$ git log --author="Protsenko" --oneline | grep max732
606f13e9efa0 gpio: max732x: Fix irq-events handler
68689dbf35e1 gpio: max732x: Add IRQF_SHARED to irq flags
67ddd32bfc9f gpio: max732x: Propagate wake-up setting to parent irq
controller
996bd13f28e6 gpio: max732x: Add DT binding documentation
09afa276d52e gpio: max732x: Fix possible deadlock
479f8a5744d8 gpio: max732x: Rewrite IRQ code to use irq_domain API
43c4bcf9425e gpio: max732x: Add device tree support
$ git log -- drivers/gpio/gpio-max732x.c
Patches in upstream
55
Confidential
Sub-task 4: Upstreaming
Testing board: schematic
56
Confidential
Sub-task 4: Upstreaming
Testing board: PCB
57
Confidential
Learnings:
● If in doubt -- check schematics
● Check out existing code in kernel for examples
● Check if there is existing framework for that problem
● Take responsibility (technical debt)
● Ask your customer about upstreaming
58
Confidential
Linus Torvalds shaves Bdale Garbee's beard
59
Confidential
59
Story #3: Flashing EEPROM
60
Confidential
Story #3: Flashing EEPROM
Task highlights:
• EEPROM chip wasn’t flashed with Board ID
• It led to 2 issues:
- U-Boot was unable to find correct DTB file
- "board_rev" variable were missing in U-Boot environment
• Fix:
- Disable “Read only” mode for EEPROM chip
- Figure out how to work with it
- Write correct Board ID value to EEPROM
- Set back “Read only” mode
61
Confidential
Sub-task 1: Disable write protection
Schematic
62
Confidential
Sub-task 1: Disable write protection
First glance at PCB
63
Confidential
Sub-task 1: Disable write protection
Disabling write protection
64
Confidential
Sub-task 2: Writing to EEPROM
static void setup_board_eeprom_env(void)
{
printf("### Writing EEPROM...n");
rc = ti_write_eeprom(CONFIG_EEPROM_BUS_ADDRESS,
CONFIG_EEPROM_CHIP_ADDRESS);
if (rc)
printf("### Error: Unable to write EEPROMn");
else
printf("### Writing EEPROM: Success!n");
}
U-Boot code (1)
65
Confidential
Sub-task 2: Writing to EEPROM
static int ti_i2c_write_eeprom(int bus_addr, int dev_addr, u32 size,
uint8_t *ep, unsigned int mem_addr)
{
/* Memory address size is 2 bytes */
return i2c_write(dev_addr, mem_addr, 2, ep, size);
}
U-Boot code (2)
66
Confidential
Sub-task 2: Writing to EEPROM
int ti_write_eeprom(int bus_addr, int dev_addr)
{
const char *name = "AM572PM_";
const char *rev = "A.20";
const char *serial = "07164P550148";
const char *config = "";
struct ti_am_eeprom am_ep;
uint8_t page[64];
int i, j;
int rc;
U-Boot code (3)
67
Confidential
Sub-task 2: Writing to EEPROM
/* Prepare structure for EEPROM */
memset(&am_ep, 0, sizeof(am_ep));
am_ep.header = TI_EEPROM_HEADER_MAGIC;
strncpy(am_ep.name, name, TI_EEPROM_HDR_NAME_LEN);
strncpy(am_ep.version, rev, TI_EEPROM_HDR_REV_LEN);
strncpy(am_ep.serial, serial, TI_EEPROM_HDR_SERIAL_LEN);
strncpy(am_ep.config, config, TI_EEPROM_HDR_CONFIG_LEN);
for (i = 0; i < TI_EEPROM_HDR_NO_OF_MAC_ADDR; ++i)
for (j = 0; j < TI_EEPROM_HDR_ETH_ALEN; ++j)
am_ep.mac_addr[i][j] = 0xff;
U-Boot code (4)
68
Confidential
Sub-task 2: Writing to EEPROM
/* Init I2C */
gpi2c_init();
rc = ti_i2c_eeprom_init(bus_addr, dev_addr);
if (rc)
return rc;
U-Boot code (5)
69
Confidential
Sub-task 2: Writing to EEPROM
/* Write 1st page */
memset(page, 0, 64);
memcpy(page, (uint8_t *)&am_ep, 64);
rc = ti_i2c_write_eeprom(bus_addr, dev_addr, 64, page, 0x00);
mdelay(100); /* t_WR = 5 msec */
if (rc)
return rc;
U-Boot code (6)
70
Confidential
Sub-task 2: Writing to EEPROM
/* Write 2nd page */
memset(page, 0, 64);
memcpy(page, ((uint8_t *)&am_ep) + 64, 14);
rc = ti_i2c_write_eeprom(bus_addr, dev_addr, 64, page, 0x40);
mdelay(100); /* t_WR = 5 msec */
if (rc)
return rc;
return 0;
}
U-Boot code (7)
71
Confidential
Learnings:
72
Confidential
Thank you
Sam Protsenko
Software Engineer
semen.protsenko@globallogic.com
73
Confidential
Abbreviations:
● BSP - Board Support Package
● CFI - Common Flash Interface
● DPLL - Digital Phase-Locked Loop
● DTB - Device Tree Binary
● EEPROM - Electrically Erasable Programmable Read-Only Memory
● eMMC - Embedded MultiMedia Card
● FIT - Flattened Image Tree
● GIC - Generic Interrupt Controller
● GPIO - General Purpose Input Output
● GPMC - General Purpose Memory Controller
● INTC - Interrupt Controller
● MTD - Memory Technology Device
● NOR - Not Or
● SoC - System On Chip
● TRM - Technical Reference Manual
● XIP - eXecute In Place

Mais conteúdo relacionado

Mais procurados

Uboot startup sequence
Uboot startup sequenceUboot startup sequence
Uboot startup sequence
Houcheng Lin
 
LCU14 302- How to port OP-TEE to another platform
LCU14 302- How to port OP-TEE to another platformLCU14 302- How to port OP-TEE to another platform
LCU14 302- How to port OP-TEE to another platform
Linaro
 

Mais procurados (20)

Linux Crash Dump Capture and Analysis
Linux Crash Dump Capture and AnalysisLinux Crash Dump Capture and Analysis
Linux Crash Dump Capture and Analysis
 
QEMU - Binary Translation
QEMU - Binary Translation QEMU - Binary Translation
QEMU - Binary Translation
 
Kernel Recipes 2015 - The Dronecode Project – A step in open source drones
Kernel Recipes 2015 - The Dronecode Project – A step in open source dronesKernel Recipes 2015 - The Dronecode Project – A step in open source drones
Kernel Recipes 2015 - The Dronecode Project – A step in open source drones
 
Qemu Introduction
Qemu IntroductionQemu Introduction
Qemu Introduction
 
Linux Initialization Process (2)
Linux Initialization Process (2)Linux Initialization Process (2)
Linux Initialization Process (2)
 
U-Boot presentation 2013
U-Boot presentation  2013U-Boot presentation  2013
U-Boot presentation 2013
 
BKK16-303 96Boards - TV Platform
BKK16-303 96Boards - TV PlatformBKK16-303 96Boards - TV Platform
BKK16-303 96Boards - TV Platform
 
Kernel Recipes 2015 - Kernel dump analysis
Kernel Recipes 2015 - Kernel dump analysisKernel Recipes 2015 - Kernel dump analysis
Kernel Recipes 2015 - Kernel dump analysis
 
HKG15-409: ARM Hibernation enablement on SoCs - a case study
HKG15-409: ARM Hibernation enablement on SoCs - a case studyHKG15-409: ARM Hibernation enablement on SoCs - a case study
HKG15-409: ARM Hibernation enablement on SoCs - a case study
 
Kernel Recipes 2015: Kernel packet capture technologies
Kernel Recipes 2015: Kernel packet capture technologiesKernel Recipes 2015: Kernel packet capture technologies
Kernel Recipes 2015: Kernel packet capture technologies
 
Kernel Recipes 2015: Speed up your kernel development cycle with QEMU
Kernel Recipes 2015: Speed up your kernel development cycle with QEMUKernel Recipes 2015: Speed up your kernel development cycle with QEMU
Kernel Recipes 2015: Speed up your kernel development cycle with QEMU
 
Uboot startup sequence
Uboot startup sequenceUboot startup sequence
Uboot startup sequence
 
HKG15-311: OP-TEE for Beginners and Porting Review
HKG15-311: OP-TEE for Beginners and Porting ReviewHKG15-311: OP-TEE for Beginners and Porting Review
HKG15-311: OP-TEE for Beginners and Porting Review
 
LCU14 302- How to port OP-TEE to another platform
LCU14 302- How to port OP-TEE to another platformLCU14 302- How to port OP-TEE to another platform
LCU14 302- How to port OP-TEE to another platform
 
Secure Boot on ARM systems – Building a complete Chain of Trust upon existing...
Secure Boot on ARM systems – Building a complete Chain of Trust upon existing...Secure Boot on ARM systems – Building a complete Chain of Trust upon existing...
Secure Boot on ARM systems – Building a complete Chain of Trust upon existing...
 
SoC Idling for unconf COSCUP 2016
SoC Idling for unconf COSCUP 2016SoC Idling for unconf COSCUP 2016
SoC Idling for unconf COSCUP 2016
 
Kernel Recipes 2015: Greybus
Kernel Recipes 2015: GreybusKernel Recipes 2015: Greybus
Kernel Recipes 2015: Greybus
 
Bypassing ASLR Exploiting CVE 2015-7545
Bypassing ASLR Exploiting CVE 2015-7545Bypassing ASLR Exploiting CVE 2015-7545
Bypassing ASLR Exploiting CVE 2015-7545
 
Linux Kernel Booting Process (1) - For NLKB
Linux Kernel Booting Process (1) - For NLKBLinux Kernel Booting Process (1) - For NLKB
Linux Kernel Booting Process (1) - For NLKB
 
Jagan Teki - U-boot from scratch
Jagan Teki - U-boot from scratchJagan Teki - U-boot from scratch
Jagan Teki - U-boot from scratch
 

Semelhante a Linux Kernel Platform Development: Challenges and Insights

Semelhante a Linux Kernel Platform Development: Challenges and Insights (20)

Let's trace Linux Lernel with KGDB @ COSCUP 2021
Let's trace Linux Lernel with KGDB @ COSCUP 2021Let's trace Linux Lernel with KGDB @ COSCUP 2021
Let's trace Linux Lernel with KGDB @ COSCUP 2021
 
Lec 10-linux-review
Lec 10-linux-reviewLec 10-linux-review
Lec 10-linux-review
 
Porting Android
Porting AndroidPorting Android
Porting Android
 
Kernel bug hunting
Kernel bug huntingKernel bug hunting
Kernel bug hunting
 
LMG Lightning Talks - SFO17-205
LMG Lightning Talks - SFO17-205LMG Lightning Talks - SFO17-205
LMG Lightning Talks - SFO17-205
 
SMP implementation for OpenBSD/sgi
SMP implementation for OpenBSD/sgiSMP implementation for OpenBSD/sgi
SMP implementation for OpenBSD/sgi
 
Когда предрелизный не только софт
Когда предрелизный не только софтКогда предрелизный не только софт
Когда предрелизный не только софт
 
Porting Android
Porting AndroidPorting Android
Porting Android
 
Porting Android ABS 2011
Porting Android ABS 2011Porting Android ABS 2011
Porting Android ABS 2011
 
Embedded Fest 2019. Игорь Опанюк. Das U-boot v2019: a look under the hood
Embedded Fest 2019. Игорь Опанюк. Das U-boot v2019: a look under the hoodEmbedded Fest 2019. Игорь Опанюк. Das U-boot v2019: a look under the hood
Embedded Fest 2019. Игорь Опанюк. Das U-boot v2019: a look under the hood
 
Android for Embedded Linux Developers
Android for Embedded Linux DevelopersAndroid for Embedded Linux Developers
Android for Embedded Linux Developers
 
[OpenStack Day in Korea 2015] Track 1-6 - 갈라파고스의 이구아나, 인프라에 오픈소스를 올리다. 그래서 보이...
[OpenStack Day in Korea 2015] Track 1-6 - 갈라파고스의 이구아나, 인프라에 오픈소스를 올리다. 그래서 보이...[OpenStack Day in Korea 2015] Track 1-6 - 갈라파고스의 이구아나, 인프라에 오픈소스를 올리다. 그래서 보이...
[OpenStack Day in Korea 2015] Track 1-6 - 갈라파고스의 이구아나, 인프라에 오픈소스를 올리다. 그래서 보이...
 
Introduction to Modern U-Boot
Introduction to Modern U-BootIntroduction to Modern U-Boot
Introduction to Modern U-Boot
 
UWE Linux Boot Camp 2007: Hacking embedded Linux on the cheap
UWE Linux Boot Camp 2007: Hacking embedded Linux on the cheapUWE Linux Boot Camp 2007: Hacking embedded Linux on the cheap
UWE Linux Boot Camp 2007: Hacking embedded Linux on the cheap
 
Strategies for developing and deploying your embedded applications and images
Strategies for developing and deploying your embedded applications and imagesStrategies for developing and deploying your embedded applications and images
Strategies for developing and deploying your embedded applications and images
 
Bsdtw17: ruslan bukin: free bsd/risc-v and device drivers
Bsdtw17: ruslan bukin: free bsd/risc-v and device driversBsdtw17: ruslan bukin: free bsd/risc-v and device drivers
Bsdtw17: ruslan bukin: free bsd/risc-v and device drivers
 
One Year of Porting - Post-mortem of two Linux/SteamOS launches
One Year of Porting - Post-mortem of two Linux/SteamOS launchesOne Year of Porting - Post-mortem of two Linux/SteamOS launches
One Year of Porting - Post-mortem of two Linux/SteamOS launches
 
Tech Days 2015: ARM Programming with GNAT and Ada 2012
Tech Days 2015: ARM Programming with GNAT and Ada 2012Tech Days 2015: ARM Programming with GNAT and Ada 2012
Tech Days 2015: ARM Programming with GNAT and Ada 2012
 
Kernel Recipes 2019 - BPF at Facebook
Kernel Recipes 2019 - BPF at FacebookKernel Recipes 2019 - BPF at Facebook
Kernel Recipes 2019 - BPF at Facebook
 
Linux Capabilities - eng - v2.1.5, compact
Linux Capabilities - eng - v2.1.5, compactLinux Capabilities - eng - v2.1.5, compact
Linux Capabilities - eng - v2.1.5, compact
 

Mais de GlobalLogic Ukraine

GlobalLogic Machine Learning Webinar “Advanced Statistical Methods for Linear...
GlobalLogic Machine Learning Webinar “Advanced Statistical Methods for Linear...GlobalLogic Machine Learning Webinar “Advanced Statistical Methods for Linear...
GlobalLogic Machine Learning Webinar “Advanced Statistical Methods for Linear...
GlobalLogic Ukraine
 

Mais de GlobalLogic Ukraine (20)

GlobalLogic Embedded Community x ROS Ukraine Webinar "Surgical Robots"
GlobalLogic Embedded Community x ROS Ukraine Webinar "Surgical Robots"GlobalLogic Embedded Community x ROS Ukraine Webinar "Surgical Robots"
GlobalLogic Embedded Community x ROS Ukraine Webinar "Surgical Robots"
 
GlobalLogic Java Community Webinar #17 “SpringJDBC vs JDBC. Is Spring a Hero?”
GlobalLogic Java Community Webinar #17 “SpringJDBC vs JDBC. Is Spring a Hero?”GlobalLogic Java Community Webinar #17 “SpringJDBC vs JDBC. Is Spring a Hero?”
GlobalLogic Java Community Webinar #17 “SpringJDBC vs JDBC. Is Spring a Hero?”
 
GlobalLogic JavaScript Community Webinar #18 “Long Story Short: OSI Model”
GlobalLogic JavaScript Community Webinar #18 “Long Story Short: OSI Model”GlobalLogic JavaScript Community Webinar #18 “Long Story Short: OSI Model”
GlobalLogic JavaScript Community Webinar #18 “Long Story Short: OSI Model”
 
Штучний інтелект як допомога в навчанні, а не замінник.pptx
Штучний інтелект як допомога в навчанні, а не замінник.pptxШтучний інтелект як допомога в навчанні, а не замінник.pptx
Штучний інтелект як допомога в навчанні, а не замінник.pptx
 
Задачі AI-розробника як застосовується штучний інтелект.pptx
Задачі AI-розробника як застосовується штучний інтелект.pptxЗадачі AI-розробника як застосовується штучний інтелект.pptx
Задачі AI-розробника як застосовується штучний інтелект.pptx
 
Що треба вивчати, щоб стати розробником штучного інтелекту та нейромереж.pptx
Що треба вивчати, щоб стати розробником штучного інтелекту та нейромереж.pptxЩо треба вивчати, щоб стати розробником штучного інтелекту та нейромереж.pptx
Що треба вивчати, щоб стати розробником штучного інтелекту та нейромереж.pptx
 
GlobalLogic Java Community Webinar #16 “Zaloni’s Architecture for Data-Driven...
GlobalLogic Java Community Webinar #16 “Zaloni’s Architecture for Data-Driven...GlobalLogic Java Community Webinar #16 “Zaloni’s Architecture for Data-Driven...
GlobalLogic Java Community Webinar #16 “Zaloni’s Architecture for Data-Driven...
 
JavaScript Community Webinar #14 "Why Is Git Rebase?"
JavaScript Community Webinar #14 "Why Is Git Rebase?"JavaScript Community Webinar #14 "Why Is Git Rebase?"
JavaScript Community Webinar #14 "Why Is Git Rebase?"
 
GlobalLogic .NET Community Webinar #3 "Exploring Serverless with Azure Functi...
GlobalLogic .NET Community Webinar #3 "Exploring Serverless with Azure Functi...GlobalLogic .NET Community Webinar #3 "Exploring Serverless with Azure Functi...
GlobalLogic .NET Community Webinar #3 "Exploring Serverless with Azure Functi...
 
Страх і сила помилок - IT Inside від GlobalLogic Education
Страх і сила помилок - IT Inside від GlobalLogic EducationСтрах і сила помилок - IT Inside від GlobalLogic Education
Страх і сила помилок - IT Inside від GlobalLogic Education
 
GlobalLogic .NET Webinar #2 “Azure RBAC and Managed Identity”
GlobalLogic .NET Webinar #2 “Azure RBAC and Managed Identity”GlobalLogic .NET Webinar #2 “Azure RBAC and Managed Identity”
GlobalLogic .NET Webinar #2 “Azure RBAC and Managed Identity”
 
GlobalLogic QA Webinar “What does it take to become a Test Engineer”
GlobalLogic QA Webinar “What does it take to become a Test Engineer”GlobalLogic QA Webinar “What does it take to become a Test Engineer”
GlobalLogic QA Webinar “What does it take to become a Test Engineer”
 
“How to Secure Your Applications With a Keycloak?
“How to Secure Your Applications With a Keycloak?“How to Secure Your Applications With a Keycloak?
“How to Secure Your Applications With a Keycloak?
 
GlobalLogic Machine Learning Webinar “Advanced Statistical Methods for Linear...
GlobalLogic Machine Learning Webinar “Advanced Statistical Methods for Linear...GlobalLogic Machine Learning Webinar “Advanced Statistical Methods for Linear...
GlobalLogic Machine Learning Webinar “Advanced Statistical Methods for Linear...
 
GlobalLogic Machine Learning Webinar “Statistical learning of linear regressi...
GlobalLogic Machine Learning Webinar “Statistical learning of linear regressi...GlobalLogic Machine Learning Webinar “Statistical learning of linear regressi...
GlobalLogic Machine Learning Webinar “Statistical learning of linear regressi...
 
GlobalLogic C++ Webinar “The Minimum Knowledge to Become a C++ Developer”
GlobalLogic C++ Webinar “The Minimum Knowledge to Become a C++ Developer”GlobalLogic C++ Webinar “The Minimum Knowledge to Become a C++ Developer”
GlobalLogic C++ Webinar “The Minimum Knowledge to Become a C++ Developer”
 
Embedded Webinar #17 "Low-level Network Testing in Embedded Devices Development"
Embedded Webinar #17 "Low-level Network Testing in Embedded Devices Development"Embedded Webinar #17 "Low-level Network Testing in Embedded Devices Development"
Embedded Webinar #17 "Low-level Network Testing in Embedded Devices Development"
 
GlobalLogic Webinar "Introduction to Embedded QA"
GlobalLogic Webinar "Introduction to Embedded QA"GlobalLogic Webinar "Introduction to Embedded QA"
GlobalLogic Webinar "Introduction to Embedded QA"
 
C++ Webinar "Why Should You Learn C++ in 2021-22?"
C++ Webinar "Why Should You Learn C++ in 2021-22?"C++ Webinar "Why Should You Learn C++ in 2021-22?"
C++ Webinar "Why Should You Learn C++ in 2021-22?"
 
GlobalLogic Test Automation Live Testing Session “Android Behind UI — Testing...
GlobalLogic Test Automation Live Testing Session “Android Behind UI — Testing...GlobalLogic Test Automation Live Testing Session “Android Behind UI — Testing...
GlobalLogic Test Automation Live Testing Session “Android Behind UI — Testing...
 

Último

Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Christo Ananth
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
dollysharma2066
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Christo Ananth
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 

Último (20)

Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
NFPA 5000 2024 standard .
NFPA 5000 2024 standard                                  .NFPA 5000 2024 standard                                  .
NFPA 5000 2024 standard .
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 

Linux Kernel Platform Development: Challenges and Insights

  • 1. 1 Confidential Linux Kernel Platform Development: Challenges and Insights Sam Protsenko Software Engineer February 10, 2018
  • 2. 2 Confidential Agenda 1. Role Overview 2. War Stories and Learnings • Story #1: Board bring-up • Story #2: Migration to a new kernel • Story #3: Hardware fixing
  • 4. 4 Confidential Tasks • Board bring-up • Porting kernel (and bootloader) to a new board - Writing the BSP - Drivers development • Migrating to a new kernel version • Bug fixing • Boot time optimizations • Upstreaming • Sometimes: - Bootloader related work - Low-level work in rootfs (Android, OpenEmbedded, etc.) - Hardware debugging
  • 5. 5 Confidential Tasks Make board minimally functional, step by step, for all required components. Make sure it works. • Check power and reset lines • Check clock signals • Debug SoC issues (caches, etc.) • Configure pin muxes • Bring-up RAM (DDR), serial console (UART), peripheral (eMMC, USB, LCD, etc.) Board bring-up
  • 6. 6 Confidential Tasks Make kernel and bootloader fully functional on a new board. • Bootloader bring-up • Device Tree file • Configuration file • SoC support • Write missing peripheral drivers Porting kernel to a new board
  • 7. 7 Confidential Tasks Modify board related files to work in a new kernel version. • Sometimes company doesn’t want to upstream its kernel • Migration work: - board files -> device tree - new API for kernel frameworks - config options - sometimes back-porting is needed • Automated approach exists: see “Prequel” by Julia Lawall Migrating to a new kernel version
  • 8. 8 Confidential Components and Tools • Linux kernel • Bootloader (U-Boot, UEFI/edk2) • RootFS (Android, Debian, OpenEmbedded, BusyBox) • C language • OS principles • Microcontrollers basics (+schematics) • Linux user experience Components • Software - toolchain (ARM GCC): gcc, gdb, ld, as - binutils (add2line, strings, objdump, nm) - Git - Linux CLI tools - board specific and task specific tools (fastboot, dfu-util, omapconf, minicom, adb) • Hardware - JTAG - logical analyzer - oscilloscope - soldering iron Tools Knowledge
  • 10. 10 Confidential 10 Story #1: NOR flash support + XIP boot
  • 11. 11 Confidential Story #1: NOR flash support and XIP boot Task highlights: • Provide NOR flash chip support: - in kernel - in U-Boot • Provide XIP boot: - for U-Boot - for kernel
  • 12. 12 Confidential Overview: NOR flash • NOR flash is XIP capable (eXecution In Place) • XIP from NOR is often used for reducing the boot time • Can be useful in automotive and mobile areas • It’s possible to run U-Boot and kernel from NOR flash (Android or Linux rootfs is stored on eMMC) • Concerns: - drivers (GPMC, MTD, CFI, ELM) - Device Tree definition - timings - U-Boot/kernel configuration for XIP
  • 15. 15 Confidential Overview: NOR and NAND flash comparison Parameter NOR NAND Capacity Small (64 KB - 512 MB) Huge (16 MB - 1 TB) XIP (code execution) Yes No Block erase time Very slow (1 sec) Fast (500 μsec) Write time Slow (10 μsec / word) Fast (200 μsec / page) Read time Fast (100 nsec / word) Fast (50 μsec / page) Erase cycle range 10,000 to 100,000 1,000,000 with ECC Access method Random Sequential Price High (4x / MB) Very low (x / MB)
  • 17. 17 Confidential Sub-task 1: Timings ● GPMC controller must be programmed with correct timings ● Timings must be calculated from NOR chip characteristics ● There are a lot of them ● Usually board manufacturer should provide you with correct timings ● If NOR flash hangs - most likely timings are wrong
  • 18. 18 Confidential Sub-task 1: Timings • cs-on • cs-rd-off • cs-wr-off • oe-on • oe-off • we-on • we-off • rd-access And much more else timings... GPMC: Timings and parameters
  • 19. 19 Confidential Sub-task 1: Timings • CONFIG1 • CONFIG2 • CONFIG3 • CONFIG4 • CONFIG5 • CONFIG6 GPMC: Registers Register example:
  • 20. 20 Confidential Sub-task 1: Timings ● Conversion tool was developed: https://gitlab.com/joeskb7/gpmc-timings Usage: ./gpmc-timings -p CONFIG1..CONFIG6 ./gpmc-timings -y <file> -y file - yield registers values from file -p registers - parse and print registers values Conversion tool
  • 21. 21 Confidential Sub-task 1: Timings &gpmc { nor@0,0 { gpmc,cs-on-ns = <0>; gpmc,cs-rd-off-ns = <50>; gpmc,cs-wr-off-ns = <57>; gpmc,oe-on-ns = <0>; gpmc,oe-off-ns = <50>; ... }; }; Timings in Device Tree
  • 22. 22 Confidential Sub-task 2: Clocks and DPLLs ● GPMC clock must be enabled and be of correct frequency ● Check correct value (calculated for NOR timings) ● Check actual value (from kernel DebugFS) ● Fix clock if needed ● Clock derivation path can be seen from SoC TRM
  • 23. 23 Confidential Sub-task 2: Clocks and DPLLs GPMC_FCLK
  • 24. 24 Confidential Sub-task 2: Clocks and DPLLs L3MAIN1_L3_GICLK = L3_ICLK
  • 26. 26 Confidential Sub-task 2: Clocks and DPLLs CORE_X2_CLK
  • 27. 27 Confidential Sub-task 2: Clocks and DPLLs ● Enable CONFIG_COMMON_CLK_DEBUG ● Mount DebugFS (in example below, it’s mounted to /d) ● Print clocks frequencies: /d/clk/.../dpll_core_x2_ck/dpll_core_h12x2_ck # cat clk_rate 532000000 /d/clk/.../dpll_core_x2_ck/dpll_core_h12x2_ck/l3_iclk_div # cat clk_rate 532000000 But we see from TRM that L3_ICLK must be CORE_X2_CLK / 2 Check clock freq in DebugFS
  • 28. 28 Confidential Sub-task 2: Clocks and DPLLs l3_iclk_div: l3_iclk_div { #clock-cells = <0>; - compatible = "fixed-factor-clock"; + compatible = "ti,divider-clock"; + ti,max-div = <2>; }; Fix the clock
  • 29. 29 Confidential Sub-task 2: Clocks and DPLLs ● Print clocks frequencies: /d/clk/.../dpll_core_x2_ck/dpll_core_h12x2_ck # cat clk_rate 532000000 /d/clk/.../dpll_core_x2_ck/dpll_core_h12x2_ck/l3_iclk_div # cat clk_rate 266000000 So GPMC functional clock frequency now is 266 MHz, which is a desired frequency. Check clock freq in DebugFS after fix
  • 30. 30 Confidential Sub-task 3: Kernel support ● NOR flash and eMMC were sharing the lines (found from schematic) ● So there was only 512 KiB of NOR flash accessible in kernel ● Means no kernel XIP ● But we can still: ○ read/write NOR from kernel ○ do U-Boot XIP ● NOR support wasn’t ready in our kernel at the time (k3.8) ● But it was ready in mainline kernel (3.11)
  • 31. 31 Confidential Sub-task 3: Kernel support ● Patches often have dependencies ● It’s hard to find all actual dependencies between branches ● Kernel maintainers have dedicated trees/branches for features like GPMC ● Use smart cherry-picking Backporting patches
  • 32. 32 Confidential Sub-task 3: Kernel support Cherry-pick like a pro
  • 33. 33 Confidential Sub-task 3: Kernel support nor@0,0 { /* We can only access 512 KiB from kernel */ partition@0 { label = "boot"; /* u-boot.bin */ reg = <0x00000000 0x00060000>; /* 384 KiB */ }; partition@1 { label = "env"; /* U-Boot environment */ reg = <0x00060000 0x00020000>; /* 128 KiB */ }; }; NOR partitions
  • 34. 34 Confidential Sub-task 3: Kernel support # flash_erase /dev/mtd/mtd0 0 0 # cat mtd0-to.img >/dev/mtd/mtd0 # cat /dev/mtd/mtd0 >mtd0-from.img MTD utils and MTD char devices read/write
  • 35. 35 Confidential Sub-task 4: U-Boot XIP ● For XIP boot we don’t need MLO (U-Boot SPL), only u-boot.bin ● Boot sequence: ○ U-Boot is started by ROM code ○ U-Boot copies all files needed to RAM (dtb, kernel, ramdisk) ○ U-Boot switches to eMMC (e.g. via GPIO line) ○ U-Boot starts kernel from RAM; now we are not in XIP boot anymore ● Problem: U-Boot hangs when running XIP from NOR
  • 36. 36 Confidential Sub-task 4: U-Boot XIP ● U-Boot is too big to figure out why it’s not working ● We can’t even be sure XIP can work at all ● Let’s shrink U-Boot to minimal code and see if it works ● XIP “Hello world” baremetal firmware was implemented: ○ start assembler code (shrinked) ○ linker script (minimal: text/rodata/data/bss, all in SRAM) ○ BSS clear ○ enable UART clock + dependency clocks ○ pin muxes ○ naiive UART driver ○ print “Hello world” to UART (serial console) https://gitlab.com/joeskb7/dra7xx-hello Approach the problem
  • 37. 37 Confidential Sub-task 4: U-Boot XIP ● Minimal app worked, but U-Boot won’t work ● Now we know NOR flash + XIP is functional and there is some bug in U-Boot ● Use JTAG to investigate the issue Investigation
  • 39. 39 Confidential Sub-task 4: U-Boot XIP ● git bisect-ing helped to find the actual bug ● We were given modified U-Boot with code like this (in drivers/mmc/Makefile): CFLAGS := $(subst -Os, -O0, $(CFLAGS)) -fPIC Root cause (2)
  • 41. 41 Confidential Sub-task 4: U-Boot XIP ● So only MMC related files were built with -O0 -fPIC ● But other U-Boot files were build with -Os ● That led to NULL pointer dereference ● Removing that line fixed the problem Fix
  • 42. 42 Confidential Learnings: ● Always check mainline kernel and mailing lists for existing patch ● Git is your friend: ○ cherry-pick thoughtfully ○ bisect often helps to find the regression ● If some task is repeated often -- develop some tool or script ○ Share it if possible ● Isolating the problem helps to find the root cause ● JTAG is an ultimate tool for debugging
  • 44. 44 Confidential Story #2: Updating MAX732x driver Task highlights: • Update MAX732x driver to use Device Tree • Provide bindings documentation • Make it functional and bug-free • Upstream changes
  • 45. 45 Confidential Overview: Chip description • I2C I/O Expander • Often used in automotive • Have one-directional and bidirectional ports • Sends interrupt to SoC when input event occurred
  • 46. 46 Confidential Sub-task 1: Device tree support #ifdef CONFIG_OF static const struct of_device_id max732x_of_table[] = { ... { .compatible = "maxim,max7325" }, ... { } }; MODULE_DEVICE_TABLE(of, max732x_of_table); #endif OF Table
  • 47. 47 Confidential Sub-task 1: Device tree support static struct i2c_driver max732x_driver = { .driver = { .name = "max732x", .owner = THIS_MODULE, .of_match_table = of_match_ptr(max732x_of_table), }, ... } I2C driver struct
  • 48. 48 Confidential Sub-task 1: Device tree support Platform data doesn’t exist in case of OF provider. - chip->irq_base = pdata->irq_base; + if (pdata) + chip->irq_base = pdata->irq_base; Check pdata
  • 50. 50 Confidential Sub-task 2: Interrupt controller ● GPIO framework is capable of handling IRQ controller code for you ● Remove IRQ domain code / manual IRQ calculation and use gpiochip_* API config GPIO_MAX732X_IRQ select GPIOLIB_IRQCHIP #include <linux/gpio/driver.h> gpiochip_add() gpiochip_remove() gpiochip_irqchip_add() gpiochip_set_chained_irqchip() GPIOLIB_IRQCHIP
  • 51. 51 Confidential Sub-task 3: DT definition and bindings ● We want to I2C address of MAX7325 to be 0x5d ● As per datasheet: Pin Line ---------- AD2 V+ AD0 V+ Check I2C address on schematics
  • 52. 52 Confidential Sub-task 3: DT definition and bindings &i2c0 { expander: max7325@5d { compatible = "maxim,max7325"; reg = <0x5d>; gpio-controller; #gpio-cells = <2>; }; }; DT Definition: disabled interrupts
  • 53. 53 Confidential Sub-task 3: DT definition and bindings &i2c0 { expander: max7325@5d { compatible = "maxim,max7325"; reg = <0x5d>; gpio-controller; #gpio-cells = <2>; interrupt-controller; #interrupt-cells = <2>; interrupt-parent = <&gpio4>; interrupts = <29 IRQ_TYPE_EDGE_FALLING>; }; }; DT Definition: enabled interrupts
  • 54. 54 Confidential Sub-task 4: Upstreaming $ git log --author="Protsenko" --oneline | grep max732 606f13e9efa0 gpio: max732x: Fix irq-events handler 68689dbf35e1 gpio: max732x: Add IRQF_SHARED to irq flags 67ddd32bfc9f gpio: max732x: Propagate wake-up setting to parent irq controller 996bd13f28e6 gpio: max732x: Add DT binding documentation 09afa276d52e gpio: max732x: Fix possible deadlock 479f8a5744d8 gpio: max732x: Rewrite IRQ code to use irq_domain API 43c4bcf9425e gpio: max732x: Add device tree support $ git log -- drivers/gpio/gpio-max732x.c Patches in upstream
  • 57. 57 Confidential Learnings: ● If in doubt -- check schematics ● Check out existing code in kernel for examples ● Check if there is existing framework for that problem ● Take responsibility (technical debt) ● Ask your customer about upstreaming
  • 60. 60 Confidential Story #3: Flashing EEPROM Task highlights: • EEPROM chip wasn’t flashed with Board ID • It led to 2 issues: - U-Boot was unable to find correct DTB file - "board_rev" variable were missing in U-Boot environment • Fix: - Disable “Read only” mode for EEPROM chip - Figure out how to work with it - Write correct Board ID value to EEPROM - Set back “Read only” mode
  • 61. 61 Confidential Sub-task 1: Disable write protection Schematic
  • 62. 62 Confidential Sub-task 1: Disable write protection First glance at PCB
  • 63. 63 Confidential Sub-task 1: Disable write protection Disabling write protection
  • 64. 64 Confidential Sub-task 2: Writing to EEPROM static void setup_board_eeprom_env(void) { printf("### Writing EEPROM...n"); rc = ti_write_eeprom(CONFIG_EEPROM_BUS_ADDRESS, CONFIG_EEPROM_CHIP_ADDRESS); if (rc) printf("### Error: Unable to write EEPROMn"); else printf("### Writing EEPROM: Success!n"); } U-Boot code (1)
  • 65. 65 Confidential Sub-task 2: Writing to EEPROM static int ti_i2c_write_eeprom(int bus_addr, int dev_addr, u32 size, uint8_t *ep, unsigned int mem_addr) { /* Memory address size is 2 bytes */ return i2c_write(dev_addr, mem_addr, 2, ep, size); } U-Boot code (2)
  • 66. 66 Confidential Sub-task 2: Writing to EEPROM int ti_write_eeprom(int bus_addr, int dev_addr) { const char *name = "AM572PM_"; const char *rev = "A.20"; const char *serial = "07164P550148"; const char *config = ""; struct ti_am_eeprom am_ep; uint8_t page[64]; int i, j; int rc; U-Boot code (3)
  • 67. 67 Confidential Sub-task 2: Writing to EEPROM /* Prepare structure for EEPROM */ memset(&am_ep, 0, sizeof(am_ep)); am_ep.header = TI_EEPROM_HEADER_MAGIC; strncpy(am_ep.name, name, TI_EEPROM_HDR_NAME_LEN); strncpy(am_ep.version, rev, TI_EEPROM_HDR_REV_LEN); strncpy(am_ep.serial, serial, TI_EEPROM_HDR_SERIAL_LEN); strncpy(am_ep.config, config, TI_EEPROM_HDR_CONFIG_LEN); for (i = 0; i < TI_EEPROM_HDR_NO_OF_MAC_ADDR; ++i) for (j = 0; j < TI_EEPROM_HDR_ETH_ALEN; ++j) am_ep.mac_addr[i][j] = 0xff; U-Boot code (4)
  • 68. 68 Confidential Sub-task 2: Writing to EEPROM /* Init I2C */ gpi2c_init(); rc = ti_i2c_eeprom_init(bus_addr, dev_addr); if (rc) return rc; U-Boot code (5)
  • 69. 69 Confidential Sub-task 2: Writing to EEPROM /* Write 1st page */ memset(page, 0, 64); memcpy(page, (uint8_t *)&am_ep, 64); rc = ti_i2c_write_eeprom(bus_addr, dev_addr, 64, page, 0x00); mdelay(100); /* t_WR = 5 msec */ if (rc) return rc; U-Boot code (6)
  • 70. 70 Confidential Sub-task 2: Writing to EEPROM /* Write 2nd page */ memset(page, 0, 64); memcpy(page, ((uint8_t *)&am_ep) + 64, 14); rc = ti_i2c_write_eeprom(bus_addr, dev_addr, 64, page, 0x40); mdelay(100); /* t_WR = 5 msec */ if (rc) return rc; return 0; } U-Boot code (7)
  • 72. 72 Confidential Thank you Sam Protsenko Software Engineer semen.protsenko@globallogic.com
  • 73. 73 Confidential Abbreviations: ● BSP - Board Support Package ● CFI - Common Flash Interface ● DPLL - Digital Phase-Locked Loop ● DTB - Device Tree Binary ● EEPROM - Electrically Erasable Programmable Read-Only Memory ● eMMC - Embedded MultiMedia Card ● FIT - Flattened Image Tree ● GIC - Generic Interrupt Controller ● GPIO - General Purpose Input Output ● GPMC - General Purpose Memory Controller ● INTC - Interrupt Controller ● MTD - Memory Technology Device ● NOR - Not Or ● SoC - System On Chip ● TRM - Technical Reference Manual ● XIP - eXecute In Place