搜档网
当前位置:搜档网 › GcodeG代码详解

GcodeG代码详解

GcodeG代码详解
GcodeG代码详解

reprap wiki上面的Gcode说明

G-code

From RepRapWiki

(Redirected from Gcode)

Jump to: navigation, search

Contents [hide]

1 Introduction

2 RepRap G Code Fields

3 Comments

4 Individual commands

4.1 Checking

4.1.1 N and *

4.2 Buffered G Commands

4.2.1 G0: Rapid move

4.2.2 G1: Controlled move

4.2.3 G28: Move to Origin

4.3 Unbuffered G commands

4.3.1 G4: Dwell

4.3.2 G20: Set Units to Inches

4.3.3 G21: Set Units to Millimeters

4.3.4 G90: Set to Absolute Positioning

4.3.5 G91: Set to Relative Positioning

4.3.6 G92: Set Position

4.4 Unbuffered M and T commands

4.4.1 M0: Stop

4.4.2 M17: Enable/Power all stepper motors 4.4.3 M18: Disable all stepper motors

4.4.4 M20: List SD card

4.4.5 M21: Initialise SD card

4.4.6 M22: Release SD card

4.4.7 M23: Select SD file

4.4.8 M24: Start/resume SD print

4.4.9 M25: Pause SD print

4.4.10 M26: Set SD position

4.4.11 M27: Report SD print status

4.4.12 M28: Begin write to SD card

4.4.13 M29: Stop writing to SD card

4.4.14 M40: Eject

4.4.15 M41: Loop

4.4.16 M42: Stop on material exhausted 4.4.17 M43: Stand by on material exhausted 4.4.18 M80: ATX Power On

4.4.19 M81: ATX Power Off

4.4.20 M84: Stop idle hold

4.4.21 M92: Set axis_steps_per_unit

4.4.22 M101 Turn extruder 1 on Forward

4.4.23 M102 Turn extruder 1 on Reverse

4.4.24 M103 Turn all extruders off

4.4.25 M104: Set Extruder Temperature (Fast)

4.4.26 M105: Get Extruder Temperature

4.4.27 M106: Fan On

4.4.28 M107: Fan Off

4.4.29 M108: Set Extruder Speed

4.4.30 M109: Set Extruder Temperature

4.4.31 M110: Set Current Line Number

4.4.32 M111: Set Debug Level

4.4.33 M112: Emergency Stop

4.4.34 M113: Set Extruder PWM

4.4.35 M114: Get Current Position

4.4.36 M115: Get Firmware Version and Capabilities

4.4.37 M116: Wait

4.4.38 M117: Get Zero Position

4.4.39 M118: Negotiate Features

4.4.40 M119: Get Endstop Status

4.4.41 M126: Open Valve

4.4.42 M127: Close Valve

4.4.43 M128: Extruder Pressure PWM

4.4.44 M129: Extruder pressure off

4.4.45 M140: Bed Temperature (Fast)

4.4.46 M141: Chamber Temperature (Fast)

4.4.47 M142: Holding Pressure

4.4.48 M143: Maximum hot-end temperature

4.4.49 M160: Number of mixed materials

4.4.50 M203: Record Z adjustment

4.4.51 M226: Gcode Initiated Pause

4.4.52 M227: Enable Automatic Reverse and Prime

4.4.53 M228: Disable Automatic Reverse and Prime

4.4.54 M229: Enable Automatic Reverse and Prime

4.4.55 M230: Disable / Enable Wait for Temperature Change 4.4.56 M240: Start conveyor belt motor

4.4.57 M241: Stop conveyor belt motor

4.4.58 M245: Start cooler

4.4.59 M246: Stop cooler

4.4.60 M300: Play beep sound

4.4.61 T: Select Tool

5 Proposed EEPROM configuration codes

6 Replies from the RepRap machine to the host computer

7 Proposal for sending multiple lines of G-code

7.1 Problem to solve

Introduction

This page describes the G Codes that the RepRap firmware uses and how they work.

The list of what can be done is extensible. But check this page first, and add your extension here first before you implement it.

A typical piece of GCode as sent to a RepRap machine might look like this:

N3 T0*57

N4 G92 E0*67

N5 G28*22

N6 G1 F1500.0*82

N7 G1 X2.0 Y2.0 F3000.0*85

N8 G1 X3.0 Y3.0*33

The meaning of all those symbols and numbers (and more) is explained below.

TO find out which specific gcode/s are implemented in any given firmware, please see the Firmware_features page.

(For the technically minded, the end of line is marked by both a and a . If you want to manually enter GCodes in your reprap using the Arduino Serial interface, make sure to select "Both NL & CR" on the bottom of the screen.)

This isn't accurate, firmware accepts single as well as single , or combinations thereof. Hosts should accepts all four combinations as well. --Traumflug 09:34, 20 April 2011 (UTC)

RepRap G Code Fields

This section explains the letter-preceded fields. The numbers in the fields are represented by nnn. Numbers can be integers, or can contain a decimal point, depending on context. For example an X coordinate can be integer (X175) or fractional (X17.62), whereas trying to select extruder number 2.76 would make no sense.

Letter Meaning

Gnnn Standard GCode command, such as move to a point

Mnnn RepRap-defined command, such as turn on a cooling fan

Tnnn Select tool nnn. In RepRap, tools are extruders

Snnn Command parameter, such as the voltage to send to a motor

Pnnn Command parameter, such as a time in milliseconds

Xnnn An X coordinate, usually to move to

Ynnn A Y coordinate, usually to move to

Znnn A Z coordinate, usually to move to

Innn Parameter - not currently used

Jnnn Parameter - not currently used

Fnnn Feedrate in mm per minute. (Speed of print head movement)

Rnnn Parameter - not currently used

Qnnn Parameter - not currently used

Ennn Length of extrudate in mm. This is exactly like X, Y and Z, but for the length of filament to extrude. It is common for newer stepper based systems to interpret ... Better: Skeinforge 40 and up interprets this as the absolute length of input filament to consume, rather than the length of the extruded output.

Nnnn Line number. Used to request repeat transmission in the case of communications errors. *nnn Checksum. Used to check for communications errors.

Comments

G Code comments:

N3 T0*57 ;This is a comment

N4 G92 E0*67

; So is this

N5 G28*22

Will be ignored by RepRap, as will blank lines. But it's better to strip these out in the host computer before the lines are sent. This saves bandwidth.

Individual commands

Checking

N and *

Example: N123 [...G Code in here...] *71

These are the line number and the checksum. The RepRap firmware checks the checksum against a locally-computed value and, if they differ, requests a repeat transmission of the line of the given number.

You can leave both of these out - RepRap will still work, but it won't do checking. You have to have both or neither though.

The checksum "cs" for a GCode string "cmd" (including its line number) is computed by exor-ing the bytes in the string up to and not including the * character as follows:

int cs = 0;

for(i = 0; cmd[i] != '*' && cmd[i] != NULL; i++)

cs = cs ^ cmd[i];

cs &= 0xff; // Defensive programming...

and the value is appended as a decimal integer to the command after the * character.

The RepRap firmware expects line numbers to increase by 1 each line, and if that doesn't happen it is flagged as an error. But you can reset the count using M110 (see below).

Buffered G Commands

The RepRap firmware stores these commands in a ring buffer internally for execution. This means that there is no (appreciable) delay while a command is acknowledged and the next transmitted. In turn, this means that sequences of line segments can be plotted without a dwell between one and the next. As soon as one of these buffered commands is received it is acknowledged and stored locally. If the local buffer is full, then the acknowledgment is delayed until space for storage in the buffer is available. This is how flow control is achieved.

