Rockbox Development > Starting Development and Compiling

Ingenic MIPS GCC 7.2.0 Toolchain to compile m3k native port

<< < (3/5) > >>

ede:

--- Quote from: vitt13 on November 30, 2021, 03:39:51 PM ---I tried to use Ingenic MIPS GCC 5.2.0 Toolchain but I gave up with non resolved many of "relocation truncated to fit: R_MIPS_GOT16 against ..." errors. It looked like bunutils problem.
Then I searched anything newer and found Ingenic MIPS Toolchain on FTP.
Direct link: ftp://ftp.ingenic.cn/Ingenic-MIPS-Toolchain/releases/ingenic-mips-toolchain-r5.0.4/
latest has date stump Oct 13, 2021
Mirror https://www.mediafire.com/folder/7x0zksrlh8d3r/Ingenic_MIPS_Toolchain
So I tried to use Ingenic MIPS GCC 7.2.0 Toolchain (mips-linux-gnu-ingenic-gcc7.2.0-glibc2.29-fp32-r5.0.4.tar.bz2) to compile m3k native port. It supports "-march=xburst" flag BTW
I had few problems with compiling but all has been resolved.
First is changing to OUTPUT_FORMAT("elf32-tradlittlemips") in *.lds or removing that string at all.inshot para pc gratis

Second is LD from that GCC 7.2.0 does not accept inlined function in header. It leads to errors at linking stage.
Third is again "relocation truncated to fit: R_MIPS_GOT16 against ..." caused by "-lgcc" flags in app/plugins/plugins.make and libs/rbcodec/codecs/codecs.make
some codecs build failed so I just changed "-lgcc" in link command to
mips-linux-gnu-ingenic-gcc7.2.0/lib/gcc/mips-linux-gnu/7.2.0/libgcc.a (for two particular compiling failed situation)
and
mips-linux-gnu-ingenic-gcc7.2.0/lib/gcc/mips-linux-gnu/7.2.0/soft-float/libgcc.a (for other files)
for added $(LDGCC720)


--- Code: ---diff -ruN rockbox/apps/plugins/plugin.lds rockbox_/apps/plugins/plugin.lds
--- rockbox/apps/plugins/plugin.lds 2021-11-30 23:15:20.509125218 +0300
+++ rockbox_/apps/plugins/plugin.lds 2021-11-30 20:54:27.453792365 +0300
@@ -7,7 +7,7 @@
 #elif defined(CPU_ARM)
 OUTPUT_FORMAT(elf32-littlearm)
 #elif defined(CPU_MIPS)
-OUTPUT_FORMAT(elf32-littlemips)
+//OUTPUT_FORMAT("elf32-tradlittlemips")
 #else
 /* We can have an #error here we don't use this file when build sims! */
 #error Unknown CPU architecture
--- End code ---


--- Code: ---diff -ruN rockbox/apps/plugins/plugins.make rockbox_/apps/plugins/plugins.make
--- rockbox/apps/plugins/plugins.make 2021-11-30 23:15:20.509125218 +0300
+++ rockbox_/apps/plugins/plugins.make 2021-11-30 22:22:04.738824749 +0300
@@ -151,7 +151,7 @@
  $(call PRINTS,LD $(@F))$(CC) $(PLUGINFLAGS) -o $(BUILDDIR)/$*.elf \
  $(filter %.o, $^) \
  $(filter %.a, $+) \
- -lgcc $(PLUGINLDFLAGS)
+ $(LDGCC720) $(PLUGINLDFLAGS)
  $(SILENT)$(call objcopy,$(BUILDDIR)/$*.elf,$@)
 
 $(BUILDDIR)/apps/plugins/%.lua: $(ROOTDIR)/apps/plugins/%.lua
@@ -161,4 +161,4 @@
  $(call PRINTS,LD $(@F))$(CC) $(PLUGINFLAGS) -o /dev/null \
  $(filter %.o, $^) \
  $(filter %.a, $+) \
- -lgcc $(OVERLAYLDFLAGS)
+ $(LDGCC720) $(OVERLAYLDFLAGS)

--- End code ---


--- Code: ---diff -ruN rockbox/lib/rbcodec/codecs/codecs.make rockbox_/lib/rbcodec/codecs/codecs.make
--- rockbox/lib/rbcodec/codecs/codecs.make 2021-11-30 23:15:21.861145243 +0300
+++ rockbox_/lib/rbcodec/codecs/codecs.make 2021-11-30 21:57:13.469772087 +0300
@@ -212,11 +212,11 @@
  $(call PRINTS,LD $(@F))$(CC) $(CODECFLAGS) -o $(CODECDIR)/$*-pre.elf \
  $(filter %.o, $^) \
  $(filter-out $(CODECLIB),$(filter %.a, $+)) $(CODECLIB) \
