明日にはでっかい太陽が昇るかもしれません。

「覚悟」とは!! 暗闇の荒野に!!進むべき道を切り開く事だッ!

Java の synchronized ブロックのようなことを C で実現する

職業柄、組込みをやっているので、 C で排他制御を行う機会は多い。

でも、毎回 ***_lock, ***_unlock で囲むのも面倒だし、解放漏れなどによるデッドロックとかわかりにくい割に初歩的なバグに悩まされることも多く、 Java の synchronized ブロックが羨ましいなーと思っていた。 (レビューで対応を見るのも面倒ってのが最近は多い)

そこで、以前は以下のようなマクロを作って、擬似的な synchronized ブロックを構築していたけど、不満な点もいくつかあった。

/* 擬似 synchronized ブロック */
#define SYNCHRONIZED1(obj, ...)                                            \
    do {                                                                   \
        pthread_mutex_lock(obj);                                           \
        pthread_cleanup_push((void (*)(void *))pthread_mutex_unlock, obj); \
        __VA_ARGS__;                                                       \
        pthread_mutex_unlock(obj);                                         \
        pthread_cleanup_pop(0);                                            \
    } while(0)

/* 使用方法 */
void *old_type(void *arg)
{
    for (int i; i < 5000; ++i) {
        SYNCHRONIZED1(&mutex, {
            counter++;
        });
    }
    return NULL;
}

動作上は問題ないけど、以下のような点が不満だった。

  1. 全体がワンライナーになるため、 __LINE__ マクロが期待する通りにならない。 (デバッグ時に困る。。)
  2. () の中に {} が入るのは C の規格上無いため、エディタのハイライトが期待通りにならない。 (vim は構文エラー扱いにする)
  3. 見た目が C っぽくない。

最近、ユニットテストフレームワーク Catch2 のコードを見ていて「できるかも!?」と思って試してみたのが以下のコード。

#define CAT_I(a, b) a ## b
#define CAT(a, b) CAT_I(a, b)
 
/* 擬似 synchronized ブロック */
#define synchronized2(obj)                                \
    void CAT(__caller__, __LINE__)(void (*fn)(void)) {    \
        pthread_mutex_lock(obj);                          \
        fn();                                             \
        pthread_mutex_unlock(obj);                        \
    }                                                     \
    auto void CAT(__callee__, __LINE__)(void);            \
    CAT(__caller__, __LINE__)(CAT(__callee__, __LINE__)); \
    void CAT(__callee__, __LINE__)(void)

/* 使用方法 */
void *new_type(void *arg)
{
    for (int i; i < 5000; ++i) {
        synchronized2(&mutex) {
            counter++;
        }                                                                                                                                                              
    }
    return NULL;
}

旧式の問題点はすべて解決され、かつ、ブロックは関数として実行されるため、 pthread_cleanup_push を使用しなくても排他の解放漏れが発生しなくなった。

nested function を使用しているため、 gcc 専用になるが、 scan-buildoclint を行う際は空にすればロジックに影響を与えずに排除することもできる。

というわけで動作確認。

上で使用方法として示した関数を 4 スレッド起動して排他が効いているか確認する。

# synchronized ブロック未使用
$ make test
gcc -MMD -MP -Wall -Werror  -c -o sync.o sync.c
gcc  -o synchronized sync.o -lpthread
./synchronized
counter: 14977

# synchronized ブロック使用 (synchronized2)
$ make test
gcc -MMD -MP -Wall -Werror  -c -o sync.o sync.c
gcc  -o synchronized sync.o -lpthread
./synchronized
counter: 20000

未使用時は排他を行っていないため期待通りインクリメントできておらず、使用時は正しくインクリメントできることを確認した。

これまで旧式で書いていたコードをすべて新しくしよう!

以下、テストコードの全文。

#include <stdio.h>
#include <unistd.h>
#include <pthread.h>

#define SYNCHRONIZED1(obj, ...)                                            \
    do {                                                                   \
        pthread_mutex_lock(obj);                                           \
        pthread_cleanup_push((void (*)(void *))pthread_mutex_unlock, obj); \
        __VA_ARGS__;                                                       \
        pthread_mutex_unlock(obj);                                         \
        pthread_cleanup_pop(0);                                            \
    } while(0)

#define CAT_I(a, b) a ## b
#define CAT(a, b) CAT_I(a, b)

#define synchronized2(obj)                                \
    void CAT(__caller__, __LINE__)(void (*fn)(void)) {    \
        pthread_mutex_lock(obj);                          \
        fn();                                             \
        pthread_mutex_unlock(obj);                        \
    }                                                     \
    auto void CAT(__callee__, __LINE__)(void);            \
    CAT(__caller__, __LINE__)(CAT(__callee__, __LINE__)); \
    void CAT(__callee__, __LINE__)(void)

static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
static unsigned long counter = 0;

void *old_type(void *arg)
{
    /* 開始タイミングを合わせる */
    pthread_mutex_lock(&mutex);
    pthread_cond_wait(&cond, &mutex);
    pthread_mutex_unlock(&mutex);                                                                                                                                  [0/5190]

    for (int i; i < 5000; ++i) {
        SYNCHRONIZED1(&mutex, {
            counter++;
        });
    }
    return NULL;
}

void *new_type(void *arg)
{
    /* 開始タイミングを合わせる */
    pthread_mutex_lock(&mutex);
    pthread_cond_wait(&cond, &mutex);
    pthread_mutex_unlock(&mutex);

    for (int i; i < 5000; ++i) {
        synchronized2(&mutex) {
            counter++;
        }
    }
    return NULL;
}

int main(int argc, char **argv)
{
    pthread_t thrd_ids[4];

    for (int i = 0; i < 2; ++i) {
        pthread_create(&thrd_ids[i], NULL, old_type, NULL);
    }
    for (int i = 2; i < 4; ++i) {
        pthread_create(&thrd_ids[i], NULL, new_type, NULL);
    }
    sleep(1);
    pthread_cond_broadcast(&cond);

    for (int i = 0; i < 4; ++i) {
        pthread_join(thrd_ids[i], NULL);
    }
    printf("counter: %ld\n", counter);

    return 0;
}

clang と gcc の両方でラムダ式のようなことをする

Web アプリ開発の方は、牛歩ながら janus-webrtc-gateway のデモ画面を Django+Vue.js with Bootstrap に移植していっている。

echotest, videocall, audiobridge となんとか動作するものが移植できたが、 videoroom での複数リモートフィードをシンプルに扱うにはどうしたものか、と考えているところで手が止まっている。。

それはさておき、仕事で gcc 拡張の nested function を使用していたところ、 clang static analyzer でエラーになる問題があったので、とりあえずの回避策をメモしておく。

#if !defined(__clang__)                               
#define LAMBDA(ret_type, ...)       \                    
    __extension__                   \                    
    ({                              \                    
        ret_type __fn__ __VA_ARGS__ \                    
        __fn__;                     \                    
    })                                                
typedef int (*CALLBACK)(int);                         
#else                                                 
#define LAMBDA(ret_type, ...) \                       
    ^ret_type __VA_ARGS__                             
typedef int (^CALLBACK)(int);                         
#endif                                                
                                                      
void dummy(CALLBACK cb, int arg)                      
{                                                     
    printf("%d", cb(arg));                             
}                                                     
                                                      
int main(int argc, char **argv)
{
    dummy(LAMBDA(int, (int arg) { return arg; }), 999);
    dummy(LAMBDA(int, (int arg) { return arg; }), -1);                                                                                                                                
                                                      
    return 0;                                   
}

仕掛けは、 gcc では nested function で実現しているところを、 clang では Apple 拡張の blocks で置き換えている。

ただ、 blocks は関数ではないので関数ポインタを渡せないし、あくまでも今回のコードに対する回避策としての意味しかない。 (そして、コンパイルフラグに -fblocks が必要になり、 libBlocksRuntime in libblocksruntime-dev をリンクする必要がでる。)

