Structure and development of windows ce oal Layer

Source: Internet
Author: User

 

Author: Qi Xiaojing Wang Weidong Wang Jian

Introduction
Windows CE Microsoft has launched a brand new operating system for the embedded field. Although Windows ce ui is very similar to other Windows operating systems, its kernel is completely rewritten, it is not a simplified version of any desktop version of Windows. Windows CE is an operating system that supports multiple CPU architectures, including arm, x86, MIPS, and shx, which greatly reduces the workload of porting an operating system during 0em development.
Operating System transplantation involves two levels of work: one is the CPU level and the other is the board level. CPU-level porting is usually done by Microsoft or chip manufacturers, while board-level porting is done by OEMs. OAL is the core of OEM's work to transplant this system!

1 oal
The full name of oal is the OEM adaption layer, that is, the adaptation layer of the original device manufacturer. In terms of logic structure, oal is located between the kernel and hardware of the operating system and is the hub connecting the system and hardware. In terms of functions, oal is similar to the BIOS on the desktop, device initialization, operating system boot, and abstract hardware functions. Unlike B10s, 0al is affiliated with the operating system and is part of the operating system. In terms of the method of existence, oal is a collection of functions. These functions reflect 0al functions, as shown in 1.

2. Minimal oal
The primary task of the oal layer is to load the kernel. In the oal layer, the set of functions that pave the way for Kernel startup forms the smallest oal layer. We can go deep into the 0al layer, as shown in figure 2.

First, let's take a look at the OS startup sequence.
① The CPU executes the boot vector and jumps to the hardware initialization code, that is, the startup function;
② After the start up function completes the minimum hardware environment initialization, jump to the kernelstart function (the kernel initial-ize function when the CPU is X86 architecture) to initialize the kernel;
③ The kernelstart function calls the oeminitdebugserial function to initialize the debug serial port, call the 0eminit function to complete hardware initialization, set the clock and interrupt, and call the oemgetextensiondram function to determine whether there is another dram.
So far, the kernel has been loaded. It can be seen that the most important thing to start an OS is to correctly load the startup function.
2.1 startup
The feature of the startup phase is that the kernel has not been loaded, making debugging difficult. The two core tasks of the startup function are to initialize the CPU to a known state and call the kernel initialization function to initialize the kernel. The following are the general content of the startup function:
① Set the processor to the monitoring mode;
② Disable cpu irq and FIQ input;
③ Disable Memory Management Unit MMU and command and data cache;
④ Refresh commands and data cache, TLB, and clear write buffr;
⑤ Determine the reason for startup: hard reset, wake from sleep,
Gpio reset, watchdog reset, eboot handoff;
⑥ Configure gpio according to the target board, such as the gpio connected to the LED;
7. Configure the Memory Manager and set the refresh frequency to enable the clock;
Configure the interrupt controller;
The real-time clock (RTC) initialized by the worker is 0, enabling real-time clock;
⑩ Sets the power management register;
⑾ Enable all board-level clock and internal and external clock;
Secret gets the physical base address of oemaddresstable and stores it in R0;
Redirect to kernelstart.
Both Bootloader and OAL contain the startup function. The minimum hardware environment must be initialized. Bootloader is preparing the hardware environment for its own execution, while oal is preparing the hardware environment for the kernel execution. Since these two hardware environments have the same requirements, most of their code can be used for reference. However, we should understand that Bootloader and OAL are physically independent and they are not the same piece of code. In addition, if you can determine that this hardware part of the bootloader has been initialized, you do not need to repeat it in OAL. Of course, the premise is that each load must go through the bootloader step. The most typical example is startup in x86 OAL. See the routine:
Naked_startup ()
{_ ASM
{
CLI
JMP kernelinitialize
}
}
After s t a r t u p is executed, jump to k e r n e 1 s t a r t/kemellnitialize (under x86 ).
2.2 kernel start
Kernel start is used to initialize the minimum kernel and call the oeminit function to initialize the board-level hardware. The following is the ARM Kernel initialization process:
① Initialize the first-level page table;
② Enable MMU and cache;
③ Enable stack for each working mode );
④ Relocates the kernel;
⑤ Execute the serial port debugging function;
6. Call oeminit;
7. initialize the memory;
Other initialization tasks.
Among the three functions used in kernelstart, oeminit (), oeminitdebugserial (), and oemgetextensiondram (), the oeminit () hardware is highly relevant and most important. (1) The minimum task of oemlnit () 0eminit is to initialize other hardware and register the system clock. Generally, oeminit should do the following.
① Set the following values to interrupt ing table sysintr → IRQ and IRQ → sysintr.
② Set static interrupt ing in the interrupt ing table.
③ Set kitl, but kitl is not usually included in the minimized oal layer.
④ Use init clock to configure the system timer, real-time clock, and clock.
⑤ Determine the interrupt source of the system clock.
6. the kernel initialization time is 1 ms.
7. Configure the interrupt controller or Programmable Interrupt Controller (PICs ).
LEDs for debugging are provided.
Reset to pwritededugled = oemwritededugled.
The supervisor calls the hookinterrupt function to register the interrupt service routine ISRs. The following example shows how to handle the interrupt service routine of timerisr hardware interrupt 5:
Void oeminit (void)
{...
Hookinterrupt (5, timerisr); // registers for timer interruption
...
}
The Interrupt Mask is cleared to prevent requests for interruption during kernel initialization.
(2) Serial Port debugging Functions
Limited debugging methods are a common problem for 0 s porting staff. Although the serial port debugging function is not as powerful as the Ethernet port debugging function, it is still much more intuitive than the LED indicator or digital tube. It is an indispensable tool for debugging oal layer code. This function group consists of four functions: 0 e m I n I t d e B u g s e r I A L (), oemreaddebugbyte (), oemwritedebugbyte () and oemwritedebugstring ().
◇ Oeminitdebugserial () is used to configure the serial port;
◇ Oemreaddebugbyte0 and oemwritedebugbyte () are used to read and write one byte to the serial port;
◇ Oemwritedebugstring () is used to write a debugging string to the serial port.
In kernelstart, oeminitdebugserial () is called to complete serial port initialization and prepare for serial port debugging.
(3) oemgetextensiondram ()
In the simplest function to minimize the oal layer, oemgetextensiondram () is not a required function. The main function of oemgetextensiondram () is to check whether another dram exists. If the target board has only one dram, this function returns false. But this function is usually included in kernelstart.
At this point, the minimum oal layer has been completed, and the most basic features of the kernel can be used normally. When the skeleton was set up, the first phase of the task came to an end, but many very important functions are not complete yet, and it is impossible to make the best use of things. Therefore, we need to further enhance the oal layer functions. This method is also commonly used in oal layer development. Complete the basic functions first, and gradually add other functions after the basic functions are correct. Step by step, even if an error occurs, it is easy to find the error location for troubleshooting.

