Recherche avancée

Médias (1)

Mot : - Tags -/book

Autres articles (47)

  • Websites made ​​with MediaSPIP

    2 mai 2011, par

    This page lists some websites based on MediaSPIP.

  • Les vidéos

    21 avril 2011, par

    Comme les documents de type "audio", Mediaspip affiche dans la mesure du possible les vidéos grâce à la balise html5 .
    Un des inconvénients de cette balise est qu’elle n’est pas reconnue correctement par certains navigateurs (Internet Explorer pour ne pas le nommer) et que chaque navigateur ne gère en natif que certains formats de vidéos.
    Son avantage principal quant à lui est de bénéficier de la prise en charge native de vidéos dans les navigateur et donc de se passer de l’utilisation de Flash et (...)

  • Creating farms of unique websites

    13 avril 2011, par

    MediaSPIP platforms can be installed as a farm, with a single "core" hosted on a dedicated server and used by multiple websites.
    This allows (among other things) : implementation costs to be shared between several different projects / individuals rapid deployment of multiple unique sites creation of groups of like-minded sites, making it possible to browse media in a more controlled and selective environment than the major "open" (...)

Sur d’autres sites (7626)

  • SegFault while freeing nvenc hwdevice_ctx

    23 février 2024, par camelCase

    For a project, I created a class encoding the output of an OpenGL renderbuffer object using h264_nvenc. Unfortunately, tidying up doesn't work, and the program crashes with a SegFault. The reason is accessing an unaccessable memory region, happening twice in the final lines (see below) when calling av_buffer_unref( &_hwDeviceRefCtx ) and implicitely also during avcodec_free_context( &_pCodecCtx ), but both calls are required for shutting down.

    


    The (in this case relevant) valgrind-output is

    


    Invalid read of size 8
   at 0x48AD987: UnknownInlinedFun (buffer.c:121)
   by 0x48AD987: UnknownInlinedFun (buffer.c:144)
   by 0x48AD987: av_buffer_unref (buffer.c:139)
   by 0x5D06D7A: avcodec_close (avcodec.c:486)
   by 0x628DD7D: avcodec_free_context (options.c:175)
   by 0x10A863: main (main.cpp:115)
 Address 0x17812700 is 0 bytes inside a block of size 24 free'd
   at 0x484488F: free (vg_replace_malloc.c:985)
   by 0x48AD98F: UnknownInlinedFun (buffer.c:127)
   by 0x48AD98F: UnknownInlinedFun (buffer.c:144)
   by 0x48AD98F: av_buffer_unref (buffer.c:139)
   by 0x48BE098: hwframe_ctx_free (hwcontext.c:240)
   by 0x48AD9A6: UnknownInlinedFun (buffer.c:133)
   by 0x48AD9A6: UnknownInlinedFun (buffer.c:144)
   by 0x48AD9A6: av_buffer_unref (buffer.c:139)
   by 0x5D06D0A: UnknownInlinedFun (decode.c:1261)
   by 0x5D06D0A: avcodec_close (avcodec.c:465)
   by 0x628DD7D: avcodec_free_context (options.c:175)
   by 0x10A863: main (main.cpp:115)
 Block was alloc'd at
   at 0x4849366: posix_memalign (vg_replace_malloc.c:2099)
   by 0x48D9BD5: av_malloc (mem.c:105)
   by 0x48D9DAD: av_mallocz (mem.c:256)
   by 0x48AD8DD: UnknownInlinedFun (buffer.c:44)
   by 0x48AD8DD: av_buffer_create (buffer.c:64)
   by 0x48BDDEB: av_hwdevice_ctx_alloc (hwcontext.c:179)
   by 0x48BDF29: av_hwdevice_ctx_create (hwcontext.c:622)
   by 0x10A482: main (main.cpp:43)

