2020年6月27日 星期六

Note for Yocto Project Development Tasks Manual v3.1 - CH3.2. Customizing Images


Yocto 可以讓User自訂image以滿足特定需求, 這個章節就是在介紹如何自訂image.
最簡單的image.bb就是全部空白
images/machine-image-brook.bb
inherit image
IMAGE_FEATURES = ""
LICENSE = "MIT"
IMAGE_LINGUAS = ""
build結果
brook@vista:~/apps_proc/poky/build/tmp-glibc/work/oe-linux-gnueabi/machine-image-brook$ find 1.0-r0/rootfs/
1.0-r0/rootfs/
1.0-r0/rootfs/var
1.0-r0/rootfs/var/cache
1.0-r0/rootfs/var/cache/opkg
1.0-r0/rootfs/var/lib
1.0-r0/rootfs/var/lib/opkg
1.0-r0/rootfs/lib
1.0-r0/rootfs/lib/systemd
1.0-r0/rootfs/lib/systemd/system
1.0-r0/rootfs/lib/systemd/system/run-postinsts.service
1.0-r0/rootfs/etc
1.0-r0/rootfs/etc/timestamp
1.0-r0/rootfs/etc/version
1.0-r0/rootfs/etc/systemd
1.0-r0/rootfs/etc/systemd/system
1.0-r0/rootfs/etc/systemd/system/sysinit.target.wants
1.0-r0/rootfs/etc/systemd/system/sysinit.target.wants/run-postinsts.service
1.0-r0/rootfs/run
1.0-r0/rootfs/usr
1.0-r0/rootfs/usr/sbin
1.0-r0/rootfs/usr/sbin/run-postinsts


3.2.1. Customizing Images Using local.conf

最簡單的客製化image就是在local.conf中加入一個package, 雖然彈性有限, 但相對簡單. 比如在local.conf加入一行
     IMAGE_INSTALL_append = " strace"
記住, strace前面有一個空白, 爾且是必須的. 此外, 善用+=運算符號可以增加可讀性.

images/machine-image-brook.bb
inherit image
IMAGE_FEATURES = ""
LICENSE = "MIT"
IMAGE_LINGUAS = ""

build結果
brook@vista:~/apps_proc/poky/build/tmp-glibc/work/oe-linux-gnueabi/machine-image-brook$ find 1.0-r0/rootfs/
1.0-r0/rootfs/
1.0-r0/rootfs/var
1.0-r0/rootfs/var/cache
1.0-r0/rootfs/var/cache/opkg
1.0-r0/rootfs/var/lib
1.0-r0/rootfs/var/lib/opkg
1.0-r0/rootfs/lib
1.0-r0/rootfs/lib/libnss_compat.so.2
1.0-r0/rootfs/lib/libresolv.so.2
1.0-r0/rootfs/lib/libresolv-2.28.so
1.0-r0/rootfs/lib/libnss_files.so.2
1.0-r0/rootfs/lib/libm.so.6
1.0-r0/rootfs/lib/libBrokenLocale-2.28.so
1.0-r0/rootfs/lib/libc-2.28.so
1.0-r0/rootfs/lib/libanl.so.1
1.0-r0/rootfs/lib/libutil.so.1
1.0-r0/rootfs/lib/libc.so.6
1.0-r0/rootfs/lib/libutil-2.28.so
1.0-r0/rootfs/lib/libnss_dns-2.28.so
1.0-r0/rootfs/lib/libnsl.so.1
1.0-r0/rootfs/lib/libdl-2.28.so
1.0-r0/rootfs/lib/libnss_compat-2.28.so
1.0-r0/rootfs/lib/ld-linux-armhf.so.3
1.0-r0/rootfs/lib/libnsl-2.28.so
1.0-r0/rootfs/lib/libpthread-2.28.so
1.0-r0/rootfs/lib/libnss_files-2.28.so
1.0-r0/rootfs/lib/libm-2.28.so
1.0-r0/rootfs/lib/libnss_dns.so.2
1.0-r0/rootfs/lib/librt-2.28.so
1.0-r0/rootfs/lib/libpthread.so.0
1.0-r0/rootfs/lib/libBrokenLocale.so.1
1.0-r0/rootfs/lib/libdl.so.2
1.0-r0/rootfs/lib/systemd
1.0-r0/rootfs/lib/systemd/system
1.0-r0/rootfs/lib/systemd/system/run-postinsts.service
1.0-r0/rootfs/lib/libanl-2.28.so
1.0-r0/rootfs/lib/ld-2.28.so
1.0-r0/rootfs/lib/librt.so.1
1.0-r0/rootfs/sbin
1.0-r0/rootfs/sbin/ldconfig
1.0-r0/rootfs/etc
1.0-r0/rootfs/etc/timestamp
1.0-r0/rootfs/etc/version
1.0-r0/rootfs/etc/ld.so.conf
1.0-r0/rootfs/etc/systemd
1.0-r0/rootfs/etc/systemd/system
1.0-r0/rootfs/etc/systemd/system/sysinit.target.wants
1.0-r0/rootfs/etc/systemd/system/sysinit.target.wants/run-postinsts.service
1.0-r0/rootfs/run
1.0-r0/rootfs/usr
1.0-r0/rootfs/usr/sbin
1.0-r0/rootfs/usr/sbin/run-postinsts
1.0-r0/rootfs/usr/bin
1.0-r0/rootfs/usr/bin/strace
1.0-r0/rootfs/usr/bin/strace-log-merge


