Perl: Setting locale failed

If you are developer or doing anything via ssh on Linux you probably are familiar with warning

It was very annoying to me so I looked for fix. Solution is pretty simple.

Edit /etc/ssh/ssh_config as su and edit / modify

with

That fixed it for me, hope someone helps too 🙂

How to download faster from Chinese Baidu cloud service (Linux)

I was struggling more than few times trying to download (especially big) files from Chinese BaiduYun cloud servers. Download is usually very slow, breaks alot of times and can’t be resumed.

While ago I figured how to download from Baidu without pain, praying and with excellent speed 🙂

I’m writing this tutorial as Linux user but download utility used (aria2) is available for other operating systems as well.

So, here’s what you need:

  • Google Chrome web browser
  • BaiduExporter extension for Chrome which you can get from Chrome Web Store
  • aria2 download utility (Debian based distros usually have it in official repositories as aria2 package)

Step 0: Install BaiduExporter in your Chrome

Step 1: Open shared link from which you want to download

panbaidu-step1

Step 2: When page is fully loaded (this can take some time), select files you want to download and put your pointer over button which says 导出下载. Picture of button: panbaidu-button

When mouse is over that button, menu should pop up as shown on picture below:

panbaidu-step2

Step 3: Click on middle item in menu that showed. After some time links to selected files will be shown in popup window as can be seen on picture below:

panbaidu-step3

Step 4:

  • Copy and paste these links somewhere (you will need them if download gets interrupted to resume download)
  • Open terminal window and navigate to folder where you want to download selected files
  • Each line starts with aria2c and whole line is basically your download command. So, take one line, copy it and paste it in your terminal window, press enter and download should start.

Note: You are not limited by instances of aria2 clients running and number of files you are downloading at same time (as far as I tested). Your limitation is your Internet speed. I managed to successfully download 5x4Gb files with aprox. speed of 10MB/s for each file on high bandwidth Internet connection.

I hope this will be helpful to someone 🙂

Kernel for few Amlogic MX devices

Since I was asked multiple times about kernels for some devices I worked on I found some time and went trough archives.

Kernel (Android one) is located on my GitHub account – kernel-amlogic-mx.

Boards covered by this kernel:

  • Prestigio PMP5670C (meson6_pmp5670c_defconfig) with panel configuration and touchscreen driver
  • VissonTech ATV-102S/ATV-106/Tronsmart Prometheus (meson6_g18_atv102s_defconfig)
  • Zoomtak T6 (meson6_g18_dbxm6_defconfig) – does not include VFD driver
  • Shiningworth MX, Gbox Midnight MX2 and most of its clones (meson6_g18_dbxmx_defconfig)

As I said, this is Android kernel based on 2014-04-28 SDK. To compile it, you need rest of SDK (JellyBean 4.2.2) which can be found on Internet.

For kernel building only, you will need ARM Linaro toolchain from Amlogic download site and modules (Wifi, nand, Mali) which hopefully still can be found on another Amlogic download site. Keep in mind that Mali driver used in your kernel must match version of Mali binaries in userspace otherwise it won’t work.

Amlogic released new Linux SDK

Yes, it happened! On 4th of May, Amlogic released their new Linux SDK which includes Kernel 3.14.29 (I’ll talk about it later), Buildroot 2016.02, U-Boot and kernel drivers for their 64bit STB and TV SoCs.

All mentioned can be found on their GPL download site.

What is new in that Linux SDK you might ask… well, nothing special. Just few new driver implementations for CEC, eMMC/NAND, lightly modified WiFi drivers code, commits to kernel tree (which was originally forked from Linaro 3.14 which can be seen from kernel sources available eg. on Hardkernel’s Odroid C2 GitHub), few new reference boards introduced and more bugs!

It is amazing how these things happen. Current GPL release of Amlogic kernel is as is. GPL releases are released as tarballs (no way you will get full git history).

I will be whining for one old issue Amlogic does have on all of it’s platforms and on all released (GPL and non-GPL) and one I struggled with today for 2-3 hours until I figured out why simple Linux tar command is crashing and not doing it’s job (Error in ‘tar’: double free or corruption) when passing simple arguments to it like:

That simple command worked perfectly on all kernels they released before latest one (tested on same Buildroot version and with same tar sources). That latest kernel is mixture of everything. There are some normal AOSP 3.14 patches and there are some backports (Amlogic engineering way) from (get this!) 4.3 kernel.

