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




2020年5月3日 星期日

Yocto Project Reference Manual - extrausers.bbclass


extrausers.bbclass這個class允許我們在image中加入新的userand group,透過EXTRA_USERS_PARAMS 來設定,如:
新增兩個user,"tester-jim"與"tester-sue" ,其密碼都是tester01
     inherit extrausers
     EXTRA_USERS_PARAMS = "\
         useradd -P tester01 tester-jim; \
         useradd -P tester01 tester-sue; \
         "

也可以用於變更(設定)密碼
     inherit extrausers
     EXTRA_USERS_PARAMS = "\
         usermod -P 1876*18 root; \
         "

更複雜的例子如下
     inherit extrausers
     EXTRA_USERS_PARAMS = "\
         useradd -p '' tester; \
         groupadd developers; \
         userdel nobody; \
         groupdel -g video; \
         groupmod -g 1020 developers; \
         usermod -s /bin/sh tester; \
         "


    參考資料:
  • https://www.yoctoproject.org/docs/1.8/ref-manual/ref-manual.html#ref-classes-extrausers, extrausers.bbclass




2020年4月26日 星期日

how to include a static library in SDK?


這天忽然想build一個static binary, 才發現SDK沒有static library, 於是只好重新build一下SDK with static package.

brook@vista:~/oe-src$ . /opt/oecore-x86_64/environment-setup-cortexa7-neon-vfpv4-oe-linux-gnueabi brook@vista:~/oe-src$ ${CC} -static kobj.c /opt/oecore-x86_64/sysroots/x86_64-oesdk-linux/usr/libexec/arm-oe-linux-gnueabi/gcc/arm-oe-linux-gnueabi/5.3.0/real-ld: error: cannot find -lc /opt/oecore-x86_64/sysroots/cortexa7-neon-vfpv4-oe-linux-gnueabi/usr/lib/crt1.o(.text+0x28): error: undefined reference to '__libc_start_main' /opt/oecore-x86_64/sysroots/cortexa7-neon-vfpv4-oe-linux-gnueabi/usr/lib/crt1.o(.text+0x2c): error: undefined reference to 'abort' /opt/oecore-x86_64/sysroots/cortexa7-neon-vfpv4-oe-linux-gnueabi/usr/lib/crt1.o(.text+0x30): error: undefined reference to '__libc_csu_fini' /opt/oecore-x86_64/sysroots/cortexa7-neon-vfpv4-oe-linux-gnueabi/usr/lib/crt1.o(.text+0x38): error: undefined reference to '__libc_csu_init' /tmp/ccDJTrij.o:kobj.c:function init_hotplug_sock: error: undefined reference to 'bzero' /tmp/ccDJTrij.o:kobj.c:function init_hotplug_sock: error: undefined reference to 'getpid' /tmp/ccDJTrij.o:kobj.c:function init_hotplug_sock: error: undefined reference to 'socket' /tmp/ccDJTrij.o:kobj.c:function init_hotplug_sock: error: undefined reference to 'perror' /tmp/ccDJTrij.o:kobj.c:function init_hotplug_sock: error: undefined reference to 'setsockopt' /tmp/ccDJTrij.o:kobj.c:function init_hotplug_sock: error: undefined reference to 'bind' /tmp/ccDJTrij.o:kobj.c:function init_hotplug_sock: error: undefined reference to 'perror' /tmp/ccDJTrij.o:kobj.c:function init_hotplug_sock: error: undefined reference to 'close' /tmp/ccDJTrij.o:kobj.c:function main: error: undefined reference to 'memset' /tmp/ccDJTrij.o:kobj.c:function main: error: undefined reference to 'recv' /tmp/ccDJTrij.o:kobj.c:function main: error: undefined reference to 'puts' collect2: error: ld returned 1 exit status


這是因為沒有加入staticdev-pkgs
SDKIMAGE_FEATURES += "staticdev-pkgs"
SDKIMAGE_FEATURES相當於IMAGE_FEATURES, 但SDKIMAGE_FEATURES用於建立SDK image用, 如
$ bitbake -c populate_sdk imagename
SDKIMAGE_FEATURES可用的參數與IMAGE_FEATURES相同, 條列如下
  • allow-empty-password: Allows Dropbear and OpenSSH to accept root logins and logins from accounts having an empty password string.
  • dbg-pkgs: Installs debug symbol packages for all packages installed in a given image.
  • debug-tweaks: Makes an image suitable for development (e.g. allows root logins without passwords and enables post-installation logging). See the 'allow-empty-password', 'empty-root-password', and 'post-install-logging' features in this list for additional information.
  • dev-pkgs: Installs development packages (headers and extra library links) for all packages installed in a given image.
  • doc-pkgs: Installs documentation packages for all packages installed in a given image.
  • empty-root-password: Sets the root password to an empty string, which allows logins with a blank password.
  • package-management: Installs package management tools and preserves the package manager database.
  • post-install-logging: Enables logging postinstall script runs to the /var/log/postinstall.log file on first boot of the image on the target system.
  • ptest-pkgs: Installs ptest packages for all ptest-enabled recipes.
  • read-only-rootfs: Creates an image whose root filesystem is read-only. See the "Creating a Read-Only Root Filesystem" section in the Yocto Project Development Manual for more information.
  • splash: Enables showing a splash screen during boot. By default, this screen is provided by psplash, which does allow customization. If you prefer to use an alternative splash screen package, you can do so by setting the SPLASH variable to a different package name (or names) within the image recipe or at the distro configuration level.
  • staticdev-pkgs: Installs static development packages, which are static libraries (i.e. *.a files), for all packages installed in a given image.
Some image features are available only when you inherit the core-image class. The current list of these valid features is as follows:
  • eclipse-debug: Provides Eclipse remote debugging support.
  • hwcodecs: Installs hardware acceleration codecs.
  • nfs-server: Installs an NFS server.
  • qt4-pkgs: Supports Qt4/X11 and demo applications.
  • ssh-server-dropbear: Installs the Dropbear minimal SSH server.
  • ssh-server-openssh: Installs the OpenSSH SSH server, which is more full-featured than Dropbear. Note that if both the OpenSSH SSH server and the Dropbear minimal SSH server are present in IMAGE_FEATURES, then OpenSSH will take precedence and Dropbear will not be installed.
  • tools-debug: Installs debugging tools such as strace and gdb. For information on GDB, see the "Debugging With the GNU Project Debugger (GDB) Remotely" section in the Yocto Project Development Manual. For information on tracing and profiling, see the Yocto Project Profiling and Tracing Manual.
  • tools-profile: Installs profiling tools such as oprofile, exmap, and LTTng. For general information on user-space tools, see the "User-Space Tools" section in the Yocto Project Application Developer's Guide.
  • tools-sdk: Installs a full SDK that runs on the device.
  • tools-testapps: Installs device testing tools (e.g. touchscreen debugging).
  • x11: Installs the X server.
  • x11-base: Installs the X server with a minimal environment.
  • x11-sato: Installs the OpenedHand Sato environment.
    參考資料:
  • https://www.yoctoproject.org/pipermail/yocto/2017-March/035377.html




熱門文章