Skip to content

How to build minimalistic kernel image for ARC

Palmyr3 edited this page May 10, 2019 · 1 revision

Here you can find instruction for building minimalistic image for single core ARC HS38 CPU which could be run in nSIM simulator. You can adopt this instruction to build image for your custom platform. In that case in addition you need to configure HW-specific options on Buildroot and kernel configuration steps.

before start

You need to have linux machine with following components installed/downloaded:

  • linux kernel sources
  • buildroot sources
  • ARC toolchain

You need to export following environment variables:

export ARCH="arc"
export CROSS_COMPILE="arc-linux-"

TIP: You can find more detailed instructions on buildroot using in this article: How to build filesystem and kernel images for ARC cores with Buildroot

build file system image

Go to buildroot sources directory and launch buildroot configuration tool:

make menuconfig

Target HW-related configuration:

  • Choose 'Target Architecture' -> 'ARC (little endian)' (BR2_arcle))
  • Choose 'Target CPU' -> 'ARC HS38' (BR2_archs38)
  • Don't forget to choose correct HW configuration options like 'MMU Page Size' and 'Atomic extension' availability. In this case they are 'MMU Page Size' -> '8KB' (BR2_ARC_PAGE_SIZE_8K) and 'Atomic extension' (BR2_ARC_ATOMIC_EXT) -> 'no'.

Generic configuration to decrease image size:

  • Enable binaries striping (BR2_STRIP_strip) -> 'yes'
  • Set gcc optimization level to 'optimize for size' (BR2_OPTIMIZE_S)
  • Build everything vith static libraries: libraries -> static only (BR2_STATIC_LIBS)
  • Disable Uclibc utils: (BR2_UCLIBC_INSTALL_UTILS) -> 'no'

Miscellaneous generic configuration:

  • Generate CPIO archieve with file system. (BR2_TARGET_ROOTFS_CPIO) -> 'yes'

In this case you'll get following buildroot defconfig:

BR2_arcle=y
BR2_archs38=y
# BR2_ARC_ATOMIC_EXT is not set
BR2_STATIC_LIBS=y
# BR2_UCLIBC_INSTALL_UTILS is not set
BR2_TARGET_ROOTFS_CPIO=y

After the end of buildroot configuration you can launch busybox configuration tool to adjust the list of target utils you build.

make busybox-menuconfig

You can significantly decrease file system image size if you remove all utilities you don't need. However this step is optional.

After the end of all configurations you can build file system image with following command:

make

After the end of build you can found file system image rootfs.cpio in output/images/ folder.

build linux kernel image

Go to linux kernel sources directory and generate minimalistic kernel image configuration:

make tinyconfig

Ater that you can launch kernel configuration tool:

make menuconfig

You should perform following configurations:

  • ARC Architecture Configuration (ISA, CPU, etc)
  • Enable serial console (enable options PRINTK, SERIAL_ARC_CONSOLE, SERIAL_ARC, TTY)
  • Build-in rootfs you got with buildroot on previous step (INITRAMFS_SOURCE)
  • Choose device tree blob and build it in (ARC_BUILTIN_DTB_NAME -> "nsim_hs")
  • Enable support of ELF abd scripts executables: (enable options BINFMT_ELF, BINFMT_SCRIPT)
  • [optional] Enable (PROC_FS) to be able to check memory availability in runtime

In result you'll get following kernel defconfig:

