ARM + Linux embedded development environment setup, armlinux
These are my notes on problems encountered in ARM + Linux since September. I think they are very useful, so I will share them!
Because I don't have any teacher to teach me, I have a lot of questions. Please contact me!
Bytes --------------------------------------------------------------------------------------------------
Zero Point drifting team: Dust and waves
Bytes ---------------------------------------------------------------------------------------------------
Bytes --------------------------------------------------------------------------------------
0. Platform Construction
Bytes --------------------------------------------------------------------------------------
Download VMware11
Download Ubutun 14
Install
Solve gedit Chinese garbled characters
Terminal input:
Gsettings set org. gnome. gedit. preferences. encodings auto-detected "['gb18030', 'gb2312', 'gbk', 'utf-8', 'big5', 'current', 'utf-16']"
Bytes --------------------------------------------------------------------------------------
1. Install the dnw Tool
Bytes --------------------------------------------------------------------------------------
Sudo apt-get install libusb-dev
Dnw. c
# Include <stdio. h>
# Include <usb. h>
# Include <errno. h>
# Include <sys/stat. h>
# Include <fcntl. h>
# Include <unistd. h>
# Define TQ2440_SECBULK_IDVENDOR 0x5345
# Define TQ2440_SECBULK_IDPRODUCT 0x1234
Struct usb_dev_handle * open_port ()
{
Struct usb_bus * busses, * bus;
Usb_init ();
Usb_find_busses ();
Usb_find_devices ();
Busses = usb_get_busses ();
For (bus = busses; bus = bus-> next)
{
Struct usb_device * dev;
For (dev = bus-> devices; dev = dev-> next)
{
If (TQ2440_SECBULK_IDVENDOR = dev-> descriptor. idVendor
& TQ2440_SECBULK_IDPRODUCT = dev-> descriptor. idProduct)
{
Printf ("Target usb device found! \ N ");
Struct usb_dev_handle * hdev = usb_open (dev );
If (! Hdev)
{
Perror ("Cannot open device ");
}
Else
{
If (0! = Usb_claim_interface (hdev, 0 ))
{
Perror ("Cannot claim interface ");
Usb_close (hdev );
Hdev = NULL;
}
}
Return hdev;
}
}
}
Printf ("Target usb device not found! \ N ");
Return NULL;
}
Void usage ()
{
Printf ("Usage: dnw <file> \ n ");
}
Unsigned char * prepare_write_buf (char * filename, unsigned int * len)
{
Unsigned char * write_buf = NULL;
Struct stat fs;
Int fd = open (filename, O_RDONLY );
If (-1 = fd)
{
Perror ("Cannot open file ");
Return NULL;
}
If (-1 = fstat (fd, & fs ))
{
Perror ("Cannot get file size ");
Goto error;
}
Write_buf = (unsigned char *) malloc (fs. st_size + 10 );
If (NULL = write_buf)
{
Perror ("malloc failed ");
Goto error;
}
If (fs. st_size! = Read (fd, write_buf + 8, fs. st_size ))
{
Perror ("Reading file failed ");
Goto error;
}
Printf ("Filename: % s \ n", filename );
Printf ("Filesize: % d bytes \ n", fs. st_size );
* (U_int32_t *) write_buf) = 0x30008000; // download address
* (U_int32_t *) write_buf + 1) = fs. st_size + 10; // download size;
* Len = fs. st_size + 10;
Return write_buf;
Error:
If (fd! =-1) close (fd );
If (NULL! = Write_buf) free (write_buf );
Fs. st_size = 0;
Return NULL;
}
Int main (int argc, char * argv [])
{
If (2! = Argc)
{
Usage ();
Return 1;
}
Struct usb_dev_handle * hdev = open_port ();
If (! Hdev)
{
Return 1;
}
Unsigned int len = 0;
Unsigned char * write_buf = prepare_write_buf (argv [1], & len );
If (NULL = write_buf) return 1;
Unsigned int remain = len;
Unsigned int towrite;
Printf ("Writing data... \ n ");
While (remain)
{
Towrite = remain> 512? 512: remain;
If (towrite! = Usb_bulk_write (hdev, 0x03, write_buf + (len-remain), towrite, 3000 ))
{
Perror ("usb_bulk_write failed ");
Break;
}
Remain-= towrite;
Printf ("\ r % d % \ t % d bytes", (len-remain) * 100/len, len-remain );
Fflush (stdout );
}
If (0 = remain) printf ("Done! \ N ");
Return 0;
}
5 Compilation: gcc-o dnw. c-lusb
6. copy the file to the/usr/local/bin directory.
# Sudo cp dnw/usr/local/bin
Bytes ----------------------------------------------------------------------------------------------
2. Install ARM-linux-gcc
Bytes ----------------------------------------------------------------------------------------------
Sudo apt-get install gcc-arm-linux-gnueabi
Arm-linux-gnueabi-gcc-v
Remember: Modify Makefile:
Arm-linux-gnueabi-gcc-g-c-o led_on.o led_on.S
Arm-linux-gnueabi-ld-Ttext 0x0000000-g led_on.o-o led_on_elf
Arm-linux-gnueabi-objcopy-O binary-S led_on_elf led_on.bin
Bytes ----------------------------------------------------------------------------------------------
3. linux serial port assistant Installation
Bytes ----------------------------------------------------------------------------------------------
Sudo apt-get minicom
CTRL + A + Z
Set serial port no traffic control: ttyUSB0
--------------------------------------------------------------------------------
4. Send the file through minicom
--------------------------------------------------------------------------------
Ctrl + a s select the file to be sent
Bytes -----------------------------------------------------------------------------------
5. make menuconfig *** [scripts/kconfig/dochecklxdialog] compile the kernel
Bytes ------------------------------------------------------------------------------------
Sudo apt-get install ncurses-dev
-----------------------------------------------------------------------
6. undefined reference to '_ stack_chk_fail'
Undefined reference to '_ stack_chk_guard'
-----------------------------------------------------------------------
-Fno-stack-protector added to CFLAGS
-----------------------------------------------------------------------
7. GUI development
Download qt-creator-opensource-linux-x86_64-3.4.0
Download qtcreator
-----------------------------------------------------------------------
------------------------------------------------------------------------
8. Porting U-boot to Linux Kernel
-----------------------------------------------------------------------
Write the driver xx_dev.c (gpio_dev.c) in the corresponding directory)
Then write the application xx. c (gpio. c)
Under the same directory:
Kconfig
Add support for the kernel in the kernel source code
Config TQ2440_GPIO_TEST
Tristate "EmbedSky SKY2440/TQ2440 Board GPIO Test (control LED )"
Depends on ARCH_S3C2440
Default y if ARCH_S3C2440
Help
GPIO control for EmbedSky SKY2440/TQ2440 Board.
Makefile: Change the kernel directory to the Development Board directory.
Configure and compile the driver
Obj-$ (CONFIG_TQ2440_GPIO_TEST) + = dev_gpio.o
Configure the kernel: make menuconfig
Select M Module
Compile the kernel make zImage
Compilation module make SUBDIR = drivers/char/modules
Find xx. ko in the corresponding directory and copy it to the Development Board.
Insmod xx. ko
Rmmod xx. ko
Dmesg
--------------------------------------------------------------------------------