Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.36 KB | None | 0 0
  1. I vezba:
  2.  
  3. tar -xvf vezba1.tar.bz2
  4. cd vezba1/
  5. ll
  6. mv tkst/ tekst
  7. mv *.txt tekst/
  8. mv .*.txt tekst/
  9. ls -d.*
  10. more .pastacode.txt
  11. less .pastacode.txt
  12. ll > ls.txt
  13. diff ls2.txt ls.txt
  14. pushd vezba1/
  15. cat sardar.txt || cat sardar1.txt > sardar.txt
  16. diff sardar.txt sardar1.txt
  17. chmod u+r sardar2.txt
  18. head -20 sardar2.txt
  19. tail sardar.txt -f
  20. cat sardar2.txt >> sardar.txt
  21. mkdir -p sardar/complete
  22. mv sardar.txt sardar/complete/sardar_all.txt
  23. rm dir1
  24. rm ./-o
  25. grep -r santa .
  26. grep -ri santa . && grep -ri singh .
  27. grep -v -r Banta .
  28. grep -ri money .
  29. grep -ri -n money .
  30. grep -ri money --context=1 .
  31. grep -ril money .
  32. grep -ril money . | xargs ls
  33. grep -ril money . | xargs rm -r
  34. rm -rf safe
  35. sort < declarations.h
  36. sort -r < declarations.h
  37. rsync -Pav tekst/ tekst1/
  38. diff tekst/ tekst1/
  39.  
  40. II vezba:
  41.  
  42. ln -s ~/linux_vezbe/Dan01/vezbe/vezba1 vezba1
  43. jobs
  44. kill 9683
  45. xkill
  46. rsync -Pav /home/mika/linux_vezbe/Dan01/vezbe/vezba1 vezba1cp/
  47. sed -i -e 's/^LOG/ALOG/g' sed2.txt
  48. sed -i -e 's/^printf/printfile/g' sed2.txt
  49. diff vezba1/ ~/linux_vezbe/Dan01/vezbe/vezba1
  50. meld vezba1/ ~/linux_vezbe/Dan01/vezbe/vezba1
  51. meld vezba1/sed1.txt ~/linux_vezbe/Dan01/vezbe/vezba1/sed1.txt
  52. killall meld
  53. tar -cjf vezba1.tar.bz2 vezba1/
  54.  
  55. IV vezba:
  56.  
  57.  
  58. ################################################################################
  59. Pre svakog make odraditi export ARCH i CROSS_COMPILE
  60. Posle svakog make(make iz src/linux) radi sledece
  61. Kopiramo zImage iz linux-kernel-labs/src/linux/arch/arm/boot u /var/lib/tftpboot
  62. ################################################################################
  63. Ako boot-ujemo sa NFS filesystem-om preko (preko mreze)
  64.  
  65. picocom -b 115200 /dev/ttyUSB0
  66. Proveriti /etc/exports da li je dobar nfsroot
  67. Restratovati nfs(sudo /etc/init.d/nfs-kernel-server restart)
  68.  
  69. U u-boot kucamo ako vec nije podeseno na ovo
  70.  
  71. setenv bootargs "root=/dev/nfs rw ip=<IPadresarpi> console=ttyAMA0,115200 nfsroot=<IPadresapc>:/home/<user>/linux-kernel-labs/modules/nfsroot"
  72. saveenv
  73.  
  74. A ako boot-ujemo preko mreze podesavamo bootargs na
  75.  
  76. setenv bootcmd "tftp 0x01000000 zImage; tftp 0x02000000 bcm2709-rpi-2-b.dtb; bootz 0x01000000 - 0x02000000"
  77. saveenv
  78.  
  79. ###############################################################################
  80. A ako boot-ujemo sa kartice sa njegovim filesystem-om
  81.  
  82. setenv bootcmd run mmc_boot
  83. saveenv
  84.  
  85. setenv bootargs "root=/dev/mmcblk0p2 rootwait console=ttyAMA0,115200"
  86. setenv bootcmd "fatload mmc 0:1 0x01000000 zImage; fatload mmc 0:1 0x02000000 bcm2709-rpi-2-b.dtb; bootz 0x01000000 - 0x02000000"
  87. saveenv
  88.  
  89. ##############################################################################
  90.  
  91. Kad budete primenjivali patch komanda
  92. patch -p1 < ~/linux-kernel-labs/modules/data/LinuksKurs.patch
  93.  
  94. Patch se primenjuje na src/linux
  95.  
  96. Pitati Maksu kako da se zImage uprzi na karticu
  97. ##############################################################################
  98. V vezba:
  99.  
  100. Kopirati zadatu konfiguraciju a pozicioniras se u src/linux
  101. cp ~/linux-kernel-labs/modules/data/Linux.config .config
  102.  
  103.  
  104. make xconfig
  105.  
  106. Ukljucimo frame buffer i ostalo
  107.  
  108. Kucamo make u src/linux
  109. make modules_install INSTALL_MOD_PATH=~/linux-kernel-labs/modules/nfsrootVezba/
  110. cd ~/linux-kernel-labs/modules/nfsrootVezba/dev
  111.  
  112. Za pretrazivanje major i minor broja cd /dev
  113. Pa odraditi ll
  114.  
  115. sudo cp /linux-kernel-labs/src/linux/arch/arm/boot/zImage /var/lib/tftpboot
  116.  
  117. 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
  118. 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/
  119.  
  120.  
  121. Kreiramo sa sudo mknod uredjaj
  122. mknod u dev folderu
  123.  
  124. sudo mknod ttyAMA0 c 204 64
  125. sudo mknod tty0 c 4 0
  126. sudo mknod tty1 c 4 1
  127. sudo mknod tty2 c 4 2
  128. sudo mknod tty3 c 4 3
  129. sudo mknod tty4 c 4 4
  130. sudo mknod console c 5 1
  131. sudo mknod null c 1 3
  132.  
  133. U dev kreiramo fb0
  134. sudo mknod fb0 c 29 0
  135.  
  136. ###############################################################################
  137. VI vezba:
  138.  
  139. Raspaujemo tar -xjf busybox-1.21.1.tar.bz2
  140. Kopiramo konfiguracju za busy-box
  141.  
  142. Pozicionirati se u src/linux
  143. sudo cp ~/linux-kernel-labs/modules/data/tinyLinux.config .config
  144.  
  145. Nakon toga iskoristiti istu konfiguraciju u linux-kernel-labs/src/busybox-1.21.1/
  146. sudo cp ~/linux-kernel-labs/modules/data/tinyBusybox.config .config
  147.  
  148. Kad smo prekopirali config pokrecemo sa make menuconfig podesavanja, i u njima u build-options selektujemo static build.
  149. Posle pokrecemo make install a rfs ce biti u _install
  150.  
  151. A u dev kreiraj console i ttyAMA0
  152. -------------------------
  153. sudo mknod console c 5 1
  154. sudo mknod ttyAMA0 c 204 64
  155. -------------------------
  156.  
  157. U ~/linux-kernel-labs/src/busybox-1.21.1/_install/ pravimo etc/init.d proc sys
  158.  
  159.  
  160. cd ~/linux-kernel-labs/src/busybox-1.21.1/_install/
  161.  
  162. mkdir proc
  163. mkdir sys
  164. mkdir -p etc/init.d
  165.  
  166. Da napravis rcS file
  167. Odradi gedit rcS
  168.  
  169.  
  170. Kreiramo u etc/init.d koji je u _install rcS i u njemu pisemo
  171. --------------------------
  172. #!/bin/sh
  173.  
  174. mount -t proc proc /proc
  175. mount -t sysfs sys /sys
  176. -------------------------
  177.  
  178. A u etc kreirati inittab i pisemo
  179.  
  180. -------------------------
  181. ::sysinit:/etc/init.d/rcS
  182. ttyAMA0::askfirst:/bin/sh
  183. -------------------------
  184.  
  185.  
  186.  
  187.  
  188. Kopiramo ~/linux-kernel-labs/modules/data/www u ~/linux-kernel-labs/src/busybox-1.21.1/_install
  189. Restratovati nfs(sudo /etc/init.d/nfs-kernel-server restart)
  190. Uraditi u U-boot reboot uredjaja
  191. I kad se otvori konzola ukucati /usr/sbin/httpd -h /www/ &
  192. Zatim otvoriti web browser(Firefox Mozzila ili Google Chrome[ver-4.6.92])
  193. Ukucati u pretrazivacu "http://adresu pi-ja"
  194. -------------------------
  195. Pozicionirati se u busybox-1.21.1/_install
  196. Prvo kreiramo gedit hello_world.c
  197. Zatim odradimo arm-linux-gnueabihf-gcc hello_world.c -o hello
  198. Pozovemo arm-linux-gnueabihf-readelf -a hello > hw.txtt
  199. Zatim pravimo u busybox-1.21.1 direkktorijum lib
  200. 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
  201. Za kopiranje se pozicionirati u cd /usr/arm-linux-gnueabihf/lib/
  202. Kopirati te biblioteke
  203. sudo cp ld-linux-armhf.so.3 /home/mika/linux-kernel-labs/src/busybox-1.21.1/_install/lib/
  204. sudo cp libc.so.6 /home/mika/linux-kernel-labs/src/busybox-1.21.1/_install/lib/
  205. Vracamo se u busybox-1.21.1
  206. Odradimo make menuconfig
  207. Otici na Busybox Setting-> Busybox Options-> pa deaktivirati static build.
  208. Zatim odraditi make install
  209. Pozicionirati se u cd /usr/arm-linux-gnueabihf/lib/
  210. Kopirati biblioteku
  211. sudo cp libm.so.6 /home/mika/linux-kernel-labs/src/busybox-1.21.1/_install/lib/
  212. --------------------------
  213.  
  214. U /home/mika/linux-kernel-labs/src/busybox-1.21.1/_install/ preimenovati linuxrc u init
  215. mv linuxrc init
  216.  
  217. Pa zatim se pozicioniras u /home/mika/linux-kernel-labs/src/linux pa pokrenes
  218. make xconfig
  219. Nadjemo sa CTRL+f initramfs i u text-box polje unesemo /home/mika/linux-kernel-labs/src/busybox-1.21.1/_install/
  220.  
  221. Sada se pozicioniramo u src/linux
  222. Ponovo prevedemo kernel i kopiramo zImage
  223. make
  224. cp ~/linux-kernel-labs/src/linux/arch/arm/boot/zImage /var/lib/tptpboot
  225.  
  226. Pokrenemo uboot i izmenimo bootargs sa rw console=ttyAMA0,115200
  227.  
  228. ###############################################################################
  229. VII vezba:
  230.  
  231. U linux/src pokrenemo make bcm2709_defconfig
  232. Makeujemo kernel
  233.  
  234. Bootargs smo promenili da bude nfs root koji vec dat
  235. 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
  236. Proveriti /etc/exports da li je dobar nfsroot
  237. Restartovati server
  238.  
  239. Pozicioniramo se u nfsroot/root/hello i iz prezentacije P6.2 str6 iskucali funkcije za init i exit za ispis pocetnih i krajnjih poruka
  240. Kad smo preveli modul ali ga prevodimo u na nasem Linuxu
  241.  
  242. Kad dobijemo konzolu pozicioniramo se u hello,u njemu pozovemo insmod hello_version.ko izlistavamo sa lsmod da vidimo dal je ucitan
  243. Kada ga uklanjamo uklanjamo ga sa rmmod hello_version
  244.  
  245. Za parametre koristimo insmod hello_version.ko who=Beli pri insmodovanju
  246.  
  247. Implementirali sve u hello_version.c
  248. *********************************************************************************************************
  249. #include <linux/init.h>
  250. #include <linux/module.h>
  251. #include <linux/i2c.h>
  252. #include <linux/kernel.h> //za KERN_INFO
  253. #include <linux/moduleparam.h> //za argumente modula
  254. #include <linux/utsname.h> //za dobavljanje verzije
  255. #include <linux/string.h> //za strlen u read funkciji
  256. #include <linux/fcntl.h> //za funkcije koje komuniciraju sa user space
  257. #include <linux/proc_fs.h>
  258. #include <asm/uaccess.h>
  259. #include <linux/slab.h>
  260. #include <linux/fs.h>
  261. #include <linux/ctype.h>
  262. #include <linux/debugfs.h>
  263. #include <linux/printk.h>
  264. #include <linux/device.h>
  265.  
  266. /* Add your code here */
  267. static void __exit hello_exit(void);
  268. static int __init hello_init(void);
  269. static ssize_t hello_read(struct file *fi, char *buff, size_t len, loff_t *f_pos);
  270. static ssize_t hello_write(struct file *fi, char *buff, size_t len, loff_t *f_pos);
  271. static int hello_ioctl(struct file *fi, int op);
  272.  
  273. static char* who = "";
  274. static char* buffer;
  275. static u32 major;
  276. static unsigned int brojacU = 0;
  277. static unsigned int brojacP = 0;
  278. static unsigned int brojacD = 0;
  279. static int opt = -1;
  280.  
  281. static struct dentry *dir = 0;
  282.  
  283.  
  284. static struct file_operations hello_fops =
  285. {
  286. .read = hello_read,
  287. .write = hello_write,
  288. .unlocked_ioctl = hello_ioctl
  289. };
  290.  
  291. static int __init hello_init(void)
  292. {
  293. pr_alert("Hello %s. You are currently using Linux %s", who, utsname()->release);
  294.  
  295. int res;
  296. res = register_chrdev(0,"hello",&hello_fops);
  297. major = res;
  298.  
  299. if(res<0)
  300. {
  301. printk("Ne mogu da nadjem major broj");
  302. return res;
  303. }
  304.  
  305. buffer = kmalloc(100, GFP_KERNEL);
  306.  
  307. if (!buffer)
  308. {
  309. goto fail;
  310. }
  311.  
  312. memset(buffer, 0, 100);
  313. printk(KERN_INFO "Major broj: %d",major);
  314.  
  315. return 0;
  316. fail:
  317. hello_exit();
  318. }
  319.  
  320. static ssize_t hello_read(struct file *fi, char *buff, size_t len, loff_t *f_pos)
  321. {
  322. int data_size=0;
  323. if(*f_pos == 0)
  324. {
  325. data_size = strlen(buffer);
  326. brojacP += data_size;
  327.  
  328. if(copy_to_user(buff,buffer,data_size) != 0)
  329. {
  330. return -1;
  331. }
  332. else
  333. {
  334. (*f_pos) += data_size;
  335. return data_size;
  336. }
  337. }
  338. else
  339. {
  340. return 0;
  341. }
  342. }
  343.  
  344.  
  345. static ssize_t hello_write(struct file *fi, char *buff, size_t len, loff_t *f_pos)
  346. {
  347. memset(buffer, 0, 100);
  348. if(copy_from_user(buffer,buff,len)!=0)
  349. {
  350. return -1;
  351. }
  352. else
  353. {
  354. brojacD = len;
  355. pr_debug("Dostupno za citanje %d bajta",brojacD);
  356. brojacU += len;
  357. pr_debug("Broj upisanih bajta %d",brojacU);
  358. return len;
  359. }
  360. }
  361.  
  362. static int hello_ioctl(struct file *fi, int op)
  363. {
  364. int i = 0;
  365. if(op == 0)
  366. {
  367.  
  368. while(buffer[i]){
  369. buffer[i] = toupper(buffer[i]);
  370. i++;
  371. }
  372. }
  373. else if(op == 1)
  374. {
  375. while(buffer[i]){
  376. buffer[i] = tolower(buffer[i]);
  377. i++;
  378. }
  379. }
  380. }
  381.  
  382. static void __exit hello_exit(void)
  383. {
  384. if(buffer)
  385. {
  386. kfree(buffer);
  387. }
  388. unregister_chrdev(major,"hello");
  389.  
  390. pr_alert("Goodbye %s \n",who);
  391. }
  392.  
  393.  
  394. module_param(who, charp, 0);
  395. module_param(opt, int, 0);
  396.  
  397. module_init(hello_init);
  398. module_exit(hello_exit);
  399.  
  400.  
  401.  
  402. MODULE_LICENSE("GPL");
  403.  
  404. *********************************************************************************************************
  405. Napravili smo u /dev uredjaj sa major brojem koji nam je kernel dao
  406.  
  407. mknod hellodev c 244 0
  408.  
  409. Testiranje write operacije
  410. echo "TeStni StRing" >> hellodev
  411. Testiranje read operacije
  412. cat /dev/hellodev
  413.  
  414. Za ioctl prevedemo ioctl.c pomocu komande
  415.  
  416. arm-linux-gnueabihf-gcc ioctl.c -o ioctle -static
  417.  
  418. Zatim ga pokrecemo u u-bootu sa ./ioctle /dev/hellodev 1
  419.  
  420. Iscitamo sa cat /dev/hellodev
  421.  
  422. Pozicioniramo se u src/linux/drivers/misc
  423. Prekopiramo hello_version.c i hello_version.o
  424. Izmeniti Makefile i dodati obj-$(CONFIG_HELLO_VERSION) += hello_version.o
  425. Izmeniti u Kconfig
  426. config HELLO_VERSION
  427. bool "Opis"
  428. default y
  429. Vratiti se u src/linux
  430. Pokrenuti make xconfig
  431. Naci pomocu HELLO_VERSION da se cekira opcija za hello_version modul
  432. Pre make-a uraditi
  433.  
  434.  
  435. sudo chown -R mika.mika ~/linux-kernel-labs/modules/nfsroot/lib
  436.  
  437. make modules_install INSTALL_MOD_PATH=~/linux-kernel-labs/modules/nfsroot
  438.  
  439. sudo chown -R root.root ~/linux-kernel-labs/modules/nfsroot/lib
  440.  
  441. Prevesti kernel sa make
  442.  
  443. Posle make file kopirati zImage iz src/linux/arch/arm/boot u /var/lib/tftpboot
  444.  
  445. I pokrenuti kernel
  446.  
  447. ################################################################################################################
  448. XI vezba:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement