Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- I vezba:
- tar -xvf vezba1.tar.bz2
- cd vezba1/
- ll
- mv tkst/ tekst
- mv *.txt tekst/
- mv .*.txt tekst/
- ls -d.*
- more .pastacode.txt
- less .pastacode.txt
- ll > ls.txt
- diff ls2.txt ls.txt
- pushd vezba1/
- cat sardar.txt || cat sardar1.txt > sardar.txt
- diff sardar.txt sardar1.txt
- chmod u+r sardar2.txt
- head -20 sardar2.txt
- tail sardar.txt -f
- cat sardar2.txt >> sardar.txt
- mkdir -p sardar/complete
- mv sardar.txt sardar/complete/sardar_all.txt
- rm dir1
- rm ./-o
- grep -r santa .
- grep -ri santa . && grep -ri singh .
- grep -v -r Banta .
- grep -ri money .
- grep -ri -n money .
- grep -ri money --context=1 .
- grep -ril money .
- grep -ril money . | xargs ls
- grep -ril money . | xargs rm -r
- rm -rf safe
- sort < declarations.h
- sort -r < declarations.h
- rsync -Pav tekst/ tekst1/
- diff tekst/ tekst1/
- II vezba:
- ln -s ~/linux_vezbe/Dan01/vezbe/vezba1 vezba1
- jobs
- kill 9683
- xkill
- rsync -Pav /home/mika/linux_vezbe/Dan01/vezbe/vezba1 vezba1cp/
- sed -i -e 's/^LOG/ALOG/g' sed2.txt
- sed -i -e 's/^printf/printfile/g' sed2.txt
- diff vezba1/ ~/linux_vezbe/Dan01/vezbe/vezba1
- meld vezba1/ ~/linux_vezbe/Dan01/vezbe/vezba1
- meld vezba1/sed1.txt ~/linux_vezbe/Dan01/vezbe/vezba1/sed1.txt
- killall meld
- tar -cjf vezba1.tar.bz2 vezba1/
- IV vezba:
- ################################################################################
- Pre svakog make odraditi export ARCH i CROSS_COMPILE
- Posle svakog make(make iz src/linux) radi sledece
- Kopiramo zImage iz linux-kernel-labs/src/linux/arch/arm/boot u /var/lib/tftpboot
- ################################################################################
- Ako boot-ujemo sa NFS filesystem-om preko (preko mreze)
- picocom -b 115200 /dev/ttyUSB0
- Proveriti /etc/exports da li je dobar nfsroot
- Restratovati nfs(sudo /etc/init.d/nfs-kernel-server restart)
- U u-boot kucamo ako vec nije podeseno na ovo
- setenv bootargs "root=/dev/nfs rw ip=<IPadresarpi> console=ttyAMA0,115200 nfsroot=<IPadresapc>:/home/<user>/linux-kernel-labs/modules/nfsroot"
- saveenv
- A ako boot-ujemo preko mreze podesavamo bootargs na
- setenv bootcmd "tftp 0x01000000 zImage; tftp 0x02000000 bcm2709-rpi-2-b.dtb; bootz 0x01000000 - 0x02000000"
- saveenv
- ###############################################################################
- A ako boot-ujemo sa kartice sa njegovim filesystem-om
- setenv bootcmd run mmc_boot
- saveenv
- setenv bootargs "root=/dev/mmcblk0p2 rootwait console=ttyAMA0,115200"
- setenv bootcmd "fatload mmc 0:1 0x01000000 zImage; fatload mmc 0:1 0x02000000 bcm2709-rpi-2-b.dtb; bootz 0x01000000 - 0x02000000"
- saveenv
- ##############################################################################
- Kad budete primenjivali patch komanda
- patch -p1 < ~/linux-kernel-labs/modules/data/LinuksKurs.patch
- Patch se primenjuje na src/linux
- Pitati Maksu kako da se zImage uprzi na karticu
- ##############################################################################
- V vezba:
- Kopirati zadatu konfiguraciju a pozicioniras se u src/linux
- cp ~/linux-kernel-labs/modules/data/Linux.config .config
- make xconfig
- Ukljucimo frame buffer i ostalo
- Kucamo make u src/linux
- make modules_install INSTALL_MOD_PATH=~/linux-kernel-labs/modules/nfsrootVezba/
- cd ~/linux-kernel-labs/modules/nfsrootVezba/dev
- Za pretrazivanje major i minor broja cd /dev
- Pa odraditi ll
- sudo cp /linux-kernel-labs/src/linux/arch/arm/boot/zImage /var/lib/tftpboot
- bootargs=root=/dev/nfs rw ip=192.168.0.100 console=ttyAMA0,115200 nfsroot=192.168.0.12:/home/mika/linux-kernel-labs/modules/nfsrootVezba
- bootargs_nfs=setenv bootargs root=/dev/nfs rw ip=192.168.0.100 console=ttyAMA0,115200 nfsroot=192.168.0.12:/home/mika/linux-kernel-labs/modules/nfsrootVezba/
- Kreiramo sa sudo mknod uredjaj
- mknod u dev folderu
- sudo mknod ttyAMA0 c 204 64
- sudo mknod tty0 c 4 0
- sudo mknod tty1 c 4 1
- sudo mknod tty2 c 4 2
- sudo mknod tty3 c 4 3
- sudo mknod tty4 c 4 4
- sudo mknod console c 5 1
- sudo mknod null c 1 3
- U dev kreiramo fb0
- sudo mknod fb0 c 29 0
- ###############################################################################
- VI vezba:
- Raspaujemo tar -xjf busybox-1.21.1.tar.bz2
- Kopiramo konfiguracju za busy-box
- Pozicionirati se u src/linux
- sudo cp ~/linux-kernel-labs/modules/data/tinyLinux.config .config
- Nakon toga iskoristiti istu konfiguraciju u linux-kernel-labs/src/busybox-1.21.1/
- sudo cp ~/linux-kernel-labs/modules/data/tinyBusybox.config .config
- Kad smo prekopirali config pokrecemo sa make menuconfig podesavanja, i u njima u build-options selektujemo static build.
- Posle pokrecemo make install a rfs ce biti u _install
- A u dev kreiraj console i ttyAMA0
- -------------------------
- sudo mknod console c 5 1
- sudo mknod ttyAMA0 c 204 64
- -------------------------
- U ~/linux-kernel-labs/src/busybox-1.21.1/_install/ pravimo etc/init.d proc sys
- cd ~/linux-kernel-labs/src/busybox-1.21.1/_install/
- mkdir proc
- mkdir sys
- mkdir -p etc/init.d
- Da napravis rcS file
- Odradi gedit rcS
- Kreiramo u etc/init.d koji je u _install rcS i u njemu pisemo
- --------------------------
- #!/bin/sh
- mount -t proc proc /proc
- mount -t sysfs sys /sys
- -------------------------
- A u etc kreirati inittab i pisemo
- -------------------------
- ::sysinit:/etc/init.d/rcS
- ttyAMA0::askfirst:/bin/sh
- -------------------------
- Kopiramo ~/linux-kernel-labs/modules/data/www u ~/linux-kernel-labs/src/busybox-1.21.1/_install
- Restratovati nfs(sudo /etc/init.d/nfs-kernel-server restart)
- Uraditi u U-boot reboot uredjaja
- I kad se otvori konzola ukucati /usr/sbin/httpd -h /www/ &
- Zatim otvoriti web browser(Firefox Mozzila ili Google Chrome[ver-4.6.92])
- Ukucati u pretrazivacu "http://adresu pi-ja"
- -------------------------
- Pozicionirati se u busybox-1.21.1/_install
- Prvo kreiramo gedit hello_world.c
- Zatim odradimo arm-linux-gnueabihf-gcc hello_world.c -o hello
- Pozovemo arm-linux-gnueabihf-readelf -a hello > hw.txtt
- Zatim pravimo u busybox-1.21.1 direkktorijum lib
- I kopiramo u taj direktorijum ono sto pise u hw.txt(otvori na bilo koj nacin),sa CTRL+F naci .so i videti sta treba koporati
- Za kopiranje se pozicionirati u cd /usr/arm-linux-gnueabihf/lib/
- Kopirati te biblioteke
- sudo cp ld-linux-armhf.so.3 /home/mika/linux-kernel-labs/src/busybox-1.21.1/_install/lib/
- sudo cp libc.so.6 /home/mika/linux-kernel-labs/src/busybox-1.21.1/_install/lib/
- Vracamo se u busybox-1.21.1
- Odradimo make menuconfig
- Otici na Busybox Setting-> Busybox Options-> pa deaktivirati static build.
- Zatim odraditi make install
- Pozicionirati se u cd /usr/arm-linux-gnueabihf/lib/
- Kopirati biblioteku
- sudo cp libm.so.6 /home/mika/linux-kernel-labs/src/busybox-1.21.1/_install/lib/
- --------------------------
- U /home/mika/linux-kernel-labs/src/busybox-1.21.1/_install/ preimenovati linuxrc u init
- mv linuxrc init
- Pa zatim se pozicioniras u /home/mika/linux-kernel-labs/src/linux pa pokrenes
- make xconfig
- Nadjemo sa CTRL+f initramfs i u text-box polje unesemo /home/mika/linux-kernel-labs/src/busybox-1.21.1/_install/
- Sada se pozicioniramo u src/linux
- Ponovo prevedemo kernel i kopiramo zImage
- make
- cp ~/linux-kernel-labs/src/linux/arch/arm/boot/zImage /var/lib/tptpboot
- Pokrenemo uboot i izmenimo bootargs sa rw console=ttyAMA0,115200
- ###############################################################################
- VII vezba:
- U linux/src pokrenemo make bcm2709_defconfig
- Makeujemo kernel
- Bootargs smo promenili da bude nfs root koji vec dat
- bootargs=root=/dev/nfs rw ip=192.168.0.100 console=ttyAMA0,115200 nfsroot=192.168.0.12:/home/mika/linux-kernel-labs/modules/nfsroot
- Proveriti /etc/exports da li je dobar nfsroot
- Restartovati server
- Pozicioniramo se u nfsroot/root/hello i iz prezentacije P6.2 str6 iskucali funkcije za init i exit za ispis pocetnih i krajnjih poruka
- Kad smo preveli modul ali ga prevodimo u na nasem Linuxu
- Kad dobijemo konzolu pozicioniramo se u hello,u njemu pozovemo insmod hello_version.ko izlistavamo sa lsmod da vidimo dal je ucitan
- Kada ga uklanjamo uklanjamo ga sa rmmod hello_version
- Za parametre koristimo insmod hello_version.ko who=Beli pri insmodovanju
- Implementirali sve u hello_version.c
- *********************************************************************************************************
- #include <linux/init.h>
- #include <linux/module.h>
- #include <linux/i2c.h>
- #include <linux/kernel.h> //za KERN_INFO
- #include <linux/moduleparam.h> //za argumente modula
- #include <linux/utsname.h> //za dobavljanje verzije
- #include <linux/string.h> //za strlen u read funkciji
- #include <linux/fcntl.h> //za funkcije koje komuniciraju sa user space
- #include <linux/proc_fs.h>
- #include <asm/uaccess.h>
- #include <linux/slab.h>
- #include <linux/fs.h>
- #include <linux/ctype.h>
- #include <linux/debugfs.h>
- #include <linux/printk.h>
- #include <linux/device.h>
- /* Add your code here */
- static void __exit hello_exit(void);
- static int __init hello_init(void);
- static ssize_t hello_read(struct file *fi, char *buff, size_t len, loff_t *f_pos);
- static ssize_t hello_write(struct file *fi, char *buff, size_t len, loff_t *f_pos);
- static int hello_ioctl(struct file *fi, int op);
- static char* who = "";
- static char* buffer;
- static u32 major;
- static unsigned int brojacU = 0;
- static unsigned int brojacP = 0;
- static unsigned int brojacD = 0;
- static int opt = -1;
- static struct dentry *dir = 0;
- static struct file_operations hello_fops =
- {
- .read = hello_read,
- .write = hello_write,
- .unlocked_ioctl = hello_ioctl
- };
- static int __init hello_init(void)
- {
- pr_alert("Hello %s. You are currently using Linux %s", who, utsname()->release);
- int res;
- res = register_chrdev(0,"hello",&hello_fops);
- major = res;
- if(res<0)
- {
- printk("Ne mogu da nadjem major broj");
- return res;
- }
- buffer = kmalloc(100, GFP_KERNEL);
- if (!buffer)
- {
- goto fail;
- }
- memset(buffer, 0, 100);
- printk(KERN_INFO "Major broj: %d",major);
- return 0;
- fail:
- hello_exit();
- }
- static ssize_t hello_read(struct file *fi, char *buff, size_t len, loff_t *f_pos)
- {
- int data_size=0;
- if(*f_pos == 0)
- {
- data_size = strlen(buffer);
- brojacP += data_size;
- if(copy_to_user(buff,buffer,data_size) != 0)
- {
- return -1;
- }
- else
- {
- (*f_pos) += data_size;
- return data_size;
- }
- }
- else
- {
- return 0;
- }
- }
- static ssize_t hello_write(struct file *fi, char *buff, size_t len, loff_t *f_pos)
- {
- memset(buffer, 0, 100);
- if(copy_from_user(buffer,buff,len)!=0)
- {
- return -1;
- }
- else
- {
- brojacD = len;
- pr_debug("Dostupno za citanje %d bajta",brojacD);
- brojacU += len;
- pr_debug("Broj upisanih bajta %d",brojacU);
- return len;
- }
- }
- static int hello_ioctl(struct file *fi, int op)
- {
- int i = 0;
- if(op == 0)
- {
- while(buffer[i]){
- buffer[i] = toupper(buffer[i]);
- i++;
- }
- }
- else if(op == 1)
- {
- while(buffer[i]){
- buffer[i] = tolower(buffer[i]);
- i++;
- }
- }
- }
- static void __exit hello_exit(void)
- {
- if(buffer)
- {
- kfree(buffer);
- }
- unregister_chrdev(major,"hello");
- pr_alert("Goodbye %s \n",who);
- }
- module_param(who, charp, 0);
- module_param(opt, int, 0);
- module_init(hello_init);
- module_exit(hello_exit);
- MODULE_LICENSE("GPL");
- *********************************************************************************************************
- Napravili smo u /dev uredjaj sa major brojem koji nam je kernel dao
- mknod hellodev c 244 0
- Testiranje write operacije
- echo "TeStni StRing" >> hellodev
- Testiranje read operacije
- cat /dev/hellodev
- Za ioctl prevedemo ioctl.c pomocu komande
- arm-linux-gnueabihf-gcc ioctl.c -o ioctle -static
- Zatim ga pokrecemo u u-bootu sa ./ioctle /dev/hellodev 1
- Iscitamo sa cat /dev/hellodev
- Pozicioniramo se u src/linux/drivers/misc
- Prekopiramo hello_version.c i hello_version.o
- Izmeniti Makefile i dodati obj-$(CONFIG_HELLO_VERSION) += hello_version.o
- Izmeniti u Kconfig
- config HELLO_VERSION
- bool "Opis"
- default y
- Vratiti se u src/linux
- Pokrenuti make xconfig
- Naci pomocu HELLO_VERSION da se cekira opcija za hello_version modul
- Pre make-a uraditi
- sudo chown -R mika.mika ~/linux-kernel-labs/modules/nfsroot/lib
- make modules_install INSTALL_MOD_PATH=~/linux-kernel-labs/modules/nfsroot
- sudo chown -R root.root ~/linux-kernel-labs/modules/nfsroot/lib
- Prevesti kernel sa make
- Posle make file kopirati zImage iz src/linux/arch/arm/boot u /var/lib/tftpboot
- I pokrenuti kernel
- ################################################################################################################
- XI vezba:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement