avafinger / nanopi-m4-ubuntu-base-minimal

Nanopi M4 RK3399 base minimal image for development (mali fbdev / gbm) - Camera support
53 stars 10 forks source link

Nanopi M4 RK3399 eMCC native image #12

Closed xaled1 closed 4 years ago

xaled1 commented 5 years ago

Hi,

I have a MicroSD to eMCC adapter and would like to burn ubuntu/kodi image directly to eMCC using etcher. Would it be possible to get the burn ready eMCC image?

Thanks in advance!

avafinger commented 5 years ago

I don't have the eMMC adapter. If you can use etcher to burn the FriendlyElec Image to eMMC then this is possible. You can write the img file provided but you have to change the order of the device mmc in /boot/boot.cmd and /etc/fstab before you boot or it will not find the rootfs and hang.

You need to change /dev/mmcblkXp1 on both files. the modified boot.cmd should be compiled with sudo mkimage -C none -A arm -T script -d boot.cmd boot.scr

You better have USB to TTL to see what is going on if fails somewhere. For the kernel 5.x is the opposite.

I will check the order when i get the board if you need it.

avafinger commented 5 years ago

Here are the parms you need for kernel 4.4:

/boot/boot.cmd setenv bootargs "earlyprintk root=/dev/mmcblk1p2 rw rootfstype=ext4 rootwait fsck.repair=${fsck.repair} panic=10 ${extra}"

/etc/fstab

# /dev/mmcblk0 => SD CARD
# /dev/mmcblk1 => eMMC CARD
/dev/mmcblk1p1  /boot   ext4    defaults            0       2
/dev/mmcblk1p2  /   ext4    defaults,noatime,nodiratime,commit=600,errors=remount-ro,x-gvfs-hide        0       1

For kernel 5.x

# /dev/mmcblk1 => SD CARD
# /dev/mmcblk0 => eMMC CARD

Unfortunately, if you are using windows you need to resort to a Linux to edit and change the files. Please, report your success.

xaled1 commented 5 years ago

Hi,

Thanks for helping!

do you mean this image:

Img (SD card 8GB) is available here: https://mega.nz/#!YLZhlYJb!uqvCIjpeBoGyfhaNYPJwb67kma7wmGTn5ZObe-CPrb4

avafinger commented 5 years ago

Yes.

Or you create your SD card (make all your adjustments), change the files as mentioned above and generates IMG to burn with etcher. To generate IMG you will need a Linux distro or VM.

xaled1 commented 5 years ago

I just installed the image to SD card and booted nano pi M4 with it.

Now to get to eMMC - should I run the Release v1.8 (OS Image for eMMC only) installation procedure from SDCard and go with the following updates on eMMC from there?

avafinger commented 5 years ago

Yes. Follow: https://github.com/avafinger/nanopi-m4-ubuntu-base-minimal#release-v18-os-image-for-emmc-only

But this does not use and need etcher

xaled1 commented 5 years ago

Yes I know that etcher will not be used in this case. I wanted to avoid the sdcard roundtrip, but it is apparently the simplest way.

Ok, got the debian installed on emcc, thanks!

now If I want to upgrade to 5.x experimental on emcc I will have to update boot.cmd and fstab in the sdcard images according to your instruction?

avafinger commented 5 years ago

Yes, once you install kernel 5.x you need to adjust boot.cmd and fstab, but please, note that 5.x does not have kodi, gpu, wifi, etc..

I would play with 5.x only with SD card if you are curious.

xaled1 commented 5 years ago

Ah, ok without Kodi it is not fun anymore. Thanks a lot for providing the images. Do you have a paypal? I would like to thank you for your work.

avafinger commented 5 years ago

I'm glad the IMG and the Tips are helpful to you. That's very kind of you. I do have a paypal but perhaps you have plans to extend your M4 board with a Camera or a HAT, why not consider buying a spare and share if you need help. Anyways, enjoy your M4 and have fun.

xaled1 commented 5 years ago

Sounds good. Btw I designed the I2S - u.fl mini breakout HAT to use with multichannel DACs. I actually started with NanoPi M4 as it the only SBC that has 8 I2S output channels on board. I will order the PCBs next week and if you are interested, I can send you one.