3. Enhance oal
The second stage aims to make full use of the hardware resources on the board and strengthen debugging methods. It includes interrupt, kitl, Ethernet port debugging function, and oemiocontrol. The oal layer that includes these four aspects is called enhanced OAL.
3.1 moderate disconnection
The data exchange between peripheral hardware and CPU is basically asynchronous and the most common interrupt mode. The sequence of Ce interrupt processing is shown in 3. Figure 3 shows that the CE interrupt is actually composed of two parts: ISR and ist. Ist is included in the driver, while ISR is included in the oal layer. Therefore, to support a hardware, you must first prepare it from the 0al layer. This preparation is completed in two steps.

① Create an interrupt identifier. The following code is excerpted from oalintr. h of samsung2410. The interrupt ing table is usually in <ceversion>/platform/<platform Name>/Inc.
# Define sysintr USB (syslntr firmware + 11)
# Define sysintr usbd (syslntr_firmware + 12)
② Create and register ISR. The main task of Isr is to return the interrupt identifier. ISR code is usually located under <ce version>/platform/<platformname>/kernel/hal.
The following code is excerpted from armint. C of samsung2410.
If (intpendval = intsrc_adc ){
S2410int.> rlntsubmskl = bit_sub_tc;
S2410int _> rintmsk | = bit_adc;
S2410int _> rsrcpnd | = bit_adc;
S2410int _> rintpnd = bit_adc;
Return (sysintr_touch );
}
In interrupt processing, three other functions also play a crucial role. It is oeminterruptenable (), oeminterruptdisable (), and oeminterruptdone ().
◇ Oeminterruptenable () is used to perform hardware operations that allow device interruption;
◇ Oeminterruptdisable () prohibits devices from sending interrupt requests;
◇ Oeminterruptdone () is terminated.
3.2 Ethernet port debugging Function
The Ethernet port debugging function is faster than the serial port debugging function.
◇ Oemethinit initializes the Ethernet debugging port;
◇ Oemethenableints enable Ethernet Adapter interruption;
◇ Oemethdisableints Ethernet Adapter disconnection;
◇ Oemethisr Ethernet Adapter Service interruption routine;
◇ Oemethgetframe receives data from the Ethernet debug port;
◇ Oemethsendframe sends data from the Ethernet debugging port;
◇ Oemethqueryclientlnfo: obtain information about the platform;
◇ Oemethgetsecs returns the time value starting from a specific time. This function is used to process timeout.
3.3 kitl
Kitl is called the kernel independent transportlayer. Its main purpose is to provide more convenient debugging methods, as shown in figure 4. After kitl appears in Windows ce.net, it isolates the software transfer protocol from the hardware transport layer. Kitl makes it unnecessary for developers to understand how the hardware transport layer interfaces with the software protocol layer.
The following is the kitl initialization code that should be added to the oeminit function.
① Initialize all PCI bridges and devices, enumerate them, allocate resources to them, and then enable them to work properly. Note: This is suitable for the scenario where the kitl network interface card (NIC) and nic bridge are available.
② Initialize the relevant bus so that the CPU can correctly identify the NIC.
③ Call the kitlinit function to initialize kitl. This part of code can be used on other platforms. The code file is halkitl. C.
④ Execute the 0emkitlinit function to initialize the relevant hardware. Search for the existence of the kitl network port, serial port, or parallel port connection.
⑤ After oemkitlinit is executed, include kitl.1ib and kitleth.1ib in the platform resource file/<platform>/kernel/buildexe/kernkitl to package kitl into the kernel. For other functions of kitl, refer to Microsoft msdn.

