hidden hit counter
Thu. Nov 30th, 2023

This shall be a sequence of articles explaining how Linux kernel boots up on ARM structure. That is half one.

ARM Linux Boot Course of:

We’ll clarify boot strategy of AT91RM9200 system-on-chip, constructed across the ARM920T ARM Thumb processor. Kwickbyte builds an embedded board referred to as kb9202 based mostly on AT91RM9200. We’ll take this board for example and see how Linux boots up on this board.

Earlier than you begin studying this it is advisable learn AT91RM9200 information sheet (specification).

You additionally must learn ARM Structure Reference Guide for higher understanding the boot course of.

Parts in Linux Boot Course of:

Linux boot course of includes the next elements.

Bootloader

Kernel Picture

Root Filesystem

Earlier than we see how the above elements work, the next is the decision move of Linux Kernel boot course of for arm structure. This offers an enormous image on complete Linux boot course of. We use U-boot bootloader.

ARM Linux Boot Course of: Massive Image

U-boot:

_start (cpu/arm920t/begin.S)

start_code (cpu/arm920t/begin.S)

start_armboot (lib_arm/board.c)

board_init (board/kb9202/kb9202.c)

timer_init (cpu/arm920t/at91/timer.c)

serial_init (drivers/serial/at91rm9200_usart.c)

main_loop (lib_arm/board.c)

Now u-boot is up and operating and is in u-boot immediate and able to settle for instructions. Assume that kernel picture is loaded into RAM and issued bootm command.

do_bootm (frequent/cmd_bootm.c)

bootm_start (frequent/cmd_bootm.c)

bootm_load_os (frequent/cmd_bootm.c)

do_bootm_linux (lib_arm/bootm.c)

stext (linux/arch/arm/kernel/head.S)

Management is given to linux.

Linux Kernel:

stext (arch/arm/kernel/head.S:78)

__lookup_processor_type (arch/arm/kernel/head-common.S:160)

__lookup_machine_type (arch/arm/kernel/head-common.S:211)

__create_page_tables (arch/arm/kernel/head.S:219)

__arm920_setup (arch/arm/mm/proc-arm920.S:389)

__enable_mmu (arch/arm/kernel/head.S:160)

__turn_mmu_on (arch/arm/kernel/head.S:205)

__switch_data (arch/arm/kernel/head-common.S:20)

start_kernel (init/primary.c:529)

start_kernel (init/primary.c:529)

tick_init(kernel/time/tick-common.c:413)

setup_arch (arch/arm/kernel/setup.c:666)

setup_machine (arch/arm/kernel/setup.c:369)

lookup_machine_type ( )

setup_command_line (init/primary.c:408)

build_all_zonelists (mm/page_alloc.c:3031)

parse_args (kernel/params.c:129)

mm_init (init/primary.c:516)

mem_init (arch/arm/mm/init.c:528)

kmem_cache_init (mm/slab.c, mm/slob.c, mm/slub.c)

sched_init (kernel/sched.c)

init_IRQ (arch/arm/kernel/irq.c)

init_timers (kernel/timer.c:1713)

hrtimers_init (kernel/hrtimer.c:1741)

softirq_init (kernel/softirq.c:674)

console_init (drivers/char/tty_io.c:3084)

vfs_caches_init (fs/dcache.c:2352)

mnt_init (fs/namespace.c:2308)

init_rootfs ()

init_mount_tree (fs/namespace.c:2285)

do_kern_mount (fs/namespace.c:1053)

set_fs_pwd(fs/fs_struct.c:29)

set_fs_root(fs/fs_struct.c:12)

bdev_cache_init (fs/block_dev.c:465)

chrdev_init (fs/char_dev.c:566)

signals_init (kernel/sign.c:2737)

rest_init (init/primary.c:425)

kernel_thread (431, arch/arm/kernel/course of.c:388)

kernel_thread() creates a kernel thread and management is given to kernel_init().

kernel_init (431, init/primary.c:856)

do_basic_setup (888, init/primary.c:787)