G0: Rapid move

Example: G0 X12

In this case move rapidly to X = 12 mm. In fact, the RepRap firmware uses exactly the same code for rapid as it uses for controlled moves (see G1 below), as - for the RepRap machine - this is just as efficient as not doing so. (The distinction comes from some old machine tools that used to move faster if the axes were not driven in a straight line. For them G0 allowed any movement in space to get to the destination as fast as possible.)

G1: Controlled move

Example: G1 X90.6 Y13.8 E22.4

Go in a straight line from the current (X, Y) point to the point (90.6, 13.8), extruding material as the move happens from the current extruded length to a length of 22.4 mm.

RepRap does subtle things with feedrates. Thus:

G1 F1500

G1 X90.6 Y13.8 E22.4

Will set a feedrate of 1500 mm/minute, then do the move described above at that feedrate. But

G1 F1500

G1 X90.6 Y13.8 E22.4 F3000

Will set a feedrate of 1500 mm/minute, then do the move described above accelerating to a feedrate of 3000 mm/minute as it does so. The extrusion will accelerate along with the X, Y movement so everything stays synchronized.

RepRap thus treats feedrate as simply another variable (like X, Y, Z, and E) to be linearly interpolated. This gives complete control over accelerations and decelerations in a way that ensures that everything moves together and the right volume of material is extruded at all points.

The first example shows how to get a constant-speed movement. The second how to accelerate or decelerate. Thus

G1 F1500

G1 X90.6 Y13.8 E22.4 F3000

G1 X80 Y20 E36 F1500

Will do the first movement accelerating as before, and the second decelerating from 3000 mm/minute back to 1500 mm/minute.

To reverse the extruder by a given amount (for example to reduce its internal pressure while it does an in-air movement so that it doesn't dribble) simply use G1 to send an E value that is less than the currently extruded length.

G28: Move to Origin

Example: G28

This causes the RepRap machine to move back to its X, Y and Z zero endstops, a process known as "homing". It does so accelerating, so as to get there fast. But when it arrives it backs off by 1 mm in each direction slowly, then moves back slowly to the stop. This ensures more accurate positioning.

If you add coordinates, then just the axes with coordinates specified will be zeroed. Thus

G28 X0 Y72.3

will zero the X and Y axes, but not Z. The actual coordinate values are ignored.

Unbuffered G commands

The following commands are not buffered. When one is received it is stored, but it is not acknowledged to the host until the buffer is exhausted and then the command has been executed. Thus the host will pause at one of these commands until it has been done. Short pauses between these commands and any that might follow them do not affect the performance of the machine.

G4: Dwell

Example: G4 P200

In this case sit still doing nothing for 200 milliseconds. During delays the state of the machine (for example the temperatures of its extruders) will still be preserved and controlled.

G20: Set Units to Inches

Example: G20

Units from now on are in inches.

G21: Set Units to Millimeters

Example: G21

Units from now on are in millimeters. (This is the RepRap default.)

G90: Set to Absolute Positioning

Example: G90

All coordinates from now on are absolute relative to the origin of the machine. (This is the RepRap default.)

G91: Set to Relative Positioning

Example: G91

All coordinates from now on are relative to the last position.

G92: Set Position

Example: G92 X10 E90

Allows programming of absolute zero point, by reseting the current position to the values specified. This would set the machine's X coordinate to 10, and the extrude coordinate to 90. No physical motion will occur.

Unbuffered M and T commands

M0: Stop

Example: M0

The RepRap machine finishes any moves left in its buffer, then shuts down. All motors and heaters are turned off. It can be started again by pressing the reset button on the master microcontroller. See also M112.

M17: Enable/Power all stepper motors

Example: M17

M18: Disable all stepper motors

Example: M18

Disables stepper motors and allows axis to move 'freely.'

M20: List SD card

Example: M20

All files in the root folder of the SD card are listed to the serial port. This results in a line like:

ok Files: {SQUARE.G,SQCOM.G,}

The trailing comma is optional. Note that file names are returned in upper case, but - when sent to the M23 command (below) they must be in lower case. This seems to be a function of the SD software. Go figure...

M21: Initialise SD card

Example: M21

The SD card is initialised. If an SD card is loaded when the machine is switched on, this will happen by default. SD card must be initialised for the other SD functions to work.

M22: Release SD card

Example: M22

SD card is released and can be physically removed.

M23: Select SD file

Example: M23 filename.gco

The file specified as filename.gco (8.3 naming convention is supported) is selected ready for printing.

M24: Start/resume SD print

Example: M24

The machine prints from the file selected with the M23 command.

M25: Pause SD print

Example: M25

The machine pause printing at the current position within the file selected with the M23 command.

M26: Set SD position

Example: M26

Set SD position in bytes (M26 S12345).

M27: Report SD print status

Example: M27

Report SD print status.

M28: Begin write to SD card

Example: M28 filename.gco

File specified by filename.gco is created (or overwritten if it exists) on the SD card and all subsequent commands sent to the machine are written to that file.

M29: Stop writing to SD card

Example: M29 filename.gco

File opened by M28 command is closed, and all subsequent commands sent to the machine are executed as normal.

M40: Eject

If your RepRap machine can eject the parts it has built off the bed, this command executes the eject cycle. This usually involves cooling the bed and then performing a sequence of movements that remove the printed parts from it. The X, Y and Z position of the machine at the end of this cycle are undefined (though they can be found out using the M114 command, q.v.).

See also M240 and M241 below.

M41: Loop

Example: M41

If the RepRap machine was building a file from its own memory such as a local SD card (as opposed to a file being transmitted to it from a host computer) this goes back to the beginning of the file and runs it again. So, for example, if your RepRap is capable of ejecting parts from its build bed then you can set it printing in a loop and it will run and run. Use with caution - the only things that will stop it are:

1.When you press the reset button,

2.When the build material runs out (if your RepRap is set up to detect this), and

3.When there's an error (such as a heater failure).

M42: Stop on material exhausted

Example: M42

If your RepRap can detect when its material runs out, this decides the behaviour when that happens. The X and Y axes are zeroed (but not Z), and then the machine shuts all motors and heaters off. You have to press reset to reactivate the machine. In other words, it parks itself and then executes an M0 command (q.v.).

M43: Stand by on material exhausted

Example: M43

If your RepRap can detect when its material runs out, this decides the behaviour when that

happens. The X and Y axes are zeroed (but not Z), and then the machine shuts all motors and heaters off except the heated bed, the temperature of which is maintained. The machine will still respond to G and M code commands in this state.

M80: ATX Power On

Example: M80

Turns on the ATX power supply from standby mode to fully operational mode. No-op on electronics without standby mode.

Note: some firmwares, like Teacup, handle power on/off automatically, so this is redundant there.

M81: ATX Power Off

Example: M81

Turns off the ATX power supply. Counterpart to M80.

M84: Stop idle hold

Example: M84

Stop the idle hold on all axis and extruder. In some cases the idle hold causes annoying noises, which can be stopped by disabling the hold. Be aware that by disabling idle hold during printing, you will get quality issues. This is recommended only in between or after printjobs.

M92: Set axis_steps_per_unit

Example: M92 X Sprinter and Marlin

Allows programming of steps per unit of axis till the electronics are reset for the specified axis. Very useful for calibration.

M101 Turn extruder 1 on Forward

Depreciated. see MCodeReference. Was used by older style DC extruders. See also Bits From Bytes

M102 Turn extruder 1 on Reverse

Depreciated. see MCodeReference. Was used by older style DC extruders. See also Bits From Bytes

M103 Turn all extruders off

Depreciated. see MCodeReference. Was used by older style DC extruders. See also Bits From Bytes

M104: Set Extruder Temperature (Fast)

Example: M104 S190

Set the temperature of the current extruder to 190oC and return control to the host immediately (i.e. before that temperature has been reached by the extruder). See also M109.

M105: Get Extruder Temperature

Example: M105

Request the temperature of the current extruder and the build base in degrees Celsius. The temperatures are returned to the host computer. For example, the line sent to the host in response to this command looks like

ok T:201 B:117

M106: Fan On

Example: M106 S127

Turn on the cooling fan at half speed. Optional parameter 'S' declares the PWM value (0-255)

M107: Fan Off

Example: M107

Turn off the cooling fan (if any).

M108: Set Extruder Speed

Sets speed of extruder motor. (Deprecated in current firmware, see M113)

M109: Set Extruder Temperature

Example: M109 S190

Set the temperature of the current extruder to 190oC and wait for it to reach that value before sending an acknowledgment to the host. In fact the RepRap firmware waits a while after the temperature has been reached for the extruder to stabilise - typically about 40 seconds. This can be changed by a parameter in the firmware configuration file when the firmware is compiled. See also M104 and M116.

M110: Set Current Line Number

Example: N123 M110

Set the current line number to 123. Thus the expected next line after this command will be 124.

M111: Set Debug Level

Example: M111 S6

Set the level of debugging information transmitted back to the host to level 6. The level is the OR of three bits:

#define DEBUG_ECHO (1<<0)

#define DEBUG_INFO (1<<1)

#define DEBUG_ERRORS (1<<2)

Thus 6 means send information and errors, but don't echo commands. (This is the RepRap default.)

M112: Emergency Stop

Example: M112

Any moves in progress are immediately terminated, then RepRap shuts down. All motors and heaters are turned off. It can be started again by pressing the reset button on the master microcontroller. See also M0.

M113: Set Extruder PWM

Example: M113

Set the PWM for the currently-selected extruder. On its own this command sets RepRap to use the on-board potentiometer on the extruder controller board to set the PWM for the currently-selected extruder's stepper power. With an S field:

M113 S0.7

it causes the PWM to be set to the S value (70% in this instance). M113 S0 turns the extruder off, until an M113 command other than M113 S0 is sent.

M114: Get Current Position

Example: M114

This causes the RepRap machine to report its current X, Y, Z and E coordinates to the host.

For example, the machine returns a string such as:

ok C: X:0.00 Y:0.00 Z:0.00 E:0.00

M115: Get Firmware Version and Capabilities

Example: M115

Request the Firmware Version and Capabilities of the current microcontroller The details are returned to the host computer as key:value pairs separated by spaces and terminated with a

linefeed.

sample data from firmware:

ok PROTOCOL_VERSION:0.1 FIRMWARE_NAME:FiveD FIRMWARE_URL:http%3A//https://www.sodocs.net/doc/6015676357.html, MACHINE_TYPE:Mendel EXTRUDER_COUNT:1

This M115 code is inconsistently implemented, and should not be relied upon to exist, or output correctly in all cases. An initial implementation was committed to svn for the FiveD Reprap firmware on 11 Oct 2010. Work to more formally define protocol versions is currently (October 2010) being discussed. See M115_Keywords for one draft set of keywords and their meanings.

M116: Wait

Example: M116

Wait for all temperatures and other slowly-changing variables to arrive at their set values. See also M109.

M117: Get Zero Position

Example: M117

This causes the RepRap machine to report the X, Y, Z and E coordinates in steps not mm to the host that it found when it last hit the zero stops for those axes. That is to say, when you zero X, the x coordinate of the machine when it hits the X endstop is recorded. This value should be 0, of course. But if the machine has drifted (for example by dropping steps) then it won't be. This command allows you to measure and to diagnose such problems. (E is included for completeness. It doesn't normally have an endstop.)

