Wednesday, November 22, 2017

Want to send some patches to the Linux kernel? I used Coccinelle to find then and else statements that are identical. Coccinelle found 80 candidates. The output is here, and the Coccinelle script I used:

@@
statement S;
@@
-if (...)
- S
-else
- S
+ S


Monday, June 13, 2016

Building Yocto for DENX M53EVK

# Depending on when you are reading this, you may need to replace "krogoth" by something newer

# Step 1: Clonning
$ git clone git://git.yoctoproject.org/poky
$ cd poky/
$ git checkout krogoth

$ git clone git://git.openembedded.org/meta-openembedded
$ cd meta-openembedded
$ git checkout krogoth
$ cd ..

$ git clone git://git.yoctoproject.org/meta-fsl-arm
$ cd meta-fsl-arm
$ git checkout krogoth
$ cd ..

$ git clone git://github.com/Freescale/meta-fsl-arm-extra.git
$ cd meta-fsl-arm-extra
$ git checkout krogoth
$ cd ..

# Step 2: Configuring
$ export MACHINE="m53evk"
$ source oe-init-build-env

# Then edit your bblayers.conf file to add meta-openembedded/meta-oe, meta-fsl-arm, and meta-fsl-arm-extra:
$ vi conf/bblayers.conf # (.../poky/build/conf/bblayers.conf)

# POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
# changes incompatibly
POKY_BBLAYERS_CONF_VERSION = "2"

BBPATH = "${TOPDIR}"
BBFILES ?= ""

BBLAYERS ?= " \
  /home/peter/m53evk/poky/meta \
  /home/peter/m53evk/poky/meta-poky \
  /home/peter/m53evk/poky/meta-yocto-bsp \
  /home/peter/m53evk/poky/meta-openembedded/meta-oe \
  /home/peter/m53evk/poky/meta-fsl-arm \
  /home/peter/m53evk/poky/meta-fsl-arm-extra \
  "

# Step 3: Build
$ bitbake core-image-minimal
...
Parsing of 1584 .bb files complete (0 cached, 1584 parsed). 2117 targets, 178 skipped, 0 masked, 0 errors.
NOTE: Resolving any missing task queue dependencies

Build Configuration:
BB_VERSION        = "1.30.0"
BUILD_SYS         = "x86_64-linux"
NATIVELSBSTRING   = "CentOSLinux-7.2.1511"
TARGET_SYS        = "arm-poky-linux-gnueabi"
MACHINE           = "m53evk"
DISTRO            = "poky"
DISTRO_VERSION    = "2.1"
TUNE_FEATURES     = "arm armv7a vfp  neon"
TARGET_FPU        = "softfp"
meta              
meta-poky         
meta-yocto-bsp    = "krogoth:8f51f6153a09f8048fb4c4ce9cf4a19655240de4"
meta-oe           = "krogoth:247b1267bbe95719cd4877d2d3cfbaf2a2f4865a"
meta-fsl-arm      = "krogoth:3f34509381092a893b8efe4451018b8d67a5abf6"
meta-fsl-arm-extra = "krogoth:698cf389aa446244a39b597fbf58be1d55096500"

Monday, October 12, 2015

git rebase eats my commits when the rebase fail... (no, not really)

I'm playing with git --rebase for the first time. The first patch of the series was fixing coding style, but it was also introducing some coding style errors related to continuation lines. Instead of adding two additional tabs, I was aligning the continuation lines with the previous opening parenthesis. Oops. So I needed to edit the first commit of the series to be able to resent all of them. git makes it quite convenient, right?

     $ git --rebase --interactive <commit hash>^

Then git will show a text file for you to edit and choose what to do with each commits. Everything fine until now. My workflow is

     $ vi path/to/file.c
     $ make path/to/file.o
     $ git add path/to/file.c
     $ git commit --amend
     $ git rebase --continue

Well this is awesome, and I had fun rebasing all my 11 commits and it was looking very good. Even when the automatic rebase doesn't work it is very intuitive and great to work with. This is one sample output when the automatic rebase fails:

     $ git rebase --continue
     [detached HEAD a22bcda] usb/host/fotg210: Remove useless else statement
      1 file changed, 2 insertions(+), 3 deletions(-)
     error: could not apply d13e859... usb/host/fotg210: Add function: output_buf_tds_dir()

     When you have resolved this problem, run "git rebase --continue".
     If you prefer to skip this patch, run "git rebase --skip" instead.
     To check out the original branch and stop rebasing, run "git rebase --abort".
     Could not apply d13e8595018d5eb2f2eea19df7b20916f3862004... usb/host/fotg210: Add function: output_buf_tds_dir()

So I just repeated the same workflow as before:

     $ vi path/to/file.c
     $ make path/to/file.o
     $ git add path/to/file.c
     $ git commit --amend
     $ git rebase --continue

And... AHHHH! Where is my commit? Why did git merged two commits? I have to start again, why didn't I create a new branch before playing with rebase? And then, like Bart being tempted by trying again until it works, I tried again just creating some branches to avoid having to do all the work again. How boring is to adjust where the first character should be in 100 lines... I even made a script that detect continuation lines and print it for me. But when the rebase failed, and I used my proven workflow, the result was exactly the same: AHHHHH!

The issue is that when the rebase fails, you are not supposed to commit, unless you want to merge two commits! But, but, where is that information available? git tells you that. Try git status after git add and you see. So the workflow when rebase fails should be:

     $ vi path/to/file.c
     $ make path/to/file.o
     $ git add path/to/file.c
     $ git status # Read what git has to tell you
     $ git rebase --continue

And no more mysterious merges!

Thursday, September 17, 2015

bool b = -1; if(b) printk("Yes, -1 maps to true!");

 /* Assign -1 to bool variable */
 bool b = -1;  
 if(b)  
     printk("Yes, -1 maps to true!");  
  
 /* Return -1 in bool function */
 bool f(void)  
 {  
        return -1;  
 }  
  
 if (f())  
     printk("Yes, -1 maps to true!");  