3.2.2. Customizing Images Using Custom IMAGE_FEATURES and EXTRA_IMAGE_FEATURES

另一個方式是設定IMAGE_FEATURES與EXTRA_IMAGE_FEATURES, 這兩個功能相似, IMAGE_FEATURES是在recipe使用, 而EXTRA_IMAGE_FEATURES是在local.conf 使用. 可以參考meta/classes/core-image.bbclass了解更多細節
簡單來說, IMAGE_FEATURES 會被轉成是當的packages或configurations後加入IMAGE_INSTALL變數中. 而EXTRA_IMAGE_FEATURES變數會在bitbake.conf中, 將其加入IMAGE_FEATURES內.
EXTRA_IMAGE_FEATURES ??= ""
IMAGE_FEATURES += "${EXTRA_IMAGE_FEATURES}"


3.2.3. Customizing Images Using Custom .bb Files

你也可以透過recipe (.bb)自訂image內容, images/machine-image-brook.bb
inherit image
IMAGE_INSTALL = "strace"
IMAGE_FEATURES = ""
LICENSE = "MIT"
IMAGE_LINGUAS = ""
build結果與3.2.1.結果相同

3.2.4. Customizing Images Using Custom Package Groups

複雜一點的image,可以透過創建package group recipe來客製化image, 比如在meta/recipes-core/packagegroups/創建packagegroup-image-brook.bb, 內容如下
SUMMARY = "Brook's sckagegroup"
PR = "r0"

inherit packagegroup

PACKAGES = "\
    ${PN}-apps \
    ${PN}-tools \
    "

RDEPENDS_${PN}-apps = "\
    strace \
    "

RDEPENDS_${PN}-tools = "\
    busybox \
    "

RRECOMMENDS_${PN}-tools = "\
    openssl \
    "

加完之後, 可以使用bitbake確認是否可用
jenkins@vista:~/apps_proc/poky/build$ bitbake -s|grep brook
packagegroup-image-brook                              :1.0-r0

接著就可以在images/machine-image-brook.bb中使用這packagegroup
inherit image

IMAGE_INSTALL = "packagegroup-image-brook-tools"

IMAGE_FEATURES = ""

LICENSE = "MIT"

IMAGE_LINGUAS = ""
結果就是會安裝busybox, 當然你也可以安裝"packagegroup-image-brook-apps".

    參考資料:
  • https://www.yoctoproject.org/docs/3.1/dev-manual/dev-manual.html, The Yocto Project Development Tasks Manual



2020年6月26日 星期五

Qualcomm Snapdragon LTE modem