init_workqueues (789, kernel/workqueue.c:1204)

driver_init (793, drivers/base/init.c:20)

do_initcalls (796, init/primary.c:769) /* Calls all subsytems init capabilities */

prepare_namespace (906, init/do_mounts.c:366)

initrd_load (399, init/do_mounts_initrd.c:107)

rd_load_image (117, init/do_mounts_rd.c:158) /* if initrd is given */

identify_ramdisk_image (179, init/do_mounts_rd.c:53)

handle_initrd (119, init/do_mounts_initrd.c:37) /*if rd_load_image is success */

mount_block_root (45, init/do_mounts.c:233)

do_mount_root (247, init/do_mounts.:218)

mount_root (417, init/do_mounts.c:334) /* if initrd not given */

mount_block_root (359, init/do_mounts.c:233)

do_mount_root (247, init/do_mounts.c:218)

init_post (915, init/primary.c:816)

run_init_process (847, init/primary.c:807)

kernel_execve (810, arch/arm/kernel/sys_arm.c:81)

Consumer Area

init() /*userspace /sbin/init */

Bootloader:

A bootloader is a small program which is able to load the kernel picture into RAM and boots up the kernel picture. That is additionally referred to as bootstrap because it brings(pulls) up system by loading an working system. Bootloader begins earlier than some other software program begins and initializes the processor and makes cpu able to execute a program like an working system. Most processors have a default deal with from which the primary bytes of code are fetched upon energy is utilized or board is reset. designers use this data to retailer the bootloader code at that deal with in ROM or flash. Because it ought to initialize the cpu and will run a program which is positioned at structure particular deal with bootloaders are extremely processor particular and board particular. Each embedded board comes with a bootstrap to obtain the kernel picture or standalone utility into the board and begin executing the kernel picture or utility. Bootloader shall be executed when energy is utilized to a processor board. Mainly it’s going to have some minimal options to load the picture and boot it up.

Additionally it is doable to manage the system utilizing a debug interface equivalent to JTAG. This interface could also be used to write down the boot loader program into bootable non-volatile reminiscence (e.g. flash) by instructing the processor core to carry out the mandatory actions to program non-volatile reminiscence. Usually achieved for first time to obtain the fundamental bootloader and for some restoration course of. JTAG is an ordinary and fashionable interface supplied by many board distributors. Some micro controllers present particular interfaces which might’t be used to take arbitrary management of a system or immediately run code, however as a substitute they permit the insertion of boot code into bootable non-volatile reminiscence (like flash reminiscence) through easy protocols. Then on the manufacturing part, such interfaces are used to inject boot code (and probably different code) into non-volatile reminiscence. After system reset, the micro controller begins to execute code programmed into its non-volatile reminiscence, similar to regular processors are utilizing ROMs for booting. In lots of instances such interfaces are carried out by hardwired logic. In different instances such interfaces might be created by software program operating in built-in on-chip boot ROM from GPIO pins.

There are another third occasion bootloaders out there which offer wealthy set of options and straightforward consumer interface. You possibly can obtain these third occasion bootloaders into board and might make them default bootloaders on your board. Usually bootloaders supplied by board distributors are changed with these third occasion bootloader. There are a fairly few third occasion boolader out there and a few of them are open supply (or free bootloaders) and a few are business. A few of them are Das U-Boot, Crimson boot, GRUB (for desktops), LILO, Loadlin,, bootsect-loader, SYSLINUX, EtherBoot, ELILO.

We’ll take U-boot boot loader as our boot loader. U-boot is the extensively used boot loader in embedded programs. We’ll clarify code from the u-boot-2010.03 supply. You possibly can obtain U-boot from the next website. http://www.denx.de/wiki/U-Boot

How U-boot is constructed:

Based mostly on the configuration of U-boot, all of the meeting recordsdata (.S) and C recordsdata (.c) are compiled utilizing cross compiler which is constructed for a selected structure and object recordsdata(.o) shall be generated. All these object recordsdata are linked by linker and an executable file shall be created. An object file or executable file is a group of sections like.textual content,.information,.bss and many others. Object recordsdata and executable recordsdata have a file format like elf. All of the sections of the article recordsdata shall be organized within the executable file based mostly on a script referred to as linker script. This script tells the place all of the sections are to be loaded within the reminiscence when it runs. Understanding this script is essential to know the way boot loader and kernel are composed and the way completely different sections of boot loader or kernel are loaded within the reminiscence.

Usually, when a program is run (executed) a loader reads executable file and hundreds completely different sections of the executable file within the specified reminiscence location and begins executing the beginning operate(entry level) specified within the linker script. However, if you wish to run(load) a boot loader there is not going to be any loader to load(principally to know the file format) completely different sections of executable file into the reminiscence. Then it is advisable use a instrument referred to as objcopy which is able to take all sections from the executable file and create a binary file which does not have any file format. This binary file may be loaded into the reminiscence and executed or may be written in to the ROM at a selected deal with (particular to the structure) which shall be executed by cpu when energy is utilized to the board.

Assume that based mostly on the U-boot configuration all recordsdata are compiled and object recordsdata are created. U-boot makefile makes use of the next linker script (particular to structure) to construct an executable file.

File: cpu/arm920t/u-boot.lds

32 OUTPUT_FORMAT(“elf32-littlearm”, “elf32-littlearm”, “elf32-littlearm”)

33 OUTPUT_ARCH(arm)

34 ENTRY(_start)

35 SECTIONS

36

OUTPUT_FORMAT in line #32 specify the file format of the executable file. Right here the executable file format is elf32 and endianness is little endian. OUTPUT_ARCH in line # 33 specify the structure on which this code runs. ENTRY in line #34 specifies the beginning operate(entry level) of u-boot program. Right here the entry level is _start.

SECTIONS in line #35 defines how completely different sections are mapped within the executable file. Loader makes use of the addresses specified on this part to load completely different part of this system into the reminiscence.

‘.’ within the line #37 specifies the beginning deal with the place the next sections ought to be loaded. On this case begin deal with is 0x00000000. After this in line #39 the reminiscence is aligned by four bytes and the.textual content part follows within the line #40.

40.textual content:

41

On the ‘.’ place (0x00000000) the code within the cpu/arm920t/begin.o is mapped and follows the code that’s there in.textual content sections of all different object (.o) recordsdata. cpu/arm920t/begin.o accommodates the _start() operate(in meeting language) which is entry level of this program.

Now the ‘.’ shall be at 0x00000000 + sizeof (.textual content). Once more reminiscence is aligned by four bytes and.rodata part follows in line #47.

. = ALIGN(four);

47.rodata:

.rodata sections from all objects recordsdata are mapped at this deal with. Follows the.information and.git sections.

49. = ALIGN(four);

50.information:

51

52. = ALIGN(four);

53.acquired:

Every U-boot command is an object of sort ‘cmd_tbl_t’ which accommodates command title, assist string and performance pointer to be executed when this command is run. All these command objects are positioned within the reminiscence sequentially. Every of this command object is constructed into an U-boot outlined part referred to as.u_boot_cmd within the object file. These all.u_boot_cmd sections are positioned within the reminiscence after the above sections(.information and.git).

. =.;

56 __u_boot_cmd_start =.;

57.u_boot_cmd:

58 __u_boot_cmd_end =.;

__u_boot_cmd_start accommodates the beginning of the instructions objects and __u_boot_cmd_end accommodates the tip of the command objects.

And subsequent follows the.bss (uninitialized international variables) sections.

60. = ALIGN(four);

61 __bss_start =.;

62.bss (NOLOAD):

63 _end =.;

__bss_start factors to the.bss begin deal with and _end accommodates the tip of the all sections.

Utilizing this linker script linker will generate an executable file referred to as u-boot. Objcopy instrument is used to generate a binary file from the u-boot executable file.

u-boot.bin: u-boot

$(OBJCOPY) $ -O binary $

By admin

Leave a Reply

Your email address will not be published. Required fields are marked *