M118: Negotiate Features

Example: M118 P42

This M-code is for future proofing. NO firmware or hostware supports this at the moment. It is used in conjunction with M115's FEATURES keyword.

See Protocol_Feature_Negotiation for more info.

M119: Get Endstop Status

Example: M119

Returns the current state of the configured X,Y,Z endstops. Should take into account any 'inverted endstop' settings, so one can confirm that the machine is interpreting the endstops correctly.

M126: Open Valve

Example: M126 P500

Open the extruder's valve (if it has one) and wait 500 milliseconds for it to do so.

M127: Close Valve

Example: M127 P400

Close the extruder's valve (if it has one) and wait 400 milliseconds for it to do so.

M128: Extruder Pressure PWM

Example: M128 S255

PWM value to control internal extruder pressure. S255 is full pressure.

M129: Extruder pressure off

Example: M129 P100

In addition to setting Extruder pressure to 0, you can turn the pressure off entirely. P400 will wait 100ms to do so.

M140: Bed Temperature (Fast)

Example: M140 S55

Set the temperature of the build bed to 55oC and return control to the host immediately (i.e. before that temperature has been reached by the bed).

M141: Chamber Temperature (Fast)

Example: M141 S30

Set the temperature of the chamber to 30oC and return control to the host immediately (i.e. before that temperature has been reached by the chamber).

M142: Holding Pressure

Example: M142 S1

Set the holding pressure of the bed to 1 bar.

The holding pressure is in bar. For hardware which only has on/off holding, when the holding pressure is zero, turn off holding, when the holding pressure is greater than zero, turn on holding.

M143: Maximum hot-end temperature

Example: M143 S275

Set the maximum temperature of the hot-end to 275C

When temperature of the hot-end exceeds this value, take countermeasures, for instance an

emergency stop. This is to prevent hot-end damage.

M160: Number of mixed materials

Example: M160 S4

Set the number of materials, N, that the current extruder can handle to the number specified. The default is 1.

When N >= 2, then the E field that controls extrusion requires N+1 values separated by spaces after it like this:

M160 S4

G1 X90.6 Y13.8 E22.4 0.1 0.1 0.1 0.7

G1 X70.6 E42.4 0.0 0.0 0.0 1.0

G1 E42.4 1.0 0.0 0.0 0.0

The second line moves straight to the point (90.6, 13.8) extruding 22.4mm of filament. The mix ratio at the end of the move is 0.1:0.1:0.1:0.7.

The third line moves back 20mm in X extruding 20mm of filament. The mix varies linearly from 0.1:0.1:0.1:0.7 to 0:0:0:1 as the move is made.

The fourth line has no physical effect, but sets the mix proportions for the start of the next move to 1:0:0:0.

M203: Record Z adjustment

Example: M203 Z-0.75

This records a Z offset in non-volatile memory in RepRap's microcontroller where it remains active until next set, even when the power is turned off and on again. If the first layer is too close to the bed, you need to effectively move the bed down, so the Z value will be negative. If the nozzle is too far from the bed during the first layer, the Z value should be positive to raise the bed. The maximum adjustment is +/-1.27mm.

M226: Gcode Initiated Pause

Example: M226

Initiates a pause in the same way as if the pause button is pressed.

M227: Enable Automatic Reverse and Prime

Example: M227 P1600 S1600

P and S are steps.

M228: Disable Automatic Reverse and Prime

Example: M228

M229: Enable Automatic Reverse and Prime

Example: M229 P1.0 S1.0

P and S are extruder screw rotations.

M230: Disable / Enable Wait for Temperature Change

Example: M230 S1

S1 Disable wait for temperature change S0 Enable wait for temperature change

M240: Start conveyor belt motor

Example: M240

The conveyor belt allows to start mass production of a part with a reprap