簡単なコールバック程度はラムダ式が使いたいけど、ラムダ式と定義済み関数ポインタを渡す処理が混在すると clang static analyer が使用できなくなる。。。

将来的にでも、 C 言語の標準仕様でなんとか解決できないかなー。

Web アプリをつくろう

ついこの間まで Qemu でブートまわりを見ていたが、それが終わったら、と思っていたのが Web アプリ作成だ。

いきなり上層まで吹っ飛んだが、興味がある分野を順に並べたらこうなってしまった。

とりあえず目標がないと手が進まないので、 Janus WebRTC Gateway のフロントエンドを作ることにする。

理由は、仕事で使っている Web サービスで唯一デモ機能の域を出ていないため。 (デモ画面を Trac プラグインに移植して使っている)

Web アプリは本格的に自作はしたことないので、いろんなフレームワークを使ってみようとは思う。

使用言語は使い慣れているということで Python 一択で、フレームワークDjango から初めてみる。

まずは、 Djangoチュートリアルを順に進めていこうと思う。

最終的には OpenID Connect の OP / RP にも対応して、つかっているいろんなサービスの認証サーバも兼ねたいな。

Linux (aarch64) on Qemu を動作させたい (3)

github.com

いろいろ変更を加え、 LS1046ARDB 向けの u-boot と kernel でシステムを立ち上げることができるようになった。

U-Boot 2017.07-00001-g62e8baa7b2-dirty (Jan 01 2018 - 08:37:01 +0000)

SoC:  LS1046AE Rev1.0 (0x87070010)
Clock Configuration:
       CPU0(A72):800  MHz  CPU1(A72):800  MHz  CPU2(A72):800  MHz
       CPU3(A72):800  MHz
       Bus:      600  MHz  DDR:      2100 MT/s  FMAN:     800  MHz
Reset Configuration Word (RCW):
       00000000: 0c150010 0e000000 00000000 00000000
       00000010: 11335559 40000012 60040000 c1000000
       00000020: 00000000 00000000 00000000 00238800
       00000030: 20124000 00003000 00000096 00000001
Model: LS1046A RDB Board
Board: LS1046ARDB, boot from Invalid setting of SW5
CPLD:  V0.0
PCBA:  V0.0
SERDES Reference Clocks:
SD1_CLK1 = 100.00MHZ, SD1_CLK2 = 100.00MHZ
I2C:   ready
DRAM:  Detected UDIMM
1.9 GiB (DDR4, 32-bit, CL=1, ECC off)
Waking secondary cores to start from fbd0e000
All (4) cores are up.
Using SERDES1 Protocol: 4403 (0x1133)
Using SERDES2 Protocol: 21849 (0x5559)
ERROR: Stopped after 0 portals
NAND:  fsl_ifc_run_command: Flash Time Out Error
fsl_ifc_run_command: Write Protect Error
fsl_ifc_run_command: Flash Time Out Error
fsl_ifc_run_command: Write Protect Error
fsl_ifc_run_command: Flash Time Out Error
fsl_ifc_run_command: Write Protect Error
fsl_ifc_run_command: Flash Time Out Error
fsl_ifc_run_command: Write Protect Error
fsl_ifc_run_command: Flash Time Out Error
fsl_ifc_run_command: Write Protect Error
0 MiB
MMC:   FSL_SDHC: 0
*** Warning - bad CRC, using default environment

EEPROM: NXID v1
In:    serial
Out:   serial
Err:   serial
controller reset failed (0x1)
Found 0 device(s).
SCSI:  Net:
MMC read: dev # 0, block # 18432, count 128 ...
Fman1: Data at 00000000fbc15470 is not a firmware
PCIe0: pcie@3400000 Endpoint: no link
PCIe1: pcie@3500000 Endpoint: no link
PCIe2: pcie@3600000 Endpoint: no link
No ethernet found.
Hit any key to stop autoboot:  0
Trying load from eMMC ..
Device: FSL_SDHC
Manufacturer ID: aa
OEM: 5859
Name: QEMU!
Tran Speed: 25000000
Rd Block Len: 512
SD version 1.0
High Capacity: Yes
Capacity: 4 GiB
Bus Width: 4-bit
Erase Group Size: 512 Bytes
187484907 bytes read in 42353 ms (4.2 MiB/s)
## Loading kernel from FIT Image at a0000000 ...
   Using 'config@1' configuration
   Trying 'kernel@1' kernel subimage
     Description:  ARM64 Linux kernel
     Type:         Kernel Image
     Compression:  gzip compressed
     Data Start:   0xa00000dc
     Data Size:    5110461 Bytes = 4.9 MiB
     Architecture: AArch64
     OS:           Linux
     Load Address: 0x80080000
     Entry Point:  0x80080000
   Verifying Hash Integrity ... OK
## Loading ramdisk from FIT Image at a0000000 ...
   Using 'config@1' configuration
   Trying 'ramdisk@1' ramdisk subimage
     Description:  LS1046 Ramdisk
     Type:         RAMDisk Image
     Compression:  gzip compressed
     Data Start:   0xa04e6138
     Data Size:    182347366 Bytes = 173.9 MiB
     Architecture: AArch64
     OS:           Linux
     Load Address: unavailable
     Entry Point:  unavailable
   Verifying Hash Integrity ... OK
## Loading fdt from FIT Image at a0000000 ...
   Using 'config@1' configuration
   Trying 'fdt@1' fdt subimage
     Description:  Flattened Device Tree blob
     Type:         Flat Device Tree
     Compression:  uncompressed
     Data Start:   0xa04dfc50
     Data Size:    25695 Bytes = 25.1 KiB
     Architecture: AArch64
   Verifying Hash Integrity ... OK
   Loading fdt from 0xa04dfc50 to 0x90000000
   Booting using the fdt blob at 0x90000000
   Uncompressing Kernel Image ... OK
   Using Device Tree in place at 0000000090000000, end 000000009001945e

Starting kernel ...