Now, normal way of debugging this error would be…. Do I have everything enabled in my configuration files (Buildroot 2016.02 and their GPL Kernel) so my tar command can read SELinux contexts, POSIX ACLs and extended attributes? After I double checked my configuration I started rebuilding whole system because well, maybe something went wrong. 2nd try… Same error.

Ok, I forgot to enable GDB but I can build it without rebuilding whole system so I did that. Running same tar with it’s attributes from debugger gives me hint. Kernel kills tar without much useful information.
Thinking about it for 5 minutes or so I remembered that in git history from non-gpl released kernel there are changes to security subsystem (SELinux to be exact).

Figuring that if I already spent that much time trying to fix issue I have, I’ll spend additional 15-20 minutes rebuilding kernel with SELinux completely disabled. And guess what…. It worked! Wtf?!

Ok, so that was it. Cleaning Buildroot configuration, modifying Kernel config not to build security subsystem, rebuilding whole thing and that issue can be closed (for now).

Second issue I mentioned earlier is really disappointing. Amlogic M8 series (S802, S805 and S812) and GXBaby (S905) in Android (I did not check older platforms like MX but I am pretty sure it is same) do have issue with online SD quality streams that are using adaptive bitrate (via application developed for world wide operator).

Not only that I reported that issue to one of Amlogic engineers but also to person who (is or was? Not sure there because he seems to ignore me for some time now) my contact in Amlogic multiple times, I offered them everything they need (VPN account, account to service provider that is providing that OTT service…) and…. I got one big NOTHING. Not even reply telling me that they are not interested in fixing that particular issue or that they just don’t care about it (it’s about manners Amlogic guys!).

I think it’s enough whining for today so I will write something I find very positive.

Guys behind site linux-meson.com are doing their best to bring Amlogic SoC support to mainline Kernel and U-Boot. More about it you can check on their site.

If there any comments or questions maybe, I will actually reply to them 🙂

Stane1983

Moved and updated site

This site has not been update for a long time. And it was offline for longer period of time.

I restored few topics for which I think are relevant and helpful when it comes to Amlogic platform. I will continue to write some new informations, problems, complaints to development…

And yes, you can expect something new and little different on this site in very near future 🙂

Cheers,
Stane1983

Burning .IMG file to Amlogic M8 devices using sdcard

Recently I had situation where I had to write firmware to S805 device that had no USB OTG port which means using USB Burning Tool is not an option.

Since I saw in Amlogic SDKs and U-Boot sources that there is a way to burn USB Burning Tool image file using sdcard (first clue was aml_sdc_burn.ini file that exists in almost all reference board device trees in Amlogic Android SDK) I decided to ask Amlogic for official documentation that explains how it works technically, what are possible values for certain options etc (because digging trough code is not quickest option to see how it works). After 2 mails and none of them with useful information, I decided to do my own research.
Basically it works almost the same way as burning image using USB Burning Tool.

Technical description:

When you put aml_sdc_burn.ini and let’s say (default name) aml_upgrade_package.img to your sdcard and you power on your device using reset button (note: on some S805 devices there is no reset button; option if implemented by manufacturer would be using your IR remote with pressed correct button when powering on your device).
During that process U-Boot finds aml_sdc_burn.ini file on your sdcard and tries to do following:

  • Temporary set internal flag that makes sdcard first bootable device
  • Resets device and tries to load U-Boot from sdcard (I will go back to this part later)
  • If successful, bootloader is loaded from sdcard and executed (instead of one stored on NAND/eMMC or SPI chip)
  • When bootloader is started, USB (well, SDC) burning mode is activated and based on values in aml_sdc_burn.ini file IMG is burned to your device

Now, if you read carefully, you might notice that sdcard with only .ini and .img file will not result in anything but rebooting your device to existing OS. That’s because I didn’t prepare my sdcard to be bootable (or recovery sdcard).

If you are running Linux, I described how to create recovery sdcard in post How to create Amlogic recovery SD card from Linux.

If you’re on Windows machine, under Downloads -> Amlogic tools you have tool called BootCardMaker which will help you to create bootable sdcard. Just start BootCardMaker as Administrator (if you are running Windows newer than XP), select your sdcard drive letter, mark that you want to format your card, select your U-Boot (must be for your device!), click on button MAKE and follow instructions.

If either on Windows or Linux, after preparing your bootable sdcard, copy your .img and .ini file to it, safely remove sdcard from your computer and you are ready for procedure described above. During burn process you will have green droid on your screen with moving progress bar. Very important is that YOU DO NOT DISCONNECT YOUR DEVICE FROM POWER DURING PROCESS.