M241: Stop conveyor belt motor

Example: M241

M245: Start cooler

Example: M245

used to cool parts/heated-bed down after printing for easy remove of the parts after print

M246: Stop cooler

Example: M246

M300: Play beep sound

Usage: M300 S P

Example: M300 S300 P1000

Play beep sound, use to notify important events like the end of printing. See working example on R2C2 electronics.

T: Select Tool

Example: T1

Select extruder number 1 to build with. Extruder numbering starts at 0.

Proposed EEPROM configuration codes

BRIEFLY: each RepRap has a number of physical parameters that should be persistent, but easily configurable, such as extrusion steps/mm, various max values, etc. Those parameters are currently hardcoded in the firmware, so that a user has to modify, recompile and re-flash the firmware for any adjustments. These configs can be stored in MCU's EEPROM and modified via some M-codes. Please see the detailed proposal at M-codes for EEPROM config. (This is proposed by --AlexRa on 11-March-2011. There is currently no working implementation of the proposed commands).

Replies from the RepRap machine to the host computer

All communication is in printable ASCII characters. Messages sent back to the host computer are terminated by a newline and look like this:

xx [line number to resend] [T:93.2 B:22.9] [C: X:9.2 Y:125.4 Z:3.7 E:1902.5] [Some debugging or other information may be here]

xx can be one of:

ok

rs

!!

ok means that no error has been detected.

rs means resend, and is followed by the line number to resend.

!! means that a hardware fault has been detected. The RepRap machine will shut down immediately after it has sent this message.

The T: and B: values are the temperature of the currently-selected extruder and the bed respectively, and are only sent in response to M105. If such temperatures don't exist (for example for an extruder that works at room temperature and doesn't have a sensor) then a value below absolute zero (-273oC) is returned.

C: means that coordinates follow. Those are the X: Y: etc values. These are only sent in response to M114 and M117.

The RepRap machine may also send lines that look like this:

// This is some debugging or other information on a line on its own. It may be sent at any time.

Such lines will always be preceded by //.

The most common response is simply:

ok

When the machine boots up it sends the string

start

once to the host before sending anything else. This should not be replaced or augmented by version numbers and the like. M115 (see above) requests those.

All this means that every line sent by RepRap to the host computer except the start line has a two-character prefix (one of ok, rs, !! or //). The machine should never send a line without such a prefix.

u-boot启动分析

背景: Board →ar7240(ap93) Cpu →mips 1、首先弄清楚什么是u-boot Uboot是德国DENX小组的开发,它用于多种嵌入式CPU的bootloader程序, uboot不仅支持嵌入式linux系统的引导,当前,它还支持其他的很多嵌入式操作系统。 除了PowerPC系列,还支持MIPS,x86,ARM,NIOS,XScale。 2、下载完uboot后解压,在根目录下,有如下重要的信息(目录或者文件): 以下为为每个目录的说明: Board:和一些已有开发板有关的文件。每一个开发板都以一个子目录出现在当前目录中,子目录存放和开发板相关的配置文件。它的每个子文件夹里都有如下文件(以ar7240/ap93为例): Makefile Config.mk Ap93.c 和板子相关的代码 Flash.c Flash操作代码 u-boot.lds 对应的链接文件 common:实现uboot命令行下支持的命令,每一条命令都对应一个文件。例如bootm命令对应就是cmd_bootm.c cpu:与特定CPU架构相关目录,每一款Uboot下支持的CPU在该目录下对应一个子目录,比如有子目录mips等。它的每个子文件夹里都有入下文件: Makefile Config.mk Cpu.c 和处理器相关的代码s Interrupts.c 中断处理代码 Serial.c 串口初始化代码 Start.s 全局开始启动代码 Disk:对磁盘的支持

Doc:文档目录。Uboot有非常完善的文档。 Drivers:Uboot支持的设备驱动程序都放在该目录,比如网卡,支持CFI的Flash,串口和USB等。 Fs:支持的文件系统,Uboot现在支持cramfs、fat、fdos、jffs2和registerfs。 Include:Uboot使用的头文件,还有对各种硬件平台支持的汇编文件,系统的配置文件和对文件系统支持的文件。该目下configs目录有与开发板相关的配置文件,如 ar7240_soc.h。该目录下的asm目录有与CPU体系结构相关的头文件,比如说mips 对应的有asm-mips。 Lib_xxx:与体系结构相关的库文件。如与ARM相关的库放在lib_arm中。 Net:与网络协议栈相关的代码,BOOTP协议、TFTP协议、RARP协议和NFS文件系统的实现。 Tools:生成Uboot的工具,如:mkimage等等。 3、mips架构u-boot启动流程 u-boot的启动过程大致做如下工作: 1、cpu初始化 2、时钟、串口、内存(ddr ram)初始化 3、内存划分、分配栈、数据、配置参数、以及u-boot代码在内存中的位置。 4、对u-boot代码作relocate 5、初始化malloc、flash、pci以及外设(比如,网口) 6、进入命令行或者直接启动Linux kernel 刚一开始由于参考网上代码,我一个劲的对基于smdk2410的板子,arm926ejs的cpu看了N 久,启动过程和这个大致相同。 整个启动中要涉及到四个文件: Start.S →cpu/mips/start.S Cache.S →cpu/mips/cache.S Lowlevel_init.S →board/ar7240/common/lowlevel_init.S Board.c →lib_mips/board.c 整个启动过程分为两个阶段来看: Stage1:系统上电后通过汇编执行代码 Stage2:通过一些列设置搭建了C环境,通过汇编指令跳转到C语言执行. Stage1: 程序从Start.S的_start开始执行.(至于为什么,参考u-boot.lds分析.doc) 先查看start.S文件吧!~ 从_start标记开始会看到一长串莫名奇妙的代码:

STM32启动文件详解

STM32启动文件详解 (2012-07-28 11:22:34) 转载▼ 分类:STM32 标签: stm32 启动 在<>,用的是STM32F103RBT6,所有的例程都采用了一个叫STM32F10x.s的启动文件,里面定义了STM32的堆栈大小以及各种中断的名字及入口函数名称,还有启动相关的汇编代码。STM32F10x.s是MDK提供的启动代码,从其里面的内容看来,它只定义了3个串口,4个定时器。实际上STM32的系列产品有5个串口的型号,也只有有2个串口的型号,定时器也是,做多的有8个定时器。比如,如果你用的 STM32F103ZET6,而启动文件用的是STM32F10x.s的话,你可以正常使用串口1~3的中断,而串口4和5的中断,则无**常使用。又比如,你TIM1~4的中断可以正常使用,而5~8的,则无法使用。 而在固件库里出现3个文件 startup_stm32f10x_ld.s startup_stm32f10x_md.s startup_stm32f10x_hd.s 其中,ld.s适用于小容量产品;md.s适用于中等容量产品;hd适用于大容量产品; 这里的容量是指FLASH的大小.判断方法如下: 小容量:FLASH≤32K 中容量:64K≤FLASH≤128K 大容量:256K≤FLASH ;******************** (C) COPYRIGHT 2011 STMicroelectronics ******************** ;* File Name : startup_stm32f10x_hd.s ;* Author : MCD Application Team ;* Version : V3.5.0 ;* Date : 11-March-2011 ;* Description : STM32F10x High Density Devices vector table for MDK-ARM ;* toolchain. ;* This module performs: ;* - Set the initial SP ;* - Set the initial PC == Reset_Handler ;* - Set the vector table entries with the exceptions ISR address ;* - Configure the clock system and also configure the external ;* SRAM mounted on STM3210E-EVAL board to be used as data ;* memory (optional, to be enabled by user) ;* - Branches to __main in the C library (which eventually ;* calls main()). ;* After Reset the CortexM3 processor is in Thread mode,

如何编写ARM7的启动代码

如何编写ARM7的启动代码(LPC2119为例) 随着生活水平的提高和IT技术的进步,8位处理器的处理能力已经不能满足嵌入式系统的需要了;而16位处理器在性能和成本上都没有很大的突破。并且在8位机的开发中,大多使用汇编语言来编写用户程序。这使得程序的可维护性、易移植性等都受到了极大的挑战。正是基于此,ARM 公司适时的推出了一系列的32位嵌入式微控制器。目前广泛使用的是ARM7和ARM9系列,ARM7TDMI内核的ARM7处理器广泛应用于工业控制、仪器仪表、汽车电子、通讯、消费电子等嵌入式设备。本文主要以philips 公司ARM7TDMI核的LPC2119为例来分析如何编写ARM7的启动代码。 1、启动代码 在嵌入式系统软件的开发中,应用程序通常是在嵌入式操作系统的开发平台上采用C语言编写的。然而,在ARM系统上电复位后,需要设置中断向量表、初始化各模式堆栈、设置系统时钟频率等,而这些过程都是针对

ARM内部寄存器结构的操作,用C语言编程是很难实现的。因此在转到应用程序的c/c++编写之前,需要用ARM的汇编语言编写启动代码,由启动代码完成系统初始化以及跳转到用户C程序。在ARM设计开发中,启动代码的编写是一个极重要的过程。然而启动代码随具体的目标系统和开发系统有所区别,但通常包含以下部分: ·向量表定义 ·地址重映射及中断向量表的转移 ·堆栈初始化 ·设置系统时钟频率 ·中断寄存器的初始化 ·进入C应用程序 下面就结合PHILIPS的LPC2119的启动代码来分析与说明ARM7处理器的启动代码的编写。 1.1向量表定义 ARM芯片上电或复位后,系统进入管理模式、ARM状态、PC(R15)指向0x00000000地址处。中断向量表为每一个中断设置1个字的存储空间,存放一条跳转指令,通过这条指令使PC指针指向相应的中断服务程序入口,继而执行相应的中断处理程序。LPC2219的中断向量表和其它基于ARM核的芯片中断向量表较类似,只要注意LPC2219要使向量表所有数据32位累加和为零(0x00000000-0x0000001C的8个字的机器码累加), 才能使用户的程序脱机运行。 1.2 地址重映射及中断向量表的转移 ARM7处理器在复位后从地址0读取第一条指令并执行,因此系统上电后地址0必须是非易失的ROM/FLASH,这样才能保证处理器有正确可用的指令。为了加快对中断的处理以及实现在不同操作系统模式下对中断的处

UBOOT命令详解

常用U-boot命令详解(z) 2010-09-30 15:05:52| 分类:学习心得体会|字号订阅 U-boot发展到现在,他的命令行模式已经非常接近Linux下的shell了,在我编译的 U-boot-2009.11中的命令行模式模式下支持“Tab”键的命令补全和命令的历史记录功能。而且如果你输入的命令的前几个字符和别的命令不重复,那么你就只需要打这几个字符即可,比如我想看这个U-boot的版本号,命令就是“ version”,但是在所有的命令中没有其他任何一个的命令是由“v”开头的,所以只需要输入“v”即可。 [u-boot@MINI2440]# version U-Boot 2009.11 ( 4月04 2010 - 12:09:25) [u-boot@MINI2440]# v U-Boot 2009.11 ( 4月04 2010 - 12:09:25) [u-boot@MINI2440]# base Base Address: 0x00000000 [u-boot@MINI2440]# ba Base Address: 0x00000000 由于U-boot支持的命令实在太多,一个一个细讲不现实,也没有必要。所以下面我挑一些烧写和引导常用命令介绍一下,其他的命令大家就举一反三,或者“help”吧! (1)获取帮助 命令:help 或? 功能:查看当前U-boot版本中支持的所有命令。 [u-boot@MINI2440]#help ?- alias for'help' askenv - get environment variables from stdin base - print or set address offset bdinfo - print Board Info structure bmp - manipulate BMP image data boot - boot default, i.e., run 'bootcmd' bootd - boot default, i.e., run 'bootcmd' bootelf - Boot from an ELF image in memory bootm - boot application image from memory bootp - boot image via network using BOOTP/TFTP protocol

Tiny6410_Uboot移植步骤详解

Uboot_for_Tiny6410_移植步骤详解 一、设计要求 1.目的 1)掌握U-boot剪裁编写 2)掌握交叉编译环境的配置 3)掌握U-boot的移植 2.实现的功能 1)U-boot编译成功 2)移植U-boot,使系统支持从NAND FLASH启动 二、设计方案 1.硬件资源 1)ARM处理器:ARM11芯片(Samsung S3C6410A),基于ARM1176JZF-S核设 计,运行频率533Mhz,最高可达 667Mhz 2)存储器:128M DDR RAM,可升级至 256M;MLC NAND Flash(2GB) 3)其他资源:具有三LCD接口、4线电阻 触摸屏接口、100M标准网络接口、标准DB9 五线串口、Mini USB2.0接口、USB Host 1.1、3.5mm音频输入输出口、标准TV-OUT