[    0.000000] Booting Linux on physical CPU 0x0
[    0.000000] Initializing cgroup subsys cpu
[    0.000000] Linux version 4.1.35-rt41 (tkenji@633840ca74ff) (gcc version 4.9.3 20150311 (prerelease) (Linaro GCC 4.9-2015.03) ) #47 SMP Tue Jan 2 15:16:32 UTC 2018
[    0.000000] CPU: AArch64 Processor [411fd070] revision 0
[    0.000000] Detected PIPT I-cache on CPU0
[    0.000000] alternatives: enabling workaround for ARM erratum 832075
[    0.000000] alternatives: enabling workaround for ARM erratum 834220
[    0.000000] earlycon: Early serial console at MMIO 0x21c0500 (options '')
[    0.000000] bootconsole [uart0] enabled
[    0.000000] efi: Getting EFI parameters from FDT:
[    0.000000] efi: UEFI not found.
[    0.000000] Reserved memory: initialized node bman-fbpr, compatible id fsl,bman-fbpr
[    0.000000] Reserved memory: initialized node qman-fqd, compatible id fsl,qman-fqd
[    0.000000] Reserved memory: initialized node qman-pfdr, compatible id fsl,qman-pfdr
[    0.000000] cma: Reserved 16 MiB at 0x00000000f7000000
[    0.000000] PERCPU: Embedded 18 pages/cpu @ffff80007bd81000 s34880 r8192 d30656 u73728
[    0.000000] Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 499464
[    0.000000] Kernel command line: console=ttyS0,115200 root=/dev/ram0 earlycon=uart8250,mmio,0x21c0500 mtdparts=1550000.quadspi:1m(rcw),15m(u-boot),48m(kernel.itb);7e800000.flash:16m(nand_uboot),48m(nand_kernel),448m(nand_free) init=/sbin/init
[    0.000000] log_buf_len individual max cpu contribution: 4096 bytes
[    0.000000] log_buf_len total cpu_extra contributions: 12288 bytes
[    0.000000] log_buf_len min size: 16384 bytes
[    0.000000] log_buf_len: 32768 bytes
[    0.000000] early log buf free: 14376(87%)
[    0.000000] PID hash table entries: 4096 (order: 3, 32768 bytes)
[    0.000000] Dentry cache hash table entries: 262144 (order: 9, 2097152 bytes)
[    0.000000] Inode-cache hash table entries: 131072 (order: 8, 1048576 bytes)
[    0.000000] software IO TLB [mem 0xf1200000-0xf5200000] (64MB) mapped at [ffff800071200000-ffff8000751fffff]
[    0.000000] Memory: 1662404K/2029568K available (7906K kernel code, 582K rwdata, 3124K rodata, 488K init, 757K bss, 350780K reserved, 16384K cma-reserved)
[    0.000000] Virtual kernel memory layout:
[    0.000000]     vmalloc : 0xffff000000000000 - 0xffff7bffbfff0000   (126974 GB)
[    0.000000]     vmemmap : 0xffff7bffc0000000 - 0xffff7fffc0000000   (  4096 GB maximum)
[    0.000000]               0xffff7bffc0000000 - 0xffff7bffc1ef8000   (    30 MB actual)
[    0.000000]     fixed   : 0xffff7ffffabfd000 - 0xffff7ffffac00000   (    12 KB)
[    0.000000]     PCI I/O : 0xffff7ffffae00000 - 0xffff7ffffbe00000   (    16 MB)
[    0.000000]     modules : 0xffff7ffffc000000 - 0xffff800000000000   (    64 MB)
[    0.000000]     memory  : 0xffff800000000000 - 0xffff80007be00000   (  1982 MB)
[    0.000000]       .init : 0xffff800000b48000 - 0xffff800000bc2000   (   488 KB)
[    0.000000]       .text : 0xffff800000080000 - 0xffff800000b47a54   ( 11039 KB)
[    0.000000]       .data : 0xffff800000bd4000 - 0xffff800000c65800   (   582 KB)
[    0.000000] Hierarchical RCU implementation.
[    0.000000]  Additional per-CPU info printed with stalls.
[    0.000000]  RCU restricting CPUs from NR_CPUS=64 to nr_cpu_ids=4.
[    0.000000] RCU: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=4
[    0.000000] NR_IRQS:64 nr_irqs:64 0
[    0.000000] Architected cp15 timer(s) running at 62.50MHz (virt).
[    0.000000] clocksource arch_sys_counter: mask: 0xffffffffffffff max_cycles: 0x1cd42e208c, max_idle_ns: 881590405314 ns
[    0.002463] sched_clock: 56 bits at 62MHz, resolution 16ns, wraps every 4398046511096ns
[    0.213960] Console: colour dummy device 80x25
[    0.239571] Calibrating delay loop (skipped), value calculated using timer frequency.. 125.00 BogoMIPS (lpj=625000)
[    0.272167] pid_max: default: 32768 minimum: 301
[    0.292607] Security Framework initialized
[    0.329354] Mount-cache hash table entries: 4096 (order: 3, 32768 bytes)
[    0.354451] Mountpoint-cache hash table entries: 4096 (order: 3, 32768 bytes)
[    0.524640] Initializing cgroup subsys memory
[    0.537831] Initializing cgroup subsys hugetlb
[    0.739184] hw perfevents: enabled with arm/armv8-pmuv3 PMU driver, 1 counters available
[    0.758835] EFI services will not be available.
[    0.995980] CPU1: Booted secondary processor
[    0.997040] Detected PIPT I-cache on CPU1
[    0.997777] SANITY CHECK: Unexpected variation in cntfrq. Boot CPU: 0x00000003b9aca0, CPU1: 0x000000017d7840
[    1.000116] ------------[ cut here ]------------
[    1.000865] WARNING: CPU: 1 PID: 0 at ../arch/arm64/kernel/cpuinfo.c:199 cpuinfo_store_cpu+0x3d4/0x3f0()
[    1.009154] Unsupported CPU feature variation.
[    1.009794] Modules linked in:
[    1.015840] CPU: 1 PID: 0 Comm: swapper/1 Not tainted 4.1.35-rt41 #47
[    1.016033] Hardware name: LS1046A RDB Board (DT)
[    1.030747] Call trace:
[    1.031754] [<ffff800000089894>] dump_backtrace+0x0/0x10c
[    1.032118] [<ffff800000089a8c>] show_stack+0x14/0x1c
[    1.032401] [<ffff800000322838>] dump_stack+0x8c/0xac
[    1.032604] [<ffff8000000b3c10>] warn_slowpath_common+0xac/0xd4
[    1.032773] [<ffff8000000b3cdc>] warn_slowpath_fmt_taint+0x4c/0x54
[    1.032870] [<ffff80000008df58>] cpuinfo_store_cpu+0x3d4/0x3f0
[    1.032967] [<ffff80000008ffbc>] secondary_start_kernel+0xe4/0x128
[    1.062332] ---[ end trace f173f86d6ac2600b ]---
[    1.159977] CPU2: Booted secondary processor
[    1.163201] Detected PIPT I-cache on CPU2
[    1.163553] SANITY CHECK: Unexpected variation in cntfrq. Boot CPU: 0x00000003b9aca0, CPU2: 0x000000017d7840
[    1.202462] CPU3: Booted secondary processor
[    1.203003] Detected PIPT I-cache on CPU3
[    1.203180] SANITY CHECK: Unexpected variation in cntfrq. Boot CPU: 0x00000003b9aca0, CPU3: 0x000000017d7840
[    1.208947] Brought up 4 CPUs
[    1.244540] SMP: Total of 4 processors activated.
[    1.245231] CPU: All CPU(s) started at EL1
[    1.296783] alternatives: patching kernel code
[    1.424440] devtmpfs: initialized
[    1.661849] DMI not present or invalid.
[    1.694198] clocksource jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[    1.847526] pinctrl core: initialized pinctrl subsystem
[    2.002574] NET: Registered protocol family 16
[    2.136361] cpuidle: using governor ladder
[    2.174769] cpuidle: using governor menu
[    2.179854] fsl-mc bus type registered
[    2.185463] MC object device driver fsl_mc_dprc registered
[    2.193242] MC object device driver fsl_mc_allocator registered
[    2.199335] Bman ver:0000,00,00
[    2.200239] unknown Bman version, default to rev1.0
[    2.270321] qman-fqd addr 0x00000000fb000000 size 0x800000
[    2.272008] qman-pfdr addr 0x00000000f8000000 size 0x2000000
[    2.274877] Qman ver:0000,00,00,00
[    2.276537] unknown Qman version, default to rev1.1
[    2.285663] vdso: 2 pages (1 code @ ffff800000bd9000, 1 data @ ffff800000bd8000)
[    2.292818] hw-breakpoint: found 6 breakpoint and 4 watchpoint registers.
[    2.353700] DMA: preallocated 256 KiB pool for atomic allocations
[    2.384210] Serial: AMBA PL011 UART driver
[    2.795706] Machine: LS1046A RDB Board
[    2.800774] SoC family: QorIQ LS1046A
[    2.801758] SoC ID: svr:0x87070010, Revision: 1.0
[    4.304871] RCPM: layerscape_rcpm_init: The RCPM driver initialized.
[    4.372132] vgaarb: loaded
[    4.402088] SCSI subsystem initialized
[    4.456503] usbcore: registered new interface driver usbfs
[    4.471751] usbcore: registered new interface driver hub
[    4.476685] usbcore: registered new device driver usb
[    4.530612] i2c i2c-0: IMX I2C adapter registered
[    4.540210] i2c i2c-0: can't use DMA
[    4.558772] i2c i2c-1: IMX I2C adapter registered
[    4.564546] i2c i2c-1: can't use DMA
[    4.574908] pps_core: LinuxPPS API ver. 1 registered
[    4.588712] pps_core: Software ver. 5.3.6 - Copyright 2005-2007 Rodolfo Giometti <giometti@linux.it>
[    4.595818] PTP clock support registered
[    4.619976] bman-fbpr addr 0x00000000fa000000 size 0x1000000
[    4.636199] Bman err interrupt handler present
[    4.647532] unknown BMan version in portal node,default to rev1.0
[    4.652998] unknown BMan version in portal node,default to rev1.0
[    4.659383] unknown BMan version in portal node,default to rev1.0
[    4.662188] unknown BMan version in portal node,default to rev1.0
[    4.667028] unknown BMan version in portal node,default to rev1.0
[    4.670040] unknown BMan version in portal node,default to rev1.0
[    4.672932] unknown BMan version in portal node,default to rev1.0
[    4.676520] unknown BMan version in portal node,default to rev1.0
[    4.680058] unknown BMan version in portal node,default to rev1.0
[    4.699803] Bman portal initialised, cpu 0
[    4.707872] Bman portal initialised, cpu 1
[    4.716818] Bman portal initialised, cpu 2
[    4.722468] Bman portal initialised, cpu 3
[    4.724234] Bman portals initialised
[    4.734674] Unexpected result from MCR_INIT_PFDR: 00
[    4.740044] Qman err interrupt handler present
[    4.774657] QMan: Allocated lookup table at ffff00000024d000, entry count 131073
[    4.787427] unknown QMan version in portal node,default to rev1.1
[    4.826345] Qman portal initialised, cpu 0
[    4.835371] Qman portal initialised, cpu 1
[    4.845039] Qman portal initialised, cpu 2
[    4.852880] Qman portal initialised, cpu 3
[    4.854145] Qman portals initialised
[    4.865027] Bman: BPID allocator includes range 32:32
[    4.870803] Qman: FQID allocator includes range 256:256
[    4.872773] Qman: FQID allocator includes range 32768:32768
[    4.879221] Qman: CGRID allocator includes range 0:256
[    4.893165] Qman: pool channel allocator includes range 1025:15
[    4.903892] No USDPAA memory, no 'fsl,usdpaa-mem' in device-tree
[    4.908763] fsl-ifc 1530000.ifc: Freescale Integrated Flash Controller
[    4.915669] fsl-ifc 1530000.ifc: IFC version 0.0, 8 banks
[    5.070779] Switched to clocksource arch_sys_counter
[    5.821905] NET: Registered protocol family 2
[    5.892757] TCP established hash table entries: 16384 (order: 5, 131072 bytes)
[    5.900429] TCP bind hash table entries: 16384 (order: 6, 262144 bytes)
[    5.905713] TCP: Hash tables configured (established 16384 bind 16384)
[    5.923881] UDP hash table entries: 1024 (order: 3, 32768 bytes)
[    5.929742] UDP-Lite hash table entries: 1024 (order: 3, 32768 bytes)
[    5.953056] NET: Registered protocol family 1
[    5.990297] RPC: Registered named UNIX socket transport module.
[    5.993178] RPC: Registered udp transport module.
[    5.995098] RPC: Registered tcp transport module.
[    5.997389] RPC: Registered tcp NFSv4.1 backchannel transport module.
[    6.048812] Trying to unpack rootfs image as initramfs...
[  173.442592] Freeing initrd memory: 178068K (ffff8000204e7000 - ffff80002b2cc000)
[  173.459824] kvm [1]: HYP mode not available
[  173.664526] futex hash table entries: 1024 (order: 4, 65536 bytes)
[  173.683605] audit: initializing netlink subsys (disabled)
[  173.699599] audit: type=2000 audit(172.430:1): initialized
[  173.758824] HugeTLB registered 2 MB page size, pre-allocated 0 pages
[  173.831518] VFS: Disk quotas dquot_6.6.0
[  173.836440] VFS: Dquot-cache hash table entries: 512 (order 0, 4096 bytes)
[  173.964076] NFS: Registering the id_resolver key type
[  173.974926] Key type id_resolver registered
[  173.976703] Key type id_legacy registered
[  173.994814] fuse init (API version 7.23)
[  174.019183] 9p: Installing v9fs 9p2000 file system support
[  174.134214] io scheduler noop registered
[  174.143555] io scheduler cfq registered (default)
[  174.155589] ls-scfg-msi soc:msi-controller: ibs_shift:2 msir_irqs:32 msir_base:0x4
[  174.191723] Find msi-controller /soc/msi-controller
[  174.361186] ls-pcie-ep 3400000.pcie: in EP mode
[  174.368386] ls-pcie-ep 3500000.pcie: in EP mode
[  174.372227] ls-pcie-ep 3600000.pcie: in EP mode
[  174.424533] Freescale LS2 console driver
[  174.451146] fsl-ls2-console: device fsl_mc_console registered
[  174.459395] fsl-ls2-console: device fsl_aiop_console registered
[  174.746038] Serial: 8250/16550 driver, 4 ports, IRQ sharing disabled
[  174.828954] msm_serial: driver initialized
[  174.952698] console [ttyS0] disabled
[  174.969494] 21c0500.serial: ttyS0 at MMIO 0x21c0500 (irq = 19, base_baud = 18750000) is a 16550A
[  174.984238] console [ttyS0] enabled
[  174.984238] console [ttyS0] enabled
[  174.991707] bootconsole [uart0] disabled
[  174.991707] bootconsole [uart0] disabled
[  175.022961] 21c0600.serial: ttyS1 at MMIO 0x21c0600 (irq = 19, base_baud = 18750000) is a 16550A
[  175.051836] 21d0500.serial: ttyS2 at MMIO 0x21d0500 (irq = 20, base_baud = 18750000) is a 16550A
[  175.072879] 21d0600.serial: ttyS3 at MMIO 0x21d0600 (irq = 20, base_baud = 18750000) is a 16550A
[  175.633702] brd: module loaded
[  175.854360] loop: module loaded
[  175.892292] at24 0-0052: 65536 byte 24c512 EEPROM, writable, 1 bytes/write
[  175.894760] at24 0-0053: 65536 byte 24c512 EEPROM, writable, 1 bytes/write
[  175.955242] ahci-qoriq 3200000.sata: forcing PORTS_IMPL to 0x1
[  176.967362] ahci-qoriq 3200000.sata: controller reset failed (0x80000001)
[  176.973038] ahci-qoriq: probe of 3200000.sata failed with error -5
[  177.518071] fsl,ifc-nand 7e800000.nand: Controller is not responding
[  178.017182] fsl,ifc-nand 7e800000.nand: Controller is not responding
[  178.517365] fsl,ifc-nand 7e800000.nand: Controller is not responding
[  179.017754] fsl,ifc-nand 7e800000.nand: Controller is not responding
[  179.518852] fsl,ifc-nand 7e800000.nand: Controller is not responding
[  179.521297] nand: No NAND device found
[  180.547645] fsl-quadspi 1550000.quadspi: cmd 0x9f timeout, addr@00000000, FR:0xffffffff, SR:0x00000000
[  181.547530] fsl-quadspi 1550000.quadspi: cmd 0x9f timeout, addr@00000000, FR:0xffffffff, SR:0x00000000
[  181.548801] fsl-quadspi 1550000.quadspi: Freescale QuadSPI probe failed
[  181.554510] fsl-quadspi: probe of 1550000.quadspi failed with error -2
[  181.605965] libphy: Fixed MDIO Bus: probed
[  181.613783] tun: Universal TUN/TAP device driver, 1.6
[  181.614639] tun: (C) 1999-2004 Max Krasnyansky <maxk@qualcomm.com>
[  181.689460] libphy: Freescale XGMAC MDIO Bus: probed
[  183.383698] libphy: Freescale XGMAC MDIO Bus: probed
[  183.693295] libphy: Freescale XGMAC MDIO Bus: probed
[  183.701213] libphy: Freescale XGMAC MDIO Bus: probed
[  183.708638] libphy: Freescale XGMAC MDIO Bus: probed
[  183.713684] libphy: Freescale XGMAC MDIO Bus: probed
[  183.720399] libphy: Freescale XGMAC MDIO Bus: probed
[  183.727568] libphy: Freescale XGMAC MDIO Bus: probed
[  183.734099] libphy: Freescale XGMAC MDIO Bus: probed
[  183.745526] libphy: Freescale XGMAC MDIO Bus: probed
[  183.803564] cpu 3: ! MAJOR FM Error [CPU03, ../drivers/net/ethernet/freescale/sdk_fman/Peripherals/FM/fm.c:137 CheckFmParameters]: Invalid Value;
[  183.809921] cpu 3: dma_aid_mode not supported by this integration.[  183.811504] cpu 3:
[  183.812269] cpu 3: ! MAJOR FM Error [CPU03, ../drivers/net/ethernet/freescale/sdk_fman/Peripherals/FM/fm.c:3512 FM_Init]: Invalid Value;
[  183.814587] cpu 3: [  183.815377] cpu 3:
[  183.817805] cpu 3: ! MAJOR FM Error [CPU03, ../drivers/net/ethernet/freescale/sdk_fman/src/wrapper/lnxwrp_fm.c:1099 InitFmDev]: Invalid State;
[  183.824491] cpu 3: FM[  183.825278] cpu 3:
[  183.829432] fsl-fman: probe of 1a00000.fman failed with error -5
[  183.835574] Freescale FM module, FMD API version 21.1.0
[  183.844579] fsl-fman-port: probe of 1a82000.port failed with error -5
[  183.850946] fsl-fman-port: probe of 1a83000.port failed with error -5
[  183.854313] fsl-fman-port: probe of 1a84000.port failed with error -5
[  183.856616] fsl-fman-port: probe of 1a85000.port failed with error -5
[  183.861868] fsl-fman-port: probe of 1a86000.port failed with error -5
[  183.864358] fsl-fman-port: probe of 1a87000.port failed with error -5
[  183.869159] fsl-fman-port: probe of 1a88000.port failed with error -5
[  183.871775] fsl-fman-port: probe of 1aa8000.port failed with error -5
[  183.874054] fsl-fman-port: probe of 1a89000.port failed with error -5
[  183.879965] fsl-fman-port: probe of 1aa9000.port failed with error -5
[  183.881931] fsl-fman-port: probe of 1a8a000.port failed with error -5
[  183.883747] fsl-fman-port: probe of 1aaa000.port failed with error -5
[  183.888476] fsl-fman-port: probe of 1a8b000.port failed with error -5
[  183.890161] fsl-fman-port: probe of 1aab000.port failed with error -5
[  183.892123] fsl-fman-port: probe of 1a8c000.port failed with error -5
[  183.894525] fsl-fman-port: probe of 1aac000.port failed with error -5
[  183.900630] fsl-fman-port: probe of 1a8d000.port failed with error -5
[  183.903143] fsl-fman-port: probe of 1aad000.port failed with error -5
[  183.905586] fsl-fman-port: probe of 1a90000.port failed with error -5
[  183.911865] fsl-fman-port: probe of 1ab0000.port failed with error -5
[  183.914582] fsl-fman-port: probe of 1a91000.port failed with error -5
[  183.919196] fsl-fman-port: probe of 1ab1000.port failed with error -5
[  183.925529] Freescale FM Ports module
[  183.930926] fsl_mac: fsl_mac: FSL FMan MAC API based driver
[  183.941196] fsl_dpa: FSL DPAA Ethernet driver
[  183.955834] fsl_dpa fsl,dpaa:ethernet@2: of_find_device_by_node(/soc/fman@1a00000/ethernet@e4000) failed
[  183.964765] fsl_dpa: probe of fsl,dpaa:ethernet@2 failed with error -22
[  183.972278] fsl_dpa fsl,dpaa:ethernet@3: of_find_device_by_node(/soc/fman@1a00000/ethernet@e6000) failed
[  183.974914] fsl_dpa: probe of fsl,dpaa:ethernet@3 failed with error -22
[  183.980941] fsl_dpa fsl,dpaa:ethernet@4: of_find_device_by_node(/soc/fman@1a00000/ethernet@e8000) failed
[  183.984175] fsl_dpa: probe of fsl,dpaa:ethernet@4 failed with error -22
[  183.990184] fsl_dpa fsl,dpaa:ethernet@5: of_find_device_by_node(/soc/fman@1a00000/ethernet@ea000) failed
[  183.991728] fsl_dpa: probe of fsl,dpaa:ethernet@5 failed with error -22
[  183.994398] fsl_dpa fsl,dpaa:ethernet@8: of_find_device_by_node(/soc/fman@1a00000/ethernet@f0000) failed
[  183.995925] fsl_dpa: probe of fsl,dpaa:ethernet@8 failed with error -22
[  184.000515] fsl_dpa fsl,dpaa:ethernet@9: of_find_device_by_node(/soc/fman@1a00000/ethernet@f2000) failed
[  184.002661] fsl_dpa: probe of fsl,dpaa:ethernet@9 failed with error -22
[  184.005407] fsl_advanced: FSL DPAA Advanced drivers:
[  184.009913] fsl_proxy: FSL DPAA Proxy initialization driver
[  184.019760] fsl_dpa_shared: FSL DPAA Shared Ethernet driver
[  184.030854] fsl_dpa_macless: FSL DPAA MACless Ethernet driver
[  184.040941] fsl_oh: FSL FMan Offline Parsing port driver
[  184.050421] e1000: Intel(R) PRO/1000 Network Driver - version 7.3.21-k8-NAPI
[  184.052395] e1000: Copyright (c) 1999-2006 Intel Corporation.
[  184.060637] e1000e: Intel(R) PRO/1000 Network Driver - 2.3.2-k
[  184.063402] e1000e: Copyright(c) 1999 - 2014 Intel Corporation.
[  184.065917] sky2: driver version 1.30
[  184.138477] VFIO - User Level meta-driver version: 0.3
[  184.209155] vfio_fsl_mc_driver_init: Driver registration fails as no fsl_mc_bus found
[  184.264459] dwc3 2f00000.usb: this is not a DesignWare USB3 DRD Core
[  184.269841] dwc3 2f00000.usb: failed to initialize core
[  184.281393] dwc3 3000000.usb: this is not a DesignWare USB3 DRD Core
[  184.284622] dwc3 3000000.usb: failed to initialize core
[  184.291060] dwc3 3100000.usb: this is not a DesignWare USB3 DRD Core
[  184.292759] dwc3 3100000.usb: failed to initialize core
[  184.364841] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
[  184.389252] ehci-pci: EHCI PCI platform driver
[  184.403425] ehci-platform: EHCI generic platform driver
[  184.424526] ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
[  184.433852] ohci-pci: OHCI PCI platform driver
[  184.460716] ohci-platform: OHCI generic platform driver
[  184.540858] usbcore: registered new interface driver usb-storage
[  184.590346] mousedev: PS/2 mouse device common for all mice
[  184.671105] rtc-pcf2127 1-0051: chip found, driver version 0.0.1
[  184.829317] rtc-pcf2127 1-0051: pcf2127_get_datetime: read error
[  184.910663] rtc-pcf2127 1-0051: rtc core: registered rtc-pcf2127 as rtc0
[  184.947195] i2c /dev entries driver
[  185.148716] ina2xx 0-0040: error configuring the device: -110
[  185.155213] 0-004c supply vcc not found, using dummy regulator
[  185.257520] lm90 0-004c: Register 0x4 read failed (-110)
[  185.258221] lm90 0-004c: Failed to read convrate register!
[  185.457230] lm90 0-004c: Register 0x3 read failed (-110)
[  185.457832] lm90 0-004c: Initialization failed!
[  185.508164] imx2-wdt 2ad0000.watchdog: timeout 60 sec (nowayout=0)
[  185.583901] qoriq_cpufreq: Freescale QorIQ CPU frequency scaling driver
[  185.590108] CPUidle arm: CPU 0 failed to init idle CPU ops
[  185.594340] sdhci: Secure Digital Host Controller Interface driver
[  185.595819] sdhci: Copyright(c) Pierre Ossman
[  185.600877] sdhci-pltfm: SDHCI platform and OF driver helper
[  185.658996] sdhci-esdhc 1560000.esdhc: No vmmc regulator found
[  185.660924] sdhci-esdhc 1560000.esdhc: No vqmmc regulator found
[  185.741316] mmc0: SDHCI controller on 1560000.esdhc [1560000.esdhc] using ADMA
ls1_mmci_wakequeues: rsplen 0 (< 4)
ls1_mmci_wakequeues: rsplen 0 (< 4)
ls1_mmci_wakequeues: rsplen 0 (< 4)
ls1_mmci_wakequeues: rsplen 0 (< 4)
ls1_mmci_wakequeues: rsplen 0 (< 4)
ls1_mmci_wakequeues: rsplen 0 (< 4)
[  185.835651] MC object device driver fsl_dpaa2_caam registered
[  185.893201] usbcore: registered new interface driver usbhid
[  185.894812] usbhid: USB HID core driver
[  185.904297] fsl-mc bus not found, restool driver registration failed
[  185.919269] MC object device driver fsl_dpio_drv registered
[  186.010281] Freescale USDPAA process driver
[  186.013941] fsl-usdpaa: no region found
[  186.024451] Freescale USDPAA process IRQ driver
[  186.043962] mmc0: new SDHC card at address 4567
[  186.049181] MC object device driver fsl_dpaa2_eth registered
[  186.051419] MC object device driver dpaa2_mac registered
[  186.064761] MC object device driver dpaa2_ethsw registered
[  186.071612] MC object device driver dpaa2_evb registered
[  186.075404] MC object device driver fsl_dce_api registered
[  186.085006] MC object device driver dpaa2_rtc registered
[  186.114675] Initializing XFRM netlink socket
[  186.133725] NET: Registered protocol family 10
[  186.140022] mmcblk0: mmc0:4567 QEMU! 4.00 GiB
[  186.249599] sit: IPv6 over IPv4 tunneling driver
[  186.269010]  mmcblk0: p1
[  186.293846] NET: Registered protocol family 17
[  186.299097] NET: Registered protocol family 15
[  186.308584] 8021q: 802.1Q VLAN Support v1.8
[  186.324297] 9pnet: Installing 9P2000 support
[  186.359469] Key type dns_resolver registered
[  186.416481] registered taskstats version 1
[  186.452709] fsl_generic: FSL DPAA Generic Ethernet driver
[  186.557572] rtc-pcf2127 1-0051: pcf2127_get_datetime: read error
[  186.558484] rtc-pcf2127 1-0051: hctosys: unable to read the hardware clock
[  186.902861] Freeing unused kernel memory: 488K (ffff800000b48000 - ffff800000bc2000)
[  186.905327] Freeing alternatives memory: 52K (ffff800000bc2000 - ffff800000bcf000)
INIT: version 2.88 booting
[  187.384848] hrtimer: interrupt took 48617776 ns
Starting udev
[  199.993140] udevd[996]: starting version 182
[  208.549759] mmcblk0: r/w command failed, status = 0x40000b00
[  208.676654] mmc0: tried to reset card
[  208.685602] mmcblk0: r/w command failed, status = 0x40000b00
[  208.689433] blk_update_request: I/O error, dev mmcblk0, sector 8388600
[  208.738275] mmcblk0: r/w command failed, status = 0x40000b00
[  208.742510] blk_update_request: I/O error, dev mmcblk0, sector 8388600
[  208.755810] Buffer I/O error on dev mmcblk0, logical block 1048575, async page read
udevd[999]: timeout: killing '/etc/udev/scripts/mount.sh' [1021]