avafinger commented 5 years ago

Nice. I don't have the skills to populate PCBs. When you have your product ready we can talk about this again. I don't have experience with I2S but I can try to help if you need.:)

avafinger commented 5 years ago

@xaled1

There is an update that exposes the S/PDIF in case you have not found a way yet and still want to use this IMG.

Check the update https://github.com/avafinger/nanopi-m4-ubuntu-base-minimal/releases/tag/v1.25

mrhaoxx commented 5 years ago

Hi, If you can connect your pi with hdmi you can use "console=tty1" in bootargs to see how it boots with a screen

mrhaoxx commented 5 years ago

Another,if I flash the 5.3.1 kernel and normal rootfs into the emmc,will that work? (Sorry my poor english

avafinger commented 5 years ago

Another,if I flash the 5.3.1 kernel and normal rootfs into the emmc,will that work?

Yes, it will, but the device order (root=) may change for the latest u-boot used in mainline. You need to check which device number you get while booting from eMMC and change it in boot.cmd root=/dev/mmcblk0p2 or root=/dev/mmcblk1p2 or root=/dev/mmcblk2p2

You can only check this with a TTL debug.

Use the latest u-boot from here: https://github.com/avafinger/nanopi-m4-ubuntu-base-minimal/releases/tag/v1.27

you can use "console=tty1" in bootargs to see how it boots with a screen

Not sure if i understand it, is it a question or affirmation? Anyway, i removed the "console=..." just because was interfering with BT.

mrhaoxx commented 5 years ago

"console=tty1" is used to output the bootlogs into the hdmi screen. Now I've flashed the 4.14.y image you provided. Could I just compile a 5.3.1 kernel and then install it?

mrhaoxx commented 5 years ago

I tried and then the system cant boot

avafinger commented 5 years ago

Can you grab a complete boot log?

avafinger commented 5 years ago

For the u-boot mainline (old):

#
# Mainline Kernel 5.x
# 0 = eMMC
# 1 = SD card
setenv boot_from_device 1
# 0 = eMMC
# 1 = SD card
setenv boot_blk 1

For the latest u-boot (5.3.y) you need to find out using the TTL debug Boot from SD CARD and access the /boot in the eMMC and edit and re-compile boot.cmd ith the correct root=/dev/mmcblk${boot_blk}p2 (mainline) or root=/dev/mmcblk?p2 (bsp)

avafinger commented 5 years ago

you must be aware of the differences here:

-- BSP
lrwxrwxrwx  1 root root       39 Fev  7  2019 dtb -> rk3399-nanopi4-rev01.dtb_4.4.173-rk3399
lrwxrwxrwx  1 root root       20 Fev  7  2019 Image -> Image_4.4.173-rk3399

-- MAINLINE
lrwxrwxrwx  1 root root       33 Jul 15 12:36 dtb -> rk3399-nanopi-m4.dtb_5.2.0-rk3399
lrwxrwxrwx  1 root root       18 Jul 15 12:36 Image -> Image_5.2.0-rk3399

I am finishing a 5.3.1 build and will post soon..

avafinger commented 5 years ago

Can you re-install your BSP in eMMC and try this: https://github.com/avafinger/nanopi-m4-ubuntu-base-minimal/releases/tag/v1.28

mrhaoxx commented 5 years ago

I’m a student,so i won’t have time to try in next 5-7 day,but i will certainly try in the national day of china.

xaled1 commented 5 years ago

There is an update that exposes the S/PDIF in case you have not found a way yet and still want to use this IMG.

Hi, I finally soldered my I2S hat.

I need the I2S GPIO output pins instead of SPDIF to work with the HAT. Could you make DTB for I2S instead of SPDIF?

avafinger commented 5 years ago

I2s1 is enabled in the kernel 4.4.y ! I2S1 supports up to 2 channels TX and 2 channels RX. See if is missing some config? do you mean 5.3.y?

avafinger commented 5 years ago

@xaled1 Use this: https://github.com/avafinger/nanopi-m4-ubuntu-base-minimal/releases/tag/v1.26

You will see this (i2s):

aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: realtekrt5651co [realtek,rt5651-codec], device 0: ff890000.i2s-rt5651-aif1 rt5651-aif1-0 []
  Subdevices: 0/1
  Subdevice #0: subdevice #0
card 1: rockchiphdmi [rockchip,hdmi], device 0: ff8a0000.i2s-i2s-hifi i2s-hifi-0 []
  Subdevices: 0/1
  Subdevice #0: subdevice #0
xaled1 commented 5 years ago

Hi,

correct me if I'm wrong but my understanding is that this i2s port is connected to hdmi and I need the i2s port that is connected to gpio pi s.

avafinger commented 5 years ago

I can see this in the DT that describes the rt5651 :

&i2s1 {
    status = "okay";
    rockchip,i2s-broken-burst-len;
    rockchip,playback-channels = <2>;
    rockchip,capture-channels = <2>;
    #sound-dai-cells = <0>;
};

&rt5651_card {
    /delete-property/ pinctrl-0;
    /delete-property/ simple-audio-card,hp-det-gpio;

    simple-audio-card,cpu {
        sound-dai = <&i2s1>;
    };
};
&i2c1 {
    status = "okay";
    i2c-scl-rising-time-ns = <150>;
    i2c-scl-falling-time-ns = <30>;
    clock-frequency = <200000>;

    rt5651: rt5651@1a {
        #sound-dai-cells = <0>;
        compatible = "rockchip,rt5651";
        reg = <0x1a>;
        clocks = <&cru SCLK_I2S_8CH_OUT>;
        clock-names = "mclk";
        pinctrl-names = "default";
        pinctrl-0 = <&i2s_8ch_mclk>;
        status = "okay";
    };
};

and

    rt5651_card: rt5651-sound {
        status = "okay";
        compatible = "simple-audio-card";
        pinctrl-names = "default";
        pinctrl-0 = <&hp_det>;

        simple-audio-card,name = "realtek,rt5651-codec";
        simple-audio-card,format = "i2s";
        simple-audio-card,mclk-fs = <256>;
        simple-audio-card,hp-det-gpio = <&gpio4 28 GPIO_ACTIVE_HIGH>;

        simple-audio-card,widgets =
            "Microphone", "Mic Jack",
            "Headphone", "Headphone Jack";
        simple-audio-card,routing =
            "Mic Jack", "micbias1",
            "IN1P", "Mic Jack",
            "Headphone Jack", "HPOL",
            "Headphone Jack", "HPOR";

        simple-audio-card,cpu {
            sound-dai = <&i2s0>;
        };
        simple-audio-card,codec {
            sound-dai = <&rt5651>;
        };
    };

and the hdmi-sound seems to be i2s2, see:

    hdmi_sound: hdmi-sound {
        status = "okay";
        compatible = "simple-audio-card";
        simple-audio-card,format = "i2s";
        simple-audio-card,mclk-fs = <256>;
        simple-audio-card,name = "rockchip,hdmi";

        simple-audio-card,cpu {
            sound-dai = <&i2s2>;
        };
        simple-audio-card,codec {
            sound-dai = <&hdmi>;
        };
    };

i2s0 (*) is left empty. So where rt5651 card is connected? Can you infer from the above what should be done?

avafinger commented 5 years ago

Maybe this can help: https://forum.radxa.com/t/i2s-hifi-audio-pi-hats/144

xaled1 commented 5 years ago

Maybe this can help: https://forum.radxa.com/t/i2s-hifi-audio-pi-hats/144 Thanks, I've seen it, but it does not provide a solution

RK3399 has three I2S/PCM controllers embedded in the design, I2S0, I2S1 and I2S2

http://opensource.rock-chips.com/images/e/ee/Rockchip_RK3399TRM_V1.4_Part1-20170408.pdf#%5B%7B%22num%22%3A848%2C%22gen%22%3A0%7D%2C%7B%22name%22%3A%22XYZ%22%7D%2C51%2C790%2C0%5D

http://wiki.friendlyarm.com/wiki/index.php/NanoPi_M4#Select_the_system_default_audio_device

rt5651 is the onboard DAC with 3.5mm jack interface SPDIF is connected to following GPIO pins

25 | GND | 26 | GPIO4_C5/SPDIF_TX(3V)

I need the sound output on the following GPIO pins:

36 | I2S0_SDO0(1.8V) 37 | I2S0_SDI1SDO3(1.8V) 38 | I2S0_SDI2SDO2(1.8V) 39 | GND 40 | I2S0_SDI3SDO1(1.8V)

I've seen some discussion about I2S on NanpoPi m4 at the armbian forum and will ask the guys over there.

avafinger commented 5 years ago

Ok.

i2s0 is already enabled and seems routed to the header pins. Maybe there is a need to enable some PCM in the kernel config. Available PCM codecs in 4.4:

# CONFIG_SND_SOC_PCM1681 is not set
# CONFIG_SND_SOC_PCM1792A is not set

I will follow your discussion on Armbian.

xaled1 commented 5 years ago

Apparently we need to "attach" some dummy 8ch codec definition to the I2S0 to get it available in aplay. I tried to figure out how rt5651 is "attached" to I2S1 to use it as example but did not get far.

Btw how did you add the SPDIF output as I don't have listed in my aplay?

Here is the armbian discussion. https://forum.armbian.com/topic/11721-nanopi-m4-audio-i2s-output-on-gpio/

avafinger commented 5 years ago

Unfortunately in my experiments, i could have either rt5651 or spdif but not both at the same time. I never figured out why. There is the resulting DTB to expose spdif here https://github.com/avafinger/nanopi-m4-ubuntu-base-minimal/releases/tag/v1.25

If i recall correctly Armbian has both but you have to build from source.

mrhaoxx commented 5 years ago

I'back and I tried the image (v1.28). There seems to be someting wrong with the network(eth) So I cant connect to the board as i dont have the correct ttl converter

avafinger commented 5 years ago

@haoxingxing

Edit /etc/network/interfaces and revert the hotplug, this has a bad effect of a long delay to get IP from dhcp server. If you unplug and plug the net connector it may get IP or: Revert to: auto eth0

allow-hotplug eth0

iface eth0 inet dhcp

and reboot.

avafinger commented 5 years ago

@xaled1 Can you explain what is your hardware (hat)? Isn't there a DAC in your HAT? My understanding is that the I2S0 is routed (wired) to the pins (header) and we have to describe the hardware attached to the pins (aka your hat) and that hardware must have a DAC to output the sound, right or wrong?

i think I2S1 is routed to rt5651 via i2c.

xaled1 commented 5 years ago

Hi, You are right, but there is no DAC in my HAT :) The idea is to be able to connect different DACs to the GPIO pins using u.fl cables. This is what HAT actually does. We need to describe a dummy 8ch DAC that is virtually connected to the I2S0. This dummy DAC description would make the audio device (externally connected DAC) available in Linux.

Here is the photo for the 2ch I2S HAT that got me inspired to create 8ch hat. https://farm6.staticflickr.com/5659/20664953226_29a3b6aace_o.jpg

avafinger commented 5 years ago

Ahh, ok. I am very limited in this field but maybe "snd-soc-dummy-dai" would help.

/*
 * The dummy CODEC is only meant to be used in situations where there is no
 * actual hardware.
 *
 * If there is actual hardware even if it does not have a control bus
 * the hardware will still have constraints like supported samplerates, etc.
 * which should be modelled. And the data flow graph also should be modelled
 * using DAPM.
 */

If you find out how this guy implemented the i2s in the RPI (DT) i think that would help.

xaled1 commented 5 years ago

Most of the external 2channel I2S DACs work ok with hifiberry-dac-overlay.dts. The overlay uses pcm5102a codec that accepts I2S signals in the very common generic format that is also accepted by a lot of other DACs. https://github.com/raspberrypi/linux/tree/rpi-4.14.y/arch/arm/boot/dts/overlays

The I2S part of the DACs is pretty common across the vendors. The major difference is usually in the I2C control of the DACs we don't need here. There is some additional explanation: https://forum.volumio.org/i2s-drivers-t1778.html

Here is an example of 8 channel driver. It would be enough to have any 8 channel diver loaded and available in alsa. I can than work with logic analyzer and fix the possible format mismatches. https://bootlin.com/blog/eight-channels-audio-on-i-mx7-with-pcm3168/

avafinger commented 4 years ago

@xaled1 Did you find a solution?