接口、SD卡座、红外接收等常用接口;另外 还引出4路TTL串口,另1路TV-OUT、 SDIO2接口(可接SD WiFi)接口等;在板的 还有蜂鸣器、I2C-EEPROM、备份电池、A D 可调电阻、8个中断式按键等。 2.软件资源 1)arm-linux-gcc-4.5.1(交叉编译) 2)u-boot-2010.09.tar.gz arm-linux-gcc-4.5.1-v6-vfp-20101103.t gz 三、移植过程 1.环境搭建 1)建立交叉编译环境 2)去这2个网站随便下载都可以下载得到最 新或者你想要的u-boot。( https://www.sodocs.net/doc/6015676357.html,/batch.viewl ink.php?itemid=1694 ftp://ftp.denx.de/pub/u-boot/ )

AM335x uboot spl分析

AM335x uboot spl分析 芯片到uboot启动流程 ROM → SPL→ uboot.img 简介 在335x 中ROM code是第一级的bootlader。mpu上电后将会自动执行这里的代码,完成部分初始化和引导第二级的bootlader,第二级的bootlader引导第三级bootader,在 ti官方上对于第二级和第三级的bootlader由uboot提供。 SPL To unify all existing implementations for a secondary program loader (SPL) and to allow simply adding of new implementations this generic SPL framework has been created. With this framework almost all source files for a board can be reused. No code duplication or symlinking is necessary anymore. 1> Basic ARM initialization 2> UART console initialization 3> Clocks and DPLL locking (minimal) 4> SDRAM initialization 5> Mux (minimal) 6> BootDevice initialization(based on where we are booting from.MMC1/MMC2/Nand/Onenand) 7> Bootloading real u-boot from the BootDevice and passing control to it. uboot spl源代码分析 一、makefile分析 打开spl文件夹只有一个makefile 可见spl都是复用uboot原先的代码。 主要涉及的代码文件为u-boot-2011.09-psp04.06.00.03/arch/arm/cpu/armv7 u-boot-2011.09-psp04.06.00.03/arch/arm/lib u-boot-2011.09-psp04.06.00.03/drivers LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot-spl.lds 这个为链接脚本 __image_copy_end _end 三、代码解析 __start 为程序开始(arch/arm/cpu/armv7/start.S) .globl _start 这是在定义u-boot的启动定义入口点,汇编程序的缺省入口是 start 标号,用户也可以在连接脚本文件中用ENTRY标志指明其它入口点。

电脑启动过程详解!!!

电脑启动过程详解 1.当按下电源开关时,电源就开始向主板和其它设备供电,这时电压还不太稳定,主板上的控制芯片组会向CPU发生并保持一个RESET(重置)信号,让CPU内部自动恢复到初始状态,但CPU在些刻不会马上执行指令,当芯片组检查到电源已经开始稳定供电了(当然从不稳定,到稳定的过程只是一瞬间的事情)它便撤去RESET信号(如果是手工按下电脑面板上的RESET按钮来重启机器,那么松开该按钮时芯片组就会撤去RESET信号)CPU马上从地址FFFF0H处开始执行指令,这个地址实际在系统BIOS的地址范围内, 无论是Award BIOS,还是AMI BIOS,在这里的只是一条跳转指令,跳到系统BIOS中真正的启动代码处。 2.系统BIOS的启动代码首先要做的事情就进行POST(Power-On Self Test,加电后自检),POST的主要任务是检查系统中一些关键设备是否存在和是否正常工作,例如内存和显卡等设备.由于POST是最早进行的检查过程,此时显卡还没有初始化,如果系统BIOS在进行POST的过程中发现了些致命错误,例如没有找到内存或内存有问题 (此时只会检查640KB常规内存),那么系统BIOS就会直接控制嗽叭发生声音来报告错误,声音的长短和次数代表了错误的类型.在正常情况下,POST过程进行的非常快,我们几乎无法感觉到它的存在,POST结束之后就会调用其它代码来进行更完整的硬件检测。 3.接下来系统BIOS将查找显卡的BIOS,前面说过,存放显卡BIOS的ROM芯片的超始地址通常设在 C0000H,系统BIOS在这个地方找到显卡BIOS之后就调用它的初始化代码来初始化显卡,此时多数显卡都在屏幕上显示出一些初始化信息,介绍生产厂商,图形芯片类型等内容,不过这个画面几乎是一闪而过,系统BIOS接着会查找其它设备的BIOS程序,找到之后同样会调用这些BIOS内部的初始化代码来初始化相关的设备。 4.查找完所有其它设备的BIOS之后,系统BIOS将显示出它自己的启动画面,其中包括有系统BISO的类型,序列号和版本号等内容. 5.接着系统BIOS将检查和显示CPU的类型和工作频率,然后开始测试所有RAM,并同时在屏莫显示内存测试的速度,用户可以在CMOS设置中自行决定使用简单耗时少或详细耗时多的测试方式. 6.内存测试通过之后,系统BIOS将开始检测系统中安装的一些标准硬件设备,包括硬盘,CD-ROM,串口,并口,软驱等设备,另外绝大数较新版本的系统BIOS在这一过程中还要自动检测和设置内存的定时参数,硬盘参数和访问模式等. 7.标准设备检查完毕后,系统BIOS内部的支持即插即用的代码将开始检测和配置系统中安装的的即插即用设备,每找到一个设备之后,系统BIOS都会在屏幕上显示出设备的名称和型号等信息,同时为该设备分配中断,DMA通道和I/O端口等资源。 8.到这一步为止,所有硬件都已经检测配置完毕了,多数系统BIOS会重新清屏并在屏幕上方显示出一个表格,其它概略地列出了系统中安装的各种标准硬件设备,以及它们使用的资源和一些相关工作参数。 9.接下来系统BIOS会更新ESCD(Extended system configuration data,扩展系统配置数据.)ESCD是系统BIOS用来与操作系统交换硬件配置信息的一种手段,这些数据被存放在CMOS之中,通常ESCD数据只在系统配置发生改变后才会更新,所以不是每次启动电脑时都能够看到"updata ESCD … Success"这样的信息, 不过某些主板的系统BIOS在保存ESCD数据时使用了与widnwos 9x不相同的数据格式,于是widnwos 9x在启动过程中会把ESCD数据修改成自己的格式,但在下一次启动时,既使硬件配置没有发生改变,系统BIOS也会把ESCD的数据格式修改回来,如此循环,将会导致在每次启动电脑时,系统BIOS都要更新一遍ESCD,这就是为什么有些机器在每次启动时都会显示出相关信息的原因。 10.ESCD更新完毕后,系统BIOS的启动代码将进行它的最后一项工作,即根据用户指定的启动顺序从软件,硬件或光驱启动,以从C盘启动为例,系统BIOS将读取并执行硬盘上的主引导记录,主引导记录接着从分区表中找到第一个活动分区,然后读取并执行这个活动分区的引导记录,而分区引导记录将负责读取并执行 IO.SYS这是DOS和widnows 9x的IO.SYS(或NT的NTLDR)首先要初始化一些重要的系统数据,然后将显示出我们熟悉的蓝天白云,在这幅画面之下,widnwos 将继续进行DOS部分和GUI(图形用户界面)部分的引导和初始化工作. 上面介绍的便是电脑在打开电源开关(或按RESET)进行冷启动时所要完成的各种初始化工作,如果在DOS 下按Ctrl Alt DEL组合键,(或从windows中选择重新启动电脑)来进行热启动,那么POST过程将被跳过去,

启动代码startups分析

启动代码start.s(相当于bootloader的前端代码),开机就执行的代码,即0x0000处放置的代码。给CPU一个合适的工作环境。面向CPU内核和外围硬件,所以一般用汇编编写。 1、在起始地址分配中断向量表即中断处理函数(CPU要求的),以为向量空间只有4字节,所以一般只是一个跳转指令,去别处执行。 2、之后初始化存储器系统 3、初始多个模式下的堆栈(模式切换时,硬件给SP置位) 4、初始化有特殊要求的外围设备,如LED灯、看门狗 5、初始化用户的执行环境(在FLASH中运行太慢了,把代码整体搬迁到RAM中) 6、切换处理器的工作模式 7、调用主程序 (没见到有存储控制器的配置代码,也没见到有时钟初始化代码) 下面分析,所给的2410的启动代码实现了以上的那些功能,实现得显然不全,或者不需要,或者在工程代码的其它部分实现。 读程序时注意,所有程序都是逐行顺序执行的,要看清跳转指令。 GET 2410addr.s //用到了2410addr.s中的寄存器地址宏定义 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Some ARM920 CPSR bit discriptions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;Pre-defined constants//预定义的变量,一下后续代码中使用方便,与CPSR相关USERMODE EQU 0x10 FIQMODE EQU 0x11 IRQMODE EQU 0x12 SVCMODE EQU 0x13 ABORTMODE EQU 0x17 UNDEFMODE EQU 0x1b MODEMASK EQU 0x1f NOINT EQU 0xc0 I_Bit * 0x80 F_Bit * 0x40 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; MMU Register discription ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;p15 CP 15 ;c0 CN 0 ;c1 CN 1 ;c2 CN 2 ;c3 CN 3

UBoot移植详解

u-boot 移植步骤详解 1 U-Boot简介 U-Boot,全称Universal Boot Loader,是遵循GPL条款的开放源码项目。从FADSROM、8xxROM、PPCBOOT逐步发展演化而来。其源码目录、编译形式与Linux内核很相似,事实上,不少U-Boot源码就是相应的Linux内核源程序的简化,尤其是一些设备的驱动程序,这从U-Boot源码的注释中能体现这一点。但是U-Boot不仅仅支持嵌入式Linux 系统的引导,当前,它还支持NetBSD, VxWorks, QNX, RTEMS, ARTOS, LynxOS嵌入式操作系统。其目前要支持的目标操作系统是OpenBSD, NetBSD, FreeBSD,4.4BSD, Linux, SVR4, Esix, Solaris, Irix, SCO, Dell, NCR, VxWorks, LynxOS, pSOS, QNX, RTEMS, ARTOS。这是U-Boot中Universal的一层含义,另外一层含义则是U-Boot除了支持PowerPC系列的处理器外,还能支持MIPS、x86、ARM、NIOS、XScale等诸多常用系列的处理器。这两个特点正是U-Boot项目的开发目标,即支持尽可能多的嵌入式处理器和嵌入式操作系统。就目前来看,U-Boot对PowerPC系列处理器支持最为丰富,对Linux的支持最完善。其它系列的处理器和操作系统基本是在2002年11 月PPCBOOT 改名为U-Boot后逐步扩充的。从PPCBOOT向U-Boot的顺利过渡,很大程度上归功于U-Boot的维护人德国DENX软件工程中心Wolfgang Denk[以下简称W.D]本人精湛专业水平和持着不懈的努力。当前,U-Boot项目正在他的领军之下,众多有志于开放源码BOOT LOADER移植工作的嵌入式开发人员正如火如荼地将各个不同系列嵌入式处理器的移植工作不断展开和深入,以支持更多的嵌入式操作系统的装载与引导。 选择U-Boot的理由: ①开放源码; ②支持多种嵌入式操作系统内核,如Linux、NetBSD, VxWorks, QNX, RTEMS, ARTOS, LynxOS; ③支持多个处理器系列,如PowerPC、ARM、x86、MIPS、XScale; ④较高的可靠性和稳定性; ④较高的可靠性和稳定性; ⑤高度灵活的功能设置,适合U-Boot调试、操作系统不同引导要求、产品发布等; ⑥丰富的设备驱动源码,如串口、以太网、SDRAM、FLASH、LCD、NVRAM、EEPROM、RTC、键盘等; ⑦较为丰富的开发调试文档与强大的网络技术支持; 2 U-Boot主要目录结构 - board 目标板相关文件,主要包含SDRAM、FLASH驱动; - common 独立于处理器体系结构的通用代码,如内存大小探测与故障检测;

i.MX6UL -- Linux系统移植过程详解(最新的长期支持版本)

i.MX6UL -- Linux系统移植过程详解(最新的长期支持版本) ?开发平台:i.MX 6UL ?最新系统: u-boot2015.04 + Linux4.1.15_1.2.0 ?交叉编译工具:dchip-linaro-toolchain.tar.bz2 源码下载地址: U-Boot: (选择rel_imx_4.1.15_1.2.0_ga.tar.bz2) https://www.sodocs.net/doc/6015676357.html,/git/cgit.cgi/imx/uboot-imx.git/ Kernel: (选择rel_imx_4.1.15_1.2.0_ga.tar.bz2) https://www.sodocs.net/doc/6015676357.html,/git/cgit.cgi/imx/linux-2.6-imx.git/ 源码移植过程: 1、将linux内核及uBoot源码拷贝到Ubuntu12.04系统中的dchip_imx6ul目录下; 2、使用tar命令分别将uboot和kernel解压到dchip_imx6ul目录下; 3、解压后进入uboot目录下,新建文件make_dchip_imx6ul_uboot201504.sh,且文件内容如下: ################################################################### # Build U-Boot.2015.04 For D518--i.MX6UL By FRESXC # ################################################################### #!/bin/bash export ARCH=arm export CROSS_COMPILE=/dchip-linaro-toolchain/bin/arm-none-linux-gnueabi - make mrproper # means CLEAN make mx6ul_14x14_evk_defconfig make2>&1|tee built_dchip_imx6ul_uboot201504.out 4进入kernel目录下,新建文件make_dchip_imx6ul_linux4115120.sh,且文件内容如下: ###################################################################

uboot版本文件结构

uboot版本文件结构的更新改变 分类:ARM2011-09-22 12:57 339人阅读评论(0) 收藏举报本来是开始分析uboot代码的,但是无论是教材还是网上资料都对于我最新下的uboot原码结构不同,对于还是小白的我不容易找到相应的文件,下面是uboot版本中文件组织结构的改变,,,,, u-boot版本情况 网站:http://ftp.denx.de/pub/u-boot/ 1、版本号变化: 2008年8月及以前 按版本号命名:u-boot-1.3.4.tar.bz2(2008年8月更新) 2008年8月以后均按日期命名。 目前最新版本:u-boot-2011.06.tar.bz2(2011年6月更新) 2、目录结构变化: u-boot目录结构主要经历过2次变化,u-boot版本第一次从u-boot-1.3.2开始发生变化,主要增加了api的内容;变化最大的是第二次,从2010.6版本开始。 u-boot-2010.03及以前版本 ├── api存放uboot提供的接口函数 ├── board根据不同开发板定制的代码,代码也不少 ├── common通用的代码,涵盖各个方面,已命令行处理为主 ├── cpu与体系结构相关的代码,uboot的重头戏 ├── disk磁盘分区相关代码 ├── doc文档,一堆README开头的文件 ├── drivers驱动,很丰富,每种类型的设备驱动占用一个子目录 ├── examples示例程序 ├── fs文件系统,支持嵌入式开发板常见的文件系统 ├── include头文件,已通用的头文件为主 ├── lib_【arch】与体系结构相关的通用库文件 ├── nand_spl NAND存储器相关代码 ├── net网络相关代码,小型的协议栈 ├── onenand_ipl

keil下C51启动代码详解

由于CPU和程序启动代码文件STARTUP.a51的重要性,一些8051派生的CPU产品要求初始化CPU来满足设计中的相应的硬件,因此,有时候用户需要对STARTUP.a51进行修改,所以进行注释一下: ;--------------------------------------------------- ;startup.A51: 用户上电初始化程序 ;---------------------------------------------------- ; ;使用以下EQU命令可定义在CPU复位时需要用0进行初始化的内存空间 ; ;IDA TA存储器的空间的绝对起始地址总是零 IDA TALEN EQU 80H ;需用0进行初始化的IDA TA存储器空间的字节数 ; XDA TASTART EQU 0H ;XDA TA存储器空间的绝对起始地址 XDA TALEN EQU 0H ;需用0进行初始化的XDA TA存储器的空间字节数 ; PDA TASTART EQU 0H ;PDA TA存储器的空间的绝对起始地址 PDA TALEN EQU 0H ;需用0进行初始化的PDA TA存储器的空间字节数 ;注意:IDA TA存储器的空间在物理上包括了8051单片机的DA TA和BIT存储空间 ;至少要保证与C51编译器运行库有关的存储器的空间进行0初始化 ; ;再入函数模拟初始化 ;----------------------------------------------------------- ;以下用EQU指令定义了再入函数模拟堆栈指针的初始化 ; ;使用SMALL存储器模式时再入函数的堆栈空间 IBPSACK EQU 0 ;使用SMALL存储器模式再入函数时将其设置成1 IBPSTACKTOP EQU 0FFH+1 ;将堆栈顶设置为最高地址加1 ; ;使用LARGE存储器模式时再入函数的堆栈空间 XBPSTACK EQU 0 ;使用LARGE存储器模式再入函数时将其设置成1 XBPSTACKTOP WQU 0FFFFH+1 ;将堆栈顶设置为最高地址加1 ; ;使用COMPACT存储器模式时再入函数的堆栈空间 PBPSTACK EQU 0 ; 使用COMPACT存储器模式再入函数时将其设置成1 PBPSTACKTOP WQU 0FFFFH+1 ;将堆栈顶设置为最高地址加1 ;;---------------------------------------------------- ;使用COMPACT存储器模式时,64KB X DA TA存储器空间的分页定义 ; ;以下用EQU指令定义PDA TA类型变量在XDA TA存储器空间的页地址 ;使用EQU指令定义PFAGE时必须与L51连接定位器PDA TA指令的控制参数一致 ; PPAGEENABLE EQU 0 ;使用PDA TA类型变量时将其设置成1 PPAGE EQU 0 ;定义页号 ; ;------------------------------------------------ NAME ? C_STARTUP ;模块名为? C_STARTUP ? C_51STARTUP SEGMENT CODE ;代码段 ? STACK SEGMENT IDA TA;堆栈段 RSEG ? STACK ;堆栈 DS 1 EXTRN COE(? C_START) ;程序开始地址

STM32F10x 启动代码文件选择

startup_stm32f10x_xx.s 启动代码文件选择startup_stm32f10x_cl.s 互联型的器件,STM32F105xx,STM32F107xx startup_stm32f10x_hd.s 大容量的STM32F101xx,STM32F102xx,STM32F103xx startup_stm32f10x_hd_vl.s 大容量的STM32F100xx startup_stm32f10x_ld.s 小容量的STM32F101xx,STM32F102xx,STM32F103xx startup_stm32f10x_ld_vl.s 小容量的STM32F100xx startup_stm32f10x_md.s 中容量的STM32F101xx,STM32F102xx,STM32F103xx startup_stm32f10x_md_vl.s 中容量的STM32F100xx startup_stm32f10x_xl.s FLASH在512K到1024K字节的STM32F101xx,STM32F102xx,STM32F103xx 固件库中的Release_Notes_for_STM32F10x_CMSIS.html写到: STM32F10x CMSIS Startup files: startup_stm32f10x_xx.s Add new startup files for STM32 Low-density Value line devices: startup_stm32f10x_ld_vl.s Add new startup files for STM32 Medium-density Value line devices: startup_stm32f10x_md_vl.s SystemInit() function is called from startup file (startup_stm32f10x_xx.s) before to branch to applic ation main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f10x.c file GNU startup file for Low density devices (startup_stm32f10x_ld.s) is updated to fix compilation err ors. 例如我用STM32F103RB,那么选启动文件为startup_stm32f10x_md.s

uboot环境变量总结

Common目录下面与环境变量有关的文件有以下几个:env_common.c,env_dataflash.c,env_eeprom.c,env_flash.c,env_nand.c,env_nowhere.c,env_nvram.c,environment.c。 env_common.c中包含的是default_environment[]的定义; env_dataflash.c,env_eeprom.c,env_flash.c,env_nand.c, env_nvram.c 中包含的是相应存储器与环境变量有关的函数:env_init(void),saveenv(void),env_relocate_spec (void),env_relocate_spec (void),use_default()。至于env_nowhere.c,因为我们没有定义CFG_ENV_IS_NOWHERE,所以这个文件实际上没有用。 environment.c这个文件时是我真正理解环境变量的一个关键。在这个文件里定义了一个完整的环境变量的结构体,即包含了这两个ENV_CRC(用于CRC校验),Flags(标志有没有环境变量的备份,根据CFG_REDUNDAND_ENVIRONMENT这个宏定义判断)。定义这个环境变量结构体的时候还有一个非常重要的关键字: __PPCENV__,而__PPCENV__在该.c文件中好像说是gnu c编译器的属性,如下: # define __PPCENV__ __attribute__ ((section(".text"))) 意思是把这个环境变量表作为代码段,所以在编译完UBOOT后,UBOOT的代码段就会有环境变量表。当然,这要在我们定义了ENV_IS_EMBEDDED之后才行,具体而言,环境变量表会在以下几个地方出现(以nand flash为例): 1、UBOOT中的代码段(定义了ENV_IS_EMBEDDED), 2、UBOOT中的默认环 境变量, 3、紧接UBOOT(0x0 ~ 0x1ffff)后面:0x20000 ~ 0x3ffff 之间,包括备份的环境变量,我们读取,保存也是对这个区域(即参数区)进行的。3、SDRAM中的UBOOT中,包括代码段部分和默认部分,4、SDRAM中的melloc分配的内存空间中。 Environment.c代码如下: env_t environment __PPCENV__ = { ENV_CRC, /* CRC Sum */ #ifdef CFG_REDUNDAND_ENVIRONMENT 1, /* Flags: valid */ #endif { #if defined(CONFIG_BOOTARGS) "bootargs=" CONFIG_BOOTARGS "\0" #endif #if defined(CONFIG_BOOTCOMMAND) "bootcmd=" CONFIG_BOOTCOMMAND "\0" #endif #if defined(CONFIG_RAMBOOTCOMMAND) "ramboot=" CONFIG_RAMBOOTCOMMAND "\0"

ARM启动代码研究

ARM启动代码研究 PRESERVE8: 1.1.PRESERVE8: Reguire8和Preserve8 C和汇编有8位对齐的要求,这两个伪指令可以满足此要求,存在REQUIRE8<——> PRESERVE8的对应关系,但不是说有一个REQUIRE8就要有一个PRESERVE8,如果是一个c文件和一个汇编文件的调用,也就涉及一个PRESERVE8或者是一个REQUIRE8. 另外,REQUIRE8和PRESERVE8并不完成8byte对齐的操作,对齐由ALIGN完成。 将ADS的代码移植到KEIL MDK上需要做的修改: 当用户拥有ADS遗留工程的所有源代码时,使用MDK重新编译链接全部代码是最好的解决方法,MDK中的新版本编译工具会重新生成满足堆栈8BYTE对齐要求的目标文件,避免由于堆栈不对齐引起的链接错误. 从ADS到KEIL很重要的一个修改的地方就是这里的8BYTE对齐,想要编译通过,在startup.s 里面我们必须加入PRESERVE8指令,使得寄存器8BYTE对齐. 代码: CODE32 PRESERVE8;这个在KEIL里面是必须的,要求8BYTE对齐.在ADS的启动代码中就没有. AREA vectors,CODE,READONLY 2:ARM的处理器可工作于多种模式,下面设置个模式的一些参数. Mode_USR EQU0x10用户模式 Mode_FIQ EQU0x11快中断模式 Mode_IRQ EQU0x12中断模式 Mode_SVC EQU0x13管理模式

Mode_ABT EQU0x17中止模式 Mode_UND EQU0x1B未定义模式 Mode_SYS EQU0x1F系统模式 参数的由来:这里各个模式的参数是由寄存器CPSR的模式位设置M[4:0]得来的,比如这里的用户模式,CPSR的M[4:0]设置为10000就是0x10,同理其他.详见<>P47页,CPSR设置很关键! 3: I_Bit EQU0x80;when I bit is set,IRQ is disabled F_Bit EQU0x40;when F bit is set,FIQ is disabled 也和CPSR寄存器的设置有关,这里两位是禁止/开启快速中断和一般中断的设置. 4:各模式下定义的堆栈地址. UND_Stack_Size EQU0x00000000 SVC_Stack_Size EQU0x00000100 ABT_Stack_Size EQU0x00000000 FIQ_Stack_Size EQU0x00000000 IRQ_Stack_Size EQU0x00000100 USR_Stack_Size EQU0x00000200 设置堆栈大小 Stack_Size EQU(UND_Stack_Size+SVC_Stack_Size+ABT_Stack_Size+ FIQ_Stack_Size+IRQ_Stack_Size+USR_Stack_Size) AREA STACK,NOINIT,READWRITE,ALIGN=3 Stack_Mem SPACE Stack_Size

相关主题