Yesterday I was reading this interesting discussion about the boolean type in C. The most interesting sentence was:

"0 is false, 1 is true, any other value is *undefined behavior*."

Then I started to look for abuses of the bool type in the Linux kernel. I wrote simple semantic patches for getting cases in which a negative values are being returned by bool functions:

 @@  
 identifier f, ret;  
 constant C;  
 typedef bool;  
 @@  
 bool f (...){  
 <+...  
 ret = -C;  
 ...  
 * return ret;  
 ...+>  
 }  

and

 @@  
 identifier f;  
 constant C;  
 typedef bool;  
 @@  
 bool f (...){  
 <+...  
 * return -C;  
 ...+>  
 }  

The first search for boolean functions that assign negative value to a variable, and return the variable, while the second search for boolean functions returning negative values.

Coccinelle found 3 candidates for me:

 diff -u -p ./tools/testing/selftests/powerpc/pmu/lib.c /tmp/nothing/tools/testing/selftests/powerpc/pmu/lib.c  
 --- ./tools/testing/selftests/powerpc/pmu/lib.c  
 +++ /tmp/nothing/tools/testing/selftests/powerpc/pmu/lib.c  
 @@ -248,6 +248,5 @@ bool require_paranoia_below(int level)  
  out_close:  
     fclose(f);  
  out:  
 -    return rc;  
  }  
 diff -u -p ./arch/powerpc/kernel/module_64.c /tmp/nothing/arch/powerpc/kernel/module_64.c  
 --- ./arch/powerpc/kernel/module_64.c  
 +++ /tmp/nothing/arch/powerpc/kernel/module_64.c  
 @@ -160,7 +160,6 @@ bool is_module_trampoline(u32 *p)  
     BUILD_BUG_ON(sizeof(ppc64_stub_insns) != sizeof(ppc64_stub_mask));  
     if (probe_kernel_read(insns, p, sizeof(insns)))  
 -        return -EFAULT;  
     for (i = 0; i < ARRAY_SIZE(ppc64_stub_insns); i++) {  
         u32 insna = insns[i];  
 diff -u -p ./tools/perf/util/util.c /tmp/nothing/tools/perf/util/util.c  
 --- ./tools/perf/util/util.c  
 +++ /tmp/nothing/tools/perf/util/util.c  
 @@ -709,7 +709,6 @@ bool find_process(const char *name)  
     dir = opendir(procfs__mountpoint());  
     if (!dir)  
 -        return -1;  
     /* Walk through the directory. */  
     while (ret && (d = readdir(dir)) != NULL) {  

Finding probable bugs with Coccinelle is easy, verifying which of the candidates are real bugs demands a little bit more work. I was mostly interested in the arch/powerpc/kernel/module_64.c file as is the only candidate that is kernel code, the other two are inside tools directory. I created test code based on examples from the article about booleans. As the file is part of the PowerPC architecture, some cross compiling is needed, but that's not a problem for Fedora. For installing the cross compiler for PowerPC:

 $ sudo dnf install gcc-powerpc64-linux-gnu  

Now that I have the compiler I want to see how does the compiler maps -1 when returning from a boolean function. Two toy examples:

 t.c:  
 _Bool main(void)  
 {  
     return -1;  
 }  
  
 t2.c:  
 int main(void)  
 {  
     return -1;  
 }  

for compiling:

 $ powerpc64-linux-gnu-gcc -O2 -S -fomit-frame-pointer <c file>  

which genarated t.s and t2.s. What is interesting is that the assembly code for t1.c returns 1 while the assembly code for t2.c returns -1.

 t.s:  
 ...  
 .L.main:  
     li 3,1  
     blr  
  
 t2.s:  
 ...  
 .L.main:  
     li 3,-1  
     blr  

This convinced me that -1 was being mapped to true, but it would be better to see the impact of my change on the real source file. For cross compiling two environment variables should be set, and before compiling the kernel should be configured. After that, creating the .s file is easy:

 $ export ARCH=powerpc CROSS_COMPILE=powerpc64-linux-gnu-  
 $ make allyesconfig  
 $ make arch/powerpc/kernel/module_64.s  

I did one make arch/powerpc/kernel/module_64.s for the original file returning -EFAULT, for a patched file returning false instead of -EFAULT, and for a patched file returning true instead of -EFAULT. Comparing this two files made it clear that -EFAULT is being mapped to true! The diff between the original .s file and the .s file returning false instead of -EFAULT starts with:

 440,441c440,441  
 < .L43:  
 <    li 3,1  # D.25775,  
 ---  
 > .L42:  
 >    li 3,0  # D.25775,  
 ...  

while the diff is empty comparing the original file and the version returning true instead of -EFAULT.

I sent patches earlier today. Let's see how it goes:



Tuesday, April 14, 2015

Adding a serial console to the Buffalo Air Station WZR-1750DHP

Playing with custom kernels and OpenWRT... It took me more than a month to flash a kernel that won't boot, but I did it yesterday. So the only way was to open the case, and connect the cables to access the serial console. Here is what I learned.

Before you start

Tools

For opening the case you will need to remove two screws that are similar to those of mobile phones. I don't know the type name nor the size, so I recommend you to check type and size before starting. The screws are under the adhesive on the back of the router near the power plug and the mode button. UPDATE: Matt Sealey posted a comment saying that the screws are Torx T6. Thank you Matt!


USB to Serial

You will need something to connect your computer to the serial interface of the router. The most common solution is to use an USB to serial adapter. There are plenty of options, but I'm using this one that I bought on Ebay for less than € 10. Search for 'FT232RL' on your favorite online store.




Cables

You will also need 3 female to female breadboard wires, which are also easy to find in your favorite online store. I found a pack of 40 wires for less than € 2.



Opening the case and connecting wires

Opening the case


This is more complicated than usual for two reasons:

  • There are two hidden screws on the back of the router. One near the power connector and other near the mode button. Remove the adhesive with care so you can put it back later. The screws are similar to the ones used on cell phones, so before you start, make sure you have the tools to open it properly.
  • There is a heat sink on the part you are going to remove, and it is glued to some metallic case on the PCB. Open the case slowly and with care.
But it is not a big deal, the case is not fragile, so you can apply a little bit of brute force when opening it.


3.3V Serial vs 5V Serial

The Serial to USB usually have the option to be 3.3V or 5V. Configure it to 3.3V. On my adapter the configuration is done on the back side of the PCB.


Connecting the wires

This is easier than opening the case. The pins on the router are near the reset button on the top right. You need to connect GND, RX and TX. The labels on the picture shows where the pins of the Serial to USB adapter should be connected to. TX on the Serial to USB should be connected to the pin with the label TX on the picture below.


Connecting 3.3V pin of the router to the VCC pin of the Serial to USB adapter causes the Serial to USB adapter to power off with the router. This can make your life harder as powering off the router may freeze the terminal emulation software on your PC.


Software

How to find the device node of the serial port?

After connecting the USB to serial adapter to your computer use dmesg and look for the ttyUSB string:

$ dmesg
...
[ 7174.272428] usb 6-1.3.4: Product: FT232R USB UART
[ 7174.272434] usb 6-1.3.4: Manufacturer: FTDI
[ 7174.321779] ftdi_sio 6-1.3.4:1.0: FTDI USB Serial Device converter detected
[ 7174.321873] usb 6-1.3.4: Detected FT232RL
[ 7174.322740] usb 6-1.3.4: FTDI USB Serial Device converter now attached to ttyUSB1

So in this case it is /dev/ttyUSB1


Do my user has permission to use the serial port?

Your distro may not allow your user to access the serial port. It is easy to check with ls and groups if you have rights:

$ ls -la /dev/ttyUSB1
crw-rw---- 1 root dialout 188, 1 Apr 14 16:55 /dev/ttyUSB1

$ groups
peter wheel dialout wireshark

As the grouop dialout has read and write permission at /dev/ttyUSB1 and as I'm member of the group dialout, everything is fine. If your user is not on the correct group, fix it before continuing. Simple dirty and dangerous hack: call minicom with sudo


Which software to use?

As I'm using Linux, I tried moserial and minicom. I could made it work only with minicom. There are two magical commands to minicom: Ctrl-A Z for showing all options and Ctrl-A X to exit in a clean way.


How to configure the serial port?

Configuring the serial port to 115200 8N1 is enough to read from the console, but not to write to it. For writing, it is necessary to disable Hardware Flow Control and disable Software Flow Control.


For minicom:
$ minicom -s -D /dev/ttyUSB1

Then navigate to Sertial port setup and make sure the configuration matches the description.



After that you could Exit to go to the console or save the configuration.


Interacting with the console

I follow this order:
  1. Connect the USB to Serial to your computer
  2. Start minicom
  3. Power on the router and wait for the initialization messages
  4. Press Ctrl-C some times until you see the prompt CFE> 
Now you can start fixing your router.



Now what?

Check this out: http://wiki.openwrt.org/doc/techref/bootloader/cfe


Sources / References

Wednesday, March 4, 2015

Buffalo WZR-1750DHP + OpenWRT

This is the first of a series of posts about Linux kernel development for ARM. There will be one or two more posts before we get into the Kernel, describing tasks as building, and configuring OpenWRT. Maybe I'll also write about de-bricking devices if I manage to do something silly with my router. :-)





What I like about the Buffalo WZR-1750DHP are the specs and the case without external antennas. It has a dual core ARM CPU with 512MB of RAM, and two wifi adapters: One for 2.4GHz and other for 5GHz.

I was expecting that to install OpenWRT in a device like the WZR-1750DHP, it would require to find and use a serial port. Luckily that's not necessary. All the procedure was done over friendly web interfaces.

As the router do not allow to install random firmware images, there are some workarounds to install OpenWRT. The steps I used are:

1 - Install and upgrade DD-WRT

  • Download the latest versions of the files factory-to-dd-wrt.bin and buffalo-wzr-1750dhp-webflash.bin from: ftp://ftp.dd-wrt.com/betas/2015/02-24-2015-r26348/buffalo_wzr-1750dhp/ As the directories names are build dates, you can browse the directories to see if there is a newer version available.
  • Update the firmware to the file factory-to-dd-wrt.bin using the web interface of the router. Be patient as this process takes some time.
  • Now your router is running DD-WRT. Using DD-WRT web interface update the firmware to the file buffalo-wzr-1750dhp-webflash.bin. Be patient as this process takes some time.
2 - Install OpenWRT
  • Download the latest version of the file openwrt-bcm53xx-bcm4708-buffalo-wzr-1750dhp-squashfs.trx from http://wiki.openwrt.org/toh/buffalo/wzr-1750dhp
  • Using DD-WRT web interface update the firmware to the file openwrt-bcm53xx-bcm4708-buffalo-wzr-1750dhp-squashfs.trx. Be patient as this process takes some time.
3 - Connect to OpenWRT
  • OpenWRT is beautifully simple, with a similar spirit of Arch Linux. This means that by default there is no web interface, and the wifi is disabled. So the first connection is made trough telnet over one of the Ethernet LAN ports. Probably you will be good with: $ telnet 192.168.1.1
  • Configure a root password with passwd: $ passwd
  • Exit telnet and login again with ssh.




Sources:

Saturday, November 9, 2013

Broken resume after suspend to ram on Toshiba R830-10p

Resume after suspend to RAM is broken on Toshiba R830. I want to fix it. Can you help me, or introduce me to someone who can help me?

Somehow the bug is related to Intel VT-d or x2apic. Disabling VT-d on the BIOS, makes the resume work. With VT-d enabled, passing nox2apic as boot parameter to Kernel also makes the resume work.

I've asked for help: https://lkml.org/lkml/2013/11/1/186

The current issue is that my notebook doesn't have real serial port, so I can't track what's going on. Suspend / resume steps before calling the platform firmware work perfectly. So it works perfectly if I echo freeze > /sys/power/state...

Ideas? Any creative idea on using systemtap to debug this issue?

Wednesday, October 30, 2013

Debugging suspend on Toshiba R830-10p: Some test results and logs

When testing suspend to RAM, all tests went well. But the real thing doesn't work... Ideas?

# echo freezer > /sys/power/pm_test
# echo mem > /sys/power/state
[27354.755748] PM: Syncing filesystems ... done.
[27354.780184] PM: Preparing system for mem sleep
[27354.780687] Freezing user space processes ... (elapsed 0.007 seconds) done.
[27354.787975] Freezing remaining freezable tasks ... (elapsed 0.001 seconds) done.
[27354.789133] suspend debug: Waiting for 5 seconds.
[27359.783027] PM: Finishing wakeup.
[27359.783028] Restarting tasks ... done.
[27359.784320] video LNXVIDEO:01: Restoring backlight state

# echo devices > /sys/power/pm_test
# echo mem > /sys/power/state 
[27476.796841] PM: Syncing filesystems ... done.
[27476.820641] PM: Preparing system for mem sleep
[27476.820952] Freezing user space processes ... (elapsed 0.001 seconds) done.
[27476.822083] Freezing remaining freezable tasks ... (elapsed 0.001 seconds) done.
[27476.823290] PM: Entering mem sleep
[27476.823403] Suspending console(s) (use no_console_suspend to debug)
[27476.824398] sd 0:0:0:0: [sda] Synchronizing SCSI cache
[27476.826199] sd 0:0:0:0: [sda] Stopping disk
[27476.949881] mei_me 0000:00:16.0: suspend
[27477.060221] i915 0000:00:02.0: power state changed by ACPI to D3cold
[27477.123519] PM: suspend of devices complete after 300.336 msecs
[27477.123520] suspend debug: Waiting for 5 seconds.
[27482.117473] i915 0000:00:02.0: power state changed by ACPI to D0
[27482.117503] e1000e 0000:00:19.0: setting latency timer to 64
[27482.117517] mei_me 0000:00:16.0: irq 55 for MSI/MSI-X
[27482.117522] e1000e 0000:00:19.0: irq 56 for MSI/MSI-X
[27482.121797] ehci-pci 0000:00:1a.0: setting latency timer to 64
[27482.121974] ehci-pci 0000:00:1d.0: setting latency timer to 64
[27482.121984] toshiba_bluetooth: Re-enabling Toshiba Bluetooth
[27482.127556] i915 0000:00:02.0: setting latency timer to 64
[27482.128809] ahci 0000:00:1f.2: setting latency timer to 64
[27482.133671] snd_hda_intel 0000:00:1b.0: irq 57 for MSI/MSI-X
[27482.145762] [drm] Wrong MCH_SSKPD value: 0x16040307
[27482.145763] [drm] This can cause pipe underruns and display issues.
[27482.145763] [drm] Please upgrade your BIOS to fix this.
[27482.444173] ata3: SATA link up 1.5 Gbps (SStatus 113 SControl 300)
[27482.446135] ata1: SATA link up 3.0 Gbps (SStatus 123 SControl 300)
[27482.446461] ACPI Error: [GTF0] Namespace lookup failure, AE_NOT_FOUND (20130517/psargs-359)
[27482.446471] ACPI Error: Method parse/execution failed [\_SB_.PCI0.SAT0.PRT0._SDD] (Node ffff880437c91cd0), AE_NOT_FOUND (20130517/psparse-536)
[27482.446525] ACPI Error: [GTF0] Namespace lookup failure, AE_NOT_FOUND (20130517/psargs-359)
[27482.446532] ACPI Error: Method parse/execution failed [\_SB_.PCI0.SAT0.PRT0._GTF] (Node ffff880437c91cf8), AE_NOT_FOUND (20130517/psparse-536)
[27482.446912] ACPI Error: [GTF0] Namespace lookup failure, AE_NOT_FOUND (20130517/psargs-359)
[27482.446918] ACPI Error: Method parse/execution failed [\_SB_.PCI0.SAT0.PRT0._SDD] (Node ffff880437c91cd0), AE_NOT_FOUND (20130517/psparse-536)
[27482.446955] ACPI Error: [GTF0] Namespace lookup failure, AE_NOT_FOUND (20130517/psargs-359)
[27482.446960] ACPI Error: Method parse/execution failed [\_SB_.PCI0.SAT0.PRT0._GTF] (Node ffff880437c91cf8), AE_NOT_FOUND (20130517/psparse-536)
[27482.446999] ata1.00: configured for UDMA/100
[27482.447050] sd 0:0:0:0: [sda] Starting disk
[27482.448130] ata4: SATA link down (SStatus 0 SControl 300)
[27482.449304] ata3.00: configured for UDMA/100
[27482.634261] PM: resume of devices complete after 517.541 msecs
[27482.634521] PM: Finishing wakeup.
[27482.634523] Restarting tasks ... done.
[27482.635801] video LNXVIDEO:01: Restoring backlight state
[27483.509825] [drm] Enabling RC6 states: RC6 on, RC6p off, RC6pp off
[27483.881322] e1000e: enp0s25 NIC Link is Up 100 Mbps Full Duplex, Flow Control: None
[27483.881332] e1000e 0000:00:19.0 enp0s25: 10/100 speed: disabling TSO

# echo platform > /sys/power/pm_test
# echo mem > /sys/power/state 
[27721.020621] PM: Syncing filesystems ... done.
[27721.043989] PM: Preparing system for mem sleep
[27721.044287] Freezing user space processes ... (elapsed 0.001 seconds) done.
[27721.045418] Freezing remaining freezable tasks ... (elapsed 0.000 seconds) done.
[27721.046353] PM: Entering mem sleep
[27721.046436] Suspending console(s) (use no_console_suspend to debug)
[27721.047172] sd 0:0:0:0: [sda] Synchronizing SCSI cache
[27721.047261] sd 0:0:0:0: [sda] Stopping disk
[27721.166793] mei_me 0000:00:16.0: suspend
[27721.293987] i915 0000:00:02.0: power state changed by ACPI to D3cold
[27721.341260] PM: suspend of devices complete after 295.104 msecs
[27721.341494] PM: late suspend of devices complete after 0.231 msecs
[27721.373902] ehci-pci 0000:00:1d.0: System wakeup enabled by ACPI
[27721.385162] ehci-pci 0000:00:1a.0: System wakeup enabled by ACPI
[27721.395828] e1000e 0000:00:19.0: System wakeup enabled by ACPI
[27721.417761] PM: noirq suspend of devices complete after 76.364 msecs
[27721.418005] ACPI: Preparing to enter system sleep state S3
[27721.418275] PM: Saving platform NVS memory
[27721.418953] suspend debug: Waiting for 5 seconds.
[27726.413177] ACPI: Waking up from system sleep state S3
[27726.413576] i915 0000:00:02.0: power state changed by ACPI to D0
[27726.468195] ehci-pci 0000:00:1a.0: System wakeup disabled by ACPI
[27726.490167] ehci-pci 0000:00:1d.0: System wakeup disabled by ACPI
[27726.512267] sdhci-pci 0000:01:00.0: MMC controller base frequency changed to 50Mhz.
[27726.545198] PM: noirq resume of devices complete after 131.829 msecs
[27726.545317] PM: early resume of devices complete after 0.076 msecs
[27726.545346] i915 0000:00:02.0: setting latency timer to 64
[27726.545364] mei_me 0000:00:16.0: irq 55 for MSI/MSI-X
[27726.545371] e1000e 0000:00:19.0: System wakeup disabled by ACPI
[27726.545380] e1000e 0000:00:19.0: setting latency timer to 64
[27726.545401] e1000e 0000:00:19.0: irq 56 for MSI/MSI-X
[27726.545534] ahci 0000:00:1f.2: setting latency timer to 64
[27726.545924] ehci-pci 0000:00:1a.0: setting latency timer to 64
[27726.546096] snd_hda_intel 0000:00:1b.0: irq 57 for MSI/MSI-X
[27726.546294] ehci-pci 0000:00:1d.0: setting latency timer to 64
[27726.550352] toshiba_bluetooth: Re-enabling Toshiba Bluetooth
[27726.568320] [drm] Wrong MCH_SSKPD value: 0x16040307
[27726.568321] [drm] This can cause pipe underruns and display issues.
[27726.568321] [drm] Please upgrade your BIOS to fix this.
[27726.866676] ata1: SATA link up 3.0 Gbps (SStatus 123 SControl 300)
[27726.867036] ACPI Error: [GTF0] Namespace lookup failure, AE_NOT_FOUND (20130517/psargs-359)
[27726.867047] ACPI Error: Method parse/execution failed [\_SB_.PCI0.SAT0.PRT0._SDD] (Node ffff880437c91cd0), AE_NOT_FOUND (20130517/psparse-536)
[27726.867096] ACPI Error: [GTF0] Namespace lookup failure, AE_NOT_FOUND (20130517/psargs-359)
[27726.867104] ACPI Error: Method parse/execution failed [\_SB_.PCI0.SAT0.PRT0._GTF] (Node ffff880437c91cf8), AE_NOT_FOUND (20130517/psparse-536)
[27726.867463] ACPI Error: [GTF0] Namespace lookup failure, AE_NOT_FOUND (20130517/psargs-359)
[27726.867471] ACPI Error: Method parse/execution failed [\_SB_.PCI0.SAT0.PRT0._SDD] (Node ffff880437c91cd0), AE_NOT_FOUND (20130517/psparse-536)
[27726.867516] ACPI Error: [GTF0] Namespace lookup failure, AE_NOT_FOUND (20130517/psargs-359)
[27726.867524] ACPI Error: Method parse/execution failed [\_SB_.PCI0.SAT0.PRT0._GTF] (Node ffff880437c91cf8), AE_NOT_FOUND (20130517/psparse-536)
[27726.867564] ata1.00: configured for UDMA/100
[27726.867622] sd 0:0:0:0: [sda] Starting disk
[27726.868654] ata4: SATA link down (SStatus 0 SControl 300)
[27726.870659] ata3: SATA link up 1.5 Gbps (SStatus 113 SControl 300)
[27726.875856] ata3.00: configured for UDMA/100
[27727.046699] PM: resume of devices complete after 502.030 msecs
[27727.046971] PM: Finishing wakeup.
[27727.046973] Restarting tasks ... done.
[27727.048108] video LNXVIDEO:01: Restoring backlight state
[27728.195009] [drm] Enabling RC6 states: RC6 on, RC6p off, RC6pp off
[27728.355744] e1000e: enp0s25 NIC Link is Up 100 Mbps Full Duplex, Flow Control: None
[27728.355752] e1000e 0000:00:19.0 enp0s25: 10/100 speed: disabling TSO

# echo processors > /sys/power/pm_test
# echo mem > /sys/power/state 
[27808.566665] PM: Syncing filesystems ... done.
[27808.590955] PM: Preparing system for mem sleep
[27808.591499] Freezing user space processes ... (elapsed 0.001 seconds) done.
[27808.592616] Freezing remaining freezable tasks ... (elapsed 0.001 seconds) done.
[27808.593723] PM: Entering mem sleep
[27808.593828] Suspending console(s) (use no_console_suspend to debug)
[27808.594707] sd 0:0:0:0: [sda] Synchronizing SCSI cache
[27808.594775] sd 0:0:0:0: [sda] Stopping disk
[27808.715371] mei_me 0000:00:16.0: suspend
[27808.823963] i915 0000:00:02.0: power state changed by ACPI to D3cold
[27808.889284] PM: suspend of devices complete after 295.679 msecs
[27808.889467] PM: late suspend of devices complete after 0.181 msecs
[27808.921825] ehci-pci 0000:00:1d.0: System wakeup enabled by ACPI
[27808.933096] ehci-pci 0000:00:1a.0: System wakeup enabled by ACPI
[27808.943763] e1000e 0000:00:19.0: System wakeup enabled by ACPI
[27808.965705] PM: noirq suspend of devices complete after 76.335 msecs
[27808.965999] ACPI: Preparing to enter system sleep state S3
[27808.966272] PM: Saving platform NVS memory
[27808.967073] Disabling non-boot CPUs ...
[27808.967359] Broke affinity for irq 54
[27808.968711] smpboot: CPU 1 is now offline
[27808.970200] smpboot: CPU 2 is now offline
[27808.970687] Broke affinity for irq 16
[27808.970690] Broke affinity for irq 23
[27808.970693] Broke affinity for irq 42
[27808.970695] Broke affinity for irq 43
[27808.970696] Broke affinity for irq 44
[27808.970698] Broke affinity for irq 45
[27808.970700] Broke affinity for irq 46
[27808.970702] Broke affinity for irq 47
[27808.970703] Broke affinity for irq 48
[27808.970705] Broke affinity for irq 49
[27808.970707] Broke affinity for irq 50
[27808.970708] Broke affinity for irq 51
[27808.970710] Broke affinity for irq 52
[27808.971730] smpboot: CPU 3 is now offline
[27808.972038] suspend debug: Waiting for 5 seconds.
[27813.965863] Enabling non-boot CPUs ...
[27813.965885] smpboot: Booting Node 0 Processor 1 APIC 0x1
[27813.966148] [sched_delayed] sched: RT throttling activated
[27813.979154] Intel pstate controlling: cpu 1
[27813.979217] microcode: CPU1 sig=0x206a7, pf=0x10, revision=0x29
[27813.979220] CPU1 is up
[27813.979236] smpboot: Booting Node 0 Processor 2 APIC 0x2
[27813.992495] Intel pstate controlling: cpu 2
[27813.992558] microcode: CPU2 sig=0x206a7, pf=0x10, revision=0x29
[27813.992561] CPU2 is up
[27813.992576] smpboot: Booting Node 0 Processor 3 APIC 0x3
[27814.005844] Intel pstate controlling: cpu 3
[27814.005890] microcode: CPU3 sig=0x206a7, pf=0x10, revision=0x29
[27814.005893] CPU3 is up
[27814.008977] ACPI: Waking up from system sleep state S3
[27814.009621] i915 0000:00:02.0: power state changed by ACPI to D0
[27814.064059] ehci-pci 0000:00:1a.0: System wakeup disabled by ACPI
[27814.086029] ehci-pci 0000:00:1d.0: System wakeup disabled by ACPI
[27814.108153] sdhci-pci 0000:01:00.0: MMC controller base frequency changed to 50Mhz.
[27814.141065] PM: noirq resume of devices complete after 131.682 msecs
[27814.141188] PM: early resume of devices complete after 0.077 msecs
[27814.141203] i915 0000:00:02.0: setting latency timer to 64
[27814.141237] mei_me 0000:00:16.0: irq 55 for MSI/MSI-X
[27814.141257] e1000e 0000:00:19.0: System wakeup disabled by ACPI
[27814.141265] e1000e 0000:00:19.0: setting latency timer to 64
[27814.141285] e1000e 0000:00:19.0: irq 56 for MSI/MSI-X
[27814.142181] ahci 0000:00:1f.2: setting latency timer to 64
[27814.152469] ehci-pci 0000:00:1a.0: setting latency timer to 64
[27814.152545] snd_hda_intel 0000:00:1b.0: irq 57 for MSI/MSI-X
[27814.152695] ehci-pci 0000:00:1d.0: setting latency timer to 64
[27814.152704] toshiba_bluetooth: Re-enabling Toshiba Bluetooth
[27814.166059] [drm] Wrong MCH_SSKPD value: 0x16040307
[27814.166059] [drm] This can cause pipe underruns and display issues.
[27814.166060] [drm] Please upgrade your BIOS to fix this.
[27814.466522] ata3: SATA link up 1.5 Gbps (SStatus 113 SControl 300)
[27814.468514] ata1: SATA link up 3.0 Gbps (SStatus 123 SControl 300)
[27814.468696] ACPI Error: [GTF0] Namespace lookup failure, AE_NOT_FOUND (20130517/psargs-359)
[27814.468700] ACPI Error: Method parse/execution failed [\_SB_.PCI0.SAT0.PRT0._SDD] (Node ffff880437c91cd0), AE_NOT_FOUND (20130517/psparse-536)
[27814.468718] ACPI Error: [GTF0] Namespace lookup failure, AE_NOT_FOUND (20130517/psargs-359)
[27814.468722] ACPI Error: Method parse/execution failed [\_SB_.PCI0.SAT0.PRT0._GTF] (Node ffff880437c91cf8), AE_NOT_FOUND (20130517/psparse-536)
[27814.468954] ACPI Error: [GTF0] Namespace lookup failure, AE_NOT_FOUND (20130517/psargs-359)
[27814.468958] ACPI Error: Method parse/execution failed [\_SB_.PCI0.SAT0.PRT0._SDD] (Node ffff880437c91cd0), AE_NOT_FOUND (20130517/psparse-536)
[27814.468976] ACPI Error: [GTF0] Namespace lookup failure, AE_NOT_FOUND (20130517/psargs-359)
[27814.468979] ACPI Error: Method parse/execution failed [\_SB_.PCI0.SAT0.PRT0._GTF] (Node ffff880437c91cf8), AE_NOT_FOUND (20130517/psparse-536)
[27814.469006] ata1.00: configured for UDMA/100
[27814.469037] sd 0:0:0:0: [sda] Starting disk
[27814.471662] ata3.00: configured for UDMA/100
[27814.472504] ata4: SATA link down (SStatus 0 SControl 300)
[27814.652459] PM: resume of devices complete after 511.934 msecs
[27814.652616] PM: Finishing wakeup.
[27814.652617] Restarting tasks ... done.
[27814.653218] video LNXVIDEO:01: Restoring backlight state
[27815.939622] e1000e: enp0s25 NIC Link is Up 100 Mbps Full Duplex, Flow Control: None
[27815.939632] e1000e 0000:00:19.0 enp0s25: 10/100 speed: disabling TSO
[27816.080477] [drm] Enabling RC6 states: RC6 on, RC6p off, RC6pp off

# echo core > /sys/power/pm_test
# echo mem > /sys/power/state 
[27978.819058] PM: Syncing filesystems ... done.
[27978.847076] PM: Preparing system for mem sleep
[27978.847699] Freezing user space processes ... (elapsed 0.006 seconds) done.
[27978.854415] Freezing remaining freezable tasks ... (elapsed 0.000 seconds) done.
[27978.855398] PM: Entering mem sleep
[27978.855500] Suspending console(s) (use no_console_suspend to debug)
[27978.856388] sd 0:0:0:0: [sda] Synchronizing SCSI cache
[27978.856480] sd 0:0:0:0: [sda] Stopping disk
[27978.976177] mei_me 0000:00:16.0: suspend
[27979.079138] i915 0000:00:02.0: power state changed by ACPI to D3cold
[27979.149989] PM: suspend of devices complete after 294.725 msecs
[27979.150318] PM: late suspend of devices complete after 0.325 msecs
[27979.182982] ehci-pci 0000:00:1d.0: System wakeup enabled by ACPI
[27979.194246] ehci-pci 0000:00:1a.0: System wakeup enabled by ACPI
[27979.204909] e1000e 0000:00:19.0: System wakeup enabled by ACPI
[27979.226842] PM: noirq suspend of devices complete after 76.622 msecs
[27979.227095] ACPI: Preparing to enter system sleep state S3
[27979.227344] PM: Saving platform NVS memory
[27979.228057] Disabling non-boot CPUs ...
[27979.228319] Broke affinity for irq 54
[27979.229609] smpboot: CPU 1 is now offline
[27979.231147] smpboot: CPU 2 is now offline
[27979.231783] Broke affinity for irq 16
[27979.231785] Broke affinity for irq 23
[27979.231788] Broke affinity for irq 42
[27979.231789] Broke affinity for irq 43
[27979.231791] Broke affinity for irq 44
[27979.231793] Broke affinity for irq 45
[27979.231794] Broke affinity for irq 46
[27979.231796] Broke affinity for irq 47
[27979.231798] Broke affinity for irq 48
[27979.231799] Broke affinity for irq 49
[27979.231801] Broke affinity for irq 50
[27979.231802] Broke affinity for irq 51
[27979.231804] Broke affinity for irq 52
[27979.232828] smpboot: CPU 3 is now offline
[27979.233279] suspend debug: Waiting for 5 seconds.
[27984.227385] microcode: CPU0 sig=0x206a7, pf=0x10, revision=0x29
[27984.227418] Enabling non-boot CPUs ...
[27984.227450] smpboot: Booting Node 0 Processor 1 APIC 0x1
[27984.240724] Intel pstate controlling: cpu 1
[27984.240789] microcode: CPU1 sig=0x206a7, pf=0x10, revision=0x29
[27984.240793] CPU1 is up
[27984.240808] smpboot: Booting Node 0 Processor 2 APIC 0x2
[27984.254085] Intel pstate controlling: cpu 2
[27984.254146] microcode: CPU2 sig=0x206a7, pf=0x10, revision=0x29
[27984.254150] CPU2 is up
[27984.254164] smpboot: Booting Node 0 Processor 3 APIC 0x3
[27984.267446] Intel pstate controlling: cpu 3
[27984.267506] microcode: CPU3 sig=0x206a7, pf=0x10, revision=0x29
[27984.267510] CPU3 is up
[27984.270772] ACPI: Waking up from system sleep state S3
[27984.271203] i915 0000:00:02.0: power state changed by ACPI to D0
[27984.325879] ehci-pci 0000:00:1a.0: System wakeup disabled by ACPI
[27984.347850] ehci-pci 0000:00:1d.0: System wakeup disabled by ACPI
[27984.369927] sdhci-pci 0000:01:00.0: MMC controller base frequency changed to 50Mhz.
[27984.402884] PM: noirq resume of devices complete after 131.893 msecs
[27984.403005] PM: early resume of devices complete after 0.078 msecs
[27984.403030] i915 0000:00:02.0: setting latency timer to 64
[27984.403059] mei_me 0000:00:16.0: irq 55 for MSI/MSI-X
[27984.403060] e1000e 0000:00:19.0: System wakeup disabled by ACPI
[27984.403069] e1000e 0000:00:19.0: setting latency timer to 64
[27984.403093] e1000e 0000:00:19.0: irq 56 for MSI/MSI-X
[27984.403258] ahci 0000:00:1f.2: setting latency timer to 64
[27984.403614] ehci-pci 0000:00:1a.0: setting latency timer to 64
[27984.403816] snd_hda_intel 0000:00:1b.0: irq 57 for MSI/MSI-X
[27984.403988] ehci-pci 0000:00:1d.0: setting latency timer to 64
[27984.408183] toshiba_bluetooth: Re-enabling Toshiba Bluetooth
[27984.425895] [drm] Wrong MCH_SSKPD value: 0x16040307
[27984.425895] [drm] This can cause pipe underruns and display issues.
[27984.425895] [drm] Please upgrade your BIOS to fix this.
[27984.722410] ata4: SATA link down (SStatus 0 SControl 300)
[27984.724371] ata1: SATA link up 3.0 Gbps (SStatus 123 SControl 300)
[27984.724764] ACPI Error: [GTF0] Namespace lookup failure, AE_NOT_FOUND (20130517/psargs-359)
[27984.724777] ACPI Error: Method parse/execution failed [\_SB_.PCI0.SAT0.PRT0._SDD] (Node ffff880437c91cd0), AE_NOT_FOUND (20130517/psparse-536)
[27984.724836] ACPI Error: [GTF0] Namespace lookup failure, AE_NOT_FOUND (20130517/psargs-359)
[27984.724864] ACPI Error: Method parse/execution failed [\_SB_.PCI0.SAT0.PRT0._GTF] (Node ffff880437c91cf8), AE_NOT_FOUND (20130517/psparse-536)
[27984.725245] ACPI Error: [GTF0] Namespace lookup failure, AE_NOT_FOUND (20130517/psargs-359)
[27984.725255] ACPI Error: Method parse/execution failed [\_SB_.PCI0.SAT0.PRT0._SDD] (Node ffff880437c91cd0), AE_NOT_FOUND (20130517/psparse-536)
[27984.725309] ACPI Error: [GTF0] Namespace lookup failure, AE_NOT_FOUND (20130517/psargs-359)
[27984.725318] ACPI Error: Method parse/execution failed [\_SB_.PCI0.SAT0.PRT0._GTF] (Node ffff880437c91cf8), AE_NOT_FOUND (20130517/psparse-536)
[27984.725386] ata1.00: configured for UDMA/100
[27984.725474] sd 0:0:0:0: [sda] Starting disk
[27984.726351] ata3: SATA link up 1.5 Gbps (SStatus 113 SControl 300)
[27984.731495] ata3.00: configured for UDMA/100
[27984.904359] PM: resume of devices complete after 502.002 msecs
[27984.904677] PM: Finishing wakeup.
[27984.904679] Restarting tasks ... done.
[27984.906546] video LNXVIDEO:01: Restoring backlight state
[27985.851959] [drm] Enabling RC6 states: RC6 on, RC6p off, RC6pp off
[27986.207485] e1000e: enp0s25 NIC Link is Up 100 Mbps Full Duplex, Flow Control: None
[27986.207493] e1000e 0000:00:19.0 enp0s25: 10/100 speed: disabling TSO





Monday, October 28, 2013

Kernel Summit 2013

I did a brief presentation of Coccinelle in a lightning talk on Friday. It was the first time I had Linus on the audience. :-) Slides here.

Photo on the Linux Kernel Summit 2013. I'm near Linus and Greg :-)*

:-)