4G X-series Modem Class X5 X7 X12
LTE Category (down / up) 4 6 12/13
Peak LTE speeds down (Mbit/s) 150 300 600
Peak LTE speed up (Mbit/s) 50 50 150
LTE Class LTE (4G) LTE Advanced (4G+)
Modems MDM9628 MDM9635M MDM9645
MDM9625 MDM9235M MDM9640
MDM9320 MDM9630 MDM9340
MDM9225 MDM9330 MDM9245
  MDM9230 MDM9240


5G X-series Modem Class X50 X55
LTE Category (down / up) N/A 22
Peak LTE speeds down (Mbit/s) 2500
Peak LTE speed up (Mbit/s) 316
LTE Class LTE Advanced Pro (4.5G)
5G Modes NSA, TDD FDD, NSA, SA, TDD
Peak 5G speeds down (Mbit/s) 6500 7500
Peak 5G speeds up (Mbit/s) ? 3000


    參考資料:
  • https://en.wikipedia.org/wiki/Qualcomm_Snapdragon_LTE_modem, Qualcomm Snapdragon LTE modem



2020年5月9日 星期六

Linux Kernel(18.2)- SysCall mount


簡單記錄一下Linux 4.19-rc8從mount system call到呼叫file_system_type.mount()的call flow
SYSCALL_DEFINE5(mount)
  |--> ksys_mount()
    |--> do_mount()
      |--> do_new_mount()
        |--> type = get_fs_type()
        |--> vfs_kern_mount(type)
          |--> mount_fs(type)
            |--> type->mount()


SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
        char __user *, type, unsigned long, flags, void __user *, data)
{
    return ksys_mount(dev_name, dir_name, type, flags, data);
}

int ksys_mount(char __user *dev_name, char __user *dir_name, char __user *type,
        unsigned long flags, void __user *data)
{
  int ret;
  char *kernel_type;
  char *kernel_dev;
  void *options;

  kernel_type = copy_mount_string(type);
  ...

  kernel_dev = copy_mount_string(dev_name);
  ...

  options = copy_mount_options(data);
  ...

  ret = do_mount(kernel_dev, dir_name, kernel_type, flags, options);
  ...
  
  return ret;
}

long do_mount(const char *dev_name, const char __user *dir_name,
  const char *type_page, unsigned long flags, void *data_page)
{
  struct path path;
  unsigned int mnt_flags = 0, sb_flags;
  int retval = 0;

  retval = user_path(dir_name, &path);

  if (flags & MS_REMOUNT)
    retval = do_remount(&path, flags, sb_flags, mnt_flags, data_page);
  else if (flags & MS_BIND)
    retval = do_loopback(&path, dev_name, flags & MS_REC);
  else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
    retval = do_change_type(&path, flags);
  else if (flags & MS_MOVE)
    retval = do_move_mount(&path, dev_name);
  else
    retval = do_new_mount(&path, type_page, sb_flags, mnt_flags, dev_name, data_page);
  ...

  return retval;
}

static int do_new_mount(struct path *path, const char *fstype, int sb_flags,
   int mnt_flags, const char *name, void *data)
{
  struct file_system_type *type;
  struct vfsmount *mnt;
  int err;

  type = get_fs_type(fstype);
  ...

  mnt = vfs_kern_mount(type, sb_flags, name, data);
  ...

  put_filesystem(type);
  ...
  err = do_add_mount(real_mount(mnt), path, mnt_flags);
  ...
  return err;
}

struct vfsmount *
vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void *data)
{
  struct mount *mnt;
  mnt = alloc_vfsmnt(name);
  ...

  root = mount_fs(type, flags, name, data);
  ...
  return &mnt->mnt;    
}

struct dentry *
mount_fs(struct file_system_type *type, int flags, const char *name, void *data)
{
  struct dentry *root;
  ...

  root = type->mount(type, flags, name, data)
  ...

  return root;
}



    參考資料:
  • https://lkml.org/lkml/2018/3/16/905, fs: add ksys_mount() helper; remove in-kernel calls to sys_mount()
  • https://www.halolinux.us/kernel-architecture/the-mount-system-call.html, The Mount System Call




熱門文章