Interpreting the code process of Wince 5.0 kitl

Source: Internet
Author: User

Author: walzerlupa open-source community $ E & y5e) zt c0k * fo5g
Date: 2005.3.19
} 9ft3kf4h0walser's Lupa open-source community x + my @; R * j, Q

Lupa open-source community $ F/1wg0x + qoiad

Bytes

Lupa open-source community ^ af lulh

_ K9_2p4s # b8p {I/0m0 Abstract: kitl is a highlight in platform builder. It provides breakpoint, variable tracking, memory viewing, and other methods similar to local debugging. If kitl is not available, embedded debugging should only be able to print messages through serial ports, greatly reducing the work efficiency. This article aims to implement the simplest serial kitl and trace and debug the Code. The Code spans the three main directories of platform, public, and private of wince, which are cumbersome, however, as long as the call can be made, all work and detours are worthwhile. I wrote down debugging experience and my personal understanding, hoping to help others avoid detours. If you have any improper understanding in this article, please do not hesitate to give me some advice. Lupa open source community) j0g % GQ 'f] F

5l ~ P2D a9xv8j2ku {0 text: Lupa open source community nt .?? F) Cf
Lupa open-source community yu I; I v9tv l! Ad v
1. Void oeminit () [platform/project/src/kernel/oal/init. C] Lupa open source community g (V. Y :~ N2 ~ + M9f
Start with the oeminit () function .. After the branch-target buffer, kernel function, initialization interrupt, and timer are initialized in sequence, it is kitl's turn. The oalkitlstart () function is called (). At this time, there is a compilation branch. If it is the release version, then in the kernel/Kern/stubs. the oalkitlstart () function in C is a stub, but return true. If it is a debug version, go to kernel/oal/kitl. oalkitlstart () in C (). lupa open-source community Wh + cr6r

Lupa open-source community $ n? 5y ~, YF & C

Ii. bool oalkitlstart () [platform/myproject/src/kernel/oal]
Hd5 G ^ I5 {5f'g0 in oalkitlstart (), first tries to read the kitl parameter left in the bootloader from 0xa00ff00. If you cannot read anything, use the default configuration in this function. Since Ethernet was used as both the download and kitl paths, pkitlargs struct is assigned in the initspecifiedethdevice function. Now we want to clearly divide the two. First, we should read the kitl parameter in the Bootloader and force it to use our default configuration below. Fill in three parameters.

X} m/mupassive P % J0

# K3k/] G %} + 's3fu01. First, this structure is the Lupa open-source community l sy; q5b eujc
Oal_kitl_args pkitlargs
VO * x4lb}. V0 {Lupa open source community: uox _) b1pmll
Uint32 flags; // set the enabled flag. Set the poll flag as needed, but be sure not to set the passive flag to the Lupa open source community D _, y 'q % U3/z1o.
Device_location devloc;
% Lenr "XM, @ J/M0 {
{H y 'K R. II; '+ N0 DWORD ifctype; // whether ether or serial is set to internal type = 0; Lupa open-source community 3y7gefwb
DWORD busnumber; // = 0
/NT! O "x + zltyir0 DWORD logicalloc; // physical address
#} 3ssj] gf8t7l0 pvoid physicalloc; // leave it behind = oalpatova (logicalloc, false?
) Ro {1fef0 DWORD pin; // Dongdong Lupa open-source community used by Ethernet "/; o g fy ~ X (|. u
} Lupa open-source community 5O Q/z2pf # KD
Unionlupa open-source community wl4hc3oh T ~ {Q
{Lupa open-source community f * TBL o mu_2s ^ 9C Z
Struct
6qho O ~ 8u: I | 5y4s0 {
J craz + gek0 uint32 baudrate; // No need to explain the Lupa open-source community ghl. k N * AE _. h
Uint32 databits; Lupa open source community fe m & P-p0gO
Uint32 stopbits; Lupa open source community} I % h5z/-I
Uint32 parity; Lupa open-source community: vk5t, HR, Iy
} Lupa open-source community N, P // J @
Structlupa open source community E1Fm-ei2Krp
{Lupa open-source community J jirv |, P
Uint16 Mac [3]; // This does not need to be explained in Lupa open-source community/G5} P_w! G: So 'a
Uint32 IPaddress; Lupa open source community) m; vf1fl
Uint32 ipmask;
IC | 4sc! _ ^ 0 uint32 iproute
M & [3o8e | 6j0} Lupa open source community 8? [5xu-d L
}
BX $ gkq & N @ C (Am %} @ 0} Lupa open source community # BK/D/I) p1v
2. pszdeviceid. It seems that this name is fun. It should be awkward to assign it to Walzer, but it is better to keep the original amoisoft to avoid being beaten.
# W9v2lw, F7 [7wbe03. global variable oal_kitl_device g_kitldevices. this stuff is in kitl. kitl_cfg.h contained in the beginning of C is assigned a value. The most important thing is to modify g_kitldevices.pdriver. this pdrvier points to the struct of a function pointer list, which defines functions such as initialization, read/write, interrupt, and flow control for the kitl module. G_kitldevices is a two-dimensional array that defines the parameter settings provided by many devices when using kitl, a For clause will be used to cyclically determine which one-dimensional array member matches the pkitlargs parameter in g_kildevices. lupa open-source community 6y e 'yv. c7gcb

