Upgrade to Pro — share decks privately, control downloads, hide ads and more …

カーネル/VM式ARMマイコン入門

 カーネル/VM式ARMマイコン入門

Linuxが動くARMマイコンボードBeagleBoneBlackにGentooを入れて電子工作する手順を解説します

Fadis

May 09, 2015
Tweet

More Decks by Fadis

Other Decks in Programming

Transcript

  1. ϒʔτͷྲྀΕ BNY 30. F..$ NJDSP4% .-0 VCPPUJNH [*NBHF .-0 VCPPUJNH

    ͕ͬͪ͜༏ઌ 6#PPU4-1 6#PPU (36#Ͱ͍͏TUBHF (36#Ͱ͍͏TUBHF
  2. 6#PPUΛϏϧυ͠Α͏ # crossdev -S armv7a-hardfloat-linux-gnueabi ΫϩείϯύΠϥΛΠϯετʔϧ # wget ftp://ftp.denx.de/pub/u-boot/u-boot-2013.04.tar.bz2 #

    tar xjpf u-boot-2013.04.tar.bz2 && cd u-boot-2013.04 # git clone https://github.com/beagleboard/meta- beagleboard.git # for i in meta-beagleboard/common-bsp/recipes-bsp/u-boot/ u-boot-denx/00*; do patch -p1 < $i; done 6#PPUͷιʔεΛμ΢ϯϩʔυͯ͠ #FBHMF#PBSE༻ͷύονΛ౰ͯΔ # make ARCH=arm CROSS_COMPILE=armv7a-hardfloat-linux- gnueabi- am335x_evm_config # make ARCH=arm CROSS_COMPILE=armv7a-hardfloat-linux- gnueabi- 6#PPUΛϏϧυ
  3. 6#PPUΛΠϯετʔϧ͠Α͏ 4%Χʔυ Ϧʔμʔ EFWTEC # wget http://dev.gentoo.org/~armin76/arm/beaglebone/ mkcard.sh # bash

    mkcard.sh /dev/sdb 30.͔Β࣮ߦ͞ΕΔϒʔτϩʔμʔ͕ಡΊΔΑ͏ʹ ύʔςΟγϣϯΛ੾Δ ໘౗ͳͷͰ༻ҙ͞ΕͨεΫϦϓτʹؙ౤͛
  4. 64#γϦΞϧίϯόʔλ 7༻ 6#PPUΛΠϯετʔϧ͠Α͏ /dev/sdb1 * 63 144584 72261 c W95

    FAT32 (LBA) /dev/sdb2 144585 15647309 7751362+ 83 Linux # mkdir /mnt/p1 && mount /dev/sdb1 /mnt/p1 # cp MLO u-boot.img /mnt/p1 γϦΞϧϙʔτ
  5. 6#PPUΛΠϯετʔϧ͠Α͏ musb-hdrc: MHDRC RTL version 2.0 musb-hdrc: setup fifo_mode 4

    musb-hdrc: 28/31 max ep, 16384/16384 memory USB Peripheral mode controller at 47401000 using PIO, IRQ 0 musb-hdrc: ConfigData=0xde (UTMI-8, dyn FIFOs, HB-ISO Rx, HB-ISO Tx, SoftConn) musb-hdrc: MHDRC RTL version 2.0 musb-hdrc: setup fifo_mode 4 musb-hdrc: 28/31 max ep, 16384/16384 memory USB Host mode controller at 47401800 using PIO, IRQ 0 Net: <ethaddr> not set. Validating first E- fuse MAC cpsw, usb_ether U-Boot# 6#PPUίϯιʔϧ
  6. ΧʔωϧΛϏϧυ͠Α͏ # git clone https://github.com/beagleboard/kernel.git # cd kernel # git

    checkout origin/3.8 -b 3.8 # ./patch.sh # cd kernel ΧʔωϧΛर͖ͬͯͯύονΛ౰ͯΔ # wget "http://arago-project.org/git/projects/?p=am33x- cm3.git;a=blob_plain;f=bin/am335x-pm-firmware.bin;hb=HEAD" -O firmware/am335x-pm-firmware.bin ిݯ؅ཧ༻ϓϩηοαʹ৯΂ͤ͞ΔϑΝʔϜ΢ΣΞ # cp ../configs/beaglebone .config # make ARCH=arm CROSS_COMPILE=armv7a-hardfloat-linux- gnueabi- menuconfig #FBHMF#POF༻ͷઃఆ͔ΒNFOVDPOpH
  7. ..$ͱ4%Χʔυͷؔ܎ %"5 %"5 %"5 (/% $-, 7%% (/% $.% %"5

    ͭͷσʔλઢͰ௨৴͢Δ ˠ)JHI4QFFE..$
  8. ΧʔωϧΛϏϧυ͠Α͏ # make ARCH=arm CROSS_COMPILE=armv7a-hardfloat-linux- gnueabi- ͓΋ΉΖʹϏϧυ # mkfs.f2fs -L

    gentoo /dev/sdb2 # mkdir -p /mnt/p2 && mount /dev/sdb2 /mnt/p2 # cd /mnt/p2 # make ARCH=arm CROSS_COMPILE=armv7a-hardfloat-linux- gnueabi- INSTALL_MOD_PATH=/mnt/p2 modules_install firmware_install # cp arch/arm/boot/zImage /mnt/p1/ # mkdir -p /mnt/p1/dtbs # cp arch/arm/boot/dts/am335x-boneblack.dtb /mnt/p1/dtbs 4%ΧʔυͷͭΊͷύʔςΟγϣϯΛ ޷͖ͳϑΝΠϧγεςϜͰϑΥʔϚοτͯ͠ ΧʔωϧΛΠϯετʔϧ
  9. (FOUPPΛΠϯετʔϧ͠Α͏ # cd /mnt/p2 # wget http://ftp.iij.ad.jp/pub/linux/gentoo/releases/arm/ autobuilds/current-stage3-armv7a_hardfp/stage3- armv7a_hardfp-20131006.tar.bz2 #

    tar xjpf stage3-armv7a_hardfp-20131006.tar.bz2 # wget http://ftp.iij.ad.jp/pub/linux/gentoo/snapshots/ portage-latest.tar.xz # tar xJpf portage-latest.tar.xz -C /mnt/p2/usr TUBHFͱQPSUBHFΛల։ # cat <<EOF >etc/fstab /dev/mmcblk0p1 /boot vfat noauto,noatime! 1 2 /dev/mmcblk0p2 / f2fs! noatime! ! 0 1 EOF GTUBCΛઃఆ
  10. (FOUPPΛΠϯετʔϧ͠Α͏ # openssl passwd -1 Password: Verifying - Password: $1$N3kc0bfR$skOb0RdWIHxOen69/pstu0

    # vim etc/shadow ... root:$1$N3kc0bfR$skOb0RdWIHxOen69/pstu0:10770:0::::: ... SPPUύεϫʔυΛઃఆ # ln -sf /etc/init.d/swclock etc/runlevels/boot # rm etc/runlevels/boot/hwclock # touch sbin/rc ىಈ࣌ͷॲཧ͔Βϋʔυ΢ΣΞΫϩοΫΛ֎ͯ͠ ιϑτ΢ΣΞΫϩοΫΛ௥Ճ͢Δ
  11. (FOUPPΛΠϯετʔϧ͠Α͏ ి஑ͱ͔͍ͭͯͳ͍ 1$ʹ͸ ిݯ͕ڙڅ͞Ε͍ͯͳ͍ؒ #*04ͷઃఆͷҡ࣋ͱ ࣌ܭΛಈ͔͠ଓ͚ΔͨΊͷ ి஑͕͍͍ͭͯΔ   

                               
  12. (FOUPPΛΠϯετʔϧ͠Α͏ # vim etc/inittab ... s1:12345:respawn:/sbin/agetty -L 9600 ttyS1 vt100

    Λ s1:12345:respawn:/sbin/agetty -L 115200 ttyO0 vt100 Ͱஔ͖׵͑Δ ... γϦΞϧ͔ΒϩάΠϯग़དྷΔΑ͏ʹ͢Δ
  13. (FOUPPΛΠϯετʔϧ͠Α͏ kernel_file=zImage initrd_file=uInitrd console=ttyO0,115200n8 mmcroot=/dev/mmcblk0p2 ro mmcrootfstype=f2fs rootwait fixrtc optargs=capemgr.disable_partno=BB-BONELT-HDMIN

    loadkernel=load mmc ${mmcdev}:${mmcpart} 0x80008000 ${kernel_file} loadinitrd=load mmc ${mmcdev}:${mmcpart} 0x81000000 ${initrd_file}; setenv initrd_size ${filesize} loadfdt=load mmc ${mmcdev}:${mmcpart} 0x815f0000 /dtbs/${fdtfile} console=ttyS0,115200n8 root=${mmcroot} rootfstype=${mmcrootfstype} $ {optargs} vram=24M omapfb.mode=hdmi:1024x768MR-16@60 omapdss.def_disp=hdmi omapfb.vram=0:4M,1:4M,2:4M,nolock mmcargs=setenv bootargs console=${console} console=ttyS0,115200n8 root=${mmcroot} rootfstype=${mmcrootfstype} ${optargs} vram=24M omapfb.mode=hdmi:1280x720@60 omapdss.def_disp=hdmi omapfb.vram=0:8M, 1:8M,2:8M,nolock boot_ftd=run loadkernel; run loadfdt uenvcmd=run boot_ftd; run mmcargs; bootz 0x80008000 - 0x815f0000 {initrd_size} 0x815f0000 6#PPUͷઃఆϑΝΠϧV&OWUYUΛॻ͘
  14. (FOUPPΛΠϯετʔϧ͠Α͏ # cp uEnv.txt /mnt/p1/ # umount /mnt/p1 # umount

    /mnt/p2 V&OWUYUΛ[*NBHFͱಉ͡σΟϨΫτϦʹஔ͘ 4%Χʔυ Ϧʔμʔ
  15. (FOUPPΛΠϯετʔϧ͠Α͏ U-Boot SPL 2013.04-dirty (Jun 19 2013 - 09:57:14) musb-hdrc:

    ConfigData=0xde (UTMI-8, dyn FIFOs, HB-ISO Rx, HB-ISO Tx, SoftConn) musb-hdrc: MHDRC RTL version 2.0 musb-hdrc: setup fifo_mode 4 musb-hdrc: 28/31 max ep, 16384/16384 memory USB Peripheral mode controller at 47401000 using PIO, IRQ 0 musb-hdrc: ConfigData=0xde (UTMI-8, dyn FIFOs, HB-ISO Rx, HB-ISO Tx, SoftConn) musb-hdrc: MHDRC RTL version 2.0 musb-hdrc: setup fifo_mode 4 musb-hdrc: 28/31 max ep, 16384/16384 memory USB Host mode controller at 47401800 using PIO, IRQ 0 OMAP SD/MMC: 0 mmc_send_cmd : timeout: No status update reading u-boot.img reading u-boot.img U-Boot 2013.04-dirty (Jun 19 2013 - 09:57:14) I2C: ready DRAM: 512 MiB WARNING: Caches not enabled NAND: No NAND device found!!! 0 MiB
  16. FNFSHFͷ४උ # cat <<EOF >>/etc/conf.d/net config_eth0="dhcp" # cp /etc/init.d/net.lo /etc/init.d/net.eth0

    # rc-update add net.eth0 default # /etc/init.d/net.eth0 start FUIΛୟ͖ى͜͢ # vim /etc/portage/make.conf ... CFLAGS=”-O2 -pipe -march=armv7-a -mfpu=vfpv3-fp16 -mfloat- abi=hard” Λ CFLAGS="-Os -pipe -march=armv7-a -mcpu=cortex-a8 - mfpu=neon -mfloat-abi=hard" ʹม͑Δ ... $16Λ$PSUFY"ʹ '16Λ/&0/ʹ
  17. FNFSHFͷ४උ γεςϜͷશͯͷύοέʔδͷϏϧυʹ GVOTBGFNBUIPQUJNJ[BUJPOT ɹΛ෇͚Δͷ͸ා͍ # cat <<EOF >/etc/portage/env/enable_neon_fp CFLAGS="-O3 -pipe

    -march=armv7-a -mcpu=cortex-a8 - mfpu=neon -mfloat-abi=hard -ftree-vectorize -funsafe-math- optimizations -funroll-loops" CXXFLAGS="${CFLAGS}" EOF # cat <<EOF >/etc/portage/package.env media-libs/faad2 enable_neon_fp media-sound/mpg123 enable_neon_fp media-libs/mesa enable_neon_fp media-libs/libjpeg-turbo enable_neon_fp ... ුಈখ਺఺਺͕ॏཁͦ͏ͳύοέʔδ͚ͩ ෇͚͍ͯͬͯɺϠόͦ͏ͩͬͨΒҾͬࠐΊΔ
  18. "3.ΞʔΩςΫνϟͷछྨ "3.W "3.W "3.W "3.W "3.W "3.W "3. "3. "3.

    5 . 3 " "3. $PSUFY. $PSUFY3 $PSUFY" 55IVNC໋ྩରԠ .ϚΠΫϩίϯτϩʔϥ 5IVNCͷΈରԠ 3ϦΞϧλΠϜϓϩηοα "ΞϓϦέʔγϣϯϓϩηοα શ෦ೖΓ
  19. "3.ΞʔΩςΫνϟͷछྨ "3.W "3.W "3.W "3.W "3.W "3.W "3. "3. "3.

    5 . 3 " "3. $PSUFY. $PSUFY3 $PSUFY" ήʔϜϘʔΠΞυόϯε χϯςϯυʔ%4 ;BVSVT4-γϦʔζ 3BTQCFSSZ1J "SEVJOP%VF ॳ୅J1IPOF #FBHMF#PBSE J1IPOFT 147*5" େମͷεϚʔτϑΥϯ NCFE -1$6 5SJN4MJDF
  20. "3.ΞʔΩςΫνϟͷछྨ "3.W "3.W "3.W "3.W "3.WB "3.WB 5IVNC %41ԋࢉ '16

    7'1W 7'1W 7'1W /&0/ /&0/ 5IVNC 5IVNC&& ҉߸Խ Ծ૝Խࢧԉ #FBHMF#POF 3BTQCFSSZ1J
  21. "3.ΞʔΩςΫνϟͷछྨ "3.WB 0VUPG 0SEFS εʔύʔεΧϥ ϚϧνίΞ 7'1W -1"& Ծ૝Խࢧԉ "

    º º ˓ ˓ º º " º ˓ ˓ ˓ ˓ ˓ " º ˓ º º º º " ˓ ˓ ˓ º º ˓ " ˓ ˓ ˓ ˓ ˓ ˓ " ˓ ˓ ˓ ˓ ˓ ˓
  22. FNFSHFͷ४උ CFLAGS=”-Os -pipe -march=armv7-a -mcpu=cortex-a8 -mfpu=neon -mfloat-abi=hard” #FBHMF#POFͷҝͷ$'-"(4 CFLAGS=”-Os -pipe

    -march=armv7-a -mcpu=cortex-a8 -mfpu=neon -mfloat-abi=hard -ftree-vectorize” "VUPWFDUPSJ[BUJPOΛ࢖͏৔߹
  23. (FOUPPΛΠϯετʔϧ͠Α͏ ਅͬઌʹΠϯετʔϧ͢΂͖෺ EJTUDD # USE=-* emerge distcc # cat <<EOF

    >>/etc/portage/make.conf MAKEOPTS="-j4" FEATURES="distcc" EOF # distcc-config --set-hosts "<ϏϧυΛݞ୅ΘΓ͢Δϗετ>" Πϯετʔϧͯ͠ ϏϧυΛ೚ͤΔϗετΛઃఆ
  24. (FOUPPΛΠϯετʔϧ͠Α͏ # vim /etc/conf.d/distccd ... DISTCCD_OPTS="${DISTCCD_OPTS} --listen <BeagleBoneBlackͷ IPΞυϨε>" ...

    #FBHMF#POF͔ΒͷཁٻΛड͚ೖΕΔΑ͏ʹઃఆ # /etc/init.d/distccd start # /etc/init.d/distccd start ྆ํͰEJTUDDEΛىಈ
  25. 9Λಈ͔ͦ͏ [ 10301.728] (II) Module omapfb: vendor="X.Org Foundation" [ 10301.728]

    ! compiled for 1.13.4, module version = 0.1.1 [ 10301.728] ! ABI class: X.Org Video Driver, version 13.1 [ 10301.728] (II) omapfb: Driver for OMAP framebuffer (omapfb) and external LCD controllers: ! omap1/2/3, S1D13745, HWA742 [ 10301.728] (--) using VT number 3 [ 10301.741] (WW) Falling back to old probe method for OMAPFB [ 10301.741] (WW) OMAPFBProbe: Not an omapfb device: [ 10301.741] (EE) No devices detected. [ 10301.741] Fatal server error: [ 10301.741] no screens found YGWJEFPPNBQGC ࡞ઓ
  26. 9Λಈ͔ͦ͏ # modprobe omapdss modprobe: ERROR: could not insert 'omapdss':

    No such device YGWJEFPPNBQ ࡞ઓ MJOVYͰΧʔωϧυϥΠόΛϩʔυ͠Α͏ͱ͢Δͱ Կނ͔σόΠε͕ແ͍ͱݴΘΕΔ MJOVYͰ͸ಈ͍͍ͯͨΒ͍͠
  27. -&% # ls /sys/class/leds/beaglebone\:green\:usr3/ brightness max_brightness subsystem uevent device power

    trigger CSJHIUOFTT ໌Δ͞Λઃఆ͢Δ -&%͕໌Δ͞ௐઅͷՄೳͳํ๏Ͱ઀ଓ͞Ε͍ͯΔ৔߹ ͔ΒNBY@CJSJHIUOFTT·Ͱͷ਺஋Λॻ͖ࠐΉͱ -&%ͷ໌Δ͕͞มԽ͢Δ ࢒೦ͳ͕Β(1*0઀ଓͷ-&%͸໌Δ͞Λௐઅग़དྷͳ͍
  28. -&% # ls /sys/class/leds/beaglebone\:green\:usr3/ brightness max_brightness subsystem uevent device power

    trigger USJHHFS -&%ΛޫΒͤΔ৚݅Λઃఆ͢Δ ಡΈग़͢ͱγεςϜ͕αϙʔτ͢Δ -&%ΛޫΒͤΔ৚͕݅ྻڍ͞ΕΔ # cat /sys/class/leds/beaglebone\:green\:usr3/trigger none nand-disk mmc0 [mmc1] timer oneshot heartbeat backlight gpio cpu0 default-on transient ͜ͷ-&%͸NND F..$ ΁ͷΞΫηε࣌ʹޫΔ
  29. -&% # ls /sys/class/leds/beaglebone\:green\:usr3/ brightness max_brightness subsystem uevent device power

    trigger USJHHFS # echo timer >/sys/class/leds/beaglebone\:green\:usr3/trigger -νΧΛ΍Γ͍ͨͷͰ৚݅ΛUJNFSʹ੾Γସ͑ # ls /sys/class/leds/beaglebone\:green\:usr3/ brightness delay_on max_brightness subsystem uevent delay_off device power trigger EFMBZ@POͱEFMBZ@P⒎͕ݱΕΔ
  30. -&% # ls /sys/class/leds/beaglebone\:green\:usr3/ brightness delay_on max_brightness subsystem uevent delay_off

    device power trigger EFMBZ@POEFMBZ@P⒎ 0/ʹͳΔ࣌ؒɺ0''ʹͳΔ࣌ؒ ͦΕͧΕϛϦඵͰઃఆ͢Δ # echo 10 >/sys/class/leds/beaglebone\:green\:usr3/delay_on # echo 490 >/sys/class/leds/beaglebone\:green\:usr3/delay_off
  31. %FWJDF5SFF # find /usr/src/linux-3.8.13-gentoo/arch/arm/mach-* /usr/src/linux-3.8.13-gentoo/arch/arm/mach-at91 /usr/src/linux-3.8.13-gentoo/arch/arm/mach-at91/stamp9g20.h /usr/src/linux-3.8.13-gentoo/arch/arm/mach-at91/soc.h /usr/src/linux-3.8.13-gentoo/arch/arm/mach-at91/setup.c /usr/src/linux-3.8.13-gentoo/arch/arm/mach-at91/sam9_smc.h /usr/src/linux-3.8.13-gentoo/arch/arm/mach-at91/sam9_smc.c

    /usr/src/linux-3.8.13-gentoo/arch/arm/mach-at91/pm_slowclock.S /usr/src/linux-3.8.13-gentoo/arch/arm/mach-at91/pm.h /usr/src/linux-3.8.13-gentoo/arch/arm/mach-at91/pm.c /usr/src/linux-3.8.13-gentoo/arch/arm/mach-at91/leds.c ... ಛఆͷϋʔυ΢ΣΞͷ৘ใΛฒ΂ͨίʔυͷ਺ʑ ͸ࣄલʹߏ੒Λ஌͍ͬͯͳ͚Ε͹ͳΒͳ͍
  32. %FWJDF5SFF BNYCPOFDPNNPOEUTJ  HQJPMFET\ DPNQBUJCMFHQJPMFET QJODUSMOBNFTEFGBVMU QJODUSMVTFSMFE@QJOT MFE\ MBCFMCFBHMFCPOFHSFFOVTS HQJPTHQJP

    MJOVY EFGBVMUUSJHHFSIFBSUCFBU EFGBVMUTUBUFP⒎ ^  HQJPͷ൪໨ʹ HQJPMFETυϥΠό͕ ѻ͏͜ͱ͕Ͱ͖Δ -&%͕ܨ͕͍ͬͯͯ ໊લ͸ CFBHMFCPOFHSFFOVTS σϑΥϧτͷ༻్͸ IFBSUCFBU
  33. $BQF.BOBHFS # ls /lib/firmware/*.dtbo /lib/firmware/BB-ADC-00A0.dtbo /lib/firmware/BB-BONE-AUDI-01-00A0.dtbo /lib/firmware/BB-BONE-BACON-00A0.dtbo /lib/firmware/BB-BONE-BACONE-00A0.dtbo ... ৭Μͳ֦ுϘʔυ༻ͷ%FWJDF5SFFͷϓϥάΠϯ

    # cat /sys/devices/bone_capemgr.*/slots 0: 54:PF--- 1: 55:PF--- 2: 56:PF--- 3: 57:PF--- 4: ff:P-O-L Bone-LT-eMMC-2G,00A0,Texas Instrument,BB- BONE-EMMC-2G 5: ff:P-O-L Bone-Black-HDMI,00A0,Texas Instrument,BB- BONELT-HDMI 6: ff:P-O-- Bone-Black-HDMIN,00A0,Texas Instrument,BB- BONELT-HDMIN ݱࡏϩʔυ͞Ε͍ͯΔ%FWJDF5SFFͷϓϥάΠϯ
  34. $BQF.BOBHFS # echo cape-bone-iio >/sys/devices/bone_capemgr.10/slots "%$Λ**0σόΠεͱͯ͠࢖͏ϓϥάΠϯΛϩʔυ # cat /sys/devices/bone_capemgr.*/slots 0:

    54:PF--- 1: 55:PF--- 2: 56:PF--- 3: 57:PF--- 4: ff:P-O-L Bone-LT-eMMC-2G,00A0,Texas Instrument,BB- BONE-EMMC-2G 5: ff:P-O-L Bone-Black-HDMI,00A0,Texas Instrument,BB- BONELT-HDMI 6: ff:P-O-- Bone-Black-HDMIN,00A0,Texas Instrument,BB- BONELT-HDMIN 8: ff:P-O-L Override Board Name,00A0,Override Manuf,cape- bone-iio 6: ff:P-O-- Bone-Black-HDMIN,00A0,Texas Instrument,BB- BONELT-HDMIN ݱࡏϩʔυ͞Ε͍ͯΔ%FWJDF5SFFͷϓϥάΠϯ
  35. -&% # emerge libftdi # cd /usr/src # git clone

    https://github.com/beagleboard/kernel.git # cd kernel # git checkout origin/3.8 -b 3.8 # ./patch.sh # cd kernel # make scripts/dtc # cp scripts/dtc /usr/sbin %FWJDF5SFFίϯύΠϥΛΠϯετʔϧ # cd /usr/src # git clone https://github.com/nomel/beaglebone.git # cd beaglebone/led-header/generated/ # ./compile.sh # ./install.sh -&%ͷ%54Λطʹ࡞͍ͬͯΔਓ͕͍Δ
  36. -&% # echo led-P9.12 >/sys/devices/bone_capemgr.*/slots ࠨଆͷ֦ுϔομͷ൪ϐϯΛ-&%ͱ͢Δ # ls /sys/class/leds/ beaglebone:green:usr0

    beaglebone:green:usr2 leds:P9.12 beaglebone:green:usr1 beaglebone:green:usr3 ΍͍ͤͷ-&%͕ͱͼ͖ͩͯͨ͠ # cd kernel # make scripts/dtc # cp scripts/dtc /usr/sbin %FWJDF5SFFίϯύΠϥΛΠϯετʔϧ # cd /usr/src # git clone https://github.com/nomel/beaglebone.git # cd beaglebone/led-header/generated/ # ./compile.sh # ./install.sh -&%ͷ%FWJDF5SFFΛطʹ࡞͍ͬͯΔਓ͕͍Δ
  37. # cd /usr/src/beaglebone/gpio-header/generated/ # ./compile.sh # ./install.sh (1*0ͷ%FWJDF5SFFϓϥάΠϯΛΠϯετʔϧ # echo

    gpio-P8.8 >/sys/devices/bone_capemgr.*/slots ӈଆͷ֦ுϔομͷ൪ϐϯΛ(1*0ͱ͢Δ # echo 67 >/sys/class/gpio/export (1*0Λ(1*0υϥΠόͷ഑Լʹ # echo rxEnable_pullUp >/sys/devices/ocp.*/gpio- P8.8_gpio67.*/state ϐϯͷঢ়ଶΛೖྗ͔ͭϓϧΞοϓʹ͢Δ ӈଆ൪ϐϯ͸4P$ͷ(1*0ʹܨ͕͍ͬͯΔ (1*0
  38. # cat /sys/class/gpio/gpio67/value 0 # cat /sys/class/gpio/gpio67/value 1 (1*0 #

    echo 67 >/sys/class/gpio/export (1*0Λ(1*0υϥΠόͷ഑Լʹ ӈଆ൪ϐϯ͸4P$ͷ(1*0ʹܨ͕͍ͬͯΔ
  39. --- gpio-P8.8-00A0.dts! 2013-10-15 22:29:14.871094049 +0900 +++ key-P8.8-00A0.dts! 2013-10-17 16:44:45.044921918 +0900

    @@ -8,7 +8,7 @@ ! compatible = "ti,beaglebone", "ti,beaglebone-black"; ! /* identification */ -! part-number = "gpio-P8.8"; +! part-number = "key-P8.8"; ! /* version = "00A0"; */ ! /* state the resources this cape uses */ @@ -106,6 +106,15 @@ ! ! ! ! pinctrl-4 = <&gpio_P8_8_rxDisable_pullDown>; ! ! ! ! pinctrl-5 = <&gpio_P8_8_rxEnable_pullDown>; ! ! ! }; +! ! ! gpio-key { +! ! ! ! compatible = "gpio-keys"; +! ! ! ! button@67 { +! ! ! ! ! linux,code = <67>; +! ! ! ! ! label = "toggle0"; +! ! ! ! ! gpios = <&gpio3 3 0>; +! ! ! ! ! gpio-key,wakeup; +! ! ! ! }; +! ! ! }; ! ! }; ! }; Ωʔίʔυ ద౰ ໊લUPHHMF ద౰ (1*0(1*0ͷ൪໨
  40. # dtc -@ -O dtb -o key-P8.8-00A0.dtbo key-P8.8-00A0.dts # cp

    key-P8.8-00A0.dtb0 /lib/firmwares HQJPLFZͷ%FWJDF5SFFΛΠϯετʔϧ # echo key-P8.8 >/sys/devices/bone_capemgr.*/slots ͦͯ͠ϩʔυ # ls /dev/input/by-path/ platform-44e0b000.i2c-event platform-gpio-key.17-event platform-gpio-keys.9-event ৽͍͠ΠϕϯτσόΠε͕ݱΕͨ # echo rxEnable_pullUp >/sys/devices/ocp.*/gpio- P8.8_gpio67.*/state ϐϯͷঢ়ଶΛೖྗ͔ͭϓϧΞοϓʹ͢Δ FWEFW
  41. # ls /dev/input/by-path/ platform-44e0b000.i2c-event platform-gpio-key.17-event platform-gpio-keys.9-event ৽͍͠ΠϕϯτσόΠε͕ݱΕͨ FWEFW # cat

    /dev/input/event2 |hexdump 0000000 9c1c 525f d80a 000d 0001 0043 0000 0000 0000010 9c1c 525f d80a 000d 0000 0000 0000 0000
  42. # ls /dev/input/by-path/ platform-44e0b000.i2c-event platform-gpio-key.17-event platform-gpio-keys.9-event ৽͍͠ΠϕϯτσόΠε͕ݱΕͨ FWEFW # cat

    /dev/input/event2 |hexdump 0000000 9c1c 525f d80a 000d 0001 0043 0000 0000 0000010 9c1c 525f d80a 000d 0000 0000 0000 0000 0000020 9c1f 525f e8ad 0008 0001 0043 0001 0000 0000030 9c1f 525f e8ad 0008 0000 0000 0000 0000
  43. struct input_event { ! struct timeval time; ! __u16 type;

    ! __u16 code; ! __s32 value; }; UJNF UZQF DPEF WBMVF Πϕϯτ͕ൃੜͨ࣌͠ࠁ Πϕϯτͷछྨ Ωʔೖྗͱ͔Ϛ΢εͷҠಈͱ͔ ԿʹมԽ͕͔͋ͬͨ Ϛ΢εͷӈϘλϯͱ͔ Ͳ͏͍͏ঢ়ଶʹͳ͔ͬͨ FWEFW MJOVYJOQVUI
  44. #FBHMF#POFͷ*$ *$4$-   *$4%" *$4$-   *$4%" *$4$-

      *$4%"   *$4$-   *$4%" ֦ͨͩ͠ுϔομʹग़ͯΔͷ͸ͭ ".Yʹ΋*$ϗετ͕ͭࡌ͍ͬͯΔ
  45. ϦΞϧλΠϜΫϩοΫ *$4$-   *$4%" *$4$-   *$4%" *$4$-

      *$4%"   *$4$-   *$4%" 4%"   4$-   (/%   7%%   #FBHMF#POFͷ*$ʹ35$Λܨ͙
  46. ϦΞϧλΠϜΫϩοΫ #include <iostream> #include <string> #include <cstdlib> #include <cstdint> #include

    <boost/date_time/gregorian/gregorian.hpp> #include <boost/date_time/posix_time/posix_time.hpp> #include <boost/spirit/include/karma.hpp> #include <boost/range/irange.hpp> #include <boost/range/algorithm.hpp> #include <boost/program_options.hpp> #include <sys/ioctl.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> #include <linux/i2c-dev.h> uint8_t unpack( uint8_t value ) { return ( ( value >> 4 ) & 0xF ) * 10 + ( value & 0xF ); } uint8_t pack( uint8_t value ) { return ( ( value / 10 ) << 4 ) | ( value % 10 ); } struct communication_failed {}; boost::posix_time::ptime get_time( int fd ) { std::vector< uint8_t > dump; dump.reserve( 8u ); boost::transform(boost::irange( 0u, 8u ), std::back_inserter( dump ), [&]( uint8_t addr ) { if( write( fd, &addr, 1 ) < 0 ) throw communication_failed(); uint8_t data;if( read( fd, &data, 1 ) < 0 ) throw communication_failed(); return data; } ); boost::posix_time::ptime now( boost::gregorian::date(2000+unpack( dump[ 7 ] ), unpack( dump[ 6 ] & 0x1F ), unpack( dump[ 5 ] & 0x3F )), boost::posix_time::time_duration(unpack( dump[ 3 ] & 0x3F ), unpack( dump[ 2 ] & 0x7F ), unpack( dump[ 1 ] & 0x7F )) ); return now; } void set_time( int fd, const boost::posix_time::ptime &time ) { std::vector< uint8_t > dump{{0,0, pack( time.time_of_day().seconds() ), pack( time.time_of_day().minutes() ), pack( time.time_of_day().hours() ), pack( time.date().week_number() ), pack( time.date().day() ), pack( time.date().month() ), pack( time.date().year() - 2000 ) }}; if( write( fd, dump.data(), dump.size() ) < 0 ) throw communication_failed(); } int main( int argc, char* argv[] ) {
  47. ϦΞϧλΠϜΫϩοΫ boost::posix_time::ptime now( boost::gregorian::date(2000+unpack( dump[ 7 ] ), unpack( dump[

    6 ] & 0x1F ), unpack( dump[ 5 ] & 0x3F )), boost::posix_time::time_duration(unpack( dump[ 3 ] & 0x3F ), unpack( dump[ 2 ] & 0x7F ), unpack( dump[ 1 ] & 0x7F )) ); return now; } void set_time( int fd, const boost::posix_time::ptime &time ) { std::vector< uint8_t > dump{{0,0, pack( time.time_of_day().seconds() ), pack( time.time_of_day().minutes() ), pack( time.time_of_day().hours() ), pack( time.date().week_number() ), pack( time.date().day() ), pack( time.date().month() ), pack( time.date().year() - 2000 ) }}; if( write( fd, dump.data(), dump.size() ) < 0 ) throw communication_failed(); } int main( int argc, char* argv[] ) { boost::program_options::options_description options("Options"); options.add_options()( "help,h", "show this message" ) ( "device,d", boost::program_options::value< std::string >(), "I2C device" ) ( "set,s", boost::program_options::value< std::string >(), "set current time" ) ( "get,g", "get current time" ); boost::program_options::variables_map variables; boost::program_options::store( boost::program_options::parse_command_line( argc, argv, options ), variables ); boost::program_options::notify( variables ); if( variables.count( "help" ) || !( variables.count( "device" ) ) || !( variables.count( "set" ) || variables.count( "get" ) ) || ( variables.count( "set" ) && variables.count( "get" ) ) ) std::cout << options << std::endl; else { const int fd = open( variables[ "device" ].as< std::string >().c_str(), O_RDWR ); if( fd < 0 ) exit( 1 ); ioctl( fd, I2C_SLAVE, 0x68 ); try { if( variables.count( "set" ) ) set_time( fd, boost::posix_time::time_from_string( variables[ "set" ].as< std::string >() ) ); else if( variables.count( "get" ) ) std::cout << get_time( fd ) << std::endl; } catch( const communication_failed& ) { exit( 1 ); } } } const int fd = open( variables["device"].as<std::string>().c_str(), O_RDWR ); ioctl( fd, I2C_SLAVE, 0x68 ); read( fd, &data, 1 ); write( fd, dump.data(), dump.size() );
  48. ϦΞϧλΠϜΫϩοΫ # echo m41t62 0x68 >/sys/class/i2c-adapter/i2c-1/new_device # ls /dec/rtc* /dev/rtc0

    # hwclock Tue Oct 15 08:29:19 2013 -0.872509 seconds -JOVYΒ͍͠ํ๏Ͱ࣌ࠁ͕ͱΕΔ # rc-update delete swclock boot # rc-update add hwclock boot # vim /etc/init.d/hwclock ... start() { echo m41t62 0x68 >/sys/class/i2c-adapter/i2c-1/new_device ... ࣮͸ΧʔωϧυϥΠό͕͋Δ
  49. ϦΞϧλΠϜΫϩοΫ ͜ΕͰిݯΛམͱͯ͠΋ ࣍ճىಈ࣌ਖ਼͍࣌͠ࠁʹͳ͍ͬͯΔ # rc-update delete swclock boot # rc-update

    add hwclock boot # vim /etc/init.d/hwclock ... start() { echo m41t62 0x68 >/sys/class/i2c-adapter/i2c-1/new_device ...
  50. #FBHMF#POFͷ41* ͨͩ͠ຊ͸ΦʔσΟΦ৴߸ͱڝ߹ ΋͏ຊ͸*$ͱڝ߹ 41*$4   41*% 41*$4  

    41*$4 410%   4$*4$-,     41*$4 41*%   41*% 41*4$-,       41*$4 ".Yʹ΋41*ϗετ͕ͭࡌ͍ͬͯΔ
  51. δϟΠϩηϯαʔ 41*$4   41*% 41*$4   41*$4 410%

      4$*4$-,     41*$4   4%0  4%*  4$-  $4  7*/  (/% 
  52. --- am335x-bone-common.dtsi.orig! 2013-10-17 23:18:50.595705986 +0900 +++ am335x-bone-common.dtsi! 2013-10-17 23:24:48.398440404 +0900

    @@ -52,6 +52,14 @@ ! ! ! ! 0x160 0x2f /* GPIO0_6 (PIN_INPUT | MUX_MODE7) */ ! ! ! >; ! ! }; +! ! spi0_pins: pinmux_spi0_pins { +! ! ! pinctrl-single,pins = < +! ! ! ! 0x150 0x30 /* spi0_sclk.gpio0_2, OUTPUT_PULLUP | MODE0 */ +! ! ! ! 0x154 0x30 /* spi0_d0.gpio0_3, INPUT_PULLUP | MODE0 */ +! ! ! ! 0x158 0x10 /* spi0_d1.i2c1_sda, OUTPUT_PULLUP | MODE0 */ +! ! ! ! 0x15c 0x10 /* spi0_cs0.i2c1_scl, OUTPUT_PULLUP | MODE0 */ +! ! ! >; +! ! }; ! }; ! ocp: ocp { @@ -548,3 +556,14 @@ ! status = "okay"; }; +&spi0 { +! pinctrl-names = "default"; +! pinctrl-0 = <&spi0_pins>; +! status = "okay"; +! gyrometer {
  53. ! ! }; +! ! spi0_pins: pinmux_spi0_pins { +! !

    ! pinctrl-single,pins = < +! ! ! ! 0x150 0x30 /* spi0_sclk.gpio0_2, OUTPUT_PULLUP | MODE0 */ +! ! ! ! 0x154 0x30 /* spi0_d0.gpio0_3, INPUT_PULLUP | MODE0 */ +! ! ! ! 0x158 0x10 /* spi0_d1.i2c1_sda, OUTPUT_PULLUP | MODE0 */ +! ! ! ! 0x15c 0x10 /* spi0_cs0.i2c1_scl, OUTPUT_PULLUP | MODE0 */ +! ! ! >; +! ! }; ! }; ! ocp: ocp { @@ -548,3 +556,14 @@ ! status = "okay"; }; +&spi0 { +! pinctrl-names = "default"; +! pinctrl-0 = <&spi0_pins>; +! status = "okay"; +! gyrometer { +! ! compatible = "st,l3g4200d"; +! ! reg = <0>; +! ! spi-max-frequency = <1000000>; +! }; +}; + 41*ͷ$4ʹδϟΠϩ͕͋Δ ϋʔυ΢ΣΞ͸MHHͰ ࠷େ.)[Ͱ௨৴ग़དྷΔ
  54. δϟΠϩηϯαʔ # ls /sys/bus/iio/devices/iio\:device0/ dev in_anglvel_z_scale in_anglvel_scale_available name in_anglvel_x_raw power

    in_anglvel_x_scale sampling_frequency in_anglvel_y_raw sampling_frequency_available in_anglvel_y_scale subsystem in_anglvel_z_raw uevent # cat /sys/bus/iio/devices/iio\:device0/in_anglvel_z_raw -105 ֯଎౓͕ͱΕΔ αʔό͕Կނ͔ߴ଎ճస͍ͯͨ͠Β ΞϥʔτϝʔϧΛඈ͹͢ ͱ͔Ͱ͖Δ
  55. #FBHMF#POFͷ"%$ ֦ͨͩ͠ுϔομʹग़͍ͯΔͷ͸ຊ  7%%@"%$ "*/   (/%"@"%$ "*/ 

     "*/ "*/   "*/ "*/   "*/ ".Yʹ͸νϟωϧͷ"%$͕͋Δ
  56. "%$ # modprobe ti_am335x_adc # echo BB-ADC >/sys/devices/bone_capemgr.10/slots # ls

    /sys/bus/iio/devices/iio\:device1/ ls /sys/bus/iio/devices/iio\:device1/ buffer in_voltage4_raw scan_elements dev in_voltage5_raw subsystem in_voltage0_raw in_voltage6_raw trigger in_voltage1_raw in_voltage7_raw uevent in_voltage2_raw name in_voltage3_raw power "%$ͷϞδϡʔϧͱ%54Λϩʔυ # cat /sys/bus/iio/devices/iio\:device1/in_voltage0_raw 2367
  57. "%$ # cat /sys/bus/iio/devices/iio\:device1/in_voltage0_raw 1 # cat /sys/bus/iio/devices/iio\:device1/in_voltage0_raw 607 #

    cat /sys/bus/iio/devices/iio\:device1/in_voltage0_raw 1728 # cat /sys/bus/iio/devices/iio\:device1/in_voltage0_raw 2871 # cat /sys/bus/iio/devices/iio\:device1/in_voltage0_raw 4094 ຊ౰͸λονύωϧ༻Β͍͠
  58. 18. ".Yʹ͸νϟωϧͷ18.͕͋Δ  ͸ͣͳΜ͚ͩͲ # echo bone_pwm_P8_13 >/sys/devices/bone_capemgr.*/slots # dmesg

    [ 1757.358156] bone-capemgr bone_capemgr.10: part_number 'bone_pwm_P8_13', version 'N/A' [ 1757.358250] bone-capemgr bone_capemgr.10: slot #9: generic override [ 1757.358275] bone-capemgr bone_capemgr.10: bone: Using override eeprom data at slot 9 [ 1757.358301] bone-capemgr bone_capemgr.10: slot #9: 'Override Board Name, 00A0,Override Manuf,bone_pwm_P8_13' [ 1757.358497] bone-capemgr bone_capemgr.10: slot #9: Requesting part number/version based 'bone_pwm_P8_13-00A0.dtbo [ 1757.358524] bone-capemgr bone_capemgr.10: slot #9: Requesting firmware 'bone_pwm_P8_13-00A0.dtbo' for board-name 'Override Board Name', version '00A0' [ 1757.358553] bone-capemgr bone_capemgr.10: slot #9: dtbo 'bone_pwm_P8_13-00A0.dtbo' loaded; converting to live tree [ 1757.358987] bone-capemgr bone_capemgr.10: slot #9: #2 overlays [ 1757.359830] bone-capemgr bone_capemgr.10: slot #9: Applied #2 overlays. [ 1757.373925] pwm_test pwm_test_P8_13.17: unable to request PWM [ 1757.373986] platform pwm_test_P8_13.17: Driver pwm_test requests probe deferral ͳΜ͔υϥΠόͷॳظԽͰ͚ͯ͜Δ