What´s the best Practice to Build own Kernel

Hello,

The Kernel 4.14, if i see right, will Support BPI-R2. What´s the best Practice to Build this Kernel and install it to the BPI-R2 ?

If there any Manual / Howto for this ?

Thanks a lot, René

there is a github-repository (currently 4.4.70), you can look there how to build images or building u-boot:

HTH Frank

Frank… “…the best Practice to Build this Kernel…” is the question

I had understand the question :slight_smile: …he can use e.g. the defconfig to have drivers set in kernel 4.14. maybe he needs uboot to… i have not said,that he must use githib-repo to build 4.4.70 only to look how it’s built (which modules,drivers,options). i don’t know if it is the “best” way, but maybe it helps to build the newer kernel. I’m also interested to have a newer kernel (try to backport mt76-driver to that kernel…having 4.14 running that will also be easier)

Assuming one’s choice is a Debian Kernel, there is quite a bit available in publications, free online publications…Finding an ARM specific document is more challenging. One really needs to comprehend the specifics of Allwinner architecture.

One has to download an appropriate toolchain. AND Sunni-Xi seems to provide their additional cross-compile support only for a 64-bit LinuxOS, including DasBoot.

One must use a default .config file or become savy with roughly 1000 line items that may be included or excluded.

If you have a Linux User Group near you, perhaps a mentor might be wise.

“Best” is highly subjective parameter.

Are you wanting the bleeding edge kernel for a good reason, a specific need, or merely bragging rights?

If you are trying to get past waiting for Sunni-Xi to provide architecture specific code, the lastest Kernel may not resolve anything.

Sunni-Xi is likely your best, final, and maybe, only good code resource for building a Linux Kernel for Allwinner. You likely can use an older DasBoot image that is specific to your board.

Lots of tutorials exist in general for building a Linux Kernel.

Most interesting seems the question: what must be changed in current stable kernel (4.13 supports main chipset mt7623)? i’m imported banana pi r2 config to 4.13 kernel (using defaults for unknown options) currently try to compile using ARCH=arm CROSS-COMPILE=arm-linux-gnueabihf-

Sorry Georg, but that was not MY question

@garywang can you answer my question? Maybe with newer kernel we have lesser problems including newer device-drivers

i’ve tried now to build the 4.14-rc5 using that commands:

sudo apt-get install git make gcc-arm-linux-gnueabihf u-boot-tools
git clone https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git bpi-r2
cd bpi-r2
cp path/to/mt7623n_evb_bpi_defconfig arch/arm/configs/ 
make ARCH=arm mt7623n_evb_bpi_defconfig
export CROSS_COMPILE=arm-linux-gnueabihf-
export ARCH=arm
export INSTALL_MOD_PATH=$(pwd)/mod/
mkdir $INSTALL_MOD_PATH
make
make uImage LOADADDR=0x80008000
make modules_install

copied kernel and modules on SD-Card, boot hangs at loading kernel:

reading bananapi/bpi-r2/linux/uEnv.txt
771 bytes read in 9 ms (83 KiB/s)
Loaded environment from uEnv.txt
Banana Pi bpi-r2 chip: mt7623n Service: linux
reading bananapi/bpi-r2/linux/uImage
8188984 bytes read in 1071 ms (7.3 MiB/s)
reading bananapi/berryboot.img
** Unable to read file bananapi/berryboot.img **
bootm flag=0, states=70f
## Booting kernel from Legacy Image at 84000000 ...
   Image Name:   Linux-4.14.0-rc5-BPI-R2-Kernel
   Image Type:   ARM Linux Kernel Image (uncompressed)
   Data Size:    8188920 Bytes = 7.8 MiB
   Load Address: 80008000
   Entry Point:  80008000
   Verifying Checksum ... OK
   Loading Kernel Image ... OK

Starting kernel ...

then it stops…any idea? I assume there is a Problem with the DTB, which should be compiled in the kernel, but how can i check this? I’ve tried using that from BPI-R2-github but filename differ resulting in build-error, renamed it, but seems not compatible:

 DTC     arch/arm/boot/dts/mt7623n-bananapi-bpi-r2.dtb
 Error: arch/arm/boot/dts/mt7623.dtsi:376.25-26 syntax error
 FATAL ERROR: Unable to parse input tree

line 376 of that file (from BPI-R2 github) is:

clocks = <&apmixedsys CLK_APMIXED_HDMI_REF>;

seems CLK_APMIXED_HDMI_REF is undefined…in BPI-R2-bsp it is defined here:

linux-mt/arch/arm/boot/dts/include/dt-bindings/clock/mt2701-clk.h:196:#define CLK_APMIXED_HDMI_REF            14

maybe its not the only one…but how can i check if dts is correctly appended?

got kernel booting using the original dts(i) by creating the uImage this way:

cat arch/arm/boot/zImage arch/arm/boot/dts/mt7623n-bananapi-bpi-r2.dtb >zImage_dtb
mkimage -A arm -O linux -C none -T kernel -a 0x80008000 -e 0x80008000 -d zImage_dtb uImage

now kernel boots, but hangs at waiting for mmcblk1

boot.log (32,8 KB)

it seems that devicetree is not correct for the mmc-devices (and some other):

[    4.568999] mtk-msdc 11230000.mmc: could not find pctldev for node /pinctrl@10005000/mmc0default, deferring probe
[    4.579244] mtk-msdc 11240000.mmc: could not find pctldev for node /pinctrl@10005000/mmc1default, deferring probe

comparing the relevant parts:

$ diff -y bpi.dtsi kernel.dtsi 
    pio: pinctrl@10005000 {                        pio: pinctrl@10005000 {
        compatible = "mediatek,mt7623-pinctrl";          |            compatible = "mediatek,mt7623-pinctrl",
                                  >                     "mediatek,mt2701-pinctrl";
        reg = <0 0x1000b000 0 0x1000>;                    reg = <0 0x1000b000 0 0x1000>;
        mediatek,pctl-regmap = <&syscfg_pctl_a>;            mediatek,pctl-regmap = <&syscfg_pctl_a>;
        pins-are-numbered;                        pins-are-numbered;
        gpio-controller;                        gpio-controller;
        #gpio-cells = <2>;                        #gpio-cells = <2>;
        interrupt-controller;                        interrupt-controller;
        interrupt-parent = <&gic>;                    interrupt-parent = <&gic>;
        #interrupt-cells = <2>;                        #interrupt-cells = <2>;
        interrupts = <GIC_SPI 113 IRQ_TYPE_LEVEL_HIGH            interrupts = <GIC_SPI 113 IRQ_TYPE_LEVEL_HIGH
                 <GIC_SPI 114 IRQ_TYPE_LEVEL_HIGH                     <GIC_SPI 114 IRQ_TYPE_LEVEL_HIGH
                                  <
        hdmi_pin: htplg {                  <
            pins1 {                      <
                pinmux = <MT7623_PIN_123_HTPL <
                input-enable;              <
                bias-pull-down;              <
            };                      <
        };                          <
    };                                };

    syscfg_pctl_a: syscfg@10005000 {                syscfg_pctl_a: syscfg@10005000 {
        compatible = "mediatek,mt7623-pctl-a-syscfg",            compatible = "mediatek,mt7623-pctl-a-syscfg",
        reg = <0 0x10005000 0 0x1000>;                    reg = <0 0x10005000 0 0x1000>;
    };                                };

    mmc0: mmc@11230000 {                        mmc0: mmc@11230000 {
        compatible = "mediatek,mt2701-mmc";          |            compatible = "mediatek,mt7623-mmc",
                                  >                     "mediatek,mt8135-mmc";
        reg = <0 0x11230000 0 0x1000>;                    reg = <0 0x11230000 0 0x1000>;
        interrupts = <GIC_SPI 39 IRQ_TYPE_LEVEL_LOW>;            interrupts = <GIC_SPI 39 IRQ_TYPE_LEVEL_LOW>;
        clocks = <&pericfg CLK_PERI_MSDC30_0>,                clocks = <&pericfg CLK_PERI_MSDC30_0>,
             <&topckgen CLK_PERI_MSDC50_3>;          |                 <&topckgen CLK_TOP_MSDC30_0_SEL>;
        clock-names = "source", "hclk";                    clock-names = "source", "hclk";
        status = "disabled";                        status = "disabled";
    };                                };

    mmc1: mmc@11240000 {                        mmc1: mmc@11240000 {
        compatible = "mediatek,mt2701-mmc";          |            compatible = "mediatek,mt7623-mmc",
                                  >                     "mediatek,mt8135-mmc";
        reg = <0 0x11240000 0 0x1000>;                    reg = <0 0x11240000 0 0x1000>;
        interrupts = <GIC_SPI 40 IRQ_TYPE_LEVEL_LOW>;            interrupts = <GIC_SPI 40 IRQ_TYPE_LEVEL_LOW>;
        clocks = <&pericfg CLK_PERI_MSDC30_1>,                clocks = <&pericfg CLK_PERI_MSDC30_1>,
             <&clk_null>;                  |                 <&topckgen CLK_TOP_MSDC30_1_SEL>;
        clock-names = "source", "hclk";                    clock-names = "source", "hclk";
        status = "disabled";                        status = "disabled";
    };                                };