- -lgcc $(subst .map,-pre.map,$(CODECLDFLAGS))
+ $(LDGCC720) $(subst .map,-pre.map,$(CODECLDFLAGS))
 
 $(CODECDIR)/%.codec: $(CODECDIR)/%.o
  $(call PRINTS,LD $(@F))$(CC) $(CODECFLAGS) -o $(CODECDIR)/$*.elf \
  $(filter %.o, $^) \
  $(filter %.a, $+) \
- -lgcc $(CODECLDFLAGS)
+ $(LDGCC720) $(CODECLDFLAGS)
  $(SILENT)$(call objcopy,$(CODECDIR)/$*.elf,$@)

--- End code ---

that nasty hack, I shamed

--- Code: ---diff -ruN rockbox/apps/debug_menu.c rockbox_/apps/debug_menu.c
--- rockbox/apps/debug_menu.c 2021-11-30 23:15:20.099119145 +0300
+++ rockbox_/apps/debug_menu.c 2021-11-29 22:48:18.561253304 +0300
@@ -188,7 +188,7 @@
     return simplelist_show_list(&info);
 }
 
-#ifdef __linux__
+#ifdef __linux__1
 #include "cpuinfo-linux.h"
 
 #define MAX_STATES 16
@@ -2588,7 +2588,7 @@
         { "Catch mem accesses", dbg_set_memory_guard },
 #endif
         { "View OS stacks", dbg_os },
-#ifdef __linux__
+#ifdef __linux__1
         { "View CPU stats", dbg_cpuinfo },
 #endif
 #if (CONFIG_BATTERY_MEASURE != 0) && !defined(SIMULATOR)
--- End code ---


--- Code: ---diff -ruN rockbox/firmware/drivers/i2c-async.c rockbox_/firmware/drivers/i2c-async.c
--- rockbox/firmware/drivers/i2c-async.c 2021-11-30 23:15:21.026132875 +0300
+++ rockbox_/firmware/drivers/i2c-async.c 2021-11-30 20:01:46.994213172 +0300
@@ -396,3 +396,30 @@
 
     return desc[1].arg;
 }
+
+int i2c_reg_write1(int bus, uint8_t addr, uint8_t reg, uint8_t val)
+{
+    return i2c_reg_write(bus, addr, reg, 1, &val);
+}
+
+int i2c_reg_read1(int bus, uint8_t addr, uint8_t reg)
+{
+    uint8_t v;
+    int i = i2c_reg_read(bus, addr, reg, 1, &v);
+    if(i == I2C_STATUS_OK)
+        return v;
+    else
+        return -1;
+}
+
+int i2c_reg_setbit1(int bus, uint8_t addr, uint8_t reg,
+                           int bit, int value, uint8_t* val)
+{
+    uint8_t clr = 0, set = 0;
+    if(value)
+        set = 1 << bit;
+    else
+        clr = 1 << bit;
+
+    return i2c_reg_modify1(bus, addr, reg, clr, set, val);
+}

--- End code ---


--- Code: ---diff -ruN rockbox/firmware/export/i2c-async.h rockbox_/firmware/export/i2c-async.h
--- rockbox/firmware/export/i2c-async.h 2021-11-30 23:15:21.085133749 +0300
+++ rockbox_/firmware/export/i2c-async.h 2021-11-30 20:01:37.124067627 +0300
@@ -247,35 +247,15 @@
                            uint8_t clr, uint8_t set, uint8_t* val);
 
 /* Variant to write a single 8-bit value to a register */
-inline int i2c_reg_write1(int bus, uint8_t addr, uint8_t reg, uint8_t val)
-{
-    return i2c_reg_write(bus, addr, reg, 1, &val);
-}
+extern int i2c_reg_write1(int bus, uint8_t addr, uint8_t reg, uint8_t val);
 
 /* Variant to read an 8-bit value from a register; returns the value
  * directly, or returns -1 on any error. */
-inline int i2c_reg_read1(int bus, uint8_t addr, uint8_t reg)
-{
-    uint8_t v;
-    int i = i2c_reg_read(bus, addr, reg, 1, &v);
-    if(i == I2C_STATUS_OK)
-        return v;
-    else
-        return -1;
-}
+extern int i2c_reg_read1(int bus, uint8_t addr, uint8_t reg);
 
 /* Variant to set or clear one bit in an 8-bit register */