3.4 oemiocontrol
Oemiocontr01 is a very important function in the oal layer. Applications call kerneliocontroi to call oeml0control. The kernel calls the kernel to obtain information about many hardware platforms. In addition, 0eml0contr0i is also the entry for converting user-mode application code to kernel-mode oal code. This means that the kernel mode can be obtained by calling 0eml0control in user mode. The 0emiocontrol function is prototype as follows:
Bool oemiocontrol (......)
{Switch (dwlocontrolcode)
{Caseioctl_hal_set_device_info:
Case10ctl_hal_reboot:
......
Default:
Return false;
}
Return true:
}
The use of hardware resources and the strengthening of debugging methods greatly enrich the oal functions. However, the power consumption of embedded systems and the security issues caused by the increasing popularity of network functions are not involved.

4. Complete oal
Complete oal refers to the oal that expands power consumption and security verification based on enhanced OAL. Therefore, this phase mainly focuses on power management and module authentication.
4.1 Power Management
The power management of the oal layer is quite different from that of the driver. A device driver is only responsible for a specific device. If possible, the device is set to power-saving mode, and the device is set to full load mode when necessary. The power management of the oal layer is responsible for managing the power consumption of the entire system. For example, when the scheduler has no thread to run for the next 25 ms, the system will be set to power-saving mode.
The power management function responds to system calls that shut down the system and make the system idle. These system calls may be soft or hard. The following two functions are power management functions that must be implemented in the oal layer:
◇ 0emidle sets the device to idle one by one, and the system is in a low power consumption state;
◇ 0empoweroff one by one sets the device to the power-off status;
◇ Oempoweroff and oemidle program code can be found in the following directory by referring to the routines % _ wincer00t %/platform/<platform>/kerlael/hal.
4.2 Module Authentication
Since Windows CE 3.0, the kernel can perform authorization verification before loading and running modules in Ram. This process is not required for modules running in Rom. Module authentication actually adds a digital signature after the loaded module. This module can be loaded into Ram only when the system verifies the digital signature with a public key. In this way, the system can block or limit the running of some modules to achieve the purpose of system security.
To achieve the above objectives, you must complete the following two functions:
◇ Oemcertifymoduleinit is used to initialize the verification process. Each verification module is called once;
◇ Oemcertifym0dule, used to verify the digital signature.
To support these two functions, the oeminit function must allocate two global variables poemloadinit and p0emloadmodule to store the addresses of these two functions.

Conclusion
The oal layer of Windows CE is a complex function set. Its complexity is not only reflected in the large number of functions, but also in the high hardware relevance of many functions. This article does not explain in detail each oal layer function, but rather layer-by-layer division of some common oal layer functions. While explaining the functions and structure of the oal layer, put forward a method and idea for developing OAL.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.