tried to change the compatible-line, but seems not working, i don’t know where mt2701-mmc is defined. definition in bananapi.dts is the block of mmc0/1 swapped, but definitions seems equal

any idea?

Thanks Frank for testing :slight_smile:

@BPI Team … can any one talk to Mediatek to fix that in the Kernel ? :slight_smile: Please

Seems @Ryder.Lee does some recent patches ( https://www.spinics.net/lists/kernel/msg2609858.html )

the address of pio is different from github, in the patch seems wrong but i’ve found only patches for the dtsi…i think there must be patches for relevant c-files

for mmc it seems to be here:

./drivers/mmc/host/mtk-sd.c:1864:    {   .compatible = "mediatek,mt8135-mmc", },

in bpi-kernel 4.4.70 there is a second param which links to a struct:

./drivers/mmc/host/mtk-sd.c:449:    { .compatible = "mediatek,mt2701-mmc", .data =     &mt2701_compat},
static const struct mt81xx_mmc_compatible mt2701_compat = {
    .clk_div_bits = 12,
    .pad_tune0 = true,
    .async_fifo = true,
    .data_tune = true,
    .busy_check = false,
    .stop_clk_fix = false,
    .enhance_rx = false,
};
struct mt81xx_mmc_compatible {
    u8 clk_div_bits;
    bool pad_tune0;
    bool async_fifo;
    bool data_tune;
    bool busy_check;
    bool stop_clk_fix;
    bool enhance_rx;
};

i tried to add these too, but compiling failes if i use mt2701-mmc compatible line in dtsi

  DTC     arch/arm/boot/dts/mt7623n-rfb-nand.dtb
Error: arch/arm/boot/dts/mt7623.dtsi:643.3-4 syntax error
FATAL ERROR: Unable to parse input tree

i don’t know how mt7623n-rfb-nand is involved…

but i assume thats not the mmc wrong, it seems a lower layer because other modules (i2c,spi) give the same error like here

./drivers/pinctrl/mediatek/pinctrl-mt2701.c:568:    { .compatible = "mediatek,mt7623-pinctrl", },

Maybe he can help

1 Like

I can build pass and do not see any error on my BPI R2. You just need to build mt7623.dtsi and mt7623n-bananapi-bpi-rs.dts for R2 .

I have tried the official repo (don’t know your patches are included) => build ok but above error.

Tried to add infos from 4.4.70 resulting in build-errors.

Have you changed dts(i) only or also c/h-files? can you send a full patch/related files to current 14.4-rc?

Or have i made a error during build (wrong appending of dtb)?

Some parts of my makefile

DEFCONFIG := mt7623n_evb_defconfig DTBS_NAME := mt7623n-bananapi-bpi-r2.dtb

all: $(OUT)/arch/$(ARCH)/boot/$(image_name) cat $(boot_dir)/zImage $(boot_dir)/dts/$(DTBS_NAME) > $(boot_dir)/zImage-dtb $(mkimage) -A arm -O linux -T kernel -C none -a 80008000 -e 80008000 -n “Linux Kernel Image” -d $(boot_dir)/zImage-dtb $(OUT)/uImage_$(KERN_VER)$(DTBS_NAME) cp $(OUT)/uImage$(KERN_VER)$(DTBS_NAME) ~/uImage$(KERN_VER)_$(DTBS_NAME)

DEFCONFIG: mt7623n_evb_defconfig (4.9 KB)

updated+resetted kernel-repo (git stash + git pull) and tried to merge your Makefile-part into mine (default for kernel) replacing “all: vmlinux” with “all: your_data” not working (missing separator) so tried manually:

frank@Frank-Laptop:~/kernel_4.14/linux$ make ../mt7623n_evb_defconfig
frank@Frank-Laptop:~/kernel_4.14/linux$ make
frank@Frank-Laptop:~/kernel_4.14/linux$ cat arch/arm/boot/zImage arch/arm/boot/dts/mt7623n-bananapi-bpi-r2.dtb > arch/arm/boot/zImage-dtb
frank@Frank-Laptop:~/kernel_4.14/linux$ mkimage -A arm -O linux -T kernel -C none -a 80008000 -e 80008000 -n "Linux Kernel Image" -d  arch/arm/boot/zImage-dtb ./uImage_4.14-mt7623n-bananapi-bpi-r2.dtb
frank@Frank-Laptop:~/kernel_4.14/linux$ export INSTALL_MOD_PATH=~/kernel_4.14/mod/
frank@Frank-Laptop:~/kernel_4.14/linux$ make modules_install
frank@Frank-Laptop:~/kernel_4.14/linux$ sudo cp -r ../mod/lib/modules/4.14.0-rc5-BPI-R2-Kernel-00031-g73d3393-dirty /media/frank/BPI-ROOT/lib/modules/
frank@Frank-Laptop:~/kernel_4.14/linux$ cp uImage_4.14-mt7623n-bananapi-bpi-r2.dtb /media/frank/BPI-BOOT/bananapi/bpi-r2/linux/uImage

kernel boots, but same errors (try to copy only relevant parts from bootlog)

[    0.000000] Booting Linux on physical CPU 0x0                                                                                                                               
[    0.000000] Linux version 4.14.0-rc5-BPI-R2-Kernel-00031-g73d3393-dirty (frank@Frank-Laptop) (gcc version 4.8.4 (Ubuntu/Linaro 4.8.4-2ubuntu1~14.04.1)) #5 SMP Thu Oct 19 10
:41:19 CEST 2017
[    0.000000] CPU: ARMv7 Processor [410fc073] revision 3 (ARMv7), cr=10c5387d                                                                                                 
[    0.000000] CPU: div instructions available: patching division code                                                                                                         
[    0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache                                                                                        
[    0.000000] OF: fdt: Machine model: Bananapi BPI-R2                                                                                                                         

...
[    0.000000] Kernel command line: board=bpi-r2 console=earlyprintk console=tty1 fbcon=map:0 console=ttyS0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait service=linux v
malloc=496M debug=7 initcall_debug=0                                                                                                                                           

...
[    0.410257] xor: using function: arm4regs (1399.600 MB/sec)                                                                                                                 
[    0.410357] pinctrl core: initialized pinctrl subsystem                                                                                                                     
[    0.411206] NET: Registered protocol family 16                                                                                                                              

...
[    3.329746] mtk-pwm 11006000.pwm: could not find pctldev for node /pinctrl@10005000/pwm@0, deferring probe                                                                  

...
[    4.276287] mtk-spi 1100a000.spi: could not find pctldev for node /pinctrl@10005000/spi@0, deferring probe                                                                  

...
[    4.485823] i2c-mt65xx 11007000.i2c: could not find pctldev for node /pinctrl@10005000/i2c@0, deferring probe                                                               
[    4.495729] i2c-mt65xx 11008000.i2c: could not find pctldev for node /pinctrl@10005000/i2c@1, deferring probe                                                               
[
...
[    4.570738] mtk-msdc 11230000.mmc: could not find pctldev for node /pinctrl@10005000/mmc0default, deferring probe                                                           
[    4.580980] mtk-msdc 11240000.mmc: could not find pctldev for node /pinctrl@10005000/mmc1default, deferring probe                                                           

...
[    4.672179] mtk-pwm 11006000.pwm: could not find pctldev for node /pinctrl@10005000/pwm@0, deferring probe                                                                  
[    4.682271] mtk-spi 1100a000.spi: could not find pctldev for node /pinctrl@10005000/spi@0, deferring probe                                                                  
[    4.692487] xhci-mtk 1a1c0000.usb: 1a1c0000.usb supply vbus not found, using dummy regulator                                                                                
[    4.700967] xhci-mtk 1a1c0000.usb: fail to get vusb33                                                                                                                       
[    4.706548] xhci-mtk 1a240000.usb: 1a240000.usb supply vbus not found, using dummy regulator                                                                                
[    4.714988] xhci-mtk 1a240000.usb: fail to get vusb33                                                                                                                       
[    4.720278] i2c-mt65xx 11007000.i2c: could not find pctldev for node /pinctrl@10005000/i2c@0, deferring probe                                                               
[    4.730285] i2c-mt65xx 11008000.i2c: could not find pctldev for node /pinctrl@10005000/i2c@1, deferring probe                                                               
[    4.740278] mtk-msdc 11230000.mmc: could not find pctldev for node /pinctrl@10005000/mmc0default, deferring probe                                                           
[    4.750611] mtk-msdc 11240000.mmc: could not find pctldev for node /pinctrl@10005000/mmc1default, deferring probe                                                           
[    4.761692] ALSA device list:                                                                                                                                               
[    4.764647]   No soundcards found.                                                                                                                                          
[    4.768577] md: Waiting for all devices to be available before autodetect                                                                                                   
[    4.775322] md: If you don't use raid, use raid=noautodetect                                                                                                                
[    4.781646] md: Autodetecting RAID arrays.                                                                                                                                  
[    4.785747] md: autorun ...                                                                                                                                                 
[    4.788519] md: ... autorun DONE.                                                                                                                                           
[    4.792021] Waiting for root device /dev/mmcblk0p2...                                                                                                                       

boot4.14.log (55,8 KB)

have you changes in your tree, that are not public yet?

That was odd. but I tried 4.14-rc1 …

v14.4.txt (11.2 KB)

git reset --hard v4.14-rc1
HEAD is now at 2bd6bf0 Linux 4.14-rc1
make clean
cp ../mt7623n_evb_defconfig arch/arm/configs/

make mt7623n_evb_defconfig
  HOSTCC  usr/gen_init_cpio
  ./scripts/gen_initramfs_list.sh: Cannot open '../prebuilt/bootable/7623_loader/rootfs_ttys0_rng.cpio.gz'

also tried with rc2 and “git pull” after git reset…also if i revert to rc5

ok, followed Instructions here: https://github.com/phjanderson/marvin/wiki/Fix-'Cannot-open-initramfs'-error-while-building-kernel to reset the initramfs-option

now compiling rc1 with your config

It appeared to you got stuck in pin control problems. Mt7623 doesn’t have its own pinctrl driver and instead it has to use mt2701 pinctrl ones. Could you confirm with this ?

rc1 resulting in a kernel panic :frowning:

[    1.768179] Hardware name: Mediatek Cortex-A7 (Device Tree)                                                                                                                 
[    1.773710] [<c0113048>] (unwind_backtrace) from [<c010d5b4>] (show_stack+0x20/0x24)                                                                                        
[    1.781394] [<c010d5b4>] (show_stack) from [<c070a300>] (dump_stack+0x9c/0xb0)                                                                                              
[    1.788561] [<c070a300>] (dump_stack) from [<c0110ebc>] (handle_IPI+0x1d0/0x348)                                                                                            
[    1.795899] [<c0110ebc>] (handle_IPI) from [<c010144c>] (gic_handle_irq+0x9c/0xa0)                                                                                          
[    1.803409] [<c010144c>] (gic_handle_irq) from [<c010e1cc>] (__irq_svc+0x6c/0x90)                                                                                           
[    1.810828] Exception stack(0xc0c01ee8 to 0xc0c01f30)                                                                                                                       
[    1.815837] 1ee0:                   00000000 0000166c c0c01f48 c011ef40 c0c00000 c0c03cc4                                                                                   
[    1.823950] 1f00: c0c03c68 c0c77bbf 00000001 c0c8b280 c0b59a28 c0c01f44 c0c01f48 c0c01f38                                                                                   
[    1.832059] 1f20: c01096fc c0109700 60000013 ffffffff                                                                                                                       
[    1.837072] [<c010e1cc>] (__irq_svc) from [<c0109700>] (arch_cpu_idle+0x48/0x4c)                                                                                            
[    1.844411] [<c0109700>] (arch_cpu_idle) from [<c0724524>] (default_idle_call+0x30/0x3c)                                                                                    
[    1.852439] [<c0724524>] (default_idle_call) from [<c0164dcc>] (do_idle+0xd0/0x144)                                                                                         
[    1.860037] [<c0164dcc>] (do_idle) from [<c01650dc>] (cpu_startup_entry+0x28/0x2c)                                                                                          
[    1.867549] [<c01650dc>] (cpu_startup_entry) from [<c071ed10>] (rest_init+0xc0/0xc4)                                                                                        
[    1.875233] [<c071ed10>] (rest_init) from [<c0b00e24>] (start_kernel+0x3bc/0x3c8)                                                                                           
[    1.882658] [<c0b00e24>] (start_kernel) from [<8000807c>] (0x8000807c)                                                                                                      
[    1.889138] ---[ end Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)