udevd[999]: '/etc/udev/scripts/mount.sh' [1021] terminated by signal 9 (Killed)

udevd[1009]: timeout: killing '/etc/udev/scripts/mount.sh' [1026]

udevd[1017]: timeout: killing '/etc/udev/scripts/mount.sh' [1039]

udevd[1011]: timeout: killing '/etc/udev/scripts/mount.sh' [1034]

udevd[1014]: timeout: killing '/etc/udev/scripts/mount.sh' [1038]

udevd[1025]: timeout: killing '/etc/udev/scripts/mount.sh' [1041]

udevd[1001]: timeout: killing '/etc/udev/scripts/mount.sh' [1032]
udevd[1013]: timeout: killing '/etc/udev/scripts/mount.sh' [1030]
udevd[1002]: timeout: killing '/etc/udev/scripts/mount.sh' [1042]

udevd[1012]: timeout: killing '/etc/udev/scripts/mount.sh' [1027]

udevd[1005]: timeout: killing '/etc/udev/scripts/mount.sh' [1043]

udevd[1007]: timeout: killing '/etc/udev/scripts/mount.sh' [1029]

udevd[1016]: timeout: killing '/etc/udev/scripts/mount.sh' [1036]


udevd[1003]: timeout: killing '/etc/udev/scripts/mount.sh' [1045]