Invalid free() / delete / delete[] / realloc()
   at 0x484488F: free (vg_replace_malloc.c:985)
   by 0x48AD98F: UnknownInlinedFun (buffer.c:127)
   by 0x48AD98F: UnknownInlinedFun (buffer.c:144)
   by 0x48AD98F: av_buffer_unref (buffer.c:139)
   by 0x5D06D7A: avcodec_close (avcodec.c:486)
   by 0x628DD7D: avcodec_free_context (options.c:175)
   by 0x10A863: main (main.cpp:115)
 Address 0x17812700 is 0 bytes inside a block of size 24 free'd
   at 0x484488F: free (vg_replace_malloc.c:985)
   by 0x48AD98F: UnknownInlinedFun (buffer.c:127)
   by 0x48AD98F: UnknownInlinedFun (buffer.c:144)
   by 0x48AD98F: av_buffer_unref (buffer.c:139)
   by 0x48BE098: hwframe_ctx_free (hwcontext.c:240)
   by 0x48AD9A6: UnknownInlinedFun (buffer.c:133)
   by 0x48AD9A6: UnknownInlinedFun (buffer.c:144)
   by 0x48AD9A6: av_buffer_unref (buffer.c:139)
   by 0x5D06D0A: UnknownInlinedFun (decode.c:1261)
   by 0x5D06D0A: avcodec_close (avcodec.c:465)
   by 0x628DD7D: avcodec_free_context (options.c:175)
   by 0x10A863: main (main.cpp:115)
 Block was alloc'd at
   at 0x4849366: posix_memalign (vg_replace_malloc.c:2099)
   by 0x48D9BD5: av_malloc (mem.c:105)
   by 0x48D9DAD: av_mallocz (mem.c:256)
   by 0x48AD8DD: UnknownInlinedFun (buffer.c:44)
   by 0x48AD8DD: av_buffer_create (buffer.c:64)
   by 0x48BDDEB: av_hwdevice_ctx_alloc (hwcontext.c:179)
   by 0x48BDF29: av_hwdevice_ctx_create (hwcontext.c:622)
   by 0x10A482: main (main.cpp:43)


    


    that is also duplicated (due to the calls to avcodec_free_context() and av_buffer_unref()).

    


    The question is : How can I fix this ?

    


    The (more or less) minimal (not) working example reads

    


    #include <string>&#xA;&#xA;extern "C" {&#xA;  #include <libavutil></libavutil>opt.h>&#xA;  #include <libavcodec></libavcodec>avcodec.h>&#xA;  #include <libavformat></libavformat>avformat.h>&#xA;  #include <libavutil></libavutil>hwcontext.h>&#xA;  #include <libavutil></libavutil>pixdesc.h>&#xA;  #include <libavutil></libavutil>hwcontext_cuda.h>&#xA;}&#xA;&#xA;//(former) libx264 encoding based on https://github.com/FFmpeg/FFmpeg/blob/master/doc/examples/muxing.c&#xA;//update to h264_nvenc with a lot of help from https://stackoverflow.com/questions/49862610/opengl-to-ffmpeg-encode&#xA;//and some additional info of https://github.com/FFmpeg/FFmpeg/blob/master/doc/examples/vaapi_encode.c&#xA;&#xA;int main() {&#xA;    const int _SrcImageWidth=640;&#xA;    const int _SrcImageHeight=480;&#xA;    &#xA;    const AVOutputFormat *_oFmt = nullptr;&#xA;    AVFormatContext *_oFmtCtx = nullptr;&#xA;    &#xA;    const AVCodec *_pCodec = nullptr;&#xA;    AVCodecContext *_pCodecCtx = nullptr;&#xA;    &#xA;    AVFrame* _frame;&#xA;    AVPacket* _packet;&#xA;    AVStream* _stream;&#xA;    &#xA;    AVBufferRef *_hwDeviceRefCtx = nullptr;&#xA;    const CUcontext* _cudaCtx;&#xA;    &#xA;    const std::string _OutFileName = "output.mkv";&#xA;    &#xA;    //constructor part&#xA;    int ret;&#xA;&#xA;    //output format context      &#xA;    avformat_alloc_output_context2( &amp;_oFmtCtx, nullptr, nullptr, _OutFileName.c_str() );&#xA;    _oFmt = _oFmtCtx->oformat;&#xA;&#xA;    //hardware format context&#xA;    ret = av_hwdevice_ctx_create( &amp;_hwDeviceRefCtx, AV_HWDEVICE_TYPE_CUDA, "NVIDIA GeForce RTX 4070", nullptr, 0 );&#xA;&#xA;    //hardware frame context for device buffer allocation&#xA;    AVBufferRef* hwFrameRefCtx = av_hwframe_ctx_alloc( _hwDeviceRefCtx );&#xA;    AVHWFramesContext* hwFrameCtx = (AVHWFramesContext*) (hwFrameRefCtx->data);&#xA;    hwFrameCtx->width = _SrcImageWidth;&#xA;    hwFrameCtx->height = _SrcImageHeight;&#xA;    hwFrameCtx->sw_format = AV_PIX_FMT_0BGR32;&#xA;    hwFrameCtx->format = AV_PIX_FMT_CUDA;&#xA;    hwFrameCtx->device_ref = _hwDeviceRefCtx;&#xA;    hwFrameCtx->device_ctx = (AVHWDeviceContext*) _hwDeviceRefCtx->data;&#xA;&#xA;    ret = av_hwframe_ctx_init( hwFrameRefCtx );&#xA;&#xA;    //get cuda context&#xA;    const AVHWDeviceContext* hwDeviceCtx = (AVHWDeviceContext*)(_hwDeviceRefCtx->data);&#xA;    const AVCUDADeviceContext* cudaDeviceCtx = (AVCUDADeviceContext*)(hwDeviceCtx->hwctx);&#xA;    _cudaCtx = &amp;(cudaDeviceCtx->cuda_ctx);&#xA;&#xA;    //codec context&#xA;    _pCodec = avcodec_find_encoder_by_name( "h264_nvenc" );&#xA;&#xA;    _packet = av_packet_alloc();&#xA;&#xA;    _stream = avformat_new_stream( _oFmtCtx, nullptr );&#xA;    _stream->id = _oFmtCtx->nb_streams - 1;&#xA;    _pCodecCtx = avcodec_alloc_context3( _pCodec );&#xA;&#xA;    _pCodecCtx->qmin = 18;&#xA;    _pCodecCtx->qmax = 20;&#xA;    _pCodecCtx->width = _SrcImageWidth;&#xA;    _pCodecCtx->height = _SrcImageHeight;&#xA;    _pCodecCtx->framerate = (AVRational) {25,1};&#xA;    _pCodecCtx->time_base = (AVRational) {1,25};&#xA;    _stream->time_base = _pCodecCtx->time_base;&#xA;    _pCodecCtx->gop_size = 12; //I-Frame every at most 12 frames&#xA;    _pCodecCtx->max_b_frames = 2;&#xA;    _pCodecCtx->pix_fmt = AV_PIX_FMT_CUDA; //required to use renderbuffer as src&#xA;    _pCodecCtx->codec_type = AVMEDIA_TYPE_VIDEO;&#xA;    _pCodecCtx->sw_pix_fmt = AV_PIX_FMT_0BGR32; &#xA;    _pCodecCtx->hw_device_ctx = _hwDeviceRefCtx;&#xA;    _pCodecCtx->hw_frames_ctx = av_buffer_ref( hwFrameRefCtx );&#xA;    av_opt_set(_pCodecCtx->priv_data, "preset", "p7", 0);&#xA;    av_opt_set(_pCodecCtx->priv_data, "rc", "vbr", 0);&#xA;    if( _oFmtCtx->oformat->flags &amp; AVFMT_GLOBALHEADER ) {&#xA;        _pCodecCtx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;&#xA;    }&#xA;&#xA;    ret = avcodec_open2( _pCodecCtx, _pCodec, nullptr );&#xA;    avcodec_parameters_from_context( _stream->codecpar, _pCodecCtx );&#xA;&#xA;    if (!(_oFmtCtx->oformat->flags &amp; AVFMT_NOFILE)) {&#xA;        ret = avio_open(&amp;_oFmtCtx->pb, _OutFileName.c_str(), AVIO_FLAG_WRITE);&#xA;    }&#xA;    ret = avformat_write_header( _oFmtCtx, nullptr );&#xA;&#xA;    //use hardware frame from above&#xA;    _frame = av_frame_alloc();&#xA;    ret = av_hwframe_get_buffer( _pCodecCtx->hw_frames_ctx, _frame, 0 );&#xA;    _frame->pts = 1;&#xA;&#xA;    av_buffer_unref( &amp;hwFrameRefCtx );&#xA;&#xA;    //destructor part&#xA;    av_frame_free( &amp;_frame );&#xA;    av_packet_free( &amp;_packet );&#xA;&#xA;    av_write_trailer( _oFmtCtx );&#xA;    avio_closep( &amp;_oFmtCtx->pb );&#xA;&#xA;    avformat_free_context( _oFmtCtx );&#xA;&#xA;    avcodec_free_context( &amp;_pCodecCtx );&#xA;    av_buffer_unref( &amp;_hwDeviceRefCtx );&#xA;&#xA;    return 0;&#xA;}&#xA;</string>

    &#xA;

    and compiles with (linux user)

    &#xA;

    g&#x2B;&#x2B; -lavutil -lavformat -lavcodec -lz -lavutil -lswscale -lswresample -lm -ggdb3 -I/opt/cuda/include main.cpp&#xA;

    &#xA;

    Thanks in advance !

    &#xA;

  • ffmpeg piped output producing incorrect metadata frame count with Python

    6 décembre 2024, par Xorgon

    Using Python, I am attempting to use ffmpeg to compress videos and put them in a PowerPoint. This works great, however, the video files themselves have incorrect frame counts which can cause issues when I read from those videos in other code.

    &#xA;

    Edit for clarification : by "frame count" I mean the metadata frame count. The actual number of frames contained in the video is correct, but querying the metadata gives an incorrect frame count.

    &#xA;

    Having eliminated the PowerPoint aspect of the code, I've narrowed this down to the following minimal reproducing example of saving an output from an ffmpeg pipe :

    &#xA;

    from subprocess import Popen, PIPE&#xA;&#xA;video_path = &#x27;test_mp4.mp4&#x27;&#xA;&#xA;ffmpeg_pipe = Popen([&#x27;ffmpeg&#x27;,&#xA;                     &#x27;-y&#x27;,  # Overwrite files&#xA;                     &#x27;-i&#x27;, f&#x27;{video_path}&#x27;,  # Input from file&#xA;                     &#x27;-f&#x27;, &#x27;avi&#x27;,  # Output format&#xA;                     &#x27;-c:v&#x27;, &#x27;libx264&#x27;,  # Codec&#xA;                     &#x27;-&#x27;],  # Output to pipe&#xA;                    stdout=PIPE)&#xA;&#xA;new_path = "piped_video.avi"&#xA;vid_file = open(new_path, "wb")&#xA;vid_file.write(ffmpeg_pipe.stdout.read())&#xA;vid_file.close()&#xA;

    &#xA;

    I've tested several different videos. One small example video that I've tested can be found here.

    &#xA;

    I've tried a few different codecs with avi format and tried libvpx with webm format. For the avi outputs, the frame count usually reads as 1073741824 (2^30). Weirdly, for the webm format, the frame count read as -276701161105643264.

    &#xA;

    This is a snippet I used to read the frame count, but one could also see the error by opening the video details in Windows Explorer and seeing the total time as something like 9942 hours, 3 minutes, and 14 seconds.

    &#xA;

    import cv2&#xA;&#xA;video_path = &#x27;test_mp4.mp4&#x27;&#xA;new_path = "piped_video.webm"&#xA;&#xA;cap = cv2.VideoCapture(video_path)&#xA;print(f"Original video frame count: = {int(cap.get(cv2.CAP_PROP_FRAME_COUNT)):d}")&#xA;cap.release()&#xA;&#xA;cap = cv2.VideoCapture(new_path)&#xA;print(f"Piped video frame count: = {int(cap.get(cv2.CAP_PROP_FRAME_COUNT)):d}")&#xA;cap.release()&#xA;

    &#xA;

    For completeness, here is the ffmpeg output :

    &#xA;

    ffmpeg version 2023-06-11-git-09621fd7d9-full_build-www.gyan.dev Copyright (c) 2000-2023 the FFmpeg developers&#xA;  built with gcc 12.2.0 (Rev10, Built by MSYS2 project)&#xA;  configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-bzlib --enable-lzma --enable-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libaribb24 --enable-libaribcaption --enable-libdav1d --enable-libdavs2 --enable-libuavs3d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libaom --enable-libjxl --enable-libopenjpeg --enable-libvpx --enable-mediafoundation --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-liblensfun --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libvpl --enable-libshaderc --enable-vulkan --enable-libplacebo --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libcodec2 --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint&#xA;  libavutil      58. 13.100 / 58. 13.100&#xA;  libavcodec     60. 17.100 / 60. 17.100&#xA;  libavformat    60.  6.100 / 60.  6.100&#xA;  libavdevice    60.  2.100 / 60.  2.100&#xA;  libavfilter     9.  8.101 /  9.  8.101&#xA;  libswscale      7.  3.100 /  7.  3.100&#xA;  libswresample   4. 11.100 /  4. 11.100&#xA;  libpostproc    57.  2.100 / 57.  2.100&#xA;Input #0, mov,mp4,m4a,3gp,3g2,mj2, from &#x27;test_mp4.mp4&#x27;:&#xA;  Metadata:&#xA;    major_brand     : mp42&#xA;    minor_version   : 0&#xA;    compatible_brands: isommp42&#xA;    creation_time   : 2022-08-10T12:54:09.000000Z&#xA;  Duration: 00:00:06.67, start: 0.000000, bitrate: 567 kb/s&#xA;  Stream #0:0[0x1](eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(progressive), 384x264 [SAR 1:1 DAR 16:11], 563 kb/s, 30 fps, 30 tbr, 30k tbn (default)&#xA;    Metadata:&#xA;      creation_time   : 2022-08-10T12:54:09.000000Z&#xA;      handler_name    : Mainconcept MP4 Video Media Handler&#xA;      vendor_id       : [0][0][0][0]&#xA;      encoder         : AVC Coding&#xA;Stream mapping:&#xA;  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))&#xA;Press [q] to stop, [?] for help&#xA;[libx264 @ 0000018c68c8b9c0] using SAR=1/1&#xA;[libx264 @ 0000018c68c8b9c0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2&#xA;[libx264 @ 0000018c68c8b9c0] profile High, level 2.1, 4:2:0, 8-bit&#xA;Output #0, avi, to &#x27;pipe:&#x27;:&#xA;  Metadata:&#xA;    major_brand     : mp42&#xA;    minor_version   : 0&#xA;    compatible_brands: isommp42&#xA;    ISFT            : Lavf60.6.100&#xA;  Stream #0:0(eng): Video: h264 (H264 / 0x34363248), yuv420p(progressive), 384x264 [SAR 1:1 DAR 16:11], q=2-31, 30 fps, 30 tbn (default)&#xA;    Metadata:&#xA;      creation_time   : 2022-08-10T12:54:09.000000Z&#xA;      handler_name    : Mainconcept MP4 Video Media Handler&#xA;      vendor_id       : [0][0][0][0]&#xA;      encoder         : Lavc60.17.100 libx264&#xA;    Side data:&#xA;      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A&#xA;[out#0/avi @ 0000018c687f47c0] video:82kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 3.631060%&#xA;frame=  200 fps=0.0 q=-1.0 Lsize=      85kB time=00:00:06.56 bitrate= 106.5kbits/s speed=76.2x    &#xA;[libx264 @ 0000018c68c8b9c0] frame I:1     Avg QP:16.12  size:  3659&#xA;[libx264 @ 0000018c68c8b9c0] frame P:80    Avg QP:21.31  size:   647&#xA;[libx264 @ 0000018c68c8b9c0] frame B:119   Avg QP:26.74  size:   243&#xA;[libx264 @ 0000018c68c8b9c0] consecutive B-frames:  3.0% 53.0%  0.0% 44.0%&#xA;[libx264 @ 0000018c68c8b9c0] mb I  I16..4: 17.6% 70.6% 11.8%&#xA;[libx264 @ 0000018c68c8b9c0] mb P  I16..4:  0.8%  1.7%  0.6%  P16..4: 17.6%  4.6%  3.3%  0.0%  0.0%    skip:71.4%&#xA;[libx264 @ 0000018c68c8b9c0] mb B  I16..4:  0.1%  0.3%  0.2%  B16..8: 11.7%  1.4%  0.4%  direct: 0.6%  skip:85.4%  L0:32.0% L1:59.7% BI: 8.3%&#xA;[libx264 @ 0000018c68c8b9c0] 8x8 transform intra:59.6% inter:62.4%&#xA;[libx264 @ 0000018c68c8b9c0] coded y,uvDC,uvAC intra: 48.5% 0.0% 0.0% inter: 3.5% 0.0% 0.0%&#xA;[libx264 @ 0000018c68c8b9c0] i16 v,h,dc,p: 19% 39% 25% 17%&#xA;[libx264 @ 0000018c68c8b9c0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 21% 25% 30%  3%  3%  4%  4%  4%  5%&#xA;[libx264 @ 0000018c68c8b9c0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 22% 20% 16%  6%  8%  8%  8%  5%  6%&#xA;[libx264 @ 0000018c68c8b9c0] i8c dc,h,v,p: 100%  0%  0%  0%&#xA;[libx264 @ 0000018c68c8b9c0] Weighted P-Frames: Y:0.0% UV:0.0%&#xA;[libx264 @ 0000018c68c8b9c0] ref P L0: 76.2%  7.9% 11.2%  4.7%&#xA;[libx264 @ 0000018c68c8b9c0] ref B L0: 85.6% 12.9%  1.5%&#xA;[libx264 @ 0000018c68c8b9c0] ref B L1: 97.7%  2.3%&#xA;[libx264 @ 0000018c68c8b9c0] kb/s:101.19&#xA;

    &#xA;

    So the question is : why does this happen, and how can one avoid it ?

    &#xA;

  • Hacking the Popcorn Hour C-200

    3 mai 2010, par Mans — Hardware, MIPS

    Update : A new firmware version has been released since the publication of this article. I do not know if the procedure described below will work with the new version.

    The Popcorn Hour C-200 is a Linux-based media player with impressive specifications. At its heart is a Sigma Designs SMP8643 system on chip with a 667MHz MIPS 74Kf as main CPU, several co-processors, and 512MB of DRAM attached. Gigabit Ethernet, SATA, and USB provide connectivity with the world around it. With a modest $299 on the price tag, the temptation to repurpose the unit as a low-power server or cheap development board is hard to resist. This article shows how such a conversion can be achieved.

    Kernel

    The PCH runs a patched Linux 2.6.22.19 kernel. A source tarball is available from the manufacturer. This contains the sources with Sigma support patches, Con Kolivas’ patch set (scheduler tweaks), and assorted unrelated changes. Properly split patches are unfortunately not available. I have created a reduced patch against vanilla 2.6.22.19 with only Sigma-specific changes, available here.

    The installed kernel has a number of features disabled, notably PTY support and oprofile. We will use kexec to load a more friendly one.

    As might be expected, the PCH kernel does not have kexec support enabled. It does however, by virtue of using closed-source components, support module loading. This lets us turn kexec into a module and load it. A patch for this is available here. To build the module, apply the patch to the PCH sources and build using this configuration. This will produce two modules, kexec.ko and mips_kexec.ko. No other products of this build will be needed.

    The replacement kernel can be built from the PCH sources or, if one prefers, from vanilla 2.6.22.19 with the Sigma-only patch. For the latter case, this config provides a minimal starting point suitable for NFS-root.

    When configuring the kernel, make sure CONFIG_TANGOX_IGNORE_CMDLINE is enabled. Otherwise the command line will be overridden by a useless one stored in flash. A good command line can be set with CONFIG_CMDLINE (under “Kernel hacking” in menuconfig) or passed from kexec.

    Taking control

    In order to load our kexec module, we must first gain root privileges on the PCH, and here a few features of the system are working to our advantage :

    1. The PCH allows mounting any NFS export to access media files stored there.
    2. There is an HTTP server running. As root.
    3. This HTTP server can be readily instructed to fetch files from an NFS mount.
    4. Files with a name ending in .cgi are executed. As root.

    All we need do to profit from this is place the kexec modules, the kexec userspace tools, and a simple script on an NFS export. Once this is done, and the mount point configured on the PCH, a simple HTTP request will send the old kernel screaming to /dev/null, our shiny new kernel taking its place.

    The rootfs

    A kernel is mostly useless without a root filesystem containing tools and applications. A number of tools for cross-compiling a full system exist, each with its strengths and weaknesses. The only thing to look out for is the version of kernel headers used (usually a linux-headers package). As we will be running an old kernel, chances are the default version is too recent. Other than this, everything should be by the book.

    Assembling the parts

    Having gathered all the pieces, it is now time to assemble the hack. The following steps are suitable for an NFS-root system. Adaptation to a disk-based system is left as an exercise.

    1. Build a rootfs for MIPS 74Kf little endian. Make sure kernel headers used are no more recent than 2.6.22.x. Include a recent version of the kexec userspace tools.
    2. Fetch and unpack the PCH kernel sources.
    3. Apply the modular kexec patch.
    4. Using this config, build the modules and install them as usual to the rootfs. The version string must be 2.6.22.19-19-4.
    5. From either the same kernel sources or plain 2.6.22.19 with Sigma patches, build a vmlinux and (optionally) modules using this config. Modify the compiled-in command line to point to the correct rootfs. Set the version string to something other than in the previous step.
    6. Copy vmlinux to any directory in the rootfs.
    7. Copy kexec.sh and kexec.cgi to the same directory as vmlinux.
    8. Export the rootfs over NFS with full read/write permissions for the PCH.
    9. Power on the PCH, and update to latest firmware.
    10. Configure an NFS mount of the rootfs.
    11. Navigate to the rootfs in the PCH UI. A directory listing of bin, dev, etc. should be displayed.
    12. On the host system, run the kexec.sh script with the target hostname or IP address as argument.
    13. If all goes well, the new kernel will boot and mount the rootfs.

    Serial console

    A serial console is indispensable for solving boot problems. The PCH board has two UART connectors. We will use the one labeled UART0. The pinout is as follows (not standard PC pinout).

            +-----------+
           2| * * * * * |10
           1| * * * * * |9
            -----------+
              J7 UART0
        /---------------------/ board edge
    
    Pin Function
    1 +5V
    5 Rx
    6 Tx
    10 GND

    The signals are 3.3V so a converter, e.g. MAX202, is required for connecting this to a PC serial port. The default port settings are 115200 bps 8n1.