# CONFIG_LOCALVERSION_AUTO is not set
# CONFIG_CROSS_MEMORY_ATTACH is not set
CONFIG_LOG_BUF_SHIFT=15
CONFIG_BLK_DEV_INITRD=y
CONFIG_INITRAMFS_SOURCE="/home/user/buildroot/output/images/rootfs.cpio"
# CONFIG_RD_BZIP2 is not set
# CONFIG_RD_LZMA is not set
# CONFIG_RD_XZ is not set
# CONFIG_RD_LZO is not set
# CONFIG_RD_LZ4 is not set
CONFIG_CC_OPTIMIZE_FOR_SIZE=y
# CONFIG_MULTIUSER is not set
# CONFIG_SYSFS_SYSCALL is not set
# CONFIG_FHANDLE is not set
# CONFIG_POSIX_TIMERS is not set
# CONFIG_BUG is not set
# CONFIG_BASE_FULL is not set
# CONFIG_FUTEX is not set
# CONFIG_EPOLL is not set
# CONFIG_SIGNALFD is not set
# CONFIG_TIMERFD is not set
# CONFIG_EVENTFD is not set
# CONFIG_SHMEM is not set
# CONFIG_AIO is not set
# CONFIG_IO_URING is not set
# CONFIG_ADVISE_SYSCALLS is not set
# CONFIG_MEMBARRIER is not set
# CONFIG_KALLSYMS is not set
CONFIG_EMBEDDED=y
# CONFIG_VM_EVENT_COUNTERS is not set
# CONFIG_COMPAT_BRK is not set
CONFIG_SLOB=y
# CONFIG_SLAB_MERGE_DEFAULT is not set
# CONFIG_ARC_HAS_LLSC is not set
# CONFIG_ARC_CURR_IN_REG is not set
# CONFIG_ARC_DBG is not set
CONFIG_ARC_BUILTIN_DTB_NAME="nsim_hs"
# CONFIG_BLOCK is not set
# CONFIG_COREDUMP is not set
# CONFIG_COMPACTION is not set
# CONFIG_UEVENT_HELPER is not set
CONFIG_DEVTMPFS=y
CONFIG_DEVTMPFS_MOUNT=y
# CONFIG_STANDALONE is not set
# CONFIG_PREVENT_FIRMWARE_BUILD is not set
# CONFIG_FW_LOADER is not set
# CONFIG_ALLOW_DEV_COREDUMP is not set
# CONFIG_INPUT is not set
# CONFIG_SERIO is not set
# CONFIG_VT is not set
# CONFIG_UNIX98_PTYS is not set
# CONFIG_LEGACY_PTYS is not set
# CONFIG_DEVMEM is not set
CONFIG_SERIAL_ARC=y
CONFIG_SERIAL_ARC_CONSOLE=y
# CONFIG_HW_RANDOM is not set
# CONFIG_HWMON is not set
# CONFIG_USB_SUPPORT is not set
# CONFIG_VIRTIO_MENU is not set
# CONFIG_IOMMU_SUPPORT is not set
# CONFIG_VALIDATE_FS_PARSER is not set
# CONFIG_FILE_LOCKING is not set
# CONFIG_DNOTIFY is not set
# CONFIG_INOTIFY_USER is not set
# CONFIG_PROC_SYSCTL is not set
# CONFIG_PROC_PAGE_MONITOR is not set
# CONFIG_SYSFS is not set
# CONFIG_MISC_FILESYSTEMS is not set
# CONFIG_ENABLE_MUST_CHECK is not set
# CONFIG_SECTION_MISMATCH_WARN_ONLY is not set
# CONFIG_FTRACE is not set
# CONFIG_RUNTIME_TESTING_MENU is not set

After the end of all configurations you can build kernel with following command:

make

launching

Image you build can be launched in nSIM simulator via following comand:

mdb -nsim -av2hs -prop=cpunum=0 -mmuv4 -Xrtc -Xatomic -Xtimer0 -Xtimer1 -Xmpyd -Xqmpyh -Xdiv_rem -toggle=deadbeef=1 -prop=nsim_mem-dev=uart0,base=0xc0fc1000,irq=24 -prop=mmu_pagesize=8192 -prop=mmu_super_pagesize=2097152 -prop=mmu_stlb_entries=16 -prop=mmu_ntlb_ways=4 -prop=mmu_ntlb_sets=128 -icache=16384,64,2,o -dcache=16384,64,4,o -prop=nsim_isa_aps_feature=1 -prop=nsim_isa_num_actionpoints=4 -prop=nsim_isa_aps_feature=1 -prop=nsim_isa_ll64_option=1 -prop=nsim_isa_rtc_option=1 -prop=nsim_isa_core=3 -noprofile -OK vmlinux
Clone this wiki locally