udevd[1011]: '/etc/udev/scripts/mount.sh' [1034] terminated by signal 9 (Killed)

udevd[1017]: '/etc/udev/scripts/mount.sh' [1039] terminated by signal 9 (Killed)


udevd[1008]: timeout: killing '/etc/udev/scripts/mount.sh' [1031]

udevd[1010]: timeout: killing '/etc/udev/scripts/mount.sh' [1028]

udevd[1004]: timeout: killing '/etc/udev/scripts/mount.sh' [1047]

udevd[1006]: timeout: killing '/etc/udev/scripts/mount.sh' [1049]
udevd[1016]: '/etc/udev/scripts/mount.sh' [1036] terminated by signal 9 (Killed)

udevd[1000]: timeout: killing '/etc/udev/scripts/mount.sh' [1046]


udevd[1003]: '/etc/udev/scripts/mount.sh' [1045] terminated by signal 9 (Killed)

udevd[1001]: timeout: killing '/etc/udev/scripts/mount.sh' [1032]

udevd[1009]: '/etc/udev/scripts/mount.sh' [1026] terminated by signal 9 (Killed)

udevd[1014]: '/etc/udev/scripts/mount.sh' [1038] terminated by signal 9 (Killed)

udevd[1008]: '/etc/udev/scripts/mount.sh' [1031] terminated by signal 9 (Killed)