Information about aml_sdc_burn.ini file format

This is default example of file:

As you can see, file contains 2 sections – common and burn_ex.

Let’s focus on common section and it’s parameters:

erase_bootloader – This parameter can contain 2 values (0 and 1). 0 will not erase your bootloader while 1 will.

erase_flash – This parameter contains 5 valid values (0 – 4) and here is what it means:

0 – Do not erase flash
1 – Normal erase (same as in USB Burning Tool)
2 – Information not available, will update post when I find out meaning of value 2
3 – Erase all (erase NAND/eMMC content and bootloader which exists in protected area)
4 – Force erase all (this option unprotects all protected areas of NAND/eMMC/SPI, raw formats everything and reparitions storage)

reboot – This parameter can contain 2 values (0 and 1). 1 will reboot your device after process is finished while 0 will not 🙂

Now burn_ex section:

package – full file name of .IMG file that exists on sdcard to be burned

media – in this example, media parameter is commented. I did not find much info about that parameter, but it seems that it should point to raw partition image of media partition. Little confusing eh. For this parameter to be enabled and work as it should, bootloader needs to be prepared for extra media partition which is not enabled by default.

Final words

Ok, I hope that I helped someone with this.

Please be noted that all that is written above you are doing at your own risk. I do not take any responsibility for broken/bricked devices etc…

How to create Amlogic recovery SD card from Linux

Amlogic recovery SD card is used when device is bricked, when bootloader does not exist on boot device (SPI chip or NAND) or it is corrupted.

Linux (any distribution) is most convenient OS for creating that kind of card. Basically, card is created that way that first 3 cylinders on card are reserved for bootloader. FAT32 partition follows (starts on sector 3 to the end of sdcard).

Let’s say we want to create recovery card for MX board. MX uses u-boot.img as bootloader name. We will asume that our device is bricked and needs complete firmware reinstall.
So, we need: u-boot.img for that device and rest of firmware (update.zip and recovery.img which is recovery kernel + tools, usually Android recovery system).

We will asume this:
Our sdcard is: /dev/sdb
First partition: /dev/sdb1
Mountpoint for sdcard: /home/stane/recoverysd

First we will unmount our sdcard if it is mounted

Next we will raw copy u-boot.img from our current folder to sdcard (not partition!)

Now we have to delete all existing partitions on sdcard and create only one that will start from 3rd cylinder. Most newer Linux distros uses also newer version of fdisk utility which consider cylinders for display/entry unit as deprecated, so before any action you have to enable it by issuing “u” in fdisk and pressing enter key.

So, lets start with fdisk. We will start it with following command:

in fdisk, as I said earlier we will first issue u command and hit enter which will result with message: Changing display/entry units to cylinders (DEPRECATED!)
Just ignore it and contine.

Next step is to delete all existing partitions from our sdcard. Hit d command and after that hit p command to see current partition status on your sdcard.
Repeat this step until all partitions are deleted.

After issuing p output should look like this:

with no partitions listed.
When we cleared our partition layout, its time to create new one.

To do that, issue n command and create primary partition (by selecting p option on next menu).
When fdisk asks for partition number, leave empty (1st is by default) and continue.
Now comes our cylinder part. Fdisk will ask you for First cylinder. Put there 3 and continue.
Next, it will ask for last cylinder. Leave default value (just press enter).

Ok, partition is created, but its raw for now. We have to assign filesystem to it (which will be FAT32). So, issue t command and after that b command (b is code for FAT32 partition type).

When done, with these steps, issue w command which will write changes to sdcard and will exit fdisk.

Ok, now we have to format our newly created partition which we will do with issuing command:

When partition is formatted, you have two options. Either you will re-insert your card to cardreader, or you will mount it manually to folder from which we unmounted it.

If you choose second option, issue command as follows:

When mounted, copy all your firmware files to sdcard and properly unmount it and eject from your cardreader. You can unmount it within your Linux distro file manager or with command:

Now your recovery sdcard is ready to use.

When you finished with recovery of your box, you’ll probably want to back your card to normal (because using it in another box, might brick it).

We are going to do that by raw copying few kilobytes of zeros to start of sdcard (after we unmounted it) with following command:

After procedure is finished, start fdisk as before (which will warn you that your drive/card is corrupted) and just issue w command. Fdisk will write changes to sdcard and exit.

After that, start fdisk again and create your new partition (none exists anymore) as you did before, just use default values. After that, format the file system on your sdcard and thats it.

Hope it helped someone 🙂