*Photo by: Thorsten Leemhuis

Sunday, October 20, 2013

Fedora: Compile a single module directory for current running Kernel

Sometimes one may want to just compile a single module and use it without rebooting the machine. In my case I wanted to play with 8139cp/8139too modules inside a KVM virtual machine running Fedora.

There are two requirements:
1 - Kernel source code
2 - Kernel development package

The source code is where to do the changes, while the development package contains the headers that allow to compile Kernel modules with the right version magic.

There are some options for obtaining the Kernel source code, but here the Fedora way is listed. You could probably download the Kernel from http://kernel.org.

Install packages, prepare RPM buil tree, and "install" the source code(Fedora way):
[fedora] $ sudo yum install @"Development Tools" rpmdevtools yum-utils ncurses-devel
[fedora] $ rpmdev-setuptree
[fedora] $ yumdownloader --source kernel
[fedora] $ sudo yum-builddep kernel-<version>.src.rpm
[fedora] $ rpm -Uvh kernel-<version>.src.rpm
Prepare the source code for building:
[fedora] $ cd ~/rpmbuild/SPECS
[fedora] $ rpmbuild -bp --target=$(uname -m) kernel.spec

Install kernel-devel:
[fedora] $ sudo yum install kernel-devel

Build Realtek Ethernet modules:
[fedora] $ cd ~/rpmbuild/BUILD/kernel-<version>/linux-<version>
[fedora] $ make -C /lib/modules/`uname -r`/build M=`pwd`/drivers/net/ethernet/realtek modules