udevd[1013]: '/etc/udev/scripts/mount.sh' [1030] terminated by signal 9 (Killed)

udevd[1006]: '/etc/udev/scripts/mount.sh' [1049] terminated by signal 9 (Killed)
udevd[1005]: '/etc/udev/scripts/mount.sh' [1043] terminated by signal 9 (Killed)

udevd[1001]: '/etc/udev/scripts/mount.sh' [1032] terminated by signal 9 (Killed)

udevd[1004]: '/etc/udev/scripts/mount.sh' [1047] terminated by signal 9 (Killed)


udevd[1010]: '/etc/udev/scripts/mount.sh' [1028] terminated by signal 9 (Killed)
udevd[1025]: '/etc/udev/scripts/mount.sh' [1041] terminated by signal 9 (Killed)

udevd[1002]: '/etc/udev/scripts/mount.sh' [1042] terminated by signal 9 (Killed)

[  248.590907] mmcblk0: r/w command failed, status = 0x40000b00

udevd[1007]: '/etc/udev/scripts/mount.sh' [1029] terminated by signal 9 (Killed)

udevd[1012]: '/etc/udev/scripts/mount.sh' [1027] terminated by signal 9 (Killed)
udevd[1033]: timeout: killing '/etc/udev/scripts/mount.sh' [1052]

[  248.802594] mmc0: tried to reset card
[  248.813772] mmcblk0: r/w command failed, status = 0x40000b00
[  248.820798] blk_update_request: I/O error, dev mmcblk0, sector 8388600
[  248.872319] mmcblk0: r/w command failed, status = 0x40000b00
[  248.877792] blk_update_request: I/O error, dev mmcblk0, sector 8388600

[  248.898861] Buffer I/O error on dev mmcblk0p1, logical block 1048319, async page read
udevd[1000]: '/etc/udev/scripts/mount.sh' [1046] terminated by signal 9 (Killed)