-inline int i2c_reg_setbit1(int bus, uint8_t addr, uint8_t reg,
-                           int bit, int value, uint8_t* val)
-{
-    uint8_t clr = 0, set = 0;
-    if(value)
-        set = 1 << bit;
-    else
-        clr = 1 << bit;
-
-    return i2c_reg_modify1(bus, addr, reg, clr, set, val);
-}
+extern int i2c_reg_setbit1(int bus, uint8_t addr, uint8_t reg,
+                           int bit, int value, uint8_t* val);
 
 /* Internal API */
 

--- End code ---


--- Code: ---diff -ruN rockbox/firmware/target/mips/ingenic_x1000/app.lds rockbox_/firmware/target/mips/ingenic_x1000/app.lds
--- rockbox/firmware/target/mips/ingenic_x1000/app.lds 2021-11-30 23:15:21.417138667 +0300
+++ rockbox_/firmware/target/mips/ingenic_x1000/app.lds 2021-11-30 20:38:02.948403179 +0300
@@ -1,7 +1,7 @@
 #include "config.h"
 #include "cpu.h"
 
-OUTPUT_FORMAT("elf32-littlemips")
+//OUTPUT_FORMAT("elf32-tradlittlemips")
 OUTPUT_ARCH(MIPS)
 ENTRY(_start)
 STARTUP(target/mips/ingenic_x1000/crt0.o)

--- End code ---


--- Code: ---diff -ruN rockbox/firmware/target/mips/ingenic_x1000/clk-x1000.c rockbox_/firmware/target/mips/ingenic_x1000/clk-x1000.c
--- rockbox/firmware/target/mips/ingenic_x1000/clk-x1000.c 2021-11-30 23:15:21.418138682 +0300
+++ rockbox_/firmware/target/mips/ingenic_x1000/clk-x1000.c 2021-11-30 19:37:40.740889896 +0300
@@ -340,6 +340,17 @@
     jz_writef(CPM_CCR, CE_CPU(0), CE_AHB0(0), CE_AHB2(0));
 }
 
+uint32_t clk_calc_div(uint32_t infreq, uint32_t outfreq)
+{
+    return (infreq + (outfreq - 1)) / outfreq;
+}
+
+uint32_t clk_calc_shift(uint32_t infreq, uint32_t outfreq)
+{
+    uint32_t div = clk_calc_div(infreq, outfreq);
+    return __builtin_clz(div) ^ 31;
+}
+
 void clk_set_ddr(x1000_clk_t src, uint32_t div)
 {
     /* Write new configuration */

--- End code ---


--- Code: ---diff -ruN rockbox/firmware/target/mips/ingenic_x1000/clk-x1000.h rockbox_/firmware/target/mips/ingenic_x1000/clk-x1000.h
--- rockbox/firmware/target/mips/ingenic_x1000/clk-x1000.h 2021-11-30 23:15:21.418138682 +0300
+++ rockbox_/firmware/target/mips/ingenic_x1000/clk-x1000.h 2021-11-30 19:38:01.519196158 +0300
@@ -80,16 +80,9 @@
 extern void clk_set_ddr(x1000_clk_t src, uint32_t div);
 
 /* Returns the smallest n such that infreq/n <= outfreq */
-inline uint32_t clk_calc_div(uint32_t infreq, uint32_t outfreq)
-{
-    return (infreq + (outfreq - 1)) / outfreq;
-}
+extern uint32_t clk_calc_div(uint32_t infreq, uint32_t outfreq);
 
 /* Returns the smallest n such that (infreq >> n) <= outfreq */
-inline uint32_t clk_calc_shift(uint32_t infreq, uint32_t outfreq)
-{
-    uint32_t div = clk_calc_div(infreq, outfreq);
-    return __builtin_clz(div) ^ 31;
-}
+extern uint32_t clk_calc_shift(uint32_t infreq, uint32_t outfreq);
 
 #endif /* __CLK_X1000_H__ */

--- End code ---


--- Code: ---diff -ruN rockbox/firmware/target/mips/ingenic_x1000/spl.lds rockbox_/firmware/target/mips/ingenic_x1000/spl.lds
--- rockbox/firmware/target/mips/ingenic_x1000/spl.lds 2021-11-30 23:15:21.424138771 +0300
+++ rockbox_/firmware/target/mips/ingenic_x1000/spl.lds 2021-11-30 20:38:26.213745184 +0300
@@ -1,7 +1,7 @@
 #include "config.h"
 #include "cpu.h"
 
-OUTPUT_FORMAT("elf32-littlemips")
+//OUTPUT_FORMAT("elf32-tradlittlemips")
 OUTPUT_ARCH(MIPS)
 ENTRY(_spl_start)
 STARTUP(target/mips/ingenic_x1000/spl-start.o)

--- End code ---

--- End quote ---

Hi

You can reconfigurate kernel with:


zcat /proc/config.gz > .config

korvin:

--- Quote from: vitt13 on December 15, 2021, 01:56:44 AM ---Also found this linker script from jz4730 sources with similar "trick" for small data.
-....

--- End quote ---
:) As first step -> I have successefully build rockbox with standart GCC 4.9.4 and Binutils 2.26.1...
But also I'd like to build with new mips-linux-gnu-ingenic-gcc7.2.0-glibc2.29-fp32-r5.1.3 toolchain... with xburst march and latest optimizations suppport.