Remove original mudules, load new ones:
[fedora] $ sudo rmmod 8139cp
[fedora] $ sudo rmmod 8139too
[fedora] $ sudo insmod ~/rpmbuild/BUILD/kernel-<version>/linux-<version>/drivers/net/ethernet/realtek/8139cp.ko
[fedora] $ sudo insmod ~/rpmbuild/BUILD/kernel-<version>/linux-<version>/drivers/net/ethernet/realtek/8139too.ko

Nice resources:
 - Building a custom kernel

Saturday, August 24, 2013

What are the source code files associated to Kconfig symbol?

I needed a way to discover which Linux source code files are related to a Kconfig symbol. As there is at least one Kconfig symbol for each Linux device driver, how could I find out what files are part of a device driver based on a single, or a set, of Kconfig symbols? I made a Perl script for that. For example:

$ cd /src/linux/drivers/net/ethernet
$ Kconfig-files.pl ALX
atheros/alx/hw.h
atheros/alx/hw.c
atheros/alx/ethtool.c
atheros/alx/main.c
atheros/alx/alx.h
atheros/alx/reg.h

All source files associated to the ALX Kconfig symbol are listed. The script is at Github.

Wednesday, January 9, 2013

make localmodconfig

Always wanted easy way of creating good config for compiling your own Kernel? You should try make localmodconfig

Before running make localmodconfig connect everything you want to work on your custom Kernel like USB pen drives and webcamera. make localmodconfig probes for loaded modules and make a new CONFIG for you.

From: http://www.h-online.com/open/features/Good-and-quick-kernel-configuration-creation-1403046.html
Thanks to +Thorsten Leemhuis

Wednesday, October 17, 2012

%.*s - Weird printk or Format of the format string

See this patch: https://lkml.org/lkml/2012/8/21/46

The author suggests:

- p9_debug(P9_DEBUG_VFS, "%s -> %s (%s)\n",
- dentry->d_name.name, st->extension, buffer);
+ p9_debug(P9_DEBUG_VFS, "%s -> %s (%.*s)\n",
+ dentry->d_name.name, st->extension, buflen, buffer);

But what the heck does %.*s? And why buflen variable was added as parameter to p9_debug? What would be the output of the C program above:

#include <stdio.h>

void main () {
        int i;
        char *ab ="abcdefghi";

        for (i = 0; i < 10; i++)
                printf ("%.*s\n", i, ab);
}

[peter@ace tmp]$ gcc test.c;./a.out

a
ab
abc
abcd
abcde
abcdef
abcdefg
abcdefgh
abcdefghi

Cool huh?