udevd[1033]: '/etc/udev/scripts/mount.sh' [1052] terminated by signal 9 (Killed)

udevd[1035]: timeout: killing '/etc/udev/scripts/mount.sh' [1057]

udevd[1037]: timeout: killing '/etc/udev/scripts/mount.sh' [1060]

udevd[1035]: '/etc/udev/scripts/mount.sh' [1057] terminated by signal 9 (Killed)

udevd[1037]: '/etc/udev/scripts/mount.sh' [1060] terminated by signal 9 (Killed)

udevd[1040]: timeout: killing '/etc/udev/scripts/mount.sh' [1056]

udevd[1040]: '/etc/udev/scripts/mount.sh' [1056] terminated by signal 9 (Killed)

udevd[1044]: timeout: killing '/etc/udev/scripts/mount.sh' [1062]

udevd[1044]: '/etc/udev/scripts/mount.sh' [1062] terminated by signal 9 (Killed)

udevd[1048]: timeout: killing '/etc/udev/scripts/mount.sh' [1063]

udevd[1048]: '/etc/udev/scripts/mount.sh' [1063] terminated by signal 9 (Killed)

[  271.695304] random: dd urandom read with 15 bits of entropy available
Populating dev cache
ALSA: Restoring mixer settings...
/usr/sbin/alsactl: load_state:1735: No soundcards found...
[  435.774983] rtc-pcf2127 1-0051: pcf2127_get_datetime: read error
hwclock: RTC_RD_TIME: Input/output error
Sun Dec 31 02:52:31 UTC 2017
[  437.847766] rtc-pcf2127 1-0051: pcf2127_set_datetime: err=-110
hwclock: RTC_SET_TIME: Input/output error
[  437.949039] rtc-pcf2127 1-0051: pcf2127_get_datetime: read error
Running postinst /etc/rpm-postinsts/100-sysvinit-inittab...
update-rc.d: /etc/init.d/run-postinsts exists during rc.d purge (continuing)
 Removing any system startup links for run-postinsts ...
  /etc/rcS.d/S99run-postinsts
INIT: Entering runlevel: 5
Configuring network interfaces... done.
Starting system message bus: dbus.
Starting OpenBSD Secure Shell server: sshd
  generating ssh RSA key...
  generating ssh ECDSA key...
  generating ssh DSA key...
  generating ssh ED25519 key...
done.
Starting rpcbind daemon...done.
starting statd: done
[  497.508169] rtc-pcf2127 1-0051: pcf2127_get_datetime: read error
hwclock: RTC_RD_TIME: Input/output error
exportfs: can't open /etc/exports for reading
NFS daemon support not enabled in kernel
starting rsyslogd ... done
Starting internet superserver: xinetd.

QorIQ SDK (FSL Reference Distro) 2.0 ls1046ardb /dev/ttyS0

ls1046ardb login: root
root@ls1046ardb:~# cat /proc/cpuinfo
processor       : 0
BogoMIPS        : 125.00
Features        : fp asimd evtstrm aes pmull sha1 sha2 crc32
CPU implementer : 0x41
CPU architecture: 8
CPU variant     : 0x1
CPU part        : 0xd07
CPU revision    : 0

processor       : 1
BogoMIPS        : 125.00
Features        : fp asimd evtstrm aes pmull sha1 sha2 crc32
CPU implementer : 0x41
CPU architecture: 8
CPU variant     : 0x1
CPU part        : 0xd07
CPU revision    : 0

processor       : 2
BogoMIPS        : 125.00
Features        : fp asimd evtstrm aes pmull sha1 sha2 crc32
CPU implementer : 0x41
CPU architecture: 8
CPU variant     : 0x1
CPU part        : 0xd07
CPU revision    : 0

processor       : 3
BogoMIPS        : 125.00
Features        : fp asimd evtstrm aes pmull sha1 sha2 crc32
CPU implementer : 0x41
CPU architecture: 8
CPU variant     : 0x1
CPU part        : 0xd07
CPU revision    : 0

root@ls1046ardb:~# QEMU: Terminated

去年内に起動させられなかったのは心残りだが、正月休みのうちにログインできるところまで持っていけたのは良かった。

一区切りにはなったけど、以下の改善は行っておきたい。

  • 山ほど出ている起動時エラーの低減
  • qemu の追加デバイスネームスペースの統一 (qoriq / ls1 → layerscape or ls1)

それができれば、 qemu に仕事で使っているカスタムボードのエミュレーションを追加していきたい。

initramfs を再構築する

Qemu 上での Kernel デバッグにおいて、 init が正常に動作しないという問題 (こちらは Qemu の UART デバイスに対する割り込み線の設定ミスだった) を調査するため、 initramfs をいじっていたので、 cpio の展開 / 再圧縮手順をまとめておく。

cpio の展開

### gz を展開する (ホントは cpio とまとめてワンライナーにしたいけど調査不足)
$ gzip -d initramfs.cpio.gz
$ ls
initramfs.cpio

### cpio を展開する
$ mkdir initramfs
$ cd initramfs
$ cpio -ivd < ../initramfs.cpio

cpio の再構築

$ cd initramfs
$ find . | cpio -H newc -o | gzip > ../initramfs.cpio.gz

Linux (aarch64) on Qemu を動作させたい (2)

Qemu への SEV 対応は、以下のような情報があり、 "パフォーマンスが悪いから nop にしているよ" みたいな感じに読めたけど、今回はパフォーマンスよりも動作の再現性を優先したいので、実装してみる。

Re: [Qemu-devel] implemetation of wfe and sev instructions on aarch64

diff --git a/target/arm/helper.h b/target/arm/helper.h
index df86bf71415..5cddcd0627f 100644
--- a/target/arm/helper.h
+++ b/target/arm/helper.h
@@ -50,6 +50,7 @@ DEF_HELPER_4(exception_with_syndrome, void, env, i32, i32, i32)
 DEF_HELPER_1(setend, void, env)
 DEF_HELPER_1(wfi, void, env)
 DEF_HELPER_1(wfe, void, env)
+DEF_HELPER_1(sev, void, env)
 DEF_HELPER_1(yield, void, env)
 DEF_HELPER_1(pre_hvc, void, env)
 DEF_HELPER_2(pre_smc, void, env, i32)
diff --git a/target/arm/op_helper.c b/target/arm/op_helper.c
index 2a856665797..dce0e11c011 100644
--- a/target/arm/op_helper.c
+++ b/target/arm/op_helper.c
@@ -445,6 +445,21 @@ void HELPER(wfe)(CPUARMState *env)
     HELPER(yield)(env);
 }
 