Lupa open-source community S/E [G/S (

After these three parameters are filled, you can enter the oalkitlinit (pszdeviceid, pkitlargs, g_kitldevices) inside the. Lupa open source community BX $ {(f4RA7KI-aw

& F 'lo q0f? C0 III. bool oalkitlinit (DeviceID, pargs, pdevice) [platform/common/src/common/kitl. C]
) Z (hb2n, M # P N0. This function first prints out all input parameters using oalmsg. Lupa open-source community N'-y' q d ({0j g
It is important to introduce the g_kitlstate global variable. The first sentence is
$ I H * @ A $ tg1u5qc0 g_kitlstate.pdevice = oalkitlfinddevice (& pargs-> devloc, pdevice) This is what we call loop judgment from the list of available devices in g_kitldevices, find the matching function pointer of the selected device.
9 h./9 | T % c1ush '1b9n0 then copy the input parameter devicdid and the previously filled oal_kitl_args structure to the Lupa open source community F (hlk [8w9 _
Then you can call kitlinit (true). If the passsive mark is set in the flag, now it's kitlinit (false.

5a3w'vms + gq0

[# PZ [L! N: W/mw0 IV. bool kitlinit (bool fstartkitl) [private/winceos/coreos/nk/kitl/ethdbg. C] Lupa open source community o yhx4i "M f
It's too cumbersome. I need to use a serial port. It's actually called ethdbg. C, and I don't want to give it a face. It's just something in private that can be viewed remotely and cannot be used ~~
I) | o # The v3a iwr0 function does three things: vipnd, Lupa open-source community
1. Three global function pointers are loaded.
8e6 | k7nc -~ 02. Use newclient to register three kitl clients: Lupa open-source community y $ SS4 [} Q # T ~ U % W?
Kitl_svcname_dbgmsg // debug message, debug information release channel: Lupa open-source community d2l2f! Yq9wgycy) |
Kitl_svcname_ppsh // ppshell, Lupa open-source community 4t0 [% we1g w8xk * f9b
Kitl_svcname_kdbg // kernel debug, kernel debugging Interface

/_ 8B} ({7vu NG0

'3y5' DL/t03. fstartkitl determines whether to start the startkitl () function. (By The Way, according to the Hungarian naming method, add B before the bool variable, but I think it is reasonable to use Ms. The bool variable is a flag. Add F before it, save the Small B to the byte type .)

A % Q: hrp2u! P7s: P0

, | 6q %? [Bq0 v. Static bool startkitl (bool finit) [private/winceos/coreos/nk/kitl/ethdbg. C] Lupa open source community Nb. R2xAE-i
This is the stuff in prviate. The most painful part begins. This function and its sub-functions will call the kitl module initialized and read/write program written by the OEM for the first time. It's a scorpion, it's a horse. Just pull it out and you will know ~ Lupa open-source community [& O & H9 _ ^ 1l & x $ DSG
First, judge whether the input parameter needs to start kitl. If kitlglobalstate is marked with kitl_st_desktop_connected, the following steps are skipped. Of course, this is the first time we run it here. If this happens, I will be Ma Jiajue. Lupa open-source community ./#? 4upy v6if 'n3s

U. KDF. _ 0 K % H; lf0 Step 1:
'D % | w2a; a 'B ue_0 the first thing to do is to call oemkitlinit (& kitl ). this is detailed later. continue reading this function. lupa open-source community/baao:} imq v
Oemkitlinit initializes the hardware abstraction layer of kitl and fills in the relevant pointer data to the global variable kitltransport kitl (whether it is wrong, why not g_kitl ), after the work is done, return to the Lupa open-source community 7m2z q {p2k2v
After startkitl receives the goods, it checks the entire kitl structure. If yes, pay the order immediately and mark the global variable kitlglobalstate with kitl_st_kitlstarted. This is the first step for kitl to start.

6 h (L (r A (B/n ~ J_1f0

(F m) H + N, C + ho0 Step 2: Lupa open source community 't1g9 {x P
The next step is kitlconnecttodesktop (). After entering this function, we used the Read and Write Functions in the hardware abstraction layer of the kitl transmission media for the first time. Now we need to debug the functions. this connecttodesktop generally sends a kitl ..... and then polling waits for the PC response, and then sends another kitl ..... the frame is like a dark number of the underground party. In fact, there is nothing mysterious, that is, adding a dedicated ktil header before a common data packet. after the connection is successful, a kitl_st_desktop_connected mark will be added to the kitlglobalstate. lupa open-source community [tn; g1w {

/? * T. M &] & n0e * XY * jyq0 Step 3:
AWM # Q) bg0h t0 set up kernel function pointers, there is nothing, just three function pointers, after the assignment, it will kitl_st_adapter_initialized. in fact, this kitlgolbalsate has a total of seven marks, namely the Lupa open-source community o5l) jrq
Kitl_started, (OK)
TS + c u * I, r j0'/01_top_connected, (OK) Lupa open source community # An & G. U * s # SCX
Timer_init ,(?)
IR * _ bq0int_enabled, (polling)
0f_7swm + fy r! @-H + k] 0ist_started, (polling) Lupa open source community y # t3xyjd7ep
Multithreaded ,(?)
. ID! ^ S (_ 0adapter_initialized. (OK)
Ncn4per8g0 has been completed here by adding "OK" in the brackets. I am not quite clear about the function of question mark. For int and ist items, we use polling, so it is definitely not needed.

B? D ^ Zi! D0lh: | 5? 0

W2y + C /&~ 7 ~ Step 4:
7jl0t: zq0g; nb0 calls setkernelcommdev to set the media in which the kernel transmits DbgMsg, ppsh, and kdbg. Lupa open-source communities # x9l "o.s ~ V & n t/
Ohyeah, my serial kitl died here. go to the serkernelcommdev (Service, commdevice) function and check that it only recognizes commdevice = kernel_comm_ether. Instead, it shields serial and paraller tied to ether and directly returns false, you don't need to do the following. in the wince configurantation provided by ms, the description of the setkernelcommdev function reads "this function is obsolete and shoshould not be used ". if you want to change it, it's still in private. nnd, Ms raped.
Nke pn # U & OQ ^ 0 if ether is successfully used here, there are two functions named nkforcecleanboot () and kitlinitializeinterrupt (). The kitl Initialization is complete. I guess init_enabled and ist_started in kitlgolbalsate are marked during this function. lupa open-source community # K + B7 [W _

I3] + @ $ k0c B0
* M g9cqu0 6. bool oemkitlinit (pkitltransport pkitl) [platform/common/src/common/kitl. C]
Sydnk: kr1 ^ 0R) after W0 mentioned startkitl, the first thing to do is to call oemkitlinit. This function is very different in wince4.2 and 5.0, And if (! Initether (pkitl )&&! Initparallelserial (pkitl), initialize ether, serial, and parallel all over again, depending on which one can be used, and 5.0 is a very obvious branch plot after it comes in, it is determined by g_kitlstate.pdevice-> type whether to call oalkitlethinit or oalkitlserialinit. there is no typical racial discrimination in oalkitlparallelinit. fortunately, we use serial. lupa open-source community n) gnyj6d
Here we have a place to choose compilation, that is, # ifdef kitl_ether and # ifdef kitl_serial. The specific definition is the cdefines =$ (cdefines) in the sources file in this directory) -dkitl_serial-dkitl_ether: I have been searching for it for a long time. in fact, I think that since the if structure is selected, it is also dispensable to select compilation.
(N "/(u p' v2n0 is good, the following will go to oalkitlserialinit.

PJ (V!] 3 {@ 8 h! T0

: E5f2ia} 1E y/, m9e) x0 VII. bool oalkitlserialinit (lpstr DeviceID, oal_kitl_device * pdevice, oal_kitl_args * pargs, kitltransport * pkitl)
9j4n ^ V (f2ivp | 0 [platform/common/src/common/kitl/kitlserial. C] Lupa open source community s) A | ku8ec
I wrote six functions to this kitlserial. c file myself.
LNA] G-enxc ri0 bool kitlserialinit (kitl_serial_intfo * pserinfo)
! C bp1 '"J: E0 uint16 kitlserialwritedata (uint8 * PCH, uint16 length) Lupa open source community & tu} BFI
Uint16 kitlserialreaddata (uint8 * PCH, uint16 length)
Q & ty6e * '$ e2t0 void kitlserialflowcontrol // stub. The ffuart I use only two lines, txd and rxd, and no such lines, so flowcontrol should naturally be stub's Lupa open-source community (V I '0o8u @ I
Void kitlserialenableint (void) // stub, use pollinglupa open source community (I + KB: A ycwz
Void kitlserialdisableint (void) // stub, use polling
Qg'o -~ H "z6w0 otherwise, the g_kitldevices in front does not have the corresponding hardware abstraction layer to fill in. Lupa open source community G | $ Qi! Um "_
The above serialrecv, encode, decode and so on all have obvious meanings. Needless to say, OK is now at the bottom, and the article can be completed.

Oracle (xyo % y-MM0

{1qw. e s 'yl0 8. Record debugging experience. Lupa open-source community q3l/. Ob Z-
Although this is the third time I have called the serial port, I have not summed up the previous experience, but it took two days to reach the place where private was aborted. In fact, we should be able to get there in one day. The problem lies in
^ Tzp8l * e01. the debugger was not used on the first day. Debugger software and Pb are constantly changing, often restarting the software or even restarting the computer. over 3/4 of the time spent on these issues on the first day is constantly restarting. Lupa open-source community y $ g4wa F8 ~ # G
2. At the end of UART initialization function, I forgot to enable UART unit in interrupt controller register. Lupa open-source community o '5}. l j0m; dh6} n
3. kitlserialflowcontrol. at the time of writing, I copied the functions under x86 and didn't want to understand what to control. after debugging, the pointer pointing to this function is set to null at the beginning, but some functions in private that need to be judged by if cannot be entered. then I changed it to stub. lupa open-source community ZW; G # U # J/^ pvq;}: Z
4. in the receive function, the Data ready bit in line Status Register is determined before each byte is received. If the value is zero, an error is returned. but there is a problem here, and I don't want to understand it too much. I deleted this judgment from the source code provided by Ms when debugging debug serial, now, when I made kitl serial, I added it with itchy hands. this may be a bug in MS or intel. However, according to the read process given in Intel CPU manul update, only the error in LSR is determined at the beginning, read the first byte without judging the Dr bit. after reading the data, judge that if the Dr bit is 1, continue to read the next byte. lupa open-source community 8e_1mh4v % M $ H
5. add a break point to the receive function through debugger. As a result, after the data in the Receive Buffer register is scanned by the debugger, it becomes zero, but nothing can be received on the CPU, it took most of the afternoon, and finally it was found by Jeffery.

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.