any good news?

Perhaps the new optimizations will help to load/utilize cpu/chip more effectively with less battery drain and generally make the ui more responsive. Anyway is a good idea to build it with latest toolchain  :) :) :)

vitt13:

--- Quote from: korvin on June 28, 2022, 11:48:20 AM ---But also I'd like to build with new mips-linux-gnu-ingenic-gcc7.2.0-glibc2.29-fp32-r5.1.3 toolchain... with xburst march and latest optimizations suppport.
...
Perhaps the new optimizations will help to load/utilize cpu/chip more effectively with less battery drain and generally make the ui more responsive. Anyway is a good idea to build it with latest toolchain  :) :) :)

--- End quote ---
I confirm that the toolchain mips-linux-gnu-ingenic-gcc7.2.0-glibc2.29-fp32-r5.0.4 does not automatically generate code with specific xburst SIMD instructions and optimizations. You need to change source code of codecs and decoders with using specific SIMD assembly instructions (MXU).
I reffer to this  https://www.rockbox.org/wiki/IngenicJz47xx , "Ingenic Media Extension Instruction Set" and "MXU User Guide" ftp://ftp.ingenic.com/SOC/X1000/X1000_M200_MXU-User-Guide.pdf

amachronic:

--- Quote from: korvin on June 28, 2022, 11:48:20 AM ---[...] Anyway is a good idea to build it with latest toolchain  :) :) :)

--- End quote ---
Using the latest GCC won't make things appreciably faster or more responsive. You could expect a few percent performance improvement, at most, which at best will translate to a few percent better battery life. Poor UI performance is likely due to slow I/O or slow algorithms, and a newer compiler won't fix either of those problems. The only case I can think of where shaving a few percent off CPU time might make a difference is heavy EQ use at high sample rates (above 96 KHz).

Upgrading the compiler may also break things -- newer compilers are far more aggressive at taking advantage of undefined behavior (UB), and Rockbox is a pretty old codebase with a lot of low-level code prone to UB.

And while MXU might provide better battery life with CPU-heavy codecs, it would be a difficult undertaking to write and maintain MXU-optimized decoder or DSP routines. But if you want to try, go right ahead! I'm just pointing out it's not simple or easy, and IMHO the effort would be better spent on other things.

korvin:

--- Quote from: vitt13 on June 28, 2022, 02:26:39 PM ---
I confirm that the toolchain mips-linux-gnu-ingenic-gcc7.2.0-glibc2.29-fp32-r5.0.4 does not automatically generate code with specific xburst SIMD instructions and optimizations. You need to change source code of codecs and decoders with using specific SIMD assembly instructions (MXU).
I reffer to this  .....

--- End quote ---



--- Quote from: amachronic on June 29, 2022, 02:11:33 PM ---
Using the latest GCC won't make things appreciably faster or more responsive. You could expect a few percent performance improvement, at most, which at best will translate to a few percent better battery life. Poor UI performance is likely due to slow I/O or slow algorithms, and a newer compiler won't fix either of those problems. The only case I can think of where shaving a few percent off CPU time might make a difference is heavy EQ use at high sample rates (above 96 KHz).

Upgrading the compiler may also break things -- newer compilers are far more aggressive at taking advantage .....

--- End quote ---

Thank you guys for the fast, detailed and qualifying professional response. For sure I understand that there are no magic ways that would fundamentally change compiled binaries, with a big difference in speed, etc. But even with 1-2% I would have been really pleased, in addition, nobody cancelled the spirit of experimentation  :) In addition, I want to thank you for the great work you've already done and emphasize that also other people remain interested in this thread. Unfortunately not everyone has the necessary experience with c/c++, Linux, gcc compilers, etc., I, for example, come from the world of java and typescript/nodejs  and would be grateful for any future help/information reg. compiling it with new toolchain gcc 7.2.0. I am using right now VirtualBox and self installed Ubuntu 18.0.4 OS and compiled binaries 1 to 1 matches official daily builds, so I am I'm glad I did it in a right way. My next goal is to make it work with new Ingenic Toolchain based on GCC 7.2.0. Well, there are a few ideas to improve the functionality of the firmware itself, I use it mainly for audiobooks (but that's a separate thread).

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version