+void HELPER(sev)(CPUARMState *env)
+{
+    ARMCPU *cpu = arm_env_get_cpu(env);
+    CPUState *cs0 = CPU(cpu), *cs = cs0;
+
+    CPU_FOREACH(cs) {
+        if (cs->halted) {
+            fprintf(stderr, "%s: cpu%d halted (%p)\n", __func__, cs->cpu_index, cs->halt_cond);
+            qemu_cond_signal(cs->halt_cond);
+        }
+    }
+    //cs0->exception_index = EXCP_INTERRUPT;
+    cpu_loop_exit(cs0);
+}
+
 void HELPER(yield)(CPUARMState *env)
 {
     ARMCPU *cpu = arm_env_get_cpu(env);
diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c
index cb44632d16a..d2b937a4343 100644
--- a/target/arm/translate-a64.c
+++ b/target/arm/translate-a64.c
@@ -1345,7 +1345,7 @@ static void handle_hint(DisasContext *s, uint32_t insn,
         return;
     case 4: /* SEV */
     case 5: /* SEVL */
-        /* we treat all as NOP at least for now */
+        s->is_jmp = DISAS_SEV;
         return;
     default:
         /* default specified as NOP equivalent */
@@ -11385,6 +11385,10 @@ void gen_intermediate_code_a64(CPUState *cs, TranslationBlock *tb)
             gen_a64_set_pc_im(dc->pc);
             gen_helper_wfe(cpu_env);
             break;
+        case DISAS_SEV:
+            gen_a64_set_pc_im(dc->pc);
+            gen_helper_sev(cpu_env);
+            break;
         case DISAS_YIELD:
             gen_a64_set_pc_im(dc->pc);
             gen_helper_yield(cpu_env);
diff --git a/target/arm/translate.h b/target/arm/translate.h
index 2fe144baa9b..c936488cdc3 100644
--- a/target/arm/translate.h
+++ b/target/arm/translate.h
@@ -132,6 +132,7 @@ static void disas_set_insn_syndrome(DisasContext *s, uint32_t syn)
 #define DISAS_EXC 6
 /* WFE */
 #define DISAS_WFE 7
+#define DISAS_SEV 13
 #define DISAS_HVC 8
 #define DISAS_SMC 9
 #define DISAS_YIELD 10

ls1046ardb 仮想ボード側も GIC を接続するバスが間違っていたので、そこを修正すると secondary core も wfe を突破することはできるようになった。

しかし、 wfe 後に EL3 → EL2 と動作環境を切り替える処理があり、そこでハングしてしまった。

現在 ls1046ardb 仮想ボードは EL1 で動作している (EL2, EL3 を有効にすると起動そうそうにハングしていたので、無効化している) ので、以下のように u-boot 側を変更して、 EL の切り替えを発生させないようにすると、 kernel コードへ移動することができるようになった。

diff --git a/arch/arm/cpu/armv8/fsl-layerscape/lowlevel.S b/arch/arm/cpu/armv8/fsl-layerscape/lowlevel.S
index 28a31b21a9..2558481c80 100644
--- a/arch/arm/cpu/armv8/fsl-layerscape/lowlevel.S
+++ b/arch/arm/cpu/armv8/fsl-layerscape/lowlevel.S
@@ -73,7 +73,7 @@ ENDPROC(smp_kick_all_cpus)
 ENTRY(lowlevel_init)
        mov     x29, lr                 /* Save LR */
 
-       switch_el x1, 1f, 100f, 100f    /* skip if not in EL3 */
+       switch_el x1, 1f, 100f, 101f    /* skip if not in EL3 */
 1:
 
 #if defined (CONFIG_SYS_FSL_HAS_CCN504)
@@ -181,6 +181,7 @@ ENTRY(lowlevel_init)
        str     w0, [x1, #0x10]
 #endif
 
+101:
        /* Initialize GIC Secure Bank Status */
 #if defined(CONFIG_GICV2) || defined(CONFIG_GICV3)
        branch_if_slave x0, 1f
@@ -487,7 +488,8 @@ slave_cpu:
        ldr     x0, [x11]
        cbz     x0, slave_cpu
 #ifndef CONFIG_ARMV8_SWITCH_TO_EL1
-       mrs     x1, sctlr_el2
+       //mrs     x1, sctlr_el2
+       mrs     x1, sctlr_el1
 #else
        mrs     x1, sctlr_el1
 #endif
@@ -521,7 +523,7 @@ ENDPROC(secondary_boot_func)
 
 ENTRY(secondary_switch_to_el2)
        switch_el x6, 1f, 0f, 0f
-0:     ret
+0:     br x4
 1:     armv8_switch_to_el2_m x4, x5, x6
 ENDPROC(secondary_switch_to_el2)
 

kernel に入ったあとは、 CPU Idle Governor の初期化でハングが発生 (全コアが idle に入ってしまう?) してしまったのでデバッグ中。

GDB で追いかけているけど、問題の箇所付近で全然違う処理に飛んでしまい、 GDB が有効に活用できなくなって苦戦中。。


追記 (2017-12-17 13:56)

CPU Idle Governor を無効にしてみたけど、やっぱりハングするので、原因は違うところっぽい。。どうやって調査しようか。。

Linux (aarch64) on Qemu を動作させたい (1)

U-Boot をひと通り動かすことができるようになったので、引き続き Linux を動作させていく。

Linux も、 NXP-SDK 付属のものを使用して、ターゲット向けのバイナリをそのまま動作させることを目指す。

FIT ファイルの作成

ビルドしたあと、 U-Boot からよみこむために FIT (Flattened uImage Tree) ファイルを作成する。

its ファイルは、 NXP-SDK 付属のものをベースにしている。

$ cat kernel.its
/dts-v1/;

/ {
        description = "Image file for the LS1046A Linux Kernel";
        #address-cells = <1>;

        images {
                kernel@1 {
                        description = "ARM64 Linux kernel";
                        data = /incbin/("path/to/arch/arm64/boot/Image.gz");
                        type = "kernel";
                        arch = "arm64";
                        os = "linux";
                        compression = "gzip";
                        load = <0x80080000>;
                        entry = <0x80080000>;
                };
                fdt@1 {
                        description = "Flattened Device Tree blob";
                        data = /incbin/("path/to/arch/arm64/boot/dts/freescale/fsl-ls1046a-rdb.dtb");
                        type = "flat_dt";
                        arch = "arm64";
                        compression = "none";
                        load = <0x90000000>;
                };
                ramdisk@1 {
                        description = "LS1046 Ramdisk";
                        data = /incbin/("path/to/fsl-image-minimal-ls1046ardb.ext2.gz");
                        type = "ramdisk";
                        arch = "arm64";
                        os = "linux";
                        compression = "gzip";
                };
        };

        configurations {
                default = "config@1";
                config@1 {
                        description = "Boot Linux kernel";
                        kernel = "kernel@1";
                        fdt = "fdt@1";
                        ramdisk = "ramdisk@1";
                };
        };
};

$ mkimage -f kernel.its kernel.itb

作成した itb ファイルは emmc イメージにコピーしておく。

Linux kernel の起動

U-Boot を起動したあと、

=> print load_addr
load_addr=0xa0000000
=> print emmc_bootcmd
emmc_bootcmd=echo Trying load from eMMC ..;mmcinfo; ext2load mmc 0:1 $load_addr /kernel.itb; bootm $load_addr
=> run emmc_bootcmd

Linux をロードできる。

で、動作はというと、2番目以降のコアを起動するところで、起動させることができずに起動待ちループで止まってしまった。

... 省略 ...
[    0.064447] Calibrating delay loop (skipped), value calculated using timer frequency.. 125.00 BogoMIPS (lpj=625000)
[    0.068584] pid_max: default: 32768 minimum: 301
[    0.078346] Security Framework initialized
[    0.092536] Mount-cache hash table entries: 4096 (order: 3, 32768 bytes)
[    0.093597] Mountpoint-cache hash table entries: 4096 (order: 3, 32768 bytes)
[    0.211129] Initializing cgroup subsys memory
[    0.217881] Initializing cgroup subsys hugetlb
[    0.320269] hw perfevents: enabled with arm/armv8-pmuv3 PMU driver, 1 counters available
[    0.324401] EFI services will not be available.
... ここで止まる ...

U-Boot のとき同様、 Qemu 経由で kernel に GDB を接続すると、以下のことがわかった。

  1. CPU の起動方法 ("enable-method") に "spin-table" が設定されている
  2. CPU の起動トリガ ("cpu-release-addr") にアドレスを書き込んだあとに SEV を呼び出している
  3. が、Qemu 側が SEV / WFE 命令に対応していないため、何も起こらない

という状況っぽい。

CPU 起動待ちのタイムアウトも発生していないのが気になるが、今は Qemu を SEV に対応させることを考えている。

でも、 Qemu の aarch64 が smp に対応していないということはないはずなので、何かが間違っているから動いていないだけの可能性もあるので、まずは Qemu の aarch64 で smp 可能なボードがどう動いているかを解析してみることにする。


追記 (2017-12-11 21:55)

とりあえず、 U-Boot のときも比較に使用していた Xilinx の Zynq MP ボードは CPU の起動方法が "psci" となっており、起動方法が異なるので参考にはならなさそう。

仮想ボードが virt の場合とかはどう動くんだろう?


追記 (2017-12-17 12:34)

仮想ボードが virt の場合も起動方法は "psci" だった。。