Rockbox Technical Forums

Rockbox Development => Starting Development and Compiling => Topic started by: ajgisme on May 02, 2007, 04:57:04 PM

Title: Patching Rockbox
Post by: ajgisme on May 02, 2007, 04:57:04 PM
I had just managed to compile the source code thingy, and i wanted to put a patch on it when i put in the code it said it couldn't patch it something about HUNK at line 8 or something!
1.) Please can someone help, i really want to put the patches on rockbox!!!!
2.) And also, with the source code, i know you can edit the menus, but how?
Because when i go to the menu it comes up with all these random letters!
Title: Re: Patching Rockbox
Post by: 007quick on May 02, 2007, 07:15:16 PM
I can only answer the first question. When Hunks fail, it means that the patch is out of sync. It will save a .rej file which will show you what the patch is supposed to do. Sometimes it is easy to add in the rejects, but other times you will have to ask the maker of the patch for a sync.
Title: Re: Patching Rockbox
Post by: ajgisme on May 03, 2007, 02:32:54 AM
what do you mean add in the rejects?
Title: Re: Patching Rockbox
Post by: 007quick on May 03, 2007, 10:31:25 AM
I think that you need to understand some concepts first.  The source code, is just a whole lot of c type files.  Patches, modify the c code.  When the developers commit stuff to svn, the source code changes.  The patch program is often not smart enough to find where it is supposed to replace the code.  If this happens, it will say, Hunk #1, etc failed. Saving rejejts to ....
You will need to look at the .rej file which will have lines with (-) and (+) the lines with the - need to be taken out of the appropriate file, while the lines with the + need to be added. Really, it is a matter of trying.
If you try to add in the rej, but it won't compile correctly.
Type,
Code: [Select]
svn revert -R *And if you want to get rid of all the leftover files that shouldn't be there. Run this command, knowing that it will get rid of your patch! So back it up
Code: [Select]
svn st | grep "^?" | cut "-d " -f7 | xargs rm -f -RDo those commands from the root of your rockbox source.
Hope this helps!
Title: Re: Patching Rockbox
Post by: Rincewind on May 03, 2007, 11:10:11 AM
to get an understanding how patches work, you can try this:

open the patch file in an editor (good editors do syntax highlighting on patches).
Every Hunk has a header which says which file is changed and at what line the change should happen. Next come a few lines of source code, some of them with "+" and "-" in front of them. These lines tell the patch file what to do - remove lines with "-", add lines with "+".
I would suggest to open the patch file and the corresponding source file side by side, try to figure out what it does, then apply the patch and look again.
If the Hunk failed only because of a small error you can fix it yourself without knowing much about programming. If you have a good editor with syntax highlighting, then you can sometimes see from the colors when something won't work.
Title: Re: Patching Rockbox
Post by: Nate! on May 03, 2007, 12:22:19 PM
Rincewind: First, I do not know C.  But, I'm looking at the scroll-margins patch.  I apply the patch and it fails  when making changes to onplay.c.  Do I contrast the rej file to the onplay.c.orig or to the onplay.c file?  I'm thinking the onplay.c.orig is the file before the patch was applied.  Maybe I need to contrast all the files: onplay.c, onplay.c.orig, onplay.c.rej, and the patch file.

*** Edit ***
Looking at both the onplay.c and onplay.c.orig there's an ifdef statement:
Quote
#ifdef HAVE_LCD_BITMAP
 Â       FOR_NB_SCREENS(i)
 Â           screens.update();
#endif
In the patch there's this:
Quote
#ifdef HAVE_LCD_BITMAP
 Â        if (global_settings.statusbar)
-            lcd_setmargins(0, STATUSBAR_HEIGHT);
+            lcd_setmargins(0, LCD_WIDTH, STATUSBAR_HEIGHT);
 Â        else
-            lcd_setmargins(0, 0);
+            lcd_setmargins(0, LCD_WIDTH, 0);
 #endif
 Â    }
In the rej file there's:
Quote
 #ifdef HAVE_LCD_BITMAP
 Â         if (global_settings.statusbar)
+             lcd_setmargins(0, LCD_WIDTH, STATUSBAR_HEIGHT);
 Â         else
+             lcd_setmargins(0, LCD_WIDTH, 0);
 Â #endif

It seems that an endif is missing. (if (global_settings.statusbar), else, missing endif?  If this is the case, where do I put the if, else, endif statement?  Before the
Quote
FOR_NB_SCREENS(i)
or after?  Or am I completely off?
*** End Edit ***

This is good stuff, thanks for breaking it down.
Title: Re: Patching Rockbox
Post by: Rincewind on May 03, 2007, 04:06:41 PM
No, there is not an endif missing. In more detail: the surrounding "#ifdef" and "#endif" is so called preprocessor code, which is executed during compiling. The inside "if" statement is the C code. In C there is no "end". Instead curly braces are used "{" "}". Because there is only one statement in the if-else block, lazy coders can leave the braces out.

anyway, since the patch changes onplay.c and this file was changed fundamentally lately (the menus were converted to the new menu API) it is likely that the error is not easily corrected in this case.

If the patch is still maintained, then a new version should be added to flyspray soon.
Title: Re: Patching Rockbox
Post by: bluebrother on May 03, 2007, 04:25:20 PM
Because there is only one statement in the if-else block, lazy coders can leave the braces out.
Which is also considered as good style ... or as bad style, depending on who you ask. C leaves some options to the developer, and some styles are agreed being good, others are agreed being bad but most style decisions depend on the developer / project style guidelines if they are considered good or bad.

So I disagree in calling that "lazy" :D (you can also put multiple statements on one line using the comma operator for example, but this is rarely used)
Title: Re: Patching Rockbox
Post by: Nate! on May 03, 2007, 06:13:10 PM
Thanks for the responses.  Oh well, thought I was on to something.  ::)